Skip to content

Instantly share code, notes, and snippets.

View LightSpeedC's full-sized avatar

Kazuaki Nishizawa LightSpeedC

View GitHub Profile
@LightSpeedC
LightSpeedC / http-proxy-server-in-10-lines.js
Last active December 14, 2018 23:47
Node.jsによる必要最小限のhttpサーバとhttpsサーバとhttp proxyサーバ ref: https://qiita.com/LightSpeedC/items/3cae342fd7e79a21869f
const http = require('http'), url = require('url');
http.createServer((cliReq, cliRes) => {
const x = url.parse(cliReq.url);
const opt = {host: x.hostname, port: x.port || 80, path: x.path,
method: cliReq.method, headers: cliReq.headers};
const svrReq = http.request(opt, svrRes => {
cliRes.writeHead(svrRes.statusCode, svrRes.headers);
svrRes.pipe(cliRes); });
cliReq.pipe(svrReq);
}).listen(8080);
@LightSpeedC
LightSpeedC / http-proxy-plus-stealth-mode.js
Last active May 11, 2019 12:30
Node.js で https をサポートする http proxy サーバを 80行で書いた ref: https://qiita.com/LightSpeedC/items/5c1edc2c974206c743f4
if ('proxy-connection' in cliReq.headers) {
cliReq.headers['connection'] = cliReq.headers['proxy-connection'];
delete cliReq.headers['proxy-connection'];
delete cliReq.headers['cache-control'];
}
@LightSpeedC
LightSpeedC / aa-chan1.js
Last active October 26, 2017 22:14
[JavaScript] 非同期処理のコールバック地獄から抜け出す方法 ref: http://qiita.com/LightSpeedC/items/7980a6e790d6cb2d6dad
'use strict';
var aa = require('aa');
var Channel = aa.Channel;
var get = require('./get');
aa(function*() {
var ch = Channel();
get('a.txt', ch);
var target;
target: for (;;) switch (target) {
case undefined:
console.log('init');
case 'start':
console.log('start');
@LightSpeedC
LightSpeedC / counter-min.html
Last active December 18, 2015 05:12
Mithril.js 試してみた(1) todo アプリを作り始める所まで ref: http://qiita.com/LightSpeedC/items/a2c967928f9cc13e0ebc
<!DOCTYPE html>
<meta charset="UTF-8">
<title>counter minimum - Mithril.js</title>
<script src="mithril.min.js"></script>
<!--[if IE]><script src="es5-shim.min.js"></script><![endif]-->
<body></body>
<script>
@LightSpeedC
LightSpeedC / links.html
Last active September 5, 2015 08:23
Mithril.js 試してみた(2) サーバーからデータを取得する m.request() ref: http://qiita.com/LightSpeedC/items/f533f048e01ac19a06ec
@LightSpeedC
LightSpeedC / debug.html
Last active September 5, 2015 08:22
Mithril.js 試してみた(3) console.logの様に画面に表示してみる ref: http://qiita.com/LightSpeedC/items/23dcecfa22b89dc7c165
<!DOCTYPE html>
<meta charset="UTF-8">
<title>debug - Mithril.js</title>
<script src="mithril.min.js"></script>
<!--[if IE]><script src="es5-shim.min.js"></script><![endif]-->
<body>
<div id="$debugElement"></div>
</body>
@LightSpeedC
LightSpeedC / todo-app.html
Last active November 23, 2015 07:59
Mithril.js 試してみた(4) todo アプリのフロント側まで ref: http://qiita.com/LightSpeedC/items/c3026847dc5809d2a7a9
<!DOCTYPE html>
<meta charset="UTF-8">
<title>ToDo App - Mithril.js</title>
<script src="mithril.min.js"></script>
<!--[if IE]><script src="es5-shim.min.js"></script><![endif]-->
<body>
<table>
<tr valign="top">
@LightSpeedC
LightSpeedC / excel-app.html
Last active September 7, 2015 11:57
Mithril.js 試してみた(5) Excelの様な表計算アプリを3時間で作る m.component() ref: http://qiita.com/LightSpeedC/items/c19677822f896adc43d9
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Excel example - Mithril.js</title>
<script src="/js/mithril.min.js"></script>
<!--[if IE]><script src="/js/es5-shim.min.js"></script><![endif]-->
<body>
<div id="$excelElement"></div>
</body>
@LightSpeedC
LightSpeedC / es-next-async-await-ex.js
Last active October 25, 2017 12:46
ES2017 async/await + Promise で解決できる事、とES2015(ES6) generators (yield) + Promise + npm aa (async-await) で解決できる事 ref: http://qiita.com/LightSpeedC/items/95e3db59276e5d1d1a0d
'use strict';
require('babel-polyfill'); // おまじない
//require('regenerator').runtime();
console.log('main: start');
main().then(function (val) {
console.log('main: finish:', val);
});