Skip to content

Instantly share code, notes, and snippets.

View byingyang's full-sized avatar

Brad Yinger byingyang

View GitHub Profile
@byingyang
byingyang / sniff.rb
Created July 15, 2011 17:09
A little script I whipped together to spit out all network traffic using libpcap
#!/usr/bin/env ruby
# this line imports the libpcap ruby bindings
require 'pcaplet'
# create packet sniffer on the wireless card
network = Pcaplet.new('-s 1500 -i en0')
# we only need to look at web packets
www_filter = Pcap::Filter.new('tcp and dst port 80', network.capture)
network.add_filter(www_filter)
@byingyang
byingyang / pandorizer.rb
Created July 15, 2011 17:08
An old script I whipped together that downloads every song that plays on pandora
#!/usr/bin/env ruby
# this line imports the libpcap ruby bindings
require 'rubygems'
require 'pcap'
require 'pcaplet'
require 'socket'
# thread safe... but we're counting on the fact that the sniffer won't begin again until we're at least
# partially requesting the song (the GET keyword has already been written by the time the network listener is listening again)
@byingyang
byingyang / util.py
Created July 15, 2011 17:06
Code that is commonly used in programming contest problems
# C-Snake's Ruby
# Commonly used contest code
#
# Last updated: 3-1-2010
import math
def fib(n):
'''Returns the nth fibonacci number O(n)'''
a, b = 0, 1
i = 1
@byingyang
byingyang / waves.txt
Created July 15, 2011 16:08
Shortwave config
> Lines beginning with `>` are comments.
> Comments and empty lines are ignored.
>
> Each command is defined on a single line comprised of:
>
> 1. a case-insensitive, alpha-numeric trigger followed
> by whitespace
> 2. a url followed by whitespace (if the url contains
> spaces they must be encoded as `%20`)
> 3. a short description
@byingyang
byingyang / gist:181626
Created September 6, 2009 03:02
Script to batch import tasks into the "Things" app by Cultured Code
# format:
# --------------
# date (mm/dd/yy)
# assignment
# assignment
# ...
#
# date
# assignment
# ...
@byingyang
byingyang / calcchat.rb
Created April 4, 2009 20:19
Script to open web page containing solution to a calcchat.com problem
#!/usr/bin/env ruby
chapter, section, question = ARGV
letter = ('a'[0] + section.to_i - 1).chr
`open 'http://calcchat.tdlc.com/calcchat/printsolution.jsp?roomName=Calculus%208e%20#{chapter}.#{section}%20Ex%20#{question}&artName=se#{'%02d' % chapter}#{letter}01#{'%03d' % question}&chapFolder=#{'%02d' % chapter}&secFolder=#{letter}&solutionPath=http://calcchat.tdlc.com/solutionart/calc8e/'`
@byingyang
byingyang / find_unused_images.rb
Created March 12, 2009 20:51
Displays the file names of files that are not found in any documents under the given search directories
#!/usr/bin/env ruby
def unused_images(image_path_dir, search_dirs)
img_fns = Dir.glob("#{image_path_dir}**/*.*")
search_dirs.each {|sd| img_fns.delete_if{|img_fn| `grep -r '#{File.basename(img_fn)}' #{sd}` != ""}}
return img_fns
end
if ARGV.size < 2
puts "Usage: image_cleanup path_to_images path_to_search ..."