Skip to content

Instantly share code, notes, and snippets.

View presidentbeef's full-sized avatar
🐢
May be slow to respond on OSS projects

Justin Collins presidentbeef

🐢
May be slow to respond on OSS projects
View GitHub Profile
#A little Twitter thing to post random quotes from Edsger Dijkstra
require 'yaml'
require 'open-uri'
require 'twitter' #twitter4r gem
require 'hpricot'
class DijkstraQuote
class << self
def dameraulevenshtein(seq1, seq2)
len1 = seq1.length
len2 = seq2.length
oneago = nil
row = (1..len2).to_a << 0
len1.times do |i|
twoago, oneago, row = oneago, row, Array.new(len2) {0} << (i + 1)
len2.times do |j|
cost = seq1[i] == seq2[j] ? 0 : 1
delcost = oneago[j] + 1
#Have a site that is compromised somehow.
#Someone is able to upload malicious .htaccess files that
#redirect based on User Agent being Windows and a whole list
#of possible referers, including Google.com.
#
#This script periodically checks the site and then emails if it gets
#anything other than a 200
require 'net/smtp'
site = "example.com"
@presidentbeef
presidentbeef / rubychat.rb
Created January 6, 2011 08:02
Simple Ruby chat with GServer
require 'gserver'
class ChatServer < GServer
def initialize *args
super
#Keep a list for broadcasting messages
@chatters = []
#We'll need this for thread safety
@presidentbeef
presidentbeef / BrakemanScanner.java
Created January 18, 2011 23:44
Java to parse output from Brakeman
/* Parse tab-separated output from Brakeman
* Use:
* brakeman -o example.tabs
* java BrakemanScanner example.tabs
*/
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.RandomAccessFile;
@presidentbeef
presidentbeef / gist:933331
Created April 20, 2011 23:32
Directory traversal checker
require 'cgi'
abort "Please supply hostname" unless ARGV[0]
hostname = ARGV[0]
depth = (ARGV[1] || 12 ).to_i
1.upto(depth) do |n|
$stderr.puts "Depth: #{n}"
@presidentbeef
presidentbeef / gist:1314419
Created October 25, 2011 21:46
Brakeman performance
jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (Java HotSpot(TM) Client VM 1.6.0_26) [linux-i386-java]
Single core, no threads, Linux:
jruby 1.6.5: 60.91 user 279.93 system 7:13.53 elapsed 78% CPU
--server: 60.51 user 175.19 system 4:55.54 elapsed 79% CPU
ruby 1.9.2-p290: 61.11 user 17.47 system 1:31.40 elapsed 85% CPU
Single core, with threads, Linux:
@presidentbeef
presidentbeef / gist:1470939
Created December 13, 2011 06:40
Using Brakeman::AliasProcessor
require 'ruby_parser'
require 'ruby2ruby'
require 'brakeman'
require 'brakeman/processors/alias_processor'
#Local variables for clarity
def process code
sexp = RubyParser.new.parse code
processed_sexp = Brakeman::AliasProcessor.new.process_safely sexp
pretty_code = Ruby2Ruby.new.process processed_sexp
@presidentbeef
presidentbeef / gist:1512567
Created December 23, 2011 00:52
Process routes with Brakeman::RoutesProcessor
$LOAD_PATH.unshift "/home/justin/work/brakeman/lib"
require 'brakeman'
require 'ruby_parser/ruby_parser'
require 'brakeman/tracker'
require 'brakeman/processors/route_processor'
tracker = Brakeman::Tracker.new
tracker.options[:rails3] = true
route_processor = Brakeman::RoutesProcessor.new tracker
@presidentbeef
presidentbeef / gist:1563286
Created January 5, 2012 01:56
Rescanning changed files
my_rails_app = "your/path/here"
changed_files = ["changed/files/here"]
require 'brakeman'
#Do initial scan
tracker = Brakeman.run :app_path => my_rails_app
puts "Warnings: #{tracker.checks.all_warnings.length}"
puts "Errors: #{tracker.errors.length}"