Skip to content

Instantly share code, notes, and snippets.

Avatar
⚔️
Coding a RPG… (as a hobby)

Offirmo Offirmo

⚔️
Coding a RPG… (as a hobby)
View GitHub Profile
@Offirmo
Offirmo / foo_spec.ts
Last active February 9, 2023 16:50
Unit Test in TypeScript
View foo_spec.ts
import { expect } from 'chai'
import {
LIB
} from '../index.js'
describe(`${LIB}`, function () {
describe('plugins', function () {
@Offirmo
Offirmo / condtypes.ts
Last active January 2, 2023 07:14
[typescript conditional types playground] #typescript
View condtypes.ts
// 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 / node.js
Last active May 7, 2023 11:14
[rare node stuff] #JavaScript #nodejs
View node.js
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#pure-esm-package
// https://nodejs.org/api/globals.html
__dirname, __filename
const assert = require('assert').strict
@Offirmo
Offirmo / javascript_learning_resources.md
Last active September 25, 2022 19:57
[Resources for learning JavaScript] #JavaScript
View javascript_learning_resources.md
@Offirmo
Offirmo / migrations.ts
Last active August 20, 2021 10:57
[Offirmo's migrations] #Offirmo #TypeScript
View migrations.ts
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 / node.js
Last active July 23, 2020 06:59
[useful node snippets] #JavaScript #nodejs
View node.js
// modules
module.exports = {
LIB,
}
// Read a file
const contents = fs.readFileSync('file path', 'utf8')
console.log(contents)
View plantyourcode.js
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
View flux.ts
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
View index.html
<!-- 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 / snippets.js
Last active August 8, 2021 11:36
[some common libs usage] #JavaScript #TypeScript
View snippets.js
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) => { ... })