Skip to content

Instantly share code, notes, and snippets.

View Offirmo's full-sized avatar
⚔️
Coding a RPG… (as a hobby)

Offirmo Offirmo

⚔️
Coding a RPG… (as a hobby)
View GitHub Profile
@Offirmo
Offirmo / condtypes.ts
Last active January 16, 2025 00:45
[🔷TS -- conditional types playground] #typescript
// type tester for generics
type ImmutablePrimitive = undefined | null | boolean | string | number | Function
interface EmptyStruct { }
// https://www.typescriptlang.org/docs/handbook/2/functions.html#other-types-to-know-about
//type T = any
//type T = unknown
//type T = void
@Offirmo
Offirmo / javascript_learning_resources.md
Last active November 4, 2025 22:23
[JS -- rsrc -- learning] #JavaScript
@Offirmo
Offirmo / migrations.ts
Last active August 20, 2021 10:57
[Offirmo's migrations] #Offirmo #TypeScript
import { enforce_immutability, LastMigrationStep, MigrationStep, generic_migrate_to_latest } from '@offirmo-private/state-utils'
import { LIB, SCHEMA_VERSION } from './consts'
import { UState, TState } from './types'
import { OMRSoftExecutionContext } from './sec'
// some hints may be needed to migrate to demo state
// need to export them for composing tests
export const MIGRATION_HINTS_FOR_TESTS: any = enforce_immutability({
})
@Offirmo
Offirmo / ts--snippets--node.ts
Last active July 5, 2025 11:08
[🔷TS -- snippets -- node] #JavaScript #TypeScript #nodejs
/////////////////////////////////////////////////
// __dirname, __filename
// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#pure-esm-package
// https://nodejs.org/api/globals.html
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
AwesomeKaleGleaner
function grid(seedCount) {
const s = Math.sqrt(seedCount)
const res = [ Math.floor(s) , Math.ceil(s) ]
if (res[0] * res[1] < seedCount )
res[0]++
return res
@Offirmo
Offirmo / flux.ts
Last active November 15, 2019 03:26
Wrapping instead of currying
import {
State,
set_age,
} from './state.ts'
const state: State = { ... }
// currying
const curried1_set_age = change_age.bind(null, state) // hard to read
@Offirmo
Offirmo / index.html
Last active December 22, 2021 02:20
[links in HTML] #html #browser
<!-- https://devdocs.io/html/element/a -->
<a href="https://github.com/Offirmo/offirmo-monorepo/issues" target="_blank" rel="noopener,external">report here</a>
@Offirmo
Offirmo / ts--common-libs.js
Last active June 21, 2025 07:36
[🔷TS -- common libs] #JavaScript #TypeScript
import EventEmitter from 'emittery'
const EMITTER_EVT = 'change'
const emitter = new EventEmitter<{ [EMITTER_EVT]: string }>()
emitter.emit(EMITTER_EVT, `[in-mem]`)
const unbind = emitter.on(EMITTER_EVT, (src: string) => { ... })
@Offirmo
Offirmo / storybook.js
Last active May 18, 2021 03:42
[storybook] Storybook recipes... #react #frontend #JavaScript
// https://storybook.js.org/basics/guide-react/#write-your-stories
// https://storybook.js.org/basics/writing-stories/
// "Component Story Format"
// https://storybook.js.org/docs/react/api/csf
import { Story, Meta } from '@storybook/react'
import HelloWorld, { HelloWorldProps } from '.'
@Offirmo
Offirmo / react.jsx
Last active August 17, 2025 10:17
[🔷TS -- React -- recipes] #react #frontend
// https://react.dev/learn/typescript
import React from 'react'
// really? or import * as React from 'react' ?? https://github.com/facebook/react/pull/18102 ALSO https://www.typescriptlang.org/tsconfig/#allowSyntheticDefaultImports
// or not even need to import React? https://parceljs.org/recipes/react/#jsx
import React, { Component } from 'react'
// (from .d.ts)
type ReactNode =
| ReactElement