Skip to content

Instantly share code, notes, and snippets.

View bhongy's full-sized avatar

Thanik Bhongbhibhat bhongy

View GitHub Profile
@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
@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 / 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 / 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() {
#333333,#1E2320,#709080,#FFFFFF,#1E2320,#FFFFFF,#F0DFAF,#CC9393
// https://slackthemes.net/#/dark_zenburn
@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;
@bhongy
bhongy / vscode__settings.json__flow
Created January 5, 2018 17:42
VSCode Workspace Settings for Flow Projects
{
// from: https://gist.github.com/bhongy/3817b9b8fad85096039df78e339deae4
/*
Suggested VSCode Extensions
- mgmcdermott.vscode-language-babel
- dbaeumer.vscode-eslint
- flowtype.flow-for-vscode
- esbenp.prettier-vscode
.wrapper {
height: 100vh;
width: 100vw;
background-color: green;
}
@bhongy
bhongy / partial-function-application.js
Last active August 29, 2015 14:03
JS: Partial Function Application
function partial(func /*, 0..n args */) {
var args = Array.prototype.slice.call(arguments, 1); // save all additional arguments to args (except index 0: func)
return function() {
var allArguments = args.concat(Array.prototype.slice.call(arguments)); // then add arguments from the original function declaration
return func.apply(this, allArguments);
};
}
// See: http://stackoverflow.com/questions/373157/how-can-i-pass-a-reference-to-a-function-with-parameters
@bhongy
bhongy / .bash_profile
Last active August 29, 2015 13:58
.bash_profile
source ~/.profile
# === SSH Agent from Atlassian - https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git
SSH_ENV=$HOME/.ssh/environment
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent