Skip to content

Instantly share code, notes, and snippets.

View jmervine's full-sized avatar

Joshua Mervine jmervine

View GitHub Profile
#!/usr/bin/env roundup
describe "redis-cli(1)"
# Start the redis server on port 9999
port=9999
printf "PORT $port\n" | ./redis-server - &
redis_pid=$!
# Give redis time to start listening
@jmervine
jmervine / gist:2052468
Created March 16, 2012 20:30
Rails: Dynamic Model from JSON sans DB
require 'net/http'
class Item
#replaced with dynamic initialization below
#attr_reader :id, :user, :state
#
#
# Sample JSON
#
# [{ "id":1, "user":"john", "state":"active" },
# { "id":2, "user":"jane", "state":"inactive" },
@jmervine
jmervine / gist:2052509
Created March 16, 2012 20:37
Ruby: dynamically generated object with accessors
class Item
def initialize item
raise "expected Hash param" unless item.kind_of? Hash
item.each do |key,value|
instance_variable_set(clean_key(key), value)
define_singleton_method(key.to_s) { instance_variable_get( clean_key(key) ) }
define_singleton_method("#{key.to_s}=") { |val| instance_variable_set( clean_key(key), val ) }
end
end
@futuremill-ltd
futuremill-ltd / gist:2318876
Created April 6, 2012 11:00
Building Ruby 1.9.3 package for Debian Squeeze
# From a fresh install of squeeze
apt-get install ruby rubygems # Need ruby to use fpm
gem1.8 install fpm --no-ri --no-rdoc
apt-get install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev ncurses-dev libyaml-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -zxvf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125
rm -rf /tmp/ruby193
@thbar
thbar / README.MD
Created April 18, 2012 09:43
Ruby JSON pipe pretty-printer

A quick ruby command line to pretty-print piped json.

Usage

Put this somewhere in your path, with chmod +x, then:

curl http://myapp.com/stuff.json | json

@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@domenic
domenic / portable-node.md
Created May 25, 2012 21:03
Tips for Writing Portable Node.js Code

Node.js core does its best to treat every platform equally. Even if most Node developers use OS X day to day, some use Windows, and most everyone deploys to Linux or Solaris. So it's important to keep your code portable between platforms, whether you're writing a library or an application.

Predictably, most cross-platform issues come from Windows. Things just work differently there! But if you're careful, and follow some simple best practices, your code can run just as well on Windows systems.

Paths and URLs

On Windows, paths are constructed with backslashes instead of forward slashes. So if you do your directory manipulation

anonymous
anonymous / file1.txt
Created September 21, 2012 20:55
gistcli - Paste
#! /usr/bin/python
#########################################################################################
# gistcli - version 1.1 #
# written by : pranavk #
#########################################################################################
import urllib2
import sys
@mariusbutuc
mariusbutuc / branch-rename-remote.git
Created September 21, 2012 23:12
Rename remote Git branch
git push origin previous_name:new_name
git branch new_name origin/new_name
# http://stackoverflow.com/a/3790682/341929
" for use before a colorscheme definition
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
" for use when not using a colorscheme
" highlight ExtraWhitespace ctermbg=red guibg=red
" show unwanted whitespace
match ExtraWhitespace /\s\+\%#\@<!$/
" strip unwanted trailing whitespace on save