Skip to content

Instantly share code, notes, and snippets.

@pfftdammitchris
pfftdammitchris / snippet-5.ts
Created July 9, 2026 18:09
TypeScript Discriminated Unions: Make Illegal States Unrepresentable - snippet-5.ts
type UserState =
| { status: 'loading' }
| { status: 'success'; data: User }
| { status: 'error'; error: Error }
| { status: 'refreshing'; data: User } // new
@pfftdammitchris
pfftdammitchris / snippet-6.ts
Created July 9, 2026 18:09
TypeScript Discriminated Unions: Make Illegal States Unrepresentable - snippet-6.ts
function assertNever(value: never): never {
throw new Error(`Unhandled state: ${JSON.stringify(value)}`)
}
function renderUser(state: UserState): string {
switch (state.status) {
case 'loading':
return 'Loading…'
case 'success':
return `Welcome, ${state.data.name}`
@pfftdammitchris
pfftdammitchris / snippet-7.ts
Created July 9, 2026 18:09
TypeScript Discriminated Unions: Make Illegal States Unrepresentable - snippet-7.ts
type CheckoutState =
| { step: 'cart'; items: CartItem[] }
| { step: 'shipping'; items: CartItem[]; address: Address }
| { step: 'payment'; items: CartItem[]; address: Address; method: PayMethod }
| { step: 'confirmed'; orderId: string }
type CheckoutAction =
| { type: 'addAddress'; address: Address }
| { type: 'addPayment'; method: PayMethod }
| { type: 'confirm'; orderId: string }
@pfftdammitchris
pfftdammitchris / snippet-8.ts
Last active July 9, 2026 18:09
TypeScript Discriminated Unions: Make Illegal States Unrepresentable - snippet-8.ts
// Bad: `status` is `string`, so TypeScript can't narrow
interface Loose { status: string; data?: User }
// Good: literal union enables narrowing
type Tight = { status: 'idle' } | { status: 'ready'; data: User }
@immoreel
immoreel / reddit-compact.user.js
Created July 9, 2026 18:09
Reddit Compact CPR - old.reddit.com in de oude compact-stijl (fork van dlmarquis/reddit-compact-tm)
// ==UserScript==
// @name Reddit Compact CPR
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Revive Reddit Compact with a site skin
// @author palenerd
// @match https://old.reddit.com/*
// @grant none
// ==/UserScript==
---
apiVersion: v1
kind: Namespace
metadata:
name: castai-agent
---
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: castai-helm
@choco-bot
choco-bot / Install.txt
Created July 9, 2026 18:08
ExpressionBlend3 v1.0.1340.0 - Failed - Package Tests Results
2026-07-09 18:02:11,999 856 [DEBUG] - XmlConfiguration is now operational
2026-07-09 18:02:13,504 856 [DEBUG] - Adding new type 'CygwinService' for type 'IAlternativeSourceRunner' from assembly 'choco'
2026-07-09 18:02:13,550 856 [DEBUG] - Adding new type 'CygwinService' for type 'IInstallSourceRunner' from assembly 'choco'
2026-07-09 18:02:13,578 856 [DEBUG] - Adding new type 'PythonService' for type 'IAlternativeSourceRunner' from assembly 'choco'
2026-07-09 18:02:13,593 856 [DEBUG] - Adding new type 'PythonService' for type 'IListSourceRunner' from assembly 'choco'
2026-07-09 18:02:13,625 856 [DEBUG] - Adding new type 'PythonService' for type 'IInstallSourceRunner' from assembly 'choco'
2026-07-09 18:02:13,640 856 [DEBUG] - Adding new type 'PythonService' for type 'IUninstallSourceRunner' from assembly 'choco'
2026-07-09 18:02:13,671 856 [DEBUG] - Adding new type 'RubyGemsService' for type 'IAlternativeSourceRunner' from assembly 'choco'
2026-07-09 18:02:13,736 856 [DEBUG] - Adding new type 'RubyGe
@qq1018408006
qq1018408006 / report.html
Created July 9, 2026 18:08
AI News & GitHub Trending Report 2026-07-09
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>每日 AI 新闻与 GitHub Trending 报告</title>
<style>
:root {
--bg: #0b1020;
--panel: #111831;
@fridayfang
fridayfang / index.html
Last active July 9, 2026 18:09
[run-repo course] alpamayo1.5 深度解析课程
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alpamayo 1.5 深度解析课程</title>
<!-- Google Fonts: Bricolage Grotesque · DM Sans · JetBrains Mono -->
<link rel="preconnect" href="https://fonts.googleapis.com">