This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cb() { | |
console.log(iNeedThis); | |
} | |
var myModule = { | |
myMethod : function() { | |
var iNeedThis; | |
setTimeout(cb, 0); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* app.js */ | |
var express = require('express'); | |
var app = express(); | |
app.set('db', myDbHandle) | |
var login = require('./lib/login'); | |
app.use(login(app)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################### | |
## ~~ 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
} |