Skip to content

Instantly share code, notes, and snippets.

View TanAlex's full-sized avatar

Tingli Tan TanAlex

View GitHub Profile
@TanAlex
TanAlex / retrieve_tgz_and_extract.py
Created February 15, 2023 06:58
[DS Python Snippets] DS Python Snippets #DataScience #Python
from pathlib import Path
import pandas as pd
import tarfile
import urllib.request
def load_housing_data():
tarball_path = Path("datasets/housing.tgz")
if not tarball_path.is_file():
Path("datasets").mkdir(parents=True, exist_ok=True)
url = "https://github.com/ageron/data/raw/main/housing.tgz"
@TanAlex
TanAlex / lambda-at-edge.tf
Created May 24, 2020 19:08
Terraform Snippet to deploy lambda@edge
data "archive_file" "folder_index_redirect_zip" {
type = "zip"
output_path = "${path.module}/folder_index_redirect.js.zip"
source_file = "${path.module}/folder_index_redirect.js"
}
resource "aws_iam_role_policy" "lambda_execution" {
name_prefix = "lambda-execution-policy-"
role = aws_iam_role.lambda_execution.id
@TanAlex
TanAlex / handler.js
Created May 24, 2020 18:58
lambda@edge function handle 404,403 response from s3 origin
'use strict';
const http = require('https');
const indexPage = 'index.html';
exports.handler = async (event, context, callback) => {
const cf = event.Records[0].cf;
const request = cf.request;
const response = cf.response;
image: node:10.15.0
test: &test
name: Install and Test
script:
- cd my-tools
- npm install
- npm test
- npm pack
artifacts: # defining the artifacts to be passed to each future step.
# - dist/**
test: &test
name: Install and Test
image: node:10.15.0
caches:
- node
script:
- npm install
- npm test
- npm run build
artifacts: # defining the artifacts to be passed to each future step.
- 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
@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"
@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 / 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 / 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)