This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run(&block) | |
begin; yield; rescue => e; Error.report(e); end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
// | |
//-------------------------------------- Model : Image | |
// | |
Image = Backbone.Model.extend({ | |
defaults: { | |
'delete' : false | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cartesianProductOf(){ | |
return _.reduce(arguments, function(mtrx, vals){ | |
return _.reduce(vals, function(array, val){ | |
return array.concat( | |
_.map(mtrx, function(row){ return row.concat(val); }) | |
); | |
}, []); | |
}, [[]]); | |
} |
OlderNewer