Saturday, October 14, 2006

Google Calculator from the Command Line

I'm not sure if you're aware of Google's built-in calculator, but it's totally awesome. It does all sorts of basic calculations, almost any unit conversion you can dream up, and for you programmers, it's great for doing base conversions. But opening a web browser to www.google.com just to make sure you converted 0x34 to decimal in your head correctly, isn't always convenient (this is of course assuming that no other calculators exist, such as bc ;-) ).

So, I threw together a very simple command line interface to Google Calculator -- aptly named gcalc. It's also a good example of how Cocoa's powerful classes can let you whip up useful tools quickly, much like a scripting language. The help screen shows some example usages:

$ gcalc
gcalc version 0.1 by Greg Miller

Usage: gcalc [-d] <calculator query>

example: gcalc "5+2*2"
example: gcalc 5!
example: gcalc "sqrt(-4)"
example: gcalc "160 pounds * 4000 feet in calories"
example: gcalc avogadros number
example: gcalc 0b110111010 + 0x33 in decimal
example: gcalc 22 lira in yen
example: gcalc 2 to the power of 5


You can download the source and a prebuilt universal binary from the Google code project page at http://code.google.com/p/uj-gcalc/

Or if you just want to glance at the source, you can check it out here:

6 comments:

Anonymous said...

That's really a nifty & useful command line tool; and it's fun to use, esp. with Visor ( http://docs.blacktree.com/visor/visor ).

Thanks for sharing this!

Yet another way to get command line arguments btw is to use NSProcessInfo:

NSArray *processInfoArgs = [[NSProcessInfo processInfo] arguments];
NSLog (@"%@\n", processInfoArgs);

Cheers,
p.

neil said...

Hey excellent, thanks for sharing this.

LIVECHAT said...
This comment has been removed by a blog administrator.
PVTechGeek said...

Pretty cool. This is a nifty tool.

admin said...

I am Very thank full the owner of this blog. Becouse of this blog is very imformative for me.. And I ask u some thiing You make more this type blog where we can get more knowledge.
thanks you very high work..
www.r10.net küresel ısınmaya hayır seo yarışması
www.r10.net küresel ısınmaya hayır seo yarışması
www.r10.net küresel ısınmaya hayır seo yarışması

fikret said...

thank you google calculator is great