Skip to content

Instantly share code, notes, and snippets.

View watson's full-sized avatar

Thomas Watson watson

View GitHub Profile
@watson
watson / whois apple.com
Last active December 14, 2015 18:39
Whois for big-co domains
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
APPLE.COM.ZON.COM
APPLE.COM.WWW.ZON.COM
APPLE.COM.WWW.BEYONDWHOIS.COM
APPLE.COM.WAS.PWNED.BY.M1CROSOFT.COM
@watson
watson / mongojs-duplicate-key-test.js
Created April 10, 2013 20:04
This code will result in 9 "E11000 duplicate key error index" errors
var dbUri = '...';
var db = require('mongojs').connect(dbUri, ['testing']);
var data = { foo: 1 };
for (var n = 0; n < 10; n++) {
db.testing.insert(data, function (err, res) {
if (err) console.log(err.message);
});
}
@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 / gist:7041200
Last active December 25, 2015 21:19
Cloudflare issue
watson% traceroute cloudflare.com
traceroute: Warning: cloudflare.com has multiple addresses; using 190.93.240.253
traceroute to cloudflare.com (190.93.240.253), 64 hops max, 52 byte packets
1 192.168.1.1 (192.168.1.1) 1.437 ms 0.888 ms 1.319 ms
2 10.66.128.210 (10.66.128.210) 61.005 ms 31.291 ms 33.169 ms
3 10.66.128.209 (10.66.128.209) 31.651 ms 35.649 ms 39.613 ms
4 172.18.4.101 (172.18.4.101) 51.770 ms
172.18.4.85 (172.18.4.85) 31.144 ms
172.18.4.81 (172.18.4.81) 31.394 ms
5 172.18.72.66 (172.18.72.66) 31.356 ms
@watson
watson / http2.js
Last active January 1, 2016 04:48
API brainstorm for treating node.js http(s) as a stream
var http2 = require('http2'); // working title
http2.get('http://foo.com').pipe(...);
http2('http://foo.com').pipe(...);
http2('https://example.com')
.on('response', function (res) {
// e.g. allows you to inspect the headers and take appropriate action
if (res.headers['some-header'] === 'some-value')
this.abort();
@watson
watson / normal.js
Last active January 3, 2016 06:09
Thinking about the most simple queueing implementation...
var process = function (a, b) {
// do some async stuff with a and b
};
process(foo1, bar1);
process(foo2, bar2);

This sets up two HTTP servers on port 3000 and 3001. The one on port 3000 works as expected, the one on port 3001 doesn't.

Console log output when requesting server on port 3000:

------- NEW WORKING REQUEST -------
New listener added: end
adding 1st data litener
New listener added: data
New listener added: data
New listener added: readable
var stream = require('stream')
var rs = new stream.Readable()
rs.push('hello')
rs.push('world')
rs._read = function() {}
var sameTick = true
rs.on('data', function() {
@watson
watson / index.js
Created June 4, 2014 10:53
Trying to auto-resume a paused stream by piping (not working)
var http = require('http');
http.createServer(function (req, res) {
console.log('Got request');
req.pause();
var size = 0;
req.on('data', function (chunk) {
console.log('Counting...');
size += chunk.length;
@watson
watson / halt.js
Created August 8, 2014 16:43
Node.js 0.10.30 bug :(
// This will stop working after a few iterations on Node 0.10.30
// For details see: https://github.com/joyent/node/issues/8065
setInterval(function () {
console.log("I'm alive!");
}, 42.1);