Skip to content

Instantly share code, notes, and snippets.

View CGamesPlay's full-sized avatar
:bowtie:

Ryan Patterson CGamesPlay

:bowtie:
View GitHub Profile
@CGamesPlay
CGamesPlay / cva.tsx
Last active August 22, 2024 17:10
CVA prop splitting
import { cva } from "cva";
export * from "cva";
type Base = Parameters<typeof cva<unknown>>[0];
type Config<T> = Parameters<typeof cva<T>>[1];
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
type Props<T> = Simplify<
Omit<
Exclude<Parameters<ReturnType<typeof cva<T>>>[0], undefined>,
@CGamesPlay
CGamesPlay / dynamicComponent.test.tsx
Last active August 22, 2024 14:22
Component factory that enables "as" props.
import * as React from "react";
import { expect, test } from "vitest";
import { makeDynamicComponent } from "./dynamicComponent";
type NoProps = object;
const ComponentA1 = (_: { req: "a"; opt?: "a" }) => null;
const ComponentA2 = (_: { req: "a"; opt?: "a" }) => null;
const ComponentB = (_: { req: "b"; opt?: "a" }) => null;
const ComponentC = (_: { opt?: "a" }) => null;
@CGamesPlay
CGamesPlay / import.py
Created December 14, 2024 00:58
Migrate Obsidian (or markdown directory) to Anytype markdown import
#!/usr/bin/env python3
# /// script
# dependencies = [
# "mistune==3.0.2",
# ]
# ///
import os
import sys
import hashlib
@CGamesPlay
CGamesPlay / repro.html
Created July 23, 2025 03:29
Safari Animation.commitStyles() CSP Bug
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Safari Animation.commitStyles() CSP Bug</title>
<!-- CSP that triggers the bug - style-src-attr 'self' only -->
<meta http-equiv="Content-Security-Policy" content="style-src-attr 'self'">
//! Proof of concept of a tokio::sync::watch-style channel with WeakSender support
//! Copyright Ryan Patterson - MIT license
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc, RwLock, RwLockReadGuard, TryLockError, Weak,
};
use tokio::sync::Notify;
/// Thread-safe reference-counted reader-writer lock with change notification.
///