How to generate test data for a web application

Fake personal details for unit tests

I’ve coded my fair share of websites that require user authentications in some form or another. Often, you’ll need to test registration forms, user details, billing/delivery address, foreign characters and all kinds of fluff related to user accounts.

Most of the time, this will be ‘user test’, ‘test1’, ‘test2’, ‘aaa’, ‘foo’, ‘123’. Sound familiar?

Sometimes you need believable information, either for testing purposes (fuzzy unit tests anyone?) or to show as a placeholder for real data on a website design. I’ve found the Faker PHP library is perfect for generating this kind of data.

Faker can generate a wide variety of testing data for your web application. This includes:

  • names
  • addresses
  • telephone numbers
  • companies
  • email addresses
  • websites
  • lorem ipsum
  • images
  • catch phrases
  • credit/debit card details
  • date times
  • user agents
  • colours

Its very easy to use as well. At its simplest, just include the library, instantiate its main class, and access its sensibly named attributes. It returns a string result as you’d expect.

require_once '/path/to/Faker/src/autoload.php';
$faker = Faker\Factory::create();

echo $faker->name;
echo $faker->address;
echo $faker->text; // lorem ipsum text

// Generate multiple different names
for ($i=0; $i < 10; $i++)
    echo $faker->name, "\n";

I’ve found this very useful. Take a look at the Faker GitHub pages.

PHP Optimisation Tricks & Tips

PHP optimisation stop watch

PHP may not be well known for being a fast and super efficient language, however there are plenty of tips and you can learn to make your heavily looped code somewhat more speedy.

Sometimes how to code your PHP in an optimised manner is be obvious, while other times you can be uncertain. In many cases, it can be truly unexpected which method of coding certain functionality is actually the most efficient.

I recently found the following very interesting article and PHP benchmarking tool. Take a look  for optimisations tricks and benchmarking of common PHP code snippets.

  • PHP Optimisation Tricks – This article describes a bunch of smaller tricks that can help make code run a little faster. In many cases, this can be useful when code is running many, many times within a loop. Please be aware that although some of these optimisation speed up the running of your code, some of them are unsightly and no where near as readable that more standard ways of coding. Some of the more bizarre optimisations should therefore be used sparingly and one could say, only when optimisation is needed.
  • The PHP Benchmark – runs many different code snippets in large loops. This allows visitors to easily compare the efficient of certain ways of coding the same type of functionality.  This is very interesting as a simple comparison, but it is worth being aware that due to PHP garbage collection and Zend optimisations results can vary. It is worth refreshing several times to see how/if the results change.

Bitcoin Helper 0.1 – Converting currencies to Bitcoin

Over the past few months, I’ve gained quite an interest in the crypto-currency Bitcoin.

Bitcoin is a new currency which has no physical form, but can be considered Internet cash. If you want more information on Bitcoin in general, take a look at the We Use Coins website, which has a great introductory video and articles/links to other useful Bitcoin resources.

Bitcoin Helper 0.1 Released

As part of my interest in Bitcoin, I’ve decided to start a mini-project in the form of Bitcoin Helper, a PHP class which will contain multiple methods to aid web site/application developers in integrating Bitcoin related functionality into their systems. The first function, which comes in Bitcoin Helper 0.1, is a really easy to use converter that can convert non Bitcoin currencies into the equivalent Bitcoin value and return the result.

To see how simple it is to use, see the following code snippet.

include "bitcoin_helper.php";
$bh = new bitcoin_helper;
echo $bh->convert_to_btc("GBP", 10);

This will convert £10 (Great British Pounds) into Bitcoin and echo out the result. The following works for USD and Euros as well.

echo $bh->convert_to_btc("USD", 10);
echo $bh->convert_to_btc("EUR", 10);

The trade data for several other currencies is provided from the external source (see the Bitcoin Charts website). If your currency is listed there, entering its ISO 4217 currency code as the first parameter of the convert_to_btc function should allow you to convert any value of that currency into Bitcoin.

Please note that this is the first release of Bitcoin Helper, so I can not guarantee it is bug free. More checks, validation, improvements and new features will be added in the future versions. Feel free to leave a comment with any suggestions.

I hope this very basic Bitcoin Helper release can assist web developers with some simple Bitcoin conversion in their sites.

Download Bitcoin Helper 0.1

To download this first version of Bitcoin Helper (0.1), please visit the Bitcoin Helper project page.

Imagine turning on your computer to read a newspaper…

This is a report about what it will be like in ‘the future’, when we will be reading news from our computer. This is ‘newspapers by computer’.

It is truly awesome to see how far we have come in terms of the Internet and networking computer communication. It is also slightly amusing to see how out of the loop the media was only 30 years ago, and more specifically how they did not, immediately, see the huge potential of networked computers, and how these system could possibly affect home computer users in very near the future.

How to View Saved Threads on reddit

reddit alien logoI’m a huge fan of reddit, the social bookmarking/community website found here. One of the features you have as a registered user is to save threads.

I feel like a completely moron but I’d never been able to find out where these saved threads were listed until today, when I looked it up. Apparently I am not the only one who has trouble finding it. Many people, including myself, went to my account/profile page on reddit and looked for a ‘saved’ tab of some sorts. It turns out this is not where the saved threads are listed at all.

The link to view saved threads is not stored in your user section, but is shown on the homepage (how did I miss it?) or on the individual subreddit pages. See my screenshot below.

Screenshot of 'saved' link on reddit

I hope this helps a few people like me, who were looking in completely the wrong place for this link. 🙂

“The Simple Purpose of Sharing”

Wikimedia Foundation logoAbout this time last year, Wikipedia requested donations and given how much I use the site, I donated and gave the cause a little bit of promotion. It makes sense.

Coming back to this year, an appeal from the Wikipedia founder Jimmy Wales has recently gone out. I’ve quoted a part of it below.

I got a lot of funny looks ten years ago when I started talking to people about Wikipedia.

Let’s just say some of the business types were skeptical of the notion that volunteers from all across the world could come together to create a remarkable pool of human knowledge – all for the simple purpose of sharing.

No ads. No profits. No agenda.

A decade after its founding, more than 380 million people use Wikipedia and its sister sites every month – almost a third of the Internet-connected world.

It is the 5th most popular website in the world. The other four have been built and maintained with billions of dollars in investment, huge corporate staffs and relentless marketing.

But, Wikipedia isn’t anything like a commercial website. It is a community creation, written by volunteers making one entry at a time. You are part of our community. And I’m writing today to ask you to protect and sustain Wikipedia.

Together, we can keep it free of charge and free of advertising. We can keep it open – you can use the information in Wikipedia any way you want. We can keep it growing – spreading knowledge everywhere, and inviting participation from everyone.

Each year at this time, we reach out to ask you and others all across the Wikimedia community to help sustain our joint enterprise with a modest donation of £20, £35, £50 or more.

If you value Wikipedia as a source of information – and a source of inspiration – I hope you’ll choose to act right now.

Jimmy Wales, Wikipedia Founder

Naturally, I’m donating again. A £50.00 GBP donation to Wikipedia and Wikimedia UK this time.

I encourage anybody who uses Wikipedia significantly, to put forward a donation, of any amount, if at all possible.

Reducing the pain of reinstalling Windows with Ninite

Ninite Installer screenshot

I’m not a Windows user primarily. The vast majority of time my computers and laptop boot into Linux, specifically Ubuntu, as of recent. However, I do have several of my machines set-up with both Ubuntu and Windows 7.

One of my major gripes with Windows, which has always been there, is that after a clean reinstall, you have no programs of any real use installed at all. In comparison, a clean install of Ubuntu gives you a graphics editor, photo manager, fully featured e-mail client, personal information management suite and a full office suite. Of course, you now get the Ubuntu Software Centre, which lets you install find and install full size applications with the same ease as using the iPhone App store or Android Marketplace.

Windows has none of this. A brand spanking new Windows install does very little for productivity without a few essential apps installed.

Usually this involves the labourious task of:

  1. Manually searching for and/or heading to the website of the program you want to download
  2. Finding the current version/build to download, starting the download and waiting for the download to complete
  3. Running the installer and waiting for its completion
  4. Repeat steps 1 – 3 for every program you wish to install

Recently, I’ve discovered Ninite, which is a fantastic website/program which lets you cut down the above procedure (which could possible take hours) to a quick procedure that takes a few minutes at most. This is how you’d do the above, with Ninite.

  1. Go to and select the programs you want to install.
  2. Download the installer it generates
  3. Run the installer and wait for its completion.

And then you’re done! No repetition, as Ninite cleverly puts the installation of many, many possible programs behind a single simplistic installer.

It supports installation for the most popular web browsers, messaging applications, media players, imaging programs, document editors/viewers, security software (such as anti-virus and anti-malware software), plug-ins (such as Flash and Java), file sharing applications, general utilities and even certain developer/administration tools.

Basically, after every (annoying) reinstall of Windows that I have to do, the first place I’m heading is to Ninite’s website.

As a final note, I’m really hoping they add official graphics drivers to their list of automatically installed items. That would be very useful for a lot of people I know. Suggesting new apps is a feature they offer right at the bottom of the Ninite website.

How HTML 5 Geolocation could be exploited

HTML 5 Geolocation Icon

Update: Although geolocation is commonly referenced when discussing HTML 5, it is a API which is maintained in a separate specification and is not actually a new feature of HTML 5.

Identifying the physical location of a computer via HTML 5’s geolocation is now incredibly easy and only requires a few lines of JavaScript.

Due to the simplicity of geolocation and its ever growing support in modern browsers, it seems very probable that this could be exploited for malicious purposes. An example scenario of how malware could theoretically track the physical location of infected machine could be as follows.

  1. Malware infects system and becomes memory resident.
  2. Malware adds malicious website URL to a local web browser’s HTML 5 geolocation white list.
  3. Malware launches hidden/backgrounded instance of web browser, navigating to malicious website URL.
  4. Malicious website JavaScript utilises HTML 5 geolocation services to track physical location.
  5. Physical location is relayed to server via AJAX or other means.
  6. Steps 4 and 5 can be repeated as part of a loop containing time delay within the malicious website’s JavaScript.
  7. Malware can monitor the memory resident state of the browser within the system’s process list and restart the hidden/backgrounded web browser instance if required.

In this example, the geolocation is all done via a local hidden user agent (web browser) using web technologies. The web part of the system, by its very nature, multi-platform. However, the initial piece of malware which launches the hidden web browser instance will likely be written in a platform specific manner.

Changing this, or writing multiple versions of the ‘browser launcher’ malware would effectively generate a form of malware which could track the physical location of users regardless of their operating system.

Do you think this kind of malware is a reasonable threat now or in the near future? What other potential problems exist for devices that can be identified by geolocation technologies?