Skip to content

Instantly share code, notes, and snippets.

View ardislu's full-sized avatar

Ardis Lu ardislu

View GitHub Profile

How to fix winget taking a long time to extract archive

Problem

Using winget to install programs with large archives (e.g., zig.zig) takes a long time and appears to hang:

PS> winget install zig.zig
Found Zig [zig.zig] Version 0.14.0
This application is licensed to you by its owner.

Modern versions of WSL2 can run GUI applications out of the box via WSLg.

  1. Install desired GUI application:
sudo apt install nautilus -y
  1. Run it:
@ardislu
ardislu / webStreamsQueuingStrategy.js
Last active March 19, 2025 05:44
Demonstration of queuing strategy for Streams API
// Demonstration of queuing strategy for Streams API
// $ node ./webStreamsQueuingStrategy.js
export { }; // Intentional unused export to force "type: module" on .js file
// These strategies are equivalent
const basicStrategy = {
highWaterMark: 3, // If no .size() specified, default is .size() === 1 (CountQueuingStrategy)
// size(chunk) { return 1; } // Implied
};
@ardislu
ardislu / getPseudoRandomValues.js
Last active January 3, 2025 06:47
Simple, small, and fast pseudorandom number generator to deterministically generate large amounts of mock test data.
/**
* Simple, small, and fast pseudorandom number generator to deterministically generate large amounts of mock test data.
*
* API is intended to follow [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues).
*
* Hash function source:
* - https://burtleburtle.net/bob/hash/integer.html
* - https://web.archive.org/web/20090408063205/http://www.cris.com/~Ttwang/tech/inthash.htm
* @param {ArrayBufferView<ArrayBufferLike>} typedArray An integer-based `TypedArray` with a byte length that is a multiple of 4.
* All elements in the array will be overwritten with random numbers.

How to change your last git commit's CommitDate and AuthorDate

  1. Show the last git commit and confirm it's the one you want to edit:
$ git log -n 1 --pretty=fuller
commit 0000000000000000000000000000000000000000 (HEAD -> main)
Author:     First Last <[email protected]>
AuthorDate: Tue Nov 26 01:01:01 2024 -0800
Commit: First Last 
@ardislu
ardislu / debounce.js
Created September 13, 2024 02:28
Minimal debounce function and example in JavaScript.
// Minimal debounce function:
function debounce(fn, wait) {
let timeoutId;
return (...args) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => fn(...args), wait);
}
}
// Minified:

Beware unexpected overloading in JavaScript array functions

What's the difference between these two?

['1', '2', '3'].map(n => parseInt(n)); // Function 1
['1', '2', '3'].map(parseInt); // Function 2

Let's see the output:

@ardislu
ardislu / minimal-form-values.html
Last active September 1, 2024 23:43
A minimal example of the most concise way to get the values from a vanilla HTML `<form>` element and assign the values to JavaScript variables in 2024. Notice that the object keys are based on the `<input>`'s `name` attribute and not `id`.
<form>
<input name="ex1">
<input name="ex2">
<input name="example-with-hypens">
<button>Submit</button>
</form>
<script>
document.querySelector('form').addEventListener('submit', e => {
e.preventDefault();
@ardislu
ardislu / batchJsonRpcDestructure.js
Created August 12, 2024 06:45
Example of making a batch JSON-RPC request and concisely destructuring the response by (ab)using the JSON-RPC id as the variable name.
const rpc = 'https://ethereum.publicnode.com';
const to = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
const requests = {
name: '0x06fdde03',
symbol: '0x95d89b41',
decimals: '0x313ce567',
totalSupply: '0x18160ddd'
}
const payload = [];
for (const [id, data] of Object.entries(requests)) {
@ardislu
ardislu / ModExp.sol
Created August 1, 2024 04:37
Minimal example of calling the `modexp` precompile (0x05) using Solidity.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract ModExp {
function modExp(bytes calldata base, bytes calldata exponent, bytes calldata modulus) public returns (bytes memory) {
(, bytes memory result) = address(5).call(abi.encodePacked(base.length, exponent.length, modulus.length, base, exponent, modulus));
return result;
}
function example() external returns (bytes memory) {