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 / 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-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
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 / 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
-}
{-
@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 / 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 / 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 / auto-save-opening-files-bat.vim
Last active January 17, 2016 01:29
Save file names your vim opened, on a bat file to restore. Alternative to http://vim.wikia.com/wiki/Automatic_session_restore_in_git_directories
" Alternative to http://vim.wikia.com/wiki/Automatic_session_restore_in_git_directories for Windows.
" I created this because automatic session restore didn't work On my windows environment.
"
" Save a bat file to reopen the last opened files on exit.
" I consulted unite.vim\plugin\unite\buffer.vim for which events to autocmd and how to handle them.
if !( has('win32') || has('win64') )
finish
end
@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 / commit-msg
Last active September 25, 2015 01:46
branch名にuser storyのidを入れてコミットメッセージにuser storyのURLを自動で貼る ref: http://qiita.com/igrep/items/17df4627192d7d9d3188
#!/bin/sh
story_id=$(git rev-parse --abbrev-ref HEAD | sed -n 's#.*stories/\([0-9]\+\).*#\1#p')
if [ -n "$story_id" ]; then
echo user story: https://www.pivotaltracker.com/story/show/$story_id >> $1
fi