kenn
Random musings and opinions of a software architect.

Game of Thrones in all its forms

The theme song to game of thrones in all manner of silly renditions. Is this a new thing? Even if it’s not, it’s still funny.

Squeaky Toys Edition

Floppy Drive Edition

Profanity Edition

WARNING: can’t be unheard!

Violin Edition

Maliciously placed here after the profanity edition ;)

On PHP 5.4 and Traits

About a week ago PHP 5.4 was released as stable. It introduces lots of bugfixes and a few new features, the most important of which is traits. Traits are PHP’s answer to multiple inheritance . Traits are not instantiated like normal classes, but instead work much like mixins, defining common functionality which can be “inserted” into concrete classes.
read more »

BitCoin: A Quick Introduction

On the 3rd of January 2009 the first BitCoin block was generated. Back then hardly anyone knew what it was, and the coins definitely weren’t worth anything. However, recently BitCoin has gotten a lot of attention, both good and bad. I first heard about BitCoin on episode 287 of Security Now (YouTube) with Steve Gibson from GRC. In a nutshell, BitCoin is a decentralised, peer-to-peer system, much like BitTottent is, in which money circulate completely anonymously, solely on the agreement of operation between all parties involved.
read more »

Planet Earth on the Desktop

The other day I came across http://die.net/earth, which I thought was one of the coolest ideas I’d seen in a long time. However, there are two problems with it: 1: I don’t feel right downloading his images once every hour, mainly because I wanted it more live than that! (yes, I know there is no point, but I still want it); and 2: I wanted to use different images in different resolutions to fit my screen.

earth
This image is generated using the Earth’s City Lights image from NASA as the night image, and one of the twelve Blue Marble Next Generation Monthlies, also from NASA. The script will detect your month, and pick an appropriate image for that month. This gives cool changes it snow and foliage and such. It doesn’t make a huge difference of course, but it’s cool :) It also uses topographical information to allow xplanet to cast some subtle shadows, which I think really brings it all to life!
read more »

Proxy Servlet for GWT in devmode

One of the problems with using GWT is that when you run in devmode, GWT manages its own instance of a Jetty server (I think it’s a Jetty server anyway). Unless you want to use GWT’s own server implementation, and perhaps even run in on Google AppEngine, you’re going to run into the same origin policy. In order to get around this problem, you have to set up a proxy server of some sort. I found a bit of servlet code written by Stou Sandalski which allows you to do this, made to solve the exact same problem in fact. However, I wanted a proxy which would not only support GET and POST requests, but basically allow me to do whatever I wanted. I also wanted it to send all request headers across to the target server. The only dependency is Apache HttpCore and HttpClient.
read more »

Installing dependencies with Apache Ant

I’ve recently been messing around with GWT and Mercurial, and came across the age old dilemma: “add libraries to version control or not …”. On one hand it’s easier to deploy and get new people to use it, on the other hand it’s pretty redundant and down right ugly. So, the only other solutions are A: tell people to install it manually, which is bound to end in tears, anger, and frustration; or B: make an auto installation script. I’ve written a few of these before, but it’s a horribly dull task. So with the GWT’s SDK pretty much forcing me to use Ant anyway, I thought it might be up for the job, and here is the build.xml script I came up with:

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <project name="test" default="build" basedir=".">
  3. <property name="dir.lib" value="lib" />
  4.  
  5. <!-- GWT version, source, and destination -->
  6. <property name="gwt.version" value="2.0.3" /> <!-- Version number for easy reference -->
  7. <property name="gwt.depfolder" value="gwt-${gwt.version}" /> <!-- The folder that the archive will produce -->
  8. <property name="gwt.deparchive" value="${gwt.depfolder}.zip" /> <!-- Filename of the archive, both local and on server -->
  9. <property name="gwt.depsource" value="http://google-web-toolkit.googlecode.com/files/${gwt.deparchive}" /> <!-- The URL to fetch the archive from -->
  10. <property name="gwt.sdk" location="${dir.lib}/gwt" /> <!-- Final location -->
  11.  
  12. <target name="installdeps" description="Install dependencies">
  13. <delete dir="${gwt.sdk}" />
  14. <get src="${gwt.depsource}" dest="${dir.lib}/${gwt.deparchive}" usetimestamp="true" />
  15. <unzip src="${dir.lib}/${gwt.deparchive}" dest="${dir.lib}" />
  16. <move file="${dir.lib}/${gwt.depfolder}" tofile="${gwt.sdk}" />
  17. <!-- <symlink link="${gwt.sdk}" resource="${dir.lib}/gwt-${gwt.version}" /> -->
  18. </target>
  19. </project>
plain

The script is actually quite simple:

  • Line 6-10: Figure out where to get it from and where to put it. This might look a bit complicated, but it should allow you to control pretty much anything from those five lines, leaving the actual target to do its work.
  • Line 12: The actual Ant target. This will be run when you execute ant installdeps.
  • Line 13: Delete the old SDK directory.
  • Line 14: Fetch the zip file from the source specified in line 9, unless the file already exists or is older than the one on the server.
  • Line 15: Extract into lib folder.
  • Line 16: Move it to a generic folder from where it can be easily accessed. I personally like symlinks (line 17), but I know they can be a pain to deal with on Windows, so I opted for just moving it.

Type-checking in Javascript

A while back I wrote a few functions to reliably determine types in javascript. The reason I made these functions is because javascript’s typeof operator doesn’t always return what you want. The main idiosyncrasy is typeof [] and typeof null both returning "object".

At the time of coding, I also wanted a function to tell me whether something was an integer, something javascript doesn’t support natively on its own. Of course, it doesn’t actually tell you if it’s an integer, merely whether it has a fraction part.

  1. function isInteger(val) {
  2. return isNumber(val) && Math.floor(val) == val;
  3. }
  4.  
  5. function isNumber(val) {
  6. return typeof val == "number";
  7. }
  8.  
  9. function isString(val) {
  10. return typeof val == "string";
  11. }
  12.  
  13. function isBoolean(val) {
  14. return typeof val == "boolean";
  15. }
  16.  
  17. function isObject(val) {
  18. return typeof val == "object" && val !== null;
  19. }
  20.  
  21. function isArray(val) {
  22. return val instanceof Array;
  23. }
  24.  
  25. function isFunction(val) {
  26. return typeof val == "function";
  27. }
plain