Skip to main content


Showing posts from December, 2011

Power of PHP: Reuse code with classes

Last time we looked at how PHP could be used to add hyperlinks to text URLs. Now this is something that could be really handy and that we might reuse over and over again. So let's save it as a class. For transparency this will be a separate file called livetext.php and it will be saved in a subfolder called 'classes'. This is what the class looks like in its entirety: <?php class liveText { function addHyperlinksToURLs ($data){ $patterns = array('/(http:\/\/|https:\/\/)/','/([a-zA-Z0-9\-\.]+ \.)(com|||org|net|mil|edu|CO.UK|ORG.UK|COM|ORG|NET|MIL|EDU) (\/.[A-Za-z0-9\.&%\/-]{1,}|)/'); $replace = array('','<a href="http://\0">\0</a>'); echo preg_replace($patterns, $replace, $data); } } ?> It consists of a single function and this does all the work. So that's it for this class. Now when we want to use it, we first of all include it with the line: include ("classes/

Remove .DS_Store files from ePUB files

I've found that since upgrading to Lion OS X .DS_Store files have been inserting themselves into ePUBs when they are zipped, and I don't think I'm alone. To erase these use the following command from within the folder containing the ePUB (changing "filename" to the name of your file): zip -d filename.epub `unzip -l filename.epub | grep .DS_Store | awk '{print $4}'` The solution is essentially the one provided by Meitar Moscovitz to remove .DS_Store files from ZIP files, since ePUBs are renamed ZIP files.

Power of PHP: Make live all web address URLs

I've been considering posting some PHP coding tips and tricks. Here's a little one to get things started. If it's popular then I'll follow up with some more in the New Year. <?php $data ="To learn more about programming iOS apps you can visit directly or search for it on Google at"; $patterns = array('/(http:\/\/|https:\/\/)/','/([a-zA-Z0-9\-\.]+\.)(com|||org|net|mil|edu|CO.UK|ORG.UK|COM|ORG|NET|MIL|EDU)(\/.[A-Za-z0-9\.&%\/-]{1,}|)/'); $replace = array('','<a href="http://\0">\0</a>'); echo preg_replace($patterns, $replace, $data); ?> This code takes a variable $data, which can be changed to any text and then finds the URLs and converts them into hyperlinked text using preg_replace. It doesn't matter whether they begin http:// or www. but it isn't a complete implementation because

Working for the Elves

I'm breaking off from the blog for Christmas, but before I go there's one thing that I want to tell you about, and that's a book called The Waking Prince . It has just gone live on the iBookstore, and is a fabulous fully-illustrated fixed-layout iBook that I was lucky enough to work on in the role of eProduction editor. The Story Elves are a committed team. The book has been illustrated by the amazing Scott Brundage  and the story written by Zoe Roizen Soane. Book design is by Alexis Roizen, and additional editing and story ideas come from Joseph Hefta. It is a book for all ages and I highly recommend. You can grab a copy by following this link  where you can also download the free extended sample. I'd also recommend taking time to visit the Story Elves website , especially if you have children, because the site is all about inspiring children to write and draw, and with it improving the way that these skills are taught in schools, while also plugging a gap betw

Xcode from scratch for scaredy cats: Sharing variables between methods in the same class

Note: If this is the first post in the series you have read, you'll first need to follow steps 1-5 in this blogpost  to create the Xcode Project and also read this post on the insertion of code in an iOS app. We can set an instance variable and use it within a method. For example if we created a New Project of the type Single View Application called Variable with a class prefix Variable, then in the VariableViewController.m file we could write -(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSString *prop = @"hello"; NSLog(@"%@", prop); } This would work fine and the app would return the expected result (the word "hello" displayed in the console, which pops opens at the foot of your Xcode window when the Simulator is running). But suppose we want to set the value of the NSString in viewDidLoad but then read this value out in another method, for example when the device

Finding droppings: WiFi on iMac and Android with Belkin Router

Note: This is a personal finding and not a comprehensive guide. I've found that newer Macs and Android share something. While older Macs seem capable of selecting their security settings from WPA or WPA2 or a conjoined WPA/WPA2 setting, newer Macs and Android appear to have one conjoined WPA/WPA2 setting. Now, the Belkin router that I use lets me select under its Security settings WPA-PSK or WPA2-PSK or WPA-PSK + WPA2-PSK. The final setting seems to work fine with all computers but the newer Mac, which was struggling to reconnect after sleep. Changing the setting to WPA2-PSK and manually setting IP addresses fixed this, but then an Android (v.2.2.1) phone refused to connect. Finally, I set the router to WPA-PSK and all on the network were happy. More on configuring wireless security on a Belkin Router can be found here .

Restore lost iOS data using Time Machine

Note: This article will only apply to you if you use Time Machine on OS X Lion to backup your system, and your device is backed up to your computer not the iCloud It is possible that when iTunes is syncing with an iPad it can hang or that a power cut or a force quit situation, or perhaps an update, has deleted some of the data that resides on your iPad local to the apps. I had this recently and found an answer on the Internet to my woes. I don't have a link to that article - it was on the iPad with the data that I reset (so the page history in Safari was lost for that day!) - but I can remember the steps, and will explain all here. The data for iOS apps - when you sync with your Mac - resides in a folder inside your User folder (i.e. Macintosh HD -> Users -> Your User Name -> Library -> Application Support -> MobileSync -> Backup). This folder is inside your personal Library folder, but you won't see the Library folder in Lion OS X because Apple have hid

Confessions of an Xcode scaredy cat

Before we proceed with this series of Xcode for iOS posts, I want to make clear the motivation behind them. Something that I'll be doing here as a stop gap between last week 's post and the next one. First and foremost, it is important to point out that I am not putting myself forward as an expert in programming Xcode for iOS. I am instead someone interested in becoming more proficient in coding for the platform. The motivation behind the "Xcode from scratch for scaredy cats" series, therefore, is somewhat self-centred, because in constructing the posts I am forcing myself to think in clear terms about the writing of code for iOS, and become better. But there is another reason as well, and that is because I wanted to help people like me who needed a foothold to start climbing the Xcode mountain. Although there are many excellent sites and tutorials for learning Xcode, as a beginner I all too often found that a long time was spent on explaining the user interf