Skip to content

Instantly share code, notes, and snippets.

View tsungtwu's full-sized avatar

Tsung Wu tsungtwu

View GitHub Profile
@tsungtwu
tsungtwu / latency.txt
Created August 15, 2022 14:54 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@tsungtwu
tsungtwu / google-tips
Created July 15, 2022 08:53 — forked from qwo/google-tips
Google Recruiter Candidate Tips ..
xxx,
Thanks again for taking the time to speak with me and for sending me your information. I'm excited to tell you that we would like to move forward in the process!
One of our coordinators will be emailing you within the next week from an @google.com domain with the date and time of your phone interview. In the meantime, I've included some preparation materials (below.)
Please note this will be a technical interview that will last for approximately 45 minutes. Google takes an academic approach to the interviewing process. This means that we are interested in your thought process, your approach to problem solving as well as your coding abilities. You may be asked questions that relate to technical knowledge, algorithms, coding, performance, how to test solutions, and perhaps your interest in Google products. The best advice that I can give you is to treat the interview like a conversation, talk through the problems, and please feel free to ask the interviewer if you are not clear with any of the questio
@tsungtwu
tsungtwu / cf-function-uri-rewrite.js
Created April 10, 2022 16:04
Use AWS CloudFront Functions for URI Rewrites
function handler(event) {
var request = event.request;
var rewrites = [
['/summer21','/recipies?year=2021&season=summer'],
['/recipies/homemade-mouse-and-cheese/', '/recipies/homemade-mac-and-cheese/'],
['/recipies/camping/grilling', '/recipies?activities=camping&with=grill']
]
for (var arrayIndex in rewrites){
if (request.uri == rewrites[arrayIndex][0]) {
@tsungtwu
tsungtwu / docker-compose.yml
Last active September 6, 2021 03:11 — forked from adibenc/docker-compose.yml
example docker-compose.yml for kong, postgres and konga, a bit fixes
version: "3"
networks:
kong-net:
driver: bridge
services:
#######################################
# Postgres: The database used by Kong
@tsungtwu
tsungtwu / Cloud Security Orienteering Checklist.md
Created August 28, 2021 18:55 — forked from ramimac/Cloud Security Orienteering Checklist.md
A Checklist of Cloud Security Orienteering

Cloud Security Orienteering: Checklist
by Rami McCarthy
via TL;DR sec

How to orienteer in a cloud environment, dig in to identify the risks that matter, and put together actionable plans that address short, medium, and long term goals.

Based on the Cloud Security Orienteering methodology.

Checklist

import boto3
import re
from urllib.request import urlopen
import logging
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/config.html#ConfigService.Client.put_configuration_recorder
# Purpose:
# Activate Custom AWS Record for AWS Config
# Supported resource type: https://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html#supported-resources
@tsungtwu
tsungtwu / gitlab-merge-request.sh
Created August 11, 2021 07:49 — forked from bench/gitlab-merge-request.sh
A script to create gitlab MR from a shell
#!/bin/bash
# Check if jq is installed
if ! type "jq" > /dev/null; then
echo please install jq
fi
title="$(git log --oneline | head -1 | cut -f 2- -d ' ')"
source_branch="$(git branch | grep '*' | cut -f 2 -d ' ')"
target_branch=master
@tsungtwu
tsungtwu / 2s3.py
Created May 11, 2021 02:31 — forked from andymotta/2s3.py
Watch a directory for changes with Python Watchdog then multipart upload to S3
import sys
import os
import time
from watchdog.observers import Observer
from watchdog.events import FileModifiedEvent, FileCreatedEvent
import boto3
import mimetypes
from botocore.exceptions import ClientError
# Create an S3 client
@tsungtwu
tsungtwu / git-semver.sh
Created March 24, 2021 03:17 — forked from ericbmerritt/git-semver.sh
Shell script for parsing semvers from git-describe
#! /bin/bash
# Assumes that you tag versions with the version number (e.g., "1.1")
# and then the build number is that plus the number of commits since
# the tag (e.g., "1.1.17")
DESCRIBE=`git describe --tags --always`
# increment the build number (ie 115 to 116)
VERSION=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[1]}'`