Skip to content

Instantly share code, notes, and snippets.

View bnoordhuis's full-sized avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
@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:
*
@bnoordhuis
bnoordhuis / punycode.py
Created June 20, 2011 16:31
python punycode encoder and decoder
#!/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 / benchmark.txt
Created June 26, 2011 00:24
Buffer.writeUInt32() benchmarklet
$ time ./node tmp/test-uint32-slow.js
real 0m8.819s
user 0m8.790s
sys 0m0.030s
$ time ./node tmp/test-uint32-fast.js
real 0m2.210s
user 0m2.190s
@bnoordhuis
bnoordhuis / uv_ip6_addr.c
Created June 27, 2011 10:03
uv_ip6_addr
/**
* I, the copyright holder of this work, hereby release it into the public domain.
* This applies worldwide. In case this is not legally possible, I grant any entity
* the right to use this work for any purpose, without any conditions, unless such
* conditions are required by law.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
common = require("../common");
assert = require("assert");
net = require("net");
http = require("http");
var serverResponse = "";
var clientGotEOF = false;
server = http.createServer(function (req, res) {
console.log('server req');
@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 <stdint.h>
#include <limits.h>
uint64_t uint64_add(uint64_t a, uint64_t b, int* overflow) {
uint64_t c;
if (UINT64_MAX - a >= b) {
*overflow = 0;
return a + b;
}
http = require('http');
fs = require('fs');
FRONTEND_PORT = 8000;
BACKEND_PORT = 8001;
//CONTENT_LENGTH = 2147483648; // 2 GB
CONTENT_LENGTH = 2097152; // 2 MB
function log_events(prefix, obj) {
@bnoordhuis
bnoordhuis / safe-exec.c
Created August 3, 2011 21:11
race-free exec-after-fork
/*
* Copyright (c) 2011, 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
@bnoordhuis
bnoordhuis / fork-vs-vfork.c
Created August 4, 2011 23:37
fork vs vfork
/*
* Copyright (c) 2011, 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