Skip to content

Instantly share code, notes, and snippets.

func padding(str string) string {
return strings.Repeat("0", 8 - len(str)) + str
}
@Jxck
Jxck / README.md
Created December 16, 2012 09:16
libuv TCP server/client sample

how to compile

$ gcc -g -Wall -I /path/to/libuv/include /path/to/libuv/uv.a -framework CoreServices server.c -o server
$ gcc -g -Wall -I /path/to/libuv/include /path/to/libuv/uv.a -framework CoreServices client.c -o client
@Jxck
Jxck / next.js
Created October 17, 2012 16:01
非同期と next()
log = console.log.bind(console);
var assert = require('assert');
function test() {
var tests = Array.prototype.slice.call(arguments);
function next() {
if(!tests.length) return;
var args = Array.prototype.slice.call(arguments);
args.push(next);
var t = tests.shift();
@Jxck
Jxck / manifest.json
Created September 29, 2012 03:02
Chrome Socket API Server
{
"manifest_version": 2,
"name": "Chrome Socket API Server",
"description": "listen & accept for socket",
"version": "0.1",
"app": {
"background": {
"scripts": ["server.js"]
}
},
@Jxck
Jxck / index.js
Created August 25, 2012 08:12
implement calculator by js with BNF parser
DEBUG = false;
TEST = true;
noop = function() {};
log = assert = noop;
if (DEBUG) {
log = console.log.bind(console);
}
if (TEST) {
assert = function(a,b,m) { console.assert(a.toString() === b.toString(), m); };
@Jxck
Jxck / rest_and_websocket
Created August 20, 2012 10:30
REST と WebSocket
# REST と WebSocket
t_wada さんとちょっと話す機会があったので、ここまでに考えてたことを一旦まとめて見たいと思う。
REST については、「Web を支える技術」でお茶を濁さず、本家論文なども参照されたし。
## REST
REST はプロトコルでもアーキテクチャでもなく、アーキテクチャスタイルです。
そこにはいくつかの原則があり、最も重要な原則の一つにステートレス性があります。
@Jxck
Jxck / binparser.js
Created August 14, 2012 07:40
binary parse for spdy
var log = console.log.bind(console);
function choiceReadLength(length) {
if (length <= 8) return 8;
if (length <= 16) return 16;
if (length <= 32) return 32;
throw new Error('too large length');
}
function choiceReadMethod(readLength) {
@Jxck
Jxck / .gitignore
Created August 14, 2012 07:33
markdown rendering using Github API by ruby
readme.md
rendered.html
remain.txt
@Jxck
Jxck / server.js
Created July 24, 2012 17:09
WebSocket Server Sample Impliment
// Reference
// http://tools.ietf.org/html/rfc6455
// http://www.w3.org/TR/2011/WD-websockets-20110929/
// https://github.com/einaros/ws
// https://github.com/Worlize/WebSocket-Node
// http://ja.wikipedia.org/wiki/WebSocket
// http://www.slideshare.net/You_Kinjoh/javascript-websocket P.68
// http://d.hatena.ne.jp/gtk2k/20120203/1328274962
var log = console.log.bind(console);
@Jxck
Jxck / cleanup.hs
Created June 11, 2012 15:04
cleanup without .hs files
import System.Directory
import Data.List
findDotIndex :: String -> Int
findDotIndex a = case findIndex (=='.') a of
Just x -> x
otherwise -> 0
splitAtDot :: String -> (String, String)
splitAtDot x = splitAt (findDotIndex x) x