Skip to content

Instantly share code, notes, and snippets.

@qcom
qcom / app.js
Created August 30, 2013 22:22
a backbone.js view
window.AttributeSearchResultView = Backbone.View.extend({
tagName: 'li',
events: {
'click': 'addAttribute'
},
addAttribtue: function() {
console.log('added');
},
initialize: function() {
this.template = _.template($('#attributeSearchResult-template').html());
@qcom
qcom / track.html
Created September 9, 2013 16:37
GoSquared tracking code
<script type="text/javascript">
var GoSquared = {};
GoSquared.acct = "GSN-889229-P";
(function(w){
function gs(){
w._gstc_lt = +new Date;
var d = document, g = d.createElement("script");
g.type = "text/javascript";
g.src = "//d1l6p2sc9645hc.cloudfront.net/tracker.js";
var s = d.getElementsByTagName("script")[0];
@qcom
qcom / gist:7165866
Created October 26, 2013 06:14
pop.scm
(define (pop lis)
(define (r a b)
(if (= (length b) 1)
a
(r (cons a (car b)) (cdr b))
))
(cond
((NULL? lis) '())
((= (length lis) 1) '())
(else (r (car lis) (cdr lis)))
@qcom
qcom / odds.scm
Last active December 27, 2015 03:09
return the elements of a list with an odd index (1, 3, 5, etc.)
(define (odds lis)
(reverse (odds-reduce lis '())))
(define (odds-reduce l1 l2)
(cond
((null? l1) l2)
((= (length l1) 1) (cons (car l1) l2))
(else (odds-reduce (cddr l1) (cons (car l1) l2)))
))
@qcom
qcom / update.js
Created December 31, 2013 09:01
update an object given a slash-delimited path (where each element in path is a property) and a value
function update(path, val, obj) {
(function r(keys, o) {
if (keys.length > 1) {
var current = keys.shift();
if (!o[current])
o[current] = isNaN(parseInt(keys[0])) ? {} : [];
r(keys, o[current]);
} else {
o[keys[0]] = val;
}
@qcom
qcom / db.js
Created January 3, 2014 06:07
overwrite mongodb document
DB.prototype.updateTodo = function(id, val, fn) {
this.db.collection('todo').update({ _id : id }, val, function(err) {
if (err) return fn(err);
console.log(arguments);
fn(null);
});
};
/*
@qcom
qcom / bind.js
Last active January 2, 2016 08:49
Function.prototype.bind = function(thisObj) {
var that = this;
return function() {
return that.apply(thisObj, arguments);
};
};
function fn() {
return this;
}
@qcom
qcom / reduce.js
Created January 16, 2014 22:27
An implementation of reduce modeled after the underscore.js api that does not default to Array.prototype.reduce.
function reduce(obj, iterator, memo, ctx) {
var keys = Object.keys(obj),
memo = memo || obj[keys[0]];
ctx = ctx || null;
for (var i = arguments[2] ? 0 : 1; i < keys.length; i++)
memo = iterator.call(ctx, memo, obj[keys[i]], keys[i], obj);
return memo;
}
@qcom
qcom / .tmux.conf
Created January 30, 2014 07:33
my tmux config
# change command prefix binding
unbind C-b
set -g prefix C-a
# decrease command-sending delay
set -sg escape-time 1
# make window and pane index one-based
set -g base-index 1
setw -g pane-base-index 1
var pg = require(‘pg’), connString = ‘***’;
function DB(cb) {
var that = this;
pg.connect(connString, function(err, client, done) {
if (err) return cb(err);
that.client = client;
cb(null, that);
});
}