Posts Tagged ‘script’

23
Oct
20:55

Perl script for converting between currencies

Hello there dear readers,

I’ve been working on a little command line utility this afternoon to convert between different currencies google style. Instead of googling “10 USD in EUR” every time, you can simply type the same in the command line and get the result straight from your terminal.

My intention was originally to make this script into a Quicksilver utility. It could easily be done by having an applescript supply the data to  but unfortunately Applescript seems broken in Quicksilver on Snow Leopard and I still haven’t had the chance to try to fix it.

In case this one caught you by surprise – yes, there’s actually a version of Qucksilver that works fine with Snow Leopard.

Installing this script

  1. Install Finance::Currency::Convert::Yahoo. To do this:
    1. Start cpan
    2. Type: install Finance::Currency::Convert::Yahoo
  2. Put the script somewhere you like
  3. Make sure it’s executable (chmod +x ./currency.pl)
  4. Done!

Using this script

Couldn’t be any easier:

% ./currency.pl 100 USD in EUR
66.58 EUR

And that’s it!

It also takes other forms of input. For instance:

  • “10USD in GBP”
  • “USD10 in GBP”
  • “USD 10 JPY”
  • “$20.10 in cny” (keep in mind that you will need to escape that dollar sign or the shell might think it needs to do something with it)

The basic rule of thumb is that the first currency is the source, the second is the target and that a number is the value in the source currency. You may only supply ONE of each.

Note: I added a substitution from “NIS” (New Israeli Shekel) to ILS (Israeli Shekel). Yahoo prefers the code ILS while I prefer NIS, no biggie.

License

Public domain, baby.

Getting the script

Save this file. Then see above instructions.

Changelog

21
Nov
19:51

Saturday Night Widget

A long time ago, I made a little widget. It’s basically a Dashboard widget showing the young John Travolta back from Saturday Night Fever.

Saturday Night Widget - screenshot

So there. If you want a copy of this widget, you can download one here. Simply double click the archive.

Please note that it should be compatible with all versions of Mac OS X after Tiger, and then, both PPC and Intel machines. (I tested it on my MacBook, and it works.)

It’s too stupid to be copyrighted, so I’m just putting it in the public domain.

12:17

Automatically set X display to client machine when SSHing

At home I have a server running Linux and a MacBook.

Every now and then, I want to run an X11 program. VNC takes up my whole screen, and therefor it’s counter productive, but there’s another way.

Mac OS X has an optional X11 server. After installing it, programs could connect to it and coexist in the Aqua environment.

The thing is that while my server doesn’t change IP, my MacBook does, since I often alternate between wi-fi and ethernet, and even then I can’t be bothered to set it every time. So basically, the IP always changes.

For this purpose, I made this useful script. I’ve tested it on zsh, but it should work in Bash as well, I believe. I put the following lines in my .zshrc:

if [ $SSH_CLIENT ]
then
export DISPLAY=`echo $SSH_CLIENT | sed 's/ [0-9]* [0-9]*$//'`:0
fi

Basically, if the variable $SSH_CLIENT is defined, it takes that variable, nips the last two figures (one being the source port and the other being the destination port), which leaves us only with the IP of the machine we’re SSHing from. Pretty useful. Now all you need to do is put xhost the_ip, where the_ip is the IP of the machine you want to connect to you, in your .xinitrc to automatically allow it to connect to you.

It werks!