01. February 2016

Getting a sum of durations in rails

For my “I had trouble finding this on google” series, here’s a solution I found to getting a total duration from a collection of objects with durations stored as Time objects.

total_duration = durations.reduce(Time.gm(2000)) do |total, time|
  total += time.to_i
end

There are two little tricks happening here. The first is that durations are stored as a time of day on January 1st, 2000, so we use that as the reduce seed. The second thing is that the Time class defines addition for integer objects, but not for other times, so you have to convert your duration to an integer first.

No rocket science here, but a couple little quirks that made it a little harder to add two times together than I expected.

23. January 2016

Brainfuck Interpreter

Every programmer has some level of interest in knowing how to write a language. I’ve always wanted to tinker with this level of software development, but even after years of development experience you never really get exposed to this stuff because what’s already there generally just works. On top of that, it’s a somewhat complex process involving several steps with intimidating terminology.

more

28. November 2015

Republished

My old “attach a camera to your RC car” tutorial has been republished into a “1-2-3 Projects” anthology by maker media.

more

11. October 2015

Converting strings to bf code

I was playing around with the esoteric programming language brainfuck. I found that it was pretty time consuming writing out strings of text using only increments and decrements of the data pointer.

So I decided to write a bf string maker in go. Code generation is pretty important in go, so it is fun to generate code for another language using go.

more