Skip to content

Instantly share code, notes, and snippets.

View bhongy's full-sized avatar

Thanik Bhongbhibhat bhongy

View GitHub Profile
@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 / Wordpress: Do if the_content is not empty
Last active September 15, 2023 03:36
Wordpress: Check if the_content is empty / do something only when the_content is empty
<?php if ( get_the_content() ) { ?>
// do or output something
<?php } ?> // break php tag for HTML block
@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 / 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
.hide-text {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
/* Scott Kellum Technique - Reference: http://www.zeldman.com/2012/03/01/replacing-the-9999px-hack-new-image-replacement/ */
Use this for SEO/Accessability Friendly
@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;
}