Skip to content

Instantly share code, notes, and snippets.

@homuler
homuler / bingo_prob.py
Created December 31, 2023 15:27
ビンゴの確率を計算する
import math
from fractions import Fraction
bingo5x5_seqs = [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24],
[1, 6, 11, 15, 20],
@homuler
homuler / throttle.ts
Created November 18, 2023 07:36
An implementation of throttled Promise.all in TypeScript
interface ThrottleOptions {
concurrency: number;
}
export async function throttledAll<T>(generator: Generator<Promise<T>>, options: ThrottleOptions): Promise<T[]> {
const { concurrency } = options;
if (concurrency <= 0) {
throw new Error(`concurrency must be greater than 0, but ${concurrency}`);
}
@homuler
homuler / android-installer-for-unity.sh
Last active August 17, 2022 23:54
A script to work around a bug that for some reason prevents Android-related commands from being executable on Linux.
#!/bin/bash
# Android-related commands are somewhat not executable on Linux, so install them again.
# cf. https://forum.unity.com/threads/android-sdk-ndk-and-openjdk-arent-marked-with-executable-permission-on-linux.1238494/
UNITY_EDITOR_ROOT="/path/to/Unity/Hub/Editor"
UNITY_EDITOR_VERSION="2021.3.3f1"
DESTINATION_ROOT="${UNITY_EDITOR_ROOT}/${UNITY_EDITOR_VERSION}/Editor/Data/PlaybackEngines/AndroidPlayer"
ANDROID_OPEN_JDK_URL=http://download.unity3d.com/download_unity/open-jdk/open-jdk-linux-x64/jdk8u172-b11_4be8440cc514099cfe1b50cbc74128f6955cd90fd5afe15ea7be60f832de67b4.zip
@homuler
homuler / backtrace.c
Last active March 31, 2022 01:10
PoC code to show how to print stack traces in C with line numbers.
// This is a PoC code to show how to print stack traces in C with line numbers.
// This code is based on [glibc/debug/backtracesymsfd.c](https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=debug/backtracesymsfd.c;hb=244b415d386487521882debb845a040a4758cb18)
/* Copyright (C) 1998-2022 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
@homuler
homuler / fontawesome-4-to-5.sh
Last active January 17, 2020 09:57
Shell script to migrate from FontAwesome v4 to v5
#!/bin/bash
# fontawesome-4-to-5.csv
# https://gist.github.com/homuler/e4c1e381cdab254d78b253ec9bc84870
#
# Usage:
# ./fontawesome-4-to-5.sh COMMAND TARGET_DIR [--csv-path=] [...GREP_OPTIONS]
DIR=$(dirname "$PWD/$0")
COMMAND=$1
@homuler
homuler / fontawesome-4-to-5.csv
Last active January 17, 2020 09:34
CSV file about FontAwesome icon name changes between version 4 and 5
Old Icon Name or Alias (Version 4) New Icon Name (Version 5) New Icon Prefix Unicode value
500px 500px fab f26e
address-book-o address-book far f2b9
address-card-o address-card far f2bb
adn adn fab f170
amazon amazon fab f270
android android fab f17b
angellist angellist fab f209
apple apple fab f179
area-chart chart-area fas f1fe
@homuler
homuler / fish_prompt.fish
Created December 26, 2019 02:39
Fish prompt with Git current branch name
function fish_prompt --description 'Write out the prompt'
set -l color_cwd
set -l suffix
switch "$USER"
case root toor
if set -q fish_color_cwd_root
set color_cwd $fish_color_cwd_root
else
set color_cwd $fish_color_cwd
end
@homuler
homuler / shogun.fish
Last active December 20, 2019 02:03
fish completion for `shogun` (https://github.com/knok/shogun-completion) command
set -l shogun_kinds kamakura muromachi tokugawa
set -l pre_kamakura_shoguns 巨勢麻呂 多治比懸守 藤原宇合 藤原麻呂 藤原継縄 藤原小黒麻呂 大伴家持 紀古佐美 大伴弟麻呂 坂上田村麻呂 文屋綿麻呂 藤原忠文 源義仲 木曾義仲
set -l kamakura_shoguns 源頼朝 源頼家 源実朝 藤原頼経 九条頼経 藤原頼嗣 九条頼嗣 宗尊親王 惟康親王 久明親王 守邦親王
set -l kenmu_shoguns 護良親王 成良親王 足利尊氏(建武)
set -l nancho_shoguns 興良親王 宗良親王 尹良親王
set -l muromachi_shoguns 足利尊氏 足利義詮 足利義満 足利義持 足利義量 足利義教 足利義勝 足利義政 足利義尚 足利義材 足利義澄 足利義稙 足利義晴 足利義輝 足利義栄 足利義昭
set -l tokugawa_shoguns 徳川家康 徳川秀忠 徳川家光 徳川家綱 徳川綱吉 徳川家宣 徳川家継 徳川吉宗 徳川家重 徳川家治 徳川家斉 徳川家慶 徳川家定 徳川家茂 徳川慶喜
set -l zou_shoguns 徳川綱重
@homuler
homuler / prime_sieves.sql
Last active December 29, 2022 12:57
Sieving Prime Numbers in SQL (PostgreSQL 9.6)
-- Enumerate prime numbers below N using only SQL
-- DDL
create table primes(
value integer primary key,
sieved boolean not null default false
);
create index prime_sieve_idx on
primes(value, sieved);