Skip to content

Instantly share code, notes, and snippets.

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

azerum

🇺🇦
🕊️🌍
  • Mostly Harmless
View GitHub Profile
@azerum
azerum / rfc5646-language-tags.js
Created April 25, 2023 15:27 — forked from msikma/rfc5646-language-tags.js
RFC 5646 Language Tags
// List of language tags according to RFC 5646.
// See <http://tools.ietf.org/html/rfc5646> for info on how to parse
// these language tags. Some duplicates have been removed.
var RFC5646_LANGUAGE_TAGS = {
'af': 'Afrikaans',
'af-ZA': 'Afrikaans (South Africa)',
'ar': 'Arabic',
'ar-AE': 'Arabic (U.A.E.)',
'ar-BH': 'Arabic (Bahrain)',
'ar-DZ': 'Arabic (Algeria)',
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];
@azerum
azerum / cases_conversion.php
Created July 17, 2021 21:30
Convert snake_case to camelCase in PHP and vice versa
<?php
function snake_to_camel_case(string $string): string {
$parts = explode('_', $string);
$parts_count = count($parts);
for ($i = 1; $i < $parts_count; ++$i) {
$parts[$i] = ucfirst($parts[$i]);
}