Skip to content

Instantly share code, notes, and snippets.

View timoxley's full-sized avatar

Tim Kevin Oxley timoxley

View GitHub Profile
@timoxley
timoxley / gist:1236424
Created September 23, 2011 00:10 — forked from scottharvey/gist:1236411
Backbone class functions in Coffeescript
class API extends Backbone.Model
{}
fetchData: ->
// API call here
@timoxley
timoxley / gist:1314547
Created October 25, 2011 22:26 — forked from uptownben/gist:1314512
Mongoose JS Schema methods error
/**
* Module dependencies.
*/
var express = require('express');
var mongoose = require('mongoose');
var fs = require('fs');
var Schema = mongoose.Schema;
var db = mongoose.connect('mongodb://localhost/myapp');
'name must be unique': function(test) {
account.save(function(err) {
if (/duplicate/.test(err) || /unique/.test(err)) {
console.log(err.message)
test.done()
}
blueprints.generate('Account', function(err, anotherAccount) {
if (err) throw err
anotherAccount.name = account.name
anotherAccount.save(function(err) {
@timoxley
timoxley / index.js
Created April 6, 2012 08:47 — forked from framlin/gist:2317972
flatiron ip address middleware
var union = require('union');
var flatiron = require('flatiron');
var winston = require('winston');
var ecstatic = require('ecstatic');
app = new flatiron.App();
app.use(flatiron.plugins.http);
app.http.before = [
function (req, res) {
@timoxley
timoxley / index.js
Created April 6, 2012 09:35 — forked from framlin/index.js
flatiron ip address middleware
var union = require('union');
var flatiron = require('flatiron');
var winston = require('winston');
var ecstatic = require('ecstatic');
app = new flatiron.App();
app.use(flatiron.plugins.http);
app.http.before = [
var union = require('union');
@timoxley
timoxley / gist:2585724
Created May 3, 2012 13:40 — forked from mhart/test1.js
'cat' in node.js
process.stdin.resume()
process.stdin.on('data', function(data) { process.stdout.write(data) })
process.stdout.on('error', function(err) {
if (err.code === 'EPIPE') process.exit()
else if (!process.stdout.listeners('error').length) process.emit('error', err)
})
function createResponse(name) {
this.name = name,
this.sayHi = function() {
return 'Hi!';
},
this.getName = function() {
return this.name;
},
@timoxley
timoxley / promise-unhandled-why.js
Last active July 13, 2021 17:03 — forked from mafintosh/promise-unhandled-why.js
promise-unhandled-why.js
start()
async function start () {
const promises = [
new Promise((resolve, reject) => setTimeout(() => reject(0), 1000)),
Promise.reject(1),
Promise.reject(2)
]
promises.forEach(p => p.catch(() => {})) // prevent unhandled