Entrepreneurship, Linux, and Ruby
Posts tagged tweetshrink
Human Readable Text Compression
Jun 13th
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
Now install the gem from it's GitHub repository:
$ sudo gem install logankoester-tweetshrink
You can use it from the command line like this:
# 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
autocmd BufEnter * nmap ,tws !!tweetshrink
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.
TweetShrink gem for Ruby
Mar 6th
TweetShrink's API is so simple that this gem barely adds anything on top of HTTParty, but here it is.
require 'rubygems' require 'tweetshrink' t = TweetShrink.shrink "One wonders why" # t['difference'] => 4 # t['text'] => "1 wonders y" # t['original_text'] => "One wonders why"
You can get it from my github account, here, or via rubygems like
$ sudo gem install logankoester-tweetshrink
Enjoy.

