Skip to content

Instantly share code, notes, and snippets.

View gwsu2008's full-sized avatar

Guang gwsu2008

View GitHub Profile
@gwsu2008
gwsu2008 / Cloudformation-InLine-Lambda.yml
Created August 9, 2020 15:15
Cloudformation-InLine-Lambda.yml
EndpointServiceTag:
Type: 'AWS::Lambda::Function'
Properties:
Handler: index.lambda_handler
Role: !GetAtt LambdaRole.Arn
Code:
ZipFile: |
import json
import boto3
import cfnresponse
@gwsu2008
gwsu2008 / Cloudformation-Lambda-Layers.yml
Created August 9, 2020 15:13
Cloudformation-Lambda-Layers.yml
MyLayer:
Type: AWS::Lambda::LayerVersion
Properties:
CompatibleRuntimes:
- python3.6
- python3.7
Content:
S3Bucket: my-bucket-us-west-2-123456789012
S3Key: layer.zip
Description: My layer
@gwsu2008
gwsu2008 / join-path
Created July 9, 2020 18:27
python-join-path
os.path.join(os.sep, 'home', 'build', 'test', 'sandboxes', todaystr, 'new_sandbox')
os.path.join(os.environ.get("HOME"), 'test', 'sandboxes', todaystr, 'new_sandbox')
test = ['test', 'test1', 'test2', 'test3']
os.path.join(*test)
@gwsu2008
gwsu2008 / jenkins-multi-branch-pipeline-java-regex
Created July 4, 2020 04:12
jenkins-multi-branch-pipeline-java-regex
^(?!.*develop|.*master|release/das-|release/dp-).*$
^(?!.*master|release/das-|release/dp-).*$
# This is a really old post, in the comments (and stackoverflow too) you'll find better solutions.
def find(key, dictionary):
for k, v in dictionary.iteritems():
if k == key:
yield v
elif isinstance(v, dict):
for result in find(key, v):
yield result
elif isinstance(v, list):
@gwsu2008
gwsu2008 / remove-jenkins-offline-nodes.groovy
Created June 24, 2020 16:25
remove-jenkins-offline-nodes
for (aSlave in hudson.model.Hudson.instance.slaves) {
if (aSlave.getComputer().?isOffline()) {
aSlave.getComputer().setTemporarilyOffline(true,null);
aSlave.getComputer().doDoDelete();
}
}
for (aSlave in hudson.model.Hudson.instance.slaves) {
println('====================');
println('Name: ' + aSlave.name);
@gwsu2008
gwsu2008 / aws-lambda-import-boto3.py
Created June 19, 2020 06:19
aws-lambda-import-boto3.py
import os
import os.path
import sys
root = os.environ["LAMBDA_TASK_ROOT"]
sys.path.insert(0, root)
import boto3 #should grab boto3 from included zip first
@gwsu2008
gwsu2008 / diff-jq.md
Created June 14, 2020 15:44 — forked from ipan/diff-jq.md
compare two JSONs with jq #json #jq
@gwsu2008
gwsu2008 / no html cache headers
Created June 10, 2020 18:26
no html cache headers
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
@gwsu2008
gwsu2008 / jenkins-auto-approve-script.groovy
Created June 3, 2020 06:15
jenkins-auto-approve-script.groovy
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval
ScriptApproval scriptApproval = ScriptApproval.get()
scriptApproval.pendingScripts.each {
scriptApproval.approveScript(it.hash)
}
/* Script to clear script approval
$JENKINS_HOME/init.groovy.d/disable-script-security.groovy:
*/