Skip to content

Instantly share code, notes, and snippets.

View mboeh's full-sized avatar

Matthew Boeh mboeh

View GitHub Profile
[alias]
# Cheap fast way of getting the current branch for, say, your shell prompt
cbranch = !cat .git/HEAD | cut -d/ -f3-4
st = status
# A pattern I find myself using a lot
up = !git fetch && git rebase origin/$(git cbranch)
# The current staged patch
di = diff --cached
# checkout is so long, and co means something sort of different to me
sw = checkout
# Ruby syntax never fails to amaze me, casefile whatever.
# Yes, this could be accomplished more elegantly another way. But this is fun.
require 'ostruct'
def DStruct(*a)
klass = Struct.new(*a)
defs = Hash.new
yield defs
klass.send :define_method, :initialize do |*a|
>> Rails.version
=> "2.1.2"
>> AbstractThingy < ActiveRecord::Base
=> true
>> AbstractThingy.record_timestamps
=> true
>> OneOfManyThingies < AbstractThingies
=> true
>> OneOfManyThingies.record_timestamps
=> nil
#!/bin/sh
capture () {
echo $SSH_AUTH_SOCK > /tmp/$(whoami)-auth-sock-path
}
clean () {
rm /tmp/$(whoami)-auth-sock-path
}
# mboeh's zshrc
# Where history is stored.
HISTFILE=~/.histfile
# Up to 2500 lines of history will be stored in a given shell session...
HISTSIZE=2500
# ... and up to 2500 will be saved when the shell exits.
SAVEHIST=2500
# Append new history lines to .histfile when the shell closes (instead of clobbering it).
# A must-have for someone who uses a lot of ZSH sessions (I have 5-10 open at any given time).
# Messing with some experimental statistical analysis for infinitely exploding dice
def roll_die(d)
rand(d) + 1
end
def roll_exploding_die(d)
r = roll_die(d)
if r == d
r + roll_exploding_die(d)
class SettingReader
def initialize hash
# You may want to consider doing a deep copy of the hash and then #freeze-ing it
@hash = hash.nil? ? {} : hash
raise ArgumentError, "must pass a hash or nil" unless @hash.kind_of? Hash
end
def get key, default = nil
h = @hash
for subkey in key.split(".")
h = h[subkey]
@mboeh
mboeh / Shell output
Created February 14, 2012 22:01
Nokogiri::XML::Reader#outer_xml issue with JRuby
[mboeh@orz:~] % rvm ree-1.8.7-2011.03 do ruby /tmp/nokogiri-jruby-outer-xml-test.rb
Loaded suite /tmp/nokogiri-jruby-outer-xml-test
Started
.
Finished in 0.000513 seconds.
1 tests, 3 assertions, 0 failures, 0 errors
[mboeh@orz:~] % rvm jruby-1.6.6 do ruby /tmp/nokogiri-jruby-outer-xml-test.rb
Loaded suite /tmp/nokogiri-jruby-outer-xml-test
Started
@mboeh
mboeh / thread-xp.rb
Created March 8, 2012 19:15
Celluloid-based mass downloader/zipper POC
require 'fiber18'
require 'celluloid'
require 'zip/zipfilesystem'
require 'uri'
require 'net/http'
class ZipManifest
include Celluloid
def initialize(filename)
@mboeh
mboeh / celluloid_thread_local_issues.rb
Created March 17, 2012 16:21
Celluloid thread local issues?
# Just so I'm clear on the issue...
class Donut < ActiveRecord::Base
# ...
end
# This encounters the issue with fiber-local variables...
class Homer
include Celluloid