Dissecting your bash prompt





Check it out here and the source is available on github.

Convert an image to ANSI escape codes



Check it out here!

WevDAV-js update




Continue reading “WevDAV-js update”

Beautifying XML

…well, making it easier to read at least.

I often have to deal with a machine produced lump of XML which is entirely impossible to read and extract information from, so I’ve made a small page that beautifies XML without sending it server side for processing (ideal for business sensitive data that can’t be transmitted to who-knows-what server) and thought I’d share in case it’s useful to anyone else.

There might be some bugs in there somewhere, but it’s served to meet most requirements of my day-to-day needs.

It’s available here.

Running CSS animations when the element is shown

Not a unique idea at all, many existing libraries out there, but I wanted a very basic jQuery plugin that I controlled entirely with CSS animations and classes being applied when the user scrolled to (or past) the element, along with a few key features: chaining animations to run in sequence, customisable delays and customisable visibility offsets.

Some code snippets from the example page. The get started, all you need to add to your page is:

<script src="jquery.animateOnShow.min.js" charset="utf-8"></script>
<link rel="stylesheet" href="animations.css" media="screen" charset="utf-8">

then you can add the following classes to your page and the animations will work when the user scrolls to them:

<p class="animate-on-show fade-in">This text will fade in!</p>
<p class="animate-on-show slide-in-from-below fade-in">You can add multiple animations if wanted...</p>

<p class="animate-on-show fade-in" data-animate-chain="sequential-example">This will fade in first</p>
<p class="animate-on-show fade-in" data-animate-chain="sequential-example" data-animate-delay="500">Then this, 500ms later</p>
<p class="animate-on-show fade-in" data-animate-chain="sequential-example" data-animate-delay="1000">Then finally this after 1000ms!</p>

All delays are relative to the first element shown with a data-animate-chain attribute, so when this first element is shown, the timeouts are set up for all other elements with the same data-animate-chain attributes.

The CSS is pretty straightforward and some basic example animations are defined in animations.css

.animate-on-show { transition: all 1s ease-in-out; }
.animate-on-show.fade-in { opacity: 0; }
.animate-on-show.fade-in.animated { opacity: 1; }

The simplified example above controls the basis for the plugin, first all elements with an animate-on-show class are set up with a 1s animation. Then the child classes, in this case fade-in are defined with an initial state, and how it should end once the animation is applied (.animated). The plugin essentially just applies the animated class to each element that is deemed visible and CSS does the rest. The additional chaining happens at the same time along with accounting for delays.

There are some global settings you can define, including vertical adjustments for some classes. For example slide-in-from-below:

.animate-on-show.slide-in-from-below { transform: translate(0, 400px); }
.animate-on-show.slide-in-from-below.animated { transform: translate(0, 0); }

is configured with an initial state of 400px below the target end location, this means we have to adjust our offset by 400. The $.AnimateOnShow.settings.custom object handles this:

    $.AnimateOnShow = {
        settings: {
            custom: {
                // these can be used to adjust positioning, like with the example
                // slide-in-from-below, the calculation needs to take the initial
                // translate into consideration and so we add the 400 which is
                // missing due to the initial state.
                'slide-in-from-below': 400,
                'slide-in-from-above': -400

If you’re adding in other animations that adjust the vertical position, be sure to add these to your version of the plugin or change in your page’s script via $.AnimateOnShow.settings.custom['your-classname-here'] = <adjustment>.

Hope this saves someone some time if they want to do something similar!

I’ve made it a fairly customisable package although it does currently rely on jQuery as the site for which this was originally developed already had it.

There’s a demo page that includes download links and you are free to use this code however you see fit!

Can you make your scripts smaller?

Minifying your JavaScript is something most people are familiar with and have to do fairly regularly, whether is reducing your page load time on PC or keeping the files within the mobile cache limits.

Having recently seen UglifyJS and having used some of the more obvious tricks (!0 === true, !1 === false, etc) myself, I wondered if there was a way you could shrink down what’s transferred even more…

As a proof of concept I’ve knocked up a (hopefully fairly) simple perl script that will wrap your code in a closure and replace a lot of the internal indexes that are used with global symbols, which when compressed with YUI/Uglify should reduce filesize overall.
Continue reading “Can you make your scripts smaller?”

Sonic the Hedgehog ‘construction cheat’ in JavaScript

I clearly spent a little too long thinking about this, but it was fun nonetheless!

I showed my 5-year-old nephew the construction cheat in Sonic the Hedgehog the other weekend and he thoroughly enjoyed printing rocks everywhere on the screen, so I wondered if it would be possible to do something similar in JavaScript, since people love using the Konami code for easter eggs, why not Sonic?

I opted for native javascript, not using any libraries for easy portability.

I’ve encountered a few issues on some sites that already capture keypresses, but for the most part it’s worked ok. I’ve only tested this on Chrome and Firefox (Mac, latest versions) but it should work fine on Windows. No idea about IE… Probably not, but I did try to use cross-browser methods where applicable!

The commented source is here and the script is enabled on the blog so you should be able to use it anywhere.

Have fun!

Oh, here are some sprites for good measure:

For those that need reminding of the code (I’m not angry, just disappointed):


WebDAV file upload bookmarklet






Pop quiz!

An interesting item from stackoverflow via /r/javascript!




Mousetrap – excellent keyboard shortcuts

Just discovered a great little library called mousetrap.


Example usage:

Mousetrap.bind('d', function() {

Mousetrap.bind('a', function() {

Mousetrap.bind('x', function() {

