Skip to content

Instantly share code, notes, and snippets.

View aesnyder's full-sized avatar

Aaron Snyder aesnyder

View GitHub Profile
@aesnyder
aesnyder / .tigrc
Created February 7, 2014 14:45
Mojo .Tigrc
bind generic f !@git fetch
bind generic p !@git pull
bind generic P !@git push
bind generic { !?git push -f
bind generic r !git rebase -i master
bind generic U !@git up
bind generic M !@git checkout master
bind generic ! !@git reset HEAD^
bind generic @ !@?git reset --hard HEAD^
bind generic a !git commit --amend
@aesnyder
aesnyder / gist:9403886
Last active August 29, 2015 13:57
Functional Chaining in CoffeeScript and Underscore.js
# ob - a chainable object helper
#
# ob({foo:1, bar: 2, zap: undefined})
# .compact()
# .map((v) -> v + 1)
# .value
#
# // {foo:2, bar: 3}
ob = (obj) ->
@aesnyder
aesnyder / gist:9764109
Created March 25, 2014 15:23
Postrender test case.
# directive to cause elements to have equal heights
# caveat -- they must share the same parent which contains this
# directive and an attribute of matchHeightOf = ".selector"
app.directive 'cssEqualHeight', ($window, $timeout) ->
restrict: 'A'
compile: (el, attrs) ->
$matchables = angular.element(el).find(attrs.matchHeightOf)
@matchHeights = makeHeightMatcher $matchables
angular.element($window).on 'resize', ->
@aesnyder
aesnyder / gist:9770794
Last active August 29, 2015 13:57
Logging, local variables, and a dash of opinion.
###
Logging, local variables, and a dash of opinion.
This gist intends to explore the impact of logging in software development. Briefly I should give
a bit of background: I'm not a fan of logging frameworks. The original intent of this article was
to present an argument against logging by examining:
1. How logging introduces state
2. Why local variables are bad
3. Proof that local variables are worse than logging
@aesnyder
aesnyder / Kompressor.coffee
Created March 27, 2014 14:18
Remove base64 heads from array - whammy.js
# remove the heads off arrays of base_64 encoded datauris
#
# in this example we take the array of images encoded from
# whammy.js and return an array without the heads. This is
# an admittedly vain optimization but, every byte counts.
Base64Header = (type) ->
head: "data:#{type};base64,"
add: (string) ->
"#{HEAD}#{string}"
app = express()
server = http.createServer app
io = require('socket.io').listen(server)
server.listen process.env.PORT
bind generic f !@git fetch
bind generic p !@git pull
bind generic P !@git push
bind generic { !?git push -f
bind generic r !git rebase -i master
bind generic U !@sh -c "git checkout master && git pull && git checkout - && git rebase master"
bind generic M !@git checkout master
bind generic ! !@git reset HEAD^
bind generic @ !@?git reset --hard HEAD^
bind generic a !git commit --amend
@aesnyder
aesnyder / chainable.coffee
Last active August 29, 2015 14:01
_.chainable
# takes an object of methods and makes them optionally chainable,
# all lodash methods are accessible in the chain too
#
# The following methods are added as well:
# attr: returns value of attribute on given object
# inlcuding: extends either object, or each object in collection
# with attrName: callback(object)
# if no callback is given then attrName is assumed to be a function
# passed to _.chainable: attrName: attrName(object)
#
@aesnyder
aesnyder / local.js
Created July 23, 2014 15:51
localstorage with non-strings
store = {
get: function(path) { return JSON.parse(localStorage.getItem(path)); },
set: function(path, item) {
localStorage.setItem(path, JSON.stringify(item));
return item;
}
}
@aesnyder
aesnyder / gist:fe0fe90489ee2c377f8d
Created February 24, 2015 19:50
Object by reference javascript coffeescript example
#without clone
car = type: 'buick'
newCar = car
newCar.type = 'honda'
car.type #honda
newCar.type #honda