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 / RPNWriter.hs
Last active December 11, 2015 09:08
Excercise from "Learn You a Haskell for Great Good!"
module RPNWriter where
-- 逆ポーランド記法で書かれた式を計算する関数 solveRPN (p.214) に、
-- Writerモナドを使って計算経過ログをとる機能を追加してみよう。
import Control.Monad.Writer
import Control.Applicative ((<$>))
import Data.Char (isDigit)
solveRPNwithLog :: String -> Writer String Double
solveRPNwithLog s = do
@igrep
igrep / PoleEither.hs
Created January 20, 2013 11:57
From "Learn you a Haskell for Great Good!" Simulation of Pole's tightrope walking by Either monad.
module PoleEither where
import Control.Monad.Error ()
import Data.List (intersperse)
type Birds = Int
type Pole = (Birds, Birds)
landLeft :: Birds -> Pole -> Either String Pole
landLeft n (left, right) =
import qualified Data.Text.IO as TIO (hGetLine)
import Data.Text (Text)
import qualified Data.Text as T
import System.IO
import Control.Applicative ((<$>), (<*>), pure)
hGetLines :: Handle -> IO [Text]
hGetLines h = do
eof <- hIsEOF h
if eof
@igrep
igrep / Kuku.hs
Created September 9, 2012 08:34
Data.Textを使った九九の表の出力。
module Kuku where
import qualified Data.Text as T
import Data.Text (Text)
import qualified Data.Text.IO as TIO
-- general function
showText :: (Show a) => a -> Text
showText = T.pack . show
import Control.Monad
import System.IO
main :: IO ()
main = do
putStr "あなたの名前は? "
hFlush stdout
eof <- isEOF
if eof
then
@igrep
igrep / profile.rb
Created September 8, 2012 09:22
example of dump
class Profile
DEFAULT = "default"
def self.generate_source name=DEFAULT
%Q"
#{self}.new #{name.dump} do|p|
# Required Properties
# DO NOT LEAVE THEM EMPTY!
p.src = ''
p.dest = ''
@igrep
igrep / class-var.rb
Created April 8, 2012 03:13
Notes about class variable in Ruby
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
$VERBOSE = true
def new_section
puts '-' * 80
end
# Can a class variable be accessed from the class methods?
class Hoge
@@a = "in #{self}"
@igrep
igrep / autoload-vimplayer.vim
Created November 22, 2011 03:03
Really thin wrapper of MPlayer for Vim editor. ref http://www.mplayerhq.hu/DOCS/tech/slave.txt
"Settings
let g:vimplayer_mplayer_extra_options = []
let s:vimplayer_pipe_mplayer = {}
function! vimplayer#play(...) abort
let vimplayer_filenames = a:000
if !empty(s:vimplayer_pipe_mplayer) "mplayer already playing something
call s:vimplayer_pipe_mplayer.stdin.write("quit\n")
@igrep
igrep / twice.sh
Created August 9, 2011 10:55
Sample to show that It's more useful to use +eval+ and +source+ if you want to decide which command to execute in your script
#!/bin/bash
#Execute command twice.
#Sample to show that
# It's more useful to use +eval+ and +source+
# if you want to decide which command to execute in your script
shopt -s expand_aliases # don't work even if expand_aliases is enabled.
# $@ #don't work well: don't expand the alias
@igrep
igrep / example.sh
Created June 29, 2011 07:00
Very simple twitter client for CLI (just tweet!)
alias tweet='cat ~/your-token.yaml | tw-post.rb'