Skip to content

Instantly share code, notes, and snippets.

@BennettRand
BennettRand / interview_answer2.py
Last active July 11, 2017 21:13
The answer to my table of elements interview question.
class TableOfElements(object):
@staticmethod
def symbols(word):
symbols = set()
for i, l in enumerate(word):
for l2 in word[i + 1:]:
sym = l.upper() + l2.lower()
if sym not in symbols:
symbols.add(sym)
yield sym
@BennettRand
BennettRand / interview_answer.py
Last active May 12, 2017 19:15
My answer to my interview question. Create an object to store IP ranges as a blacklist and return if an IP is in the blacklist. Assume no range overlap.
def ip2int(ip):
o = map(int, ip.split('.'))
res = (16777216 * o[0]) + (65536 * o[1]) + (256 * o[2]) + o[3]
return "{:0>32b}".format(res)
class BlacklistNode(object):
def __init__(self, parent=None):
self.parent = parent
self.branches = {}
self.blocked = False

Keybase proof

I hereby claim:

  • I am bennettrand on github.
  • I am bennettrand (https://keybase.io/bennettrand) on keybase.
  • I have a public key ASAYeJ_bjVIPcApG3hdyp0w-EWwRDALAujGHSFzFR_lXygo

To claim this, I am signing this object:

@BennettRand
BennettRand / fan_control.py
Last active August 29, 2015 14:07
jQuery Mobile Fan Control for RPi
import RPi.GPIO as GPIO
import time
import random
import signal
from multiprocessing import Pool
from paste import httpserver
import paste.request
import threading
import pywapi
#!/usr/bin/python
'''
Author: Igor Maculan - n3wtron@gmail.com
A Simple mjpg stream http server
Editied By: Bennett Rand
Added:
ThreadingMixIn - multiple connections
'''
import cv2
import Image