Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Murphy mmmurf

  • San Francisco, CA
View GitHub Profile
@mmmurf
mmmurf / redate.rb
Last active Sep 15, 2015
script to fix the created datestamp on files rescued from snapjoy's end of life backup downloads. This makes them show up in the proper order in Carousel
View redate.rb
# this script fixed the ordering in carousel of may snapjoy files.
# works on OSX
require 'date'
Dir.glob("./**/*.jpeg").each do |f|
next if f =~ /nknown/
m = /(?<serial>\d{0,6})-(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/.match(f)
d = DateTime.new(m['year'].to_i, m['month'].to_i, m['day'].to_i) + Rational(m['serial'].to_i, 86400)
View morse.js
function MorseNode(ac, rate) {
// ac is an audio context.
this._oscillator = ac.createOscillator();
this._gain = ac.createGain();
this._gain.gain.value = 0;
this._oscillator.frequency.value = 750;
this._oscillator.connect(this._gain);
View locale_diff.rb
# Run: curl https://gist.github.com/raw/719970/locale_diff.rb | ruby - en fi
require 'rubygems'
require 'yaml'
l1 = ARGV[0]
l2 = ARGV[1]
first = YAML.load_file(l1 + ".yml")
second = YAML.load_file(l2 + ".yml")
def diff(root, compared, structure = [])
View gist:5606427
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
View gist:1313698
class DomainSession < Rack::Session::Cookie
def set_cookie(env, headers, cookie)
cookie[:domain] ||= Rack::Request.new(env).host[/(\.[^\.]+){2}$/]
super
end
end
use DomainSession
View datamapper association empty set strange behavior
require 'dm-core'
require 'dm-migrations'
class Foo
include DataMapper::Resource
property :id, Serial
has n, :bars
end
class Bar
View gist:347158
/projects/5304ecaf565147c7e488$ unicorn
I, [2010-03-28T16:40:14.986279 #27939] INFO -- : listening on addr=0.0.0.0:8080 fd=3
I, [2010-03-28T16:40:15.095040 #27939] INFO -- : worker=0 spawning...
I, [2010-03-28T16:40:15.096947 #27939] INFO -- : master process ready
I, [2010-03-28T16:40:15.098584 #27941] INFO -- : worker=0 spawned pid=27941
I, [2010-03-28T16:40:15.807127 #27941] INFO -- : worker=0 ready
No view class found for layout in .
NoMethodError - undefined method `empty?' for nil:NilClass:
/usr/local/ruby1.9/lib/ruby/gems/1.9.1/gems/mustache-0.9.1/lib/mustache/sinatra.rb:67:in `mustache'
/home/mmmurf/projects/5304ecaf565147c7e488/app.rb:13:in `block in <class:App>'
View carbon.md

Vim

autocmd BufWritePre * :%s/\s\+$//e

Emacs

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Textmate

View gist:173357
config.after_initialize do
#CACHE
MEMCACHE_SERVER = case RAILS_ENV
when 'development' then 'localhost:11211'
when 'staging' then '127.0.0.1:11211'
when 'production' then '192.168.2.26:11211'
when 'test' then nil
else raise
end
View gist:48250
(in /home/mmmurf/projects/penguin_shipping_lab)
/usr/bin/ruby1.8 -Ilib:lib "/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb" "test/gateways/penguin_discounted/pdf_test.rb" "test/gateways/penguin_discounted/images_test.rb" "test/gateways/endicia/pdf_test.rb" "test/gateways/endicia/images_test.rb" "test/gateways/ups/pdf_test.rb" "test/gateways/ups/images_test.rb" "test/gateways/usps/images_test.rb"
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in `load_missing_constant': uninitialized constant Dependencies (NameError)
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in `const_missing'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:89:in `const_missing'
from ./lib/penguin_shipping_lab.rb:23
from ./init.rb:5:in `require'
from ./init.rb:5
from ./test/gateways/penguin_discounted/../../test_helper.rb:1:in `require'
from ./test/gateways/penguin_discounted/../