Skip to content

Instantly share code, notes, and snippets.

View BlacklightShining's full-sized avatar

Blacklight Shining BlacklightShining

View GitHub Profile
#!/usr/bin/env python3
# icoo.py -- spawn two processes and connect their streams in a specific way
#
# usage: icoo.py <first-program> <second-program>
#
# icoo.py expects exactly two arguments (it uses Python's shlex.split() to
# parse them into `argv`s for the processes it spawns).
#
# After spawning the processes, icoo.py reads lines from their stdout streams

Keybase proof

I hereby claim:

  • I am blacklightshining on github.
  • I am blackl (https://keybase.io/blackl) on keybase.
  • I have a public key whose fingerprint is DF5D 0879 BAB8 8531 19F1 9FCB B3B4 E1FD E007 7044

To claim this, I am signing this object:

import bisect
identity = (lambda x: x)
class SortedList:
def __init__(self, iterable=None, key=identity, reverse=False):
self._key = key
self.reverse = reverse
self._items = []
self._keys = []
import enum
from functools import total_ordering
@total_ordering
class OrderedEnum(enum.Enum):
def __lt__(self, other):
if type(self) is not type(other):
return NotImplemented
# At this point, we know the operands are both from the same enum.
try:
from collections import deque
def multi_iter(iterable, n, overlap=True):
iterator = iter(iterable)
group = deque(maxlen=n)
# When we run out of elements, next() will raise StopIteration for us.
for _ in range(n):
group.append(next(iterator))
while True:
yield tuple(group)
def fibonacci():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
def circular_equals(self, other):
if len(self) != len(other):
return False
if not self:
return True
for offset in range(len(other)):
if all(
self[index] == other[(index+offset) % len(other)]
for index
in range(len(self))

Keybase proof

I hereby claim:

  • I am BlacklightShining on github.
  • I am blackl (https://keybase.io/blackl) on keybase.
  • I have a public key whose fingerprint is 7ADB 6E80 2F70 115A 3610 F8A2 76BD 2F78 572E 8487

To claim this, I am signing this object:

#!/usr/bin/env python3
def collatz(number):
if (number <= 0):
raise ValueError("number must be positive")
if (number % 1 != 0):
raise ValueError("number must be an integer")
while number != 1:
if number % 2 == 1:
number = number * 3 + 1
#!/usr/bin/env python3
# eytlus in Freenode/#python wrote this.
# I decided to keep my own copies of it around.
# I've edited this. See the revision history for diffs and originals.
from __future__ import print_function, division
def eytlus_hash(text, a=0, b=0):