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 / fetch.js
Last active May 2, 2019 11:54
[fetch usage] #JavaScript #browser
/////// GET
fetch('/user/search?activeFilter=pending&max-results=11')
.then(response => {
const {ok, status} = response;
if (!ok || status !== 200)
throw new Error();
return response.json();
})
.catch((e => {
console.log('parsing failed or whatever', e)
@Offirmo
Offirmo / dom-manipulation--reading.ts
Last active June 21, 2025 07:35
[✳️DOM -- manipulation -- READING] #JavaScript #dom #browser #frontend
// +++ https://blog.garstasio.com/you-dont-need-jquery/selectors/
// http://youmightnotneedjquery.com/
/// various access
self // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
self.origin
self.isSecureContext
window
window.document
@Offirmo
Offirmo / deep_destructuring.js
Last active January 16, 2025 00:43
[JS -- deep destructuring] #JavaScript
// from https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Op%C3%A9rateurs/Affecter_par_d%C3%A9composition
var metadata = {
title: "Scratchpad",
translations: [
{
locale: "de",
localization_tags: [ ],
last_edit: "2014-04-14T08:43:37",
url: "/de/docs/Tools/Scratchpad",
title: "JavaScript-Umgebung"
@Offirmo
Offirmo / template.bash
Last active January 22, 2025 03:31
[Bash -- template] #bash
## * #!/usr/bin/env bash is more portable than #!/bin/bash
#!/usr/bin/env bash
#
# This script does this and that.
## https://stackoverflow.com/questions/31313305/portably-trapping-err-in-shell-script
## http://mywiki.wooledge.org/BashFAQ/105
## TODO review those lines:
set -o errexit
@Offirmo
Offirmo / proxy-function.ts
Last active January 16, 2025 00:45
[🔷TS -- proxy function] #TypeScript
/**
* Conveniently proxy functions instead of storing the value and applying it yourself.
*
* proxyFunction(someApiFunction, (args, callOriginalFunction) => {
* if (whateverYouWant) {
* return 'custom value'
* // Never call the original
* }
*
*
@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 / marky.ts
Last active December 2, 2018 07:51
[User timing measurement with marky] #TypeScript #JavaScript #frontend
import 'marky'
const user_timing_measurement = (window as any).user_timing_measurement
user_timing_measurement.mark('bootstrap')
...
user_timing_measurement.stop('bootstrap')
// https://www.html5rocks.com/en/tutorials/webperformance/basics/
@Offirmo
Offirmo / rx-observable.js
Last active May 26, 2017 03:02
[Observable] #tags:JavaScript,RxJS
const obs$ = Rx.Observable.create((observer) => {
observer.next(1)
// either:
observer.error(new Error('404'))
observer.complete()
})
observable.subscribe(
value => console.log(value),
err => console.error(value),
@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 / simple_di.ts
Last active January 16, 2025 00:46
[🔷TS -- Simple dependency injection] #TypeScript
import { foo } from '../libs/foo'
import { bar } from './libs/bar'
interface InjectableDependencies {
logger: Console
foo: typeof foo
}
const defaultDependencies: InjectableDependencies = {
logger: console,