rubycoloredglasses


I'm Jason, a web applications developer in the Denver, Colorado area.


  1. Using Find Each to Process Batches

    I just found out that there is a find_each method provided by ActiveRecord which loops through an array of models that are retrieved in batches of 1000 at a time.

    The find is performed by find_in_batches with a batch size of 1000 (or as specified by the :batch_size option).

    User.find_each(:start => 2000, :batch_size => 5000) do |user|
      user.do_something
    end
    

  2. Development Time

    It seems common that development tasks or projects take much more time than expected. My manager recently pointed these out to me:

    The 90/90 Rule - “The first 90 percent of the code accounts for the first 90 percent of the development time. The remaining 10 percent of the code accounts for the other 90 percent of the development time.” — Tom Cargill, Bell Labs

    Hofstadter’s Law - “Hofstadter’s Law: It always takes longer than you expect, even when you take into account Hofstadter’s Law.” — Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


  3. Minecraft Mods

    I’ve been playing Minecraft for a little while now. Want to see what else this thing can do, so I want to get access to console commands. This is a challenge it seems, so I’m going to document how it’s done here.

    I’m currently using Minecraft version 1.4.7. I just downloaded the latest build/snapshot (possibly unstable yet likely compatible) from Minecraft-Console by simo415 on Github. A prerequisite to this mod running is modloader, which states that it’s only for version 1.4.7.


  4. Obtain MySQL Query Statistics using Explain

    Sometimes it really counts to restructure the queries made to your MySQL database, especially so that they do make use of indexes which are present on the table.

    You can obtain information on which keys are being used with a query by using the EXPLAIN statement before your SELECT statement. Here are some examples of it’s output.


  5. Git Branching Model

    I just want to put this here for future reference.

    There is a version control branching model known as Git-Flow, which is very similar to the model used on the team I work with. See A Successful Git Branching Model. This seems to work well for teams that make several separate commits to the ‘develop’ branch, with different versioned releases provided to the ‘release branch’ that may or may not have been tested and put through a quality assurance process, and finally only major updates (not releases) merged into the ‘master’ branch and tagged with the appropriate version number.


  6. Referencing Gem Source Code

    It’s often difficult to work with Ruby Gems that your Rails application depends on because the source code for the gem itself is packed away in a gem directory. I’ve often found myself using the command ‘rvm gemdir’ to output the path to the gem directory that my application is using, changing to that directory, and opening the source using Textmate. This is a time consuming process.

    Instead, it’s useful to simply unpack a gem into your Rails application so that it loads from the vendor/gems directory. I’m currently using the following command to unpack the RefineryCMS gems into my Rails app for reference.


  7. You can be a programmer too!

    I’ve been telling people to check out CodeSchool.com because it has well laid out interactive courses that you can take to learn advanced web development technologies (jQuery, Coffeescript, Rails, etc).

    However, it doesn’t have the prerequisite courses on HTML, CSS, Javascript, and Ruby.

    It turns out that CodeAcademy.com covers those languages.

    Of course not just anyone can be a web developer, but if you’re nerdy and this stuff excites you, then go for it. I have a job working in San Francisco as a professional developer, doing Ruby on Rails programming. No college. Just experience. Just takes will and determination, and the effort to get experience even if it means taking a pay cut for a while.

    If you’re looking for something a little more low level, like algorithms or an intro to computer science, check out Udacity.


  8. Spree Extension Development Environment using RVM

    I’ve found that there is trouble working with a Spree extension when your gem set does not include the gems included with the Spree gem itself. I discovered this after generating a Spree extension, confining the extension to it’s own gem set using RVM, and then running ‘bundle install’ based on the Gemfile/gemspec configuration of just the extension itself.

    To overcome this, I recommend making a folder named ‘spree’, then configuring that folder to use a shared ‘Spree’ gem set.


  9. Creating a Gem

    In the past gems were created manually, or generated using the echoe gem (last release Sept 21, 2011), or the Jeweler gem (last release November 7, 2011).

    Since then it appears that the most automated way to create a gem is by using Bundler, via the bundle gem command.

    $ bundle gem my_tools
          create  my_tools/Gemfile
          create  my_tools/Rakefile
          create  my_tools/LICENSE
          create  my_tools/README.md
          create  my_tools/.gitignore
          create  my_tools/my_tools.gemspec
          create  my_tools/lib/my_tools.rb
          create  my_tools/lib/my_tools/version.rb
    Initializating git repo in /Users/jsmith/Sites/my_tools
    

  10. Ruby File Modes

    When working with files, you can open them in one of several modes.

    File.new("/file/path.txt", "w")
    

    You can find the description of these modes in the IO documentation.