Skip to content

Instantly share code, notes, and snippets.

View gjohnson's full-sized avatar

Garrett Johnson gjohnson

View GitHub Profile
@gjohnson
gjohnson / mongo-stats.js
Created October 29, 2013 13:47
messing around
/**
* Module dependencies.
*/
var strftime = require('strftime');
/**
* Creates the `record` function for `collection`.
*
@gjohnson
gjohnson / deploy.rb
Created October 19, 2013 16:46
deploy.rb
#
# Multistage.
#
set :stages, %w(production staging)
set :default_stage, "production"
require 'capistrano/ext/multistage'
@gjohnson
gjohnson / loadscript.js
Created September 24, 2013 22:29
load script helper
module.exports = function (redis, code) {
var cache = null;
return function (keys, args, done) {
if (!cache) load(code, curry(evalsha, keys, args, done))
else evalsha(cache, keys, args, done);
};
function curry(fn) {
var isOldIE = (function(){
var comment = '<!--[if IE]><i><![endif]-->';
var div = document.createElement('div');
div.innerHTML = comment;
return !!div.getElementsByTagName('i').length;
})();
type Message struct {
codec uint32
meta uint8
body string
}
@gjohnson
gjohnson / filters.html
Created June 11, 2013 18:52
angular filters
<input type="text" ng-model="search" placeholder="filter..." />
<div ng-repeat="item in items | filter:search">
<!-- goodness -->
</div>
/**
* Dependencies.
*/
var Domain = require('domain');
var http = require('http');
var app = require('..');
/**
@gjohnson
gjohnson / index.js
Created May 8, 2013 20:13
Handle session timeouts within ajax calls nicely.
$httpProvider.responseInterceptors.push(function($window){
return function(promise){
return promise.then(function(){
// session is valid, carry along...
return promise;
}, function(error){
if (error.status == 401) {
// invalid session, need to re-login...
$window.location = '/login';
}
@gjohnson
gjohnson / app.js
Last active December 16, 2015 11:58
splitting up angular controllers
(function(){
var ScopeShare = angular.module('ScopeShare', []);
ScopeShare
.controller('FormController', function($scope){
$scope.user = {};
$scope.submit = function(){
console.log(JSON.stringify($scope.user));
};
@gjohnson
gjohnson / proto1.js
Created April 20, 2013 11:20
__proto__ behavior
var a = { hello: 'world' };
var b = {};
// has no own property "hello"
console.log(b.hello); // undefined
// set __proto__ to b, so "hello" will resolve
b.__proto__ = a;
console.log(b.hello); // hello