Skip to content

Instantly share code, notes, and snippets.

@hasclass
hasclass / Foobar
Created June 27, 2019 08:32
Foobar
asdf
# --- BEFORE ---
module Rack
class ETag
def call(env)
# ...
unless headers['Cache-Control']
if digest
headers['Cache-Control'] = @cache_control if @cache_control
else
/*!
* jQuery JavaScript Library v1.9.0pre
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license
* http://jquery.org/license
/*!
* jQuery JavaScript Library v1.9.0pre
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license
* http://jquery.org/license
@hasclass
hasclass / jquery.typeFast.js
Created December 18, 2012 15:00
optimized jquery.type method.
/*!
* jQuery JavaScript Library v1.9.0pre
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license
* http://jquery.org/license
class Foo
def method_missing(method_name, *args)
return if method_name == :to_ary
# ...
end
end
# Running above benchmark
# user system total real
# flatten Object objects 0.000000 0.000000 0.000000 ( 0.014153)
require 'benchmark'
class Foo
def method_missing(method_name, *args)
if method_name.match(/foo_bar/)
# code
else
super(method_name, *args)
end
end
@hasclass
hasclass / test.rb
Created October 27, 2010 12:23
Test
class Foo
def foo
return nil
end
end
ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)
# Group an array into a Hash of Arrays
#
# [<Obj: name, category>,<Obj: name, category>,<Obj: name, category>]
#
# => {'category_1' => [<Obj: name, category>], 'category_2' => [<Obj: name, category>,<Obj: name, category>]}
arr.inject({}) {|hsh,obj| hsh[obj.category] ||= []; hsh[obj.category] << obj; hsh}