Archive for February, 2009

Handling line endings in Ruby on Rails

Tuesday, February 24th, 2009

I’ve been working on a Rails app that automatically builds shell scripts. It pulls a bunch of prewritten code out of an SQLite database and writes it out in order to a text file.

Only problem is there are some rouge line ending sneeking to the database. I’m developing on Solaris 10 where the default line ending is a line feed character (LF, 0×0A). For reasons I don’t understand, Rails and/or SQLite is using an LF CR combination on all of the code that was entered through a text field and saved to the database. When it gets spat back out into the shell script text file and I try to execute it, Korn chokes. Korn expects LF line endings in text files and that’s all there is to it.

After poking around to uncover where the line ending might be being set, I decided it’d be easier to tweak the three places in the Ruby script where code was being outputted to the text file and modify the line ending there.

finalscript << assertion.snippet.code.delete("\x0D") << "\n"

Essentially we’re deleting all of the CR characters from the chunk of code, leaving just the LF which keeps Korn happy.

I’m not totally happy with it as a solution, but it works, it was fast and cheap and solves something that probably doesn’t affect too many people.


				

Seven days without caffeine

Tuesday, February 24th, 2009

Seven days in to my caffeine free period of life (yes, it’s a period, not permenant) and I think I’ve gotten past most of the feeling like rubbish stages. At the very least, I’ve been able to function at work without feeling like the living dead, and actually written some decent code and solved some problems. All without caffeine. Amazing!
Some observations, in no particular order:

Detoxing is sneaky

When you’re used to operating with a lot of caffeine in your system, you know when it’s time for a top up. Hrm, feeling snoozy. Coffee. Fuzzy, coffee. Needing a moment of clarity, RedBull. When you’re getting used to not having that, the downward slides can be sneakier. I’ve been careful about getting plenty of sleep, but the effects are outworking in other ways. I’ll feel grumpier. Or unsettled. Headachy. Whatever it the problem, they sneak up on me, starting out fairly mild going from there. It just makes everything harder. I’ve found there to be three go to options (as opposed to one previously, have a coffee…).

  1. Go to bed. Obviously I can’t do this at 11am, but a lot of the time it’s happened after 8pm, so just getting ready for bed has definitely helped. The extra sleep certainly helps.
  2. Berocca.  This stuff is awesome. It’s a big cup of fizzy-make-better without the inevitable sugar/caffeine crash. Not sure what an excessive dose would be. I’m doing 1-2 per day.
  3. Walking & exercise. Moving around seems to help feel less crap. I’m sure if you looked you’d find someone authoritative saying that exercising releases endorphins. I’m sure it does. For me, lifting heavy things or going for a walk to the shops puts me in a better mood, and if I was feeling tired before, I’ll still be tired, but satisfyingly tired. I lifted heavy stuff. I deserve sleep.

Coffee isn’t just a drink. It’s a social object.

Chemical stimulation aside, I’ve missed the social aspect of coffee. It’s not just something I drink. Coffee is something I do. With other people. I’ve found I’ve skipped oppportunities where I would have gone out for coffee with folks, instead opting to stay in. Bummer. Sure, there are other drinks which would substitute. But at the moment, coffee is still a major social motivator for me.

As an aside, I really miss Starbucks in this town. For me, they had the social factors figured out. Can’t think of anywhere else around here that fills that gap.

    On the whole I’m really quite happy with how it’s all going. In a couple of weeks I plan to have coffee again, but only for social purposes, not as a productivity crutch.

    Bugger

    Saturday, February 21st, 2009
     /></a></p>
<p><span style=Bugger, originally uploaded by geoffconet.

    Saw this unfold at the Carillion as we were sitting on the other side of the lake.

    There was nothing I could do except take some pics, and definitely nothing they could have done. By the time they got to the bike, it would have caused more injury than anything to try and stop it.

    Not much you can do except laugh about it. And hope they hose themselves down – the lake has been closed for the past 2 weeks due to blue-green algae infection… Yikes.

    Living in a world without caffeine

    Friday, February 20th, 2009

    This week, for the third time in my life, I’ve quit caffeine. For plenty of people, this wouldn’t be a big deal. For me, it is. And it’s that very fact that it is a big deal which is prompting me to quit.

    (more…)