Skip to content

Instantly share code, notes, and snippets.

@sstephenson
sstephenson / gist:1529115
Created December 28, 2011 18:43
Example bats test
#!/usr/bin/env bats
load test_helper
setup() {
load_fixture rehash
}
teardown() {
destroy_fixture
#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) {
$ time rbenv install 1.9.2-p290
Downloading https://github.com/downloads/sstephenson/ruby-packages/1.9.2-p290.x86_64-darwin.rubypackage...
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
#!/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
sstephenson / gist:1143900
Created August 13, 2011 14:20
Using multiple versions of Rails without gemsets
# 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
sstephenson / date_parse.coffee
Created August 10, 2011 20:43
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
sstephenson / gist:1120938
Created August 2, 2011 19:08
Quick guide to installing rbenv
# Clone rbenv into ~/.rbenv
git clone git@github.com:sstephenson/rbenv.git ~/.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
sstephenson / gist:921992
Created April 15, 2011 16:33
REE vs 1.9.2 for a small Rails 3 app
ree-1.8.7-2010.02
-----------------
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
ruby-1.9.2p180
--------------
units: Finished in 1.504977 seconds.
@sstephenson
sstephenson / config.ru
Created April 8, 2011 04:46
Rackup file for Rails 2.3 apps
require File.dirname(__FILE__) + '/config/environment'
run ActionController::Dispatcher.new