Skip to content

Instantly share code, notes, and snippets.

@qcom
qcom / app.js
Last active August 29, 2015 14:05
function cb() {
console.log(iNeedThis);
}
var myModule = {
myMethod : function() {
var iNeedThis;
setTimeout(cb, 0);
}
};
@qcom
qcom / setup.sql
Last active August 29, 2015 14:05
CREATE TABLE IF NOT EXISTS items (
id serial PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS industries (
id serial PRIMARY KEY,
name text UNIQUE NOT NULL
);
CREATE TABLE IF NOT EXISTS items_industries (
@qcom
qcom / app.js
Last active August 29, 2015 14:05
/* app.js */
var express = require('express');
var app = express();
app.set('db', myDbHandle)
var login = require('./lib/login');
app.use(login(app));
var moment = require('moment');
var queryBuilder = require('./queryBuilder.js').bind(null, 'https://someurl.com');
module.exports = helpers = {};
/* delete all key/value pairs on obj that are equal to the provided val */
helpers.deleteAll = function(obj, val) {
for (var key in obj)
if ((typeof obj[key] === 'string' ? obj[key].trim() : obj[key]) === val)
delete obj[key];
@qcom
qcom / db.js
Created July 22, 2014 22:57
wrangling that flow control tho
db.postClassified = function(data, callback) {
var tx = new Transaction(client);
async.waterfall([
function(cb) { tx.begin(cb); },
function(result, cb) {
if (!data.image_name) return cb(null, null);
tx.query("INSERT INTO images (file_name) VALUES ($1) RETURNING id", [data.image_name], cb);
},
function(result, cb) {
tx.query("INSERT INTO classifieds (email, phone_number, name, posting_title, price, address, image, posting_body, condition) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
@qcom
qcom / server.js
Last active August 29, 2015 14:03
function logAndNext() {
app.get('log').pageRequested({ ip : ip, pos : req.session.pos, page : req.url, method : req.method }, function(err) {
if (err) throw err;
next();
});
}
if (!req.session.pos) {
app.get('db').getPosByIp(ip, function(err, pos) {
req.session.pos = pos;
logAndNext();
@qcom
qcom / async.js
Last active August 29, 2015 14:02
trying async module
var pg = require('pg');
var request = require('request');
var async = require('async');
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;
@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) {
#####################################################################
## ~~ 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 / 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();
});
}