Skip to content

Instantly share code, notes, and snippets.

View jhs's full-sized avatar

Jason Smith jhs

  • McKinsey & Company
  • New York, NY
View GitHub Profile
@jhs
jhs / couchdb.js
Last active December 13, 2015 16:58
// Service all /_couchdb/* requests for CouchDB
//
module.exports = handle_http
function handle_http(req, res) {
res.writeHead(200, 'OK')
res.end('Hello to CouchDB!\n')
}

Hi, all.

Encouraged by my successful experiment with a Node.js view server, I am now working on a branch, nodejs_couchdb, with the following properties:

  • Remove couchjs from the project
  • Remove dependency on SpiderMonkey, libjs, 1.8.whatever...all that is gone
  • Remove dependency on libcurl
  • (Thus, simplified autoconf version dependency Hell)

Phase 1: Dependency on a "couchjs" executable which you install via npm install couchjs

@jhs
jhs / npm_Dec2012.txt.md
Last active December 10, 2015 11:08
Node.js npm December stats and reflections

Sent this to the [CouchDB users list][email] just now; duplicated here for others to see or comment

Hi, all. Sorry to be distant from the community recently. No excuse.

I thought I might share December stats from one of Apache CouchDB's most well-known deployments and killer apps: the Node.js npm registry.

Facts

  • Zero downtime
@jhs
jhs / rant.md
Last active December 10, 2015 09:18
Rant about Node.js library logging

What I want for library logging

I write Node.js libraries, and I want logging. Why is this so problematic?

Note, I am despairing about how library authors log stuff not how application builders decide on a logging framework.

Hopefully this document can become a spec or feature list for code I will write some day.

The antipattern

@jhs
jhs / example.js
Created December 10, 2012 03:16
My Node.js modules these days
// Short module explanation // Something to gather my thoughts
// // I think this looks cool.
//
module.exports = the_exported_function // Modules are a function. Always.
//
module.exports.extra = extra // Additional API entry points if
module.exports.other = other // desired.
//
var util = require('util') // Other packages from npm or core
var assert = require('assert') // No comma-first due to lots of
@jhs
jhs / for_in.js
Created August 10, 2012 16:34
Looping syntax
for (var thing in {'foo':1, 'bar':1, 'neat':1}) {
console.log('doing ' + thing)
doing(thing)
}
@jhs
jhs / iris-redis-example.js
Created August 4, 2012 02:00
Iris-Redis example
if(!process.env.redis_pass)
return console.error('Run this first: export redis_pass=<your password>')
var redis = require('iris-redis') // npm install iris-redis first, of course.
var client = redis.createClient(6379, 'redis.pouch.iriscouch.com')
client.auth(process.env.redis_pass)
client.on("ready", function() {
console.log('Connected %s at %s:%d', client.host, client.stream.remoteAddress, client.stream.remotePort)
client.iris_config(function(er, config) {
@jhs
jhs / irccloud_search.js
Created May 25, 2012 10:39
Get irccloud backlog
var request = require('request')
var SINCE = +process.env.since
if(!SINCE)
throw new Error('Need $since')
get_lines(SINCE)
function get_lines(beforeid) {
var headers = { 'Cookie': process.env.cookie }
if(!headers.Cookie)
@jhs
jhs / hello.js
Created April 6, 2012 00:41
Safe Javascript semicolons
var http = require('http');;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
http.createServer(function (request, response) {;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
response.writeHead(200, {'Content-Type': 'text/plain'});;;;;;;;;;;;;;;;;;;;;;;
response.end('Hello World\n');;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}).listen(8124);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
console.log('Server running at http://127.0.0.1:8124/');;;;;;;;;;;;;;;;;;;;;;;;;
@jhs
jhs / app.js
Created March 16, 2012 05:13
Failing node-couchapp Kanso application
// Example node-couchapp Kanso application.
//
var fs = require('fs')
var ddoc = module.exports = { 'views':{} }
fs.readdirSync(__dirname + '/views').forEach(function(file) {
var match = file.match(/^(.+)\.js$/)
, mod = match && match[1]