Skip to content

Instantly share code, notes, and snippets.

View ijkilchenko's full-sized avatar
👽

Alex Ilchenko ijkilchenko

👽
  • @meta, ex-google
  • San Francisco, CA
View GitHub Profile
# author: @ijkilchenko
# MIT License
def words_over_vocab(vocab, n):
return _words_over_vocab(vocab, '', n)
def _words_over_vocab(vocab, word, n):
if len(word) == n:
yield word
else:
#!/usr/bin/python3
# author: @ijkilchenko
# MIT License
import math
import hashlib
import random
from collections import defaultdict
def base10_to_baseB(num, B):
import random
import math
from hashlib import md5
class MyHashTable(object):
def __init__(self, hash_functions, len_table):
self.hash_functions = hash_functions
self.len_table = len_table
self.table = [-1]*self.len_table
@ijkilchenko
ijkilchenko / heap.py
Last active June 16, 2016 04:19
Heap which supports insertion in O(log(n)) time and finding the max (the root node) in O(1). Also, the tree of the heap is always as short as possible -- what I call a balanced heap.
import random
class Node():
def __init__(self, data=None):
self.data = data
self.parent = None
self.left = None
self.right = None
self.load = 1 # Assumed to be a leaf when initialized.
import random
import numpy as np
#from cvxpy import *
def p(M):
"""Method to pretty print our matrix. """
for i in range(len(M)):
print(' '.join([str(num) for num in M[i]]))
def generate_M(N=3, max_touches=2):
syntax enable
colorscheme monokai
set number
set ruler
set swapfile
set dir=~/tmp
set tabstop=4
from sklearn.datasets import make_classification
from sklearn.cross_validation import train_test_split
from itertools import product
import numpy as np
import pandas as pd
class NeuralNetwork:
g = np.vectorize(lambda z: 1 / (1 + np.exp(-z)))
log = np.vectorize(lambda x: np.log(x))
from math import log10, floor
def r(num):
num_digits = floor(log10(num) + 1)
return num//10 + (num % 10)*(10**(num_digits-1))
def does_a_divide_b(a, b):
if b % a == 0:
return True
else:
import random
from math import sqrt, floor
"""
Guessing game. When playing, the game picks a random value from i to j
and each time a guess g is made, g is added to the previous running cost
of playing this game.
"""
cache = {}
class Game:
import keyboard
import time
if __name__ == '__main__':
frames = [0]
def forward():
global last_frame_index
while True:
if not is_paused: