Skip to content

Instantly share code, notes, and snippets.

View kschiess's full-sized avatar
💭
see .plan

Kaspar Schiess kschiess

💭
see .plan
View GitHub Profile
@kschiess
kschiess / gist:2788364
Created May 25, 2012 14:15
parslet 1.3.0 vs. treetop
CSV parsing
size parslet treetop csv
253: 0.020 0.020 0.000
5293: 0.540 0.130 0.000
10207: 1.170 0.210 0.000
15247: 1.600 0.510 0.010
20161: 2.430 0.650 0.010
25201: 3.170 0.820 0.000
30115: 3.970 0.970 0.210
35155: 4.810 1.320 0.010
@kschiess
kschiess / gist:2788349
Created May 25, 2012 14:12
parslet 1.4.0 vs. treetop
CSV parsing
size parslet treetop csv
253: 0.010 0.010 0.000
5293: 0.330 0.120 0.010
10207: 0.670 0.240 0.000
15247: 1.100 0.430 0.000
20161: 1.550 0.580 0.000
25201: 1.950 0.810 0.010
30115: 2.480 0.960 0.160
35155: 3.100 1.130 0.010
@kschiess
kschiess / unicorn_hunter.rb
Created March 21, 2012 12:59
Hunts down your unicorn workers and kills them
require 'guard/guard'
module Guard
class UnicornHunter < Guard
# Called on file(s) modifications that the Guard watches.
# @param [Array<String>] paths the changes files or paths
# @raise [:task_has_failed] when run_on_change has failed
def run_on_change(paths)
if system("killall -m 'unicorn worker'")
puts "Unicorn hunter has found a unicorn..."
@kschiess
kschiess / textmate.rb
Created February 14, 2012 11:23
A textmate like folder search using picky. This is just a prototype.
require 'picky'
require 'facets'
require 'facets/array/combination.rb'
Picky.logger = Picky::Loggers::Silent.new
input = ARGV
Folder = Struct.new(:id, :name)
folders = Dir[ENV['HOME'] + "/**"].
@kschiess
kschiess / funcall.rb
Created November 4, 2011 10:02
Extends Mini-Parser from Getting Started to be able to use funcalls wherever a simple integer would do
require 'pp'
require 'parslet'
require 'parslet/convenience'
class MiniP < Parslet::Parser
# Single character rules
rule(:lparen) { str('(') >> space? }
rule(:rparen) { str(')') >> space? }
rule(:comma) { str(',') >> space? }
@kschiess
kschiess / prevent.rb
Created October 26, 2011 11:48
How to prevent rake from polluting global namespace
class Module
def with_rake_pollution_prevention_append_features(klass)
unless caller.first.match(/rake/) && self.name == "Rake::DeprecatedObjectDSL"
without_rake_pollution_prevention_append_features(klass)
end
end
alias without_rake_pollution_prevention_append_features append_features
alias append_features with_rake_pollution_prevention_append_features
end
require 'parslet'
require 'parslet/convenience'
require 'pp'
def parse(input)
parser = SongParser.new
begin
tree = parser.parse(input)
rescue Parslet::ParseFailed => error
puts error, parser.root.error_tree
@kschiess
kschiess / gist:1151562
Created August 17, 2011 13:51
A matcher thingy.
class Matcher
def initialize(expr)
@expr = expr
end
def ===(value)
@bindings = {}
match(@expr, value, @bindings)
end
@kschiess
kschiess / split.rb
Created February 15, 2011 10:40
prints instance variable accesses inside a class methods.
#!/usr/bin/env ruby
require 'ruby_parser'
class Graph
def initialize
@watch_lvars = []
end
def visit(tree)
require 'rubygems'
require 'parslet'
require 'pp'
class JSON < Parslet::Parser
rule(:space) { match('\s').repeat(1) }
rule(:space?) { space.maybe }
rule(:quote) { str('"') }
rule(:nonquote) { str('"').absnt? >> any }
rule(:comma) { str(',') >> space? }