This file contains hidden or 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
| fnv1a_128_prime = 309485009821345068724781371 | |
| fnv1a_128_offset = 144066263297769815596495629667062367629 | |
| fnv1a_128_mask = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF | |
| def fnv1a_128(bs): | |
| h = fnv1a_offset | |
| for b in bs: | |
| h ^= b | |
| h *= fnv1a_prime |
This file contains hidden or 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
| def base26_encode(n, max_len=6): | |
| # base-26 alphabet (A-Z) | |
| value = '' | |
| digits = n | |
| while digits > 0: | |
| if len(value) == max_len: | |
| raise ValueError(n) | |
| value += chr((digits % 26) + A) | |
| digits /= 26 | |
| value += 'A' * max(max_len - len(value), 0) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |