Skip to content

Instantly share code, notes, and snippets.

View whs's full-sized avatar

Manatsawin Hanmongkolchai whs

View GitHub Profile
@whs
whs / kubens.sh
Created September 25, 2017 01:34
kubens() {
kubectl config set-context $(kubectl config current-context) --namespace=$1
}
kubectx() {
kubectl config use-context $1
}
const dns = require('dns');
const util = require('util');
const lookup = util.promisify(dns.lookup);
let timeStart = new Date().getTime();
let times = 0;
let minTime = Infinity;
let maxTime = 0;
let error = 0;
#define _GNU_SOURCE
#define _DARWIN_C_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
@whs
whs / render2.js
Last active September 1, 2017 06:52
function renderSuccessPage(req, res, renderProps, store, next, statusCode = 200) {
setImmediate(() => {
AWSXRay.captureFunc('SSR', () => {
try {
res.header('Content-Type', 'text/html; charset=utf-8')
const content = {
html: ReactDOMServer.renderToString(<Root store={store} renderProps={renderProps} />),
store: store.getState().toJSON(),
head: Helmet.rewind(),
@whs
whs / startserver.js
Last active September 1, 2017 06:52
export default function startServer(handler) {
AWSXRay.captureHTTPsGlobal(require('http'))
const app = express()
app.use(AWSXRay.express.openSegment('React'))
// load other middlewares
// load handlers
app.use(AWSXRay.express.closeSegment())
@whs
whs / render.js
Last active September 1, 2017 06:51
function renderSuccessPage(req, res, renderProps, store, next, statusCode = 200) {
setImmediate(() => {
try {
res.header('Content-Type', 'text/html; charset=utf-8')
const content = {
html: ReactDOMServer.renderToString(<Root store={store} renderProps={renderProps} />),
store: store.getState().toJSON(),
head: Helmet.rewind(),
lang: getLanguage(req)
@whs
whs / dnstrace.js
Last active September 1, 2017 06:51
import dns from 'dns'
import AWSXRay from 'aws-xray-sdk'
function patchDnsLookup() {
const realLookup = dns.lookup
dns.lookup = (hostname, ...args) => {
if (hostname === process.env.AWS_XRAY_DAEMON_ADDRESS) {
return realLookup(hostname, ...args)
}
AWSXRay.captureAsyncFunc('DNS Lookup', (subsegment) => {
def split_icu(txt):
import PyICU
def is_tha(c):
return ord(c) >= 0x0E00 and ord(c) <= 0x0E7F
def merge(ans, tok):
if is_tha(tok[0]) or len(ans[:-1]) == 0 or is_tha(ans[-1][0]):
return ans + [tok]
else:
return ans[:-1] + [ans[-1] + tok]
icu_txt = PyICU.UnicodeString(txt)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Clickr</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="title" class="title">Clickr</div>
<div id="message">กดตรงไหนก็ได้เพิ่มเริ่มเล่น</div>