Skip to content

Instantly share code, notes, and snippets.

View orrisroot's full-sized avatar
🥰
Wish for your happiness

Yoshihiro OKUMURA orrisroot

🥰
Wish for your happiness
View GitHub Profile
@orrisroot
orrisroot / entityData.ts
Created November 23, 2025 09:39
EntityData - A record structure for storing entities by their IDs and maintaining a list of all IDs.
/**
* @type {EntityData}
* A record structure for storing entities by their IDs and maintaining a list of all IDs.
*
* @template T The type of the items in the entity data.
* @template K The type of the keys used to identify items. Defaults to `string`.
*
* @property {Record<K, T>} byId - A mapping of entity IDs to their corresponding items.
* @property {K[]} allIds - An array of all entity IDs.
*/
@orrisroot
orrisroot / arrayUnique.ts
Created October 10, 2025 12:20
arrayUnique - Removes duplicate items from an array based on a comparison function.
/**
* arrayUnique - Removes duplicate items from an array based on a comparison function.
*
* @param items The array to filter.
* @param compare A function to compare two items for equality.
* @returns A new array with duplicate items removed.
*
* Usage example:
* const uniqueItems = arrayUnique<Item>(items, (a, b) => a.id === b.id);
*/
const naturalCompare = (a: string, b: string): number => {
const locales = new Set<string>([...navigator.languages, 'en-US', 'ja-JP']);
return new Intl.Collator(Array.from(locales), {
sensitivity: 'variant',
numeric: true,
}).compare(a, b);
};
@orrisroot
orrisroot / TaskQueue.ts
Last active October 3, 2025 03:48
A concurrency‑controlled task queue
/**
* A concurrency‑controlled task queue.
*
* It uses `eventemitter3` for signalling when all queued work has finished.
*
* Usage:
* const queue = new TaskQueue(10);
* queue.enqueue(() => doSomething());
* await queue.waitAll(); // resolves when nothing is left
*/
@orrisroot
orrisroot / hasDuplicate.ts
Last active June 11, 2025 03:47
Whether an array has duplicate elements
const hasDuplicate = <T,>(items: T[], func: (a: T, b: T) => boolean = (a, b) => a === b): boolean => {
return items.find((item, idx) => items.some((item2, idx2) => func(item, item2) && idx !== idx2)) != null;
};
@orrisroot
orrisroot / update-docker-composed-service.sh
Created November 15, 2021 09:40
Script to update docker images and to restart docker composed services, if used docker images has been updated.
#!/bin/bash
for cmd in docker jq; do
if ! command -v ${cmd} > /dev/null; then
echo "Error: ${cmd} is required." 1>&2
exit 1
fi
done
COMPOSE_FILE="$1"
@orrisroot
orrisroot / setup-docker-compose.sh
Created November 15, 2021 04:49
Setup docker compose plugin
#!/bin/bash
for cmd in docker curl jq; do
if ! command -v ${cmd} > /dev/null; then
echo "Error: ${cmd} is required to setup docker compose plugin." 1>&2
exit 1
fi
done
DOCKER_COMPOSE="${HOME}/.docker/cli-plugins/docker-compose"
@orrisroot
orrisroot / detect-updates-to-the-docker-base-image.sh
Last active May 16, 2023 00:48
Detect updates to the Docker base image
#!/bin/bash
REQUIRED_COMMANDS=("skopeo" "jq" "basename")
for COMMAND in "${REQUIRED_COMMANDS}"; do
if ! command -v ${COMMAND} > /dev/null; then
echo "Error: ${COMMAND} command is required." 1>&2
exit 2
fi
done
@orrisroot
orrisroot / rpmcheck.sh
Last active December 3, 2021 08:33
configuration check script after update rpm packages
#!/bin/bash
# VERSION:20211203
_uid=$(id -u)
if test $_uid -ne 0; then
echo "Error : This script have to run as root"
exit 1
fi
@orrisroot
orrisroot / .php-cs-fixer.php
Last active July 27, 2022 03:30
default php-cs-fixer configuration for my projects
<?php
declare(strict_types=1);
$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,