Skip to content

Instantly share code, notes, and snippets.

View lukesutton's full-sized avatar

Luke Matthew Sutton lukesutton

View GitHub Profile
// authentication
// client/account specific info
// urls
// data format transformations; flattening etc
// declarative data transform
// - flatten
// - rename
// - convert
// - renaming
// - blacklist/whitelist
// Paths
protocol Path {
associatedtype Entity
var path: String { get }
}
protocol ListPath: Path {
associatedtype Entity
var path: String { get }
}
struct Key<T: Storable> {
let label: String
init(_ label: String) {
self.label = label
}
}
protocol Storable {}
struct Store {
@lukesutton
lukesutton / frp-sketch.js
Last active December 28, 2015 22:59
The beginning of a very simple streams library.
// http://jsfiddle.net/MrkuK/
// Test version of a stream
function Stream(opts) {
this._subscribers = [];
this.opts = _.extend({
autoDispose: false,
valueOnSubscribe: false
}, opts);
}
@lukesutton
lukesutton / jquery.plugin.js
Created October 29, 2013 23:26
Scaffold for a jQuery plugin.
(function($) {
function Plugin($el, opts) {
this.$el = $el;
this.settings = $.extend({
// Add default settings here.
}, opts);
}
Plugin.prototype = {
@lukesutton
lukesutton / dirty_form.js
Last active December 24, 2015 22:59
The start of a 'dirty' input tracking plugin. It's been done a bajillion times, but this one is simple.
/* -------------------------------------------------------------------------- */
/* DIRTY FORM
/* Checks to see if the user has made any changes to a form. Toggles the save
/* control on or off appropriately. Also prompts user to save it they attempt
/* to navigate away with unsaved changes.
/* -------------------------------------------------------------------------- */
(function($) {
var DirtyForm = function(form) {
this.$form = form;
this.$save = form.find('button.save');
@lukesutton
lukesutton / package_tracking.rb
Created September 20, 2013 07:20
The beginning of a screen scraper for AusPost's package tracking.
def extract(doc_string)
doc = Nokogiri::HTML(doc_string)
doc.css('#more-details-content .ed-details-row').map do |r|
time = Time.parse(r.at_css('.ed-date p').inner_text.strip)
activity = r.at_css('.ed-activity p').inner_text.strip
location = r.at_css('.ed-location p').inner_text.strip
state = location.match(/\s+(\w{2,3})$/)[1]
suburb = location.gsub(state, '').strip
@lukesutton
lukesutton / module.js
Created November 5, 2012 03:13
Simple function for declaring modules.
function module(scope, fn) {
var result = fn();
if (_.isEmpty(result)) {
throw "When defining a module, you _must_ return an object containing exports.";
}
var split = scope.split('.');
if (split.length > 1) {
var parts = _.initial(split, 1),
last = _.last(split),
(function(_) {
var Inflector = function(config) {
};
_.inflect = function(lang) {
return new Inflector(_.inflect.langs[lang]);
};
@lukesutton
lukesutton / elixir.rb
Created May 28, 2012 02:33 — forked from huffman/elixir.rb
Elixir 0.5.0 Homebrew recipe
# Install this recipe with:
# brew install --HEAD https://gist.github.com/raw/2816905/daafa0d7e3c5da694401fac138aae340a9ead157/elixir.rb
require 'formula'
class Elixir < Formula
homepage 'http://elixir-lang.org/'
head 'https://github.com/elixir-lang/elixir.git', :tag => '0.5.0'
depends_on 'erlang'