Skip to content

Instantly share code, notes, and snippets.

View igrep's full-sized avatar
:shipit:
Writing in Haskell or TypeScript.

YAMAMOTO Yuji igrep

:shipit:
Writing in Haskell or TypeScript.
View GitHub Profile
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 => {
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
@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 / parser-strscan.rb
Last active June 16, 2023 21:14
Arithmetic expression parser with StringScanner in Ruby, inspired by parser combinators.
require 'strscan'
class Parser
def initialize string
@scanner = StringScanner.new string
end
def self.eval string
self.new(string).expr
@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 / 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 / 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 / gist:1028628
Created June 16, 2011 03:37
(UNNAMED) generator expression like Python in Ruby
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$VERBOSE = true
=begin
Maybe usable as generator expression in Python
requires ruby1.9 or facets ( >= 2.9.1 )
=end
if RUBY_VERSION < '1.9'
require 'rubygems'