14 Dec 2009 » Permalink
The most important thing I learned today wasn't about programming: it was about bottled water. Kind of terrifying from a waste level and a health level.
Hi! I'm Clinton R. Nixon, a software developer with Viget Labs in Durham, NC, USA. Below, you can find notes on what I learn each day. You can also look at talks I've given, articles I've written, or learn more about me.
The most important thing I learned today wasn't about programming: it was about bottled water. Kind of terrifying from a waste level and a health level.
This post from EngineYard on Google Go makes me want to learn it something fierce. I'm planning on curling up with it and Adam Keys' Just For Fun video this cold weekend by a warm fire.
I needed to introspect on a Ruby method and find out the names of its arguments for a project I'm working on, and realized Ruby's own introspection wouldn't let me get this info. After some Googling, I found that Merb has this functionality. I didn't want to include all of Merb in my project, so I've extracted it.
class Dummy
def one_arg(foo); end
def multiple_args(foo, bar, baz); end
def optional_args(foo, bar = 1); end
def star_args(*foo); end
end
Dummy.instance_method(:one_arg).get_args
# => [[[:foo]], []]
Dummy.instance_method(:multiple_args).get_args
# => [[[:foo], [:bar], [:baz]], []]
Dummy.instance_method(:optional_args).get_args
# => [[[:foo], [:bar, 1]], [:bar]]
Dummy.instance_method(:star_args).get_args
# => [[[%s[*foo]]], []]
You can get the gem from Gemcutter.
I love emacsclient for opening files in Emacs from the command line, but closing those windows drives me nuts. I expect it just to work like killing any other buffer. With the help of some Googling, I put together this code today to close client buffers by using C-x k.
(defun close-client-window ()
(interactive)
(if (y-or-n-p "Close client window? ")
(server-edit)))
(add-hook 'server-switch-hook
(lambda ()
(when (current-local-map)
(use-local-map (copy-keymap (current-local-map))))
(local-set-key (kbd "C-x k") 'close-client-window)))
I've been away from this too long, so I've picked a project to give me something to learn each day. I'm building a web-based Roguelike game. I've never built a computer game before, and I've got a lot to learn about sprites, collision detection, map generation, and other stuff.
For today, I managed to build a play area that you can move a character around in. Not impressive, but it's a solid first step. The cool thing I learned about is gameQuery, a jQuery plug-in for developing games.
I am not sure what has gotten into me, but I decided to set up monit on my MacBook Pro. Monit's used for monitoring Unix systems, especially servers and the processes on those servers. I read a presentation on Monit (PDF) that showed me how to monitor files for changes and then execute commands based off that, like reloading Apache whenever you edit your Apache configuration file. And then I thought, "Why don't I do this on my laptop?"
There's only a few steps. The first is getting monit installed. It's not hard, and the tarball; ./configure; make; make install biz should work for you. If you like Homebrew like I like Homebrew, you can grab a recipe from this here commit.
Next, configure monit. I put my monit configuration file in /usr/local/etc/monitrc. I'll show it at the bottom of this post.
My major issue was with mail delivery. If you have a SMTP server you want to use, you're set. If you want to use your OS X box as a mail server, you've got to reconfigure Postfix. By default, it only runs when files are put in /var/spool/postfix/maildrop. Here's my configuration from /System/Library/LaunchDaemons/org.postfix.master.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AbandonProcessGroup</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.postfix.master</string>
<key>OnDemand</key>
<false/>
<key>Program</key>
<string>/usr/libexec/postfix/master</string>
<key>ProgramArguments</key>
<array>
<string>master</string>
</array>
<key>QueueDirectories</key>
<array/>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Learn more about launchd so I won't have to post a giant slab of XML again.
Once I got mail delivery going (you might need to edit /etc/aliases and then run sudo postalias /etc/aliases; sudo postfix reload) and mutt installed to check my mail, which I leave as an exercise to the reader, I was set. I dropped the following configuration in /usr/local/etc/monitrc:
set daemon 120
set logfile syslog facility log_daemon
set alert cnixon@localhost
set mail-format { from: monit@moro.local }
set mailserver localhost
set httpd port 2812 and use address localhost
allow localhost # Allow localhost to connect
check directory vhosts path /etc/apache2/passenger_pane_vhosts
if changed timestamp
then exec "/usr/sbin/apachectl graceful"
check directory apache_conf path /etc/apache2/other
if changed timestamp
then exec "/usr/sbin/apachectl graceful"
check file monitrc path /usr/local/etc/monitrc
if changed timestamp
then exec "/usr/local/bin/monit reload"
check device MacintoshHD with path /
if space usage > 90%
then exec "/usr/local/bin/growlnotify -m \
'Your harddrive is getting full' 'MONIT SAY'"
Check out the PDF presentation above, or the Monit documentation if a line doesn't make sense. The summary:
When I add or remove any files from /etc/apache2/passenger_pane_vhosts or /etc/apache2/other, Apache gets reloaded. I'd like it to do this whenever a file is changed in either one, but monit doesn't easily support file globs. Maybe I should write a script to write my monit conf.
When I change monitrc, monit reloads it.
If my hard drive starts to get full, Growl tells me about it.
Check out my post on MongoDB and MongoMapper at Viget Extend today.