Skip to content

Instantly share code, notes, and snippets.

View norman's full-sized avatar
🪕
Scruggs not drugs

Norman Clarke norman

🪕
Scruggs not drugs
View GitHub Profile
@norman
norman / benchmarks.txt
Last active December 20, 2015 21:58
FriendlyId 5.0 versus 4.0
## 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)
@norman
norman / Gemfile
Last active November 21, 2019 11:58
Delayed Job without Rails
source 'https://rubygems.org'
gem 'delayed_job'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'pg'
" 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
@norman
norman / date.rb
Created April 10, 2013 14:07
My code before and after reading the docs for Ruby's Date class from stdlib.
# 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
require "ffaker"
require 'thread'
class ConcurrentHash
def initialize
@reader, @writer = {}, {}
@lock = Mutex.new
end
def [](key)
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
bundle exec ./bench.rb
Using Haml 3.1.8 (Separated Sally)
Template: /Users/norman/work/haml-bench/standard.haml
Darwin Normans-MacBook-Pro.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.0]
------------------------------------------------------------------------
1000 Iterations
Rehearsal --------------------------------------------------------
compiled haml pretty 0.770000 0.020000 0.790000 ( 0.924422)
@norman
norman / iso8601.rb
Last active December 12, 2015 01:38
require "rubygems"
require "tzinfo"
input = '1/31/13 13:34'
format = '%m/%d/%y %H:%M'
zone = TZInfo::Timezone.get('America/Los_Angeles')
local = DateTime.strptime(input, format)
utc = zone.local_to_utc(local)
output = utc.iso8601
http://d3.minus.com/1341336326/SNLI5co7KKoIjMjzrX2SGg/dD0pIYLgWF7lV/One-Click-G2x-recovery-flasher-04-28-12.rar
require "haml"
Haml::Helpers::HTML_ESCAPE['&'] = '&#x0026'
Haml::Engine.new(%q{%a(href='/posts' data-icon="&" aria-hidden='true')}).render
=> "<a aria-hidden='true' data-icon='&#x0026' href='/posts'></a>\n"