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 cgrep { | |
local command="" | |
for var in "$@"; do | |
command+="grep $var | " | |
done | |
eval ${command% | } | |
} |
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
#!/usr/bin/env ruby | |
require 'time' | |
@default_root_dir = '~/code' # CHANGE THIS | |
def print_git_logs_since(date_str, root_directory) | |
logs_by_date_by_project = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] =[]}} | |
root_directory ||= @default_root_dir |
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 time(&block) | |
$breakpoints = [] | |
start = Time.now | |
yield | |
puts "----------------\n" | |
puts "Total time:" | |
puts "\t#{(Time.now - start).round(1)}s" | |
puts "Breakdown:" | |
$breakpoints.each.with_index do |(msg, t), i| | |
puts "\t#{(t-start).round(1)}s, breakpoint #{i} #{"(#{msg})" if msg}" |
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
class Leader | |
attr_reader :count | |
attr_reader :actually_visited | |
def initialize | |
@count = 1 | |
@actually_visited = false | |
end | |
def respond_to_state(s) |
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 supersay { | |
say -v princess '$1' & | |
say -v 'Agnes' $1 & | |
say -v 'Albert' $1 & | |
say -v 'Alex' $1 & | |
say -v 'Bad News' $1 & | |
say -v 'Bahh' $1 & | |
say -v 'Bells' $1 & | |
say -v 'Boing' $1 & | |
say -v 'Bruce' $1 & |
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 groc { # git rebase origin/{current} | |
local remote_branch="${1:-origin}/$(git branch | grep \* | cut -c 3-)" | |
git rebase $remote_branch | |
} | |
function gpoc { # git push origin {current} | |
local current_branch="$(git branch | grep \* | cut -c 3-)" | |
git push origin $current_branch | |
} |
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 twitter_puddle(wall): | |
height = max(wall) | |
total = 0 | |
for x in range(1, len(wall)-2): | |
lowest_wall = min(max(wall[:x]), max(wall[x+1:])) | |
if lowest_wall > wall[x]: | |
total += lowest_wall - wall[x] | |
return total | |
assert(twitter_puddle([2, 5, 1, 2, 3, 4, 7, 7, 6]) == 10) |
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 randomizeFonts() { | |
if (window.jQuery) { | |
elements = jQuery('*'); | |
families = jQuery.unique(elements.map(function() { return jQuery(this).css('font-family') })); | |
families.push("'comic sans ms', sans-serif"); | |
elements.each(function() { | |
jQuery(this).css('font-size', 32*Math.random() + 'px'); | |
jQuery(this).css('font-family', families[Math.floor(Math.random()*families.length)]); | |
}); |
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
# execute e.g. | |
# $ kill_matching phantomjs | |
function kill_matching { | |
export matchee=$1 | |
ruby -e 'puts `ps aux | grep #{`echo $matchee`}`.split("\n").each{|l| `kill -9 #{l.split[1]}` unless l.include?("grep") }' | |
} |
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
class DeepOpenStruct | |
def initialize(hash) | |
hash.each { |k, v| define_singleton_method(k) { | |
instance_variable_get(:"@#{k}") || instance_variable_set(:"@#{k}", coerce(v)) | |
} } | |
end | |
def [](k) | |
send(k) | |
end |
OlderNewer