Saturday, January 12, 2013

New Album: A Sine of the Times

Sunday, January 6, 2013

Almost Anything in Ruby can be a Hash Key

This was a definite huh / aha moment - finding the idiomatic Ruby way to solve a typical problem, in this case, taking an array of objects, and grouping them in a hash so that each element in the hash was all of the objects belonging to a particular user. You could parse out some unique value from your user object (which was the brain-damaged PHP way I had been thinking of this problem) and use that has a hash key:
#ugly
slug = (post.user.name +" "+post.user.id.to_s).to_sym
posts_by_user[slug] << post
When it turns out that you can use objects themselves as hash keys in Ruby, and then use the Hash.keys method to grab those objects back when you need them. So if you had a Post, which belonged to User, and you wanted to get them all and group them by user (assuming that your ORM or whatever won't do it for you in this instance):
posts = Post.all
posts_by_user = Hash.new {|h,k| h[k]=[]}
posts.each do |post|
  #if there is no entry for this user, create one with an empty array
  posts_by_user[post.user] ||= []
  #shovel the post on to the group for that user
  posts_by_user[post.user] << post
end
Iterate through them like this -
posts_by_user.keys.each do |user|
  #the user object
  p user.inspect
  #referencing the hash with the user object as key
  posts_by_user[user].each do |post|
    #each post belonging to that user
    p post.inspect
  end
end

Thursday, October 11, 2012

Apache Benchmark Tips

Apache Benchmark (ab) is a great tool for doing quick load testing on websites. Here's a patched version that will let yourun apache benchmark against different pages on your site in the same batch (not just the homepage). Found via Rainbow Chard

Tuesday, July 24, 2012

Working with Node.js

Been working with node.js for the past week.  Going to start with some simple things like a Rock, Paper, Scissors game.  I'd like to try some music, using node to send OSC.  Here's an example (not mine) of using node.js with a monome:

Thursday, July 12, 2012

I Put an Album on Bandcamp

"Pythagorean Clouds" on Bandcamp

Because sometimes I do actually record "albums".  Used to alot more, back when I was doing more beat-oriented stuff with Buzz.  I might put some of those older things on Bandcamp too.  Since Bandcamp caps the song length for new users at 26 minutes (with some snark about jam bands and "Serious Ambient Composers" (ahem) on top of that) there's not that much that I've recorded in the last 5 years that I can post.  

Anyway, "Pythagorean Clouds" is a collection of shorter pieces I wrote last summer, inspired by seeing a Pendulum Video I had seen on BoingBoing.  That led to developing a new "instrument" based on stacking up tones with amplitude oscillators and playing cyclical sounds, as opposed to the very linear stuff I had been doing involving factors of integers.  There are some pieces in there too involving modulated sine waves that were inspired by trying to compose 140-character drones that I could fit into a Tweet.

I might post some other older stuff on Bandcamp, or some excerpts of newer stuff.

Monday, July 9, 2012

Using Git for Things Besides Code

Does anybody out there use Git for other work / projects beside writing code?
I use it to keep backups of prose text that I write (journals, stories, essays, etc, though not this blog).
There are projects out there that use Git for blogging, like  How to Node - just fork the blog, commit your article, and send a pull request.

There's also Octopress - which combines Git with Ruby to make a blogging engine.  Since Backtrace.us runs on Sinatra, and I'm starting to use a lot of custom css and html in this blog, I'd probably be better off moving my blog off of Blogger and onto a self-hosted system like Octopress.  (Then again, I've been on Blogger for almost 12 years, and the convenience is nice.)

Is anyone using Git for revisions with binaries?  Keep a repository of psd's, pdf's or word doc's ?  When I set up a repo for work projects I usually include an "assets" directory where I put things like wireframes, comps, and specs (pdf's and psd's mostly) and then commit them as revisions happen to the project docs, instead creating the anti-pattern of tracking revisions thru filenames - nothing drives me crazy like going into a project directory and seeing files with names like "Wireframes-0612-version2-final-final.pdf"

Anybody do any other crazy things?  Commit and rollback your Redis cache? Track revisions to audio / video files you're editing?  Leave a comment if you do...