jQueryクックブック

クックブックなので、通して読む本というよりは知りたいことがあった場合にインデックスから探して解決するための本、つまりクックブック。

ProductName jQueryクックブック
jQuery Community Experts
オライリージャパン / ¥ 3,780 ()
在庫あり。

jQueryを深く知るための本というわけでもないかも、そこもまたクックブック。

以下の章が参考になった。

  • コンテンツに基づいて要素を選択する
  • jQuery.extendを使ってオブジェクトを拡張する
  • テーブルを素早く読み込む
  • ファイルをバックグラウンドでアップロードする
  • QUnitを使ってプラグインをユニットテストする
  • jQueryUI音楽プレーヤーを作成する
  • ユニットテスト(18章)

ソースコードを読むのもいいかな?なんて思ったりもする。

おりがみプログラミング

リストを定義してmap append concatを実装

ProductName 関数プログラミングの楽しみ

オーム社 / ¥ 4,410 ()
在庫あり。

data List a = Nil | Cons a (List a) deriving Show

wrap :: a -> List a
wrap x = Cons x Nil

nil :: List a -> Bool
nil Nil = True
nil (Cons x xs) = False

foldL :: (a -> b -> b) -> b -> List a -> b
foldL f e Nil = e
foldL f e (Cons x xs) = f x (foldL f e xs)

mapL :: (a  -> b) -> List a -> List b
mapL f Nil = Nil
mapL f (Cons x xs) = Cons (f x) (mapL f xs)

appendL :: List a -> List a -> List a
appendL Nil ys = ys
appendL (Cons x xs) ys = Cons x (appendL xs ys)

concatL :: List (List a) -> List a
concatL Nil = Nil
concatL (Cons (Cons x xs) xss) = appendL (Cons x xs) (concatL xss)

追記 091025

foldLを使って書きなおすという問題だったので

mapL :: (a  -> b) -> List a -> List b
mapL f = foldL (Cons . f) Nil

appendL :: List a -> List a -> List a
appendL xs ys = foldL Cons ys xs

concatL :: List (List a) -> List a
concatL xs = foldL appendL Nil

Real World Haskell 3章 (グラハムスキャン)

練習問題3-9,10,11,12

ProductName Real World Haskell―実戦で学ぶ関数型言語プログラミング
Bryan O'Sullivan,John Goerzen,Don Stewart
オライリージャパン / ¥ 3,990 ()
在庫あり。

3-12はわからなかったので、酔いどれコードを参考にした。というかほとんど写経。

量子男のささいなログにも書いてあったけど3-11の使いどころがいまいちわからない。この場合もリスト全部じゃなくて最後のほうだけチェックすればいいような気がした。

-- 3-9,3-10,3-11

data Direction = CounterClockwise | Clockwise | Straight deriving (Show,Eq)
type Pos = (Float,Float)

calcpos :: Pos -> Pos -> Pos -> Direction
calcpos a b c | iprod >  0 = CounterClockwise
              | iprod <  0 = Clockwise
              | iprod == 0 = Straight
              where iprod = ((fst a) - (fst b)) * ((snd c) - (snd b))
                          - ((snd a) - (snd b)) * ((fst c) - (fst b))

directions :: [Pos] -> [Direction]
directions []         = []
directions (x:[])     = []
directions (x:y:[])   = []
directions (x:y:z:zs) = calcpos x y z : directions (y:z:zs)

-- 3-12
sortCoordinate :: [Pos] -> [Pos]
sortCoordinate ps = sortBy cmp ps
    where cmp a b | snd a < snd b = LT 
                  | snd a > snd b = GT
                  | fst a < fst b = LT
                  | fst a > fst b = GT
                  | otherwise = EQ

sortAngle :: Pos -> [Pos] -> [Pos]
sortAngle p ps = sortBy cmp ps
    where cmp a b = compare (cot b) (cot a)
              where cot c = (fst c - fst p) / (snd c - snd p)

gsort :: [Pos] -> [Pos]
gsort ps = let csort = sortCoordinate ps 
               lower = head csort
           in  lower : sortAngle lower (tail csort)

isCounterClockwise :: [Direction] -> Bool
isCounterClockwise [] = False
isCounterClockwise (x:xs) | x == CounterClockwise = True
                          | otherwise = isCounterClockwise xs

scan :: [Pos] -> [Pos] -> [Pos]
scan [] (y1:y2:ys) = scan [y1,y2] ys
scan xs []         = xs
scan xs (y:ys) | isCounterClockwise (directions (xs++[y])) = scan (init xs) (y:ys)
               | otherwise                    = scan (xs++[y]) ys

graham :: [Pos] -> [Pos]
graham xs = scan [] $ gsort xs

-- データ生成用
randX :: [Float]
randX = randomRs (-100,100) (mkStdGen 5)

randY :: [Float]
randY = randomRs (-100,100) (mkStdGen 3)

randPoss :: Int -> [(Float,Float)]
randPoss n = take n $ zip randX randY

Real World Haskell 3章

二周目。今度は問題を解きながら。

というわけで練習問題

回文をつくるのと回文かどうかをチェックする。後者は回文を作ってみて元の文を二つ並べたものと一致するかをチェック

-- 3-4    
mypalin :: [a] -> [a]
mypalin [] = []
mypalin (x:xs) = [x] ++ mypalin xs ++ [x]

-- 3-5
ismypalin :: Eq a => [a] -> Bool
ismypalin xs = (mypalin xs) == (xs ++ xs)

ProductName Real World Haskell―実戦で学ぶ関数型言語プログラミング
Bryan O'Sullivan,John Goerzen,Don Stewart
オライリージャパン / ¥ 3,990 ()
在庫あり。

親子パンづくり教室

娘と参加。

1284971046 1284971052

マックロクロスケ作成中。

1284971015 1284971041

完成。

1284971023

続いてウィンナーロール

1284971058 1284971035

マヨネーズとパン粉をまぶしてオーブンに

1284971029

何かを作るのは楽しい。もう少し料理をする方向にライフスタイルをシフトさせようかなぁ。

今日の畑(100920)

久々に娘を連れて。結果的に失敗。

アイスが食べたい、喉が乾いた、蚊に刺されてかゆいとかトイレ行きたいとかうるさくて草むしりが全然進まなかった。

かろうじて収穫のみ。

茄子は最近皮が固くて食べるのに困る。

1284949580 1284949624

ミョウガはちゃんと採れ始めた。ちょうど鰹を買ってあったらしいのでワシャワシャかけて食べる。夕方イケタニさんで日本酒でも買ってくるかな。

1284949611 1284949592

甘長美人と韓国唐辛子はコンスタントに収穫できるので楽だけど、そろそろ終盤っぽいな。

1284949599 1284949586

アサツキも芽が出てきた。

1284949617

最終的な今日の収穫。

1284949605

今週は休みがちょこちょこあるのでこのタイミングで葉物の種を撒く予定。

メタプログラミングRuby 金曜日

コードを記述するコード

evalとか。pythonだとexecか

ProductName メタプログラミングRuby
Paolo Perrotta
アスキー・メディアワークス / ¥ 2,940 ()
在庫あり。

第二部は「Railsにおけるメタプログラミング」っていう部であまり興味がなかったのでさらっと読み流した。

最後の

メタプログラミングというものなど存在しない。すべてはただのプログラミングじゃ

とこは気に入った。

twitterオフに行ってきた

壱膳屋@沼津

12849366631284936665

カメラとかテクノとかB1

おつです

欲しいなー

ProductName シグマ DP2s COMPACT DIGITAL CAMERA

シグマ / (2010-03-27)
在庫あり。

娘の画力があがっていた

昨日は娘の相手をしていた。

1284936173

パティシエールってコレか。

ProductName 夢色パティシエールマイスイーツクッキング

コナミデジタルエンタテインメント / ¥ 5,250 (2010-05-27)
在庫あり。

メタプログラミングRuby 木曜日

クラス定義

特異クラスとか特異メソッドとか

ProductName メタプログラミングRuby
Paolo Perrotta
アスキー・メディアワークス / ¥ 2,940 ()
在庫あり。

Rubyの話はなんとなくわかったけど、Pythonで考えた場合にいまいち理解が浅い。

DWの連載あとで読もう