Skip to content

Instantly share code, notes, and snippets.

View igrep's full-sized avatar
:shipit:
Writing in Haskell, TypeScript, or Power Automate

YAMAMOTO Yuji igrep

:shipit:
Writing in Haskell, TypeScript, or Power Automate
View GitHub Profile
javascript:(()=>{"use strict";let leftAvailable=255;function fnv1a(t){let l=2166136261;for(let e=0;e<Math.ceil(t.length/2);++e){var n=t.charCodeAt(2*e),d=t.charCodeAt(2*e+1),d=isNaN(d)?0:d;l=(l^(n^d<<16))*16777619}return l}leftAvailable-=".html".length;const re=/[\uD83C-\uDFFF\u2600-\u26FF\\\/:*?"<>|]+/g,titleFsSafe=document.title.replace(re,"").trim(),{href,hostname,pathname,search,hash}=location,urlFsSafe=(""+hostname+pathname+search+hash).replace(re,"_"),fnvHash=fnv1a(""+document.title+href).toString(32);leftAvailable-=fnvHash.length;let safeTitle=titleFsSafe,safeUrl=urlFsSafe;const titleUtf8=(new TextEncoder).encode(titleFsSafe.normalize("NFD")),sumLength=titleUtf8.length+urlFsSafe.length;if(leftAvailable<sumLength){const i=Math.ceil(titleUtf8.length/sumLength*leftAvailable);safeTitle=(new TextDecoder).decode(titleUtf8.slice(0,i)),safeUrl=urlFsSafe.slice(0,leftAvailable-i-1)}document.head.dataset.title4pdforiginaltitle&&document.head.dataset.title4pdforiginalurl===href||(document.head.dataset.title4pdfori
import { WASI, OpenFile, wasi } from "@bjorn3/browser_wasi_shim";
// Workaround for https://github.com/bjorn3/browser_wasi_shim/issues/14
export function patchWasi(self: WASI): void {
self.wasiImport.poll_oneoff = ((
inPtr: number,
outPtr: number,
nsubscriptions: number,
sizeOutPtr: number,
): number => {
@igrep
igrep / example.bat
Last active November 10, 2023 05:13
Abuse unison's -sshcmd option to synchronize with the VM on WSL without sshd.
> unison C:\unison-test ssh://user@localhost/unison-test -retry 0 -repeat watch -sshcmd C:\\double\\backslashes\\path\\to\\wsl-as-ssh.cmd
@igrep
igrep / hateb-bookmarklet.js
Last active June 6, 2023 04:06
開いているページに対するはてブコメントページを開く(公式の拡張もあるけど、ブックマークするよりコメントを見たいのでこっちの方が個人的にはありがたい)
javascript:(()=>{"use strict";const isHttps="https:"===location.protocol,protocolLength=(isHttps?"https://":"http://").length;window.open("https://b.hatena.ne.jp/entry/"+(isHttps?"s/":"")+location.href.slice(protocolLength))})();
@igrep
igrep / borrow.ts
Last active April 19, 2023 10:23
Runtime borrow checker for JavaScript
export interface Borrowed<X> {
unsafeBorrow<Result>(use: (x: X) => Result): [Borrowed<X>, Result];
get isBorrowed(): boolean;
}
export class AlreadyBorrowedError extends Error {
override name = "AlreadyBorrowedError";
}
export function unsafeBorrowed<X>(x: X): Borrowed<X> {
@igrep
igrep / translate-mdn-ja-nvim.vim
Last active March 18, 2023 05:41
MDNの翻訳中、現在開いている英語版のパスを日本語版のパスに変換して開く(WindowsのNeovimで動かしていて、なおかつtranslated-contentとcontentが同じディレクトリーにある前提なので注意)
function! ToJaPath(enPath) abort
" e.g. content\files\en-us\glossary\boolean\html\index.md
return substitute(a:enPath, '^content\\files\\en-us', 'translated-content\\files\\ja', '')
endfunction
function! PrepareJaPath() abort
let path_to_index_md = ToJaPath(expand('%'))
call mkdir(v:lua.vim.fs.dirname(path_to_index_md), "p")
return path_to_index_md
endfunction
@igrep
igrep / no-empty.hs
Created November 16, 2022 09:33
Example type class for a type-level list with no instance for an empty list.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
import Data.Kind (Type)
data ExampleData (as :: [Type]) = ExampleData
@igrep
igrep / bookmarklet.js
Last active January 28, 2023 14:27
Replace a YouTube Short video's URL into traditional one. YouTubeのShortのURLを従来の形式のURLに書き換える
javascript:location.href="https://www.youtube.com/watch?v="+location.href.slice(`${location.origin}/shorts/`.length)
@igrep
igrep / rewrite-the-only-case-where-I-use-let-in.hs
Last active April 13, 2021 03:19
唯一let ... inを使いたくなる瞬間をdoのletでどうにかする
import Test.Hspec
import Test.Hspec.QuickCheck
import Test.QuickCheck
-- 従来、Hspecで個別のテストケースに対して Gen を定義したい場合、
-- いちいち違う名前を付けるのが面倒なので let ... in で g (あるいはgen)という名前を使い回していたが、
-- 別にそれもdoの中のletで解決できることが発覚した。
main = hspec $ do
-- let ... inを使った場合
@igrep
igrep / lets-in-do.hs
Created April 13, 2021 02:49
do記法の中でletやlet ... inを使ったサンプル
main = do
-- let ... in を使った場合
let f :: String -> IO ()
f = putStrLn
in f "f"
-- ただの let を使った場合(こっちの方が大抵おすすめ!)
let g :: String -> IO ()
g = putStrLn
g "g"