Skip to content

Instantly share code, notes, and snippets.

@olee12
olee12 / latency.txt
Created July 12, 2019 06:17 — 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
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard
labels:
k8s-app: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
@olee12
olee12 / BinarySearch.go
Last active October 12, 2019 14:48
Binary Search in go.
// BinarySearch ...
func BinarySearch(array []int, target int) int {
low := 0
high := len(array) - 1
mid := 0
for low <= high {
mid = (low + high) / 2
if array[mid] > target {
high = mid - 1
} else if array[mid] < target {
@olee12
olee12 / UpperBound.go
Created October 12, 2019 14:50
Upper Bound in go.
// UpperBound ...
func UpperBound(array []int, target int) int {
low, high, mid := 0, len(array)-1, 0
for low <= high {
mid = (low + high) / 2
if array[mid] > target {
high = mid - 1
} else {
low = mid + 1
@olee12
olee12 / LowerBound.go
Created October 12, 2019 15:07
Lower Bound in golang
// LowerBound ...
func LowerBound(array []int, target int) int {
low, high, mid := 0, len(array)-1, 0
for low <= high {
mid = (low + high) / 2
if array[mid] >= target {
high = mid - 1
} else {
low = mid + 1
}
@olee12
olee12 / Search in a 2D Matrix.cpp
Created October 13, 2019 12:24
Search in a 2D sorted Matrix
bool searchMatrix(vector<vector<int>>& matrix, int target) {
if (matrix.size() == 0 || matrix[0].size() == 0) return false;
int row = matrix.size();
int col = matrix[0].size();
int low = 0;
int high = row * col - 1;
while (low <= high)
{
@olee12
olee12 / Euler circuit.cpp
Created October 19, 2019 16:06
Euler circuit or path
map<string, multiset<string> > adj;
vector<string> result; // reverse the result if you are trying to find a path that starts from u.
void dfs(string u) {
while(adj[u].size()) {
string v = *adj[u].begin();
adj[u].erase(adj[u].begin());
dfs(v);
}
return result.push_back(u);
@olee12
olee12 / pair min priority_queue.cpp
Created October 20, 2019 07:45
pair min priority_queue
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
/*
top : 9 4
top : 10 5
top : 10 8
top : 15 10
*/
@olee12
olee12 / max sliding window.cpp
Created October 20, 2019 08:59
max sliding window
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
deque<pair<int,int>> q;
vector<int> ret;
for(int i = 0;i<nums.size();i++) {
while(q.size() && q.back().first <= nums[i]) q.pop_back();
q.push_back({nums[i],i});
while(q.front().second <= (i-k)) q.pop_front();
if(i + 1 >= k) ret.push_back(q.front().first);
}
return ret;
@olee12
olee12 / iterm2.md
Created November 5, 2019 07:17 — forked from squarism/iterm2.md
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)