Skip to content

Instantly share code, notes, and snippets.

View bnoordhuis's full-sized avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
@bnoordhuis
bnoordhuis / pthread_chdir.c
Created December 6, 2012 02:25
OS X undocumented __pthread_chdir() and __pthread_fchdir() syscalls
#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 / results.txt
Created October 30, 2012 22:52
show difference between mmap() and malloc()
$ 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 November 16, 2010 23:01
node.js + sendfile = file serving++
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'
@bnoordhuis
bnoordhuis / trace.py
Created July 6, 2011 19:02
trace function calls with gdb
#!/usr/bin/env python
import re
import sys
import subprocess
import tempfile
nm = 'nm'
gdb = 'gdb'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char **make_copy(int argc, char **argv)
{
size_t strlen_sum;
char **argp;
char *data;
size_t len;
@bnoordhuis
bnoordhuis / trace-all-events.js
Created January 3, 2012 14:38
Trace all events in a node.js application
(function() {
var EventEmitter = require('events').EventEmitter;
var inspect = require('util').inspect;
var emit_ = EventEmitter.prototype.emit;
EventEmitter.prototype.emit = function(name) {
var args = Array.prototype.slice.call(arguments);
if (!(this === process.stderr && name === 'drain')) {
console.error("Event '%s', arguments: %s",
name, inspect(args.slice(1), false, 1));
}
@bnoordhuis
bnoordhuis / fno_delete_null_pointer_checks.diff
Created September 20, 2016 18:14
clang 3.9.0 -fno-delete-null-pointer-checks
diff --git a/tools/clang/include/clang/Driver/Options.td b/tools/clang/include/clang/Driver/Options.td
index d03ab04..0e03a0a 100644
--- a/tools/clang/include/clang/Driver/Options.td
+++ b/tools/clang/include/clang/Driver/Options.td
@@ -479,6 +479,12 @@ def fno_autolink : Flag <["-"], "fno-autolink">, Group<f_Group>,
Flags<[DriverOption, CC1Option]>,
HelpText<"Disable generation of linker directives for automatic library linking">;
+def fdelete_null_pointer_checks : Flag<["-"], "fdelete-null-pointer-checks">,
+ Group<f_Group>, Flags<[CC1Option]>,
@bnoordhuis
bnoordhuis / gc.stp
Created November 15, 2012 14:36
systemtap script that prints aggregated node.js garbage collector statistics
#!/usr/bin/env stap
global samples
global all_samples
global timestamp
probe process("node").mark("gc__start")
{
timestamp = gettimeofday_us()
}
@bnoordhuis
bnoordhuis / punycode.js
Created June 20, 2011 15:49
javascript punycode encoder and decoder
/**
* 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:
*
// Copyright (c) 2014, 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