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
# RSpec matcher to spec delegations. | |
# | |
# Usage: | |
# | |
# describe Post do | |
# # post.name -> post.author.name | |
# it { should delegate(:name).to(:author) } | |
# | |
# # post.author_name -> post.author.name | |
# it { should delegate(:author_name).to(:author).as(:name) } |
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
#! /usr/bin/env python | |
import pyfits | |
import argparse | |
parser = argparse.ArgumentParser( | |
description='Add BeSS FITS headers to a file') | |
parser.add_argument('filename', type=str, help='FITS filename') | |
parser.add_argument('--outfile', '-o', type=str, help='Output filename', | |
required=True) |
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
#!/usr/bin/env ruby | |
# | |
# Usage: ./offline_pull_requests.rb user/repo | |
# | |
require 'octokit' | |
require 'erb' | |
require 'redcarpet' | |
def filename_for(pull) | |
'%d.html' % pull.number |
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
$ heroku run bash | |
Running `bash` attached to terminal... up, run.6771 | |
~ $ ls -l /dev/stdin | |
lrwxrwxrwx 1 root root 15 2014-08-11 22:31 /dev/stdin -> /proc/self/fd/0 | |
~ $ ls -l /proc/self/fd/0 | |
lrwx------ 1 u51787 51787 64 2014-08-11 22:31 /proc/self/fd/0 -> /dev/pts/1 | |
~ $ id | |
uid=51787(u51787) gid=51787 | |
~ $ echo echo | cat | |
echo |
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
desc <<-EOT | |
Display the id and error messages of all invalid instances of each model in | |
model_classes, which should be a comma separated list of model names. If | |
model_classes is blank all models will be reported. | |
EOT | |
task :validate_models, [:models] => :environment do |t, args| | |
model_classes = if args[:models] | |
args[:models].split(',').map(&:constantize) | |
else | |
Rails.application.eager_load! |
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
def value_of_first_matching_key_in_hash(hash, array_of_keys) | |
end | |
describe do | |
it 'searches a hash for an array of keys and returns the value of the first found' do | |
keys = [:a, :b, :c] | |
hash = {:c => 3, :b => 2, :a => 1} | |
expect(value_of_first_matching_key_in_hash(hash, keys)).to eql 1 |
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
# Log an exception with the backtrace cleaned as per the 'Application Trace' | |
# in the development mode browser exception view. | |
logger.error( | |
"some_tag: exception = %s: %s" % [ | |
exception.inspect, | |
Rails.backtrace_cleaner.clean(exception.backtrace) | |
] | |
) |
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 'delegate' | |
class CaseInsensitiveHashWriter < SimpleDelegator | |
def []=(key, value) | |
return __getobj__[key] unless key.respond_to?(:downcase) | |
matched_key = keys.detect do |k| | |
k.respond_to?(:downcase) && k.downcase == key.downcase | |
end | |
if matched_key | |
__getobj__[matched_key] = value |
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
class Animal | |
@@noise = nil | |
def speak | |
@@noise | |
end | |
end | |
class Dog < Animal | |
@@noise = 'Woof' |
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
#!/bin/bash | |
usage() { | |
cat <<EOT | |
Usage: PAPERTRAIL_API_TOKEN=abc123 $0 directory | |
Save all papertrail archives to outdir. Existing files will not be | |
overwritten if they have the correct filesize. | |
PAPERTRAIL_API_TOKEN can be found under the 'Me -> Profile' in Papertrail, |