Skip to content

Instantly share code, notes, and snippets.

View davidkelley's full-sized avatar

David Kelley davidkelley

View GitHub Profile
@davidkelley
davidkelley / gist:4342647
Last active December 9, 2015 23:08
This coffeescript snippet creates a modularised event delegator for usage in conjunction with RequireJS. Backward compatibility support to IE8 only.
define [], ->
# Handles site-wide event delegations for all elements.
# @param selector The CSS-style element selector.
# @param event The event to bind to, click, hover, mouseenter, etc.
# @param handler The handler function to execute on event firing
# return void
(selector, event, handler) ->
# Define function to wrap the handler function in
@davidkelley
davidkelley / osx-postgresql-memory-fix
Created July 9, 2013 09:11
Commands to fix the PostgreSQL fatal shared memory bug in OS X
# Sudo system control to fix memory in current session
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216
# Fix memory bug for future sessions
cat << 'EOF' >> /etc/sysctl.conf
kern.sysv.shmall=65536
kern.sysv.shmmax=16777216
EOF
@davidkelley
davidkelley / sort_by_version_number
Created July 10, 2013 13:06
Modifies the Array class in Ruby to support sorting by valid version numbers
#Modify Array prototype
class Array
#Sorts numerically descending, period
#separated occurences ie. file.10.1.2.3.git
def sort_by_version_number!
regex = /(([0-9]+\.?){4,})\./
self.sort! do |a,b|
#Get version numbers
a = Gem::Version.new(a.match(regex)[1])
b = Gem::Version.new(b.match(regex)[1])
@davidkelley
davidkelley / commands.sh
Last active December 22, 2015 03:49
This Gist will setup a full-screen Chromium kiosk on the Raspberry Pi without launching any GUI. It will clone a repository from the provided location and navigate to it inside Chromium.
#location of git repo
REPO=""
#install library dependencies
sudo apt-get update && apt-get upgrade -y
sudo apt-get install -y chromium-browser x11-xserver-utils unclutter xwininfo git git-core couchdb
#better font experience
sudo apt-get install -y ttf-mscorefonts-installer
@davidkelley
davidkelley / install-postgres
Created September 13, 2013 09:35
Commands to setup Postgresql on OS X.
#!/bin/bash
brew update
brew doctor
brew uninstall postgresql || true
brew install postgresql
initdb /usr/local/var/postgres -E utf8
gem install lunchy
@davidkelley
davidkelley / gist:9002267
Last active January 27, 2020 08:43
Example showing how to connect with a USB device using Javascript. Note that this file uses the chrome.usb.* API's which are only available for "packaged app" Chrome extensions.
var port = 0;
var endpoint = 0x01;
var device = { vendorId: 0x04b8, productId: 0x0202};
var connect = function(callback) {
chrome.permissions.getAll(function(p) {
if (p.permissions.indexOf('usb') >= 0) {
//construct permission object for our device
var obj = { usbDevices: [device] };
@davidkelley
davidkelley / network.template
Created April 13, 2014 15:12
AWS Cloudformation that launches Private and Public Subnets inside a configured VPC complete with a Bastion Host
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Creates networking infrastructure.",
"Parameters" : {
"BastionKeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the bastion host",
"Type" : "String",
@davidkelley
davidkelley / .script.app
Last active June 15, 2016 16:34
Configures Vagrant to run Docker & Fig
# Run Application specific setup tasks here!
#!/usr/bin/env bash
cd /vagrant
fig run web foreman run rake db:create
fig run web foreman run rake db:migrate
<Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">
<Header>
<To xmlns="http://www.w3.org/2005/08/addressing">https://api.rkd.reuters.com/api/TokenManagement/TokenManagement.svc/
Anonymous</To>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://www.reuters.com/ns/2006/05/01/webservices/rkd/TokenManagement_1/
CreateServiceToken_1</Action>
</Header>
<Body>
<CreateServiceToken_Request_1 xmlns:global="http://www.reuters.com/ns/2006/05/01/webservices/rkd/Common_1" xmlns="http://www.
reuters.com/ns/2006/05/01/webservices/rkd/TokenManagement_1">
@davidkelley
davidkelley / gist:45d410e9f0ec472cbae8
Created June 24, 2014 21:45
Rubinius on Ubuntu Trusty (14.04)
FROM ubuntu:trusty
# Install Ruby
RUN apt-get -y update
RUN apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
RUN apt-get -y install wget
RUN wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
RUN tar -xvzf ruby-2.1.2.tar.gz
RUN cd ruby-2.1.2 && ./configure --prefix=/usr/local
RUN cd ruby-2.1.2 && make