Skip to content

Instantly share code, notes, and snippets.

Avatar

Malcolm Locke malclocke

  • Christchurch, New Zealand
View GitHub Profile
View gist:421827
<?php
/**
* Create your custom stylesheets based on the taxonomy tid in
* $theme_dir/css/taxonomy/$tid.css
*/
function THEME_preprocess_node(&$vars, $hook) {
if ($terms = taxonomy_node_get_terms($vars->['node'])) {
foreach ($terms as $term) {
$stylesheet = '/css/taxonomy/'. $term->tid .'.css';
if (file_exists(dirname(__FILE__) . $stylesheet)) {
View inotify-test.c
#include <sys/inotify.h>
#include <stdio.h>
#include <errno.h>
/* size of the event structure, not counting name */
#define EVENT_SIZE (sizeof (struct inotify_event))
/* reasonable guess as to size of 1024 events */
#define BUF_LEN (1024 * (EVENT_SIZE + 16))
@malclocke
malclocke / adminpass.drush.inc
Created Aug 18, 2010
A drush command to reset a Drupal site admin password, either permanently or temporarily
View adminpass.drush.inc
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@malclocke
malclocke / stopfinder.rb
Created Dec 6, 2010
Get info on ChurChur Metro buses within a lat/long boundary
View stopfinder.rb
require 'rubygems'
require 'net/http'
require 'json'
require 'nokogiri'
require 'open-uri'
# Lat long boundaries
#
# Around the casino
#xmin=172.6299226284027
@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) }
@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 / 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 / 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 / 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 / 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', '')