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 / gist:1068927
Created July 7, 2011 05:23
half-assed attempt at rewriting dm-gen to use Thor
require 'thor'
require 'thor/actions'
module DataMapper
module Gen
class CLI < Thor
include Thor::Actions
DM_VERSION = '1.0'
@postmodern
postmodern / gist:1020374
Created June 11, 2011 08:44
rbx -Xprofile benchmarks/hexdump.rb
% cumulative self self total
time seconds seconds calls ms/call ms/call name
------------------------------------------------------------
10.98 277.26 104.33 30721151 0.00 0.01 Hash#find_entry
9.58 116.29 91.02 36303266 0.00 0.00 Hash::Entry#match?
9.51 141.50 90.35 29760101 0.00 0.00 String#<<
5.52 501.94 52.41 9920000 0.01 0.05 Hexdump::Dumper::print<330> {}
4.72 949.77 44.83 12 3735.59 79147.48 String#each_byte
4.70 345.50 44.70 9920000 0.00 0.03 Hexdump::Dumper::each<279> {}
4.18 321.67 39.69 30721093 0.00 0.01 Hash#[]
@postmodern
postmodern / gist:963589
Created May 9, 2011 22:51
net-http-server benchmarks (single threaded)
$ 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
Completed 300 requests
Completed 400 requests
@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)
@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 / 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 / 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 / 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 / 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 / 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 = {}