Skip to content

Instantly share code, notes, and snippets.

Avatar

Joseph jjinking

  • San Francisco Bay Area
View GitHub Profile
View spacemacs-cheatsheet.md

emacs --daemon to run in the background. emacsclient.emacs24 <filename/dirname> to open in terminal

NOTE: "M-m and SPC can be used interchangeably".

  • Undo - C-/
  • Redo - C-?
  • Change case: 1. Camel Case : M-c 2. Upper Case : M-u 3. Lower Case : M-l
@jjinking
jjinking / combinations.scala
Last active Jun 3, 2017
Scala combinations
View combinations.scala
def comb[T](l: List[T]): List[List[T]] = l match {
case Nil => List(Nil)
case x::xs => {
val prevResult = comb(xs)
prevResult ++ prevResult.map(y => x::y)
}
}
View lru_cache.py
"""
LRUCache
"""
class LRUCache:
"""
Least Recently Used Cache
Implemented with a dictionary and a linked list
"""
def __init__(self, capacity):
@jjinking
jjinking / threading_stuff.py
Last active Nov 21, 2016
Examples of threading in python taken from slides (http://www.dabeaz.com/usenix2009/concurrent/Concurrent.pdf) that @dabeaz presented at USENIX Technical Conference, June 15, 2009 and other resources
View threading_stuff.py
import time
import threading
"""
Threads defined by a class
"""
class CountdownThread(threading.Thread):
def __init__(self,count):
threading.Thread.__init__(self)
View trie.py
class TrieNode:
def __init__(self):
"""Node objects within trie
"""
self.children = {}
self.is_word = False
class Trie:
@jjinking
jjinking / optimized_trie.py
Created Nov 1, 2016
Trie object in python using hash tables for keeping track of children
View optimized_trie.py
class Trie:
"""
Trie object will try to optimize by keeping unseen suffixes in a single node,
and then unravels those suffixes when the letters in the suffix are encountered
"""
class Node:
"""Each trie node"""
def __init__(self):
self.children = {}
self.count = 1
@jjinking
jjinking / minheap.py
Created Oct 29, 2016
MinHeap (or minPQ) in python that allows updates to items already in the heap
View minheap.py
class MinHeap:
"""Min Heap
"""
def __init__(self):
self.N = 0
self.vals = []
self.val2pos = {}
self.pos2key = {}
@property
View uniqueBSTs.hs
import Text.Printf
import Control.Exception
import System.CPUTime
time :: IO t -> IO t
time a = do
start <- getCPUTime
v <- a
end <- getCPUTime
let diff = (fromIntegral (end - start)) / (10^12)
View edit_dist_72.py
# Edit distance problem
class Solution(object):
def minDistance_recursive(self, word1, word2):
"""
Recursive solution
:type word1: str
:type word2: str
:rtype: int
View prime_number_generation.py
'''
Sieve is good for pre-generating list of primes, so that you can check quickly if a number is prime or not.
If you're checking if a single number is a prime or not, use the looping method
'''
import math
def generate_primes_sieve(n):
non_primes = set()