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 / rare.ts
Last active April 19, 2026 09:20
[🔷TS -- rare stuff] #TypeScript
// https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript
type MyRecord = Record<string, number>
type MyRecord = { [key: string]: number }
// TODO improved enums!
const OPERATORS = [ '*', '/', '+', '-' ] as const
type Operator = typeof OPERATORS[number]
type Color = "primary" | "secondary" | (string & {});
@Offirmo
Offirmo / claude_setting.json5
Last active March 22, 2026 19:59
Claude code settings
// https://code.claude.com/docs/en/settings
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(npm run lint)",
"Bash(npm run test *)",
"Read(~/.zshrc)"
],
"deny": [
@Offirmo
Offirmo / javascript_learning_resources.md
Last active November 4, 2025 22:23
[JS -- rsrc -- learning] #JavaScript
@Offirmo
Offirmo / basics.py
Last active November 4, 2025 22:22
[Python basics] #python
## https://developers.google.com/edu/python
# ternary
a if x else b
## strings
## https://developers.google.com/edu/python/strings
s = 'hi'
print(s[1]) ## i
print(len(s)) ## 2
@Offirmo
Offirmo / js--rare-stuff.ts
Last active October 27, 2025 20:06
[🔰JS -- rare stuff I forget all the time] #JavaScript #TypeScript
// null coalescings https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing
foo = foo ?? 42
foo ??= 42
// optional chaining https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
dog?.name
dog?.[name]
hello?.(target)
@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
@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))
@Offirmo
Offirmo / ts--hackerrank.ts
Last active June 21, 2025 07:36
[🔷TS -- snippets -- Hacker Rank] #TypeScript #JavaScript #competition
/////// REDUCE ///////
res = iter.reduce((acc, val) => {
return acc + val
}, 0)
err = decorators.reduce((err, decorator) => {
return decorator(err)
}, err)
@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) => { ... })