Skip to content

Instantly share code, notes, and snippets.

View acairns's full-sized avatar

Andrew Cairns acairns

View GitHub Profile
@acairns
acairns / example.php
Created July 24, 2016 11:33
Reflection-based Event Emitter
<?php
final class WarpDriveEngaged
{
private $speed;
public function __construct($speed)
{
$this->speed = $speed;
}
@acairns
acairns / FooFilter.php
Last active August 29, 2015 14:05
Abstract for Resource Filter
<?php
class FooFilter extends ResourceFilter
{
public function index()
{
// Custom filtering for index();
}
public function store()
@acairns
acairns / 0_reuse_code.js
Created January 20, 2014 15:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@acairns
acairns / .bash_alias
Created January 7, 2014 23:21
Open file with iA Writer from command line
alias ia="open $1 -a /Applications/iA\ Writer.app"
@acairns
acairns / publish
Created January 5, 2014 11:58
Bash script to publish Jekyll post from _drafts into _posts
#!/bin/sh
if [ -z "$1" ]
then
echo "No draft file found"
exit
fi
mv $1 _posts/`date +"%Y-%m-%d"`-`basename $1`
@acairns
acairns / jekyll.sh
Last active December 26, 2015 22:19
Create GitHub-based Jekyll Project
#!/bin/bash
# Requirements
command -v git > /dev/null 2>&1 || { echo >&2 "I require git but it's not installed. Aborting."; exit 1; }
command -v gem > /dev/null 2>&1 || { echo >&2 "I require gem but it's not installed. Aborting."; exit 1; }
gem list jekyll -i > /dev/null 2>&1 || { echo >&2 "I require the jekyll ruby gem but it's not installed. Aborting."; exit 1; }
# Configuration
while [[ -z $PROJECTNAME ]]; do read -p "Enter name of the project: " PROJECTNAME; done
while [[ -z $PROJECTDESC ]]; do read -p "Enter description of the project: " PROJECTDESC; done
@acairns
acairns / Gruntfile.js
Created October 8, 2013 14:40
Simple LESS & CSS min setup with Grunt.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
less: {
development: {
files: {
"dist/style.min.css": "src/style.less"
}
}
@acairns
acairns / test_searching_large_arrays.php
Last active December 24, 2015 00:49
A binary search on a sorted array.
<?php
class Test_Searching_Large_Arrays extends PHPUnit_Framework_TestCase {
const SAMPLE_SIZE = 100000;
public function test_search()
{
$haystack = array();