This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
example = """ | |
one | |
two | |
three | |
{% if 1 %}{% end %} | |
{{ | |
dance( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var image_nes_filter = (function() { | |
var PIXEL_SIZE = 4; | |
dither = (function() { | |
// Floyd–Steinberg dither | |
var ERROR_DIFFUSION_1_16 = 1 / 16, | |
ERROR_DIFFUSION_3_16 = 3 / 16, | |
ERROR_DIFFUSION_5_16 = 5 / 16, | |
ERROR_DIFFUSION_7_16 = 7 / 16, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""A multiprocessing Queue but is "fair" to every flow/session/channel. | |
See https://en.wikipedia.org/wiki/Fair_queuing. | |
""" | |
import sys | |
import time | |
from multiprocessing.queues import Queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.db.models.fields.related import ManyToManyRel, ReverseOneToOneDescriptor | |
from django.utils.translation import gettext_lazy as _ | |
class OneToManyRel(ManyToManyRel): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.multiple = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example usage: | |
# declare | |
class Color(Choices): | |
RED = 'Red' | |
GREEN = 'Green' | |
BLUE = 'Blue' | |
# use on model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import sys | |
""" | |
encoding is little endian | |
header details: (lsb to msb) | |
int7 1 | |
length 7 bits of int [-64, 63] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function element(tagName) { | |
/* | |
create an element | |
arguments: tagName, [attributes], children... | |
*/ | |
// help the minifier out a bit | |
var args = arguments | |
var doc = document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class cached_property(object): | |
"""Decorator that converts a method with a single self argument into a property cached on the instance.""" | |
def __init__(self, func): | |
self._get = func | |
self.__doc__ = getattr(func, '__doc__') | |
self._name = '_cached_' + func.__name__ | |
@staticmethod | |
def _set(obj, value): | |
raise AttributeError("can't set attribute") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Turn an integer into a nice base64 encoded string | |
# E.g. 4095 -> D_8 | |
# requires python 3 | |
import base64 | |
def encode(n): | |
return base64.urlsafe_b64encode(n.to_bytes((n.bit_length() + 7) // 8, 'big')).rstrip(b'==') |