Archive for the 'Dump' Category

Query String to Object via regex

Just sharing a nice little code snippet that makes use of regular expressions instead of loops for converting.

Pronounceablely Random

If you work in a secure(ish) environment then you’ll be changing passwords on a regular basis. An old colleague and I came up with a script that would generate a password based on fictional words from a dictionary lookup. Then we/he realised that this could actually be generated on the fly, be completely random and […]

Idiot Proofing the jQuery.ready

I’m always writing quick prototypes of ideas I’ve got, and often they’ll include some quick jQuery. However, for reasons unbeknownst to me, about 1/3 of the time I forget to wrap the statements in a .ready() function, and since I have the habit of putting my script tags in the head – the code never […]

JavaScript namespaces

Based on the Prototype namespacing made easy, except this doesn’t require Prototype. String.prototype.namespace = function(separator) { var ns = this.split(separator || ‘.’), p = window, i; for (i = 0; i < ns.length; i++) { p = p[ns[i]] = p[ns[i]] || {}; } }; This isn’t so much to ditch Prototype, but to encourage using […]

Base64 decode to file

Useful if you’ve just received an email that says it has attachments but you can’t get them out (as I just did!). View the raw source of the email, copy the Base64 encoded text, drop in to a file, and run through this. The output will be the binary (or ascii) attachment. perl -MMIME::Base64 -ne […]

On Demand Script Loading

This code will return true while it’s waiting to load the external script – and if called again (i.e. at a later date or if you’ve got an excited user) will know that the script has already been loaded. It allows for scripts to be loaded on demand without the use of an external library […]

Delay the DOM ready event / Generate a dummy file

dd if=/dev/zero of=dummy.file bs=1000000 count=1 This will generate a 1Mb (approx) file. Useful for tests. In my particular case, I’m trying to delay the DOM ready event in JavaScript – so I’m going load a large file in a script tag – which will load before the DOM ready is fired. To delay the DOM […]