Skip to content

Instantly share code, notes, and snippets.

View h3h's full-sized avatar

Bradford Fults h3h

View GitHub Profile
autodetach on
defkanji euc
deflogin on
startup_message off
defscrollback 100000
defshell -bash
chdir
term "xterm"
escape ^Tt
encoding UTF-8 UTF-8
@h3h
h3h / gist:321336
Created March 4, 2010 02:35
bash aliases for running test/spec tests
# test/spec test runner
function ts()
{
ruby $1 -r s 2>/dev/null | grep -v "^HelperTestCase" | grep -v "dummy (e"
}
# test/spec test runner (with test name)
function tsn()
{
ruby $1 -r s -n "/$2/" 2>/dev/null | grep -v "^HelperTestCase" | grep -v "dummy (e"
@h3h
h3h / thing.rb
Created April 12, 2010 15:51
Sharing a value slot across multiple objects.
class Thing
@@things = {}
def initialize
@pointer = self.hash
end
def set(x)
@@things[@pointer] = x
end
module Enumerable
def how_many_have?(method)
self.select {|x| x.send(method)}.count
end
alias_method :how_many_are?, :how_many_have?
end
# >> [1,2,3,4,5].how_many_are?(:even?)
# => 2
#
@h3h
h3h / gist:417878
Created May 28, 2010 23:16
Test case for an XFBML bug in Facebook's connect-js library.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>XFBML Bug</title>
</head>
<body>
@h3h
h3h / .irbrc
Created June 16, 2010 17:38
My ~/.irbrc
# The irbrc file for Brad Fults <bfults@gmail.com>
#
# Most of the code here came from http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks
#
unless self.class.const_defined? "IRB_RC_HAS_LOADED"
HISTFILE = "~/.irb-history"
MAXHISTSIZE = 100
begin # ANSI codes
ANSI_BLACK = "\033[0;30m"
if (!Array.prototype.uniq)
{
Array.prototype.uniq = function(fun)
{
var seen = {};
return this.filter(function (el) {
var key = typeof (fun) == "function" ? fun(el) : el;
var r = !seen[key];
seen[key] = true;
return r;
AK
VT NH ME
WA MT ND MN NY MA
WI MI CT RI
OR ID SD IL IN OH PA NJ
MD DE
WY NE IA WV VA DC
CA NV UT CO KS MO KY NC
OK AR TN SC
AZ NM LA MS AL GA
@h3h
h3h / gist:669173
Created November 9, 2010 14:49
rvm fails to install ruby binary with curl error
08:47:28 [bfults@austin] ~$ rvm info
1.8:
system:
uname: "Darwin austin 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386"
bash: "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)"
zsh: "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"
rvm:
@h3h
h3h / active_record_from_hash.rb
Created March 10, 2011 00:34
You know, for objects.
require 'active_support/core_ext/hash/keys'
# Intended as an extension for an ActiveRecord model. It allows construction
# of a valid ActiveRecord object from a Hash, including proper handling of
# the :id attribute.
module ActiveRecordFromHash
def from_hash(hsh)
hsh = hsh.symbolize_keys
self.new.tap do |obj|