Skip to content

Instantly share code, notes, and snippets.

View FestivalBobcats's full-sized avatar

Ben Hundley FestivalBobcats

  • Mission Cloud
  • Fayetteville, AR
View GitHub Profile
@FestivalBobcats
FestivalBobcats / .bash_profile
Created March 14, 2014 16:00
Git branch and changes indicator for bash
__quiet() {
$1 2> /dev/null
}
parse_git_branch() {
__quiet 'git branch' | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
count_git_changes() {
count=$(__quiet 'git status -s' | wc -l)
@FestivalBobcats
FestivalBobcats / quinky.rb
Created July 1, 2014 23:05
Quinky (GroupMe haiku bot)
require 'json'
require 'typhoeus'
require 'ansi'
ACCESS_TOKEN = #
GROUP_ID = #
def register_bot(name, avatar_url=nil)
url = "https://api.groupme.com/v3/bots?token=#{ACCESS_TOKEN}"
body = {
def self.volatility(prices)
mean = (prices.inject {|s,n| s+n}) / prices.length
sd = Math.sqrt((prices.inject(0) {|s,n| s + (n-mean)*(n-mean)}) / (prices.length-1))
rsd = sd/mean*100
('%.2f'%rsd)
end
def run(&block)
begin; yield; rescue => e; Error.report(e); end
end
@FestivalBobcats
FestivalBobcats / .profile
Created September 8, 2011 16:00
Quickly open a gem directory with Textmate
gemopen() {
gem_dir=( $(find $GEM_HOME/gems -maxdepth 1 | grep $1) )
for line in ${!gem_dir[*]}; do
echo $(($line + 1)). ${gem_dir[$line]}
done
if [ ${#gem_dir[*]} == 0 ]; then
echo $1 directory not found.
else
echo -e '> \c'
read inpt
@FestivalBobcats
FestivalBobcats / gist:1217912
Created September 14, 2011 21:55
Inspect every method as it's called
module Breadcrumbs
def self.included(mod)
mod.extend ClassMethods
mod.class_variable_set :@@__defined_methods, []
end
module ClassMethods
def method_added(m)
unless (meths = class_variable_get(:@@__defined_methods)).include?(m)
__quiet() {
$1 2> /dev/null
}
parse_git_branch() {
__quiet 'git branch' | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
count_git_changes() {
count=$(__quiet 'git status -s' | wc -l)
gemopen() {
gem_dir=( $(find $GEM_HOME/gems -maxdepth 1 | grep $1) )
dir_count=${#gem_dir[*]}
if [ $dir_count == 0 ]; then
echo $1 directory not found.
elif [ $dir_count == 1 ]; then
mate ${gem_dir[0]}
else
for line in ${!gem_dir[*]}; do
echo $(($line + 1)). ${gem_dir[$line]}
# Orig
def items options = Hash.new
products = true_category.descendant_products.available.visible
if options[:vendor]
products = products.by_vendor options[:vendor]
end
if options[:factor]
@FestivalBobcats
FestivalBobcats / gist:1284489
Created October 13, 2011 15:19
Ruby splatz
> def a(x,y); end
=> nil
> send :a, [1,2]
ArgumentError: wrong number of arguments (1 for 2)
from (irb):1:in `a'
from (irb):2
from /Users/bhundley/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
> send :a, *[1,2]
=> nil