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 / 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 / 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 = ''
import Control.Monad
import System.IO
main :: IO ()
main = do
putStr "あなたの名前は? "
hFlush stdout
eof <- isEOF
if eof
then
@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 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 / 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) =
@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 / install-only-changed.sh
Last active December 11, 2015 22:58
maybe useful when you want to try your committed vimscript on your vim
#!/bin/bash
# maybe useful when you want to try your committed vimscript on your vim
# WARNING: as written, this script doesn't backup the destination directory
GIT_PAGER=cat
PAGER=cat
updated_files=$(git diff --name-only master)
dest_dir=$1
@igrep
igrep / 2013-02-17-reproduce-git.sh
Created February 17, 2013 12:15
A literate bash script.
#!/usr/bin/bashdb
# GistID: 4971264
######################################################
# NOTES:
# This is not just an executable shell script.
# You can read this as a blog post also.
# And by excuting, you'll find what I experienced.
# I recommend you to execute this script step by step
# -*- coding: utf-8 -*-
# GistID: 5023699
# Tried by: Rails 3.2.12
# 自己中な (Selfish) Controller
class JikochusController < ApplicationController
def index
@jikochus = Jikochu.all