Today at AppAcademy we have gone through almost all of Michael Hartl’s rails tutorial.  I just wanted to quote Hartl explanation of what a database index is and how it works.  I love the analogy because it’s probably the most simplistic examples I’ve probably ever seen:

Putting an index on the email column fixes the problem. To understand a database index, it’s helpful to consider the analogy of a book index. In a book, to find all the occurrences of a given string, say “foobar”, you would have to scan each page for “foobar”. With a book index, on the other hand, you can just look up “foobar” in the index to see all the pages containing “foobar”. A database index works essentially the same way.

Bam!

wat-gigantic-duckFirst off, I stole this pic from Greg Pike’s post about Javascript.  Now that the confession is out of the way…

Today at App Academy my pair and I were asked to explain the meaning of Ruby’s “double pipe equals” operator  to our cohorts.  I figured that might be a good topic to post here.

The double pipe equals, which will be referred to as “||=” from now on, is an operator that’s used for conditional assignment.

In a nutshell the||= operator’s usage is something like this:

blah ||= blabbity_blah()

This essentially says: “if blah is false then set it to blabbity_blah(), otherwise leave it set to whatever it was before we started”

Here’s a contrived, but-still-real-code, example lifted (and modified) from Wikibooks: