Generating planets with javascript and WebGL

I recently stated using three.js to play around with webgl and here are the first fruits - procedurally generating planets with javascript. The demo is avalible here.


Switching default search to DuckDuckGo

I've been trying out DuckDuckGo (DDG) for a while now and it has some very nice features:

  • No user tracking
  • Encryption by default
  • They don't 'bubble' your searches - tailoring your search based on previous searches (which pushes, possibly more relevant results, down in your results)
  • They have some great power features

And it's this last point that has made me jump the google ship (that and the new G+ integration into searches), at least temporarily. Try searching "50 dollars in euros" in DDG and the top result is pulled from wolfram alpha (not just the link but the actual result - at the time of writing €37.74), "array.prototype" gives a stackoverflow question (again the actually question, not just a link), "Ethan Hawkes" pulls information from wikipedia.

But my favorite power feature revolve around adding key terms within your search: want to search

  • The mozilla developer network - add '!js'
  • Amazon UK - add '!auk'
  • Google Scholar - add '!scholar'
  • PHP.net - add '!php'
  • If you think google would be better for a result - add '!g'
  • the list goes on.....

Fully CSS (bordered) popup bubble

This is my addition to the world of totally css popup bubbles: borders on tooltips - life changing, I know.

The challenge is this: create a pop-up bubble for an element with no non-semantic elements, with the end result looking something like this:


Html-wise I've opted for the following (I'll argue why later....):

<article class="popup">
    Main Text
    <aside>Hello I'm a popup bubble!</aside>

here I've used <aside>'s "Additional content to an <article>" definition.

So to start with I want the <aside> to be taken out of the flow of the page and positioned with absolute reference to the main text:

.popup{ position:relative;}

.popup > aside{
    background: white;
    border:1px solid black;
    border-radius: 5px;
    width: 200px;

(with some border-radius for good measure):


The main text's CSS is taken from the great twitter bootstrap, and isn't necessary for the demo but is nice eye candy!

Now comes the challenging bit: how to do the tag at the bottom? My first thought was to use a "V" in the content of a psudo-class, positioned correctly, but that just looked weird! So I turned to a nicety of the CCS border spec: the ability to make triangles with CSS.


Box2d.js and load times

I recently discovered box2djs by Ando Yasushi, a nice little physics simulation engine made to run in javascript, here's an example from the homepage:

box2d-js homepage

However, it being a port of a port, there are one or two little problems. The main one by far is the delivery of the library - in the flash version, modules are loaded lazily (i.e. as needed), however in javascript all the different libraries need loading up-front.... all 64 of them... in a set order... and each file has the full MIT license information at the top!

So the browser has to make 64 different server calls and pull down 349 Kb just to start doing anything. This can clearly be improved on.

Turning on server-side gzip, is a good way to reduce the amount of data transmitted with no real downsides. Also putting everything in one file will help a lot, but more can still be done.

To shrink the javascript filesize even more there are two paths: compressors or encoders. Compressors (like yahoo's YUI compressor) remove whitespace, rename internal variables to have shorter name and do a hundred and one different optimizations, but crucially, the end javascript is programmatically identical to the input file (a browser doesn't care if a variable is called "theGreenBallsRadius" or "aPb"). Encoders (like Dean Edwards' Packer) go one stage further - they encode the resulting file (much like gzipping) and then tag on some javascript so the browser can decode it at the other end, but this creates some javascript overhead before things can get up and running.

Now because everything is better in table form:

NameFilesSize (Kb)w/ GZip (Kb)

This shows near 85% improvement just by putting everything in one file and turning on gzip! But even better, the filesize can be halved on top of this.

My first instinct was to go with the Packer encoded version: it's the smallest (or close enough) whether the user's browser supports gzip or not. But the YUI compressed version is my recommendation. Why? Well I'm glad you asked! The vast majority of visitors' browsers will accept gzipped files, so for them there's no filesize difference between YUI and Packer. Now with YUI you can just un-gzip and you're away, however with Packer you unzip then decode then you're good to go. This additional step will still halt rendering until it's complete, making the page load feel slower - the exact thing we were trying to improve.

There you go, a good library made better! Now onto hacking it.....


The Anatomy of a Spam Scam

Note: I'll be updating this as I go

Got some blatantly rubbish spam the other day:

From: XXX@ifsertao-pe.edu.br
Date: 14 March 2011 11:54
Subject: Notification

You Have Won The EuroMillions Lottery
Contact: Edward Louis via Email: euro-millions16@live.com


How little effort! (The X's being added by me to give the guy with the hacked account some privacy). So I decided to reply.


Interactive Ray Optics

Here's the ray optics demonstration I made during my PhD. It models ray-surface interactions in javascript... and that's pretty much it! But it's still quite a fun way to waste 5 mins. Any modern browser should be able to run it*.

Ray Optics Demo* i.e. not IE