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
{ rustPlatform
, fetchCrate
, fetchFromGitHub
, lib
, stdenv
, darwin
}:
let
pname = "tauri-cli";
# https://crates.io/crates/tauri-cli
import type { Effect as T } from '@effect-ts/core'
import { pipe } from '@effect-ts/core'
import * as STM from '@effect-ts/core/Effect/Transactional/STM'
import * as TRef from '@effect-ts/core/Effect/Transactional/TRef'
export * from '@effect-ts/core/Effect/Transactional/STM'
export class Gate {
constructor(readonly ref: TRef.TRef<boolean>) {}
import { Effect as T, pipe } from '@effect-ts/core'
/** Sleeps the specified duration depending on whether the document is hidden or not */
export const sleepBackgroundForegroud = ({
durationHiddenMs,
durationVisibleMs,
}: {
durationHiddenMs: number
durationVisibleMs: number
}) => {
@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(
@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 / 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
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
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 }),
),
{ lib, stdenv, pkgs ? import <nixpkgs> { } }:
let
packages = {
playwright-chromium = pkgs.callPackage ./playwright-chromium.nix { };
};
rev = "1041";
inherit (pkgs.stdenv.hostPlatform) system;
/**
* 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 = [