Skip to content

Instantly share code, notes, and snippets.

@reinh
reinh / gist:41325
Created December 29, 2008 17:50 — forked from rezaprima/gist:39869
function current_git_branch {
git branch 2> /dev/null | grep '\*' | awk '{print $2}'
}
hack()
{
CURRENT=$(current_git_branch)
git checkout master
git pull origin master
git checkout ${CURRENT}
BR=$(git symbolif-ref HEAD 2> /dev/null || git name-rev HEAD 2> /dev/null || echo 'no branch')
BR=${BR#HEAD\ }
BR=${BR#refs/heads/}
reinhenrichs(master):rubinius$ cd kernel
reinhenrichs(master):rubinius/kernel$ cd common
reinhenrichs(master):rubinius/kernel/common$ cd ..
reinhenrichs(master):rubinius/kernel$ git checkout HEAD^
reinhenrichs(master~1):rubinius/kernel$
reinhenrichs(master~1):rubinius/kernel$ git checkout master
reinhenrichs(master):rubinius/kernel$ cd ..
reinhenrichs(master):rubinius$ cd ..
reinhenrichs:/Users/reinhenrichs/code/opensource$
module Readers
# Maps key/value pairs from the data structure used to initialize a
# Endeca object. Allows attribute renaming. Use a block to perform data
# injunction on the value as it is set. Depends on an +attributes+ accessor
# for the attributes hash.
#
# ==== Examples
#
# # Specify basic attributes
# reader :title
# Thanks to Josh Susser
class Object
alias_method :try, :send
end
class NilClass
def try
nil
end
end
class Endeca::Document < SomeAwesomeName::Abstract
def properties
@properties ||= @raw['Properties'] || {}
end
alias_method :attributes, :properties
# Returns the collection of Endeca::Dimension for the given Document
def dimensions
return @dimensions if @dimensions
@dimensions = {}
class Hash
def to_query_string
map { |k, v|
"#{URI.esacape(k)}=#{URI.escape(v)}"
}.join('&')
end
end
module Enumerable
def comprehend(&block)
map(&block).compact
end
def comprehend2(&block)
inject([]){|arr, x| result = block[x]; arr << result if result; arr}
end
def comprehend3(&block)
#!/bin/env ruby -wdK
# Given an array, print it as a bar graph
# Use FOR SPEED!!!
class VertiBar
WIDTH = 72
STEPS = WIDTH/6
def self.draw(sample)
new(sample).draw
end
def self.next_available_arv_id
return self.get_next_patient_identifier(identifier_type = "Arv national id")
end