Skip to content

Instantly share code, notes, and snippets.

View jul-sh's full-sized avatar

jul-sh jul-sh

  • Google DeepMind
  • New York City
  • 02:26 (UTC -05:00)
View GitHub Profile
@jul-sh
jul-sh / skill.md
Created January 9, 2026 18:59
Enum-Driven State: Refactoring and Authoring guides

Enum-Driven State

A behavior-preserving refactor that makes unintended states structurally impossible using Sum Types (Enums, Discriminated Unions, Sealed Classes).


Core Principles

  1. Make Illegal States Unrepresentable: Structure types so invalid combinations cannot compile—no runtime validation or comments needed.
  2. Sum Types over Product Types: Replace structs with optional fields (status, data?, error?) with enums where each variant holds exactly what it needs.
  3. Pattern Matching: Replace boolean checks (if isX) with exhaustive match/switch. Adding a new state forces compiler errors at all call sites.
This skill is expanded to be language-agnostic, anchoring the concept in **Algebraic Data Types (Sum Types)**. This provides the theoretical basis for *why* this prevents bugs (math/cardinality) and provides concrete implementation patterns for modern languages like Rust, TypeScript, Python, and Kotlin.
---
---
## name: enum-driven-state description: Enforce type-safe state modeling using Sum Types (Enums, Discriminated Unions, Sealed Classes) to make invalid states unrepresentable. Refactor parallel booleans, nullable "conditional" fields, and loose flags into exclusive cases with associated data.
# Enum-Driven State (Make Invalid States Unrepresentable)
@jul-sh
jul-sh / SKILL.md
Created January 9, 2026 16:19
Enum-driven state skill for Claude
name description
enum-driven-state
Enforce enum-driven, type-safe state modeling so invalid states are unrepresentable; refactor boolean flags/"isX" helpers and conditional-only fields into enum cases with associated data.

Enum-Driven State (Type-Safe Modeling)

Use this skill when a codebase shows boolean flags, optional fields, or "only valid for X" comments that can be expressed as an enum with associated data. The goal is to make invalid states impossible to represent and to update call sites to match enum cases directly.

Core principles

#!/usr/bin/env python3
"""
Complete Akuvox login + refresh + door open workflow.
Example:
python3 scripts/akuvox_refresh_and_open.py --country-code 1 --phone 2121239876 --subdomain ucloud --sms-code 123456
Steps performed:
1. Resolve the regional REST host and send `sms_login` with the supplied code.
2. Rotate the session token three times using the refresh API.
describe('The `mergeTwoSortedArrays` function', () => {
it('merges two sorted arrays', async () => {
expect(mergeTwoSortedArrays([1, 3, 5, 7], [2, 4, 6, 8, 10])).toEqual([
1,
2,
3,
4,
5,
6,
7,

Keybase proof

I hereby claim:

  • I am juliettepretot on github.
  • I am julsh (https://keybase.io/julsh) on keybase.
  • I have a public key ASCrf6x-EPPgpQBkXusyDW9hdVYuw3PbjbR8ZJqsTylVAQo

To claim this, I am signing this object:

@jul-sh
jul-sh / useObjectToKey.js
Last active February 11, 2020 11:14
The goal of this hook is to provide an alternative to using indexes as keys in react. Instead, what if we could use the object references as keys. Since React only accepts strings as keys, let's associate string keys to object references.
import React from 'react'
import { render } from 'react-dom'
/*
The goal of this hook is to provide an alternative to using indexes as
keys in react. Instead, what if we could use the object references as keys.
Since React only accepts strings as keys, let's associate string keys to
object references.
@jul-sh
jul-sh / about.md
Last active February 9, 2019 19:04
connectHooks

I'm not sure a HoC for hooks is a good idea, but it seemed fun to build. Also, it may come in handy when adding new code to old components.

Use like so:

export default connectHooks([
  {
    hook: useFetch,
 hookArgs: ["https://swapi.co/api/people/1"],
function fish_prompt
set -l last_status $status
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o AE111D)
set -l blue (set_color -o blue)
set -l green (set_color -o green)
if not set -q __fish_git_prompt_show_informative_status
set -g __fish_git_prompt_show_informative_status 1
import { useState, useEffect } from 'react'
// Use this hook to quickly read whether a component is being rendered server
// side or client-side. This can be helpful when building components that are
// intended to work without client-side JavaScript.
// Use like:
// const isMounted = useIsMounted()
const useIsMounted = () => {