2007-07-01から1ヶ月間の記事一覧

ファイルの中身とマッチさせるテンプレート

Jscriptでそれなりに使えるだろうから備忘録としてとっておく。 cmd =WScript.CreateObject("WScript.Shell"); exe=cmd.Exec("cmd /c type C:\\foo\\bar.txt"); s=exe.StdOut.ReadAll(); target=/正規表現/.exec(s)[1]; //WScript.echo(pass); ie=WScript.Cr…

自機のIPアドレスをクリップボードに入れる

ipconfigコマンドを実行し、ieを用いてクリップボードに入れる。 cmd =WScript.CreateObject("WScript.Shell"); exe=cmd.Exec("ipconfig.exe"); s=exe.StdOut.ReadAll(); ip=/\d+\.\d+\.\d+\.\d+/.exec(s)[0]; ie=WScript.CreateObject('InternetExplorer.Ap…

100円ライター

接写するとそれなりに迫力がある。

日本語化

http://portableapps.com/マシンを移るたびにfirefoxがリセットされるのが耐えられなくなった。http://kicku.blog44.fc2.com/blog-entry-20.html 以上を参考にfirefox-potableをインストール&日本語化した。

関数内のコマンドに引数をそのまま渡す

単に "$*" でよかった。以下の実験により理解。 function中で代入される引数の""を外さないようにしたかった。 $ echo "aaa bbb" ccc aaa bbb ccc $ function a() { echo $*; }; a "aaa bbb" ccc aaa bbb ccc $ function a() { echo "$*"; }; a "aaa bbb" cc…

haskellに惚れた一瞬

haskellによるFizzBuzz別解。zipWith3とcycleで気持ちよく組めました。 putStr$concat$zipWith3 (\x y z->(if x++y=="" then show z else x++y)++"\n") (cycle ["","","Fizz"] )(cycle ["","","","","Buzz"])[1..100] 嫌なんだけど mapM_の方が短くなるな。…

runghc -eを直したので以下でいける。 $ runghc -e 'import System;main=getArgs>>=mapM_ catFile;catFile a=do{c<-readFile a;mapM_ putStrLn $ zipWith (\x y->(reverse$take 4$reverse(" "++(show x)))++" "++y) [1..] (lines c)}' a.txt 1 aaa 2 bbb 3 …

後ろから取ってくるtake

やっぱreverse$take$reverseの方が短いしわかりやすい。 しかし、なんてださいんだ>if ガードかパターンマッチで書くべきなんだろうが一行でかけない。 Prelude> let takelst n s=if n==0 then [] else (if n==1 then [] else takelst(n-1)$init s)++[last …