Skip to content

Instantly share code, notes, and snippets.

View hasparus's full-sized avatar

Piotr Monwid-Olechnowicz hasparus

View GitHub Profile
@hasparus
hasparus / @changesets__assemble-release-plan@5.2.3.patch
Last active August 31, 2023 13:06
a bit wasteful CI/CD setup with PR snapshot release and automerged Changesets on main
diff --git a/dist/assemble-release-plan.cjs.dev.js b/dist/assemble-release-plan.cjs.dev.js
index 3a37c62c975518f975c22e1b4b3974d9b325a5da..cc7b4669526b9ccddcf184f52f8cb5225cc8284e 100644
--- a/dist/assemble-release-plan.cjs.dev.js
+++ b/dist/assemble-release-plan.cjs.dev.js
@@ -132,16 +132,38 @@ function determineDependents({
} of dependencyVersionRanges) {
if (nextRelease.type === "none") {
continue;
- } else if (shouldBumpMajor({
- dependent,
import { ReactRenderer, StoryObj } from '@storybook/react'
import { ComponentAnnotations } from '@storybook/types'
import { describeStories } from './tiniest-storybook-test-suites'
import * as stories from './MyComponent.stories'
describeStories(stories)
@hasparus
hasparus / generator.ts
Last active April 27, 2022 08:12
freebooter-generator/lib
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// generator.js
// written and released to the public domain by drow <drow@bin.sh>
// http://creativecommons.org/publicdomain/zero/1.0/
// Adapted and rewritten to TypeScript by hasparus <hasparus@gmail.com>
// - used PRNG instead of Math.random
// - added context and `ctx -> text` functions
import { random } from "./random";
@hasparus
hasparus / #All Stories Actually Render the Component.md
Last active April 22, 2022 10:26
ensure all stories render the component they describe

It's easy to overlook that your component stories stopped working after changes to the component source. If we're not reusing our stories in unit tests and thus ensure they still work on CI in every Pull Request, we need to remember to check them during code review.

When you're hotfixing a production bug you have more serious concerns than not breaking the docs. That's understandable. Every app I worked on that used Storybook eventually had some broken stories. Fixing them lands at the bottom of the backlog; they're just some component examples and those components work on production now! You're going to do it only if you actually need those stories.

const UNEXPECTED_ACCESS = Symbol() as never
export function throwsOnUnexpectedAccess<T extends object>(target: T): T {
return new Proxy(target, {
get: (target, key) => {
const value = target[key as keyof typeof target]
if (value === UNEXPECTED_ACCESS) {
throw new Error(`Unexpected access to "${String(key)}"`)
}
return value
},
@hasparus
hasparus / windows-auto-darkmode.ps1
Last active April 20, 2024 17:39
A PowerShell script setting light mode during the day and dark mode after 18:30.
# Set your triggers to 06:00, log in, and 18:30.
# Set this to false if you like light Windows UI.
# Personally, I'm conflicted so I change it back and forth every few months.
$SYSTEM_ALWAYS_DARK = $TRUE
$lightTheme = @{ AppsUseLightTheme = 1; SystemUsesLightTheme = 1 }
$darkTheme = @{ AppsUseLightTheme = 0; SystemUsesLightTheme = 0 }
# We set light mode between 06:00 and 18:30.
@hasparus
hasparus / compare-jest-snapshots-between-files.ts
Created August 11, 2021 08:06
When you rename a test file the snapshot name changes and the old snapshot is declared obsolete. Thankfully, as Jest snapshots are JS files exporting a bunch of strings, we can compare them with a simple script instead of going through them by hand.
function requireSnapshots(paths: string[]) {
const map = new Map<string, string>()
for (const path of paths) {
const module = require(path)
for (const name of Object.keys(module)) {
if (map.has(name)) {
throw new Error(`Conflict on snapshot "${name}" in ${paths}`)
}
map.set(name, module[name])
@hasparus
hasparus / Microsoft.Powershell_profile.ps1
Last active May 26, 2022 17:13
A guide on setting up on new laptops for future me, and a manifest of all the tools I installed.
# Git Completions
Import-Module posh-git
# Prompt
Invoke-Expression (&starship init powershell)
# Aliases
Set-Alias g git
# Utils
// TypeScript Playground: https://tsplay.dev/mq8eYN
/// <reference types="@types/jest" />
import type { MatcherState } from 'expect';
const matchers = {
toHaveWordsCount(this: MatcherState, sentence: string, wordsCount: number) {
// implementation redacted
},
// Imagine that @prisma/client is a normal library and it doesn't have different types in userspace and libraries
import {GetEvents, LogDefinition, LogLevel, PrismaClient, PrismaClientOptions} from "@prisma/client"
import {exec} from "child_process"
interface EnhancedPrismaClient<
// TypeScript doesn't have higher (i.e. * -> * -> *) order types, so
// we can't use anything like ConstructorParameters<typeof PrismaClient>,
// because ConstructorParameter will "strip" generics.
//
// The only way to preserve generic parameters is to copy them.