Skip to content

Instantly share code, notes, and snippets.

@leongkui
leongkui / gitbranch.sh
Last active December 21, 2015 22:19
simple bash shell prompt modification to add git branch information to the shell prompt
#### shell prompt color
export COLOR_NC='\e[0m' # No Color
export COLOR_WHITE='\e[1;37m'
export COLOR_BLACK='\e[0;30m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
@leongkui
leongkui / startvm.sh
Last active June 16, 2020 16:55
azure start vm
#! /bin/bash
## This script will read in configuration from azure_config.yml and spin up a VM instance
## it assumes you has a base image and data disk
## Suggestion on how to create a reusable image and use a persistent data disk
## 1. launch an instance with your selected image/OS, and attach a data disk to it
## 2. once instance is up and running, configure the OS and install the necessary libraries/packages
## 3. format the data disk, mount the disk, add the disk mounting information to fstab
## 4. tips: any folder (like $HOME/anaconda) that need frequent update, put it in data disk and symlink to your home directory.
## 5. once the instance is updated, shutdown the instance, and detach the data disk from the instance.
@leongkui
leongkui / delvm.sh
Created July 11, 2019 04:10
azure delete vm
#!/bin/bash
function parse_yaml {
config_file="azure_config.yml"
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $config_file |
awk -F$fs '{
@leongkui
leongkui / azure_config.yml
Last active June 16, 2020 16:54
script yml file sample
vm:
name: ""
resource:
group: ""
image:
name: ""
instance:
size: ""
ssh:
pubkey: ""
@leongkui
leongkui / aws_presigned_s3.go
Last active August 7, 2021 00:19
Generate AWS S3 Pre-signed URL in Golang
// From https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/s3-example-presigned-urls.html
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"log"
"time"
@leongkui
leongkui / customType.go
Created August 21, 2021 05:00
[Golang Custom Type Value] #golang
package main
import (
"fmt"
)
type LeaveType string
const(
AnnualLeave LeaveType = "AnnualLeave"
@leongkui
leongkui / react-toastify.jsx
Created August 21, 2021 05:04
[react-toastify] react-toastify example #react #react-toastify
import React from 'react';
import { toast } from 'react-toastify';
toast('🦄 Wow so easy!', {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
@leongkui
leongkui / test.sh
Created August 24, 2021 12:30
[Golang go test specific test case and file] #golang #unittest
go test -run "^NameOfTest$"
go test -v foo_test.go foo.go
@leongkui
leongkui / go-cyclo
Created September 10, 2021 00:01
[Golang Cyclomatic Complexities] #golang
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
gocyclo -ignore "_test.go" .
@leongkui
leongkui / react-hook-state-update.js
Created September 28, 2021 02:59
[react hook state update] #react #reacthook
// Through Input
const [state, setState] = useState({ fName: "", lName: "" });
const handleChange = e => {
const { name, value } = e.target;
setState(prevState => ({
...prevState,
[name]: value
}));
};