This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import React from "react"; | |
| export interface OptControlledValue<T> { | |
| value?: T; | |
| set?: (value: T) => void; | |
| initial: T; | |
| } | |
| export function useMaybeControlledValue<T>(options: OptControlledValue<T>): [T, (val: T) => void] { | |
| const optionsSet = options.set; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # Start a UI app and move its window to a specific Xfce workspace. | |
| # | |
| # Example: Move app xoscope to workspace number 2 (starts at 1). | |
| # | |
| # $ run-in-workspace 2 xoscope | |
| run_in_workspace() { | |
| local workspace=$1 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| set -e -u -o pipefail | |
| # Open a new pull request in github from the current branch | |
| open_pr() { | |
| local base_branch=${1:-"development"} | |
| local merge_organisation_opt=${2:-} | |
| local browser="xdg-open" | |
| local repo current_branch merge_organisation merge_branch url | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | type AllKeysOfUnion<U> = U extends any ? keyof U : never; | |
| type NonCommonKeysOfUnion<U> = Exclude<AllKeysOfUnion<U>, keyof U>; | |
| type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | |
| type UnionWithKeys<U, K extends keyof any> = U extends any | |
| ? { [Key in K]: Key extends keyof U ? U[Key] : never } | |
| : never; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const canvas = document.getElementById("tutorial"); | |
| const context = canvas.getContext("2d"); | |
| function drawBackground() { | |
| context.beginPath(); | |
| context.fillStyle = "rgb(200, 200, 200)"; | |
| context.rect(0, 0, 640, 480); | |
| context.fill(); | |
| context.closePath(); | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /* Naturals using Peano numbers. See https://ostro.ws/2019/12/09/taking-types-too-far/ */ | |
| type Zero = { prev: never }; | |
| type Nat = { prev: Nat }; | |
| type Succ<N extends Nat> = { prev: N }; | |
| type Prev<N extends Nat> = N["prev"]; | |
| type Nats = { | |
| 0: Zero; | |
| 1: Succ<Zero>; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | type Length<T extends any[]> = T["length"]; | |
| type Head<T extends any[]> = T[0]; | |
| type Tail<T extends any[]> = ((...xs: T) => any) extends (x: any, ...t: infer T) => any ? T : never; | |
| type Last<T extends any[]> = { | |
| 0: never; | |
| 1: T[0]; | |
| ">1": Last<Tail<T>>; | |
| }[Length<T> extends 0 ? 0 : Length<T> extends 1 ? 1 : ">1"]; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function renderJoin(nodes: ReactNode[], separator: ReactNode): ReactNode { | |
| return nodes.flatMap((node, idx) => | |
| idx < nodes.length - 1 ? [node, separator] : [node] | |
| ).map((node, idx) => <React.Fragment key={idx}>{node}</React.Fragment>); | |
| } | |
| // Usage | |
| const myComponent: React.FC = props => { | |
| return <div>{renderJoin([<p>item1</p>, <p>item2</p>], <br />)}</div>; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | export type Matcher<KindField extends string, Kind extends string, Obj, Result> = { | |
| [K in Kind]: (obj: Extract<Obj, { [F in KindField]: K }>) => Result; | |
| }; | |
| export function match<KindField extends string>(field: KindField) { | |
| return function< | |
| Obj extends { [K in KindField]: Kind }, | |
| Result, | |
| Kind extends string = Obj[KindField] | |
| >(obj: Obj, matcher: Matcher<KindField, Kind, Obj, Result>): Result { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
| function idOf(idx: number): string { | |
| const quotient = Math.floor(idx / letters.length); | |
| const remainder = idx % letters.length; | |
| return (quotient > 0 ? idOf(quotient - 1) : "") + letters[remainder]; | |
| } | |
| function cell(colIdx: number, rowIdx: number): string { | |
| return idOf(colIdx) + (rowIdx + 1).toString(); |