Skip to content

Instantly share code, notes, and snippets.

View timruffles's full-sized avatar

Tim Ruffles timruffles

View GitHub Profile
@timruffles
timruffles / boot_time_comparison.rb
Created October 13, 2011 11:11
How to save 30s every time you run rake
boot_times = """
rails 0.00046
mysql2 0.106019
json 0.064801
rdoc 0.001773
aasm 0.02832
asset_hat 0.049811
chronic 0.048493
fastercsv 0.077824
airbrake 0.966085
@timruffles
timruffles / null.rb
Created October 13, 2011 14:17
NullObject
class NullObject
def initialize target_class
@target_class = target_class
end
def method_missing method, *args, &block
if @target_class.instance_methods.include?(method)
nil
else
raise "Tried to call '#{method}' on a NullObject for #{@target_class}; method doesn't exist on #{@target_class}"
end
@timruffles
timruffles / server.go
Created October 14, 2011 14:55
HTTP server challenge entry
package main
import (
"net"
"regexp"
"fmt"
"bufio"
"bytes"
)
func main() {
get_parser := regexp.MustCompile("[\\?&]value=([^& ]+)*")
@timruffles
timruffles / js_coffee.txt
Created October 15, 2011 16:01
JS Coffeescript real world comparison
+-----------------------------------------------------+--------------+-------------------+----------+---------------+
| File | Coffee Lines | Coffee Characters | JS Lines | JS Characters |
+-----------------------------------------------------+--------------+-------------------+----------+---------------+
| app/coffee/plv/accessors.coffee | 17 | 320 | x 1.9 | x 1.8 |
| app/coffee/plv/clock.coffee | 30 | 671 | x 1.6 | x 1.6 |
| app/coffee/plv/collection.coffee | 38 | 1089 | x 1.9 | x 1.4 |
| app/coffee/plv/comparison.coffee | 13 | 192 | x 1.5 | x 1.6 |
| app/coffee/plv/config.coffee | 24 | 597 | x 1.3 | x 1.1 |
| app/coffee/plv/console.coffee | 8 | 162
@timruffles
timruffles / js_coffee_comp.rb
Created October 15, 2011 16:04
JS coffee script size comparsion table
require "rubygems"
require "terminal-table/import"
def coffee_length file
non_comment = open(file).read.split("\n").reject {|l| l =~ /^(?:\s+#.*|\s*)$/}
[non_comment.length, character_length(non_comment)]
end
def js_length file
non_comment = open(file).read.split("\n").reject {|l| l =~ /^(?:\s+\/\/.*|\s+\/\*[^\*]*\/\s*|\s*)$/}
[non_comment.length, character_length(non_comment)]
end
@timruffles
timruffles / meh.coffee
Created October 26, 2011 22:23
canvas test
Element::on = Element::addEventListener
doc = document
Array::each = Array::forEach
Number::times = (fn) ->
iter = 0
while iter++ < this
fn(iter)
Enemy = (@pubSub) ->
@timruffles
timruffles / throttler.coffee
Created October 31, 2011 18:08
throttler.coffee
realThrottle = (fn,throttledFor) ->
throttler = {}
->
unless throttler.throttled
fn()
throttler.throttled = true
setTimeout (-> throttler.throttled = false), throttledFor
@timruffles
timruffles / datamung.rb
Created November 4, 2011 18:21
an enviroment for quick shell data munging in xml,html or json
#!/usr/bin/ruby
require "rubygems"
require "nokogiri"
require "json"
format = ARGV[0]
code = ARGV[1]
class Runner
attr_accessor :doc
@timruffles
timruffles / point_in_poly.coffee
Created November 8, 2011 17:28
Point in poly in coffeescript
pointInPoly = (point,poly) ->
segments = for pointA, index in poly
pointB = poly[(index + 1) % poly.length]
[pointA,pointB]
intesected = (segment for segment in segments when rayIntesectsSegment(point,segment))
intesected.length % 2 != 0
rayIntesectsSegment = (p,segment) ->
[p1,p2] = segment
[a,b] = if p1.y < p2.y
@timruffles
timruffles / microrequire.coffee
Created November 17, 2011 15:33
microrequire
((global)->
global.require = (deps,fn) ->
whenLoaded(deps,fn)
defined = {}
waitingOn = {}
whenLoaded = (deps,action) ->
waiter =