Knowledge for the World


All things web development.

Naming things is hard. "There are only two hard problems in Computer Science: cache invalidation and naming things." — Phil Karlton Truer words were never spoken.

The N+1 problem occurs when at least two objects are stored in a database with a one-to-many relationship and queries are performed against the "one" table, then separately n number of times against the related object, n being the number of related objects.To illustrate this, I'll use the analogy of a meal website and a page where you wish to display the meals. In the controller:@meals = Meal.where(status=1) # approximate query: SELECT * FROM meals WHERE status = 1;In the view:<% @meal.each do |meals| %> <div class="meal-row"> <h4><%= %><br /> <%= link_to meal.user.username, user_path(meal.user.username) %> <%# approximate query: SELECT * FROM users WHERE = {{ meal_id }}; %> </h4> <p><%= meal.description %></p> <%= link_to 'Cook This Now', meal %> </div> <% end %>Notice how we're creating a link to meal.user.username.To approximate the queries used in this page, we have the following:SELECT * FROM meals WHERE status = 1; # 1 time, yielding n rows SELECT * FROM users WHERE = {{ meal_id }}; # n timesThe ORM in Rails should do a lot of work to minimize the net slowness of this problem such as database indexing and caching template fragments, but nothing will change the fact that you are querying the database in a loop.Now let's take a look at how to find these in your code and how to get rid of them.

Converting XML files to JSON is a good practice for providing easy manipulation and preparing service responses. You can accomplish this efficiently with just three lines of code.

Vundle, Pathogen, Vim-plug, VAM, and the others can be great time savers but sometimes you just have to do something yourself so you can understand what exactly the time saving software is doing for you in the background. For myself, I got sick of not understanding what these were doing to my system. I realized I did not know the fundamentals of vim plugins so I set out to learn.This is a step by step guide to teach you how to install a basic vim plugin without the help of any fancy manager.

Bourbon is a library of Sass mixins. It provides a lot of functionality while keeping your css slim. Assuming you're using a standard rails installation, Sass will already be installed and working.

I started programming in PHP, so by default I would use apache even when I just wanted to test basic HTML files. As I was learning Python, I discovered a great HTTP request handler.

Text shadows are a beautiful and subtle effect for your web site. CSS3 text shadows are currently support on all versions of Chrome, Safari, Firefox 3.5+, and IE 10+.

Public key encryption is also known as asymmetric because it requires two different keys - a public key and a private key. Encryption requires the public key, and decryption requires the private key.

There are some fundamental git commands that you will use frequently that are hard to work into a "how-to" guide. Here are some basic git commands and how to use them. These are in no specific order.

This guide will show you how to properly commit and push your work in Git. It is assumed that you have Git installed and that you're currently in a clean master branch.

There are a lot of free website builders, many of which are terribly difficult to use. I'm going to use WebStarts for this tutorial because I think it's the easiest to use.