Skip to content

Instantly share code, notes, and snippets.

View amacdougall's full-sized avatar

Alan MacDougall amacdougall

View GitHub Profile
@amacdougall
amacdougall / state_machine_examples.js
Created March 24, 2015 21:11
State machine examples
// simple state machine using a state variable
/* States can be anything -- strings, integers, whatever. In C examples, you'll
* see integers, because they take up less space in memory. In Ruby, they'd be
* symbols; in Java, they'd be Enumerations or something. In JavaScript, it's
* generally wise to make them strings, for easy debugging.
*
* These example states are for an imaginary ship.
*/
var ANCHORED = "anchored";
@amacdougall
amacdougall / sample_code.cljs
Created March 13, 2015 03:53
ClojureScript sample code
;; Some examples of Clojure syntax. ClojureScript is almost entirely identical
;; to Clojure.
;; Anything preceded by semicolons is a comment. Double-semicolons are
;; generally doc comments; single semicolons are developer comments.
(def message "Hello world!")
message ; simply naming something returns its value
@amacdougall
amacdougall / pre-commit
Last active August 31, 2015 15:27
Viewport pre-commit hook
#!/usr/bin/ruby
#
# Prevents commit, with an informative message, if any of the following
# conditions are true:
#
# Any js file in the src directory does not pass eslint.
#
# Any js file in the src directory requires formatting with js-beautify.
#
# Must have eslint and js-beautify installed as CLI apps. If they are not
@amacdougall
amacdougall / kill_orphaned_branches.rb
Created March 3, 2015 20:46
Kill branches which exist on your origin but not locally
#!/usr/bin/ruby
# delete branches which exist on the origin repo but not locally
WHITELIST = [
"master",
"production",
"earth",
"wind",
"water",
@amacdougall
amacdougall / design_tool_meeting_distilled.md
Last active August 29, 2015 14:10
Design Tool Planning Meeting Distillation

Design Tool Planning

We began with a single question: "what next?" The one-word answer was obvious: "testing." From there, we discussed three topics: what kinds of tests to write; how to write and run them; and what refactorings might best support the tests.

Each topic led to less consensus than the preceding one, but I will attempt to summarize the competing views.

What Tests We Need

Smoke Tests

@amacdougall
amacdougall / compose.js
Created August 19, 2014 18:59
Function composition test question.
/**
* Given any number of functions, returns a single function which acts as
* if each function were called in right to left order. The result of each
* function will be the argument to the next.
*
* To put it another way, compose(f, g)(x) should have the same result
* as f(g(x)).
*
* @param {...Function} functions - Any number of input functions.
*/
;; Bogey (sets the :current boolean for each player)
(defn select-player [app player]
(om/transact! app :players (fn [players]
(mapv (fn [p]
(assoc p :current (= p @player)))
players))))
;; Birdie -- but I feel like it's more cognitive load
(defn select-player [app player]
(let [set-current #(assoc % :current (= % @player))]
@amacdougall
amacdougall / gist:f6151270c3c50bbb25e9
Created July 9, 2014 21:25
That one pipeline question
// Make a function called pipeline that accepts a value as a parameter, as well as any number of functions as additional parameters.
// The function will return the value that results from the first parameter being used as a parameter for the next function and so on.
var double = function(val) { return val * 2; }
var addOne = function(val) { return val + 1; }
var addThree = function(val) { return val + 3; }
/**
* Given an initial value and any number of function arguments,
* returns the value obtained by applying each function to the
@amacdougall
amacdougall / .git-completion.bash
Created May 16, 2014 16:24
Git autocomplete hacked to remove remote branch autcomplete.
#!bash
#
# bash/zsh completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
// This works, but since it has to take `n, f1, ...` instead of `n, [f1, ...]`,
// we need to do a messy concat/apply at the end.
function pipeline(n) {
var actions = rest(arguments);
if (_.isEmpty(actions)) {
return n;
} else {
return pipeline.apply(null, [first(actions)(n)].concat(rest(actions)));
}
};