Skip to content

Instantly share code, notes, and snippets.

View gist:1529115
#!/usr/bin/env bats
load test_helper
setup() {
load_fixture rehash
teardown() {
View relative_prefix.c
#include <string.h>
#include <stdio.h>
#include <sys/param.h>
#include <stdlib.h>
char *relative_prefix(char *argv0, char *prefix) {
char *file_name, *result;
size_t size;
if (argv0 == NULL) {
View gist:1299584
$ time rbenv install 1.9.2-p290
Installing 1.9.2-p290...
Installed 1.9.2-p290 to /Users/sam/.rbenv/versions/1.9.2-p290
real 0m18.979s
user 0m1.211s
sys 0m3.334s
View sanitize-variables.bash
#!/usr/bin/env bash
# Reads lines from stdin in the format `VAR=value` and escapes
# them for the shell, prepending each line with `export`.
# Parameter substitution is allowed in `value` with `$VAR` and
# `${VAR}` syntax. You can escape `$` and `\` with a backslash.
sed \
-e "/^[ "$'\t'"]*[A-Za-z_][0-9A-Za-z_]*=/ !d" \
-e "s/'/'\\\\''/g" \
sstephenson / gist:1143900
Created Aug 13, 2011
Using multiple versions of Rails without gemsets
View gist:1143900
# RubyGems has this functionality built-in. Just specify
# the particular version you want to use as the first argument
# of the command, surrounded by underscores.
$ gem install rails --version 3.0.9
$ gem install rails --pre
$ rbenv rehash
$ rails --version
sstephenson /
Created Aug 10, 2011
ISO8601 (JSON) timestamp support for Date.parse
# Older browsers do not support ISO8601 (JSON) timestamps in Date.parse
if isNaN Date.parse "2011-01-01T12:00:00-05:00"
parse = Date.parse
iso8601 = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[-+]?[\d:]+)$/
Date.parse = (dateString) ->
dateString = dateString.toString()
if matches = dateString.match iso8601
[_, year, month, day, hour, minute, second, zone] = matches
offset = zone.replace(":", "") if zone isnt "Z"
sstephenson / gist:1120938
Created Aug 2, 2011
Quick guide to installing rbenv
View gist:1120938
# Clone rbenv into ~/.rbenv
git clone ~/.rbenv
# Add rbenv to your PATH
# NOTE: rbenv is *NOT* compatible with rvm, so you'll need to
# remove rvm from your profile if it's present. (This is because
# rvm overrides the `gem` command.)
echo 'export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"' >> ~/.bash_profile
exec $SHELL
# Extend jQuery objects with Underscore collection methods.
# Each collection method comes in two flavors: one prefixed
# with _, which yields a bare DOM element, and one prefixed
# with $, which yields a jQuery-wrapped element.
# So if `this` is a jQuery object, instead of:
# _.max @, (el) -> $(el).height()
sstephenson / gist:921992
Created Apr 15, 2011
REE vs 1.9.2 for a small Rails 3 app
View gist:921992
units: Finished in 0.930402 seconds.
functionals: Finished in 12.241386 seconds.
integration: Finished in 1.648589 seconds.
rake 20.19s user 4.96s system 98% cpu 25.588 total
units: Finished in 1.504977 seconds.
sstephenson /
Created Apr 8, 2011
Rackup file for Rails 2.3 apps
require File.dirname(__FILE__) + '/config/environment'