Skip to content

Instantly share code, notes, and snippets.

Avatar
🪕
Scruggs not drugs

Norman Clarke norman

🪕
Scruggs not drugs
View GitHub Profile
@norman
norman / Gemfile
Last active Nov 21, 2019
Delayed Job without Rails
View Gemfile
source 'https://rubygems.org'
gem 'delayed_job'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'pg'
View RemoveTrailingSpace.vim
" 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 Apr 10, 2013
My code before and after reading the docs for Ruby's Date class from stdlib.
View date.rb
# 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
View uniqifier.rb
require "ffaker"
require 'thread'
class ConcurrentHash
def initialize
@reader, @writer = {}, {}
@lock = Mutex.new
end
def [](key)
View uniqifier.rb
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
View haml-benchmark.txt
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)
View iso8601.rb
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
View gist:3040150
http://d3.minus.com/1341336326/SNLI5co7KKoIjMjzrX2SGg/dD0pIYLgWF7lV/One-Click-G2x-recovery-flasher-04-28-12.rar
View gist:2993097
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"
View gist:2962063
function eval_data(string)
local chunk, err = loadstring(string)
if not chunk then error(err) end
local result = {}
setfenv(chunk, result)
chunk()
return result
end