Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
Writing in Haskell, TypeScript, or Power Automate

YAMAMOTO Yuji igrep

:shipit:
Writing in Haskell, TypeScript, or Power Automate
View GitHub Profile
@igrep
igrep / no-empty.hs
Created Nov 16, 2022
Example type class for a type-level list with no instance for an empty list.
View no-empty.hs
{-# 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 Jan 28, 2023
Replace a YouTube Short video's URL into traditional one. YouTubeのShortのURLを従来の形式のURLに書き換える
View bookmarklet.js
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 Apr 13, 2021
唯一let ... inを使いたくなる瞬間をdoのletでどうにかする
View rewrite-the-only-case-where-I-use-let-in.hs
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 Apr 13, 2021
do記法の中でletやlet ... inを使ったサンプル
View lets-in-do.hs
main = do
-- let ... in を使った場合
let f :: String -> IO ()
f = putStrLn
in f "f"
-- ただの let を使った場合(こっちの方が大抵おすすめ!)
let g :: String -> IO ()
g = putStrLn
g "g"
@igrep
igrep / download-from-m3u8.hs
Created Feb 20, 2021
Download and concatenate videos from a m3u8 file in Twitter etc.
View download-from-m3u8.hs
#!/usr/bin/env stack
{- stack --resolver lts-17.4 script
--package=typed-process
--package=filepath
--package=modern-uri
--package=text
-}
{-# LANGUAGE OverloadedStrings #-}
@igrep
igrep / list-google-shopping-list-items.js
Created Sep 1, 2020
For bookmarklet: List (and select to copy) the items in Google Shopping List
View list-google-shopping-list-items.js
prompt("Copy", [...document.getElementsByClassName('listItemTitle')].map(e => e.innerText).join("\n"))
@igrep
igrep / add-item-to-google-shopping-list.js
Created Aug 27, 2020
Function to a given item to Google Shopping List. Paste the code in the DevTools' console!
View add-item-to-google-shopping-list.js
const input = document.getElementsByClassName("listItemInput")[0];
const form = document.getElementsByClassName("addForm")[0];
function addItem(name){
input.dispatchEvent(new Event("focus"));
input.value = name;
input.dispatchEvent(new Event("input"));
form.dispatchEvent(new Event("submit"));
}
@igrep
igrep / simulate-left-below-above-right.vim
Created Feb 11, 2020
Simulate left, below, above, and right actions of unite.vim with denite.nvim
View simulate-left-below-above-right.vim
function! Denite_do_open(split_cmd, context) abort
execute(a:split_cmd)
call denite#do_action(a:context, 'open', a:context['targets'])
endfunction
call denite#custom#action('openable,file,buffer,directory', 'left', funcref('Denite_do_open', ['leftabove vsplit']))
call denite#custom#action('openable,file,buffer,directory', 'below', funcref('Denite_do_open', ['rightbelow split']))
call denite#custom#action('openable,file,buffer,directory', 'above', funcref('Denite_do_open', ['leftabove split']))
call denite#custom#action('openable,file,buffer,directory', 'right', funcref('Denite_do_open', ['rightbelow vsplit']))
View asmtut1-1.s
.text
.global _start
_start:
MOV X0, #65
MOV X8, #93
SVC 0
@igrep
igrep / with-intmap-dynamic.hs
Last active Sep 15, 2019
Simulate ST Monad without "impure" things
View with-intmap-dynamic.hs
#!/bin/env stack
{-
stack script --resolver=lts-14.6
--package=mtl
--package=containers
-}
{-# OPTIONS -fdefer-type-errors #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes #-}