Skip to content

Instantly share code, notes, and snippets.

View toshirot's full-sized avatar

Toshiro Takahashi toshirot

View GitHub Profile
@shigeki
shigeki / large_file.js
Created November 26, 2012 13:47
大容量ファイルのダウンロードを提供するサンプルコード
var fs = require('fs');
var http = require('http');
var util = require('util');
var file = './1G.file';
var stat = fs.statSync(file);
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'octet-stream/binary',
'Content-Length': stat.size
});
var rStream = fs.createReadStream(file);
@toshirot
toshirot / websocket-protocol-fallback.js
Created December 4, 2011 00:09 — forked from nicokaiser/websocket-protocol-fallback.js
WebSocket library fallback for old protocol clients
// This code is fallback for https://github.com/Worlize/WebSocket-Node
// add the broadcast to https://gist.github.com/1219165
// 2011.11.30 tato@http://www.facebook.com/javascripting
// Example of how to fallback to alternative websocket library for old protocol clients
// see https://gist.github.com/1148686
var http = require('http'),
WebSocketRequest = require('websocket').request,
@jcxplorer
jcxplorer / uuid.js
Created February 12, 2011 16:58
UUID v4 generator in JavaScript (RFC4122 compliant)
function uuid() {
var uuid = "", i, random;
for (i = 0; i < 32; i++) {
random = Math.random() * 16 | 0;
if (i == 8 || i == 12 || i == 16 || i == 20) {
uuid += "-"
}
uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16);
}