Skip to content

Instantly share code, notes, and snippets.

@mdub
mdub / use_render_main.html.haml
Created May 15, 2011 12:18
Example of using "render_main" markup builder
= render_main do |main|
- main.action_ribbon do
%p ACTION CONTENT
%p MAIN CONTENT
- main.sidebar do |sidebar|
- sidebar.header do
@mdub
mdub / gitdown.rb
Created June 14, 2011 06:54
Clamp global option example
rrequire "clamp"
class Logger
DEFAULT_LEVEL = 0
attr_accessor :log_level
def initialize
@log_level = DEFAULT_LEVEL
@mdub
mdub / newrelic-fiber-hack.rb
Created July 26, 2011 12:45
Patch the NewRelic RPM agent to allow for use of Fibers
require 'new_relic/control'
# monkey-patch NewRelic::Agent::TransactionSampler to avoid storing the
# current TransactionSampleBuilder in a Thread-local, as it does not play nicely
# in the presence of Fibers
module NewRelic
module Agent
class TransactionSampler
@mdub
mdub / postgresql_full_text_search.rb
Created August 3, 2011 07:05
PostgreSQL full-text search support for ActiveRecord
module PostgresqlFullTextSearch
extend ActiveSupport::Concern
module ClassMethods
def tsearch(column_names, terms)
raise(ArgumentError) if terms.nil?
return self.scoped if terms == ""
vectors = Array(column_names).map do |column_name|
# this is fine
params = {
"mode" => "update"
"people" => {
"jackie"=> "Jackie Watkins"
"max"=> "Max Edwards"
}
}
# this is not
@mdub
mdub / 0-readme.md
Created February 28, 2012 02:24 — forked from albertoperdomo/0-readme.md
ruby-1.9.3-p125 cumulative performance patch.

Patched ruby 1.9.3-p125 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p125 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).

Huge thanks to funny-falcon for the performance patches.

@mdub
mdub / gist:2129095
Created March 20, 2012 00:38
toplevel constant Bar referenced by Foo::Bar
>> class Foo; end
=> nil
>> module Bar; end
=> nil
>> Foo::Bar
(irb):3: warning: toplevel constant Bar referenced by Foo::Bar
=> Bar
>> Bar::Foo
NameError: uninitialized constant Bar::Foo
@mdub
mdub / output.txt
Created March 21, 2012 02:34
Ruby lazy enumerable benchmark
$ ruby --version
ruby 2.0.0dev (2012-03-20 trunk 35094) [x86_64-darwin11.3.0]
$ ruby pipeline_bench.rb
IMPLEMENTATION take(10) take(100) take(1000) to_a
conventional (eager) 0.01416 0.01407 0.01422 0.01411
enumerating 0.00003 0.00007 0.00063 0.03140
lazing 0.00004 0.00011 0.00098 0.04759
ruby2 Enumerable#lazy 0.00004 0.00013 0.00112 0.05304
facets Enumerable#defer 0.00005 0.00018 0.00162 0.07108
@mdub
mdub / getoptlong-test.rb
Created April 24, 2012 04:00
Play with getoptlong
require 'getoptlong'
opts = GetoptLong.new(
[ "--name", "-n", GetoptLong::REQUIRED_ARGUMENT ],
[ "--help", "-h", GetoptLong::NO_ARGUMENT ],
[ "--version", "-v", GetoptLong::NO_ARGUMENT ]
)
opts.each do |opt, arg|
p [opt, arg]
@mdub
mdub / gist:2946149
Created June 18, 2012 00:20
ST2 custom keybindings
[
{ "keys": ["super+ctrl+r"], "command": "reveal_in_side_bar" },
{ "keys": ["super+shift+\\"], "command": "reindent" },
{ "keys": ["alt+m"], "command": "markdown_preview", "args": {"target": "browser"} }
]