Skip to content

Instantly share code, notes, and snippets.

View cshaa's full-sized avatar
💭
what kind of cow does oat milk come from... ?

Michal cshaa

💭
what kind of cow does oat milk come from... ?
View GitHub Profile
class Mutex<T> {
#locked = false
#waiters: (() => void)[] = []
#value: T
constructor(value: T) {
this.#value = value
}
lock(): Promise<MutexLock<T>> {
class ResultClass<IsOk extends boolean, OkType, ErrType> {
constructor(
/**
* For `Ok(value)` returns `true`; for `Err(value)` returns `false`.
*/
public readonly isOk: IsOk,
/**
* For `Ok(value)` returns `value`; for `Err(value)` returns `undefined`.
*/
@cshaa
cshaa / browser.js
Created May 20, 2025 19:23
Copy a paragraph from PDF, correctly remove hyphenation, and paste the result into VS Code
addEventListener('keyup', async (e) => {
if (e.key !== 'x') return;
if (!e.ctrlKey) return;
const text = await navigator.clipboard.readText();
await navigator.clipboard.writeText(text.replaceAll("-\n", "").replaceAll("\n", " ") + "\n\n")
})
@cshaa
cshaa / argus-schema.json
Created January 31, 2025 23:56
Release Argus – JSON Schema for config.yml
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"settings": {
"type": "object",
"properties": {
"log": {
"type": "object",
"description": "Logging settings for the application.",
const objToKeysDeep = (obj: object, prefix = ""): string[] =>
Object.entries(obj).flatMap(([key, value]) =>
typeof value === "object"
? objToKeysDeep(value, `${prefix}${key}.`)
: `${prefix}${key}`
);
const missingInLang = async (lang: string) => {
const en = (await import(`./packages/decap-cms-locales/src/en/index.js`))
.default;
@cshaa
cshaa / schema.json
Last active October 23, 2024 08:58
Decap CMS – JSON Schema for config.yml
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"backend": {
"type": "object",
"properties": {
"name": { "type": "string" },
"repo": { "type": "string" },
"branch": { "type": "string" },

Note

This document is an RFC (Request for Comments), and should be treated as a suggestion to the community, and not as an actual standard. If you have any feedback, ideas or implementations you'd like to share regarding Structured Pipes, please feel free to drop these in the comment section below.

Structured Unix Pipes

An inter-process protocol that allows processes to communicate using structured data, much like Nushell's internal commands can. In order for a structured pipe a | b to work, the protocol must be supported by command a, command b, and the shell. The protocol is designed in such a way, that if either of the processes doesn't support structured pipes, communication reverts to ordinary (unstructured) Unix pipes.

Structured pipes pass data in a machine-readable format. Before the data start flowing between the two programs, the shell process asks them which formats they understand, and selects the the most prefered format supported by both.

S

{
"content_metadata": {
"chapter_info": {
"brandIntroDurationMs": 1532,
"brandOutroDurationMs": 3204,
"chapters": [
{
"length_ms": 15928,
"start_offset_ms": 0,
"start_offset_sec": 0,
{
"content_metadata": {
"chapter_info": {
"brandIntroDurationMs": 3924,
"brandOutroDurationMs": 4945,
"chapters": [
{
"length_ms": 22959,
"start_offset_ms": 0,
"start_offset_sec": 0,
@cshaa
cshaa / nat.ts
Last active June 20, 2024 09:33
TypeScript type-level unsigned integer addition – add together two number literals.
declare const Zero: unique symbol;
type Zero = { [Zero]: true };
declare const Succ: unique symbol;
type Succ<T> = { [Succ]: T };
type FirstElementOrZero<Arr extends any[]>
= Arr extends []
? Zero
: Arr[0];