Skip to content

Instantly share code, notes, and snippets.

View gwsu2008's full-sized avatar

Guang gwsu2008

View GitHub Profile
@gwsu2008
gwsu2008 / backup-jenkins-s3.sh
Created December 13, 2018 07:22
backup-jenkins-s3.sh
# Delete all files in the workspace
rm -rf *
# Create a directory for the job definitions
mkdir -p $BUILD_ID/jobs
# Copy global configuration files into the workspace
cp $JENKINS_HOME/*.xml $BUILD_ID/
# Copy keys and secrets into the workspace
@gwsu2008
gwsu2008 / python-date-quarterly.py
Created December 15, 2018 00:28
python-date-quarterly.py
mport pandas as pd
from datetime import datetime
No_of_quarters=8
#today = datetime.date.today()
today = datetime(2019, 1, 11)
month = pd.Period(today, freq='M')
quarter = month.asfreq('Q-DEC')
print(type(quarter))
@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) ------------------";
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 / 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
@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 / 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 / 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 / xcodebuild-cli
Created April 17, 2019 19:10
xcodebuild-cli
xcodebuild -list -workspace BaseNetworkConcept.xcworkspace/ -json
@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