Skip to content

Instantly share code, notes, and snippets.

/* Make Jobs Searchable */
DROP TRIGGER make_job_searchable ON jobs;
DROP TRIGGER make_job_searchable_update ON jobs;
DROP FUNCTION make_job_searchable();
CREATE FUNCTION make_job_searchable() RETURNS trigger AS $make_job_searchable$
DECLARE
searchable_document text;
industries text;
@qcom
qcom / app.js
Last active August 29, 2015 13:59
trying to avoid a nested promise and a callback
thisReturnsAPromise().then(function(val) {
if (something) {
anotherPromiseReturningFn(val.property).then(function() {
callback();
});
} else {
callback();
}
});
@qcom
qcom / app.js
Last active August 29, 2015 13:59
oh control flow I don't understand you
// app.get('db') is a reference to my wrapper module over knex.js
// which just bundles actions/behavior into entity-named properties (tag, jobIndustries, etc.)
app.get('db').tag.getBelongingToJob(job.job_id)
.then(function(tags) {
job.tags = tags;
return app.get('db').jobIndustries.get(job.job_industry);
}).then(function(jobIndustry) {
job.job_industry = jobIndustry;
return app.get('db').jobCategories.get(job.job_category);
@qcom
qcom / app.js
Last active August 29, 2015 13:58
control flow confusion
/* map query string fields to search filters */
var inexactFilters = {
date_added : function(queryVal, job, cb) {
cb(moment(job.date_added).format('MM-DD-YYYY') === queryVal);
},
tags : function(queryVal, job, cb) {
console.log(cb.toString());
app.get('db').tag.getBelongingToJob(job.job_id).then(function(tags) {
cb(queryVal.split(',').filter(function(tag) { return tags.map(function(tag) { return tag.tag_content; }).indexOf(tag) !== -1; }).length > 0);
@qcom
qcom / app.js
Created March 24, 2014 18:34
my attempt at an expressjs route
/* relevant section of my db module */
db.user = {};
db.user.available = function(email) {
return knex('users')
.where('email', email)
.then(areNone);
};
db.user.add = function(data) {
return knex('users')
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);
});
}
@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
@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 / 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 / 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);
});
};
/*