Skip to content

Instantly share code, notes, and snippets.

View nathanbowser's full-sized avatar

Nathan Bowser nathanbowser

View GitHub Profile
@nathanbowser
nathanbowser / gist:3382533
Created August 17, 2012 20:52
Dash benchmarks
All benchmarks were run on a 4 core processor and executed on the same box as the running process. The tests were run for 10,000 requests, 100 concurrent.
One process (dev mode) -- fetching index
----------------------------------------
Hit 4000 requests, then ab died with apr_pollset_poll: The timeout specified has expired (70007)
Slow as balls.
One process (prod mode) -- fetching index
@nathanbowser
nathanbowser / git-publish
Created September 28, 2012 13:54
Git publish
#!/usr/local/bin/node
var exec = require('child_process').exec
, cmds = []
cmds.push('git checkout gh-pages')
cmds.push('git merge master')
cmds.push('git push origin gh-pages')
cmds.push('git checkout master')
exec(cmds.join(' && '))
var http = require('http')
, mongoose = require('mongoose')
, Schema = mongoose.Schema
var conn = mongoose.connect('mongodb://localhost/mongoose_test')
var names = ('Nathan Kristina Linus').split(' ')
var Person = new Schema({
name: String
});
collection: widgets
[
{
title: 'Red Widget',
parts: {
top: [{id: 1}],
bottom: [{id: 2}]
}
}
@nathanbowser
nathanbowser / gist:4495005
Created January 9, 2013 17:23
Duplicate ids
var ids = document.querySelectorAll('[id]')
for(var i = 0; i < ids.length; i++) {
var dups = document.querySelectorAll('[id="' + ids[i].id + '"]')
if (dups.length > 1 && ids[0] === ids[i]) {
console.log('Duplicate id: ' + ids[i].id)
}
}
module.exports.thumb = function (buffer) {
var full = new Buffer(buffer, 'base64') // Convert base64 encoded value into binary
, thumbStream = new stream.Stream() // Create a new writable stream
im(full).thumb(800, 450, 100, 'topLeft', function (err, stdout, stderr) {
var writeStream = fs.createWriteStream('n.jpg')
stdout.pipe(thumbStream)
})
return thumbStream
var Mandrill = require('mandrill-api').Mandrill
, m = new Mandrill('<key goes here>')
m.messages.sendTemplate('mandrill-api-test', function (response) {
console.log(response)
})
// This generates the following:
///Volumes/Bertha/users/koopa/node_modules/mandrill-api/mandrill.js:108
{
"graph": {
"datasequences": [
{
"datapoints": [
{
"value": 12,
"title": "2008"
},
{
{
"graph": {
"datasequences": [
{
"datapoints": [
{
"value": 12,
"title": "Jan 2012"
},
{
var request = require('request')
process.on('uncaughtException', function (err) {
console.log('Unwanted', err)
})
request('gizmo').on('error', function (err) {
console.log('Wanted', err)
})