ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.4.0]
------------------------------------------------------------------------
1000 Iterations
Rehearsal --------------------------------------------------------
compiled haml pretty 0.550000 0.000000 0.550000 ( 0.551526)
compiled haml ugly 0.270000 0.000000 0.270000 ( 0.270457)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local class = {} | |
local methods = {} | |
function class.new() | |
local instance = {} | |
return setmetatable(instance, {__index = methods}) | |
end | |
return class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# By default, changes to the layout temnplate won't cause a Rails etag | |
# to change. I suppose this is to facilitate Turbolinks. Sometimes you | |
# might want to change an etag in response to changes in the layout - | |
# this is particularly true when working in development mode. This is | |
# one way to do it, there are probably other (read: likely better) ways | |
# to do this too. | |
class FooController < ApplicationController | |
# There's probably some API method to get the name of the layout | |
# rather than hard-coding it like I did here, but I'm too lazy to | |
# look it up right now. |
FriendlyId uses Rails's extending method to avoid overwriting your model's find
method. Internally this is implemented similar to this:
def self.friendly
all.extending(friendly_id_config.finder_methods)
end
This however comes with a performance impact, because extending
invokes Ruby's extend
, which blows away MRI's method cache. To work around this, FriendlyId lets you include a :finders
module which overrides your model's find
to increase performance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FlexMinder | |
module Factories | |
def factory(klass, attributes) | |
name = klass.to_s | |
underscored = name.underscore | |
class_eval(<<-END, __FILE__, __LINE__ + 1) | |
def build_#{underscored}(attributes = {}) | |
attributes = valid_#{underscored}_attributes.deep_merge(attributes) | |
#{name}.new(attributes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## FriendlyId 5.0 | |
------------------------------------------------------------------------ | |
Using ruby 2.0.0 AR 4.0.0 with sqlite3 (in-memory) | |
Rehearsal ------------------------------------------------------------------------- | |
find (without FriendlyId) 0.410000 0.000000 0.410000 ( 0.412285) | |
find (in-table slug) 0.890000 0.000000 0.890000 ( 0.911959) | |
find (in-table slug; finders addon) 0.670000 0.010000 0.680000 ( 0.686639) | |
find (external slug) 1.660000 0.040000 1.700000 ( 1.721548) | |
insert (without FriendlyId) 0.960000 0.010000 0.970000 ( 0.977678) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" File Name: removeTrailingSpace.vim | |
" | |
" Author: Sudipta Ghorui <sudipta05@gmail.com> | |
" | |
" Credits: Bitan Kundu <bitan@alumnux.com> | |
" who always suggested me to do this manualy | |
" | |
" Last Modified: 05 May 2006 | |
" | |
" Description: removes the trailing space from the file when user will save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# before | |
class Date | |
def first_business_day_of_month | |
date = beginning_of_month | |
loop do | |
return date if date.workday? | |
date = date.next | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "ffaker" | |
require 'thread' | |
class ConcurrentHash | |
def initialize | |
@reader, @writer = {}, {} | |
@lock = Mutex.new | |
end | |
def [](key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "ffaker" | |
require 'thread' | |
# Taken from Josh Peek's code at: http://stackoverflow.com/questions/1080993/pure-ruby-concurrent-hash | |
class ConcurrentHash | |
def initialize | |
@reader, @writer = {}, {} | |
@lock = Mutex.new | |
end |