Skip to content

Instantly share code, notes, and snippets.

@senvey
senvey / System Design.md
Created June 21, 2024 01:52 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@senvey
senvey / myconvtensorflow.py
Created September 11, 2018 21:18
TensorFlow
#!/bin/env python
import math
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data as mnist_data
print("Tensorflow version " + tf.__version__)
# https://stackoverflow.com/questions/47068709/your-cpu-supports-instructions-that-this-tensorflow-binary-was-not-compiled-to-u
import os
@senvey
senvey / query.sql
Created June 30, 2016 18:37
Hive table index
CREATE INDEX
example_by_business_id
ON TABLE
example_table (businessID)
AS 'COMPACT' WITH DEFERRED REBUILD;
ALTER INDEX example_by_business_id ON example_table REBUILD;
# Change the magic key to `^A`:
set-option -g prefix C-a
unbind-key C-b
bind-key a send-prefix
### Some familiar `screen`-like movement bindings ###
# `^A^A` to toggle between the last two windows
bind-key C-a last-window
# `^A space` to move to the next window
bind-key Space next-window
@senvey
senvey / gist:2048e40da406ffd7bf32
Created November 6, 2014 04:13
Restart ssh-agent
killall ssh-agent; eval `ssh-agent`
@senvey
senvey / search.py
Last active August 29, 2015 14:06
[pika] Clump Finding Problem
"""
Given integers L and t, a string Pattern forms an (L, t)-clump inside a (larger) string Genome if there is an interval of Genome of length L in which Pattern appears at least t times. For example, TGCA forms a (25,3)-clump in the following Genome: gatcagcataagggtcccTGCAaTGCAtgacaagccTGCAgttgttttac.
Clump Finding Problem
Find patterns forming clumps in a string.
Given: A string Genome, and integers k, L, and t.
Return: All distinct k-mers forming (L, t)-clumps in Genome.
@senvey
senvey / count.py
Last active August 29, 2015 14:06
Find the count of given number in a sorted array.
def count(array, n):
# starting point
left, right = 0, len(array)
while left < right:
mid = (left + right) / 2
if array[mid] >= n:
right = mid
else:
left = mid + 1
@senvey
senvey / max_distance.py
Created September 5, 2014 23:04
Given an array A of integers, find the maximum of j-i subjected to the constraint of A[i] < A[j]
# http://leetcode.com/2011/05/a-distance-maximizing-problem.html
def max_distance(array):
# collect possible starting points
# alternative: only record index without the num
starts = [(array[0], 0)]
for i, each in enumerate(array):
if each < starts[-1][0]:
starts.append((each, i))
@senvey
senvey / successor.py
Last active September 24, 2018 16:22
Inorder successor in a binary tree
def successor(node):
if node.right:
c = node.right
while c.left:
c = c.left
return c
n, p = node, node.parent
# note: check if p is not None
while p and n != p.left: