Skip to content

Instantly share code, notes, and snippets.

View gwsu2008's full-sized avatar

Guang gwsu2008

View GitHub Profile
@gwsu2008
gwsu2008 / iam assume role
Last active February 5, 2021 23:28
iam assume role
first configure role to allow assume role in trust relationship
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::12345678:user/xyz",
"Service": "ec2.amazonaws.com"
},
@gwsu2008
gwsu2008 / One import via join.yaml
Created May 1, 2020 20:31 — forked from jgautheron/One import via join.yaml
Fn::ImportValue from other stacks
Tags:
- Key: Name
Value:
!Join ['_', [ ec2, "Fn::ImportValue" : {"Fn::Sub":'${BaseStackName}-Environment'}, test2]]
#This will create a name tag with value: ec2_<yourValueFromOtherStack>_test2
@gwsu2008
gwsu2008 / jenkins-groovy-create-user.groovy
Created April 23, 2020 19:29
jenkins-groovy-create-user
import hudson.model.*
import hudson.security.*
import hudson.tasks.Mailer
def userId = 'tester1'
def password = 'password!'
def email = '[email protected]'
def fullName = 'tester1 tester2'
def instance = jenkins.model.Jenkins.instance
def existingUser = instance.securityRealm.allUsers.find {it.id == userId}
@gwsu2008
gwsu2008 / Makefile
Created April 17, 2020 17:45 — forked from ryu1kn/Makefile
Encrypt/decrypt with AWS KMS using AWS cli
# How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli
KEY_ID=alias/my-key
SECRET_BLOB_PATH=fileb://my-secret-blob
SECRET_TEXT="my secret text"
ENCRYPTED_SECRET_AS_BLOB=encrypted_secret_blob
DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target
encrypt-text:
@gwsu2008
gwsu2008 / python_underscore.py
Created April 11, 2020 17:58
python_underscore.py
1. Single Leading Underscore: _var
The underscore prefix is meant as a hint to another programmer that a variable or method starting with a single underscore is intended for internal use. This convention is defined in PEP 8.
2. Single Trailing Underscore: var_
In summary, a single trailing underscore (postfix) is used by convention to avoid naming conflicts with Python keywords. This convention is explained in PEP 8.
3. Double Leading Underscore: __var
A double underscore prefix causes the Python interpreter to rewrite the attribute name in order to avoid naming conflicts in subclasses.
@gwsu2008
gwsu2008 / python-print-forma.py
Created April 11, 2020 17:11
python-print-forma.py
arg1 = 'number 1'
arg2 = 'number 2'
logger.info((f'arg1: {arg1}, arg2: {arg2}'))
@gwsu2008
gwsu2008 / python-import-modules.py
Last active April 11, 2020 17:08
python-import-modules.py
# main.py
import A
import sys
sys.path.insert(0, r'.\subfolder')
import B
objectA = A.A('Alice')
objectB = B.B('Bob')
@gwsu2008
gwsu2008 / jenkins.paramter.list.groovy
Created February 17, 2020 17:09
jenkins.parameter.list.groovy
import groovy.json.JsonSlurper
def cmd = 'aws ecr describe-images --repository-name repo_name --query "sort_by(imageDetails,& imagePushedAt)[].imageTags[]"'
def ecr_images_json = cmd.execute()
def data = new JsonSlurper().parseText(ecr_images_json.text)
def ecr_images = []
println (data)
@gwsu2008
gwsu2008 / docker-run-python-script
Created February 2, 2020 04:58
docker-run-python-script
# run only one script
docker run -it --rm --name python-test -v "$PWD":/usr/src/app -w /usr/src/app python:3.8.1-slim python test.py
# Dockerfile to build a custom python docker with pip modules
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
@gwsu2008
gwsu2008 / ssh-keygen.sh
Created January 31, 2020 22:57
ssh-keygen overwrite without prompt
ssh-keygen -o -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' 2>/dev/null <<< y >/dev/null