Skip to content

Instantly share code, notes, and snippets.

View bhongy's full-sized avatar

Thanik Bhongbhibhat bhongy

View GitHub Profile
@bhongy
bhongy / es6-recursive-flatten.js
Created February 1, 2018 04:17
Simple Recursive Flatten Function in ES6
const flatten = xs => Array.isArray(xs)
? [].concat(...xs.map(flatten))
: xs;
#333333,#1E2320,#709080,#FFFFFF,#1E2320,#FFFFFF,#F0DFAF,#CC9393
// https://slackthemes.net/#/dark_zenburn
@bhongy
bhongy / unconditional-stack.js
Created July 12, 2018 03:00
Anti-if Stack Implementation
// idea from: https://www.youtube.com/watch?v=APUCMSPiNh4
class IllegalStateError extends Error {
constructor(...args) {
super(...args);
}
}
class Empty {
size() {
@bhongy
bhongy / node-fs-write-from-stdin.js
Last active January 4, 2022 12:07
[nodejs] A simple example how to write to a file from stdin using stream.
// from: http://book.mixu.net/node/ch9.html
'use strict';
const fs = require('fs');
const file = fs.createWriteStream('./output.txt');
process.stdin.pipe(file);
// stdin is paused by default
@bhongy
bhongy / node-proxy-server.js
Created August 7, 2018 17:33
[nodejs] A simple example how to write a proxy server piping server request to client request / client response back to server response.
// from: http://book.mixu.net/node/ch10.html
'use strict';
const http = require('http');
const url = require('url');
const server = http.createServer((sreq, sres) => {
const { pathname } = url.parse(sreq.url);
const opts = {
@bhongy
bhongy / create-tls.sh
Last active October 18, 2021 12:35
Creating TLS Certificate
openssl genrsa -out tls.key 4096
openssl req -new -x509 -key tls.key -out tls.cert -days 360 -subj