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
const { promisify } = require('util'); | |
const exec = promisify(require('child_process').exec); | |
/** Returns a random byte as a floating-point decimal between 0 and 1. */ | |
async function random() { | |
const payload = await exec(`gpg-connect-agent "SCD RANDOM 1" /bye`); | |
const randomBytes = payload.stdout.split('\n')[0].substr(2); | |
const buffer = Buffer.from(randomBytes, 'utf-8'); | |
const number = buffer.readUIntBE(0, 1); |
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
/// This class extends [SizedBox] whilst implementing [PreferredSizeWidget] | |
/// based on the defined size. This allows the use of [SizedBox] in places | |
/// where [PreferredSizeWidget] is required, such as in [AppBar.preferredSize]. | |
class PreferredSizedBox extends SizedBox implements PreferredSizeWidget { | |
const PreferredSizedBox({super.key}); | |
const PreferredSizedBox.shrink({super.key, super.child}) : super.shrink(); | |
const PreferredSizedBox.expand({super.key, super.child}) : super.expand(); | |
PreferredSizedBox.fromSize({super.key, super.child, super.size}) | |
: super.fromSize(); |
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
/** | |
* This is a TypeScript version of the `Completer` class from Dart. | |
* | |
* A `Completer` provides a future that can be imperatively concluded (once and | |
* only once) with either `#complete` or `#completeError`. | |
* Once the completer has completed (or errored), the future will be resolved | |
* with the specified value. | |
* | |
* This is trivially implemented by instantiating a Promise and capturing the | |
* resolve and reject functions. |
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 extension that adds the [chunked] method to a [Stream] of [List]s, to | |
/// allow dividing that [Stream] of (potentially) arbitrarily sized [List]s into | |
/// a stream of fixed sized [List]s. | |
extension ChunkedStream<T> on Stream<List<T>> { | |
/// Convert the stream to a chunked stream, where each chunk is of the given | |
/// [size]. The size of each chunk must be at least one, but the size may be | |
/// any number larger than one (if the stream is finished before a chunk is | |
/// finished, that chunk is returned as-is). | |
Stream<List<T>> chunked(final int size) async* { | |
if (size < 1) { |
OlderNewer