Skip to content

Instantly share code, notes, and snippets.

View piaoger's full-sized avatar

Piaoger piaoger

View GitHub Profile
@piaoger
piaoger / isProcessRunning.js
Created November 2, 2015 10:32
isProcessRunning.js
// a signal of 0 can be used to test for the existence of a process.
var exec = require('child_process').exec
var tryKill
function isRunning(pid, cb) {
var err = null,
result = null;
if (typeof pid !== 'number') {
err = "pid must be number"
} else {
@piaoger
piaoger / bootstrap-nodejs.sh
Last active November 13, 2016 13:21
bootstrap.sh
#!/bin/bash
###########################################################
# how to use
# curl -f -L https://gist.githubusercontent.com/piaoger/b6da9366ef28a065f152/raw/c06e66e7b4ff22fbb7295fd8a30899cd7d11936c/bootstrap.sh -O
# sh bootstrap.sh
###########################################################
echo off
@piaoger
piaoger / filehelper.scala
Created December 1, 2015 03:04
fileutils.scala
def deleteFile(dfile : File) : Unit = {
if(dfile.isDirectory){
val files = dfile.listFiles
if(files != null)
files.foreach{ f => deleteFile(f) }
}
dfile.delete
}
@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)
@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 / 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 / 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 / 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 / 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 / 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() {