Skip to content

Instantly share code, notes, and snippets.

View andynu's full-sized avatar

Andrew Nutter-Upham andynu

View GitHub Profile
# zsh function
svnhistgrep () {
term=$1
file=$2
versions=($(svn log $file | perl -ne 'print "$1 " if (/r(\d+)/)'))
for r in $versions
do
echo "$file r$r"
svn cat -r$r $file | egrep -C 3 -n $term
done
@andynu
andynu / gist:283144
Created January 21, 2010 20:05
scm related zsh aliases (svn, svk, git)
# my scm related aliases
export clrsvn='sed \
-e "s/^\? \(.*\)/$(tput setaf 243) [?] \1$NC/" \
-e "s/^A \(.*\)/$(tput setaf 02) [A] \1$NC/" \
-e "s/^C \(.*\)/$(tput setaf 200) [C] \1$NC/" \
-e "s/^D \(.*\)/$(tput setaf 01) [D] \1$NC/" \
-e "s/^I \(.*\)/$(tput setaf 238) [I] \1$NC/" \
-e "s/^! \(.*\)/$(tput setaf 09) [!] \1$NC/" \
-e "s/^G \(.*\)/$(tput setaf 214) [G] \1$NC/" \
-e "s/^M \(.*\)/$(tput setaf 11) [M] \1$NC/" \
@andynu
andynu / ftptls_rss.rb
Created June 10, 2010 19:49
ftp listing to rss
#!/usr/bin/ruby
#
# little ftps with tls to rss utility
# makes a connection, lists the contents of the
# directory and produces an rss feed of the results.
#
# config in our home directory ~/.ftprss
# example:
# :host: ftp.example.com
# :user: username
@andynu
andynu / highlight.rb
Created August 20, 2010 17:07
a filter to colorize output
#!/usr/bin/ruby
# encoding: utf-8
#
# filter to colorize output
#
# cat file | highlight aaa bbb cc
#
# aaa,bbb,ccc all get assigned different colors and are highlighted in the output
#
@andynu
andynu / list_by_role.rb
Created October 12, 2010 07:06
a capistrano task to list tasks by role.
# a capistrano task to list tasks by role.
namespace :list do
desc "list tasks by role"
task :by_role do
tasks = top.task_list(:all)
set(:verbose, false) unless exists?(:verbose)
unless verbose
tasks = tasks.reject { |t| t.description.empty? || t.description =~ /^\[internal\]/ }
end
@andynu
andynu / jenkins.pl
Created September 23, 2011 17:05
Jenkins CI External Task Submission Perl Script
#!/usr/bin/env perl
#
# A job run submission script for
# Jenkins (http://jenkins-ci.org/)
#
# Your command will run regardless of if the jenkins server is up or
# not. However there is no buffering so if your jenkins server is not
# up when the task completes then the run won't be recorded.
#
@andynu
andynu / active_record_by_inference.rb
Created September 24, 2011 21:56
Reverse engineer ActiveRecord definitions by examining an existing (mysql) database.
#!/usr/bin/env ruby
# encoding: utf-8
#
# Reverse engineer ActiveRecord definitions
# by examining an existing database.
#
# This is mysql spesific at the moment.
#
# % active_record_by_inference -h
# Usage: active_record_by_inference.rb [options] [table] [table] ...
@andynu
andynu / falling_balls.js.coffee
Created September 28, 2011 12:31
a coffeescript clone of the processing's bouncybubbles example
#
# a coffeescript port of http://processing.org/learning/topics/bouncybubbles.html
#
ids = 0
spring = 0.02
gravity = 0.01
friction = -0.2
force_field = 1.5
balls = []
@andynu
andynu / rest_api.sh
Created November 30, 2011 05:51
Bare bones, no auth, json rest server in rails.
#!/bin/bash -x
rvm install 1.9.3-head
rvm use 1.9.3-head
rvm gemset create rails31
rvm use 1.9.3-head@rails31
gem install bundler rails
rails new rest_api
@andynu
andynu / gist:1477485
Created December 14, 2011 17:08
A array of hashes summing method
def sum_by(arr_hash, value_key, group_key=nil, &block)
if group_key.instance_of? Proc
block = group_key
group_key = nil
end
arr_hash.inject({}) do |sums, row|
group_key = (block_given?) ? block.call(row) : group_key
sums[group_key] ||= 0.0
sums[group_key] += row[value_key] || 0.0
sums