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
# Runs assert_difference with a number of conditions and varying difference | |
# counts. | |
# | |
# Call as follows: | |
# | |
# assert_differences([['Model1.count', 2], ['Model2.count', 3]]) | |
# | |
def assert_differences(expression_array, message = nil, &block) | |
b = block.send(:binding) | |
before = expression_array.map { |expr| eval(expr[0], b) } |
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
$ git branch -r --merged | | |
awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' | | |
xargs git push origin --delete |
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 'sequel' | |
require 'logger' | |
DB = Sequel.sqlite(loggers: [Logger.new(STDOUT)]) | |
DB.create_table :authors do | |
primary_key :id | |
String :name | |
end |
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
# | |
# Example of how to convert CSV data on read, in this case parsing | |
# some JSON in a CSV. | |
# | |
require 'csv' | |
require 'json' | |
csv = <<EOT | |
id,json_stuff | |
1,"{""foo"":""bar""}" |
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
echo -n "3pm Christmas Day in LA in local timezone: " | |
date --date 'TZ="America/Los_Angeles" 2016-12-25T15:00' | |
echo -n "3pm Christmas Day in LA in London: " | |
TZ="Europe/London" date --date 'TZ="America/Los_Angeles" 2016-12-25T15:00' |
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
# Example integration spec for a Rake task in Rails | |
# | |
# cat <<EOT > lib/tasks/myapp.rake | |
# namespace :myapp do | |
# task :mytask => :environment do | |
# puts "Hello" | |
# end | |
# end | |
# EOT |
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
# 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
#!/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, |
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
autocmd User Rails/app/assets/javascripts/*/*.js | |
\ let b:rails_alternate = substitute( | |
\ substitute(rails#buffer().path(), 'app/assets/', 'spec/', ''), | |
\ '.js', '_spec.js', '') | |
autocmd User Rails/spec/javascripts/*/*_spec.js | |
\ let b:rails_alternate = substitute( | |
\ substitute(rails#buffer().path(), 'spec/', 'app/assets/', ''), | |
\ '_spec.js', '.js', '') |
NewerOlder