Skip to content

Instantly share code, notes, and snippets.

View azerum's full-sized avatar
🇺🇦
🕊️🌍

azerum

🇺🇦
🕊️🌍
  • Mostly Harmless
View GitHub Profile
@azerum
azerum / auto-nvmrc.sh
Created December 12, 2025 09:03
Automatic `nvm use` on cd'ing into directory for macOS zsh
# Generated by ChatGPT
# Keep track of last used .nvmrc path
typeset -g NVM_LAST_USED=""
# Function to find closest .nvmrc in current dir or above
function nvm_find_rc() {
local dir="$PWD"
while [[ "$dir" != "/" ]]; do
if [[ -f "$dir/.nvmrc" ]]; then
export type DeepReadonly<T> =
//Functions are objects, but don't need to be deep readonly
T extends Function ? T :
T extends Map<infer MK, infer MV> ? ReadonlyMap<DeepReadonly<MK>, DeepReadonly<MV>> :
T extends Set<infer E> ? ReadonlySet<DeepReadonly<E>> :
T extends Array<infer E> ? ReadonlyArray<DeepReadonly<E>> :
T extends object ? DeepReadonlyObject<T> :
T;
@azerum
azerum / TriggerHelpers.js
Created May 18, 2022 19:55
Helper functions to work with triggers in Lens Studio
// -----JS CODE-----
//NOTE:
//To this scipt to work you need to:
// - Put 'Behavior' script on the very top of Objects hierarchy. Use
// + > Helper Scripts > Behavior to add it. You can leave that script
// to work 'On Awake'
// - Put this script on top of the Objects hierarchy, AFTER behavior. Bind
// this script to 'On Start', NOT 'On Awake'
/**
* 'probabilities' is an array of pairs [probability, choice]
*/
function chooseWithProbabilities(probabilities) {
const pSum = probabilities.reduce((sum, [p, _]) => sum + p, 0);
if (pSum !== 100.0) {
throw new Error(
'Sum of the probabilities must be equal to 100. '
+ `Current sum is ${pSum}`
@azerum
azerum / partial.php
Last active May 15, 2022 19:06
Functions for partial application in PHP
<?php
function bind(callable $f, ...$params)
{
return function () use ($f, $params) {
return call_user_func_array($f, $params);
};
}
function partial(callable $f, ...$params)
@azerum
azerum / pipeline.php
Created July 24, 2021 19:42
Chain functions with signature 'function($value, callable $next)' in PHP
<?php
function pipeline(callable ...$pipes) {
$pipes_count = count($pipes);
if ($pipes_count === 0) {
return;
}
$last_pipe = $pipes[$pipes_count - 1];