Refactoring Ruby Iteration Patterns to the Database

Check out my recent article on thoughtbot’s blog. Frequently on projects we need to run a calculation through an ActiveRecord association. For example, we might want to get a user’s all time purchases, a company’s total amount of products sold, or in our case, the total amount of loans made to a campaign. This sort of calculation is ripe for using a map and an inject but frequently the solution is more elegant and faster if we can have SQL do the work instead. Read On →

Stuck? Get into the pairing mentality

This post is on the softer side of things. I was working on a Ruby exercism this morning alone in a coffeeshop and was just not getting anywhere. The problem was simple enough: Write a function to convert from normal numbers to Roman Numerals However trivial the problem was I was just spinning my wheels. It must have been an off day. I ended up with a mess of if statements that was seemingly leading nowhere. Read On →

N + 101: an example query optimization

Meet FreshFinder. FreshFinder is a location aware website that allows you to explore farmers’ markets across the US. Data is sourced from the USDA and presented in a beautiful map-based interface. The full application architecture can be seen here. The code is available under the FreshFinder organization on GitHub. The site is pretty zippy but we had to do some work to get it that way. Here’s the story. Read On →

Writing and deploying multiple Rails apps with Nginx

For our last project, my team built a real time dashboard for development teams so managers and team members can have an at a glance look at what’s happening in a project. A user can create a project and link up Github repos, Pivotal Tracker Projects, Travis CI builds, and Code Climate scores. We built the app using a Services Oriented Architecture and learned quite a bit along the way. Read On →

Doing more than deploying code in a git post-receive hook

Editing on the server You know that terrible feeling you get when you’re editing code on the production server? Wouldn’t it be nice if we could easily deploy code from our command line to our VPS? Our most recent project was deployed to a VPS on Digital Ocean and having come from a lot of experience deploying to Heroku, we had to script out our deploy pipeline by hand. It was a fun learning experience ripe with seemingly undebuggable pitfalls. Read On →

How ActiveRecord casts params before validation

I was building a model recently to support a form where users can create events with a given day and time. I was experimenting with using Postgres’ range data types and needed to parse the user input from many fields into a single tsrange (timestamp range) field. Using attr_accessors got me most of the way there but I learned some interesting things about how ActiveRecord casts data types before validation. Read On →

Using Postgresql's tsrange Range Type with Rails

The Range Data Type Postgres 9.2 and later supports range data types including: int4range — Range of integer int8range — Range of bigint numrange — Range of numeric tsrange — Range of timestamp without time zone tstzrange — Range of timestamp with time zone daterange — Range of date and as of Rails 4.0.0 in pull request 7345 so does Rails. Some of the commentary on this PR about bounds is interesting if you have some time to kill. Read On →

It all comes together: Ruby, JS, and functional programming

Whenever you learn a new word, you inevitably see that word in the newspaper a day later. You’ve been seeing that word all along you just didn’t know it was there. I had a similar experience with programming yesterday when Ruby, Javascript, and functional programming concepts (by way of Clojure and Ruby lambdas) all came together. It was an exciting day… ###Javascript and Ajax I took my first deep dive into javascript a couple weeks ago doing exercises on exercism. Read On →

rails_12factor logging problems

Our most recent project is to extend our previous project using another team’s codebase. One of the first things we did was run the tests. We were greeted with a mess of ActiveRecord and view rendering logs. Oh man, this last team did some strange stuff, we thought. We were expecting to see some pretty green (and red) dots but instead the terminal output looked like this: $ rake test_all ActiveRecord::SchemaMigration Load (1. Read On →

What I learned setting up delayed_paperclip and Sidekiq

A recent project required an admin user to be able to upload images. Using paperclip we got the uploading going in no time. But, having the uploads going through the app server was very slow (~1.5s requests) so we moved the uploading into a background job. Having never messed with background jobs before I chose to use delayed_paperclip as an easy way to wade into the topic. Using delayed_paperclip is appealing because it will solve our problem and teach us about background jobs all without having to write custom code. Read On →