Human Readable Text Compression
13 Jun 2009
As a Web Service
TweetShrink, a web service from TRNSFR, uses a database of common instant / text messaging abbreviations to reduce the number of characters in a tweet. It’s essentially a human-readable compression algorithm. For example, “Some text to shrink” becomes “sum text 2 shrnk” when passed through their API.
But it doesn’t enforce Twitter’s 140 character limit, which means it can be used beyond Twitter for whatever you like. Back in March I released the tweetshrink gem for Ruby, and today I’ve updated it to 0.2 which includes a command line interface.
From the command line
First, make sure you have Ruby and Rubygems installed. On Debian-based operating systems (such as Ubuntu), this goes a little something like
$ sudo apt-get install ruby rubygems
Now install the gem from it’s GitHub repository:
$ sudo gem sources -a http://gems.github.com # (only need to do this once)
$ sudo gem install logankoester-tweetshrink
You can use it from the command line like this:
$ echo "Some text to shrink" | tweetshrink
# Or with a file...
$ tweetshrink ./file_to_shrink.txt
From vim
Or, you can integrate it with vim for ultimate text shrinking convenience. Just add the following to your .vimrc:
""""""""""""""""""""""""""""""""""
" Tweetshrink text filter (:tws) "
""""""""""""""""""""""""""""""""""
autocmd BufEnter * vmap ,tws !tweetshrink<CR>
autocmd BufEnter * nmap ,tws !!tweetshrink<CR>
Now you can shrink a single line by hitting ,tws in Normal mode, or shrink a whole a visual block.
Of course, this is just as easy to integrate with your favorite text editor; I just happen to use vim.
On the Web
When I integrated this feature with my blog & tweet scheduler PingLater.fm, I realized TweetShrink didn’t have a favicon. I needed an icon to use for the button, so I created these – feel free to use them for whatever.
[gallery link=“file” columns=“4”]