Archive for the ‘Computers & Internet’ category

Fixing other people’s code

March 10th, 2009

Well I’ve spent a very productive afternoon fixing CSS bugs in jQuery UI http://jqueryui.com, to make a very specific set of conditions work under Internet Explorer.

If you’re interested, basicaly putting an overflow inside the dialog overlow causes the first overflow to render incorrectly if the positions are relative.

The great thing, though about the open source community is I can now help my fellow programmers by submitting my findings (and fixes) back to the UI dev team.

This is where I have mixed feelings about open source, as in GPL style open source. If I write software as a sole developer what can I realistically offer than a small amount of support in addition to effectively giving my code away for free to anyone who buys a licence. Then for them to be able to resell it and I don’t make money anymore.

The GPL is great for big projects or simply hobbies but it isn’t all that great for sole developers. I much prefercthr method of giving source with the application but don’t give distribution rights away.

Two days with PDO and my lack of faith in the PHP extension developers

February 25th, 2009

OK let me first start by saying, I absolutely love PHP, I tend to compile my PHP from source and for the most part have absolutely no issues with it whatsoever.

Now for work I needed to install PDO extensions to PHP with Microsoft SQL Server support (PDO_DBLIB). I shall also start off by saying that I currently use the standard sqlite extensions to PHP.

Now PDO is actually available on Linux as pdo.so in the modules directory usually by default so let’s actually just try to run

pecl install pdo_dblib

Can’t do that we get the error

“pear/PDO_DBLIB requires PHP extension “pdo” (version >= 1.0)”

OK well we had PDO installed but clearly the wrong version.  First up I recompiled PHP adding in the following configuration lines

–with-zlib –enable-pdo=shared –with-pdo-sqlite=shared –with-sqlite=shared

I actually already had zlib compiled, I just reference it here as it’s required. That all worked great, without errors.  So now let’s run

pecl install pdo

we should get the right version, correct?  No we still get the same error.  This led me to the following bug report.  Note that this bug was opened in May 2006 and is still unsolved at the time of writing.  What we have to do is manually download the package, edit package.xml and remove the PDO dependency line.  Install as usual and restart apache!

These are the steps that work

pecl download pdo_dblib

This will download a tar ball of the extension. Extract the tar ball.

tar -xzvf PDO_DBLIB-*.tgz

That will uncompress the package in to a standalone file, package.xml
and a folder containing the extension, in my case it was, PDO_DBLIB-X.X.
Where X was the version number. Open package.xml using your favourite
command line editor. Find and remove the line,

<dep type=”ext” rel=”ge” version=”1.0″>pdo</dep>

Save the package.xml file, and move it in to the PDO_DBLIB directory.

mv package.xml ./PDO_DBLIB-X.X

Navigate to the PDO_DBLIB directory, then install the package from the
directory. You may need root access for this step.

cd ./PDO_DBLIB-XX

pecl install package.xml

After editing php.ini to load

extension=pdo.so
extension=pdo_dblib.so

phpinfo() reported that the DBLib driver was available as was PDO, all was great. Now I tried to run sqlite_open and it refused to work.

I thought maybe it was the pdo sqlite extension that was conflicting, as I don’t actually use the pdo version of sqlite, just the main function library I decided to reconfigure php without the sqlite options.

Then I get an error saying that I had configured PDO as a shared object but sqlite was static.  Hmm the PHP manual tells me something different though and I quote

In PHP 5, the SQLite extension and the engine itself are bundled and compiled by default. However, since PHP 5.1.0 you need to manually activate the extension in php.ini (because it is now bundled as shared). Moreover, since PHP 5.1.0 SQLite depends on PDO it must be enabled too, by adding the following lines to php.ini (in order):

So this is telling me that SQLite is enabled by default and is installed as shared.  Well the PHP installer just told me different, that it’s installed by default but as static!

OK so back to configure PHP again but this time with the sqlite shared options.  Then we’ll reference sqlite.so in the php.ini extensions and restart apache!

Oh no we can’t load apache because the version of sqlite.so is incompatible with the version we need for pdo_dblib.so.

Let us run

pecl install sqlite

Running that gives us the following error

tmp/tmp8laqB1/SQLite-1.0.3/sqlite.c:125: warning: initialization from
incompatible pointer type
/tmp/tmp8laqB1/SQLite-1.0.3/sqlite.c:126: warning: initialization from
incompatible pointer type
*** Error code 1
make: Fatal error: Command failed for target `sqlite.lo’
ERROR: `make’ failed

The PHP bug report at http://pecl.php.net/bugs/bug.php?id=8181 that was opened in July 2006 tells us this has all been fixed, but with numerous responses telling the developers that it’s still broken.  At the time of writing, this is still broken!

This then leads me to the following fix

$ pear download sqlite
then unpacked and began to compile it
$ tar zxvf SQLite-1.0.3.tgz
$ cd SQLite-1.0.3
$ phpize
$ ./configure
$ make

edit sqlite.c, comment out the following line:
/* static unsigned char arg3_force_ref[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; */

And then change these lines
function_entry sqlite_functions[] = {
PHP_FE(sqlite_open, arg3_force_ref)
PHP_FE(sqlite_popen, arg3_force_ref)
to:
function_entry sqlite_functions[] = {
PHP_FE(sqlite_open, third_arg_force_ref)
PHP_FE(sqlite_popen, third_arg_force_ref)

$ make
$ make install
$ cp modules/sqlite.so /usr/lib/php/modules
$ /sbin/service/httpd restart

Why oh why do I have to edit the c source code to get this working?   Which by the way DOES actually fix the problem and now I have PDO, SQLite and PDO_DBLIB working on the same system.

This is why I’m starting to loose faith in the open source PHP community, not because they do a great job in the first place, but because bugs like this exist for well over 2 years!

The response from the Open Source community will be, fix it yourself.  That simply isn’t the point, I’m not a C developer, nor do I have the inclination to be.  I also do not know the inner C workings of PHP to easily fix these issues.

I’ve just wasted two days of my life researching, testing, debugging PHP extensions, I hope it helps anyone else with these issues!

Choosing a hosting provider

January 30th, 2009

Always a bit daunting and a question I’m often asked. ‘I want a website but where do I host it’?

A quick Google search will reveal thousands of companies (and the 12 Google Adwords results) and 10′s of different options.

A web developer looking to publish a website will most likely be even more confused when doing a search, instead of finding a good web hosting provider highlighted by the search engine.

The reason is very simple many individuals and companies, small and big, have seen the opportunities in web hosting.  Indeed even I partnered with a friend a number of years back to sell space on one of my dedicated servers… it was space going to spare why not make some money from it?  Of course responsibility and support needs come with that and that is the reason I stopped offering it as I had too much real work to do!

The result of this saw new web hosting providers created overnight, to go with this there is now a plethora of forums, ‘reviews’ sites, publications and middle parties, mixed with an entire array of web hosting products, from free hosting to powerful dedicated or co-located servers.

Now I’m not going to recommend any specific providers, even the ones that currently host my site but to try to explain the options available.

Free Web Hosting

Unless you have a personal website, you should never look for free web hosting.  Sorry you just shouldn’t, unless that is your experimenting and testing code or are willing to be at the whim of a company that can delete, loose your website without any guarantees from the provider themselves.

Companies that offer free hosting tend to do it for the following reasons:

  • they will recoup their costs back by inserting ads on your website or
  • they are providing Internet for you, and offer you a ‘free web space’ and free email, as part of their Internet package, so it’s not truely free anyway

Putting ads outside your control on your own website can be irrelevant and obtrusive  and won’t make your website appear credible. Those webpages are as credible a myspace page, and are just useful to host a couple of images and html pages.

As for Internet Hosting Providers, their free web hosting service is often tied to your subscription. This means that as soon as you stop doing business with them, the free web space is most likely to be deleted or at the very least you will no longer have access to it for updating your site.

Shared Web Hosting or ‘Cheap’ Web Hosting

Cheap web hosting is almost always shared web hosting.  A shared web host is where you get a little bit of space on a larger powerful server.  Shared hosting is very common amongst websites online.  Pricing ranges from just over $1 to over $30 (it is common for many web hosts to change in US $ even if they aren’t based in the US!).

They offer a huge array of options from PHP to .NET to OSCommerce to PHPBB.

Here is what you should look for in shared hosting:

  • Web Technologies supported. If you are looking to open up a wordpress blog, you need obviously to make sure that the shared plan has PHP and MySQL. Same for Ruby On Rails applications, or .NET shared hosting. This criteria is probably the most important since there’s no use finding a cheap web hosting provider if it won’t run your website. Here’s a possible list of what to look for: programming languages, database, web server software installed, cron jobs, domain name tools, etc.
  • Number of users hosted on a single machine. The total number of users directly affects the speed of your website, and there are lots of providers who overload their servers. To gauge this number, ask for a list of active and fairly big websites under their shared web hosting plan, and see if the websites are running well.   They may not be able to divulge the exact domains running but they should be able to give you and idea of how many sites.
  • Price and possible discounts. Many companies offer deals and discounts at specific periods so shop around.
  • Support and Guarantees. Lastly, doing business with a web hosting company is mostly a long-term relationship, as it is a huge hassle moving hosting providers, especially when it comes to moving all your domains and IP addresses, etc. You might find a great deal, from a new unknown provider, but what you need to make sure is that this company is reliable, that they will still be there one year from now; and there will be someone listening to you if you are having a technical problem with your website.  Looking for well used support forums and live chat capabilities from your provider are good indicators.

Dedicated Servers or ‘Virtual Private Servers’

You can look for a VPS (virtual private server) or a dedicated server if you are a small or large company serious about your web presence, if you are a web developer who need performance and greater control of your web server, or if you plan to host an entire array of websites, either your own, or your clients’.

Here are the advantages for virtual private servers offerings:

  • it’s often cheaper (although not always) than dedicated servers
  • provisioning is usually automated, on-demand and quick, which is good for web developers looking for a hassle-free experience or quick deployment of their server infrastructure.  You can have your server ready for your to load your sites on in minutes.
  • billing can be done hourly, which can be a key business argument for startups and companies alike,
  • you get SSH access and a control panel (Plesk or cPanel), which is often enough for your needs.

Here are the advantages for dedicated servers offers:

  • you can get customized servers, fine-tuned to your needs, such as the exact quantity of RAM, the right CPU, network speed, required bandwidth etc. You can order a RAID hardware setup for instance, which is impossible for a VPS. Need more RAM than processing power? it’s possible. Do you prefer AMD chips instead of Intels? Just order it in the form.
  • you can setup advanced configurations for your technology infrastructure, by setting up firewalls, web clusters, load-balancers, anti-DDOS solutions, etc., which is again, impossible for a VPS
  • you don’t have to design advanced backup solutions, since your dedicated server is physical and your data won’t evaporate one day, which is the case for VPSs. Of course you still need to consider backups but it’s just the same as backing up your home computer, just make sure you do it!
  • a dedicated server can be cheaper than many purchased virtual servers, if you use virtualization software such as Virtuozzo or VMWare. For example, by virtualizing your dedicated server, you can have one instance as the web server, another instance as the database server, another instance for cache.
  • You have 100% control of your server. The web hosting provider cannot for instance offer CPU or RAM bursts to other users, so performance will be equal and guaranteed any time of the year.

In my opinion the biggest advanced of dedicated vs VPS is that there are known ways to secure your data, whereas data tampering is a real issue in cloud computing.

Here are the main points you should look for when choosing the best web hosting providers for your dedicated or virtual server:

  1. Assess if the company owns their data center, or if they are a reseller who are in fact hosting their server in another company. Look for a physical address, phone lines, network details. Of course, it’s better to do business with a company which runs its own data center. It’s not only about the price, but the guarantee that there will be personel who will physically fix servers when the need arises, know their own equipment and hardware inside out and have a quick turnaround
  2. Price of your desired configuration, and price of hardware parts and software, both the setup and monthly costs
  3. Path to scalability, such as availability of more powerful configurations
  4. Quality of network, which can be done with traceroutes, pings or by testing various websites hosted there
  5. Reliability and trustworthiness. See for instance how many years the company has been in business. For instance, a company which has been operating for more than 10 years means it is unlikely to disappear overnight. Also, a company which has a open blogs and forums is more trustworthy than another web hosting company which doesn’t offer a place for its users to collaborate and exchange.  A lack of a forum could also indicate the company doesn’t have many customers.
  6. Support. Assess if the company’s support is responsive, if there are customer complaints on the company’s forum.

As stated in the shared hosting section, don’t forget that doing business with a web hosting company is above all a long-term relationship. Please don’t judge purely on the price, choose most of all a company you can trust.

If anyone is interested my site is hosted on a dedicated server by iWeb in Canada after a disasterous experience with The Planet when their datacentre had their power transformer explode!  It’s running CentOS and sitting on a 100Mb/s port so network speed won’t be an issue.

A weekend of XBox 360

January 18th, 2009

XBox 360You can’t argue with spending a day of playing on the XBox 360, well you can but I enjoyed it!

So I’ve been playing with a few new games recently.  Now I often find it very hard to get into a game longer than a few plays, and indeed in the past the only two that have really gripped me are Call of Duty 4: Modern Warfare and Tom Clancy’s Rainbow Six Vegas.

So I’ve been playing recently Tom Clancy’s Rainbow Six Vegas 2, 007 Quantum of Solace, WWE Smackdown vs Raw 2009, Call of Duty: World at War and Need for Speed Pro-Street.

So I’ve already got bored with Need for Speed and Rainbow Six Vegas 2.  Call of Duty: WaW had me gripped for a few weeks, especially as I leveled up to the max during the beta, but now that’s bored me.

007 and WWE I’m enjoying in single player mode very much at the moment, but for XBox Live, I keep being drawn back to CoD4 for some reason.  Bring on Call of Duty: Modern Warefare 2 in the autumn (fall for any US readers).

So this weekend I’ve managed to up my gamer score by about 500 and up my CoD4 level to 49 Prestige 2, that was until either BT or XBox Live decided that the Internet was something that should run at 28.8kbs again.

Some cool tips and tricks for the iPhone SDK

December 21st, 2008

During the course of developing my latest iPhone application (currently awaiting approval from Apple) I solved a number of issues I’ve had in previous attempts but I’ve finally solved them.  Apologies to anyone reading this that thinks, derrr I’ve known this for ages, but hopefully it’ll help some developers with their iPhone applications.

1) Updating the main UI from a thread.

If you call a function using a thread

[NSThread detachNewThreadSelector:@selector(getXML) toTarget:self withObject:nil];

then you might want to update the main user interface e.g. to display a status on a toolbar.  Well as it turns out the thread is protected and can’t access the main ui whilst the thread is running.  The way to solve this is using the following code

[self performSelectorOnMainThread: @selector(updateBadge) withObject:nil waitUntilDone:NO];

where updateBadge is a function.

2) Changing a refresh button to display a UIActivityIndicatorView on a toolbar
Let’s say we have a toolbar at the bottom of the screen and we’ve added a refresh button e.g.
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(actionRefresh:)];

refreshItem.style = UIBarButtonItemStylePlain;

NSArray *items = [NSArray arrayWithObjects: flexItem, refreshItem, nil];

[toolbar setItems:items animated:NO];

Then by default with that code it would display a refresh button at the right hand side of the toolbar, and when clicking on it would call refreshAction:(id)sender.  To be helpful to the end user we might want to change the refresh button to an activity indicator whilst the refresh action was taking place.

The first job is to make the refresh button and flex item a global property so you can call them from different place.  Now we also need to create a UIActivityIndicator.

When the refresh action starts you can call the following code to display the activity indicator

CGRect frame = CGRectMake(0.0, 0.0, 25.0, 25.0);

UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];

[loading sizeToFit];

loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin);

[loading startAnimating];

UIBarButtonItem *statusInd = [[UIBarButtonItem alloc] initWithCustomView:loading];

statusInd.style = UIBarButtonItemStylePlain;

NSArray *items = [NSArray arrayWithObjects: flexItem, statusInd, nil];

[toolbar setItems:items animated:NO];

Then when the refresh action stops, simply call the following, as we’ve already made flexItem and refreshItem a global property we don’t need to redefine them or re-point them to their action selector.

NSArray *items = [NSArray arrayWithObjects: flexItem, refreshItem, nil];

[toolbar setItems:items animated:NO];
3) How to display an application badge
Now of the three items I discovered this is probably the easiest and it simply the code you need to display the little red badge icon, like the one you see when you have unread email on the mail icon on the home screen.
[UIApplication sharedApplication].applicationIconBadgeNumber = 10;
To hide the badge simply set the value to 0

The dilemma of iPhone Apps

December 6th, 2008

I’m sure other iPhone developers have come up against the same dilemma as me, you come up with what you think is a great idea for a new iPhone Application to perform a quick search on the iTunes App Store and discover that 5 other people have done the same thing.  So the dilemma, do you still write the app because you think you can do better, or do you think of another idea?

Well so far I’ve developed one that I came up with the idea and the same day it got published two others of the same subject did.  For the second idea no one had written an app on this subject yet.  Yet when I came to submit the final code there were three, yet I still submitted because I’d spend enough time working on it.

Now the second dilemma, I’ve got another idea, which obviously I won’t share until I’ve completed it, but do I actually bother as at the time of writing, no one has done this yet, but will they have done by the time I finish coding the application.  Although it will probably only take a fortnight to code.

Heck I’ll probably write it anyway… watch this space!

The simply amazing MacBook Air

December 6th, 2008

Unlike many teccys, I’m neither in the Windows, Mac or Linux camp.  I’m actually in all three.  I love using Linux for web servers, they are simply the best operating system in my opinion for running PHP, MySQL and Apache (otherwise known as LAMP).

I also love Windows Vista.  Controversial some might say, however I have NEVER had a single issue with Vista and it works fantastically for me, it looks great as well!

Now onto the Apple Macs.  My history with macs is both relatively recent and actually quite old at the same time.  I can remember as a kid, my dad bringing one of the early Macs home from work and me playing with the drawing tools.

Now my first mac was an iMac Snow, one of the old CRT screens all in one with a CD drive, running OS X 10.2, then came an iBook G4, followed by a Mac Mini.

Then came the current iMac generation which interestingly also makes my most stable Windows PC to date due to the fantastic BootCamp.

Just before I went on holiday this year i finished my latest iPhone App, called iSki, which shows the snow fall and webcams for all the major ski resorts in the world.  I submitted it to the App Store the day before I left, knowing that it usually takes Apple about a week to two to approve initial submissions of new Apps.

At the end of the second week, the App was rejected due to minor issues and I knew could be fixed in seconds and resubmitted.  

How does this relate to the MacBook Air? Well if I had a Mac with me I could have fixed this issue, resubmitted within minutes rather than waiting a week to get home and then a further week to get it approved (which actually it was).

So the answer for me was either the MacBook or the MacBook Air?  The MacBook is cheaper and more powerful but the MacBook Air is incredibly small and very light.  I almost got a MacBook until I remembered the entire reason for the purchase… portability!  Then I remembered the Apple Refurb Store.

The rest is history, I’m now typing this on my Air and it’s a wonderful bit of kit, if I’d have wanted a desktop replacement I’d have gone for the MacBook Pro, for the portable work system, the Air wins on so many levels for me.

I’m on Twitter

October 30th, 2008

I’m now on Twitter, lots of people seem to constantly talk about it, I still don’t really see the point in it but I’m going to give it a go and see whether I like it or not.

In the mean time you can follow me, although I will not promise that it’ll be exciting or informative, here.

myTube for the iPhone

October 1st, 2008
What is myTube?: Information and navigation of the London Underground network.

Highlights:

  • Tube Status: browse the latest tube status updates, including DLR. Change the look and feel from pre-defined skins.
  • Map: view the London Underground map live on the TfL website and optionally download and save the map to your iPhone for viewing offline
  • Nearest Station: find the nearest Tube or DLR station from your current GPS location, distance and directions over ground
  • Route Planner: whilst overground just select your starting station, your destination and find out how to get there including line changes, then view that route whilst underground
  • Navigation: how to get to or from a Tube station using an address or post code
  • Tourist Attractions: Find attractions near to stations and how to get there overground

This application is designed for usage in connection with the UK London Underground network.

Because of TfL copyright we cannon bundle the Tube map for offline browsing with the application itself. When you use the map it will use the one on TfL’s site, however you can optionally download and save the map for viewing without an Internet connection.

This Application is available from the iTunes App Store.