Archive for January 2016

  • Unit Testing ActiveRecord eager-loading

    January 27, 2016

    If you’ve worked with relational databases and any ORMs like Java’s Hibernate, .NET’s NHibernate or Rails’ ActiveRecord in the past, you might be familiar with SELECT N+1 issues. It is a common performance problem in database-dependent applications and, because of this, these ORMs provide a built-in solution to this problem.

    In ActiveRecord, includes, preload and eager_load come to the rescue. Therefore, it is not unusual to find these keywords scattered in different places where your application accesses the database. Hopefully this isn’t a lot of places though - you are using Query Objects, right?

    An example application

    Let’s imagine for a second that we have an application where you can browse restaurants, which in turn have many reviews…

    Continue Reading →

  • Query Objects in the Rails world - A Different Approach

    January 26, 2016

    If you have worked with Ruby on Rails before then you might be familiar with ActiveRecord scopes. Using them, you can achieve what many would consider very readable code. Let’s say that we have an application where we display an inbox where users receive messages.

    class Message < ActiveRecord::Base
    end
    

    Now, let’s imagine that after reading a Message, it is marked as read, and let’s represent that with a read column in the database. Additionally, our users can either archive the Message or move it to the trash. We’ll represent this concept with a location column in the messages table.

    Querying the database the Rails way

    Let’s say that our users want to have a way to view unread messages in their inbox. Using ActiveRecord, you could achieve…

    Continue Reading →

  • Installing MacVim with Lua enabled through Homebrew

    January 11, 2016

    If you’re like me, you like to have control over the plugins that you have installed in your editor setup. However, staying up to date with the different plugins can be a little bit of a hassle from time to time, so lately, I’ve been using YADR, a set of community maintained dotfiles.

    A great autocompletion plugin that YADR comes with is neocomplete.vim, which “provides a keyword completion system by maintaining a cache of keywords in the current buffer”. Unfortunately, for it to work, it needs MacVim with Lua enabled.

    Now, I already had MacVim installed through Caskroom:

    which mvim
    # /usr/local/bin/mvim
    ls -l $(which mvim)
    # /usr/local/bin/mvim -> /opt/homebrew-cask/Caskroom/macvim/7.4-84/mvim
    

    But this version was installed without Lua…

    Continue Reading →