snippet

Haskell で json を扱う

JSON Schema が提案されたりして、ますます使う機会が増えてきた JSON。 Haskell では http://hackage.haskell.org/cgi-bin/hackage-scripts/package/json を使って JSON を扱うことができる。 そこで、http://delicious.com の hot list をとってくるサンプ…

HaXml で html をパース

Haskell Haxml モジュール サンプルコード - x76789の研究メモ を参考にして、http://qb6.2ch.net/_403/madakana.cgi を見て自分が規制されているかどうか表示するコードを書いた。 Parsec もそうだけど、コンビネータを使ったパーサって使い方が面白い。あ…

リダイレクトをたどる

Network.HTTP の練習がてらに。 http://hackage.haskell.org/packages/archive/HTTP/4000.0.5/doc/html/Network-HTTP.html 標準入力からURLのリストを受けとって、標準出力にそれぞれの最終的なリダイレクト先の URL を表示する。 module Main where import …

ファイルサイズの取得

元ネタ http://ja.doukaku.org/243/ module Main where import IO import System (getArgs) import Maybe (fromMaybe) getFileSize :: String -> IO (Maybe Integer) getFileSize path = catch (bracket (openFile path ReadMode) hClose (\h -> hFileSize h…

mixi API を用いて日記を投稿する

mixi API の使い方は http://ido.nu/kuma/2008/07/30/digging-mixi-for-iphone-application-and-new-api-for-posting-a-diary-with-a-photo/ を参考にした。 また、mixi API に使われている WSSE という認証方法については はてなフォトライフAtomAPI を参考…

ちょっと修正

簡易マイミク更新チェッカー - EAGLE 雑記 なんか一部無駄なことをしていたので修正。 @@ -63,7 +63,7 @@ # post datetime dt = li.at('dt').text.toutf8.strip if date_re.match(dt) - dt = Time.local(*[$1, $2, $3, $4, $5]) + dt = Time.local($1, $2, $…

簡易マイミク更新チェッカー

手動で更新チェックは面倒なので。 nokogiri でごりごり html を解析している。 ruby1.8 でも ruby1.9 でも nokogiri さえ入っていれば動くはず。 使い方としてはまぁ見ての通りで、最初に yamlpath のところに email: foo@example.com password: xxxxxxxx …

ランダムな ASCII 文字列を作る

これから適当な短いコードを書くときには snippet というカテゴリにしよう。 Create a random password encrypted with md5 with custom lenght Using awk, echo, md5sum これを見て、そういや以前適当にランダムな ASCII 文字列を作るスクリプトを書いたな…