Skip to content

Instantly share code, notes, and snippets.

View igrep's full-sized avatar
:shipit:
Programming in TypeScript, Python, or Haskell.

YAMAMOTO Yuji igrep

:shipit:
Programming in TypeScript, Python, or Haskell.
View GitHub Profile
@igrep
igrep / reify.hs
Last active June 19, 2016 04:06
Example result of Language.Haskell.TH.reify
stack exec ghci -- -XTemplateHaskell
:m Language.Haskell.TH
data A = A { a :: Int, b :: String }
$(stringE . show =<< reify 'A)
-- prettified output
DataConI
Ghci12.A ( -- DataConI/Name
AppT ( -- DataConI/Type
@igrep
igrep / gitrebase.vim
Last active July 31, 2016 08:43
A utility command when git rebase -i with vim. Install this as ~/.vim/ftplugin/gitrebase.vim.
" NOTE: depends on fugitive.vim https://github.com/tpope/vim-fugitive
" Show commit on the line
map <Space><Space> 0w:<C-u>execute "Git! show " . expand("<cword>")<CR>
@igrep
igrep / hood-error-case.hs
Last active August 31, 2017 06:11
hood error case
#!/usr/bin/env stack
{-# LANGUAGE DeriveGeneric #-}
-- stack --resolver lts-8.4 runghc --package hood
import Debug.Hood.Observe
import GHC.Generics
data Hoge =
Hoge
@igrep
igrep / count-by-extension.hs
Created June 20, 2017 03:54
Haskell scriptingたのしー!
#!/bin/env stack
{- stack --resolver=lts-8.19
runghc
--package=attoparsec
--package=bytestring
--package=unordered-containers
--package=filepath
-}
{-
import qualified Control.Foldl as L
-- https://ja.stackoverflow.com/questions/36399/%E3%81%AA%E3%81%9C%E3%81%93%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%E3%81%AF%E3%82%B9%E3%83%9A%E3%83%BC%E3%82%B9%E3%83%AA%E3%83%BC%E3%82%AF%E3%81%97%E3%81%BE%E3%81%99%E3%81%8B
-- の問題を、foldlライブラリーを使ってコンスタントなメモリ消費量で計算した例
main :: IO ()
main = do
let points = [(x,y) | x <- range 10000, y <- range 10000]
let all = L.length
let hit = L.handles (L.filtered ((<= 1) . distance)) L.length
let pi h a = fromIntegral h * 4 / fromIntegral a
@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 / portfolio.js
Last active February 7, 2018 05:56
GMOクリック証券「保有投信一覧」で、ジャンル毎の評価額の割合を計算(私の保有している銘柄がばれてしまうので、一部修正しています)
(() => {
const countFunds = parseInt(document.querySelector('#dataCount>span').innerHTML, 10);
const a = [];
for(let i = 1 ; i <= countFunds ; ++i){ a.push(i); } ;
const funds = a.map((i) => {
return {
name: $(`#positionFundName${i} a`).text(),
price: parseInt($(`#positionAppraisedAmount${i}`).text().replace(/,/g, ''), 10)
};
@igrep
igrep / parser-oo.rb
Created May 19, 2018 05:00
Arithmetic expression parser *without* StringScanner in Ruby, inspired by parser combinators.
class Parser
def initialize string
@string = string
# To improve performance, increments position instead of modifying @string.
@position = 0
end
def self.eval string
@igrep
igrep / without.hs
Last active May 28, 2018 01:12
without function for Record in extensible package
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
@igrep
igrep / .local.vimrc
Created June 27, 2018 04:48
workaround of bug of Neoformat for Windows https://github.com/sbdchd/neoformat/issues/169
let g:neoformat_haskell_mystylishhaskell = {
\ 'exe': 'stylish-haskell',
\ 'args': ['2>nul'],
\ 'stdin': 1,
\ }
let g:neoformat_enabled_haskell = ['mystylishhaskell']
augroup fmt
autocmd!
autocmd BufWritePre *.hs undojoin | Neoformat mystylishhaskell
augroup END