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
#!/usr/bin/env python3 | |
import hashlib | |
import tarfile | |
def hash_dict(tar_path): | |
tar = tarfile.open(tar_path) | |
result = {} | |
for member in tar: | |
if member.name.endswith(".pyc"): |
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 wrap(min, max, value) { | |
while (value < min) value += max - min | |
while (value > max) value -= max - min | |
return value | |
} | |
function clamp(min, max, value) { | |
return Math.min(Math.max(min, value), max) | |
} |
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 time | |
class ChronoPrint: | |
"""Usage: | |
cp = ChronoPrint() | |
foo() | |
cp("foo") # prints: 1.21 foo | |
bar() | |
cp("bar") # prints: 0.72 bar | |
""" |
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
#!/usr/bin/env python3 | |
import base64 | |
import hashlib | |
import http.server | |
def ws_accept(key): | |
if isinstance(key, str): | |
key = key.encode('ascii') | |
return base64.standard_b64encode(hashlib.sha1( |
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 math | |
class Bitfield: | |
def __init__(self, size): | |
self.size = size | |
self.bytes = bytearray(math.ceil(size / 8)) | |
def __len__(self): | |
return self.size |
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
// https://developers.google.com/maps/documentation/utilities/polylinealgorithm | |
function polylineDecode (str, precision) { | |
// Decode str to int array | |
let strIndex = 0 | |
let values = [] | |
while (strIndex < str.length) { | |
let byte | |
let result = 0 | |
let shift = 0 | |
do { |
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
/* eslint-disable-next-line */ | |
export default ['Africa/Abidjan','Africa/Accra','Africa/Algiers','Africa/Bissau','Africa/Cairo','Africa/Casablanca','Africa/Ceuta','Africa/El_Aaiun','Africa/Johannesburg','Africa/Juba','Africa/Khartoum','Africa/Lagos','Africa/Maputo','Africa/Monrovia','Africa/Nairobi','Africa/Ndjamena','Africa/Tripoli','Africa/Tunis','Africa/Windhoek','America/Adak','America/Anchorage','America/Araguaina','America/Argentina/Buenos_Aires','America/Argentina/Catamarca','America/Argentina/Cordoba','America/Argentina/Jujuy','America/Argentina/La_Rioja','America/Argentina/Mendoza','America/Argentina/Rio_Gallegos','America/Argentina/Salta','America/Argentina/San_Juan','America/Argentina/San_Luis','America/Argentina/Tucuman','America/Argentina/Ushuaia','America/Asuncion','America/Atikokan','America/Bahia','America/Bahia_Banderas','America/Barbados','America/Belem','America/Belize','America/Blanc-Sablon','America/Boa_Vista','America/Bogota','America/Boise','America/Cambridge_Bay','America/Campo_Grande', |
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
// ex: strftime("%Y-%m-%d %H:%M:%S") | |
function strftime(format, d) { | |
d = d || new Date() | |
function pad (v) { return ("0" + v).substr(-2, 2) } | |
var r = format.replace(/%Y/g, d.getFullYear()) | |
r = r.replace(/%m/g, pad(d.getMonth() + 1)) | |
r = r.replace(/%d/g, pad(d.getDate())) | |
r = r.replace(/%H/g, pad(d.getHours())) | |
r = r.replace(/%M/g, pad(d.getMinutes())) | |
r = r.replace(/%S/g, pad(d.getSeconds())) |
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 xhr(options, success) { | |
var r = new XMLHttpRequest(); | |
r.open(options.method || "GET", options.url, true); | |
r.onreadystatechange = function () { | |
if (r.readyState != 4 || r.status != 200) return; | |
success(r.responseText, r); | |
}; | |
r.send(options.data || null); | |
} |
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
// Color interpolation | |
// Usage: | |
// var myGradient = Gradient([ | |
// [50, "#9999ff"], | |
// [100, "#99ff99"], | |
// [150, "#ff9999"] | |
// ]); | |
// myGradient(75); // returns "#99cccc" | |
define([], function () { |
NewerOlder