Posted: October 14th, 2009 | Author: Jerod | Filed under: Cappuccino, Projects | Comments Off
In Brief:

I just launched CappuccinoFlow: a community driven link blog for the Cappuccino framework. If you’re at all interested in this amazing new technology out of 280north, make sure to subscribe to the RSS feed, follow along on Twitter, and post cool Cappuccino-related links to the flow!
In Detail:
It has been a little quiet around these parts lately. I blame Cappuccino.
For the uninitiated, Cappuccino is a framework for writing web applications (for example). It is built on Objective-J, which is an Objective-C-esque superset of JavaScript. It is completely rad. Also, it’s all client-side so I still get to use Rails on the back-end. I believe the apt word is: woot.
I wanted a link blog to support the small, but growing, Cappuccino community. I’m a big fan of RubyFlow so I contacted its creator, Peter Cooper, and asked him if I could set one up for Cappuccino. He was gracious enough to say yes, and he had conveniently open-sourced an old version of his site awhile back. I forked it on GitHub and the result is CappuccinoFlow.
I’ll probably have to modify my blog’s headline soon, because once I become proficient in Objective-J & Cappuccino you’ll probably see some posts about it.
Posted: September 9th, 2009 | Author: Jerod | Filed under: OS X | Comments Off
OS X’s built-in System Profiler provides a great graphical display of pretty much anything you’ll want to know about your Mac.

That’s cool and all, but what if you want to access that information programmatically? Turns out you can also run the System Profiler from the terminal by executing this command:
jerod@mbp:~$ /usr/sbin/system_profiler
What’s great about this access method is that it allows you to slurp that data into any other program and have your way with it! For instance, I wanted to track my new battery’s cycle count and charge capacity over time. Why? I dunno, because I’m a geek, okay, get off my back!… Anyways, with the system_profiler command I simply run this little Ruby script every day:
1
2
3
4
5
6
7
8
9
10
| require 'date'
data = `/usr/sbin/system_profiler SPPowerDataType`
cycles = data[/Cycle count: (\d+)/, 1]
condition = data[/Condition: (\w+)/, 1]
capacity = data[/Full charge capacity \(mAh\): (\d+)/, 1]
File.open('/Users/jerod/Documents/battery_history.csv', "a") do |file|
file.puts "#{Date.today},#{cycles},#{capacity},#{condition}"
end |
Ruby uses the (possibly familiar) backticks (line 3) to capture output from a shell command. All that was left for me to do was to parse the raw data and save it to a CSV file.
Finally, note that the my script is passing SPPowerDataType as an argument which narrows down the returned results. You can learn more about how to use the system_profiler command by readings its manual. Just:
jerod@mbp:~$ man system_profiler
Posted: September 7th, 2009 | Author: Jerod | Filed under: Tools | View Comments
Command-line jockeys are intimately familiar with the cd command. We’ve typed commands like this one a gozillion times:
jerod@mbp:~/src/ruby/rails$ cd ..
jerod@mbp:~/src/ruby$
We all know that . represents the current working directory and .. represents the current working directory’s parent directory. If we follow this pattern to its logical conclusion, then … would represent the current working directory’s parent’s parent, etc. Unfortunately, cd doesn’t work that way.
Read the rest of this entry »
Posted: September 1st, 2009 | Author: Jerod | Filed under: OS X | Tags: hacks, snowleopard | View Comments
Looks like I’m not the only one who hates Snow Leopard’s blue ring around selected windows in Exposé.
Thankfully, we don’t have to live with such monstrosities. Here’s a quick fix to free yourself from the blue haze. Fire up Terminal.app, then:
1
2
3
4
| cd /System/Library/CoreServices/Dock.app/Contents/Resources/
sudo mv expose-window-selection-big.png expose-window-selection-big.ugly
sudo mv expose-window-selection-small.png expose-window-selection-small.ugly
sudo killall Dock |
This will disable the blue rings altogether, but you may want to replace these two images with some custom ones that look a little cooler instead.
Let me know via the comments or on Twitter if you find some replacement images!
***UPDATE***
My friend Doug provided some drop-in replacement images that are a huge improvement. Just drop them into the directory after renaming the default images. So after step #3 above, do:
This will open Finder in the current directory. Now drag the replacement images into this directory, provide your password, and kill the Dock.
VoilĂ !
DOWNLOAD HERE
Posted: August 24th, 2009 | Author: Jerod | Filed under: Ruby | View Comments
A lot of people end up writing Ruby methods that looks something like this:
def stop_error(message)
puts "ERROR: #{message}"
exit(1)
end
Which they call in their app like so:
stop_error "Oh noes, file doesn't exist!" unless File.exist?(file)
I used to write that method a lot too. Did you know Ruby has a built-in method that provides just what we’re all looking for?
Kernel::abort
So, stop writing your own little method and just abort it:
abort "Oh noes, file doesn't exist!" unless File.exist?(file)