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
@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"
@igrep
igrep / download-from-m3u8.hs
Created February 20, 2021 08:27
Download and concatenate videos from a m3u8 file in Twitter etc.
#!/usr/bin/env stack
{- stack --resolver lts-17.4 script
--package=typed-process
--package=filepath
--package=modern-uri
--package=text
-}
{-# LANGUAGE OverloadedStrings #-}
@igrep
igrep / .vimrc
Last active November 11, 2020 20:49
vim-watchdogsでエラーをquickfix listに出した後、カーソルをquickfix listのウィンドウに移動させない ref: http://qiita.com/igrep/items/e5d288f42d9abb23e4c1
function! GoToPreviousWindowWhenQf() abort
if &filetype == 'qf'
wincmd p
endif
endfunction
let g:quickrun_config = {
\ "_": {
\ "outputter/quickfix/open_cmd" : "cwindow | call GoToPreviousWindowWhenQf()"
\ },
\ }
@igrep
igrep / list-google-shopping-list-items.js
Created September 1, 2020 14:23
For bookmarklet: List (and select to copy) the items in Google Shopping List
prompt("Copy", [...document.getElementsByClassName('listItemTitle')].map(e => e.innerText).join("\n"))
@igrep
igrep / add-item-to-google-shopping-list.js
Created August 27, 2020 12:29
Function to a given item to Google Shopping List. Paste the code in the DevTools' console!
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 February 11, 2020 11:04
Simulate left, below, above, and right actions of unite.vim with denite.nvim
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']))
.text
.global _start
_start:
MOV X0, #65
MOV X8, #93
SVC 0
@igrep
igrep / with-intmap-dynamic.hs
Last active September 15, 2019 10:13
Simulate ST Monad without "impure" things
#!/bin/env stack
{-
stack script --resolver=lts-14.6
--package=mtl
--package=containers
-}
{-# OPTIONS -fdefer-type-errors #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes #-}
@igrep
igrep / fact.js
Last active July 30, 2019 04:04
Roughly simulate the difference between pointfree style and pointful style. Inspired by https://kakkun61.hatenablog.com/entry/2019/07/29/%E9%96%A2%E6%95%B0%E3%81%AE%E3%83%A1%E3%83%A2%E5%8C%96
/*
fact :: Int -> Integer
fact 0 = 1
fact n = fromIntegral n * fact (n-1)
*/
const fact = function(n){
if (n == 0){
return 1;
} else {
return n * fact(n - 1);