• Candyfair app ·

    Halloween season came around and with it came big bags of candy at the office. Some candies disappeared faster than others, leading exclamations like “aww all the Twix are gone!” or “there’s nothing but stupid 3 Musketeers left” to be heard around the office. Summer remarked that we needed an app to tell us how best to divide the candy so that no one who didn’t want stupid 3 Musketeers would be forced to eat them, and the weirdos who actually like 3 Musketeers could revel in their abundance. Enter my next pet project.

  • Arel and tags ·

    I love working out ActiveRecord and Arel queries in Rails apps. I thought I’d share some of the more fun queries I’ve designed in Arel, spread out over a few blog posts. We’ll start with one for fetching tags separated by account.

  • BlicblockJS: a game from The Sims 4 ·

    I made another thing! This time, I made my first game. Well, the first game I’ve ever finished (I’ll get back to you someday Mahjong). It’s a JavaScript web implementation of the game Blicblock that your Sims play in The Sims 4. I built it using AngularJS, my new loves Yeoman and Bower, and Bootstrap. You can try it out in your web browser and view or contribute to the source code on Github.

  • RailsBridge Lexington ·

    Yesterday I helped out at the first ever RailsBridge held in Lexington. We had twenty-five people sign up as attendees and maybe ten volunteer coaches, including myself. It’s intended to be an all-day session introducing women to programming, specifically by having them create a simple Ruby on Rails app. I gave the opening presentation, which you can find on SlideShare and also download as a PDF. It introduced the ladies to programming basics, and had them walk through several examples in IRB. Friday night we held an InstallFest where everyone brought their laptops and we helped them get stuff installed, including RailsInstaller in Windows, Git, Sublime Text 2 as an editor, and Node.js in Windows to have a JavaScript runtime. They also made a couple basic Rails apps that were no more than scaffolds, committed them to local Git repositories, and published them on Heroku. This was to prepare them for Saturday, when they did the same thing but with a more complex Rails app.

  • painful Facebook application development ·

    For the past few days, I’ve been trying to create a Facebook application for interacting with Github. I hoped to spend my time mainly on the Github portion, figuring out how to post wall posts on Facebook about recent Github activity, etc. However, I’ve instead argued with the various Facebook APIs. I started out using PHP with no framework but quickly switched to CakePHP after I realized things were going to get hairy. CakePHP was okay for a while until I hit the roadblock of not being able to load any page but the index… Every sub-page I tried to create produced 404 errors, which no one else seemed to have (or at least document), so I said ‘screw it’ and switched to Rails.

  • code reports Rake task ·

    This will run various Ruby Gems for creating code quality reports, store them in public/ in your Rails app, and create public/reports.html with links to each report. You need Saikuro, Flog, Flay, Reek, and Roodi, since this Rake task uses them all.

  • finding invalid foreign keys in Rails ·

    Sometimes it would be useful to tell users of your Ruby on Rails application if there is a problem in the database, such as some foreign keys are invalid. As an example, let’s assume you have two models, Book and Author, such that each Book has an author_id which connects with Author via its primary key, id. That is, the tables are: books(id, author_id) and authors(id). Each table probably has fields other than that, but those are the only fields we need to worry about. Below is a method that generates an unordered HTML list for display to the users:

  • the many methods to #find things in Rails ·

    For the longest time, I didn’t understand the full power of the various #find methods in Rails. I probably still don’t, but my understanding of them has certainly expanded. I used to use plain #find for everything. If I wanted to find all rows in the table ‘groups’ that had an ‘id’ field value of 1, 2, 3, or 4, I would do something like this:

    1
    2
    3
    4
    
    Group.find(
      :all,
      :conditions => ["id=? OR id=? OR id=? OR ID=?", 1, 2, 3, 4]
    )
    
  • #post method in tests with a different controller ·

    I wanted a #login method in test_helper that would allow me to easily login from any of my functional tests. However, the #post method won’t allow you to set a different controller than the one in the @controller instance variable that’s defined in your test’s #setup. Well, by looking at how the #process method works, you can see that it just grabs the controller from @controller. Redefine that, and you’re good to go:

  • go from model to associated table name and back ·

    Given a table object, it returns the related string object; e.g. SubAttribute => 'sub-attribute'. Useful if you want to make a list of all your tables with perhaps their fields listed out to the side.

  • conditioner for ActiveRecord-friendly conditions from a collection ·

    I frequently have a collection of values that I want to match in an ActiveRecord query, but it would be nice if I could let ActiveRecord handle checking the data and escaping it properly. So, I wrote this method to return ActiveRecord-friendly conditions, such as:

    1
    
    ["user_id=? AND job_id=?", 3, 4]
    
  • simple Rails preference storage ·

    So you’ve got some Rails application and you need to store information from the users across their interactions with the app. Here’s a simple, straightforward way to do that.