LinuxSoftware

Coding and tramping in Aotearoa / New Zealand

Car insurance

Oct 31

Fun with Javascript

, , david, Saturday, 3:24 pm

The RenoufTxt Algorithm: Tim came up with the idea of using an automatic txt compression on fixed length fields, where the input being entered is just a little bit too long for the field size. It’d be better to increase the size of the field, but maybe there might be some situation where that is not possible. This was back when I had more free time, so I coded it up. It was a good excuse to write some Javascript (I should say ECMAscript) code anyway. Javascript is a very interesting language, the way objects are just dictionaries with member functions just values being stored by function name. Python is similar, but has a few more restrictions.

Here’s an example of an input field with RenoufTxt enabled on it.

Updated: It seems later versions of Firefox wisely block bits of Javascript sitting inside blog posts. You’ll have to go to this page to see the script in action.

And, here is the source code: renouftxt.js.

My implementation tries four different methods [toNumber, abbrev, innerAbbrev, removeVowels] to compress each word and tries to choose the words and methods which give the most compression for the best readability. That’s probably way over-engineered, but this was “just for fun”. A simpler implementation might just remove vowels.