Skip to content

Instantly share code, notes, and snippets.

View piaoger's full-sized avatar

Piaoger piaoger

View GitHub Profile
@piaoger
piaoger / gen-ghpages.sh
Last active September 28, 2016 08:51
generate gh-pages
gitconfig() {
git config user.name "piaoger"
git config user.email "piaoger@gmail.com"
}
rev=$(git rev-parse --short HEAD)
depot=https://github.com/piaoger/playground-rust.git
@piaoger
piaoger / get-public-ipv4.sh
Created September 12, 2016 06:20
get-public-ipv4.sh
# get public ipv4
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
# http://stackoverflow.com/questions/14594151/methods-to-detect-public-ip-address-in-bash
AMI_ID=$(curl --connect-timeout 5 "http://169.254.169.254/latest/meta-data/ami-id")
if [[ $AMI_ID == ami-* ]] ;
then
IPV4=$(curl --connect-timeout 5 "http://169.254.169.254/latest/meta-data/public-ipv4")
else
@piaoger
piaoger / resource-usage.sh
Last active October 26, 2016 08:48
query cpu/ram/hdd usage
#!/bin/bash
# from http://unix.stackexchange.com/questions/69167/bash-script-that-print-cpu-usage-diskusage-ram-usage
FREE_DATA=`free -m | grep Mem`
CURRENT=`echo $FREE_DATA | cut -f3 -d' '`
TOTAL=`echo $FREE_DATA | cut -f2 -d' '`
echo CPU: `top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'`%
echo RAM: $(echo "scale = 2; $CURRENT/$TOTAL*100" | bc)%
@piaoger
piaoger / md5checksum.sh
Last active August 16, 2016 06:33
md5 checksum
#md5 generation
# linux: md5sum file >md5file
# mac: md5 -r file >md5file
#Md5 comparison
# linux: md5sum -c md5file
# mac: manual check ?
function find_md5sum() {
@piaoger
piaoger / listfiledirs.sh
Last active August 16, 2016 03:19
list *.js files and child directories
# list *.js files in directory
for file in ./*.js
do
if [[ -f $file ]]; then
echo $file
fi
done
# list child dirs except hidden ones
@piaoger
piaoger / zipping.sh
Last active August 11, 2016 23:35
zippint time test
# for compress time and size,
# it seems that we can get the balance with "-1", i.e compress faster
ZIP_FOLDER="Utils./Users/piaoger/Box/*"
ZIP_OUTPUT=output.zip
FROM_TIME1=$(date)
zip -r output.zip Utils./Users/piaoger/Box/*
@piaoger
piaoger / clearcache.sh
Created June 23, 2016 08:30
clear cached memory in Linux
#!/bin/sh
# https://www.blackmoreops.com/2014/10/28/delete-clean-cache-to-free-up-memory-on-your-slow-linux-server-vps/
sync
sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
@piaoger
piaoger / reverseproxy.go
Created May 13, 2016 06:25
reverseproxy.go
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
type handle struct {
@piaoger
piaoger / formatDate.js
Last active January 25, 2016 05:53
format date utc
// borrowed from http://www.cnblogs.com/duanhuajian/p/4485106.html
// change: use utc time instead
function formatDate (date, fmt) {
var o = {
"M+" : date.getUTCMonth()+1,
"d+" : date.getUTCDate(),
"h+" : date.getUTCHours()%12 == 0 ? 12 : date.getUTCHours()%12,
"H+" : date.getUTCHours(),
"m+" : date.getUTCMinutes(),
"s+" : date.getUTCSeconds(),
@piaoger
piaoger / script_location.sh
Created January 12, 2016 09:23
get location of bash script
this_script=$(cd ${0%/*} && echo $PWD/${0##*/})
this_dir=$(cd ${0%/*} && echo $PWD)