Skip to content

Instantly share code, notes, and snippets.

@mmitou
mmitou / calc.hs
Created March 24, 2013 10:45
積分をあれこれ
import Control.Monad
linearScale :: (Fractional a, Integral b) => (a, a) -> b -> ([a], a)
linearScale (begin, end) n = (xs, dx)
where
dx = (end - begin) / (fromIntegral n)
xs = [(fromIntegral n) * dx + begin | n <- [0 .. ]]
forwardEuler :: (Fractional a, Integral b) => (a, a) -> b -> (a -> a) -> [a]
forwardEuler range n f = ys
makePyramid :: Int -> [String]
makePyramid h | h < 1 = []
| otherwise = [makeLine n | n <- numbers]
where
numbers = take h [x | x <- [1..], odd x]
l = last numbers
makeLine n = spaces ++ asters ++ spaces
where
numOfSpaces = (l - n) `div` 2
spaces = [' ' | _ <- [1 .. numOfSpaces]]
@mmitou
mmitou / tmux.conf
Created July 12, 2013 09:22
tmuxの設定サンプル
# Prefix
set-option -g prefix C-z
# 日本語環境
setw -g utf8 on
set -g status-utf8 on
# 設定の再読み込み
bind C-r source-file ~/.tmux.conf
@mmitou
mmitou / Hello.cabal
Created July 12, 2013 09:49
gtk2hsでHello, world
-- Initial Hello.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: Hello
version: 0.1.0.0
synopsis: Hello world
-- description:
homepage: http://foobar
license: MIT
license-file: LICENSE
@mmitou
mmitou / memo.md
Created July 13, 2013 06:47
fedora 19 インストール後のメモ

fedora 19インストール後の作業メモ

必要そうなものをインストールする

sudo yum update  -y
# mozc関連
sudo yum install -y mozc*
# ibus関連
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
const uint64_t MAP_ARRAY_LENGTH = 100;
struct map_node {
uint64_t state;
void *value;
struct map_node *next;
@mmitou
mmitou / printFile.hs
Created September 8, 2013 22:18
ファイル表示
{-# LANGUAGE ScopedTypeVariables #-}
import System.IO
import Control.Monad
import Control.Exception
printFile :: FilePath -> IO ()
printFile filePath = do
h <- openFile filePath ReadMode
x <- hGetContents h
putStrLn x
import Control.Monad.Trans.Resource(runResourceT, allocate, release)
import Control.Monad.IO.Class(liftIO)
import System.IO
printFile :: FilePath -> IO ()
printFile filePath = runResourceT $ do
(releaseKey, resource) <- allocate (openFile filePath ReadMode) hClose
liftIO (hGetContents resource >>= putStrLn)
release releaseKey
return ()
@mmitou
mmitou / post.hs
Created September 24, 2013 01:06
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Conduit
import Data.Conduit
import Data.Conduit.Binary
import Control.Monad.IO.Class (liftIO)
import Data.Conduit
import System.IO
@mmitou
mmitou / find.hs
Created October 4, 2013 09:47
ファイルを探す処理をconduitで書く
{-# LANGUAGE RankNTypes #-}
import Data.Conduit
import qualified Data.Conduit.List as CL(consume, filter)
import Data.Conduit.Filesystem
import qualified Filesystem.Path as FP (FilePath, filename)
import Control.Monad.IO.Class(MonadIO)
pickup :: (Monad m) => FP.FilePath -> Consumer FP.FilePath m (Maybe FP.FilePath)
pickup target = await >>= pickup'
where