Instantly share code, notes, and snippets.

View snake_to_camel.rb
# Using gsub (least performant)
"test_string".capitalize.gsub(/_(\w)/){$1.upcase} # => TestString
# Using split & map with capitalize
# Using split & map (most performant)
View rails http status codes
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing

Host to Host a Rails App on a Home Server

Hosting services like Heroku and Amazon EC2 are nice. That is, until they cost money. Some things are worth running on your own hardware, especially when the cost and Terms of Service requirements outweigh the expense of rolling your own hosting.

I am writing this because I recently had to figure all this out in order to host a personal blog off a Raspberry Pi, and I thought I'd share what I learned. This guide assumes that you already know how to install Ruby and you know how to use Rails. If you don't, look those up first before coming back to this guide.


  • Ruby >=2.0
  • Rails >=4.0
  • Nginx

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

import pyaudio
import wave
FORMAT = pyaudio.paInt16
RATE = 44100
CHUNK = 1024
View knapsack.js
//Knapsack algorithm
// wikipedia: [Knapsack (0/1)](
// Given a set `[{weight:Number, benefit:Number}]` and a capacity,
// find the maximum value possible while keeping the weight below
// or equal to the capacity
// **params**:
// `capacity` : Number,
// `items` : [{w:Number, b:Number}]
// **returns**:
View gist:7d8060819ab8c396c012
// Pseudocode to demonstrate debouncing
$(".item_column").on("scroll", function(){
// this function fires way too fast
// With debouncing:
$(".item_column").on("scroll", _.debounce(function(){
// max this function can fire is every 150 milliseconds