a huge beanie is approaching fast 1

Posted by s.f. on November 25, 2008

In Rails, one form helper(well, besides a broken date_select) stands alone as cruel, sadistic, and impossible-to-please with just a simple hash. That form helper’s name: option_groups_from_collection_for_select.

It’s so painful that most people would re-implement it, rather than fall victim to its NoMethodError wails. But that’s not the path for us. When you’re using something like Base Without Table to clean up your email contact forms, you don’t have time to mess around with o_g_f_c_f_s’ hunger for has_many. That’s when you pull out OpenStruct, and cleave the beast in twain.
Continue reading…

Builder, indentation, and namespaces

Posted by s.f. on September 04, 2008

Builder is a neat piece of kit but, like most sane libraries, wasn’t designed around the brain-damage that is Business-dialect XML(chock full of custom namespaces and tags devoted solely to attributes).

Builder’s docs seem to imply that a namespaced tag always needs to be in block form:

xml.bqcm :UselessMetadata {|n| n<< "flue"}

or

xml.bqcm :UselessMetadata do xml.text!("flue") end

But you’ll end up with wonky indenting because Builder is sensibly expecting that you should take care of the whitespace yourself when using this form:

<bqcm:UselessMetadata>
flue
</bqcm:UselessMetadata>

The clean way to do it is giving the symbol as the first argument:

xml.bqcm(:UselessMetadata, "flue")

which provides:

<bqcm:UselessMetadata>flue</bqcm:UselessMetadata>

EDIT(2:18pm)
“But what if I have attributes AND a simple text value?”
Just make sure the attributes are sent in an explicit hash as the second parameter:

xml.bqcm(:UselessMetadata, {:QuestionableAttribute=>"chimney"}, "flue")

“I still want to send my text like I was doing, and I want proper indenting NOW NOW NOW”
Fair enough:


xml.bqcm :UselessMetadata do
xml.__send__ :_indent
xml.text!("flue")
xml.__send__ :_newline
end

God, sphinx, and you

Posted by s.f. on April 15, 2008

god is my newest favorite tool for server and Rails monitoring, not to mention the entertaining conversations it can produce(”God was spanking the mongrels repeatedly, without letting them fully start”, “god spammed my mailbox with over 700 emails this weekend”, “I’m killing god right now, it should be back in a minute”). One of the last pieces I forgot to include in this setup was Sphinx and, in an apt demonstration of Murphy’s law, it decided to silently die this weekend while I was out of town. So the first thing I did today was to let god manage it as well.

One hurdle people might run into is whether to let god auto-daemonize the process(a useful feature indeed), but our hand is forced by Sphinx already daemonizing itself along with its own PID file(trying to let both god and a process daemonize itself is pretty much crossing the streams). Fortunately, sphinx provides its own “stop” command so we don’t have to go crazy trying to lookup a PID in our god config:


w.start = "searchd -c #{RAILS_ROOT}/config/#{RAILS_ENV}.sphinx.conf"
w.stop = "searchd -c #{RAILS_ROOT}/config/#{RAILS_ENV}.sphinx.conf --stop"
w.pid_file = File.join(RAILS_ROOT, "log/searchd.#{RAILS_ENV}.pid")
Easy peasy. I absolutely adore god's ability to plug into the event system on OSX, so between god and launchd, I've almost got a bulletproof config[1].

[1] “bulletproof” for the value of “resists .22 rounds hand-thrown at it by a grade-schooler”, mind you.

audio surfin’, across the universe

Posted by s.f. on February 16, 2008

So the public version of Audio Surf has just been released as a Steam app. As you can see, it’s already becoming addictive for replays in addition to beating other people’s high scores(someone’s already beat my score on Deltron 3030’s “Battlesong”).

Of course, there’s potentially one problem for some people: the default distribution is not compatible with Windows 2000. Rather than being the use of an XP-exclusive technology, it’s because of the XBox360 pad support, the DLL of which is compiled against a slightly higher DirectX version than Microsoft allows for Win2k. Fortunately, there’s a quick way to fix it if you don’t mind doing some hex-hacking.

Standard disclaimers: do this at your own risk, not my fault if your computer bursts into flames while the “Psycho” shower-scene music plays, etc.

0. If you don’t have a hex-editor, I recommend HxD.
1. From the root of your Steam directory, find this file: SteamApps\common\audiosurf\engine\xinput1_3.dll
(it’s probably wise to copy it somewhere as a backup, just in case). Open the file with your hex-editor.
2. Find the string “TraceMessage”. There should be exactly one occurence.
3. Replace it with “GetUserNameA” (case is important). Save the file.
4. Start Audiosurf, and you should be good to go!

Now, to start working through my JAM Project songs..