Skip to content

Instantly share code, notes, and snippets.

View RPing's full-sized avatar
🎯
Focusing

Stephen Chen RPing

🎯
Focusing
View GitHub Profile
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu-deployment
labels:
app: ubuntu
spec:
replicas: 1
selector:
matchLabels:
@RPing
RPing / consistent_hashing.py
Created March 8, 2021 11:03
python2 consistent hashing impl
'''https://michaelnielsen.org/blog/consistent-hashing/'''
import bisect
import hashlib
class ConsistentHash:
'''ConsistentHash(n,r) creates a consistent hash object for a
cluster of size n, using r replicas.
It has three attributes. num_machines and num_replics are
self-explanatory. hash_tuples is a list of tuples (j,k,hash),
@RPing
RPing / latency.txt
Created February 21, 2021 11:38 — 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
@RPing
RPing / binlog-rollback.pl
Created May 25, 2020 12:37 — forked from C0reFast/binlog-rollback.pl
binlog-rollback.pl
#!/usr/bin/perl -w
use strict;
use warnings;
use Class::Struct;
use Getopt::Long qw(:config no_ignore_case); # GetOption
# register handler system signals
use sigtrap 'handler', \&sig_int, 'normal-signals';
@RPing
RPing / gif2mp4.sh
Last active December 25, 2018 10:44
gif to mp4 and loop it
#!/bin/sh
# sh gif2mp4.sh <gif url/local file> <loop count>
# output file will be out.mp4
ffmpeg -f gif -i $1 -pix_fmt yuv420p -vcodec libx264 tmp.mp4
for (( i = 0; i <= $2; i++ ))
do
printf "file tmp.mp4\n" >> list.txt
done
@RPing
RPing / debug.py
Created December 16, 2018 08:48
pprint debug
import pprint
ppp = pprint.PrettyPrinter(indent=4)
import pdb; pdb.set_trace()
@RPing
RPing / memo.txt
Created January 22, 2018 10:15
MySQL 開資料庫 中文設定
create database XXX character set utf8mb4 collate utf8mb4_unicode_ci;
@RPing
RPing / styles.less
Created April 6, 2017 15:39
my Mac atom stylesheet
// style the background color of the tree view
.tree-view {
// background-color: whitesmoke;
font-family: Inconsolata, Monaco, Consolas, 'Courier New', Courier;
font-size: 15px;
}
atom-workspace {
font-family: Inconsolata, Monaco, Consolas, 'Courier New', Courier;
// font-size: 15px;
}
@RPing
RPing / Open iTerm2 in Finder folder
Last active December 10, 2016 06:44
Apple script to open an iterm2 window from right-clicking on a folder in Finder. To use:(1) Open Automator(2) Create a new service(3) Change "Service receives selected" drop downs to "Files or folders" in "Finder"(4) Select "Run applescript" from the sidebar, then paste this script in and save
-- Adapted from these sources:
-- http://peterdowns.com/posts/open-iterm-finder-service.html
-- https://gist.github.com/cowboy/905546
--
-- Modified to work with files as well, cd-ing to their container folder
on run {input, parameters}
tell application "Finder"
set my_file to first item of input
set filetype to (kind of (info for my_file))
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer: