Skip to content

Instantly share code, notes, and snippets.

View gwsu2008's full-sized avatar

Guang gwsu2008

View GitHub Profile
@gwsu2008
gwsu2008 / jenkins-git-env
Created May 21, 2019 20:23
jenkins-git-env
Environment variables
The git plugin sets several environment variables you can use in your scripts:
GIT_COMMIT - SHA of the current
GIT_BRANCH - Name of the remote repository (defaults to origin), followed by name of the branch currently being used, e.g. "origin/master" or "origin/foo"
GIT_LOCAL_BRANCH - Name of the branch on Jenkins. When the "checkout to specific local branch" behavior is configured, the variable is published. If the behavior is configured as null or **, the property will contain the resulting local branch name sans the remote name.
GIT_PREVIOUS_COMMIT - SHA of the previous built commit from the same branch (not set on first build on a branch)
GIT_PREVIOUS_SUCCESSFUL_COMMIT - SHA of the previous successfully built commit from the same branch (not set on first build on a branch)
GIT_URL - Repository remote URL
GIT_URL_N - Repository remote URLs when there are more than 1 remotes, e.g. GIT_URL_1, GIT_URL_2
@gwsu2008
gwsu2008 / bash-set-cmd.sh
Last active January 3, 2020 06:16
bash set pipe status
set -e causes the shell to exit whenever a pipeline, list, or compound command exits with non-zero status;
set -u causes the shell to exit whenever it attempts to expand a parameter which isn't defined.
set -o pipefail If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or
zero if all commands in the pipeline exit successfully. This option is disabled by default.
@gwsu2008
gwsu2008 / build-pandas
Last active May 1, 2019 22:00
build-pandas
sudo yum groupinstall "Development Tools"
sudo yum install make glibc-devel gcc patch
sudo yum install gcc-c++
sudo yum install openssl-devel
update-alternatives --config gcc ( choose gcc48)
/usr/local/bin/virtualenv test-env
source test-env/bin/activate
@gwsu2008
gwsu2008 / xcodebuild-cli
Created April 17, 2019 19:10
xcodebuild-cli
xcodebuild -list -workspace BaseNetworkConcept.xcworkspace/ -json
@gwsu2008
gwsu2008 / Linux-Time-Stamp
Created April 10, 2019 20:28
Linux-Time-Stamp
Most common Bash date commands for timestamping
From time to time I get asked how to use the date command to generate a timestamp. Here is an idiot-friendly script you can post for reference in your team’s bin/ if you get interrupted about timestamp questions or have an aversion to typing phrases like “man date” (with or without a space).
All but the first one and last three produce filename-friendly strings.
A big thanks to the following folks for pointing out mistakes and suggesting useful format inclusions:
2013-05: Rich for the reminder to include UTC and timezoned stamps.
2017-10: “Hamilton and Meg” (haha!) for pointing out I had my 4 year example formats messed up and for prodding me to include a 2-year example.
2018-01: Autumn Gray for suggesting that I add examples of including short and long days of the week.
@gwsu2008
gwsu2008 / jenkins-groovy-console-script-stop-job
Created April 3, 2019 23:27
jenkins-groovy-console-script-stop
Thread.getAllStackTraces().keySet().each() {
if (it.name.contains('JOB_NAME')) {
println "Stopping $it.name"
it.stop()
}
}
@gwsu2008
gwsu2008 / python-read-s3-file.py
Last active January 3, 2020 06:18
Python read S3 file
import json
import boto3
def lambda_handler(event, context):
client = boto3.client('s3')
res = client.get_object(Bucket='szabgab', Key='abc.json')
content = res["Body"].read()
data = json.loads(content)
@gwsu2008
gwsu2008 / AWS EBS warm up
Created February 5, 2019 23:31
AWS EBS warm up
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-initialize.html
sudo dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
swapon -s
/etc/fstab
/swapfile swap swap sw 0 0
@gwsu2008
gwsu2008 / ebs_warming.sh
Created December 25, 2018 06:11
ebs_warming.sh
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: sudo $0 /dev/sdh1"
exit 1;
fi
dd if=$1 of=/dev/null & pid=$!
while true; do
ps -p$pid --no-heading || break;
echo "-- $(date) ------------------";