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 / translate-mdn-ja-nvim.vim
Last active March 18, 2023 05:41
MDNの翻訳中、現在開いている英語版のパスを日本語版のパスに変換して開く(WindowsのNeovimで動かしていて、なおかつtranslated-contentとcontentが同じディレクトリーにある前提なので注意)
View translate-mdn-ja-nvim.vim
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に書き換える
View bookmarklet.js
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.
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 / gist:1028628
Created June 16, 2011 03:37
(UNNAMED) generator expression like Python in Ruby
View gist:1028628
#!/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'
@igrep
igrep / rewrite-the-only-case-where-I-use-let-in.hs
Last active April 13, 2021 03:19
唯一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 April 13, 2021 02:49
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 February 20, 2021 08:27
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 / parser-strscan.rb
Last active December 14, 2020 21:43
Arithmetic expression parser with StringScanner in Ruby, inspired by parser combinators.
View parser-strscan.rb
require 'strscan'
class Parser
def initialize string
@scanner = StringScanner.new string
end
def self.eval string
self.new(string).expr
@igrep
igrep / .vimrc
Last active November 11, 2020 20:49
vim-watchdogsでエラーをquickfix listに出した後、カーソルをquickfix listのウィンドウに移動させない ref: http://qiita.com/igrep/items/e5d288f42d9abb23e4c1
View .vimrc
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
View list-google-shopping-list-items.js
prompt("Copy", [...document.getElementsByClassName('listItemTitle')].map(e => e.innerText).join("\n"))