Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / commands.sh
Created July 20, 2011 20:10
IP cheats
# determine interfaces in promiscuous mode (ie sniffing)
ifconfig | grep PROMISC
# DNS lookup, reverse lookup
nslookup
# List all processes, for all users
# UID PID PPID C STIME TTY TIME CMD
ps -afx
@thinkerbot
thinkerbot / setup_history.sh
Created July 13, 2011 17:30
Setup bash history
cat > histfile <<DOC
echo a
echo b
echo c
DOC
# run a new shell to clear out history artifacts
sh
history -cr histfile
!1
@thinkerbot
thinkerbot / ip_to_hex.sh
Created July 7, 2011 17:08
Convert IP addresses to hex from the command line
function ip_to_hex() {
dec=$(echo "$1" | tr '.' ';')
hex=$(echo "obase=16;$dec" | bc)
printf "%02x%02x %02x%02x\n" 0x$hex
}
@thinkerbot
thinkerbot / Rakefile
Created June 15, 2011 16:22
Illustration of rake/pull/24
# To run, export RUBYOPT so that it applies the patch before invoking rake:
#
# export RUBYOPT='-rpatch'
# rake -h
# rake -T
# rake -- cmd_echo a b
#
#
# Part 1
@thinkerbot
thinkerbot / fetch.rb
Created May 30, 2011 17:43
fetch + format craigslist data into csv
require 'rubygems'
require 'rest_client'
request = 'http://denver.craigslist.org/search/cta?query=accord&srchType=T&minAsk=8000&maxAsk=20000&hasPic=1&s=%s'
page_min, page_max = ARGV
(page_min.to_i...page_max.to_i).each do |page|
puts RestClient.get(request % page)
end
@thinkerbot
thinkerbot / current_ruby.sh
Created May 25, 2011 17:10
print the current ruby
ruby --version | cut -d ' ' -f '1 2' | tr ' ' -
@thinkerbot
thinkerbot / example.sh
Created May 24, 2011 00:17
demonstrates error with rvmrc + 'rvm exec rvm current'
mkdir example
cd example
rvm exec ruby --version
# jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2010-12-03 9cf97c3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [x86_64-java]
# jruby 1.6.1 (ruby-1.8.7-p330) (2011-04-12 85838f6) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [darwin-x86_64-java]
# rubinius 1.2.4dev (1.8.7 a81a80db yyyy-mm-dd JI) [x86_64-apple-darwin10.4.0]
# ruby 1.8.6 (2010-09-02 patchlevel 420) [i686-darwin10.4.0]
# ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10.4.0]
# ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.4.0]
@thinkerbot
thinkerbot / .gitignore
Created May 10, 2011 17:05
Generate madlibs
*/*.txt
*.sh
*.gz
@thinkerbot
thinkerbot / Rakefile
Created April 25, 2011 06:57
Pagination task for an rdoc tutorial
desc "Setup pagination links for tutorial"
task :paginate_tutorial do
pages = Dir.glob File.expand_path('../Tutorial/*', __FILE__)
pages.each_with_index do |page, index|
content = File.read(page)
content.gsub!(/^(Previous|Next)\[link:.*\]$/, '').strip!
previous_page = pages[index - 1]
next_page = pages[index + 1] || pages[0]
@thinkerbot
thinkerbot / newline_shell_out.rb
Created January 24, 2011 21:55
examples of handling newlines in ruby shell-out
# echo -e "abc\nabc"
# echo -e "xyz\
# xyz"
puts `echo "abc\nabc"`
puts `echo "xyz\
xyz"`
abc = "abc\nabc"
puts `echo "#{abc}"`