Skip to content

Instantly share code, notes, and snippets.

View leaysgur's full-sized avatar
🫖

Yuji Sugiura leaysgur

🫖
View GitHub Profile
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);
@leaysgur
leaysgur / index.html
Created June 14, 2021 12:46
CSS only loading
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Loading...</title>
</head>
<body class="loading">
</body>
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
let id = 0;
async function handleRequest(request) {
const params = new URL(request.url).searchParams;
const mode = params.get("mode") || "0";
@leaysgur
leaysgur / calc.js
Created January 18, 2021 14:49
虫食い算
// 2x
// * yz
// =====
// ?3?
// ???
// =====
// ?4?
for (let x = 0; x < 10; x++) {
for (let z = 0; z < 10; z++) {
@leaysgur
leaysgur / use-flow.js
Created December 2, 2020 09:36
setState when N tasks are done
const useFlow = (numOfTasks = 1) => {
const [allDone, setAllDone] = useState(false);
const taskRef = useRef(0);
const done = useCallback(() => {
if (allDone) return;
taskRef.current++;
setAllDone(taskRef.current >= numOfTasks);
}, [allDone, numOfTasks]);
@leaysgur
leaysgur / next-preact.d.ts
Created September 1, 2020 10:02
Use nextjs Link component w/ Preact + TypeScript
import type { VNode, JSX } from "preact";
declare module "react" {
export = React;
export as namespace React;
declare namespace React {
type DetailedReactHTMLElement<
P extends JSX.HTMLAttributes<T>,
T extends HTMLElement