Skip to content

Instantly share code, notes, and snippets.

@snipsnipsnip
snipsnipsnip / awaitable.ts
Last active October 8, 2025 08:36
lazy_then.ts caches the promise content and calls continuation with it async-transparently
//! SPDX-License-Identifier: Apache-2.0
//! https://snipsnipsnip.github.io
/** A value or a promise of it */
export type Awaitable<T> = T | Promise<T>
/**
* Caches a value that is initialized asynchronously.
* Returned closure produces `Promise<T>` on first call, then `T` __synchronously__ on subsequent calls.
* @param init initializer function that returns a `Promise<T>` to be cached
@snipsnipsnip
snipsnipsnip / typedoc-custom.cjs
Last active October 7, 2025 00:27
typedoc-custom.cjs applies mermaid to markdown files included as projectDocuments which somehow don't work well with typedoc-plugin-mermaid
"use strict";
let nodes = document.querySelectorAll('code.mermaid');
let maybe = nodes.length === 0 ? null : import('https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs');
maybe?.then(({ default: mermaid }) => mermaid.run({ nodes }));
// SPDX-License-Identifier: CC0-1.0
// https://github.com/snipsnipsnip/
@snipsnipsnip
snipsnipsnip / restore-source-from-plantuml-svg.pl
Last active September 16, 2025 09:53
I've accidentally deleted a PlantUML file but luckily SVG output had them embedded
#!/usr/bin/perl
use v5.36;
use autodie;
use HTML::TokeParser ();
use MIME::Base64 qw(encode_base64 decode_base64);
use Compress::Zlib qw(deflateInit inflateInit);
main() if $0 eq __FILE__;
sub main() {
@snipsnipsnip
snipsnipsnip / peekable_async_iterator.ts
Last active September 17, 2025 06:25
reusingRace<A,B>(factoryA: () => Promise<A>, factoryB: () => Promise<B>): () => Promise<A | B>
//! SPDX-License-Identifier: Apache-2.0
//! snipsnipsnip.github.io
// See also: https://doc.rust-lang.org/std/iter/struct.Peekable.html
export class PeekableAsyncIterator<T, TReturn> implements AsyncIterator<T, TReturn, undefined> {
private last: Promise<IteratorResult<T, TReturn>> | undefined
constructor(private readonly wrapped: AsyncIterator<T, TReturn, undefined>) {}

*Locating Specific Docs*

I've successfully found the documentation for light_ranged_integers version 0.1.3. The new function is of particular interest, as it returns a Result. I'm now reviewing the possible error types defined within RangedIntError.

*Resolving Result Import*

I've pinpointed the issue: the compiler can't find unwrap because the Result type isn't std::result::Result. It's a custom type defined by the crate. My next step is to import the custom Result type, anticipating that this will fix the problem. I am now trying to use unwrap() once again.

*Considering the Failures*

I'm facing a complete meltdown. My Rust code attempts have been abysmal, a string of failures. The immediate next step involves a comprehensive error summary before admitting defeat. The initial hurdle: a frustrating unresolved import error.

*Accepting Defeat*

\n\n

{
"address": "0x9b2aaaf663839d09907bff786f9796c582c2fb9b",
"msg": "Hi, I'm https://github.com/snipsnipsnip/",
"sig": "0x8ad0bbb248ad8d33f1025245e2bad57030156337dd426ae003a9209efc54af4f06f29318f7c201c83e3fd57793376089bfd006c4b51deaed55b663ad5ccbe46f1c",
"version": "2"
}
@snipsnipsnip
snipsnipsnip / chrome-i18n.js
Last active January 11, 2020 11:37 — forked from eligrey/chrome-i18n.js
Easy i18n for your Chrome extensions and apps' DOM.
/*
* A cut-down i18n utility. @snipsnipsnip
* Based on Chrome DOM i18n By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
"use strict";
for (let e of document.querySelectorAll("[data-i18n]")) {
@snipsnipsnip
snipsnipsnip / kill-steamvr.bat
Created August 6, 2019 03:26
kill-steamvr.bat
@taskkill /f /im vr*
@snipsnipsnip
snipsnipsnip / autozip.rb
Created June 9, 2019 13:16
autozip.rb is a 7za wrapper extracts/archives any zips/folders (respectively) put in the working directory
# frozen-string-literal: true
require 'fileutils'
require 'shellwords'
require 'date'
Outdir = 'out'
def run(cmd)
puts "!#{cmd}"
system cmd
@snipsnipsnip
snipsnipsnip / trac-update-field.py
Last active April 20, 2019 09:19
trac-update-field.py writes a single field with xmlrpc
from __future__ import annotations
from xmlrpc.client import Transport, ServerProxy
import sys
import typing
if typing.TYPE_CHECKING:
import http.client
from typing import Dict, List, Tuple, Optional