Skip to content

Instantly share code, notes, and snippets.

View alextanhongpin's full-sized avatar

Alex Tan Hong Pin alextanhongpin

View GitHub Profile
@alextanhongpin
alextanhongpin / readme.js
Created July 23, 2017 20:51
Simple object to README.md
const data = {
hello: 'world',
someInteger: 1,
aFloat: 1.40,
isTrue: false,
items: [1, 2, 3]
}
function toReadme(data) {
@alextanhongpin
alextanhongpin / instructions.md
Last active June 13, 2023 16:48
Setting up locale on alpine:3.6 docker image

Locale

When using the alpine docker image, the command locale -a or locale-gen does not exist. You might need them to install different locales in your docker image to allow your applications to support multilingual. Most common issue is when dealing with database inputs (MySQL), whereby the text will be displayed as garbage characters if you do not have the right locale installed.

FROM alpine:3.6

# ---not shown here---
@alextanhongpin
alextanhongpin / index.js
Created July 12, 2017 05:51
JSON object to Markdown table
const data = require('./data/jobs.json')
const fs = require('fs')
const jobs = data.jobs.recordsets[0]
const d = jobs.reduce((obj, job) => {
Object.keys(job).map((j) => {
if (!obj[j]) {
obj[j] = job[j]
}
})
@alextanhongpin
alextanhongpin / nginxoptimization.config
Created February 25, 2018 12:17 — forked from wearhere/nginxoptimization.config
Optimized nginx configuration for an AWS Elastic Beanstalk environment using an Application Load Balancer.
files:
"/opt/elasticbeanstalk/#etc#nginx#optimized-nginx.conf":
mode: "000644"
owner: root
group: root
encoding: plain
content: |
# Elastic Beanstalk Managed
# Elastic Beanstalk managed configuration file
@alextanhongpin
alextanhongpin / time.go
Last active July 3, 2022 20:08
JavaScript timestamp to golang time.Time
package main
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"
)
@alextanhongpin
alextanhongpin / nginx.conf
Created September 20, 2017 08:24
The default nginx config for AWS Elasticbeanstalk
# Elastic Beanstalk Managed
# Elastic Beanstalk managed configuration file
# Some configuration of nginx can be by placing files in /etc/nginx/conf.d
# using Configuration Files.
# http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/customize-containers.html
#
# Modifications of nginx.conf can be performed using container_commands to modify the staged version
# located in /tmp/deployment/config/etc#nginx#nginx.conf
@alextanhongpin
alextanhongpin / compress.js
Last active October 9, 2021 16:45
Sample usage for compress.js library.
const compress = new Compress()
const upload = document.getElementById('upload')
upload.addEventListener('change', (evt) => {
const files = [...evt.target.files]
compress.compress(files, {
size: 4, // the max size in MB, defaults to 2MB
quality: 0.75, // the quality of the image, max is 1,
maxWidth: 1920, // the max width of the output image, defaults to 1920px
@alextanhongpin
alextanhongpin / golang-pipe-to-graphviz.go
Last active April 13, 2020 18:17
Sample golang code that pipes the dynamic .dot file data to external graphviz process to write the .png file
// -- IMPORTSS NOT SHOWN
path, _ := exec.LookPath("dot")
cmd := exec.Command(path, fmt.Sprintf("-T%s", "png"))
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
}
go func() {
defer stdin.Close()
// Writes the data to stdin.
@alextanhongpin
alextanhongpin / mysql-parser.go
Created April 13, 2020 18:17
Sample usage of mysql parser - could be useful to create ERD diagrams from database schema
package main
import (
"fmt"
"log"
"github.com/pingcap/parser"
"github.com/pingcap/parser/ast"
_ "github.com/pingcap/tidb/types/parser_driver"
)
@alextanhongpin
alextanhongpin / package.json
Created January 11, 2018 08:08
How to "host" your npm modules on Github and refer it.
{
"name": "test-github",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "alextanhongpin <alextan@seekasia.com>",
"description": "",