Skip to content

Instantly share code, notes, and snippets.

View leaysgur's full-sized avatar
🫖

Yuji Sugiura leaysgur

🫖
View GitHub Profile
@leaysgur
leaysgur / income-tax.mjs
Last active December 4, 2023 20:35
所得税とその税率を計算
// @ts-check
/**
* | 課税所得 | 税率 | 控除額 |
* | ---------------------------------- | ---- | ----------- |
* | 1,000円 から 1,949,000円まで | 5% | 0円 |
* | 1,950,000円 から 3,299,000円まで | 10% | 97,500円 |
* | 3,300,000円 から 6,949,000円まで | 20% | 427,500円 |
* | 6,950,000円 から 8,999,000円まで | 23% | 636,000円 |
* | 9,000,000円 から 17,999,000円まで | 33% | 1,536,000円 |
@leaysgur
leaysgur / arraybuffer-to-hex.js
Created July 7, 2023 07:48
ArrayBuffer <-> HEX string
function arrayBufferToHex(arrayBuffer) {
const view = new Uint8Array(arrayBuffer);
let result = "";
for (let i = 0; i < view.length; i++) {
const value = view[i].toString(16);
result += value.length === 1 ? "0" + value : value;
}
return result;
@leaysgur
leaysgur / extend-osd.js
Created July 3, 2023 12:23
Extend OpenSeadragon internals to support async `getTileUrl()` with custom tile source.
$ = window.OpenSeadragon;
$.TileSource = class extends $.TileSource {
downloadTileStart(context) {
// 👼 Keep original code as is
var dataStore = context.userData,
image = new Image();
dataStore.image = image;
dataStore.request = null;
const ID_BYTES = 8; // 64 bits
const HEADER_BYTE_LENGTH = 2 * Uint16Array.BYTES_PER_ELEMENT;
// OpenAI embeddings are [-1, 1), so we can
// quantize to Int16 by multiplying by 2^15
const QUANTIZE_MAX = Math.pow(2, 15);
export class VectorCollection {
static VERSION = 1;
export const promiseAllWithConcurrency = async <T>(
queue: (() => Promise<T>)[],
concurrency: number = 1
) => {
let index = 0;
const results: T[] = [];
const execThread = async () => {
while (index < queue.length) {
const curIndex = index++;
local wezterm = require "wezterm";
local act = wezterm.action;
return {
font = wezterm.font("Cica"),
font_size = 22,
adjust_window_size_when_changing_font_size = false,
initial_cols = 120,
initial_rows = 40,
// @ts-check
import fs from "node:fs/promises";
import path from "node:path";
// This script is temporary work-around for issue,
// https://github.com/withastro/astro/issues/2146
// TL;DR, we need to replace all url() in CSS manually...
// e.g. url(__VITE_ASSET__********__) => url(/assets/asset.********.webp)
// Some url() work fine if they are updated to data-url.
(async () => {
#!/usr/bin/env bash
set -e
bytesToHuman() {
b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}iB)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
@leaysgur
leaysgur / powerset.rs
Created November 8, 2021 00:32
[Rust] all subsets in vec
fn powerset<T>(s: &[T]) -> Vec<Vec<&T>> {
(0..2usize.pow(s.len() as u32))
.map(|i| {
s.iter()
.enumerate()
.filter(|&(t, _)| (i >> t) % 2 == 1)
.map(|(_, e)| e)
.collect()
})
.collect()
@leaysgur
leaysgur / high-low-game.js
Created June 29, 2021 08:33
High Low Game
class Game {
constructor({ $buttons, $result, $reset }) {
this.answer = null;
this.$buttons = $buttons;
this.$result = $result;
this.$reset = $reset;
}
start() {
this.answer = Math.floor((Math.random() * 5) + 1);