class String def -(other) self.index(other) == 0 ? self[other.size..self.size] : nil end endThis snippet gives the Ruby String class a minus operator. Which works like> 'abcde' - 'abc'=>...
more
Usually when I am prototyping a web UI - either in Javascript or Flex, I would just write a static html, because that's the simplest thing that works. But, once in a while, it doesn't work because of...
more
I came across this interesting gotcha while debugging through someone else's rails code. When you set a model's one-to-many attribute(an perhaps other association types as well), let's...
more
Python has multiple inheritence - a feature that's really handy because it allows the programing idiom called mixins - where you write a a bunch of methods on a "mixin" class and then later on...
more
Okay, so in ruby:>> nil or 'value'=> "value"because nil acts as false when used with boolean operators and any other object acts as true. Now let's assign the result to a temp variable a:>> a =...
more
I've been a user of Turbogears for 4 months now, working on a client facing app. The app has not gone production yet, so I don't have much insight on deployment, but I have a lot of experience on the...
more
In Javascript:myfunction.toString()This gives you the entire definition of the function as a string, with which you can parse to get the argument names, or in prototype.js you can just...
more
First, let me define what I mean by safe: the earlier a programming language catches a programming error for you, the safer it is. Haskell is extremely safe, whereas php is extremely unsafe. Some...
more
I have been making the same mistake a few times recently: instead of writingthings.each do |thing| ... endWhere things is a method, not a variable, I would write:things do |thing| ... endwhich has...
more
After learning of growl from Micah's post, I decided to port it to the windows equivalent: snarl. It was pretty easy:Follow Micah's instructions except for the growl bitsInstall Snarl from their...
more