Skip to content

Instantly share code, notes, and snippets.

Avatar
🪕
Scruggs not drugs

Norman Clarke norman

🪕
Scruggs not drugs
View GitHub Profile
@norman
norman / gist:31643
Created Dec 3, 2008
AR monkeypatch to allow :order => :random
View gist:31643
module ActiveRecord
class Base
private
def self.add_order!(sql, order, scope = :auto)
scope = scope(:find) if :auto == scope
scoped_order = scope[:order] if scope
if order
sql << " ORDER BY #{connection.order(order)}"
@norman
norman / presenters-kit.en.textile
Created Jan 19, 2009
Presenter's Kit for the "Locos Por Rails" conference in Buenos Aires
View presenters-kit.en.textile
View presenters-kit.es.textile
View gist:141646
local val = "hello world"
local env = getfenv()
local func = assert(loadstring("print(val)"))
setfenv(func, env)
print(func())
-- expecting "hello world" but get "nil"
View gist:144664
require 'luarocks.require'
require 'rex'
require 'socket'
-- returns tag, id and classes
function parse_haml_tag_using_regex(str)
return rex.match(str, '(%[a-z0-9]*)?(#[a-z0-9-_]*)?(\.[a-z0-9-_\.]*)?')
end
-- returns tag, id and classes
View gist:284082
# ruby-1.9.1-p378
irb(main):009:0> "é".force_encoding("UTF-8") =~ /[\W]/u
=> 0
irb(main):010:0> "e".force_encoding("UTF-8") =~ /[\W]/u
=> nil
# ruby-1.9.1-p243
irb(main):006:0> "é".force_encoding("UTF-8") =~ /[\W]/u
=> nil
irb(main):007:0> "e".force_encoding("UTF-8") =~ /[\W]/u
View gist:294710
| AR |
--------------------------------------------------------------------------------------
find model using id x2000 | 1.264 |
find model using array of ids x2000 | 2.708 |
find unslugged model using friendly id x2000 | 1.954 |
find unslugged model using array of friendly ids x2000 | 2.829 |
find slugged model using friendly id x2000 | 3.305 |
find slugged model using array of friendly ids x2000 | 8.431 |
find cached slugged model using friendly id x2000 | 2.117 |
find cached slugged model using array of friendly ids x2000 | 3.178 |
View gist:314267
$ gem install date-performance
Building native extensions. This could take a while...
ERROR: Error installing date-performance:
ERROR: Failed to build gem native extension.
/Users/norman/.rvm/rubies/ruby-1.9.1-p378/bin/ruby extconf.rb
creating Makefile
make
gcc -I. -I/Users/norman/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/i386-darwin10.2.0 -I/Users/norman/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1/ruby/backward -I/Users/norman/.rvm/rubies/ruby-1.9.1-p378/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -pedantic -Wall -Wno-long-long -Winline -o date_performance.o -c date_performance.c
View gist:338082
class Sitemap
attr_accessor :entries
def add(array, &block)
array.map do |a|
if entry = block(a)
@entries << entry
end
end
View gist:340373
require "mocha"
Factory.define :post do |p|
p.title "first post"
p.after_build do |post|
slug = Slug.new(:name => "first-post", :sequence => 1, :sluggable => post)
post.stubs(:slug).returns(slug)
end
end