Skip to content

Instantly share code, notes, and snippets.

View qwo's full-sized avatar

Stanley Zheng qwo

View GitHub Profile
@qwo
qwo / ssh rule
Last active June 5, 2020 07:58
Generate SSH IP Allow-list
#!/bin/sh
set -- $(dig -t txt +short _cloud-netblocks.googleusercontent.com +trace)
included="" ip4=""
while [ $# -gt 0 ]; do
k="${1%%:*}" v="${1#*:}"
case "$k" in
include)
# only include once
@qwo
qwo / main.c
Created May 13, 2020 03:51 — forked from ColorfulCodes/main.c
This is the mt3620 blinky
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <applibs/storage.h>
#include <applibs/log.h>
#include <applibs/gpio.h>
@qwo
qwo / mastermind.py
Created November 5, 2019 19:09
Mastermind in Python!
## Mastermind
## Two Players
## 6 colors
## First Guess
TRYS = 10
MASTERMIND_CODE = ['r', 'g', 'r', 'b']
import getpass
SELECT owner,
Count(DISTINCT( breed )) AS num_breeds,
Count(name) AS num_dogs
FROM dogs
GROUP BY owner
ORDER BY num_dogs DESC
LIMIT 3
@qwo
qwo / cloudSettings
Last active May 25, 2020 17:29
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-11-15T22:05:25.530Z","extensionVersion":"v3.4.3"}
@qwo
qwo / _0000trackpad
Last active October 9, 2019 00:58
X1 Carbon 7 linux setup
#!/bin/sh
case "$1" in
resume)
DISPLAY=:0.0 su USER -c '/usr/bin/synclient TouchpadOff=0' ;;
esac
# /etc/pm/sleep.d/0000trackpad
@qwo
qwo / aws.txt
Last active July 16, 2019 19:11
Useful Cloud Commands
# Authenticate ECR
eval $(aws ecr get-login --no-include-email | sed 's|https://||')
export AWS_PROFILE=aws-sand; eval $(aws ecr get-login --no-include-email --region us-east-1 --profile aws-sand | sed 's|https://||')
docker tag foobar:latest 399450685648.dkr.ecr.us-east-1.amazonaws.com/foobar:latest
# for each buckets
export BUCKET_PREFIX="s3://nfl-sandbox-datalake-"
array=( aws s3 ls $BUCKET_PREFIX* )
for i in "${array[@]}"
import unittest
def is_binary_search_tree(root):
# Determine if the tree is a valid binary search tree
stack = [(root, -float('inf'), float('inf'))]
while len(stack):
node, lower_bound, upper_bound = stack.pop()
if (node.value <= lower_bound) or (node.value >= upper_bound):
return False
@qwo
qwo / tricks.py
Created December 4, 2018 03:39
AoC Tricks
## https://docs.scipy.org/doc/numpy-1.13.0/user/basics.io.html
import np
## get all input
claims = [[int(sub_str) for sub_str in re.findall(r'-?\d+', line)] for line in inputz.split('\n')]
## populate an array
canvas = np.zeros((1000,1000))
@qwo
qwo / mlapis.html
Last active August 22, 2018 21:38
instructor turned off the notebook lol
<!DOCTYPE html>
<!-- saved from url=(0086)https://8081-dot-4315443-dot-devshell.appspot.com/notebooks/datalab/docs/mlapis.ipynb# -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>mlapis</title>
<link rel="shortcut icon" type="image/x-icon" href="https://8081-dot-4315443-dot-devshell.appspot.com/static/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./mlapis_files/codemirror.css">
<link rel="stylesheet" href="./mlapis_files/style.min.css" type="text/css">