Skip to content

Instantly share code, notes, and snippets.

@nitori
nitori / flif.py
Last active July 24, 2017 21:29
flif.py
import logging
from distutils import log
logging.basicConfig(level=logging.DEBUG)
log.set_verbosity(log.DEBUG)
from cffi import FFI
@nitori
nitori / piratemap.py
Last active December 16, 2015 21:56
test
import math
import colorsys
from itertools import product
from noise import snoise2
from PIL import Image
import numpy as np
@nitori
nitori / genmap.py
Last active December 17, 2015 05:10
from itertools import product
import random
from noise import snoise2
from PIL import Image
import numpy as np
size = (500, 500)
import asyncio
import time
HOST = "localhost"
PORT = 8888
class Client(asyncio.Protocol):
def __init__(self, message, loop, host, port):
self.message = message
class Message:
def __init__(self, command, params, trailing, prefix=None, raw_line=None):
self.prefix = prefix
self.command = command.upper()
self.params = params
self.trailing = trailing
self._raw_line = raw_line
@nitori
nitori / szip.py
Last active March 23, 2016 21:36
class szip:
def __init__(self, *sequences):
self.sequences = sequences
def __len__(self):
return min(len(seq) for seq in self.sequences)
def __getitem__(self, index):
if isinstance(index, slice):
return szip(*(seq[index] for seq in self.sequences))
#!/usr/bin/env python3.5
import asyncio
from collections import namedtuple
import functools
import random
Message = namedtuple('Message', 'prefix command params')
Prefix = namedtuple('Prefix', 'nick ident host')
import ast
import _ast
import importlib.util
import os
import sys
from types import ModuleType
class PluginException(Exception):
@nitori
nitori / midinote.py
Last active November 8, 2016 20:24
Very basic MIDI file parser. Does nothing much.
# sample output of a basic midi file https://gist.github.com/knitori/35a7d3a69189f35f655d9edb99b10b66
import struct
import io
def track_reader(buf):
while True:
marker = buf.read(4)
if marker == b'':
@nitori
nitori / timed_cache.py
Last active January 8, 2017 00:08
Like lru_cache but with a timeout instead
import functools
import time
def timed_cache(seconds, typed=False):
def _decorator(user_function):
cache = {}
sentinel = object()