Skip to content

Instantly share code, notes, and snippets.

import requests
def get_content(url):
response = requests.get(url, stream=True)
for index, line in enumerate(response.iter_lines()):
if index == 0:
continue
yield line
@zhoufeng1989
zhoufeng1989 / The Technical Interview Cheat Sheet.md
Last active August 29, 2015 14:28 — 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.

Writing better python code


Swapping variables

Bad code

" copy all this into a vim buffer, save it, then...
" source the file by typing :so %
" Now the vim buffer acts like a specialized application for mastering vim
" There are two queues, Study and Known. Depending how confident you feel
" about the item you are currently learning, you can move it down several
" positions, all the way to the end of the Study queue, or to the Known
" queue.
" type ,, (that's comma comma)
@zhoufeng1989
zhoufeng1989 / debug.py
Created August 24, 2013 09:56
debug decorator
import functools
def debug(fn):
@functools.wraps(fn)
def wrapper(*args, **kwargs):
print 'call function {} with arguments {}, {}'.\
format(fn.__name__, str(args), str(kwargs))
ret = fn(*args, **kwargs)
print '{} return value {}'.format(fn.__name__, str(ret))
@zhoufeng1989
zhoufeng1989 / cache.py
Created August 24, 2013 09:42
cache decorator
import functools
#wraps(fn) => partial(update_wrapper, wrapped=fn)
def cache(fn):
_cache = {}
@functools.wraps(fn)
def wrapper(*args, **kwargs):
key = str(args) + str(kwargs)

Python Number Conversion Chart

From To Expression
# Extracted from the awesome book "Pro Python"
def C3(cls, *mro_lists):
"""Implementation of the Python's C3 Algorithm.
Notes:
* The order of items in an MRO should be preserved in all of
its future subclasses
"""
import itertools