This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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)% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gitconfig() { | |
| git config user.name "piaoger" | |
| git config user.email "[email protected]" | |
| } | |
| rev=$(git rev-parse --short HEAD) | |
| depot=https://github.com/piaoger/playground-rust.git |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # open file manager of current directory in the terminal | |
| # http://askubuntu.com/questions/31069/how-to-open-a-file-manager-of-the-current-directory-in-the-terminal | |
| xdg-open . | |
| # mac | |
| # open . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://play.rust-lang.org/ | |
| // https://is.gd/VHQlvO | |
| // Line comments which go to the end of the line. | |
| /* Block comments which go to the closing delimiter. */ | |
| fn main () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // http://rustbyexample.com/scope/borrow.html | |
| // https://is.gd/E0jeLL | |
| fn simple_borrow() { | |
| let mut v = vec!["A"]; | |
| { | |
| // immutable borrow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://en.wikipedia.org/wiki/Dangling_pointer | |
| void f() { | |
| int *x = malloc(sizeof(int)); | |
| *x = 1024; | |
| printf("%d\n", *x); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # raii (c++) | |
| before: | |
| void UseFile(char const* fn) | |
| { | |
| FILE* f = fopen(fn, "r"); // 获取资源 | |
| // 使用资源 | |
| try { | |
| if (!g()) { fclose(f); return; } | |
| // ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # I want compress yesterday's log, so I have to learn how to get yesterday with bash | |
| # yesterday=$(date --date='-1 day' +%Y-%m-%d) | |
| # today=$(date +%Y-%m-%d) | |
| # yesterday_log=service_log_${yesterday}.log | |
| # zip ${yesterday_log}.zip ${yesterday_log} | |
| ## today | |
| today=$(date +%Y-%m-%d) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| appname=python | |
| getpids() { | |
| local pids=$(ps -ef | grep $1 | grep -v grep| awk '{print $2}') | |
| echo $pids | |
| } | |
| pids=`getpids $appname` |