Aaron Van Bokhoven

I am a Hawaii based Software Developer and a Film Photographer.
  • I love coding with Ruby and Ruby on Rails, and I love shooting with film.
  • I've started to work more with Ember.js and Backbone.js.
  • I currently live in Honolulu, Hawaii, but frequent Chicago and California.
  • I believe that programming is a form of art, like painting and photography, where you can express your ideas and logic and see it transform into something real.
Aaron Van Bokhoven
Email me at bokhoven@gmail.com. View my Photo Blog. I'm also on Twitter.

My current work:

Hawaii Photo Rental
http://www.hawaiicamera.com
Buoy Alarm
http://buoyalarm.com
Flux Hawaii Magazine
2011 - Summer, Fall, Winter(cover)
2012 - Spring, Fall, Winter
2013 - Spring
http://fluxhawaii.com

Open source contributions:

Coffee-Resque (my fork)
https://github.com/aaronvb/coffee-resque
Pow
http://pow.cx (github)
My Gists
http://gist.github.com/aaronvb

You can also find me at:

Github
http://github.com/aaronvb
Photography portfolio
http://aaronvb.com/photo
Junkparty
http://junkparty.com
Flickr
http://flickr.com/photos/aaronvb


May 11, 2013

My SO and I decided to create a small DIY cheap-as-possible aquaponics project. She was inspired by the Kapiolani Community College garden, which has a pretty significant aquaponics system.

I have no experience with gardening, other than growing a few tomatos and herbs at my parents house. My SO has much more knowledge in that area. I do however, understand the basic concept of an aquaponics system(thanks to Google), and basic knowledge of a bell siphon, which I'll go over in a bit.

With the design left to me, we headed to Home Depot for supplies. We picked up two small plastic bins, one being almost twice as large as the other. We wanted to go with a 1:2 ratio of grow bed to fish tank. We also grabbed 15ft of white 1/2" PVC, a valve, a 1" to 1/2" adapter for the bell siphon, 1ft of 3" PVC for the shield, and numerous fittings such as a 90 degree, 3 way splitter, and 45 degree. For the grow bed we use a charcoal type grow media that was suggested to us from our local hydro/aquaponics store. We also picked up a small pump from them.

My first idea was to have the pump move water over the grow bed and empty it through holes in the pvc pipe, and at the end have it circulate back into the fish tank. Seen below:

This however, wouldn't work because I wasn't able to control the flow into the bed. So I decided to go with a 3 way splitter to control the pressure of the pipe carrying the water up to the bed. The released water pressure would go back into the fish tank, while also aerating it for the fish. This seems to be pretty common in aquaponic systems. Shown below is the updated version.

For the bell siphon design, I use a 1/2" to 1" PVC adapter. This provides enough high pressure inside the pvc pipe to cause the siphon to start. For the bell part of the siphon, I use a starbucks glass bottle. Why do I use a starbucks bottle as the bell? It fits perfectly, and it being transparent helps me diagnose problems with the siphon, such as clogs. It was also free. To allow water to flow under the bell and into the top of the siphon, I have a loose zip tie sitting at the bottom that keeps the bottle off the floor.

To be continued in part 2, where all our fish die, upgraded parts, and a new design.


April 20, 2013

Lately during my free time I've been reading through sorting algorithms for fun and decided to implement several in Ruby. I'll be posting each one in a separate article as I go through them.

Here's a bubble sort in Ruby.

Bubble sort is a pretty fun and easy sorting algorithm. For each pass through an array of values, each value is compared to its adjacent value and swapped into the correct order and so on. Worst case is O(n^2) and best case is O(n) if the array is already sorted.

Let's start with the test.

In the test I create an array of random numbers and assert_equal to the result of the bubble sort.

Next the code for the bubble sort.

I use recursion for each pass until swapped is equal to false, which means that the array is sorted.


January 16, 2013

I recently made the move from Linode to Heroku for my personal sites. The last time I checked out Heroku was about 2 years ago, which I later dismissed because at the time it seemed like having your own VPS was the right thing to do.

Having your own VPS sounds good in theory, but in reality it's not, for me at least. I liked being able to throw up random projects, host my friends projects, and tinker with new frameworks and languages. I maybe did that once or twice out of the 4 years I had my own VPS. In reality, I'm way to busy to do any of that. I started to get lazy on updates, and security patches. The traffic my personal sites receive are so minimal they don't need a VPS.

After my week at the Aloha Ruby Conf, I noted to myself to check out Heroku once again, to see what has changed. To my surprise, A LOT has changed. There's the new cedar stack, updated gem which is really awesome to use, procfile, etc, I could go on.

Anyway, I read through all their documents, which are amazingly good, and then signed up to try their free tier, 1 Dyno, which seems like a perfect size for my site.

The first thing I had to do was switch my applications database from MySQL to PostgreSQL because Heroku has native support for PostgreSQL. You can use MySQL through one of their add-ons if you wish.


# gem 'mysql2'
gem 'pg'

Then I got my site up on Heroku by logging in and deploying.


$ heroku login
$ heroku create
$ git push heroku master
$ heroku run rake:db:migrate

I really like Unicorn(http://unicorn.bogomips.org) as my webserver and was excited to see that they fully support it, and all I needed to do was add one line to my Procfile. I also want to mention that even though 1 Dyno is supposed to only have 1 level of concurrency, with Unicorn I can have multiple concurrency.

Add Unicorn the Gemfile.


gem 'unicorn'

I added a Unicorn config file to my project by creating config/unicorn.rb. In the file I can configure the number of workers and timeout.


worker_processes 5
timeout 30
preload_app true

before_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end

# If you are using Redis but not Resque, change this
if defined?(Resque)
Resque.redis.quit
Rails.logger.info('Disconnected from Redis')
end

sleep 1
end

after_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end

# If you are using Redis but not Resque, change this
if defined?(Resque)
Resque.redis = ENV['REDIS_URI']
Rails.logger.info('Connected to Redis')
end
end

Now that Unicorn is set up, Heroku needs to use Unicorn instead of its default web server. To tell Heroku to use Unicorn, they've provided the Procfile. I created a file named Procfile in the project root directory. Inside the web server can be configured.


web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

After that's pushed to Heroku, I can check to make sure Unicorn is running by using $ heroku ps.


$ heroku ps
> === web: `bundle exec unicorn -p $PORT -c ./config/unicorn.rb`
web.1: up 2013/01/16 14:21:20 (~ 1h ago)

I also needed access to cron or something similar to schedule my nightly Rake that updates the photos on the front page to my latest Flickr photos. Once again that took me a few minutes to set up through their web interface.

First I created my rake task in lib/tasks/flickr_update.rake. It's a simple script that updates a table with the last 3 photos I posted to flickr. I'm using the gem 'fleakr' to do this. I have a RecentPhoto model that has the attributes: title, url(url to the photos flickr page), image_url(url to the exact location of the image file).


namespace :flickr do
desc "update flickr photos on index page"
task :update => :environment do
Fleakr.api_key = 'xxxxxx' # replace with your Flickr API key
user = Fleakr.user('xxxx') # replace with your Flickr Username
RecentPhoto.destroy_all # remove all photos from table
3.times do |num|
photo = user.photos[num]
image_url = photo.medium.url
image_url = image_url[0..-5] << "_q.jpg" # using the q version of this photo which is a square thumbnail.
RecentPhoto.create(title: photo.title, url: photo.url, image_url: image_url)
end
end
end

In the Heroku web application settings add the Scheduler add-on. Then add the heroku run command for that rake task.

That pretty much covers my move from Linode to Heroku. I highly suggest reading through the Heroku documents.

Side note: The only downside to Heroku that I encountered was not being able to write to disk. Since my site is entirely static, the comments are javascript, I relied on page caching to keep the load time fast. When I switched to Heroku I had to disable page caching because I'm not able to write to the cached html pages to disk.


December 14, 2012

Yes, you can use the Seagate STAE128 Thunderbolt Adapter for Backup Plus with any SATA external 2.5" Hard Drive. You can also use the STAE121 but I've read that they discontinued that for the newer STAE128.

Here's a little review on my experience with the Seagate STAE128 Thunderbolt Adapter and a bare 2.5" SATA external hard drive. Since switching over to the Macbook Pro Retina with 256gb SSD, I've been a little worried about my hard drive space.

Coming from the regular Macbook Pro with a 750gb hard drive I wasn't used to worrying about space. I had to move all of my music to an external and reduced the amount of photos I could work on at a time. Since I scan my photos to raw uncompressed TIFF files at a fairly high DPI, the files are quite large. I used to keep about six months to a years worth of scanned negatives on my laptop at a time, and moved anything older to an external. With only 256gb to spare I'm limited to maybe half of that.

So my research started when I was looking into an external in which I could use to edit directly on and was portable. This required something fast and small. I looked into USB 3.0 and Thunderbolt, to which the later provided minimal results. The best I could find were 3 or 4 heavy options for Thunderbolt external hard drives at really steep prices, considering I could buy a 1TB USB 3.0 portal external for a hundred dollars.

After more research I came upon the Seagate Thunder Bolt Adapter, STAE 121, that would allow me to convert the Seagate enclosed external drives to Thunderbolt. A little more googling and I found out I could actually use the STAE 121 with a bare 2.5" SATA hard drive. A little skeptical at first mostly because of the lack of people talking about it on the internet, I went to Best Buy to see if they had it in stock.

When I got there I found the newer version, the Seagate Thunderbolt Adapter For Backup Plus, or STAE128. A little confused, I tried to google it but found nothing. I bought it, and a Thunderbolt plug by Apple.

STAE 128 Seagate Thunderbolt Adapter for Backup Plus

STAE 128 Seagate Thunderbolt Adapter for Backup Plus

At first I thought I would need to use a SATA cable to connect my hard drive, but it actually plugged right into it.

STAE 128 Seagate Thunderbolt Adapter for Backup Plus

STAE 128 Seagate Thunderbolt Adapter for Backup Plus

STAE 128 Seagate Thunderbolt Adapter for Backup Plus

I'm using a Seagate Momentus 7200rpm 500gb hard drive which I pulled from my old Macbook Pro. I don't have any benchmarks from when that was installed internally, but I did find a few through google and this seems to be about the average, http://jasontomczak.com/2009/06/macbook-pro-and-the-seagate-momentus-500gb-7200rpm-drive/.

My results using the same hard drive and the Seagate Thunderbolt Adapter STAE128 were very close to that.

Seagate Thunderbolt Adapter for Backup Plus STAE128 Benchmark

Compared to my 2TB Western Digital External HDD USB2.0.

and for fun, compared to the internal 256gb SSD that's inside my Macbook Retina.

Macbook Pro Retina 256gb SSD Benchmark

Overall I'm definitely happy with the STAE128. I get to use my SATA 2.5" hard drives that I have laying around, I get speeds that match internal speeds, it's portable and self powered, and best of all it was only $99(+$50 for the Thunderbolt cable). The price alone beats any of the other Thunderbolt options out right now.

Next up, installing and booting Windows 7 off the STAE128 Thunderbolt drive.

UPDATE:

I successfully installed, and am now running, Windows 7 from my Thunderbolt external hard drive. I followed these directions and it worked perfectly.

Windows 7 Thunderbolt STAE128 benchmark


November 29, 2012

Here's an interesting problem I ran into today.

Polymorphic associations in Ruby on Rails are actually quite easy to do, especially in Rails 3.2. If you need a refresher, there's a great screencast over at Railscasts, which does require a subscription which I highly highly recommend: http://railscasts.com/episodes/154-polymorphic-association-revised.

However, my problem was a little different, and maybe a special case because I can't think of many applications this would apply to.

Say I have a Location and a Checkpoint, and the Location and Checkpoint can have notes, posted by Users. I would use a polymorphic association for the Notes to the Location and Checkpoint. But, I also want a single Note, to be posted to many Locations or Checkpoints, which for a single model-to-model relationship I could simply use a join table.

Example, two Locations which are near each other, maybe they're coordinates, could share a single Note describing the general area, and with the same Note model, one Note may describe multiple Checkpoints.

Solution: Make the join table polymorphic.

Notes model that contains the content and user_id, which I use to associate the User model with.

Note join model that is also polymorphic. notable_id and notable_type is the polymorphic attributes used by ActiveRecord.

Next I add the model associations to Location and Checkpoint models.


Above I set the note_joins model as the polymorphic association :notable, which will use the notable_id and notable_type attributes to assign which model and ID the note join belongs to. Then I set the has_many association on the Note model, through note_joins. This will let me use such methods as Location.first.notes to pull up all the notes that belong to that location. The same applies to Checkpoint.

In the NoteJoin model I need specify that it belongs to the notable polymorphic association and that it also belongs to a Note. I do so by adding the following.

Now for the Note model, it should belong to the notable polymorphic association, and also belong to a user(through the user_id attribute).

At this point everything should work, and through the NoteJoin model I can have a single Note belong to many different Locations and even Checkpoints.

Let's quickly test this in console.


> Location.first.notes.create(user_id: 1, content: "foobar")
=> #< Note id: 1, content: "foobar", user_id: 1, created_at: "2012-11-30 02:19:24", updated_at: "2012-11-30 02:19:24" >
> Location.first.notes
=> [#< Note id: 1, content: "foobar", user_id: 1, created_at: "2012-11-30 02:19:24", updated_at: "2012-11-30 02:19:24" >]

Great it works, but now I want to see what Locations or Checkpoints this Note belongs to through NoteJoin. To do that I need to update my Note model to include a has_many locations and checkpoints. Notice I'm using the source and source_type option, to pass my polymorphic association :notable, since that's how we translate which model it belongs to.

And now I can find the locations which my note belongs to.


> Note.first.locations
=> [#< Location id: 1, name: "foobar", created_at: "2012-11-30 02:19:24", updated_at: "2012-11-30 02:19:24" >]

Another problem came up after this point. If I were to create a Note, how could I easily add many Locations to it? My first thought was to create a method that would update the join table, but I knew there had to be an easier way already built in ActiveRecord to do this.

I did some digging around and found a simple solution:


> note = Note.create(user_id: 1, content: "foobar2")
=> #< Note id: 2, content: "foobar2", user_id: 1, created_at: "2012-11-30 02:19:24", updated_at: "2012-11-30 02:19:24" >
> Location.all.each do |location|
note.locations << location
end

I'm using << to push location objects into the note.locations array, and ActiveRecord will handle the creation of the NoteJoin record. Pretty neat.



© Aaron Van Bokhoven