Skip to content

Instantly share code, notes, and snippets.

View postmodern's full-sized avatar
🚀
releasing new versions

Postmodern postmodern

🚀
releasing new versions
View GitHub Profile
@postmodern
postmodern / http_parser.rb
Created January 15, 2011 04:39
A pure Ruby HTTP parser using Parslet.
require 'parslet'
require 'pp'
class HTTPParser < Parslet::Parser
#
# Character Classes
#
rule(:digit) { match('[0-9]') }
rule(:digits) { digit.repeat(1) }
rule(:xdigit) { digit | match('[a-fA-F]') }
@postmodern
postmodern / c_parser.rb
Created January 16, 2011 04:24
An ANSI C Parser using the Ruby Parslet library.
#
# A C Parser using the Parslet library.
#
# ANSI C Grammar:
#
# * http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
# * http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
#
require 'parslet'
@postmodern
postmodern / log.txt
Created January 19, 2011 05:17
Net::HTTP::Server benchmark.
$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-linux]
$ ab -n 1000 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 100 requests
Completed 200 requests
@postmodern
postmodern / list_prior_art.rb
Created March 8, 2011 23:59
Lists prior "art" (aka all of your repositories).
#!/usr/bin/env ruby
require 'net/http'
require 'json'
require 'date'
class PriorArt < Struct.new(:name,:description,:created_at,:updated_at)
end
prior_art = {}
@postmodern
postmodern / gix_require_benchmark.rb
Created March 10, 2011 05:04
Benchmark each require in your Ruby code.
require 'rubygems'
require 'rbtree'
class Req
attr_accessor :path, :time, :requires, :exception
def initialize(path)
@path = path
@requires = []
@time = 0
end
@postmodern
postmodern / gist:863599
Created March 10, 2011 05:05
Times for each require in ronin.
ruby-1.9.2-p180 :001 > require './require_benchmark.rb'
=> true
ruby-1.9.2-p180 :002 > require 'ronin'
=> true
ruby-1.9.2-p180 :003 >
0.00090616 tsort
0.001040251 enumerator
0.001549864 pathname
0.001783703 set
0.001899229 data_paths/data_paths
@postmodern
postmodern / gist:900981
Created April 4, 2011 00:45
implicit splat and explicit splat in Ruby 1.9
class Command
def initialize(path,arguments,env={})
@path = path
@arguments = arguments
@env = env
end
def to_ary
[@env, @path, @arguments]
@postmodern
postmodern / sqlmap.txt
Created April 13, 2011 07:14
injections used by sqlmap.py
ccopy_reg
_reconstructor
p0
(clib.core.datatype
injectionDict
p1
c__builtin__
dict
p2
(dp3
@postmodern
postmodern / dm_find_validation_errors.rb
Created April 15, 2011 08:43
Quick and Dirty way to find DataMapper Validation errors.
require 'pp'
invalids = ObjectSpace.each_object(DataMapper::Resource).select { |obj| !obj.saved? && !obj.valid? }
pp invalids.map { |obj| [obj.class, obj.errors.to_hash] }
@postmodern
postmodern / gist:939069
Created April 23, 2011 23:05
A Mixin module, that configures other modules so they can be included or extended.
module Mixin
def self.included(base)
base.module_eval do
def self.mixin(*modules,&block)
@mixin_modules = modules
@mixin_block = block
def self.included(base)
unless @mixin_modules.empty?
base.send(:include,*@mixin_modules)