Skip to content

Instantly share code, notes, and snippets.

View schickling's full-sized avatar
Making the web better

Johannes Schickling schickling

Making the web better
View GitHub Profile
@schickling
schickling / flake.nix
Last active April 10, 2023 08:54
WASM Nix build script
# ...
# nix run .#wasm-packages
apps.wasm-packages = {
type = "app";
program = toString (pkgs.writeShellScript "wasm-packages" ''
${wasmPackScript { packageName = "somepkg-wasm"; }}/bin/wasmPackScript
'');
};
@schickling
schickling / WorkerCodec.ts
Created April 3, 2023 14:22
Worker codec refactor attempt
import type { Either } from '@mytunes/utils/effect2'
export type HasTag<T = {}> = { _tag: string } & T
// NOTE implementations using `AnyWorkerCodec` might be unsafe
// export type AnyWorkerCodec = WorkerCodec<AnyIWorkerCodec>
export type AnyWorkerCodec = WorkerCodec<any>
// export type AnyWorkerCodec = WorkerCodec<any, any, any, any, any, any, any, any>
export type AnyIWorkerCodec = IWorkerCodec<any, any, any, any, any, any, any, any>
@schickling
schickling / blob.ts
Created April 1, 2023 09:52
blob <> file[] encoding
// export const encodeFilesToBlob = (files: File[]): Promise<Blob> => {
// const formData = new FormData()
// files.forEach((file) => {
// formData.append('files[]', file, file.name)
// })
// return new Response(formData).blob()
// }
/**
* Structure:
* First 4 bytes: number of files
* Middle section: Array of file sizes (in bytes) relative to the order of the `files` array
* End section: Array of file name lengths (in bytes) relative to the order of the `files` array
*
* Array of file sizes (in bytes) relative to the order of the `files` array with the first element being the number of files.
* Encoded as a Uint32Array (so each element has to be less than 2^32 ~ 4GB)
*
* e.g. for files = [
{ lib, stdenv, pkgs ? import <nixpkgs> { } }:
let
packages = {
playwright-chromium = pkgs.callPackage ./playwright-chromium.nix { };
};
rev = "1041";
inherit (pkgs.stdenv.hostPlatform) system;
import * as msgpack from 'msgpackr'
import { OT, pipe, T, Tagged } from './index.js'
export const fetchHead = (url: string | URL, headers?: HeadersInit): T.Effect<OT.HasTracer, FetchHeadError, Response> =>
pipe(
T.tryCatchPromise(
() => fetch(url as any, { method: 'head', headers }),
(error) => new FetchHeadError({ url, error }),
),
import React from 'react'
const PR = Math.round(window.devicePixelRatio || 1)
const FRAME_BAR_WIDTH = 2
export type FPSMeterProps = {
width?: number
height?: number
resolutionInMs?: number
@schickling
schickling / FPSMeter.tsx
Last active January 24, 2023 21:07
FPS Meter Canvas
import React from 'react'
const PR = Math.round(window.devicePixelRatio || 1)
const FRAME_BAR_WIDTH = 2
export type FPSMeterProps = {
width?: number
height?: number
resolutionInMs?: number
@schickling
schickling / demo-todo-app.spec.ts
Created January 15, 2023 17:59
Playwright example
import { type Page, expect, test } from '@playwright/test'
test.beforeEach(async ({ page }) => {
await page.goto('https://demo.playwright.dev/todomvc')
})
const TODO_ITEMS = ['buy some cheese', 'feed the cat', 'book a doctors appointment']
test.describe('New Todo', () => {
test('should allow me to add todo items', async ({ page }) => {
@schickling
schickling / bufferUpTo.ts
Created December 30, 2022 21:02
bufferUpTp.ts
import { Cause, Chunk, Effect as T, Exit as Ex, Managed as M, Option as O, pipe, Queue as Q } from '@effect-ts/core'
import * as S from '@effect-ts/core/Effect/Experimental/Stream'
import * as CH from '@effect-ts/core/Effect/Experimental/Stream/Channel'
export const bufferUpTo =
(n: number) =>
<R, E, A>(stream: S.Stream<R, E, A>) => {
const queue = toQueueOfElements_(stream, n)
return new S.Stream(