This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gserver' | |
class ChatServer < GServer | |
def initialize *args | |
super | |
#Keep a list for broadcasting messages | |
@chatters = [] | |
#We'll need this for thread safety |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
OlderNewer