Skip to content

Instantly share code, notes, and snippets.

import unittest
from functools import partial
class BinaryTree(object):
"""
In computer science, a binary tree is a tree data structure in which each
node has at most two children (referred to as the left child and the right
child).
import unittest
from functools import partial
class BinaryTree(object):
"""
In computer science, a binary tree is a tree data structure in which each
node has at most two children (referred to as the left child and the right
child).
import time
def print_board(board):
for row in board:
for column in row:
print(column),
print("")
print("- " * len(board[0]))
def count_neighbours(x, y, board):
"""
Write code that, given a tree with weighted nodes, prints, for each node,
the weight of the subtree rooted at that node (each node only knows it's own ID,
it's parent's ID and it's own weight).
e.g
you get a csv with the following format:
id, parent, weight
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
background-color: black;
}
#mycanvas {
background-color: black;
font-color: green;
from itertools import product
def my_product(head, *tail):
if not tail:
return ((h,) for h in head)
return ((h,) + t for h in head for t in my_product(*tail))
@quatrix
quatrix / heya.py
Last active August 29, 2015 14:10
__author__ = 'quatrix'
import re
import unittest
def _get_lowest_version(s):
"""
Takes a string of the following format:
var React = require('react');
var forms = require('newforms');
var _ = require('underscore');
var RegexValidator = forms.validators.RegexValidator
var $ = require('jquery');
var schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "/",
"type": "object",
@quatrix
quatrix / main.go
Last active August 29, 2015 14:19
package main
// basically just reimplemented (paritally) the TimeSpanSemaphore
// as specified here http://joelfillmore.com/throttling-web-api-calls/
import (
"container/heap"
"fmt"
"sync"
"time"
import json
def flatten(n):
while True:
changed = False
for k, v in n.iteritems():
if len(v.keys()) == 1:
del n[k]
vk = v.keys()[0]
n[k + '/' + vk] = v[vk]