Skip to content

Instantly share code, notes, and snippets.

alias g='git'
alias gst='g status'
alias gfe='g fetch'
alias gco='g checkout'
alias gcd='gco develop'
alias gcm='gco master'
from typing import List
class Permutation(object):
def permute(self, nums: List[int]) -> List[List[int]]:
def dfs(nums, permute, result):
if not nums:
result.append(permute)
return
for j, x in enumerate(nums):
dfs(nums[:j] + nums[j+1:], permute + [nums[j]], result)
class NumberCombination(object):
def number_combination(self, nums):
result = []
tracker = []
for x in nums:
for i in range(1,3):
if self.__ni_helper(x[0:i], x[i:], tracker):
result.append(tracker)
tracker = []
return result
from typing import List
class CombinationSum(object):
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
def dfs(comb, i, target, res):
if target == 0:
res.append(comb)
return
for j, x in enumerate(candidates[i:]):
if x <= target:
class SudokuBacktracking(object):
def __init__(self, grid):
self.grid=grid
self.grid_size=9
if not self.grid or len(self.grid)!=self.grid_size or len(self.grid[0])!=self.grid_size:
raise ('Must initialize the 9x9 board!')
def print_grid(self):
print('\n'.join(str(i) for i in self.grid))
class WordSearch(object):
def exist(self, board: [], word: str) -> bool:
for i in range(len(board)):
for j in range(len(board[i])):
if board[i][j] == word[0]:
if WordSearch.__search_adjacent(board, word[1:], i, j):
return True
return False
@stalk-calvin
stalk-calvin / chr.py
Created March 10, 2019 04:33
Implementation of Constant Hashing ring
import config
class Ring(object):
"""
Acts as an implementation interface
"""
def add(self, *keys):
raise NotImplementedError

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@stalk-calvin
stalk-calvin / tmux.md
Created June 4, 2017 00:47 — forked from andreyvit/tmux.md
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@stalk-calvin
stalk-calvin / The Technical Interview Cheat Sheet.md
Created January 25, 2017 03:20 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.