Skip to content

Instantly share code, notes, and snippets.

@mmrwoods
mmrwoods / pseudo_long_opts.sh
Created August 25, 2011 12:54
pseudo long opts for use with getopts
# Allow pseudo long options based on naming convention.
# Long opts are converted to short opts by simply discarding all but
# the first character, which does nothing more than allow for more
# readable argument lists.
set -- `echo " $@ " | sed s/\ "-\{1,\}\([a-zA-Z]\)[-a-z]\{1,\}[=\ ]/\ -\1\ /g"`
@mmrwoods
mmrwoods / BritishWithHash.keylayout
Created September 7, 2011 13:28
British OSX keyboard layout, with § (section sign) key remapped to output hash
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--
* save to ~/Library/Keyboard Layouts/BritishWithHash.keylayout
* enable as input source within keyboard preferences
* select as input source in menu bar
NOTE: although this works in Lion, it messes up the press and hold for alternative characters feature.
-->
<!-- Fri, 24 Feb 2006 Generated from KCHR: "British" -->
<!--Last edited by Ukelele version 2.1.7 on 2011-09-07 at 14:20 (BST)-->
@mmrwoods
mmrwoods / delete git tag from remote repo
Created January 9, 2012 12:43
Delete git tag from remote repo
git tag -d 12345
git push origin :refs/tags/12345
@mmrwoods
mmrwoods / generate version number from git
Created January 9, 2012 12:57
Generate semantic versioning compatible number from git tags
git describe --tags --match "v*" 2> /dev/null | sed s/-/+build./ | sed s/-/./
@mmrwoods
mmrwoods / pg_search_document_metadata.rb
Last active December 18, 2015 17:49
Adds metadata to pgsearch documents, allowing search results to be rendered with just the document data.
module PgSearch
module ClassMethods
def rebuild_pg_search_documents
self.find_each {|record| record.update_pg_search_document}
end
end
class Document
before_validation do
self.meta = generate_meta
@mmrwoods
mmrwoods / formtastic_cancel_action.rb
Last active December 19, 2015 00:09
Make formtastic's cancel action return the user to the original referrer
# Make formtastic's cancel action return the user to the original referrer
#
# By default, the cancel action in formtastic always goes to the previous
# page, so hitting cancel after validation failures returns the user to
# the form, not the original referring page. The code below modifies the
# cancel action such that it by default returns to the original referrer.
# It does so by simply keeping track of the referrer in a hidden field.
#
# See also https://github.com/justinfrench/formtastic/issues/780
@mmrwoods
mmrwoods / rekordbox2mp3cd
Last active December 23, 2015 09:28
Burn a rekordbox export to an MP3 CD
#!/bin/bash
# Burns a rekordbox export to an MP3 CD compatible with older CDJs.
#
# Copies mp3, m4a and wav audio files from export volume to a single CD,
# converting to constant bit rate mp3 compatible with older CDJs and other
# non-pioneer CD players as required.
#
# Will explode if files won't fit onto a single CD. Yup, I know this is shit.
#
@mmrwoods
mmrwoods / deferred_gc.rb
Created October 21, 2013 08:16
Disable GC and running the collector manually every few seconds for cuke runs
# Taken from Jamis Buck's post "The road to faster tests"
# http://37signals.com/svn/posts/2742-the-road-to-faster-tests
#
# Disabling GC and running the collector manually every few seconds
# knocks 25-30% off the time taken to run all of my non-js scenarios
# on ruby 1.9.3p448, without any other memory management tuning.
DEFERRED_GC_THRESHOLD = (ENV['CUCUMBER_DEFERRED_GC_THRESHOLD'] || 3.0).to_f
last_gc_run = Time.now
@mmrwoods
mmrwoods / fix_wordpress_permissions.sh
Last active December 30, 2015 06:48
Experimental script to fix fscked wordpress permissions
#!/bin/bash
# Experimental script to fix fscked wordpress permissions, needs testing
usage() {
echo "Usage: $0 [-u user] path-to-wordpress-install"
}
# allow user to be set via command line option
while getopts “u:v” OPTION
@mmrwoods
mmrwoods / wicklow.vim
Last active December 30, 2015 21:39
My old vim colour scheme, based on Eclipse, tweaked for Ruby development. Dumping it here because I'm going to remove it from my dotfiles repo.
" Vim color file
" Maintainer: Mark Woods
" Licence: Public Domain
" GUI only color scheme based on the eclipse color scheme, optimised for ruby.
set background=light
highlight clear
if exists("syntax_on")