Skip to content

Instantly share code, notes, and snippets.

View mervintankw's full-sized avatar

Mervin Tan Kok Wei mervintankw

View GitHub Profile
@mervintankw
mervintankw / countries.json
Last active December 5, 2022 05:00
List of country name and code
[
{ "name": "Afghanistan", "code": "AF" },
{ "name": "Albania", "code": "AL" },
{ "name": "Algeria", "code": "DZ" },
{ "name": "American Samoa", "code": "AS" },
{ "name": "Andorra", "code": "AD" },
{ "name": "Angola", "code": "AO" },
{ "name": "Anguilla", "code": "AI" },
{ "name": "Antarctica", "code": "AQ" },
{ "name": "Antigua and Barbuda", "code": "AG" },

How to setup AWS lambda function to talk to the internet and VPC

I'm going to walk you through the steps for setting up a AWS Lambda to talk to the internet and a VPC. Let's dive in.

So it might be really unintuitive at first but lambda functions have three states.

  1. No VPC, where it can talk openly to the web, but can't talk to any of your AWS services.
  2. VPC, the default setting where the lambda function can talk to your AWS services but can't talk to the web.
  3. VPC with NAT, The best of both worlds, AWS services and web.
@mervintankw
mervintankw / WordPress Pods Simple Currency List
Last active May 30, 2021 06:22 — forked from AmrMekkawy/currency-dropdown-list.html
Currency list for WordPress pods simple list
USD|United States Dollars
EUR|Euro
GBP|United Kingdom Pounds
DZD|Algeria Dinars
ARP|Argentina Pesos
AUD|Australia Dollars
ATS|Austria Schillings
BSD|Bahamas Dollars
BBD|Barbados Dollars
BEF|Belgium Francs

Using Github with Two Factor Auth.

It's a fairly common complaint that after enabling github two factor authentication that command line utilities stop working. The underlying issue is command line utilities send your username and password with each request to github, using two factor authentication disables github from accepting just your username and password, so your command line utilities such as git appear to stop working. Github will still accept a personal access token instead of your password however.

Re-enabling your command line utilities (OSX)

@mervintankw
mervintankw / Xero Bank Transaction API Request
Created December 19, 2018 08:08
Xero API Bank Transaction API Request with incorrect validation on field Type
// Got the request and response messages via Xero API History on API calls.
// Request message
{"BankTransactions":[{"Type":"RECEIVE","Contact":{"ContactID":"fc6cb299-ea76-4bc9-881d-bbd71db9a60f","ContactStatus":"ACTIVE","Name":"First Thai Food","EmailAddress":"","BankAccountDetails":"","Addresses":[{"City":"","Region":"","PostalCode":"","Country":"","AddressType":"STREET"},{"City":"","Region":"","PostalCode":"","Country":"","AddressType":"POBOX"}],"Phones":[{"PhoneNumber":"","PhoneAreaCode":"","PhoneCountryCode":"","PhoneType":"DEFAULT"},{"PhoneNumber":"","PhoneAreaCode":"","PhoneCountryCode":"","PhoneType":"DDI"},{"PhoneNumber":"","PhoneAreaCode":"","PhoneCountryCode":"","PhoneType":"FAX"},{"PhoneNumber":"","PhoneAreaCode":"","PhoneCountryCode":"","PhoneType":"MOBILE"}],"DefaultCurrency":"SGD"},"LineItems":[{"Description":"Employee lunch","Quantity":1,"UnitAmount":32,"AccountCode":"461","TaxType":"INPUT","TaxAmount":2.09,"LineAmount":32}],"BankAccount":{"AccountID":"617b2867-3e64-45ed-a40b-e6dd72106def"},"
//Create a local writestream
var wstream = fs.createWriteStream(tempFile, { encoding: 'binary' });
//Data has been written successfully
wstream.on('finish', function() {
fs.readFile(tempFile, function (err, fsData) {
// trigger upload to S3 function
uploadToS3(req, {
s3Path: s3Path,
contentType: data.mime_type,
@mervintankw
mervintankw / centos-6-9-install-script.sh
Last active April 22, 2018 09:15
Install apache and node.js on Centos 6.9
#!/bin/bash
# edit variable values here
NODE_VERSION="8.4.0"
###### DO NOT EDIT FROM HERE ONWARDS ######
# update centos
sudo yum -y update
# install development tools
@mervintankw
mervintankw / country.sql
Last active October 16, 2017 04:25
sql script to create country table and insert country data
CREATE TABLE `country` (
`iso` char(3) NOT NULL DEFAULT '',
`name` varchar(80) NOT NULL DEFAULT '',
`nice_name` varchar(80) NOT NULL DEFAULT '',
`iso3` char(3) DEFAULT NULL,
`num_code` smallint(6) DEFAULT NULL,
`phone_code` int(5) NOT NULL,
`created_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`iso`)
@mervintankw
mervintankw / validateUEN.js
Last active July 5, 2023 06:43
validates that UEN (Unique Entity Number) number is valid based on https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
/**
* validates UEN of businesses in Singapore
* https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
* @param {string} uen
* @returns {boolean}
*/
function validateUEN (uen) {
var debug = true;
const entityTypeIndicator = [
'LP', 'LL', 'FC', 'PF', 'RF', 'MQ', 'MM', 'NB', 'CC', 'CS', 'MB', 'FM', 'GS', 'GA',