Rounding to a Certain Significant Figures in JavaScript

October 14th, 2008

A recent question at stackoverflow.com prompted me to take a stab at implementing a function for rounding a given decimal number to a given number of significant figures (or digits).

function sigFigs(n, sig) {
    var mult = Math.pow(10,
        sig - Math.floor(Math.log(n) / Math.LN10) - 1);
    return Math.round(n * mult) / mult;
}

alert(sigFigs(1234567, 3)); // Gives 1230000
alert(sigFigs(0.06805, 3)); // Gives 0.0681
alert(sigFigs(5, 3)); // Gives 5

Repeating or Padding Strings in JavaScript

October 13th, 2008

Here’s a nice trick for repeat a string a given number of times. Read the rest of this entry »


JavaScript Date Formatting – An Unorthodox Way

September 2nd, 2008

Most date formatting implementations use format strings where format specifiers like “mm”, “mmm”, “HH”, etc. are used for selecting different components of a date. Here’s a different approach that allows you to use more human-readable format specifiers (while being rather verbose). Read the rest of this entry »


Subpixel Scrolltext in JavaScript

August 5th, 2008

Subpixel Scrolltext SnapshotAfter having it in my to-do list (the “what if?” section) for a long time, I’ve finally managed to spend some time on a JavaScript implementation of a very tiny scrolltext; using a 5×5 font with subpixel rendering (aka ClearType). Knowing what subpixel-rendered static letters look like on an LCD, I wanted to see the effect of scrolling them, 1/3 pixel at a time. Note: you need an LCD monitor to see the full effect. Read the rest of this entry »


Adobe (Photoshop) Color Book Specification in HTML Format

June 18th, 2008

I finally sat down and created a friendlier, HTML version of the Unofficial Adobe Color Book Specification by updating the original post. This obsoletes the 80-column plain-text version that I wrote up in 2003.


A Boulder Dash Clone in Only 20 Lines of JavaScript

June 18th, 2008

This was my very first entry for the quasi-regular, friendly 20-line JavaScript competition over at OZONE Asylum, for the month of January 2008. My entry titled “Rockford the Invincible” got the second place among some very impressive entries (I was actually a bit shocked that I got the second place).

Rockford the Invincible

In-game screenshot. Click to play!

Read the rest of this entry »


Generating “Unified Diff” Files with ClearCase

September 7th, 2007

In my company, we recently migrated from CVS to ClearCase. We were a bit thrown off by the fact that ClearCase doesn’t readily provide diff files that span multiple files. We have all been used to reviewing CVS diff files which do so. People here had to come up with their own scripts to remedy this issue. Read the rest of this entry »


ACB2XML 2.0b – Export Adobe Color Book Data as XML

May 8th, 2007

Here’s a freeware tool that I had written back in 2003, shortly after reverse-engineering the Adobe Color Book Format. This command-line Windows application extracts color data from color book files and generates XML. Once the color data is safely in XML domain, the rest is up to your imagination…

Download acb2xml20.zip (30 KB)

Read the rest of this entry »


Burrito 1.0b – FTP to POP3 Protocol Translator

May 7th, 2007

With Burrito you can read and manage your e-mails with any FTP client! It acts as a POP3/FTP protocol translator — it’s actually an FTP server that translates FTP commands to POP3 commands and serves your e-mail messages as individual files. You can view, delete and copy your e-mail messages as if they were files on an FTP server.

Download burrito10b.exe (479 KB)

Read the rest of this entry »


Verifying the Integrity of an Easynews Download without a Checksum File

February 6th, 2007

Suppose you had to download a huge file from Easynews as a single piece because a multiple archive version wasn’t available. If the poster didn’t supply a checksum file (MD5, SFV) or Parchive files, you can’t readily tell if the file you’ve downloaded is intact. Here’s a method I came up with for verifying the integrity of an ISO image file that didn’t come with a checksum. I didn’t want to burn the ISO image without knowing that the file was intact, to avoid an interrupted or corrupt installation. Read the rest of this entry »