Skip to content

Instantly share code, notes, and snippets.

@davetapley
davetapley / warn_legacy.rb
Last active November 16, 2015 16:45
Notify Sentry when legacy attributes are used
LEGACY_PROCESSOR_ATTRS.each do |*attr|
define_method(attr) do
Raven.capture_message "Read legacy attribute #{attr}", level: 'warning'
read_attribute attr, *opts
end
define_method("#{attr}=") do |*opts|
Raven.capture_message "Wrote legacy attribute #{attr}", level: 'warning'
write_attribute attr, *opts
end
@davetapley
davetapley / .ackrc
Created November 10, 2015 22:13
Dave's ack config
--type-set=coffee=.coffee
--type-set=haml=.haml
--type-set=sass=.sass
--type-set=minifiedjs=.min.js
--nocss
--nominifiedjs
--ignore-dir=coverage
--ignore-dir=dragonfly
--ignore-dir=javascripts/lib
#!/bin/sh
{
echo "This script requires superuser access to install apt packages."
echo "You will be prompted for your password by sudo."
# clear any previous sudo permission
sudo -k
# run inside sudo
sudo sh <<SCRIPT
@davetapley
davetapley / delegating_decorator.rb
Created August 21, 2015 19:04
Rails decorator delegation with method missing
class << self
def method_missing(method, *args)
result = (method == :all) ? Account.scoped : Account.send(method, *args)
result.where(something: true).map { |a| self.new a }
rescue NoMethodError => e
if result.is_a? ActiveRecord::Relation
raise e
else
raise NoMethodError.new "Account.#{ method } did not return a relation", method, args
@davetapley
davetapley / substring_replacement.sh
Last active August 29, 2015 14:27
Substring Replacement in Bash
# Works okay:
FILE=something.txt; echo ${FILE/txt/log}
# Works okay:
find . -name \*.txt -exec sh -c 'FILE={}; echo ${FILE}' \;
# Fails with 'sh: 1: Bad substitution':
find . -name \*.txt -exec sh -c 'FILE={}; echo ${FILE/txt/log}' \;
# Works
> event.context
=> {"meridien"=>"pm", "contact"=>"jennifer", "contact_id"=>954}
> event.context.class
=> Hash
> event.context['works'] = 'normally'
=> "normally"
> event.context
=> {"meridien"=>"pm", "contact"=>"jennifer", "contact_id"=>954, "works"=>"normally"}
>
> # Now trying HashWithIndifferentAccess
@davetapley
davetapley / 85004_fm_free.txt
Created June 26, 2015 23:56
Free FM channels at 85004
# http://radio-locator.com/cgi-bin/vacant?select=city&city=54004&state=&x=0&y=0
89.1 FM BEST!
89.5 FM BEST!
89.9 FM BEST!
90.1 FM BEST!
90.5 FM BEST!
91.5 FM BEST!
91.7 FM BEST!
93.3 FM BEST!
@davetapley
davetapley / pending_fail.rb
Created January 23, 2015 18:01
Pending failing rspec tests
#!/usr/bin/ruby
require 'pty'
cmd = ARGV.first
begin
PTY.spawn( cmd ) do |stdin, stdout, pid|
begin
stdin.each do |line|
$ rvm get stable
Downloading https://get.rvm.io
Downloading https://github.com/wayneeseguin/rvm/archive/1.26.9.tar.gz
Downloading https://github.com/wayneeseguin/rvm/releases/download/1.26.9/1.26.9.tar.gz.asc
gpg: Signature made Wed 07 Jan 2015 04:55:10 AM MST using RSA key ID BF04FF17
gpg: Can't check signature: public key not found
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found.
Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).
GPG signature verification failed for '/home/dave/.rvm/archives/rvm-1.26.9.tgz' - 'https://github.com/wayneeseguin/rvm/releases/download/1.26.9/1.26.9.tar.gz.asc'!
Token {{id}}
{{debugger}}
{{view 'translation-list' contentBinding='translations'}}