SCRIPTS

A few fancy and whimsical creations:


Morseblink.pl

A Perl utility to read text files by blinking your keyboard’s LEDs in morse. Inspired by Cryptonomicon.
You can peruse the code here.

Try:

$ perl morseblink.pl my-file.txt
$ echo "This message in morse" | perl morseblink.pl


Quick online lookup from the terminal: Describe.rb

A command line lookup tool (and dictionary) that uses the mighty handy “define:” Google keyword at the *nix terminal.

What am I talking about? Try “define: isomorphism” in Google. Or “define: milankovich cycles“, or “define: point-to-point protocol“. See what I mean? Because it’s an aggregator, you’re not restricted to dictionary words or phrases. If there’s a Wikipedia article on it, the first few lines will show up.

Code here, download here.
(If Ruby’s not your thing, perhaps you’d like the Python version? I’m not sure this still works, though.)

Use as

$ describe.rb "milankovich cycles" isomorphism

It takes more than one argument.


A command line Google Calculator

This one’s not mine, but I use it all the time; you will too!

What does it do? Just about anything Google does, on the command line. Example:

$ gcalc “1.2 gallons in ml”
1.2 Imperial gallons = 5,455.31025 millilitres

$ gcalc “131 USD in INR”
131 U.S. dollars = 6,497.69357 Indian rupees

$ gcalc “radius of sun^3 * 4 * pi / 3 in km^3″
((radius of the sun^3) * 4 * pi) / 3 = 1.40922394 x 10E18 km^3

Like the Unix units utility, only better.
Download here, better demonstration of its features here.


Quick definitions in Emacs

I like to have access to the above in Emacs; hitting a key to immediately see definitions of the word under the cursor is very satisfying. If you’re an Emacs user, here’s some Emacs-Lisp code to set things up. First, put the above script (describe.rb) somewhere in your $PATH, then these functions in your .emacs, and you’re all set:

(defun describe-word-at-point (&optional prefix)
  "Briefly describe word at point. With PREFIX argument, show
verbose descriptions with hyperlinks."
  (interactive "P")
  (let ( (word (thing-at-point 'word)) )
    (shell-command (concat "describe.rb " word (cond ((null prefix) nil)
                                                  (t " -v"))))))

(defun describe-word (word &optional prefix)
  "Briefly describe WORD entered by user. With PREFIX argument,
show verbose descriptions with hyperlinks."
  (interactive "sDescribe word: \nP")
  (shell-command (concat "describe.rb " word (cond ((null prefix) nil)
                                                  (t " -v")))))

I bind these functions to Control-? (mnemonic: Control+What) to query Google for the word under the cursor, and “Control-x ?” to type in a word. Either way, the results show up in an adjacent buffer.

(global-set-key (kbd "C-?") 'describe-word-at-point)
(global-set-key (kbd "C-x ?") 'describe-word)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s