Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ry
ry / net.js
Created December 18, 2009 20:39
var debugLevel = 0;
if ('NODE_DEBUG' in process.ENV) debugLevel = 1;
function debug (x) {
if (debugLevel > 0) {
process.stdio.writeError(x + '\n');
}
}
var assert = process.assert;
@ry
ry / https-hello-world.js
Created January 4, 2011 00:03
new node https api
// curl -k https://localhost:8000/
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
https.createServer(options, function (req, res) {
// Answer to http://github.com/ry/http-parser/issues/#issue/1
// UNTESTED
struct line {
char *field;
size_t field_len;
char *value;
size_t value_len;
};
@ry
ry / 20190802-oumuamua.md
Last active June 6, 2021 05:00
Example
@ry
ry / uv-ipc.c
Created September 21, 2011 22:02
typedef struct uv_ipc_s uv_ipc_t;
/* uv_ipc_t is a subclass of uv_stream_t */
struct uv_ipc_s {
UV_HANDLE_FIELDS
UV_STREAM_FIELDS
UV_IPC_PRIVATE_FIELDS
};
for i in $HOME/local/*; do
[ -d $i/bin ] && PATH="${i}/bin:${PATH}"
[ -d $i/sbin ] && PATH="${i}/sbin:${PATH}"
[ -d $i/include ] && CPATH="${i}/include:${CPATH}"
[ -d $i/lib ] && LD_LIBRARY_PATH="${i}/lib:${LD_LIBRARY_PATH}"
[ -d $i/lib ] && LD_RUN_PATH="${i}/lib:${LD_RUN_PATH}"
# uncomment the following if you use macintosh
# [ -d $i/lib ] && DYLD_LIBRARY_PATH="${i}/lib:${DYLD_LIBRARY_PATH}"
[ -d $i/lib/pkgconfig ] && PKG_CONFIG_PATH="${i}/lib/pkgconfig:${PKG_CONFIG_PATH}"
[ -d $i/share/man ] && MANPATH="${i}/share/man:${MANPATH}"
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Here is a reference to the commit: http://codereview.chromium.org/659007
// [...]
void SetProcessName(CFStringRef process_name) {
if (!process_name || CFStringGetLength(process_name) == 0) {
NOTREACHED() << "SetProcessName given bad name.";
XTerm*utf8: 1
XTerm*faceName: DejaVu Sans Mono
XTerm*faceSize: 13
XTerm*background: #000000
XTerm*foreground: #aaaaaa
XTerm*metaSendsEscape: true
XTerm*colorBD: #ffffff
XTerm*colorBDMode: true
XTerm*cursorBlink: false
XTerm*cursorColor: #bbbbcc
@ry
ry / fib.js
Created March 12, 2012 00:17
a proper fibonacci server in node. it will light up all your cores.
var http = require('http')
var fork = require('child_process').fork;
function fib(n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}