Skip to content

Instantly share code, notes, and snippets.

View wingkwong's full-sized avatar
👁️‍🗨️
Focusing

աӄա wingkwong

👁️‍🗨️
Focusing
View GitHub Profile
@wingkwong
wingkwong / gist:a8ece2db9d255718deb9b366457f60ba
Created May 24, 2018 12:54
Import a CSV file to SQLite3
sqlite3 db.sqlite3
sqlite> .mode csv
sqlite> .separator ","
sqlite> .import table1.csv table1
sqlite> .import table2.csv table2
sqlite> .import table3.csv table3
sqlite> .import table4.csv table4
sqlite> .exit
@wingkwong
wingkwong / Makefile
Last active November 18, 2019 14:02
Relocate golang boilerplate packages using Makefile
GITHUB := "github.com"
PROJECTNAME := $(shell basename "$(PWD)")
PACKAGENAME := $(GITHUB)/$(shell basename "$(shell dirname "$(PWD)")")/$(PROJECTNAME)
GOBASE := $(shell pwd)
.PHONY .SILENT: relocate
## relocate: Relocate packages
relocate:
# Example: make relocate TARGET=github.com/wingkwong/myproject
@test ${TARGET} || ( echo ">> TARGET is not set. Use: make relocate TARGET=<target>"; exit 1 )
@wingkwong
wingkwong / Taskfile.yml
Last active December 6, 2019 15:12
Relocate golang boilerplate packages using Taskfile
version: '2'
tasks:
relocate:
cmds:
- echo " *** Relocating packages to {{.TARGET_PATH}} ***"
- task: replace-string
vars: {
SOURCE_STR: "{{.PACKAGE_NAME}}",
TARGET_STG: "{{.TARGET_PATH}}"
@wingkwong
wingkwong / remove-duplicate-records.py
Created November 17, 2019 13:34
Removing duplicate records in a CSV file using Pandas
import pandas as pd
d = pd.read_csv('CSV_FILE.csv', keep_default_na = False)
d.drop_duplicates(subset = ['COMPOSITE_KEY1', 'COMPOSITE_KEY2', 'COMPOSITE_KEY3', 'COMPOSITE_KEY4', 'COMPOSITE_KEY5', 'COMPOSITE_KEY6', 'COMPOSITE_KEY7', 'COMPOSITE_KEY8', 'COMPOSITE_KEY9', 'COMPOSITE_KEY10'], inplace = True, keep = 'first')
d.to_csv('CSV_FILE_PROCESSED.csv', index = False)
@wingkwong
wingkwong / install-gnu-parallel.sh
Created November 22, 2019 08:54
Installing GNU Parallel
#!/bin/bash
sudo tar xjf parallel-latest.tar.bz2
cd parallel-yyyymmdd
sudo ./configure && make
sudo make install
# in case you need to relink the executable file
sudo ln -s /usr/bin/parallel /usr/local/bin/parallel
@wingkwong
wingkwong / .htaccess
Created November 27, 2019 03:01
Redirecting from non-www to www
RewriteEngine on
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
@wingkwong
wingkwong / query-check-tablespace-oracle.sql
Created December 4, 2019 10:54
Query to check tablespace size for Oracle Database
select df.tablespace_name "Tablespace",
totalusedspace "Used MB",
(df.totalspace - tu.totalusedspace) "Free MB",
df.totalspace "Total MB",
round(100 * ( (df.totalspace - tu.totalusedspace)/ df.totalspace))
"Pct. Free"
from
(select tablespace_name,
round(sum(bytes) / 1048576) TotalSpace
from dba_data_files
@wingkwong
wingkwong / query-locked-objects.sql
Created December 4, 2019 10:58
Query locked objects in Oracle Database
select
c.owner,
c.object_name,
c.object_type,
b.sid,
b.serial#,
b.status,
b.osuser,
b.machine
from
@wingkwong
wingkwong / kubernetes-application-bible-for-developers.md
Last active May 24, 2022 17:18
This is a bible for certified Kubernetes application developers. It covers the features and how to design and build applications to run on Kubernetes.

Updates on 22 Feb 2020

  • Updated version to 1.17.3-00 for kubelet, kubeadm and kubectl
  • Updated kube-flannel as extensions/v1beta1 was removed

Creating a cluster

# Setup Docker & Kubernetes repositories
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@wingkwong
wingkwong / generate-s3-presigned-url.go
Last active December 27, 2019 07:49
A simple function to generate s3 presigned url in Go
func GetS3PresignedUrl(bucket string, key string, region string, expiration time.Duration) string {
// Initialize a session in the target region that the SDK will use to load
// credentials from the shared credentials file ~/.aws/credentials.
sess, err := session.NewSession(&aws.Config{
Region: aws.String(region)},
)
// Create S3 service client
svc := s3.New(sess)