Skip to content

Instantly share code, notes, and snippets.

View watson's full-sized avatar

Thomas Watson watson

View GitHub Profile
@watson
watson / christmas-dinner.md
Last active December 28, 2017 12:00
Copenhagen Node.js Christmas Dinner invitation

Copenhagen Node.js Christmas Dinner

Date: January 6th 2018
Time: 5pm -> ?

Location

Zendesk DK HQ
Snaregade 12, 2nd floor
1205 Copenhagen

@watson
watson / bisect.sh
Last active January 27, 2022 10:55
Automated git bisect to find breaking commit in Node core. This example was used to find a specific issue, so it should of course be modified to fit your needs. These files are ment to be put inside the root of your locally cloned node repo.
#!/usr/bin/env bash
# This script is an easy way to bisect between two releases of Node.js
if [ $# -ne 2 ]; then
echo "Error: No arguments supplied!"
echo "Usage:"
echo " ./bisect.sh <git-ref> <git-ref>"
echo
echo "Example:"
@watson
watson / npm-seq-203248.js
Last active February 12, 2017 02:36
Odd npm registry change sets
{ seq: 203248,
id: 'testx2',
changes: [ { rev: '1-53eafb13e023fc3a7a1b319a3eb17b2a' } ],
doc:
{ _id: 'testx2',
_rev: '1-53eafb13e023fc3a7a1b319a3eb17b2a',
name: 'testx2',
versions:
{ '1.0.0':
{ dist: { tarball: 'http://registry.npmjs.org/testx2/-/a' },
@watson
watson / big-npm.js
Last active February 4, 2017 10:28
Run through the entire npm CouchDB database and list each change-set larger than a previous set
'use strict'
var ChangesStream = require('changes-stream')
var block = 0
var biggest = 0
var changes = new ChangesStream({
db: 'https://replicate.npmjs.com',
include_docs: true,
@watson
watson / error.js
Created September 24, 2016 14:48
Creating custom error types in Node.js
var util = require('util')
util.inherits(NotFoundError, Error)
throw new NotFoundError('foo')
function NotFoundError (message) {
Error.captureStackTrace(this, this.constructor)
this.name = this.constructor.name
this.message = message
@watson
watson / jsonstream.js
Last active July 11, 2018 19:13
Example of using the JSONStream module
var request = require('request')
var JSONStream = require('JSONStream')
var opts = {
url: 'https://api.github.com/users/watson/repos',
headers: {'User-Agent': 'request'}
}
request(opts)
.pipe(JSONStream.parse('*'))
@watson
watson / redos.js
Last active December 15, 2022 17:11
Node.js ReDoS example
// for more info about ReDoS, see:
// https://en.wikipedia.org/wiki/ReDoS
var r = /([a-z]+)+$/
var s = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa!'
console.log('Running regular expression... please wait')
console.time('benchmark')
r.test(s)
@watson
watson / four-byte-emojis.json
Last active April 28, 2024 13:47
Emoji's sorted by byte-size
[
"😁",
"😂",
"😃",
"😄",
"😅",
"😆",
"😉",
"😊",
"😋",
@watson
watson / test.js
Last active November 8, 2015 09:42
Testing error-callsites with error-create
var assert = require('assert')
var callsites = require('error-callsites')
var MyCustomError = require('error-create')('MyCustomError')
var err = new MyCustomError('foo')
assert(err instanceof Error)
assert(err instanceof MyCustomError)
assert.doesNotThrow(function () {
callsites(err)
@watson
watson / bad.js
Created October 28, 2015 21:49
Async/delayed/cached
var files = ['foo.js', 'bar.js', 'foo.js']
files.forEach(function (file) {
// this will end up reading foo.js twice
fs.readFile(file, function (err, data) {
// ...
})
})