Skip to content

Instantly share code, notes, and snippets.

View malclocke's full-sized avatar

Malcolm Locke malclocke

  • Christchurch, New Zealand
View GitHub Profile
$ 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
#!/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
@malclocke
malclocke / bessify.py
Created December 19, 2013 01:02
Add BeSS headers to a FITS file
#! /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)
@malclocke
malclocke / delegates_matcher.rb
Last active December 15, 2015 12:19
Rspec delegation matcher
# 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) }
@malclocke
malclocke / gist:4171963
Created November 29, 2012 21:13
Vim config for Javascript spec alternates
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', '')
@malclocke
malclocke / Makefile
Created December 6, 2011 10:06
Makefile for .chordpro -> .pdf
CHORDII := chordii -a
pdfs := $(patsubst %.chordpro,%.pdf,$(wildcard *.chordpro))
all: $(pdfs)
%.ps : %.chordpro
$(CHORDII) $< > $@
%.pdf : %.ps
@malclocke
malclocke / Makefile
Created October 13, 2011 07:49
Makefile for deployment
DEPLOYHOST=ben@awesomehost.co.nz
DEPLOYDIR=/var/www
# WARNING: The --delete flag will delete anything on the remote end that isn't
# on the local end. But you've got backups, right?
upload:
rsync -vax -e ssh --exclude .git --delete . $(DEPLOYHOST):$(DEPLOYDIR)/
@malclocke
malclocke / USAGE
Created May 10, 2011 22:01
A minimal Rails 3 generator
# lib/generators/test_generator/USAGE
Description:
A minimal rails 3 generator example
Example:
rails generate NewClass method1 method2
This will create:
app/models/new_class.rb
@malclocke
malclocke / gist:943565
Created April 27, 2011 01:31 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
$ git branch -r --merged |
awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' |
xargs git push origin --delete
@malclocke
malclocke / gist:905037
Created April 6, 2011 02:46
Variation on Rails assert_difference with multiple count values
# 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) }