Skip to content

Instantly share code, notes, and snippets.

@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);
});
}
@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')
@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
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:59
trying to avoid a nested promise and a callback
thisReturnsAPromise().then(function(val) {
if (something) {
anotherPromiseReturningFn(val.property).then(function() {
callback();
});
} else {
callback();
}
});
/* 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 14:01
function cb() {
app.get('db')[config.dbProperty].add(req.body, options.getAddObj(req.body)).then(function(id) {
res.redirect('/' + config.routeName + '/' + id);
});
}
if (itemHasCompany(config.itemName)) {
return util.updateCompany(req.body, req.session.user, app).then(function() {
cb();
});
}
#####################################################################
## ~~ HTML STREAM ~~ ##
#####################################################################
Your program will get some html written to stdin. Convert all the inner html to
upper-case for elements with a class name of "loud".
You can use `trumpet` and `through` to solve this adventure.
With `trumpet` you can create a transform stream from a css selector:
@qcom
qcom / addLocations.js
Created June 24, 2014 18:27
pull records from postgres that lack a lat/long position value and update accordingly via google's geocoding api
var pg = require('pg');
var request = require('request');
function getUrl(location) {
return 'https://maps.googleapis.com/maps/api/geocode/json?address=' + location.address + ', ' + location.city + ', ' + location.state + ' ' + location.zip_code;
}
var count = 0;
pg.connect(connString, function(err, client, done) {