Skip to content

Instantly share code, notes, and snippets.

View malclocke's full-sized avatar

Malcolm Locke malclocke

  • Christchurch, New Zealand
View GitHub Profile
@malclocke
malclocke / stopfinder.rb
Created December 6, 2010 21:06
Get info on ChurChur Metro buses within a lat/long boundary
require 'rubygems'
require 'net/http'
require 'json'
require 'nokogiri'
require 'open-uri'
# Lat long boundaries
#
# Around the casino
#xmin=172.6299226284027
@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 / 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 / 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 / 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 / papertrail-archive.sh
Last active November 25, 2015 03:14
Requires `jq` binary
#!/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,
@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 / 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)
# 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
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'