Author Archives: Glen Scott
My first year as a freelancer developer
I can't quite believe it, but a year has now passed since I started working on a freelance basis. I feel I've learnt a huge amount in this time, so I'd like to share my experiences in the hope that they might be useful to others.
Things that have gone well
The freedom
This was always the aspect that excited me about freelancing -- that of being able to pick and choose work, and decide your own hours. And, by and large, it has worked out as well as I had hoped.
Being able to work on pet projects
I've built up an insane number of ideas for sites and apps over the years, but never had any time or motivation to build them. Now I'm freelancing, I've been able to revisit these ideas and actually build some. I've been able to look at them from a business perspective and decide which ones may actually be able to make some money.
Working from home
Being able to work from home and spend more time with my young son has been fabulous, but it hasn't been without its downsides. It can get pretty lonely at times, but I've made good use of co-working sessions to keep things interesting.
Finding work
On the whole, I have been able to find work when I've needed it. That's not to say it's been simple -- I've certainly not sat back and waited for the work to find me. However, I've been hunting down interesting work through a variety of different methods, some of which are more successful than others. I'll dedicate a future blog post to this subject.
Invoicing and accounting
I don't have an accountant yet, so have needed software to help me through this area. I use FreeAgent for this purpose, and I can thoroughly recommend it.
Things that have not gone so well
Building my own website
It's taken most of the year to get my own site released, but I wanted it up and running much earlier. It's taken so long because I put paid client work, and other pet projects before it.
Working with clients on-site
My preference has always been to work from home wherever possible, but I also recognise the need to work onsite in certain situations -- for example, at the beginning of projects. One mistake I've made is agreeing to work onsite every day for the duration of a project. During this time, I was the only non-permanent employee working in the office, so I felt like an outsider. Furthermore, the client insisted that I used their own hardware and software for developing -- a compromise that I will not make again.
What next?
It's been a fantastic year, and I can't imagine going back to traditional employment. As long as the challenges are keeping me interested, I'll continue down the freelance route. My plan is to grow out from "Glen Scott the Freelancer" to "Glen Scott, the Business" and that will be my focus of my second year.
Out with the old, in with the new
It's been a long time coming, but I've finally got a couple of pages of my new site live. There will be more pages added over the next few weeks, but I thought I'd at least get these out as a starting point.

Let me know what you think, or if you spot any bugs
New site preview
My new site is coming along slowly, but surely. Even though I've had the Photoshop designs for many months (thanks, Jonny!), the actual HTML and CSS build has been quite a challenge. Getting a pixel-perfect representation of the design that works consistently across browsers has been tricky! So, I've made a few compromises along the way but overall am very happy how things are turning out.
Here is a small preview of what will become my new homepage:

I'll be adding content to the other pages and tidying up over the next few weeks before letting it out in the wild. Let me know what you think!
HTML5, character encodings and DOMDocument loadHTML and loadHTMLFile
Whilst working on a script for my GetProThemes app recently, I came across a problem with PHP's loadHTML and loadHTMLFile methods.
The problem
I noticed that when using loadHTMLFile to parse an HTML document, the character encoding -- UTF-8 in this case -- was not being taken into consideration. Because of this, there was some mojibake after I extracted some content from the document. Here is an example of the problem:
$i18n_str = 'Iñtërnâtiônàlizætiøn'; $html = <<<EOS <!doctype html> <head> <meta charset="UTF-8"> <title>html 5 document</title> </head> <body> <h1 id="title">$i18n_str</h1> </body> </html> EOS; $dom = new DOMDocument(); $dom->loadHTML( $html ); echo $dom->getElementById( 'title' )->textContent; // output: Iñtërnâtiônà lizætiøn
After some digging into the PHP source code, I discovered this function, along with loadHTML, uses Libxml for determining the character set of the HTML document automatically. It uses a function named htmlCheckEncoding for this purpose. What this function does is to look for a meta tag declaring the character set. Unfortunately, it only looks for the HTML4 style declaration:
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
This means that if your source document is HTML5, it will not pick up the newer meta tag declaration which has this form:
<meta charset="utf-8">
It seems that this glitch has been fixed in version 2.8.0 of Libxml, but if you are stuck with an older version then I have created a workaround.
The solution
I have created a drop-in replacements for the loadHTML/loadHTMLFile methods which will automatically convert an HTML5 character set declaration, if it exists, into an HTML4 character set declaration and thus allowing Libxml to parse the document correctly.
Fixing the above example is trivial:
require_once 'DOMDocumentCharset.php'; $i18n_str = 'Iñtërnâtiônàlizætiøn'; $html = <<<EOS <!doctype html> <head> <meta charset="UTF-8"> <title>html 5 test</title> </head> <body> <h1 id="title">$i18n_str</h1> </body> </html> EOS; $dom = new DOMDocumentCharset(); $dom->loadHTMLCharset( $html ); echo $dom->getElementById( 'title' )->textContent; // output: Iñtërnâtiônàlizætiøn
So, the fix involves:
1. Including the DOMDocumentCharset class
2. Instantiating DOMDocumentCharset rather than DOMDocument
3. Calling the new loadHTMLCharset method
The class will only activate the workaround if the installed Libxml version is less than 2.8.0, so upgrading Libxml will not break this code.
The source code can be found on GitHub: dom-document-charset
An App in a Day
One thing I've really enjoyed about freelancing is the freedom to work on pet projects. When I have not been working with my paying clients, these projects have kept me busy. The trouble is, I seem to have many -- twenty at the last count -- in a perpetual state of "in progress".
So, today I had some free time and set myself a challenge -- develop and launch a useful web app in 24 hours. I decided to develop a browser for professionally-designed WordPress themes.
This challenge also allowed me to play around with some new technologies. In this case, I chose to use jQuery Masonry for the front-end Pinterest-like display.

The app consists of two main parts:
1. A feed processing script that pulls in popular theme information from Mojo Themes and ThemeForest and saves them into a DB. This script is run via cron to update the themes on a weekly basis.
2. Some frontend logic that pulls out these themes and displays a preview graphic for users to click on.
In the end, I spent around eight hours on the development.
I registered a domain name, set up the hosting, added Google Analytics and affiliate referral codes and uploaded the files. The site can be found here:
It's been a fun day, and I'll be very interested to hear if the site is useful to anyone!
Coming soon: A handy new application for freelancers, contractors and small businesses
Over the last few months, I've been working with Webwings to develop a new web application which we hope will save freelancers, contractors and small businesses a lot of time.
Development has been swift and pain-free thus far, due in part to the choice of CodeIgniter as the framework. It's proven to be an excellent base on which to iterate and incrementally build our product.
We have been alpha testing with a select group of users, and have received very positive feedback. We are aiming to get a beta release out within the next couple of months. If you are interested in participating in this, please leave a comment at the bottom of this page, and I will be in touch.
Updated site coming soon
Over the last few months, I've been working with graphic designer Jonny Tansley on a brand and design for my own site, www.glenscott.co.uk.
It's progressing well, and you can see a small sneak preview of the branding below:

Development of the new site continues, and I will post updates on the blog as it gets closer to launch.
View carriage returns, line feeds and tabs within text files
This is a useful Python one-liner for viewing characters that are usually hidden in text files;
- Carriage returns (shown as \r)
- Line feeds (shown as \n)
- Tabs (shown as \t)
python -c "f = open('filename.txt', 'r'); f.seek(0); file = f.readlines(); print file"
Example output:
['Carriage return and line feed: \r\n', 'Line feed: \n', 'Tab: \t\n']
I recently used this script when trying to work out why a shell script was not executing correctly on a Debian machine -- the reason was some carriage returns inserted by a Windows-based editor.
Securing your CodeIgniter passwords with bcrypt
I've applied a small modification to the Portable PHP password hashing framework, so it can be easily used in CodeIgniter projects. An example of using it to authenticate users:
$this->load->library( 'PasswordHash' );
$query = $this->db->query("
SELECT
`user_id`,`password` AS `hash`
FROM
`user`
WHERE
`username` = ". $this->db->escape($username) ."
LIMIT
1
");
// check to see whether username exists
if ( $query->num_rows() == 1 ) {
$row = $query->row();
if ( $this->passwordhash->CheckPassword( $password, $row->hash ) ) {
return $row->user_id;
}
}
To generate a hashed password:
$this->load->library( 'PasswordHash' );
$password = ( isset( $_POST['password'] ) ? $_POST['password'] : '' );
if ( $password ) {
$hash = $this->passwordhash->HashPassword( $password );
if ( strlen( $hash ) < 20 ) {
exit( "Failed to hash new password" );
}
}
For more details, please check out the repository on GitHub: github.com/glenscott/passwordhash-ci








