Skip to content

Instantly share code, notes, and snippets.

View jasonkarns's full-sized avatar
🏠
Working from home

Jason Karns jasonkarns

🏠
Working from home
View GitHub Profile
@jasonkarns
jasonkarns / dispatcher.coffee
Created December 3, 2013 21:16
Inverse _.partial
# we have an event aggregator that is treated as an adapter to hide
# whatever eventing lib/framework/utility we decide to use
#
# originally, it was backed by Backbone.Events. Now it's Angular's $rootScope
#
# `on` accepts a callback that expects to be given event args. (as backbone.events does)
#
# Angular's $on, on the other hand, accepts a callback that expects
# $scope as the first param, followed by event args.
@jasonkarns
jasonkarns / tap.coffee
Created November 16, 2013 03:00
What if _.tap could set the context of the interceptor? I would imagine that it would set the context to the tapped object by default. I can't think of a use case for setting it to another arbitrary object.
# the thought came to me when dealing with angular
myModule = angular.module('myModule', [])
myModule.value 'X', X
myModule.factory 'F', F
myModule.service 'S', S
# with tap, but without setting context
_(angular.module('myModule', [])).tap (myModule) ->
myModule.value 'X', X
@jasonkarns
jasonkarns / bad-ember-shrinkwrap.json
Created November 2, 2013 02:04
npm shrinkwraps for linemanjs
{
"name": "ember-template",
"version": "0.0.1",
"dependencies": {
"grunt-ember-handlebars": {
"version": "0.7.0",
"from": "grunt-ember-handlebars@0.7.0",
"dependencies": {
"grunt": {
"version": "0.4.1",
@jasonkarns
jasonkarns / 0-problem.md
Last active December 21, 2015 09:28
Since I can't put markdown here in the description... read the problem.md

Situation

We want to monkey patch (wrap, really) core Backbone objects. Let's use Backbone.Router for this example.

Setup

The original Backbone.Router is wrapped as shown in duck_punch.js.

  1. The constructor function (Backbone.Router) is replaced with ours (which runs the console profiler around the invocation of the original function). L4-9
  2. Since we've overwritten Backbone.Router, we restore its prototype to be the original's prototype. L12
@jasonkarns
jasonkarns / application.coffee
Last active December 20, 2015 04:49
Support arbitrary static files in Lineman with the grunt-contrib-copy task
module.exports = require(process.env['LINEMAN_MAIN']).config.extend "application",
# tell lineman to load the grunt-contrib-copy task via npm
loadNpmTasks: 'grunt-contrib-copy'
# tell lineman to run the copy tasks as part of its build process
# run 'dev' target for both run and build phases
# run 'dist' target during build phase
appendTasks:
common: "copy:dev"
@jasonkarns
jasonkarns / global.coffee
Last active December 19, 2015 14:28
Get access to global object in a Lint-, ES5-, strict-mode-, and node- safe way.
root = ((f) -> f('return this')())(Function)
@jasonkarns
jasonkarns / facebook_sucks.css
Last active December 17, 2015 08:38
Facebook sucks. Hide the like button counter (for button_count buttons).
.fb-like {
position:relative;
}
.fb-like::after {
content: '';
position: absolute;
height: 20px;
width: 24px;
top: 0;
@jasonkarns
jasonkarns / partialObject.underscore.js
Last active December 16, 2015 22:09
Instead of partially applying parameters to a function, partially apply properties on a plain old javascript object.
_.partialObject = function(func, partial_object) {
return function(object) {
return func.call(this, _.extend({}, partial_object, object));
};
};
@jasonkarns
jasonkarns / fb.js
Last active December 16, 2015 19:59
Facebook's JS SDK doesn't support registering multiple 'ready' handlers. So here's an implementation inspired by Twitter's SDK. (uses underscore)
window.fb = (b = { _e: [], ready: function(f){ b._e.push(f); } });
window.fbAsyncInit = function() {
fb.ready = function(f){ f(); };
_.invoke(fb._e, 'call');
};
fb.ready(function(){ console.info("facebook sdk loaded"); });
@jasonkarns
jasonkarns / readme.md
Last active March 11, 2024 23:26
Git send-email using Gmail
  1. Configure git.
# ~/.config/git/config
[sendemail]
  confirm = auto
  smtpServer = smtp.gmail.com
  smtpServerPort = 587
  smtpEncryption = tls
  smtpUser = <gmail email address>