SMS Character Count

It is commonly known that Twitter allows 140 character messages, and some will tell you that a single SMS message is limited to 160 characters. However, it’s not as simple as that. In the US a single SMS message can contain 140 bytes of data, which if using GSM encoding, we can squeeze up to 160 7-bit characters. Those 7-bit GSM characters don’t match up with normal ASCII characters, and even worse, not all characters take 7 bits, some take up 14 bits (for example the { character)!

When we start talking about messaging in non-latin scripts, such as Chinese, then a different encoding must be used. In the SMS world the encoding of choice is UCS-2, which uses 16 bits per character. This limits a single part message to 70 characters (down from 160).

On top of that, most SMS clients will let you send concatenated SMS messages. That is, multiple message parts that appear as one long SMS message. A two part message allow up to 304 characters, not the 320 (160×2) you might expect. This is due to the overhead required to store meta data about each part.

This all makes it very hard to count how long a SMS message will be, what characters are allowed, and how many parts it will take. To help with these isuses, I’ve created this simple tool which allows you to type out your message, and see how well it’ll fit

SMS Character Count

Alignment of Raphaël Paper.text(…) and Paper.print(…)

Working with Raphaël I noticed the alignment of text drawn with the Paper.text(…) and Paper.print(…) methods differed. The documentation wasn’t helpful in explaining the difference, so I wrote a simple test to work out their behaviour, and then a small method to normalise them.
Read more »

Most starred project this week, and second most forked.

After getting my js-sequence-diagrams project onto Hacker News, the popularity has gone viral.


Draw UML Sequence Diagrams with Javascript

I’m happy to announce one of my projects, js-sequence-diagrams. This uses Javascript to draw UML sequence diagrams in SVG format. Here is an example:

js-sequence-diagram example

You can alter the diagram in real time, and I even have a simple jQuery plugin to make this easy to use on your own sites.

<script src="sequence-diagram-min.js"></script>
<div class="diagram">A->B: Message</div>
$(".diagram").sequenceDiagram({theme: 'hand'});

MongoDB Compression

For a while people have wanted MongoDB to compress their data, or at least compress their field names. This would be beneficial in not only reducing the amount of disk space required, but also in theory improving performance as we trade disk IO with CPU IO. I thought this be a fun project to investigate, so I started by working out if this would actually be useful. Read more »

How many ways are there to say phone number?

In the various systems I’ve worked on, I have seen far too many terms to describe a phone number. I thought I’d catalogue them! Read more »

Invalid IP range checking defeated by DNS

I’ve seen a particular kind of vulnerability in a few different applications but I’m not sure of an appropriate name for it. So I thought I’d write about it, and informally call it the “DNS defeated IP address check”. Basically, if you have an application that can be used as a proxy, or can be instructed to make web request, you don’t want it fetching files from internal services. Read more »

JSHint ‘x’ is an implied global variable

I’ve started using JSHint to check my javascript. One error I encountered was:

     85,5:'grammar' is not defined.
     85,1: 'grammar' is an implied global variable.

Read more »

Nodewii talk at Node DC

Last night I gave a short talk at NodeDC, on how to use Node.js with a wiimote. The offical title was “Controlling Node.js with a wiimote – My experiences with developing multi-threaded nodejs addon”. I’d like to thank the NodeDC guys for arranging everything last night, it was a great night, with some great talks.

The slides can be found here:


Many months ago I purchased this cool little device from Pulse Eight, called a USB CEC Adapter. Basically it allows your computer to speak to a HDMI device over a protocol called CEC. This is useful for using your PC to control your TV, and for using your TV remote to control your PC. This device now allows me to use my normal TV remote to control XBMC, and to turn my PC on standby if I turn my TV off. Read more »