Skip to content

Instantly share code, notes, and snippets.

View huangsam's full-sized avatar
🌱
Continuous learning

Samuel Huang huangsam

🌱
Continuous learning
View GitHub Profile
@huangsam
huangsam / puzzle.py
Last active January 15, 2019 18:20
Prints n iterations of a certain pattern...guess it!
#!/usr/bin/env python
import sys
def pattern(n):
"""Prints n iterations of a certain pattern...guess it!"""
old = [1]
print("1")
for i in range(n - 1):
new = []
@huangsam
huangsam / rename.sh
Last active December 24, 2015 13:38
Change file extensions in a directory.
#!/bin/bash
<<COMMENT
Author: Samuel Huang
rename.sh: change file extensions in a directory
COMMENT
path="."
interact=false
recurse=false
@huangsam
huangsam / lb-run.sh
Last active August 29, 2015 14:12
Load balance Docker containers in a Vagrant VM
#!/bin/bash
# lb-run.sh: Run load balancer on three app instances
# kill necessary containers
if [ "x$1" == "xkill" ] ; then
docker rm -f etcd app1 app2 app3 proxy
exit 0
fi
# run etcd server
@huangsam
huangsam / default.yml
Last active August 17, 2016 05:29
Try Kubernetes out via REST
kube:
protocol: http
# this is a weak default. Must use KUBE_HOST to set host
host: localhost
# this is a weak default. Must use KUBE_PORT to set port
port: 8080
@huangsam
huangsam / gist:f1e687eec24534c23fc0da8d9cd7047d
Created July 1, 2017 17:42 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@huangsam
huangsam / destructuring.js
Created July 1, 2017 19:06 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@huangsam
huangsam / latency.txt
Created July 31, 2017 18:07 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
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
@huangsam
huangsam / threads_v1.py
Last active January 4, 2018 21:55
Threading for "embarrassingly parallel" tasks
# -*- coding: utf-8 -*-
import multiprocessing as mp
import queue
import threading
def worker(f, iq, oq):
"""Logic for a single worker thread.
The loop terminates when it's given a None item, so ensure
@huangsam
huangsam / matching.py
Created January 5, 2018 00:02
Advanced class utilities
# -*- coding: utf-8 -*-
import importlib
import inspect
import pkgutil
import re
def is_match(entry, pattern):
"""Identify entry match.