As part of some Ruby-Processing work I’m doing, I needed a random number within a specified range. Processing has its own random function, but I wanted to use Ruby.
I needed a random number in the interval (-range, range). I immediately thought, “specify the max value range*2 as a param to rand, and then subtract range to get it into the interval -range to range.” My autopilot first attempt yielded:
num = rand(range*2.0) - range
However, I didn’t read the documentation for Kernel#rand closely. According to the docs, the max parameter is converted to an integer:
I keep forgetting where this is. It’s Thomas Keller of the French Laundry, Bouchon, and Per Se. The voice-over inflates the sandwich (world’s greatest?), but it does look mighty tasty.
I’m a big fan of Processing, and who can complain about a project involving dancers, a choreographer, and a programmer? I love the pong part. I gotta defrost my projector sometime and see what I can do with it.
I use the iTunes Store as a way to find and preview music, and I’ve purchased quite a bit of music and TV shows through it. I’ve seen several cases where music has been mis-labeled or mis-categorized. For example, the last two albums on this page for the UK band XTC:
I’m not the only one who noticed this particular problem. More…
I needed to batch compile some files recently, and I had to lookup how to do this with Aquamacs. It’s pretty simple. If Aquamacs is at /Applications/Aquamacs, then this will work:
Doesn’t everyone have concepts that they can’t keep organized in their heads? I frequently get values for certain keys mixed up in my head, especially ones that I don’t use very often. At the Lone Star Ruby Conference, Greg and I were talking about the triple equals operator in Ruby recently (===), and I confused my notion of it in Ruby with what I thought was its function in Perl. Obviously I don’t use it very much. Hopefully I can clear this up though.
In Ruby, triple equals (Object#===) is, “effectively the same as calling #==, but typically overridden by descendants to provide meaningful semantics in case statements,” based on the Object class documentation. So, for classes like Array, #=== is effectively the same as #==. I say effectively since I haven’t actually perused the source of array.c, though you can see in object.c that rb_equal (===) calls == and then checks id_eq if that doesn’t return true. And in the case of your own objects, triple equals can be used to provide your own equality tests for case statements.
These days I’m working to become proficient in Emacs (I’ve recently switched from Vim, as Greg mentioned on his blog). With that comes all kinds of things like org-mode, yasnippet, and lots of keyboard combinations.
A part of this current effort I’m learning Emacs Lisp right now. There’s probably a better way to do block comment cycling in Ruby, but this was good practice on writing some simple elisp functions.
(defunruby-comment-region ()
"In Ruby, comment out the current region with =begin/=end statements."
(interactive)
(save-excursion
(goto-char (point))
(insert "=end")
(goto-char (mark))
(insert "=begin\n")))
(defunruby-uncomment-region ()
"In Ruby, uncomment the current region -- remove =begin/=end statements."
(interactive)
(save-excursion
(if (re-search-backward "^=begin")
(replace-match ""))
(if (re-search-forward "^=end")
(replace-match ""))))