Skip to content

Instantly share code, notes, and snippets.

@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
rvm use ree-1.8.7-2010.02@global
rvm gemset create rails2310
gem install rails -v=2.3.10
@ches
ches / rvm-prompt.sh
Created February 20, 2011 16:02
An example of a bash prompt showing RVM Ruby version and active gemset
RED="\[\033[01;31m\]"
GREEN="\[\033[01;32m\]"
COLOR_NONE="\[\033[0m\]"
function ruby_version {
if [[ -f ~/.rvm/bin/rvm-prompt ]]; then
local system=$(~/.rvm/bin/rvm-prompt s)
local interp=$(~/.rvm/bin/rvm-prompt i)
if [[ ! -n $system ]]; then
# Don't show interpreter if it's just MRI
require 'net/http'
require 'json'
###
# Stupid simple class for uploading to imgur.
#
# client = Imgur2.new 'my imgur key'
# p File.open(ARGV[0], 'rb') { |f|
# client.upload f
# }
@vijaydev
vijaydev / Vim Tricks
Created April 27, 2011 12:51
Vim Tricks
.s@\(\d\+\)@\=(submatch(1) + 17)@
Search for numbers and replace them with results of expressions involving them. submatch(1) is \1 (groups in regexes)
@sanand0
sanand0 / viz.py
Created May 3, 2011 17:10
Utility functions for visualisations
'''
Usage: viz.py INPUT.csv [template.html] > OUTPUT.xhtml
'''
import re
import math
import logging
import datetime
import operator
from tornado import template
@jeresig
jeresig / .vimrc
Created May 4, 2011 16:46
VIM Config
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
set nocompatible
set autoindent
set tabstop=2
set showmatch
set vb t_vb=
set ruler
set nohls
set incsearch
syntax on
@fxn
fxn / post.md
Created May 23, 2011 21:08
GeoPlanet data with ancestor chain cache imported in 10 minutes

GeoPlanet data with ancestor chain cache imported in 10 minutes

Yahoo! provides its GeoPlanet data as three separate TSV files, available for download here.

That's a database with some 17 million records:

  • 5.7 million records: locations (aka places).
  • 2.2 million records: alternative names for each place (aka aliases).
  • 9.6 million records: matrix of neighbourhoods per place (aka adjacencies).
# Respond to also allows you to specify a common block for different formats by using any:
#
# def index
# @people = Person.all
#
# respond_to do |format|
# format.html
# format.any(:xml, :json) { render request.format.to_sym => @people }
# end
# end

Sprockets Railtie Setup

This file at actionpack/lib/sprockets/railtie.rb defines the Sprockets::Railtie, defining another Railtie for Rails. This Railtie is responsible for detecting if the application at-hand is using CoffeeScript, and if so will set config.app_generators.javascript_engine on the application to be :coffee.

Next, this defines an initializer called sprockets.set_configs which sets up ActionController::Base to either use or not use sprockets depending on the configuration option config.assets.enabled.

Finally, this file defines an after_initialize hook for the application which is the real meat of this Railtie. If assets are disabled (with the config.assets.enabled config option set to false) then this after_initialize hook will do nothing.

If assets are enabled then, this initializer first makes a call to an asset_environment protected method near the bottom of this file which requires the sprockets gem, creates a new Sprockets::Environment object, and then co