Headshot of James Moss

James Moss

I’m a freelance full-stack engineer with over 15 years experience. Currently taking on new React based opportunities, drop me a line 👋

Character encoding headaches

I recently worked on a project with a strange character encoding issue. The application in question was an old CMS system which had originally been developed using a Latin–1 character set both for storing it’s data and in regards to the pages being served by Apache. More recently it had been updated to use UTF8 to eliminate lots of encoding problems which were arising, especially as more non English speaking users started to utilise the system.

There was however an odd issue occurring; the database and it’s tables had been setup correctly to store everything as UTF8; PHP and Apache had been configured to correctly serve UTF8 content and the application itself had been updated to use PHP’s set of [mb_ string functions][]. However when I viewed the database using Navicat it still looked like the data was being stored as Latin–1.

After a bit of digging I discovered that when the connection to the database was being made, [mysql_set_charset()][] wasnt being called which meant PHP was defaulting to Latin–1. I fixed this but in doing so, Latin–1 characters were being displayed as UTF8, and everything ended up looking like a mess. I set about writing a script to fix the data in MySQL and came across this great snippet on stackoverflow:

UPDATE table SET col = CONVERT(CONVERT(CONVERT(col USING latin1) USING binary) using utf8);

I wrote a quick PHP script which iterated over the database ran this query on any text, varchar or char columns and the problem was solved. There are other ways to achieve the same effect which involve dumping the database without any encoding information and then re-importing it, specifying UTF8 but I prefer this approach. As a word of warning, remember to backup any databases before running this. Also be aware if you have a lot of data it could take some time.

Daft Punk helmet Arduino controller code

Now and then it’s nice to step away from web development and work on a project in meatspace. Last year I was lucky enough to help the super talented Harrison Krix program the lights for his Guy Manuel Daft Punk helmet. He was midway through the project and had the electronics nailed down but programming the Arduino board wasn’t his speciality so he got in contact with me after seeing my Guy Man helmet in action. I updated my original code (which used a Rainbowduino) to use Harrison’s Arduino setup, here it is in action:

</param></param></param></param></embed>

Much better than my helmet for sure. I’ve had a few emails recently asking for the source code for this. I’ve chatted with Harrison and he’s happy to make it public so here it is:

DOWNLOAD (Note: requires Arduino Potentiometer library which can be found here)[][]

It’s released under an MIT license so feel free to do what you want with it but make sure you include the license and original attribution if you do decide to re-distribute it.

Unfortunately I don’t have the time to write up a big tutorial on how to use it at the moment or exactly how it works, however the code is fairly well commented so unless you’re a complete newbie you should be able to understand what’s going on. I’ll try to answer any questions if you leave them in the comments. I’d also like to state I’m by no means an Arduino expert so there may be better or faster ways of doing things in the code which I’m not aware of, but it all works. The electronics are detailed over on [Harrison’s blog][] if you’re not already familiar with them.

[]: /src/Guy_Manual_Helmet_LED.zip [Harrison’s blog]: http://volpinprops.blogspot.com/2010/07/daft-punk-final.html

What factors does Google take into account when ranking your site?

The algorithm Google uses to rank your site in its search engine results pages is highly complex and the team who work on it are highly secretive. There are very few who know exactly how it works. The algorithm is often updated and refined which means keeping your site at the top of search results is an ongoing task.

In a recent keynote speech at PubCon, a Google engineer Matt Cutts, revealed that there are roughly 200 different variables which are analysed by the algorithm when it’s deciding where to rank your site. Over at Search Engine Journal, Ann Smarty and her readers are attempting to put together a definitive list of these variables. Of course nobody knows how accurate this list is, however with the input of hundreds of SEO specialists with years of experience it’s very likely that many of the these factors are correct.

Let’s Try to Find All 200 Parameters in Google Algorithm @ SEJ http://www.searchenginejournal.com/200-parameters-in-google-algorithm/15457/

Google Chrome has arrived... and its good!

Today Brian Rakowski announced the launch of Google’s new browser, Chrome. After teasing us yesterday with a great comic book strip explaining what it is, how it works and the ideas behind it they finally opened up downloads at around 8pm(GMT).

The Good

  • Its fast! Websites seems really snappy. Ive yet to run any benchmarks yet but I can see it beating Firefox and Safari in all areas
  • Lightweight. I was a bit unsure of having multiple processes running all over my machine but they seem to managed well. RAM usage can get a bit high with multiple tabs open but with just GMail open its only using 17mb (vs FF3’s 112mb)
  • Standards compliant. It’s got WebKit under the hood so this was expected really.

The bad

  • The installation procedure is awful. Why do I have to download a 500k setup file which then in turn downloads the installation file and extracts it to a random location on my hard drive. Getting installation right is very important as it’s often the first interaction a user will be having with your application.
  • Im running Windows XP and the GUI is some kind of Vista hybrid (just like Windows Live Messenger). Although its fairly minimal it does annoy me.
  • They’ve adopted the IE7 style of doing away with the File, Edit, Help menu and placing it all under one icon. At least give us the option to change it back guys.
  • No “Add to dictionary” feature when you right click on a misspelled word. Bit of an oversight really.

The good points really do outweigh the few bad points mentioned here. I feel guilty dropping Firefox after championing it for so many years but it has become bloated and unstable.

I’ll be looking forward to new updates and plugins over the coming weeks.

Fantastic Contraption

I’m not normally a big fan of Flash games, they tend to either be poorly implemented or lacking scope. This week however, I discovered the brilliant physics based Flash game Fantastic Contraption.

The premise is simple; using a series of different rods and wheels you must build a machine to move a ball into a target zone. You are free to build your machine however you like and because of this the game is extremely open ended.

A user created bulldozer clearing balls out of its
path

By creating a standard account, Fantastic Contraption lets you save your designs and share them with friends as well as browse through other people attempts. After upgrading to a full account (a one-time fee of $10), you are able to create your own levels and share them with others.

Colin Northway and his team have turned a great idea into a well executed puzzler which I highly reccommend.