Programming

Musing, prognostication, and other pretentious activities as they relate to programming.

Zombie Songs

For all those times when you’ve been thinking to yourself “Man, this would be the perfect situation in which to play a zombie song,” I’m glad to say modern independent musicians have stepped up to fill this gap:

Further zombie song recommendations are welcome in the comments.

0 comments

Posted by Calamitous on Sep 22, 2009

A More Effective Name

A quick note:

If you are:

  • Using Rails
  • Using RSpec
  • Have just discovered the incredible joy of named scopes

…restrain yourself, by any means available (up to and including physical violence) from creating a named scope called “public” or “private.” The reasons for this should be fairly obvious.

Really, whoever ends up cleaning up behind you will appreciate it.

0 comments

Posted by Calamitous on Aug 18, 2009

Annihilate Ubuntu’s Annoying System Beep

A quickie to remind myself next time I build an Ubuntu box, and am being slowly driven batty by a tiny, tinny obsolete PC speaker made of hate:

sudo gvim /etc/modprobe.d/blacklist

(or /etc/modprobe.d/blacklist.conf, for Ubuntu 9.04) …and add the following line:

blacklist pcspkr

From the command line, kill it in the current session:

sudo rmmod pcspkr

No more waking the baby with late-night hacking sessions!

0 comments

Posted by Calamitous on Jul 09, 2009

Select Tag Funkiness With Merb

In my ongoing travails with Merb & Friends, I’ve run across a few behaviors with the select() form helper method. Since there’s currently a dearth of examples, I thought I’d document them for myself and future googlers.

Continue Reading…

6 comments

Posted by Calamitous on Jan 18, 2009

A Rails Developer Spends One Week With Merb (and HAML and JQuery and DataMapper)

Developers often talk about some hot new technology they plan on spending time with, but very rarely do they ever get around to it. I’m ordinarily in the same boat, but last week I had a new personal project crop up for a simple web application (5-6 models) which was an ideal candidate for testing out a slew of new tech that I’ve been meaning to get around to.

Merb, an erstwhile competitor to Rails, has been making a big splash lately. I decided to step out of my comfort zone of Rails/Acti* and into the wild and woolly world of young, cutting-edge frameworks. Since I’m undergoing the pain of learning a new framework, I figured I’d go whole hog and use Haml, jQuery, and DataMapper, as well.

Before last week, I’d never done much more than spin through the initial tutorials for any of these tools. That being the case, I can’t really speak to performance, deployment, or any of half-a-hundred other critical issues to consider when selecting a framework– this is strictly a shallow, first-impressions review.

I welcome comments and corrections to my observations, and suggestions for easing some of the new-developer pain.

Continue Reading…

3 comments

Posted by Calamitous on Jan 08, 2009

If You Like Lyrical Code…

Osake reminded me this morning that I hadn’t posted this one up yet…
1
 
2
3
4if (self =~ /pina coladas/ && Rain.caught(self)
    && !yoga.include?(self) && self.brain == 0.5)   Personals.answer   self.relationship = :train_wreck end
Continue Reading…

1 comments

Posted by Calamitous on Dec 07, 2008

Bank of America: Bad, Bad, Bad

So, yeah, this is going to be a little ranty; feel free to skip it if you like Bank of America, or just don’t feel like hearing a windy blowhard spouting bile.

I’m not going into the many reasons I decided to close out my Bank of America account, just the representative experience of actually doing it.

Continue Reading…

38 comments

Posted by Calamitous on Nov 24, 2008

Code Lyrical Umpteen-something…

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19class MaryMoon < Vegetarian

  def initialize
    @ttl = 2_524_554_080
    doowop
    @loves = Miso.new
    @alone.ambivalence = false
  end

  def eat(type)
    doowop
    raise ArgumentError if type.is_a? Meat
    return sho_like() if type.is_a? Bone
  end

  def doowop
    Thread.new { 3.times { 'Mary Moon' } }
  end
end
As always, jump for answers! Continue Reading…

0 comments

Posted by Calamitous on Oct 30, 2008

Mysterious, Incomprehensible Capistrano Errors

So yesterday a co-worker and I were fighting fires in our Capistrano deploy scripts. We’d been updating a crufty monstrosity of a cap script, and were getting an error along the lines of:
uninitialized constant #<Class:0x7f3230382cf0>::Capistrano::Deploy
After half a day of rolling back every single change we’d made to the scripts in the last week, we discovered a small junk file with some test code we’d stuck in the ‘lib/recipes’ directory. It was getting included even though it was not ‘require’d anywhere.

PROTIP: CAPISTRANO INCLUDES EVERYTHING IN THE ‘lib/recipes’ DIRECTORY BECAUSE IT HATES YOU.

Also, it saves typing maybe three lines of code.

0 comments

Posted by Calamitous on Oct 29, 2008

Berceuse Code Lyrical

Somewhat in the same vein as our last one:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32def Son
  def pray(beneficiaries)
    unless beneficiaries.uniq.size == EVERYONE.size
      raise(ArgumentError, "Prayers should include everyone!")
    end
    @prayed = true
  end

  def tuck
    if @prayed
      internal_temperature = 99.9
      @sin_free = true
    end
  end

  def sleeping
    unless @eyes_open >= 1 && @pillow.gripped?
      @anthropomrphic_personification = Sandman.enter
      @sin_free = false
    end
  end
end

def Sandman
  def enter
    Light.exit
    Night.enter
    Hand.take
    never_never_land(:off)
    self.new
  end
end
Continue Reading…

0 comments

Posted by Calamitous on Oct 17, 2008

Brainmallows

I love these things. They’re all filler and no meat, like marshmallow sandwiches. Which are also delicious.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23class Jungle
  attr_reader :fun, :games, :everything_you_want

  def welcome(new_user)
    self.new(new_user)
  end

  def initialize(new_user)
    (@@names ||= []) << new_user.name
  end

  def find(needs_query)
    return "Whatever: #{needs_query}"
  end

  def receive_money(amount)
    # TODO: this may be returning an unwanted value
    # check with Jim in accounting
    return :your_disease if amount > 0.0
  end
end

Jungle.welcome(honey)
Answer after the jump. Continue Reading…

0 comments

Posted by Calamitous on Oct 14, 2008

Your Buddhism is Indistinguishable From Its Surroundings

1
2
3
4
5
6
7
8MY_DREAM = ['red', 'gold', 'green']

def karma.chameleon
  2.times { you.action(come && go) }
  Loving.type = :easy if you.colors == MY_DREAM
end

([karma] * 5).map(&:chameleon)
Continue Reading…

0 comments

Posted by Calamitous on Oct 10, 2008

Stop That

I’m compelled to highlight a gem I found in our codebase the other day. If you ever find yourself writing something like:
1variable == value ? true : false
…go sit in the corner and think about what you did wrong.

0 comments

Posted by Calamitous on Oct 08, 2008

Code Lyrical, for the Old Folks

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13def i(arg)
  case arg
    when older.reject(&:my_hair) && years.from_now >= MANY
      send(:valentine, :birthday_greetings, :bottle_of_wine)
  end
  door.lock if Time.now >= Time.parse('2:45')
end

def need(age)
  age <= TOO_OLD
end

alias :feed, :need
Continue Reading…

0 comments

Posted by Calamitous on Sep 26, 2008

Code Lyrical III

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13class Object
  alias old_is_a? is_a?
  def is_a?(klass)
    if klass == Thing
      return self.respond_to?(:that_swing)
    end
    old_is_a?(klass)
  end
end

if it.is_a? Thing
  8.times(doo_wah)
end
Answer after the jump. Continue Reading…

0 comments

Posted by Calamitous on Sep 20, 2008

Name That Code

1
2
3
4
5
6def hi!
  what = who = 'Slim Shady'

  self.name = [what, who]
  jigga_jigga
end
As before, answer after the jump… Continue Reading…

0 comments

Posted by Calamitous on Sep 16, 2008

RSS Has been de-b0rked

Apologies to anyone who’s tried to use the RSS feeds. They should be fixed now.

0 comments

Posted by Calamitous on Sep 13, 2008

Code Lyrical

So I blame Scotty for this:

1
2
3until WhiteBoy.dead? do
  lay(:down => :boogie) && ThatFunkyMusic.play(:right)
end

Can you guess the song? :) Answer after the jump.

Continue Reading…

0 comments

Posted by Calamitous on Sep 12, 2008

Everyone Gaze in Awe at the New Blog (Post)

Soooo… yeah, I’ve basically failed to do anything interesting with my blog for a while. I have determined that the root cause of this is not laziness, but INADEQUATE SOFTWARE. Thus, I’m switching from Mephisto to Radiant.

Mephisto is OK, but on a lightweight VPS slice like mine it fills the RAM, settles itself comfortably onto the swap partition, and stays there eating all the chips and never cleaning the toilet. Also, the Mephisto guys make releases somewhat less often than I post, so it’s not exactly fresh software.

Anyway, welcome to the new blog! Please be patient while I work out the kinks.

0 comments

Posted by Calamitous on Sep 07, 2008

Them what deals with th’Devil…

With my recent spate of GServer problems, I thought I’d post something that, surprisingly, turned out not to be much of a problem at all: turning a Ruby GServer into a Windows service.

Continue Reading…

0 comments

Posted by Calamitous on Apr 26, 2007

More GServer Goodness

In a previous posting, I demonstrated how to create a telnet server from a Rails application. After having actually used GServer in anger, I can add a few notes to it:

ACCESSING YOUR SERVER REMOTELY

Continue Reading…

2 comments

Posted by Calamitous on Apr 15, 2007

Multi-line strings in Ruby– I Love Carriage Returns!

If you’ve ever done any serious development in VB or the old VBScript, you’ve probably done something like this:

strSQL = "SELECT o.* " & _
         "FROM people p " & _
         "INNER JOIN orders o " & _
         "ON o.person_id = p.id " & _
         "WHERE person_id = " & PersonID & ";"
Continue Reading…

4 comments

Posted by Calamitous on Apr 09, 2007

How to Turn a Rails Application Into a Telnet Server in 30 Lines of Code!

Ruby on Rails is a beautiful thing; simple, fast, and powerful. As they say, it takes the pain out of web development.

I’m fortunate enough to have been able to use Rails at work for a few months now, and the more I learn about the Rails framework and the Ruby language, the more enamoured I become of the simplicity, beauty, and zen-like nature of these tools. But you didn’t come here to see me gush with adoration like a schoolgirl at an Elvis concert, you came to see:

How to Turn a Rails Application Into a Telnet Server in 30 Lines of Code!

Continue Reading…

0 comments

Posted by Calamitous on Apr 09, 2007


Older articles…