Skip to content

Instantly share code, notes, and snippets.

View TanAlex's full-sized avatar

Tingli Tan TanAlex

View GitHub Profile
@TanAlex
TanAlex / debounce.js
Last active June 9, 2019 04:54
[Javascript Utils]Javascript Utilities #utils
// Credit David Walsh (https://davidwalsh.name/javascript-debounce-function)
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
var called = false;
// This is the function that is actually executed when
@TanAlex
TanAlex / get_url.yml
Created June 15, 2019 21:59
[ansible note]Ansible Notes #ansible
- name: Download files
get_url:
url: "{{item.url}}"
dest: "/var/www/html/{{item.dest}}"
with_items: [{"url": "https://archive.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz", "dest": "server1.tar.gz"},
{"url": "https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.1-bin.zip", "dest": "server2.zip"}]
AWSTemplateFormatVersion: "2010-09-09"
Description: >
Launch a static website backed by an S3 bucket and served via https through cloudfront.
Assumes you have the following available already
* An address in mind (e.g. blog.example.com)
* An existing Route53 Hosted Zone for the domain
* A validated AWS ACM certificate arn for the desired web address which must be in eu-west-1
Parameters:
HostedZoneID:
Description: >
AWSTemplateFormatVersion: "2010-09-09"
Description: >
Create an S3 bucket and configure it for s3-website hosting
Create a record in a pre-existing Route53 HostedZone and point at the newly created bucket
Parameters:
HostedZoneID:
Description: The Hosted Zone ID in which to create the website DNS record
Type: AWS::Route53::HostedZone::Id
WebsiteAddress:
Description: >
@TanAlex
TanAlex / bash_aws_jq_cheatsheet.sh
Created July 31, 2019 20:12 — forked from lukeplausin/bash_aws_jq_cheatsheet.sh
AWS, JQ and bash command cheat sheet. How to query, cut and munge things in JSON generally.
# Count total EBS based storage in AWS
aws ec2 describe-volumes | jq "[.Volumes[].Size] | add"
# Count total EBS storage with a tag filter
aws ec2 describe-volumes --filters "Name=tag:Name,Values=CloudEndure Volume qjenc" | jq "[.Volumes[].Size] | add"
# Describe instances concisely
aws ec2 describe-instances | jq '[.Reservations | .[] | .Instances | .[] | {InstanceId: .InstanceId, State: .State, SubnetId: .SubnetId, VpcId: .VpcId, Name: (.Tags[]|select(.Key=="Name")|.Value)}]'
# Wait until $instance_id is running and then immediately stop it again
aws ec2 wait instance-running --instance-id $instance_id && aws ec2 stop-instances --instance-id $instance_id
# Get 10th instance in the account
@TanAlex
TanAlex / cheatsheet-git.sh
Created August 8, 2019 23:06 — forked from raineorshine/cheatsheet-git.sh
Cheatsheet: git commands
# adding and committing
git add -A # stages All
git add . # stages new and modified, without deleted
git add -u # stages modified and deleted, without new
git commit --amend # Add staged changes to previous commit. Do not use if commit has been pushed.
git commit --amend --no-edit # Do so without having to edit the commit message.
# remotes - pushing, pulling, and tracking
git fetch # gets remote objects and refs. Needed if new branches were added on the remote.
git remote -v # Lists all remotes (verbose)
@TanAlex
TanAlex / list.txt
Created August 12, 2019 20:10 — forked from shortjared/list.txt
List of AWS Service Principals
acm.amazonaws.com
alexa-appkit.amazon.com
apigateway.amazonaws.com
application-autoscaling.amazonaws.com
appstream.application-autoscaling.amazonaws.com
appsync.amazonaws.com
athena.amazonaws.com
autoscaling.amazonaws.com
batch.amazonaws.com
channels.lex.amazonaws.com
@TanAlex
TanAlex / canary-lamba.js
Created April 26, 2020 18:18
AWS CloudWatch Synthetics Canary Script
var synthetics = require('Synthetics');
const log = require('SyntheticsLogger');
const pageLoadBlueprint = async function () {
// INSERT URL here
const URL = "https://example.com";
const username = "user@example.com";
const passwd = "@#^!abcd1234"
let page = await synthetics.getPage();
@TanAlex
TanAlex / bitbucket-eks-pipeline.yaml
Created May 8, 2020 15:58
sample bitbucket pipeline to deploy docker image
image: atlassian/default-image:2
pipelines:
default:
- step:
name: "Build and push"
services:
- docker
script:
- IMAGE="bitbucketpipelines/hello-app-eks"
- pushd customer-reporting.sls && npm install serverless-plugin-aws-alerts && popd
- |
echo "Runway Execution Step............"
if [[ "$BITBUCKET_BRANCH" == master ]]; then
eval $(aws ecr get-login --no-include-email | sed 's;https://;;g')
# do something
else
echo "Current branch is not master, skip";
fi