Skip to content

Instantly share code, notes, and snippets.

View gwsu2008's full-sized avatar

Guang gwsu2008

View GitHub Profile
@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 / 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 / Android-Emulator-on-AWS-EC2.txt
Created July 26, 2019 18:56 — forked from atyachin/Android-Emulator-on-AWS-EC2.txt
Installing and running Android Emulator on Amazon AWS EC2 (Ubuntu 16.04 / m5.xlarge)
Steps for installing the Android Emulator from EC2 console:
-----------------------------------------------------------
sudo apt install default-jdk
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
unzip sdk-tools-linux-4333796.zip -d android-sdk
sudo mv android-sdk /opt/
export ANDROID_SDK_ROOT=/opt/android-sdk
echo "export ANDROID_SDK_ROOT=/opt/android-sdk" >> ~/.bashrc
echo "export PATH=$PATH:$ANDROID_SDK_ROOT/tools" >> ~/.bashrc
re-login
@gwsu2008
gwsu2008 / ios-remove-unavailable-simulator
Created August 16, 2019 21:21
ios-remove-unavailable-simulator
i=1
while [ $i -ne 20 ]; do let i=$i+1; xcrun simctl list | grep Shutdown | grep unavailable | tail -n1 | awk -F"Shutdown" '{print $1}' | tr -d '()' | awk '{print $NF}' | xargs -I{} xcrun simctl delete {}; done
@gwsu2008
gwsu2008 / aws_saml.py
Created August 30, 2019 23:43 — forked from JoeyG1973/aws_saml.py
aws saml login with session that auto refreshes.
# Took this:
# https://s3.amazonaws.com/awsiammedia/public/sample/SAMLAPICLIADFS/samlapi_formauth_adfs3.py
# converted to boto3 and smooshed it together with this:
# https://gist.github.com/kapilt/ac8e222081f63ba64e93
# which gave birth too this:
import sys
import botocore
import boto3
import requests
from botocore.credentials import RefreshableCredentials
from botocore.session import get_session
from boto3 import Session
def assumed_session(role_arn, session_name, session=None):
"""STS Role assume a boto3.Session
With automatic credential renewal.
@gwsu2008
gwsu2008 / skip_phases
Created September 19, 2019 22:18
maven phases
Skip compile -Dmaven.main.skip
Skip exec -Dexec.skip
@gwsu2008
gwsu2008 / python_convert_utc_to_local
Created September 19, 2019 22:33
python_convert_utc_to_local
from datetime import datetime
from dateutil import tz
# METHOD 1: Hardcode zones:
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('America/New_York')
# METHOD 2: Auto-detect zones:
from_zone = tz.tzutc()
to_zone = tz.tzlocal()
@gwsu2008
gwsu2008 / iam_assume_role_1
Last active September 19, 2019 23:00
iam_assume_role_1
import botocore
import boto3
import datetime
from dateutil.tz import tzlocal
from botocore.credentials import DeferredRefreshableCredentials
from botocore.session import Session
def assumed_role_session(role_arn: str, base_session: botocore.session.Session = None):
base_session = base_session or boto3.session.Session()._session
@gwsu2008
gwsu2008 / fix-Could not connect to lockdownd. Exiting.
Created October 1, 2019 23:00
fix-Could not connect to lockdownd. Exiting.
brew uninstall ideviceinstaller
brew uninstall libimobiledevice
brew uninstall usbmuxd
brew install usbmuxd --HEAD
brew install --HEAD libimobiledevice
brew unlink libimobiledevice && brew link libimobiledevice
brew install --HEAD ideviceinstaller
brew unlink ideviceinstaller && brew link ideviceinstaller
sudo chmod -R 777 /var/db/lockdown