Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / git-reauthor-latest
Created September 5, 2012 19:07
Rewrite recent commits with current pair
#!/bin/sh
##########################################################################
# Example:
#
# git checkout some_branch
# git pair sc
# git reauthor-latest 3
#
n=${1:-0}
@thinkerbot
thinkerbot / slice
Created August 24, 2012 19:33
Print segments of files at the same location.
#!/usr/bin/env ruby
begin
require 'optparse'
offset=0
length=-1
lineno=nil
quiet=false
OptionParser.new do |opts|
@thinkerbot
thinkerbot / README.md
Created August 19, 2012 20:30
Command line option handling strategies

= Argument handling strategies

# generate 1k,10k worth of arg data
ruby -e '200.times  {|i| puts("%.5d" % i) }' > 1k.txt
ruby -e '2000.times {|i| puts("%.5d" % i) }' > 10k.txt

# check size, bytes should be 1k
cat 1k.txt | tr -d "\n" | wc

baseline

@thinkerbot
thinkerbot / remove_unused_routes
Created August 7, 2012 16:06
Remove unused routes from config/routes.rb
#!/bin/bash
########################################################################
# Add to Gemfile:
#
# gem 'traceroute', '= 0.2.2'
#
# Then:
bundle install
Meh. Not that secret.
@thinkerbot
thinkerbot / Gemfile
Created June 14, 2012 23:04
ActiveRecord vs Machinist vs FactoryGirl
source 'http://rubygems.org'
gem 'activerecord'
gem 'sqlite3'
gem 'factory_girl', '= 2.6.4'
gem 'machinist'
@thinkerbot
thinkerbot / README.md
Created June 7, 2012 21:03
Find and remove old git branches

Description

Find and delete old git branches that are no longer needed.

Usage

Clone the repo and add to your path (just for ease of use):

Utilities

# fork
zmqc -w PUSH ADDRESS...

# merge 
zmqc -w PULL ADDRESS...

Wrapper

@thinkerbot
thinkerbot / .gitignore
Created May 8, 2012 20:09
Ruby sprintf from the command line.
/ronn
@thinkerbot
thinkerbot / README.md
Created May 7, 2012 02:06
A shell script transpiler

Provides a mechanism to write portable shell scripts in a higher-level language.

Ruby may be used to describe shell scripts in code. For example shell commands may be represented as methods and command pipelines as method chains. The method calls are translated into shell script. Zero or more script files may be generated in this process.

Cursor objects can be used to mark the locations in the final script where a given shell expression is to be added. For example one cursor could mark where options are defined in a 'getopts' command, another could mark where the option