Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
@bnoordhuis
bnoordhuis / http-and-https-proxy.js
Created Feb 8, 2013
A node.js proxy that accepts HTTP and HTTPS traffic on the same port.
View http-and-https-proxy.js
var fs = require('fs');
var net = require('net');
var http = require('http');
var https = require('https');
var httpAddress = '/path/to/http.sock';
var httpsAddress = '/path/to/https.sock';
fs.unlinkSync(httpAddress);
fs.unlinkSync(httpsAddress);
@bnoordhuis
bnoordhuis / bytestokey.js
Created Nov 29, 2017
Compute key+IV from passphrase (createCipher to createCipheriv migration script)
View bytestokey.js
// Copyright (c) 2017, Ben Noordhuis <info@bnoordhuis.nl>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
View .vimrc
" vim > vi
set nocompatible
syntax on
filetype on
filetype plugin on
filetype indent on
" auto reload changes files (that don't have unsaved changes)
set autoread
@bnoordhuis
bnoordhuis / await.js
Created Aug 28, 2019
Await pending promises on Node.js process exit
View await.js
// Copyright (c) 2019, Ben Noordhuis <info@bnoordhuis.nl>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@bnoordhuis
bnoordhuis / pthread_chdir.c
Created Dec 6, 2012
OS X undocumented __pthread_chdir() and __pthread_fchdir() syscalls
View pthread_chdir.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <fcntl.h>
#ifndef SYS___pthread_chdir
# define SYS___pthread_chdir 348
#endif
@bnoordhuis
bnoordhuis / uml-notes.md
Last active Oct 11, 2018
Setting up User Mode Linux on Fedora 20
View uml-notes.md

user mode linux: build and run

Generate default .config.

$ make defconfig ARCH=um SUBARCH=x86_64

Build the linux ELF binary.

$ make -j8 linux ARCH=um SUBARCH=x86_64
@bnoordhuis
bnoordhuis / stacktrace.cc
Last active Jul 23, 2018
Decode C/C++ and V8 JS stack frames.
View stacktrace.cc
#include "v8.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <cxxabi.h>
#include <dlfcn.h>
using namespace v8;
@bnoordhuis
bnoordhuis / punycode.py
Created Jun 20, 2011
python punycode encoder and decoder
View punycode.py
#!/usr/bin/env python
#
# Copyright (C) 2011 by Ben Noordhuis <info@bnoordhuis.nl>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@bnoordhuis
bnoordhuis / results.txt
Created Oct 30, 2012
show difference between mmap() and malloc()
View results.txt
$ gcc -DUSE_MMAP=0 tmp/rss.c && ./a.out
rss 360448
==============
rss 360448
rss 1429504
rss 552960
==============
rss 552960
rss 1359872
rss 1359872
@bnoordhuis
bnoordhuis / gist:702695
Created Nov 16, 2010
node.js + sendfile = file serving++
View gist:702695
http = require('http');
fs = require('fs');
fd = fs.openSync(__filename, 'r');
size = fs.fstatSync(fd).size;
server = http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Length': size,
'Content-Type': 'text/plain'