Skip to content

Instantly share code, notes, and snippets.

View VldMrgnn's full-sized avatar
🏠
working

Vlad VldMrgnn

🏠
working
  • Bucharest Romania
View GitHub Profile
@cowboyd
cowboyd / 01-client.ts
Created March 10, 2024 16:48
Model a remote iterable using `EventSource` and Effection
import { main } from "npm:[email protected]";
import { useEventStream } from "./use-event-stream.ts";
// consume the server as an interable.
await main(function* () {
let source = yield* useEventStream<number, string>("http://localhost:8000");
let next = yield* source.next();
@cowboyd
cowboyd / heartbeat.ts
Last active November 7, 2023 17:12
Run an operation on a heartbeat, only one operation at a time
import {
call,
createSignal,
each,
type Operation,
spawn,
type Stream,
suspend,
} from "effection";
@veekaybee
veekaybee / normcore-llm.md
Last active April 27, 2025 07:05
Normcore LLM Reads

Anti-hype LLM reading list

Goals: Add links that are reasonable and good explanations of how stuff works. No hype and no vendor content if possible. Practical first-hand accounts of models in prod eagerly sought.

Foundational Concepts

Screenshot 2023-12-18 at 10 40 27 PM

Pre-Transformer Models

@cowboyd
cowboyd / use-handler.tsx
Last active February 4, 2023 22:59
A hypothetical restartable operation for @effection/react
import { useCallback, useMemo } from 'react';
import { Task, Operation, createQueue, spawn } from 'effection';
import { useOperation } from './use-operation';
/**
* Create an event handler that can be used for UI events safely.
* If the handler is invoked more than once, the existing task is halted
* and a new one is spawned. E.g.
*
* const AutoCompleter = ({ searchFn }) => {
//========== .split() with lookbehind ==========
// Downside: Safari doesn’t support lookbehind
import * as assert from 'node:assert/strict';
const RE_SPLIT_AFTER_EOL = /(?<=\r?\n)/;
function splitLinesWithEols1(str) {
return str.split(RE_SPLIT_AFTER_EOL);
}

Minimalist Layout System

This super simple, fast, flexible layout system operates in a single pass (no reflow or constraint solving) and is probably <100 lines of non-comment, non-duplicate logic (there's a lot of duplicate logic between the top/left/right/bottom directional code that's not worth de-duplicating).

To layout PinLayout's Example 1:

pinlayout example 1

The code is much simpler than PinLayout's:

/**
* Export all data from an IndexedDB database
*
* @param {IDBDatabase} idbDatabase The database to export from
* @return {Promise<string>}
*/
export function exportToJson(idbDatabase) {
return new Promise((resolve, reject) => {
const exportObject = {}
if (idbDatabase.objectStoreNames.length === 0) {
@yelouafi
yelouafi / algebraic-effects-series-1.md
Last active April 17, 2025 05:09
Operational Introduction to Algebraic Effects and Continuations

Algebraic Effects in JavaScript part 1 - continuations and control transfer

This is the first post of a series about Algebraic Effects and Handlers.

There are 2 ways to approach this topic:

  • Denotational: explain Algebraic Effects in terms of their meaning in mathematics/Category theory
  • Operational: explain the mechanic of Algebraic Effects by showing how they operate under a chosen runtime environment

Both approaches are valuables and give different insights on the topic. However, not everyone (including me), has the prerequisites to grasp the concepts of Category theory and Abstract Algebra. On the other hand, the operational approach is accessible to a much wider audience of programmers even if it doesn't provide the full picture.

@yelouafi
yelouafi / delimited-continuations.js
Last active March 21, 2025 18:59
delimited continuations using javascript generators
// We model the call stack using a linked list of Generators
// Each Generator has a _return field pointing back to its parent
function stepGen(gen, arg) {
const {done, value} = gen.next(arg)
if(done) {
if(gen._return) {
stepGen(gen._return, value)
}
@pcan
pcan / README.md
Last active April 3, 2025 02:58
Node.js plain TLS Client & Server, 2-way Cert Auth

Node.js TLS plain TLS sockets

This guide shows how to set up a bidirectional client/server authentication for plain TLS sockets.

Newer versions of openssl are stricter about certificate purposes. Use extensions accordingly.

Prepare certificates

Generate a Certificate Authority: