Menu Open

Blog > Code

Convert NSTimeInterval to NSString - iOS Development

17 September 2012, 4:38 PM
To convert NSTimeInterval to NSString the following code works perfect

NSTimeInterval today = [[NSDate date] timeIntervalSince1970];
NSString *intervalString = [NSString stringWithFormat:@"%f", today];

Find string in NSArray and return index of string - iOS Development

12 September 2012, 3:54 PM
Find a string in an NSArray
NSArray *animals = [NSArray arrayWithObjects:@"Dog", @"Mouse", @"Cat", nil];
NSLog(@"Index: %i", [animals indexOfObject:@"Cat"]);

This would provide the following 
Index: 2

Convert NSString to Int - iPhone Development iOS

4 September 2012, 11:34 PM
Some simple code for converting string to int and int to string

String to Int
NSString *name = @"10";int value = [name intValue];

Int to String
int value = 100;NSString *name = [NSString stringWithFormat:@"%i", value];

PHP - Show String as Currency - Comma Separated - number_format()

7 February 2012, 12:57 PM
Working to show currency in a readable format

// 1 million coins is easier to read as 1,000,000
$value = "1000000"; // echo as 1,000,000
echo number_format($value, 0, '.', ',');

// echo as 1,000,000.00
echo number_format($value, 2, '.', ',');

// echo as 1:000:000
echo number_format($value, 0, '.', ':');

NSString - Check if String contains String

7 February 2012, 12:54 PM
Check to see if string is found. Looking for in string
NSString *input= @"does this string contain the word data";
NSString *find= @"data"; NSRange range;
for (NSString *string in stringList) {
range = [input rangeOfString:find];
if (range.location != NSNotFound)
NSLog (@"feed ready for download");
NSLog (@"feed broken");
} }

Cocoa NSURLConnection not called & [NSApp stop]

18 May 2011, 9:15 PM
We came across the issue of NSURLConnection not being called until the Modal was stopped using [NSApp stop] and this is the way around it. We have to use RunLoop.
- (void) awakeFromNib { NSURL *url=[[NSURL alloc] initWithString:@"/linkout.php?"]; NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url];   NSURLConnection *c = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES]; responseData=[[NSMutableData data] retain];   CFRunLoopRun(); }

Then you will need to stop CFRunLoopRun();

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSString *alert = [NSString stringWithFormat:@"Connection failed: %@", [error description]]; NSLog(alert);   CFRunLoopStop(CFRunLoopGetCurrent()); }   - (void)connectionDidFinishLoading:(NSURLConnection *)connection { CFRunLoopStop(CFRunLoopGetCurrent());    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(responseString);   [connection release]; }

Email Pipe to Program - PHP - cPanel

27 February 2011, 1:48 AM
Simple code to allow you to pipe an email to PHP using Forwarder setup with cPanel. You can use by setting up a new Forwarder and using Advanced options. To pipe you will need to enter this in the box requires changing the root to your PHP file.
/usr/bin/php -q /home/user1/scripts/pipemail.php
pipemail.php must have permission 0775 Contents of pipemail.php are as followed 
#!/usr/bin/php -q

Warning: iPhone SSH Default Password Must Change -

9 November 2009, 5:20 PM
ssh root@ (Device IP)
password: alpine
iPhone~# passwd
New Password:
Again Password:

Change it using the above in Terminal on your iPhone device. This is important and must be done by all users as soon as SSH is installed

Find it - Needle & HackStack PHP

6 November 2009, 5:20 PM
This is handy function which i have been using i put it together myself and use it alot to get data out of documents. 

// (c) Ollie Kett 2009 function FindIt($content, $start, $end) {
$haystack = strstr($content, $start);
$r = substr($haystack, 0, strpos($haystack, $end));
$remove = array($start);
$with   = array('');
$output  = str_replace($remove, $write, $r);
return $output;

Run in the follow manner for example i will use the below content
$content = 'information'
I would run that like the follow
FindIt($content, '', '');

That will return the result of 

You may want to explore your data if you have information such as 10/100. Explode it to like this
//You use FindIt() instead of 10/100
$e = explode("/", "10/100");

This returns the result of
$e[0] -> 10
$e[1] -> 100

Load a remote image into UIImageView

4 November 2009, 9:46 PM
Loading a remote image into UIImageView

UIImage *img = [[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString: @"/linkout.php?"]]] retain]; if (img != nil) { // Image was loaded successfully. [disk setImage:img]; [disk setUserInteractionEnabled:NO]; [img release]; // Release the image now that we have a UIImageView that contains it. }

Pass Sessions between subdomains in php

2 November 2009, 12:23 PM
With our ever growing API systems we have to parse alot of stuff over SSL to keep connect data secure at the moment we current have

However we dont use wildcard SSL as it's very pricely. We're currelty registerting a new server and SSL which will run on

This will mean pass PHP sessions between different locations so that the data from our API is connected via SSL and send between the secure layer.

Do to this just put the following code before you start your session.
ini_set("session.cookie_domain", "");

Between working and Error

19 October 2009, 12:41 AM
A simple line of code may have been annoying some of you that use our products in our activation platform some of you might have now we're been having a few issues over the last fews days this is actually because of a stupid error code mistake. This part of the code 
or die();
Only being 9 characters long (include space) was causing error across the whole platform as it was performing an error out instead of running the code.  Very annoying :( - Anyways a remote patch has been supplied and it seems to be working now.

LockMail Beta 1.0 - Rolled to Testers

13 October 2009, 6:46 PM
The LockMail Beta 1.0 has been rolled to developers on the LockMail Beta Repo.

You can download files however the program will not work unless you UDID has been registered on the Beta Program its not too late to register - Email me.

If you are using it you will need access to some vital data which includes the mail server setup use the following for the follow is required just enter the details as shown below

[qtitle]Google Mail[/qtitle][q]Server: gmail
Pass: [/q]

[qtitle]Yahoo (Works for some and doesn't for others)[/qtitle][q]Server: yahoo
Pass: [/q]

[qtitle]Me (MobileMe)[/qtitle][q]Server: mobileme
Pass: [/q]

[qtitle]Windows Live / MSN[/qtitle][q]Server: live
User: (,
Pass: [/q]

[qtitle]Other (Personal)[/qtitle][q]Server:
Pass: [/q]

LockMail Connection API

12 October 2009, 8:58 PM
To connect to the LockMail Connect API / Platform you do so in the follow method


An example of this would be


htmlspecialchars() - PHP - MySQL Insert

6 October 2009, 5:21 PM
I use this normally to add stuff to a database. I insert by converting using this [qtitle]PHP 4, 5[/qtitle]
$var = htmlspecialchars("Test", ENT_QUOTES)
Once i want to read out from the data i use. [qtitle]PHP 5.1 >[/qtitle]