Skip to content

Instantly share code, notes, and snippets.

@cohama
cohama / hoge.hs
Created June 23, 2013 13:18
SEND_MORE_MONEY in Haskell
-- S E N D
-- + M O R E
-- ---------
-- M O N E Y
import Data.List
digitsToNum :: [Int] => Int
digitsToNum = foldl (\acc x -> 10*acc + x) 0
diff -r c8559a2d8e5f runtime/ftplugin/ocaml.vim
--- a/runtime/ftplugin/ocaml.vim Sun Jul 21 17:06:00 2013 +0200
+++ b/runtime/ftplugin/ocaml.vim Mon Jul 22 00:34:09 2013 +0900
@@ -44,19 +44,21 @@
" (un)commenting
if !hasmapto('<Plug>Comment')
nmap <buffer> <LocalLeader>c <Plug>LUncomOn
- vmap <buffer> <LocalLeader>c <Plug>BUncomOn
+ xmap <buffer> <LocalLeader>c <Plug>BUncomOn
nmap <buffer> <LocalLeader>C <Plug>LUncomOff
@cohama
cohama / scheme.vim
Created August 8, 2013 15:46
Scheme でも lisp_rainbow! .vim/after/syntax/scheme.vim に配置
syn region schemeParen0 matchgroup=hlLevel0 start="`\=(" end=")" skip="|.\{-}|" contains=ALLBUT,schemeParen0,schemeParen2,schemeParen3,schemeParen4,schemeParen5,schemeParen6,schemeParen7,schemeParen8,schemeParen9
syn region schemeParen1 contained matchgroup=hlLevel1 start="`\=(" end=")" skip="|.\{-}|" contains=ALLBUT,schemeParen1,schemeParen3,schemeParen4,schemeParen5,schemeParen6,schemeParen7,schemeParen8,schemeParen9,schemeParen0
syn region schemeParen2 contained matchgroup=hlLevel2 start="`\=(" end=")" skip="|.\{-}|" contains=ALLBUT,schemeParen2,schemeParen4,schemeParen5,schemeParen6,schemeParen7,schemeParen8,schemeParen9,schemeParen0,schemeParen1
syn region schemeParen3 contained matchgroup=hlLevel3 start="`\=(" end=")" skip="|.\{-}|" contains=ALLBUT,schemeParen3,schemeParen5,schemeParen6,schemeParen7,schemeParen8,schemeParen9,schemeParen0,schemeParen1,schemeParen2
syn region schemeParen4 contained matchgroup=hlLevel4 start="`\=(" end=")" skip="|.\{-}|" contains=ALLBUT,schemeParen4,schemeParen6,
foldl' :: (a -> b -> a) -> a -> [b] -> a
foldl' f acc [] = acc
foldl' f acc (x:xs) = foldl' f (f acc x) xs
foldr' :: (a -> b -> b) -> b -> [a] -> b
foldr' f acc [] = acc
foldr' f acc (x:xs) = f x (foldr' f acc xs)
@cohama
cohama / simple_lambda.ml
Last active December 23, 2015 02:49
TaPL 10 章 単純型付きラムダ計算の実装
let (|>) x f = f x
let (|-) f g = fun x -> g (f x)
let getOrElse defVal = function
| Some(v) -> v
| None -> defVal
type ty =
| TyArr of ty * ty (* arrow type *)
| TyBool
@cohama
cohama / .zshrc
Created November 6, 2013 10:14
Enter 単発で `ls` を実行。1つのスペース+Enter で `git staus -s` を実行
function do_enter() {
if [ -z "$BUFFER" ]; then
echo
ls -F
elif [ "$BUFFER" = " " ]; then
if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" = 'true' ]; then
echo
echo -e "\e[0;33m--- git status ---\e[0m"
git status -s
fi
@cohama
cohama / .zshrc
Created November 20, 2013 16:07
スペース2回で "git " を入力する
function do_space() {
if [ "$BUFFER" = " " ]; then
LBUFFER="git "
else
LBUFFER="$LBUFFER "
fi
}
zle -N do_space
bindkey ' ' do_space
@cohama
cohama / formatter_spec.vim
Last active December 29, 2015 06:29
Vim script でランダム文字列生成
let s:V = vital#of('r')
let s:Xor = s:V.import('Random.Xor128')
function! s:randomString(char_kind, length)
let rand_str = ''
for i in range(a:length)
let rand_char = a:char_kind[abs(s:Xor.rand()) % len(a:char_kind)]
let rand_str .= rand_char
endfor
return rand_str
@cohama
cohama / todo.hs
Created December 1, 2013 13:46
すごい Haskell 9.5 もっと ToDo リスト
import System.Environment
import System.Directory
import System.IO
import Data.List
import Control.Exception
dispatch :: String -> [String] -> IO ()
dispatch "add" = add
dispatch "view" = view
dispatch "remove" = remove
let s:V = vital#of('vital')
function! s:truncate(text, max_width, ellipsis)
let ellipsis_width = strdisplaywidth(a:ellipsis)
let text_width = strdisplaywidth(a:text)
if text_width > a:max_width
let truncated = s:V.strwidthpart(a:text, a:max_width - ellipsis_width)
" for double width string
if strdisplaywidth(truncated) != a:max_width - ellipsis_width
let truncated .= ' '
endif