Skip to content

Instantly share code, notes, and snippets.

View groeneman's full-sized avatar

Michael Groeneman groeneman

View GitHub Profile
@groeneman
groeneman / index.js
Created September 29, 2017 03:58
Higher order functions
var Q = function(f, g){
return function(x, y){
return f(x, y) > g(x, y)
}
}
var addition = function(a, b) { return a + b }
var subtraction = function(a, b) { return a - b }
var isAddingGreaterThanSubtracting = Q(addition, subtraction)
var result = isAddingGreaterThanSubtracting(1, 2)
@groeneman
groeneman / init.coffee
Last active March 30, 2017 21:59
Michael's Atom Config
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@groeneman
groeneman / Bibliography.md
Last active October 26, 2016 22:34
Bibliography
@groeneman
groeneman / 0_reuse_code.js
Last active August 29, 2015 14:22
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
@groeneman
groeneman / megamap.rb
Created November 21, 2014 19:43
Hash#megamap
class Hash
def mega_map(key_transform, value_transform)
new_keys = keys.map(&key_transform)
new_values = values.map(&value_transform)
Hash[new_keys.zip(new_values)]
end
end
hash = {"succeeded"=>"node2", "flagged"=>"node3"}
transform = ->(v){v.to_sym}
@groeneman
groeneman / stale_objects.rb
Last active December 25, 2015 21:49
Staleness in long-lived instantiations of the same object
it "guards against stale objects by checking a fresh instance before creating a duplciate account" do
@d = Dummy.create
# Hey, I somehow have an extra instance of this object!
@d2 = Dummy.find(@d.id)
# And I set up an account by calling from my original instance
d1s_account = @d.account(AC_AR)
# My original instance got the account back and stored it just fine
d1s_account.id.should_not be_nil
@d.account_id(AC_AR).should eq(d1s_account)
# If I create a new instance now, it'll have the account ID as we expect
@groeneman
groeneman / ko_precedence.html
Last active December 19, 2015 12:29
Inconsistency in Knockout's data-bind precedence
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js'></script>
<script type="text/javascript">
function viewModel() {
var self=this;
this.someText = ko.observable('I am a string');
this.observableBoolean = ko.observable(false);
};