17102009 Linux
スレッドプログラミング(pthread)
12章のwebサーバをスレッドを利用するように書き換える。
17102009 Linux
スレッドプログラミング(pthread)
12章のwebサーバをスレッドを利用するように書き換える。
17102009 Linux
データグラム通信を利用したライセンスサーバを書く。
17102009 Linux
Cでweb serverを書く
GETだけをサポートした簡単なものを書いた。
15102009 Scala
Souce.fromURLで
import scala.io.Source
object Main {
def main(args : Array[String]) : Unit = {
println(
Source.fromURL("http://blog.kzfmix.com/","utf8")
.getLines
.mkString
)
}
}
proxyの指定は
import scala.io.Source
object Main {
def main(args : Array[String]) : Unit = {
System.setProperty("http.proxyHost","proxy.co.jp")
System.setProperty("http.proxyPort","8080")
println(
Source.fromURL("http://blog.kzfmix.com/","utf8")
.getLines
.mkString
)
}
}
参考 - scala.io.Sourceとscala.xml.parsing.XhtmlParserCommentsAdd Star
14102009 Linux
ソケット
socket->bind->listen->accept->read/write->close
14102009 Scala
おもむろに。
scala> var increase = (x: Int) => x + 1
increase: (Int) => Int = <function>
scala> val l = List(1,2,3,4,5)
l: List[Int] = List(1, 2, 3, 4, 5)
scala> l map increase
res3: List[Int] = List(2, 3, 4, 5, 6)
scala> l.map(increase)
res5: List[Int] = List(2, 3, 4, 5, 6)
map 関数 listじゃなくてlist map 関数なのね
gauche
gosh> (map (lambda (x) (+ x 1)) '(1 2 3 4 5))
(2 3 4 5 6)
clojure
user=> (map (fn [x] (+ x 1)) [1 2 3 4 5])
(2 3 4 5 6)
14102009 Linux
11.4 popenを書く
pipeしてforkして親の標準入力をパイプにつないで、この標準出力をパイプにつないで、execlでsh -c commandを実行する
shの-cオプションはコマンドを実行して終了する。
-c string If the -c option is present, then commands are read from string.
If there are arguments after the string, they are assigned to the positional
parameters, starting with $0.