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 / useStateWithReactiveInput.ts
Last active March 11, 2024 13:10
Reactive `useState` variant
import React from 'react'
/**
* A variant of `React.useState` which allows the `inputState` to change over time as well.
* Important: This hook is synchronous / single-render-pass (i.e. doesn't use `useEffect` or `setState` directly).
*
* Notes:
* - The output state is always reset to the input state in case the input state changes (i.e. the previous "external" `setStateAndRerender` call is forgotten)
* - This hook might not work properly with React Suspense
* - Also see this Tweet for more potential problems: https://twitter.com/schickling/status/1677317711104278528
import React from 'react'
const PR = Math.round(window.devicePixelRatio || 1)
const FRAME_BAR_WIDTH = 2
export type FPSMeterProps = {
width?: number
height?: number
systemFps?: number
@schickling
schickling / UIImageFixedOrientationExtension.swift
Last active February 4, 2024 15:00
Extension to fix orientation of an UIImage (Sets orientation to portrait)
extension UIImage {
func fixedOrientation() -> UIImage {
if imageOrientation == UIImageOrientation.Up {
return self
}
var transform: CGAffineTransform = CGAffineTransformIdentity
@schickling
schickling / Rakefile
Last active January 31, 2024 23:00
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)
@schickling
schickling / flake.nix
Created January 18, 2024 15:15
Node.js 16 Nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-23.11";
nixpkgsOld.url = "github:NixOS/nixpkgs/release-23.05";
nixpkgsUnstable.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, nixpkgsOld, nixpkgsUnstable, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
@schickling
schickling / _README.md
Last active January 4, 2024 09:37
Script to import and export docker-machine configurations to sync between hosts/collaborators

docker-machine import/export

Script to import and export docker-machine configurations to sync between hosts/collaborators

Export (on host A)

$ docker-machine ls
NAME       ACTIVE   DRIVER         STATE     URL                            SWARM   DOCKER    ERRORS
dev        -        digitalocean   Running   tcp://example.com:2376                 v1.10.1
import { describe, expect, it } from 'vitest'
import { Equal } from '../index.js'
import * as Schema from './index.js'
import { JsonWrapper, jsonWrapper } from './SchemaJsonWrapper.js'
describe('wrapper', () => {
it('wrapper', () => {
const wrapped = jsonWrapper(Schema.number)
const decoded = Schema.parseSync(wrapped)(10)
/* eslint-disable prefer-arrow/prefer-arrow-functions */
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
/// <reference lib="dom" />
import type { RuntimeFiber } from '@effect/io/Fiber'
import * as FiberRef from '@effect/io/FiberRef'
import * as Scheduler from '@effect/io/Scheduler'
@schickling
schickling / flake.nix
Created September 28, 2023 13:00
Node.js 16 Nix flake
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
import type { Otel, Scope } from '@overtone/utils/effect'
import { Duration, Effect, Either, pipe, Request, RequestResolver } from '@overtone/utils/effect'
export type MakeArgs<TTag extends string, C, E, A, E2, A2> = {
tag: TTag
fetchResources: (resourceIds: ReadonlyArray<string>) => Effect.Effect<C, E, A[]>
mapResult?: (fetchedResources: A) => Either.Either<E2, A2>
batchTimeoutMs?: number
batchCapacity: number
cache?: {