Skip to content

Instantly share code, notes, and snippets.

View shigeki's full-sized avatar

Shigeki Ohtsu shigeki

View GitHub Profile
@shigeki
shigeki / stdin-to-ws.js
Last active October 27, 2023 16:32
標準入力をWebSocketで送信するサンプルプログラム
var http = require('http');
var WebSocketServer = require('websocket').server;
var port = 8080;
process.stdin.resume();
process.stdin.setEncoding('utf8');
var index = '<!DOCTYPE html><html><head><title>stdin-to-ws</title></head>'
+ '<body><div id="msg"></div><script>'
+ 'var msg = document.getElementById("msg");'
+ 'var ws = new WebSocket("ws:localhost:8080/stdin-to-ws", "stdin-to-ws");'
@shigeki
shigeki / superagent-proxy-patch.diff
Created June 13, 2012 01:11
superagentをプロキシ対応するパッチ(SSL対応:要 tunnel モジュール) original from https://gist.github.com/2914780
--- node_modules/tower/node_modules/superagent/lib/node/index.js.org 2012-06-03 04:27:15.000000000 +0900
+++ node_modules/tower/node_modules/superagent/lib/node/index.js 2012-06-13 10:07:53.142584979 +0900
@@ -458,6 +458,29 @@
// initiate request
var mod = exports.protocols[url.protocol];
+ // use proxy
+ if(process.env.http_proxy) {
+ var proxy = parse(process.env.http_proxy);
+ if (url.protocol === 'http:') {
@shigeki
shigeki / main.c
Created October 9, 2012 02:20
Solving Consumer-Producer Problem with libuv condvar
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <assert.h>
#include "uv.h"
#define MAX_CONSUMERS 16
#define MAX_LOOPS 100
@shigeki
shigeki / app.js
Created October 13, 2011 08:42
Testing http.request with socket.io
var app = require('express').createServer(),io = require('socket.io').listen(app),http = require('http');
app.listen(8080);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
io.sockets.on('connection', function (socket) {
var options = {
host: 'www.google.com',
@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);
@shigeki
shigeki / 新しく発行された中間証明書
Created October 14, 2016 02:52
GlobalSign中間証明書のHPKP比較
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
04:00:00:00:00:01:31:89:c6:44:c9
Signature Algorithm: sha256WithRSAEncryption
Issuer: OU=GlobalSign Root CA - R3, O=GlobalSign, CN=GlobalSign
Validity
Not Before: Aug 2 10:00:00 2011 GMT
Not After : Aug 2 10:00:00 2022 GMT
@shigeki
shigeki / app.js
Last active December 28, 2015 18:09
Post Upload Control: File size check
var stream = require('stream');
var express = require('express');
var multiparty = require('multiparty');
var app = express();
var maxlimit = 2 * 1024 * 1024; // 2M byte
var postHandler = function(req, res, next) {
var length = 0;
var buflist = [];
var content_length = req.get('content-length');
@shigeki
shigeki / index.html
Created July 5, 2013 00:24
Ajax reconnect testing on quic vs spdy3
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<title>Ajax GET Test</title>
<script>
window.addEventListener('DOMContentLoaded', function() {
if (window.chrome.loadTimes().npnNegotiatedProtocol) {
var protocol = document.getElementById("protocol");
protocol.innerHTML = window.chrome.loadTimes().npnNegotiatedProtocol;
@shigeki
shigeki / main.c
Created April 10, 2013 02:36
uv_check() を利用した thread worker からのメッセージの出力 (worker 内の sleep 処理に依存しない方法)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <queue>
#include "uv.h"
using namespace std;
uv_loop_t *loop;
@shigeki
shigeki / main.c
Created April 8, 2013 23:54
worker 内で単一の async ハンドラを操作すると thread safe なのかチェックするテスト
#include <stdio.h>
#include <stdlib.h>
#include "uv.h"
uv_loop_t *loop;
uv_async_t async;
static int closed = 0;
static int async_called = 0;
void print_progress(uv_async_t *handle, int status /*UNUSED*/) {