Countries of the world in PHP array
A handy snippet to share with anyone who needs access to the countries of the world (Australia/New Zealand at the top in my example) as a PHP list:
[Read the rest of this entry...]
A handy snippet to share with anyone who needs access to the countries of the world (Australia/New Zealand at the top in my example) as a PHP list:
[Read the rest of this entry...]
A new error has started showing up when submitting iPhone Apps through iTunes Connect:
“The application-identifier entitlement is not formatted correctly; it should contain your 10-character App ID Seed, followed by a dot, followed by your bundle identifier.”
From what I can tell, the way to fix this to create a NEW entitlements file (see my previous post on creating adhoc builds for instructions on how to do this). Previously we’d only had to create an entitlements file and uncheck “get-task-allow”.
However now it appears you also need to add a new “keychain-access-group” and add an item which includes your App Identifier (get this from the iTunes Provisioning Portal) and your bundle identifier (com.mycompany.bundle_name).
See an example below:
Unfortunately, it’s quite a fiddly process to record audio and play it back at the same time on the iPhone. By default, the sound output is very quiet from the iPhone’s speaker when you are recording sound. So how do we fix this?
First, setup your audio session to record audio:
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey, nil];
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
} else {
NSLog(@"Error: %@", error);
}
Then tell the device you want to record and play audio at the same time:
AVAudioSession *audioSession = [AVAudioSession sharedInstance]; NSError *err = nil; [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
Then, and this is the key, allow the volume from the speakers to also be loud when recording:
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride),&audioRouteOverride);
The end result? You can happily play audio at full volume while recording from the device’s microphone. Happy days.
WSP Digital, who provide a range of products and services, from the world leading EIATRACK service through to advanced iPhone development, launched their new website yesterday:
Taking inspiration from origami in it’s design, look and feel, the website is a nice example of the power of WordPress to produce effective platforms to inform customers of your services.

If you’re getting an XML error when you’re using Facebook Connect to post to a users stream using the function:
$facebook->render_prompt_feed_url()
Then ensure the following:
For some reason the content is being placed in a hidden field on the page on “mobile” devices. This isn’t escaping the contents of the post, and hence breaks if you have any of the above.
Highly frustrating! Hope this helps someone.

After the recent release to developers of iPhone SDK 4.0, the inevitable scramble to review the new APIs has been on in earnest. One of the first things noticed were the following new AVCaptureDevice class properties:
These new properties relating to the iPhone SDK class AVCaptureDevice, a class used for audio and video capture and management, suggest that the new iPhone (to be announced at WWDC 2010??) may well include a “Flash”, a “Torch” and a front camera.
If this was to turn out to be true, then a front camera for the phone would make video calls possible, the ability to take photos while viewing the camera feed, and the flash would allow you to take photos in the dark!
All very cool new potential features. Let’s keep our fingers crossed that this turns out to be the case!
WSP Digital today released Product Ecology, a new web based sustainability tool providing Life Cycle Assessment (LCA) and Product Compliance support.

Aimed at product designers, industrial designers, product developers, engineers, environmental managers and brand owners the tool provides three key features:
It’s clear that the tool has been developed with usability in mind, providing a unique and powerful web-based tool for the design community.
I couldn’t find a decent way online to convert ICS files into an Excel type format for easy manipulation, or adding to documents etc. So I’ve built a simple one that is now available online:
http://csv2sql.evandavey.com/ical2csv.php
This takes an iCal URL and provides you with a CSV file as a download. Makes it much easier to get a list of dates from ICS files and use them for other purposes.
Also available is the CSV2SQL converter that I made last year, taking CSV files and coverting them into INSERT/UPDATE statements for use on a database.
I love using VMWare Fusion on Mac, it’s perfect as I can run everything I need on one machine, and minimise my exposure to windows. However, sometimes things go astray – windows “goes to sleep” and won’t come back to allow me to restart or shutdown the virtual machine. How do you fix this?

Hold down the “option” key and then go to the “Virtual Machine” menu option. You’ll notice that the options switch from “Shutdown” to “Force Shutdown” when you hold down the “option” key. Simply choose your required “Force” option and you should be back in business!
So, you’re building a web based twitter client in PHP. Easy, just use a simple Twitter API client and call the Twitter API directly. But what if you don’t want to store the user’s Twitter authentication information anywhere? It’s a security risk anyway and some people don’t want to give up their account details to a 3rd party. So what to do? The solution is to use OAuth with Twitter. [Read the rest of this entry...]
To remove applications that start automatically when you boot up is a simple process on the Mac, however still one that I get asked by friends and family regularly how to control. To manage the applications that launch when you first boot up, follow these steps:
Okay, I normally don’t come straight out with a non-technical answer to something like “what’s the best way to backup all my files?”, except that there is a really really simple way to do this.
Backblaze is a backup-to-the-cloud service which costs $5 a month for unlimited backups. It deals with external hard drives, duplicate files, etc etc and requires zero configuration. Simply install and you’re done. Thoroughly recommended.
Using “dig” you can determine what IP address or CNAME your domain is pointing to quite easily. However what I didn’t know was that you can actually check what the root server thinks your domain is pointing at, so you can check if its set correctly when you are migrating to a new IP address.
To do this, simply type:
dig domaintolookup.com +trace
This is really easy, but something I never knew until I just tried this:
You’re done! Best Excel trick ever!
This is a simple process, however not something I could find documented anywhere easy to find. MAMP supplies you with a range of sample configuration files:
/Applications/MAMP/Library/share/mysql/my-huge.cnf /Applications/MAMP/Library/share/mysql/my-innodb-heavy-4G.cnf /Applications/MAMP/Library/share/mysql/my-large.cnf /Applications/MAMP/Library/share/mysql/my-medium.cnf /Applications/MAMP/Library/share/mysql/my-small.cnf
To setup one of these for MAMP, simply issue the following command:
sudo cp /Applications/MAMP/Library/share/mysql/my-choicehere.cnf /Applications/MAMP/Library/my.cnf
Here’s a simple code snippet for converting a UIImage to a greyscale equivalent:
-(UIImage *) convertToGreyscale:(UIImage *)i {
int kRed = 1;
int kGreen = 2;
int kBlue = 4;
int colors = kGreen;
int m_width = i.size.width;
int m_height = i.size.height;
uint32_t *rgbImage = (uint32_t *) malloc(m_width * m_height * sizeof(uint32_t));
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(rgbImage, m_width, m_height, 8, m_width * 4, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetShouldAntialias(context, NO);
CGContextDrawImage(context, CGRectMake(0, 0, m_width, m_height), [i CGImage]);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
// now convert to grayscale
uint8_t *m_imageData = (uint8_t *) malloc(m_width * m_height);
for(int y = 0; y < m_height; y++) {
for(int x = 0; x < m_width; x++) {
uint32_t rgbPixel=rgbImage[y*m_width+x];
uint32_t sum=0,count=0;
if (colors & kRed) {sum += (rgbPixel>>24)&255; count++;}
if (colors & kGreen) {sum += (rgbPixel>>16)&255; count++;}
if (colors & kBlue) {sum += (rgbPixel>>8)&255; count++;}
m_imageData[y*m_width+x]=sum/count;
}
}
free(rgbImage);
// convert from a gray scale image back into a UIImage
uint8_t *result = (uint8_t *) calloc(m_width * m_height *sizeof(uint32_t), 1);
// process the image back to rgb
for(int i = 0; i < m_height * m_width; i++) {
result[i*4]=0;
int val=m_imageData[i];
result[i*4+1]=val;
result[i*4+2]=val;
result[i*4+3]=val;
}
// create a UIImage
colorSpace = CGColorSpaceCreateDeviceRGB();
context = CGBitmapContextCreate(result, m_width, m_height, 8, m_width * sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
CGImageRef image = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIImage *resultUIImage = [UIImage imageWithCGImage:image];
CGImageRelease(image);
// make sure the data will be released by giving it to an autoreleased NSData
[NSData dataWithBytesNoCopy:result length:m_width * m_height];
return resultUIImage;
}
Thanks to the friendly people at StackOverflow.com for this snipet.
Recently I was involved in a podcast regarding the iPhone OS 3.0 upgrade. We looked at all the new features (and some upcoming ones in v3.1) and discussed how they relate to new features clients can develop in their apps.
You can hear more here:
So you’ve created a pretty Google Map on your website. You place a whole heap of markers on your map, driven from data you’ve got stored in your database.
A nice thing to do when we first show the map, would be to ensure that all the markers are visible on the map.
To do this, we need to set the zoom level and center point of the map dynamically. So how do we do this? The answer is GLatLngBounds():
// Get your locations from the database
var mapLocations = <? echo json_encode(Locations::Find()) ?>;
// Initialise our map, add some controls and a default center point
var map = new GMap2(document.getElementById("Mall_Map"));
map.setCenter(new GLatLng(15, 20), 2);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
// Now the fun part - create a GLatLngBounds object
var bounds = new GLatLngBounds();
//
for (var i=0; i<mapLocations.length; i++)
{
var location = mapLocations[i];
var point = new GLatLng(location.Latitude, location.Longitude);
// createMarker() is a custom function which returns a marker for a given GLatLng
var marker = createMarker(point);
// extend our bounds to include this point
bounds.extend(point);
// add our marker
map.addOverlay(marker);
}
// Now dynamically set the center and zoom level for our map based on our bounds!
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
The key is the use of the line:
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
This uses our bounds (which we’ve dynamically extended to include each of our points) to determine what the center and bounds zoome level should be.
Okay, so you’ve accidentally adding a bunch of files to SVN. Or, you need to copy a bunch of files but you don’t want to take the .svn folders with you. How to get rid of these? On any *nix machine (Mac included) you can run the following command:
rm -rf `find . -type d -name .svn`