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
| /** | |
| * Balances work between several asynchronous functions. | |
| * Given an array of async functions that make the same computation, | |
| * returns a single function that has the computation made by | |
| * the first idle function. | |
| * | |
| * @template T,U | |
| * @param {((...args:T) => Promise<U>)[]} functions | |
| * @param {boolean?} fifo Whether to process the arguments in fifo or lifo | |
| * @returns {(...args:T) => Promise<U>} |
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
| async function maxCanvasSize(ratio) { | |
| let cvs = document.createElement("canvas"); | |
| let xmin = 1, xmax = 1 << 18; | |
| while (xmax - xmin > 1) { | |
| let x = ((xmin + xmax) / 2) | 0; | |
| let y = (x / ratio) | 0; | |
| if (await canvasTest(cvs, x, y)) xmin = x; | |
| else xmax = x; | |
| } | |
| return [xmin, xmin / ratio | 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
| #!/usr/bin/env python3 | |
| # coding: utf-8 | |
| from functools import reduce | |
| from operator import xor | |
| import struct | |
| aes_inverse_s_box = bytes.fromhex( | |
| '52096ad53036a538bf40a39e81f3d7fb7ce339829b2fff87348e4344c4dee9cb547b9432a6c2233dee4c950b42fac34e082ea16628d924b276' | |
| '5ba2496d8bd12572f8f66486689816d4a45ccc5d65b6926c704850fdedb9da5e154657a78d9d8490d8ab008cbcd30af7e45805b8b34506d02c' | |
| '1e8fca3f0f02c1afbd0301138a6b3a9111414f67dcea97f2cfcef0b4e67396ac7422e7ad3585e2f937e81c75df6e47f11a711d29c5896fb762' |
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
| # My AES implementation | |
| # By Daniel Miller | |
| # Ported to python 3 by @lovasoa | |
| def xor(s1, s2): | |
| return bytes(a ^ b for a, b in zip(s1, s2)) | |
| class AES(object): |
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
| /** | |
| * Multi-level array flattening. Takes an array of arbitrarily deep nested arrays, and returns an array of values. | |
| * It mutates the original array instead of creating a new one. | |
| **/ | |
| function flatten(arr) { | |
| for (let i = 0, inc=1; i < arr.length; i += inc) { | |
| if (Array.isArray(arr[i])) { | |
| const flat = flatten(arr[i]); | |
| arr.splice(i, 1, ...flat); | |
| inc = flat.length; |
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
| async function* fetchChunks(...args) { | |
| let response = await fetch(...args); | |
| let reader = response.body.getReader(), state = {done:false}; | |
| while (!state.done) { | |
| state = await reader.read(); | |
| yield state.value; | |
| } | |
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 -m doctest | |
| from __future__ import annotations | |
| import typing | |
| def f(clazz): | |
| """ | |
| >>> class MyClass: | |
| ... pass | |
| >>> class MyOtherClass: |
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
| /// An iterator where you can look back on items that were already consumed | |
| struct PartiallyConsumedIterator<T, I: Iterator<Item=T>> { | |
| /// Elements that were already consumed | |
| previous: Vec<T>, | |
| /// Elements that still have to be consumed | |
| remaining: I, | |
| } | |
| impl<T, I: Iterator<Item=T>> From<I> for PartiallyConsumedIterator<T, I> { | |
| fn from(iter: I) -> Self { |