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 dataclasses import dataclass | |
from datetime import datetime, timedelta | |
TIME_FORMAT = '%H:%M:%S,%f' | |
def load_time(s: str) -> float: | |
t = datetime.strptime(s, TIME_FORMAT) | |
return (t - t.replace(hour=0, minute=0, second=0, microsecond=0)).total_seconds() |
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 time | |
from typing import List, NamedTuple | |
from django.core.cache import caches | |
class RateLimit(NamedTuple): | |
seconds: int | |
limit: int |
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 parseHTML(html) { | |
var template = document.createElement('template'); | |
template.innerHTML = html; | |
return template.content; | |
} |
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
isEu = function() { | |
var euCountryCodes = new Set(['be', 'el', 'lt', 'pt', 'bg', 'es', 'lu', 'ro', 'cz', 'fr', 're', 'gp', 'mq', 'gf', 'yt', 'bl', 'mf', 'pm', 'wf', 'pf', 'nc', 'hu', 'si', 'dk', 'fo', 'gl', 'hr', 'mt', 'sk', 'de', 'it', 'nl', 'aw', 'cw', 'sx', 'fi', 'ax', 'ee', 'cy', 'at', 'se', 'ie', 'lv', 'pl', 'uk', 'gb', 'ai', 'bm', 'io', 'vg', 'ky', 'fk', 'gi', 'ms', 'pn', 'sh', 'tc', 'gg', 'je', 'im']); | |
return function isEu() { | |
return ( | |
Intl.DateTimeFormat().resolvedOptions().timeZone.startsWith('Europe/') || | |
euCountryCodes.has((navigator.userLanguage || navigator.language).slice(0, 2)) | |
); | |
} | |
}(); |
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 sys, re | |
class TerminalController: | |
""" | |
A class that can be used to portably generate formatted output to | |
a terminal. | |
`TerminalController` defines a set of instance variables whose | |
values are initialized to the control sequence necessary to | |
perform a given action. These can be simply included in normal |
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 fractions import Fraction, gcd | |
def matrix_determinant(m): | |
"""determinant using laplace transform""" | |
size = len(m) | |
assert len(m[0]) == size | |
if size == 2: | |
return m[0][0] * m[1][1] - m[0][1] * m[1][0] | |
return sum( |
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 sys | |
def getsizeof_deep(o, verbose=False): | |
default_size = sys.getsizeof(0) | |
seen = set() | |
todo = [o] | |
size = 0 |
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
# http://isthe.com/chongo/tech/comp/fnv/ | |
# https://tools.ietf.org/html/draft-eastlake-fnv-11 | |
FNV_PARAMS = { | |
# bits -> prime, offset basis | |
# see http://isthe.com/chongo/tech/comp/fnv/ | |
32: (16777619, 2166136261), | |
64: (1099511628211, 14695981039346656037), | |
128: (309485009821345068724781371, 144066263297769815596495629667062367629), |
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
# encoding: US-ASCII | |
# stolen largely from http://www.ruby-forum.com/topic/140784 | |
require 'stringio' | |
require 'fileutils' | |
def extract_chunk(input, output) | |
lenword = input.read(4) | |
length = lenword.unpack('N')[0] | |
type = input.read(4) |
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 getRandomBase64String(length) { | |
var array = new Uint8Array(Math.ceil(length * 3 / 4)); | |
crypto.getRandomValues(array); | |
return btoa(String.fromCharCode.apply(null, array)).slice(0, length); | |
} | |
function getRandomHexString(length) { | |
var array = new Uint32Array(Math.ceil(length / 8)); | |
crypto.getRandomValues(array); | |
return Array.prototype.map.call(array, i => i.toString(16).padStart(2, '0')).join('').slice(0, length); |
NewerOlder