Skip to content

Instantly share code, notes, and snippets.

View pH200's full-sized avatar

pH pH200

  • Cytisan Software
  • Taipei, Taiwan
View GitHub Profile
@pH200
pH200 / gist:1806807
Created February 12, 2012 06:40
Modified DailyTextLogListener
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Permissions;
namespace Darkthread
{
/// <summary>
/// 會依每天日期獨立個別檔案的TextWriterTraceListener
/// </summary>
@pH200
pH200 / gist:3672019
Created September 8, 2012 05:13
Encoding files with UTF8 BOM
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace UTF8BOM
{
class Program
@pH200
pH200 / Makefile
Created October 2, 2012 02:20
Makefile for TypeScript on OSX, Linux, etc
TYPESCRIPT_HOST=node
BASE= ./
BIN=$(BASE)bin
BUILT=$(BASE)built
BUILT_LOCAL=$(BUILT)/local
BUILT_LOCALTEST=$(BUILT)/localtest
HOST=$(TYPESCRIPT_HOST)
@pH200
pH200 / gist:3845842
Created October 6, 2012 19:18
GDB backtrace V8 3.1.8
#0 0xf7fdb430 in __kernel_vsyscall ()
#1 0xf7d0426f in raise () from /lib32/libc.so.6
#2 0xf7d077c5 in abort () from /lib32/libc.so.6
#3 0x083570b8 in v8::Shell::System (args=...) at src/d8-posix.cc:460
#4 0x0809bf16 in v8::internal::HandleApiCallHelper<false> (args=...,
isolate=0x85240b8) at src/builtins.cc:1128
#5 0x08096ff0 in v8::internal::Builtin_Impl_HandleApiCall (args=...,
isolate=0x85240b8) at src/builtins.cc:1145
#6 0x08096fcf in v8::internal::Builtin_HandleApiCall (args=...,
isolate=0x85240b8) at src/builtins.cc:1144
@pH200
pH200 / gist:3852437
Created October 8, 2012 13:10
node async foreach
Array.prototype.forEachAsync = function (callback, complete) {
var raiseComplete/*: (arg?: bool) => void*/ = complete ? (function (arg) {
complete(arg);
}) : (function () { });
function next (self, index, length) { /* rec */
if (index === length) {
raiseComplete(true);
} else {
process.nextTick(function () {
@pH200
pH200 / hiredis.txt
Created October 12, 2012 14:19
Node redis benchmark, comparing hiredis and faster parsers. Running on Mac Mini.
Client count: 5, node version: 0.8.11, server version: 2.4.17, parser: hiredis
PING, 1/5 min/max/avg/p95: 0/ 4/ 0.08/ 1.00 1719ms total, 11634.67 ops/sec
PING, 50/5 min/max/avg/p95: 0/ 6/ 1.24/ 2.00 497ms total, 40241.45 ops/sec
PING, 200/5 min/max/avg/p95: 1/ 9/ 4.47/ 7.00 449ms total, 44543.43 ops/sec
PING, 20000/5 min/max/avg/p95: 49/ 440/ 250.05/ 397.65 457ms total, 43763.68 ops/sec
SET small str, 1/5 min/max/avg/p95: 0/ 3/ 0.09/ 1.00 1792ms total, 11160.71 ops/sec
SET small str, 50/5 min/max/avg/p95: 0/ 3/ 1.28/ 2.00 515ms total, 38834.95 ops/sec
SET small str, 200/5 min/max/avg/p95: 0/ 10/ 4.75/ 7.00 478ms total, 41841.00 ops/sec
SET small str, 20000/5 min/max/avg/p95: 50/ 653/ 355.20/ 596.65 674ms total, 29673.59 ops/sec
SET small buf, 1/5 min/max/avg/p95: 0/ 17/ 0.16/ 1.00 3355ms total, 5961.25 ops/sec
@pH200
pH200 / hiredis.txt
Created October 12, 2012 14:27
Node redis benchmark, comparing hiredis and faster parsers. Running on Ubuntu 12.04 on Windows 8 Hyper-V.
Client count: 5, node version: 0.8.11, server version: 2.4.17, parser: hiredis
PING, 1/5 min/max/avg/p95: 0/ 8/ 0.08/ 1.00 1620ms total, 12345.68 ops/sec
PING, 50/5 min/max/avg/p95: 0/ 7/ 1.75/ 3.00 703ms total, 28449.50 ops/sec
PING, 200/5 min/max/avg/p95: 1/ 14/ 6.65/ 11.00 667ms total, 29985.01 ops/sec
PING, 20000/5 min/max/avg/p95: 37/ 361/ 201.48/ 317.55 385ms total, 51948.05 ops/sec
SET small str, 1/5 min/max/avg/p95: 0/ 8/ 0.08/ 1.00 1760ms total, 11363.64 ops/sec
SET small str, 50/5 min/max/avg/p95: 0/ 6/ 1.96/ 3.00 786ms total, 25445.29 ops/sec
SET small str, 200/5 min/max/avg/p95: 0/ 14/ 6.85/ 11.00 687ms total, 29112.08 ops/sec
SET small str, 20000/5 min/max/avg/p95: 36/ 406/ 229.36/ 368.00 429ms total, 46620.05 ops/sec
SET small buf, 1/5 min/max/avg/p95: 0/ 7/ 0.12/ 1.00 2508ms total, 7974.48 ops/sec
.git
node_modules
@pH200
pH200 / post-receive
Created December 1, 2012 10:14
node website post-receive
#!/bin/bash
export GIT_WORK_TREE=/var/www/project
git checkout -f
pushd $GIT_WORK_TREE
npm install
NODE_ENV=production forever restart server.js
popd
@pH200
pH200 / nodeexe.c
Created January 10, 2013 02:36
C execute
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
if (argc > 1) {
char* arg = argv[1];
char cmdprefix[] = "node app.js -channel demo -url ";
char* cmd = (char*)malloc(
strlen(cmdprefix) + strlen(arg) + 1
/* \0 */