Skip to content

Instantly share code, notes, and snippets.

View watson's full-sized avatar

Thomas Watson watson

View GitHub Profile
'use strict'
const asyncHooks = require('async_hooks')
const asyncIds = new Set()
const asyncHook = asyncHooks.createHook({
init (asyncId, type, triggerAsyncId, resource) {
const eid = asyncHooks.executionAsyncId()
process._rawDebug(`${type}(${asyncId}): trigger: ${triggerAsyncId} execution: ${eid}`, resource)
@watson
watson / console.log
Created April 23, 2013 09:56
This is what a traceroute from a Norwegian Airlines airplane looks like. I grapped it flying from Nice to Copenhagen on the 22nd of April 2013.
watson% traceroute google.com
traceroute: Warning: google.com has multiple addresses; using 173.194.70.139
traceroute to google.com (173.194.70.139), 64 hops max, 52 byte packets
1 192.168.33.1 (192.168.33.1) 1.203 ms 1.333 ms 0.859 ms
2 * * *
3 * * *
4 * * *
5 192.168.14.106 (192.168.14.106) 3277.827 ms 2498.515 ms 1261.000 ms
6 192.168.14.102 (192.168.14.102) 833.789 ms 1879.912 ms 3759.086 ms
7 2.239.214.82.in-addr.arpa (82.214.239.2) 2454.781 ms 1959.662 ms 1167.737 ms
@watson
watson / destroy-test.js
Last active September 1, 2018 19:58
Testing write on corked stream in combination with destroy for readable-stream@3
'use strict'
const { Writable } = require('readable-stream')
let stream
console.log('write')
stream = getStream()
stream.write('foo')
@watson
watson / server.js
Created August 27, 2018 14:17
Mock Elastic APM Server that always responds with an error before bothering to read the entire request body
'use strict'
const zlib = require('zlib')
const http = require('http')
const body = zlib.gzipSync(JSON.stringify({
errors: {
ERR_QUEUE_FULL: {
count: 23,
message: 'queue is full'
@watson
watson / server.js
Created August 27, 2018 12:49
HTTP server that half-closes the socket when an incoming HTTP request is received
'use strict'
const http = require('http')
const server = http.createServer(function (req, res) {
console.log(req.method, req.url)
res.socket.end() // Half-close the socket by sending FIN packet
})
server.listen(8200, function () {
@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 / boom.js
Last active February 22, 2018 21:01
Breaks in Node.js 9.6.0
var assert = require('assert')
var events = require('events')
assert(events.usingDomains)
@watson
watson / cheatsheet.md
Created October 5, 2014 23:34
ffmpeg cheat sheet

Convert A -> B

Convert and transcode:

ffmpeg -i in.mkv out.mp4

Covert without transcoding:

@watson
watson / install-redis.ps1
Last active January 23, 2018 09:59 — forked from FeodorFitsner/install-redis.ps1
Install Redis
Write-Host "Downloading Redis..." -ForegroundColor Cyan
$redisRoot = "$env:SYSTEMDRIVE\Redis"
$zipPath = "$($env:USERPROFILE)\redis-2.8.19.zip"
(New-Object Net.WebClient).DownloadFile('https://github.com/MSOpenTech/redis/releases/download/win-2.8.19/redis-2.8.19.zip', $zipPath)
7z x $zipPath -y -o"$redisRoot" | Out-Null
del $zipPath
Write-Host "Installing Redis as a Windows service..."
& "$redisRoot\redis-server.exe" --service-install