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
pragma solidity ^0.8.0; | |
function keccak256_2(bytes memory data) external pure returns (bytes32) { | |
bytes32 h1 = keccak256(data); | |
bytes32 h2; | |
/// @solidity memory-safe-assembly | |
assembly { | |
mstore(0, h1) | |
h2 := keccak256(0, 32) | |
} |
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
export async function* concurrently<T>(...gs: AsyncGenerator<T, void>[]): AsyncGenerator<T, void> { | |
const k = (i: number) => (res: IteratorResult<T>) => [i, res] as const; | |
const running = new Set(gs); | |
try { | |
const ps = gs.map((g, i) => g.next().then(k(i))); | |
const queue = new Set(ps); | |
while (queue.size > 0) { | |
const [i, res] = await Promise.race(queue); | |
const g = gs[i]!; | |
queue.delete(ps[i]!); |
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
export async function* chain<T, U>(g: AsyncGenerator<T, void>, f: (x: T) => AsyncGenerator<U, void>): AsyncGenerator<U, void> { | |
type R<I> = IteratorResult<I extends number ? U : T, void>; | |
type IR<I> = [I, R<I>]; | |
const k = <I>(i: I) => (res: R<I>): IR<I> => [i, res]; | |
const running = new Set<AsyncGenerator<unknown, void>>([g]); | |
let p = g.next().then(k(null)); | |
const ps: Promise<IR<number>>[] = []; | |
const gs: AsyncGenerator<U, void>[] = []; | |
const queue = new Set<Promise<IR<null> | IR<number>>>([p]); | |
try { |
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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.16; | |
import "./StateMachines.sol"; | |
contract Pausable is StateMachines { | |
StateMachine m = initial("unpaused"); | |
event Paused(bool paused); |
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
npm ls $(jq -r '.packages | to_entries[] | select(.value.deprecated != null) | .key | split("node_modules/")[-1]' package-lock.json) |
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
// larger buffer => faster | |
const BUFFER_SIZE = 1024; | |
let buffer; | |
/** | |
* @param {string} text | |
* @returns {number} | |
*/ | |
function utf8Length(text) { |
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
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.17; | |
function isAsciiPrintableShortString(string memory str) pure returns (bool) { | |
unchecked { | |
uint256 b = uint256(bytes32(hex"0101010101010101010101010101010101010101010101010101010101010101")); | |
bytes32 chars = bytes32(bytes(str)); | |
uint256 len = bytes(str).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
"use strict"; | |
const defaultOptions = { | |
reverse: true, | |
python: false | |
} | |
function merge(sequences) { | |
let result = []; | |
sequences = sequences.map(s => s.slice()); |
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 Std.Data.Nat.Lemmas | |
import Std.Tactic.Omega | |
import Std.Tactic.Simpa | |
def fib (n : Nat) := | |
match n with | |
| 0 | 1 => n | |
| n' + 2 => fib (n' + 1) + fib n' | |
def fastfib (n : Nat) := loop n 1 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
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.13; | |
import {Test} from "forge-std/Test.sol"; | |
contract SwapTest is Test { | |
event Gasused(uint); | |
event Swap( | |
bytes32 indexed id, |