Skip to content

Instantly share code, notes, and snippets.

Avatar

Malcolm Locke malclocke

  • Christchurch, New Zealand
View GitHub Profile
View heroku_stdin.log
$ 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
View offline_pull_requests.rb
#!/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 Dec 19, 2013
Add BeSS headers to a FITS file
View bessify.py
#! /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 Dec 15, 2015
Rspec delegation matcher
View delegates_matcher.rb
# 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 Nov 29, 2012
Vim config for Javascript spec alternates
View gist:4171963
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 Dec 6, 2011
Makefile for .chordpro -> .pdf
View Makefile
CHORDII := chordii -a
pdfs := $(patsubst %.chordpro,%.pdf,$(wildcard *.chordpro))
all: $(pdfs)
%.ps : %.chordpro
$(CHORDII) $< > $@
%.pdf : %.ps
@malclocke
malclocke / Makefile
Created Oct 13, 2011
Makefile for deployment
View Makefile
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
A minimal Rails 3 generator
View USAGE
# 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 Apr 27, 2011 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
View gist:943565
$ git branch -r --merged |
awk -F'/' '/^ *origin/{if(!match($0, /(>|master)/)){print $2}}' |
xargs git push origin --delete
@malclocke
malclocke / gist:905037
Created Apr 6, 2011
Variation on Rails assert_difference with multiple count values
View gist:905037
# 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) }