Skip to content

Instantly share code, notes, and snippets.

View bnoordhuis's full-sized avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/select.h>
#include <curl/curl.h>
#define IMAP_URL "imap://testuser:testuser@localhost/Drafts"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include "iconv.h"
int main(void) {
size_t inbytesleft, outbytesleft;
// https://github.com/bnoordhuis/node-iconv/issues/16
gc = require('iconv').gc;
Iconv = require('iconv').Iconv;
function randomIndex(a) {
return a[Math.floor(a.length * Math.random())];
}
sourceEncodings = 'ascii iso-8859-1 utf-8'.split(' ');
targetEncodings = 'ascii iso-8859-1 utf-8 utf-16le utf-16be utf-32le utf-32be'.split(' ');
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "markdown.h"
#include "xhtml.h"
#ifndef N_THREADS
#define N_THREADS 2
@bnoordhuis
bnoordhuis / http_status_codes.py
Created May 16, 2011 12:24
HTTP status codes
HTTP_STATUS_CODES = {
100: "Continue",
101: "Switching Protocols",
200: "OK",
201: "Created",
202: "Accepted",
203: "Non-Authoritative Information",
204: "No Content",
205: "Reset Content",
206: "Partial Content",
#!/usr/bin/env python
import socket
import sys
host, port = sys.argv[1:]
host = socket.gethostbyname(host)
port = int(port)
require('http').createServer(function(req, res) {
console.error('Request', req.headers);
req.on('data', function(chunk) {
console.error('Received chunk', chunk, chunk.toString());
});
setTimeout(function() {
var body = "Hello World\n";
@bnoordhuis
bnoordhuis / default.vcl
Created June 14, 2011 10:46
[varnish] normalize Accept-Encoding header
# normalize Accept-Encoding header
if (req.http.Accept-Encoding) {
if (req.url ~ "\.(jpeg|jpg|png|gif|gz|tgz|bz2|tbz|zip|flv|pdf|mp3|ogg)$") {
remove req.http.Accept-Encoding; # already compressed
}
elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
}
elsif (req.http.Accept-Encoding ~ "deflate") {
set req.http.Accept-Encoding = "deflate";
@bnoordhuis
bnoordhuis / test-utf8.c
Created June 14, 2011 22:49
Simple UTF-8 <-> Unicode encoder
/**
* 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 / ebadname.js
Created June 18, 2011 22:23
ebadname.js - uncatchable exception
var http = require('http');
var host = '********';
host += host;
host += host;
host += host;
host += host;
host += host;
try {