Skip to content

Instantly share code, notes, and snippets.

View uhyo's full-sized avatar
🈚
Current status: totemo yowai programmer

uhyo uhyo

🈚
Current status: totemo yowai programmer
View GitHub Profile
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Navigation API Scroll To Top Repro</title>
<style>
body {
min-height: 200vh;
}
.controls {
@uhyo
uhyo / google-chrome-top-layer-bug-repro.html
Last active August 16, 2024 09:11
Google Chrome top layer bug repro
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>repro</title>
<style>
#popover1 {
top: 100px;
left: 100px;
width: 100px;
// 試合を繰り返して昇格する確率を求める
// ・5勝の貯金を積み上げると昇格
// ・3敗の借金を積み上げると降格
// ・借金中に勝利すると今までの借金がチャラになり+1勝になる
generateCSV();
function generateCSV() {
const header='1試合の勝率,昇格確率,降格確率,合計';
let csv = header + '\n';
for (let p = 0; p <= 100; p ++) {
@uhyo
uhyo / useBufferflyEffect.ts
Created January 12, 2022 00:35
useButterflyEffect()
const effects: Map<number, () => void> = new Map();
let nextEffectId = 1;
/**
* Similar to useEffect, but an effect from another randomly chosen instance of useButterflyEffect is called
* when given deps change.
*/
function useButterflyEffect(effect: () => void, deps: readonly unknown[]) {
useEffect(() => {
const effectId = nextEffectId++;
@uhyo
uhyo / g.js
Created November 4, 2020 01:44
Googleの大統領選の結果の州をクリックすると色を変えられるやつ2020
(()=>{
const svg = document.querySelector('svg.vlmbi.H21Mnd');
const svg2 = cl(svg);
const paths = svg2.querySelectorAll('path.xH0v4d');
const cs = [
'rgb(218, 220, 224)',
'rgb(0, 155, 216)',
'rgb(166, 220, 241)',
'rgb(241, 176, 180)',
'rgb(219, 29, 40)',
function offsetRange(arr) {
return (
arr.map(v => [v, v+1])
.join(",")
.replace(/(,\d+)\1/g, "-")
.replace(/(-+,)\d+/g, (_, s) => "-" + (s.length))
.replace(/(,\d+),\d+/g, (_, s) => `${s}-1`)
.split(",")
.map((v) => {
const [offset, range] = v.split("-");
@uhyo
uhyo / gist:f97499872fb0685bd5a4b11fa0f55aef
Last active May 26, 2020 12:23
Sync way of obtaining promise result
Promise.prototype.then = (()=> {
const _then = Promise.prototype.then;
return function(...args) {
_then.call(this, (res) => {
promiseResultMap.set(this, res);
})
this.then = _then;
return _then.apply(this, args);
}
})();
@uhyo
uhyo / use.js
Created April 9, 2020 10:57
JavaScript Top
const use\uffa0std = {
collections: {
get HashMap() {
globalThis.HashMap = class HashMap {};
return undefined;
}
}
}
@uhyo
uhyo / fizzbuzz.js
Last active October 16, 2019 09:14
fizzbuzz.js
let fizzbuzz = false;
function* range() {
for (let i=1; i<=100; i++) yield i;
}
async function fizz() {
for (const i of range()) {
if (i % 3 === 0) {
fizzbuzz=true;
process.stdout.write("Fizz");
}
const numBegArr = ["-", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
const numBegSet = new Set(numBegArr);
const isNumericBeginning = char => numBegSet.has(char);
const isNumericBeginning2 = char => numBegArr.includes(char);
const isNumericBeginning3 = char =>
char === "-" ||
char === "0" ||
char === "1" ||
char === "2" ||