Skip to content

Instantly share code, notes, and snippets.

View jorangreef's full-sized avatar

Joran Dirk Greef jorangreef

View GitHub Profile
@jorangreef
jorangreef / pause-keep-alive
Created February 24, 2011 17:58
Server.request.pause() causing problems for subsequent requests on keep-alive connections
var http = require('http');
http.createServer(
function(request, response) {
request.pause();
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.write('now press CMD + R and every other request will hang for 2 minutes before returning');
response.end();
}
).listen(4000);
@jorangreef
jorangreef / cipher-server.js
Last active August 29, 2015 14:15
Test io.js TLS ciphers
var constants = require('constants');
var fs = require('fs');
var https = require('https');
// Modified form of current io.js default ciphers which gets A+ on ssllabs (assuming SHA256 certificate signature).
// Downside is it's not explicit which would be much better.
var ciphersImplicit = [
'ECDHE-RSA-AES128-GCM-SHA256',
'ECDHE-RSA-AES128-SHA256',
'ECDHE-RSA-AES128-SHA',
@jorangreef
jorangreef / gist:1aa7ec6ccd82585090bc
Last active August 29, 2015 14:15
io.js Default Ciphers Test
var constants = require('constants');
var fs = require('fs');
var https = require('https');
// Fedor's explicit cipher list.
// Good to see AES256 at the top of the list.
// Perhaps all the ECDHE ciphers should be moved above the DHE ciphers?
// Is the DES-CBC3-SHA necessary?
// Does not get A+ on ssllabs.
// Missing forward secrecy for IE and Safari reference browsers.
#!/bin/bash
# Invoke this script with a relative '.app' path, for example:
# codesign-electron.sh "darwin-x64/Electron.app"
# 1. Run the following command to get a list of identities:
# security find-identity
# 2. Now set the value of the identity variable below to the identity you want to use:
identity="Developer ID Application: ... (...)"
@jorangreef
jorangreef / test-watch.js
Last active December 19, 2015 12:17
Test the reliability and average and max latency of the underlying OS notification system used by Node's fs.watch. Uses fsync to flush the filesystem cache to make sure these don't delay notifications (this makes little to no difference).
var Node = {
child: require('child_process'),
fs: require('fs'),
path: require('path')
};
// This will be removed and then created and then removed:
var testdirectory = 'testfswatchmisses';
if (Node.fs.remove !== undefined) throw new Error('fs.remove exists');
var fs = require('fs');
var path = require('path');
/*
This test is designed for Windows, and tests whether changed folder events
are emitted on time or after several seconds delay (up to 40 seconds or more).
This requires renaming a file at least two subfolders deep relative to the
watched folder. Renaming a file only one subfolder deep will not reproduce
the slow behavior.
@jorangreef
jorangreef / crash.js
Last active January 28, 2016 18:09
Reproduces a crash in Node.js on Windows 7 and Windows 10 when using a recursive fs.watch
var path = require('path');
var fs = require('fs');
// Be careful of adding in console.log statements as these can
// influence the outcome of the script on Windows and cause it to pass.
process.on('uncaughtException', function(error) {
console.log('error: ' + error);
});
@jorangreef
jorangreef / v8 gc segfault
Last active October 29, 2016 15:11
This will segfault if v8's heap.cc CollectAllGarbage and CollectAllAvailableGarbage are empty functions
setInterval(
function() {
},
1000
);
var array = [];
array.push(new Buffer(12189696));
array.push(new Buffer(629145600));
@jorangreef
jorangreef / fstat.js
Created September 25, 2018 15:27
fs.fstat()
var fs = require('fs');
function callback(error) {
if (error) {
console.error(error);
process.exit(1);
return;
}
if (++count >= 1000000) {
console.log((Date.now() - now) + 'ms');
@jorangreef
jorangreef / open.js
Created November 28, 2018 13:39
DirectIO cross-platform open()
const DirectIO = require('@ronomon/direct-io');
const Node = {
fs: require('fs'),
path: require('path'),
process: require('process')
};
const PATH = '\\\\.\\PhysicalDrive1';
// 4096 is better than 512 because it works with new Advanced Format devices: