Skip to content

Instantly share code, notes, and snippets.

View ThinhPhan's full-sized avatar
🎯
Focusing

Thinh Phan ThinhPhan

🎯
Focusing
View GitHub Profile
@ThinhPhan
ThinhPhan / javascript-datetime-format.md
Created October 4, 2019 09:20
Javascript code snippets - Date Time Format to String

As toISOString() will only return current UTC time , not local time. We have to make a date by using .toString() function to get date in yyyy-MM-dd format like

let now = new Date(new Date().toString().split('GMT')[0]+' UTC').toISOString().split('T')[0];
// 2019-10-04

To get date and time into in yyyy-MM-ddTHH:mm:ss format

@ThinhPhan
ThinhPhan / generate-users.js
Created September 10, 2019 10:20
Collection of common Javascript bootstrap.
// Generate Users
const userIdBase = 'User_'
const regionIdBase = 'Region_'
const genderFemale = 'Female'
const genderMale = 'Male'
const genderNotSpecified = 'Not Specified'
const maxUserId = 100
const maxRegionId = 1000
let interval = 1000;
@ThinhPhan
ThinhPhan / Dockerfile
Created August 20, 2019 08:43
Nodejs with docker entrypoint init Posgres DB
FROM debian:stretch
...
COPY docker-entrypoint.sh /usr/local/bin/
RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["postgres"]
@ThinhPhan
ThinhPhan / centos-create-user.sh
Last active August 17, 2019 14:27
[WIP] Create user in initial setup for new CentOS VPS (read from Digital Ocean tutorials)
#!/bin/sh
# Print out current command and exit as soon as any line in the script fails
set -ex
set -o errexit
set -o pipefail
USER=$1
# Create user
@ThinhPhan
ThinhPhan / docker-expose-vs-ports.md
Created August 16, 2019 16:32
Docker expose vs ports

ports

  1. Activates the container to listen for specified port(s) from the world outside of the docker(can be same host machine or a different machine) AND also accessible world inside docker.
  2. More than one port can be specified (that's is why ports not port)

docker port

expose

  1. Activates container to listen for a specific port only from the world inside of docker AND not accessible world outside of the docker.
@ThinhPhan
ThinhPhan / Dockerfile
Last active November 10, 2024 12:11
Docker PostgreSQL - initial scripts - create user, create multiple databases.
FROM postgres:9.15-alpine
COPY create-multiple-postgresql-databases.sh /docker-entrypoint-initdb.d/
@ThinhPhan
ThinhPhan / chunk.sh
Created August 8, 2019 04:00
chunk of unused command
this_dir=$(dirname -- "$0")
this_dir=$(realpath "${this_dir}")
this_name=$(basename -- "$0")
top_dir="${this_dir}/../../.."
project="node-${module_name}"
arch="aarch64" # AKA: arm64, arm64v8
architecture=$(basename "${this_dir}")
name="${project}-${architecture}"
dir="/usr/local/opt/${project}/"
@ThinhPhan
ThinhPhan / command.sh
Created July 26, 2019 07:47
GCP Compute Engine instance install Docker scripts
# Type the following commands to run the install script.
chmod +x install.sh
sudo ./install.sh
# In your user folder, create the following directories as your user.
mkdir ~/tmp
mkdir ~/log
mkdir ~/data
mkdir ~/scripts
@ThinhPhan
ThinhPhan / waveshare-7inch-config-1024x600(C).md
Last active May 19, 2019 16:26
7 inch LCD Waveshare Configurations

Configuration for LCD 7 inch WaveShare on Raspberry Pi 3

Copy belows configs to boot/config.txt (mount SDCard to your PC to see this partition)

# REQUIRED
# set current over USB to 1.2A
max_usb_current=1
hdmi_group=2
hdmi_drive=1
@ThinhPhan
ThinhPhan / docker-hack-commands.md
Last active May 19, 2019 17:42
Docker Hack Commands for every work day.

Docker Life Hack Scritps


Docker Status: Images, Containers

echo -e "Images"; docker images; echo -e "Containers"; docker ps --all

"docker cleanup": Clean up volumes with status ‘exited’ and ‘dangling’ images