Skip to content

Instantly share code, notes, and snippets.

View jorangreef's full-sized avatar

Joran Dirk Greef jorangreef

View GitHub Profile
@jorangreef
jorangreef / gist:77e7c609a15c6bea2ed749340c6ae9b3
Created September 9, 2020 14:48
stack or result location semantics
fn stack_or_result_location_semantics() custom_struct {
var custom_structs: [1]custom_struct = undefined;
fill_in_custom_struct(&custom_structs, 1);
return custom_structs[0];
}
fn boom_or_safe() void {
var custom_struct = stack_or_result_location_semantics();
}
@jorangreef
jorangreef / binding.c
Created March 9, 2019 15:13
get_buffer()
#include <assert.h>
#include <limits.h>
#include <node_api.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
static int arg_buf(
napi_env env,
napi_value value,
@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:
@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 / 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 / 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);
});
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 / 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');
#!/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 / 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.