Skip to content

Instantly share code, notes, and snippets.

View alextanhongpin's full-sized avatar
😹
Focusing

Alex Tan Hong Pin alextanhongpin

😹
Focusing
View GitHub Profile
@alextanhongpin
alextanhongpin / main.py
Created September 7, 2017 09:48
CSV to JSON converter
import csv
import json
with open('data/ref_language.csv') as csvfile:
reader = csv.DictReader(csvfile)
fieldnames = reader.fieldnames
output = []
for row in reader:
j = {}
for i, _ in enumerate(fieldnames):
@alextanhongpin
alextanhongpin / README.md
Created September 4, 2017 13:57
Include Visual Studio Code in PATH

export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

@alextanhongpin
alextanhongpin / index.js
Created September 3, 2017 14:42
Sample fetch post for web
window.fetch('/v1/webpush', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
}).then((body) => {
return body.json()
})
@alextanhongpin
alextanhongpin / README.md
Created August 29, 2017 05:49
A simple guide on how to write technical articles

Objective

What do you want to achieve from this example?

Audience

Who is the target audience that is most likely interested with this example? Beginners/intermediate? Frontend/backend/devops/qas?

References

@alextanhongpin
alextanhongpin / precise-time
Created August 22, 2017 03:36
Precise time calculation in nodejs
var start = new Date();
var hrstart = process.hrtime();
setTimeout(function (argument) {
// execution time simulated with setTimeout function
var end = new Date() - start,
hrend = process.hrtime(hrstart);
console.info("Execution time: %dms", end);
console.info("Execution time (hr): %ds %dms", hrend[0], hrend[1]/1000000);
@alextanhongpin
alextanhongpin / README.md
Last active August 16, 2017 07:08
Sample netstat.conf

In order to scrape golang data, it needs to be enabled in the python.conf.d:

// python.conf.d
go_expvar: yes

You also need to import expvar in the golang file

@alextanhongpin
alextanhongpin / concurrent.py
Created July 26, 2017 09:13
Sample concurrency in python
import math
from concurrent.futures import ThreadPoolExecutor, wait, as_completed
from time import time
x = []
for i in range(105):
x.append(i)
@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 / localStorage.html
Created July 12, 2017 12:39 — forked from sagar-ganatra/localStorage.html
Local storage event listeners
<!DOCTYPE html>
<html>
<head>
<title>localStorage Test</title>
<script type="text/javascript" >
var count = 0;
var storageHandler = function () {
alert('storage event 1');
};
@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]
}
})