Entries from 2011-01-01 to 1 year

ScalaでWebスクレイピングして画像収集する

2011年も相変わらず「Scalaは実用的なのか?」という 「え、実用的も何も、普通に使ってますが、、、」としか答えられない質問を幾度も受けました。 Scalaは実用的で、例えばコミケのコスプレ画像の収集などができます。*1 【コミケ81】コスプレイヤー画像ま…

LiftyでLiftアプリを作る

http://lifty.github.com/ Lift in Actionでも紹介されてるのにイマイチな知名度のLifty。 最近sbtの0.11系に対応しました。 Liftyを使えば lifty create lift project でプロジェクト作成 lifty create lift mapper でモデルのテンプレ作成 lifty create li…

ScalaQueryでConnection Poolを使う

Database#createConnectionをoverrideします。 ConnectionPoolはscalikejdbc/scalikejdbc · GitHubを使わせてもらいました。

ScalaQueryでレコードをcase classにマッピングする

少し前のエントリ(ScalaQueryの使い方&サンプル集)ではDBのレコードをタプルにマッピングしましたが、 case classにマッピングすることもできます。<>にapplyとunapplyを渡すのですね。ちょっとかっこ悪いような。 で、<>が定義されているのは...https://git…

unfiltered-scalateがunfilteredのexternal module扱いになっていた件

いつの間にかunfiltered-scalateがunfiltered本体のリポジトリから外され、external moduleになってました。 https://github.com/unfiltered/unfiltered-scalate 気になってunfilteredのMLを漁りました。理由っぽいのを見つけました。 https://groups.google…

第二回Scala会議にて勝手にrpscala/akskscalaの宣伝をした

http://www.ustream.tv/recorded/19044858/highlight/224421 ust、なんなんでしょうかこの画質...yusukeyさんごいすー...

ScalaQueryの使い方&サンプル集

Scala Advent Calendar jp 2011 - PARTAKEの2日目の記事です。 Scala から RDB を使う必要があり、 ScalaQuery をいろいろ調べてみました。 DBオブジェクトの取得 Database.forURL とかを使います。 scala> import org.scalaquery.session.Database import o…

ScalaQuery で SQL を実行する

ScalaQuery を使おうかと思っていじってます。とりあえずシンプルに SQL を実行するところから。StaticQuery ってのを使うみたいです。 https://github.com/szeiger/scala-query/blob/master/src/main/scala/org/scalaquery/simple/StaticQuery.scala データ…

1 + 1 が意外に難しい

「Daimon.scala 第21回 (Scala School 斜め読み1)」 : ATNDでの一幕 1 + 1 = 2 ですね。 scala> 1 + 1 res0: Int = 2 ところで、Scala では演算子は実はメソッドです。 A method B は A.method(B) です。 なので 1 + 1 は 1.+(1) と書けるはず。 scala> 1.…

Loan Patternいろいろ(using, scalazのwithResource, scala-arm)

まずはコード1を見てください。 // コード1 def copyFile() = { val in = new FileInputStream(new File("foo.txt")) val out = new FileOutputStream(new File("bar.txt")) val buf = new Array[Byte](1024) var len = 0; while ({ len = in.read(buf); len…

はじめての sbt-plugin

sbtでコマンドを定義する - tototoshiの日記にてコマンドの定義の仕方を書きました。 今度はこれの延長で sbt-plugin を作ってみます。 sbt-plugin にすることで再利用しやすくなりますね。 作るもの hello コマンドを追加する sbt-hello-plugin を作ります…

sbtでコマンドを定義する

sbtでは独自にコマンドをできます。使用するのは Command.command, Command.single, Command.args です。 引数なしのコマンドを定義する Command.command を使います。 val command: Command = Command.command("name")(action) 1つ目の引数がコマンド名、 2…

Scala で Twitter の Streaming API を使ってみる

Streaming API についてのドキュメントはこちら The Streaming APIs | Twitter Developers Twitter4j 使ってしまえば便利ですね。

.sbtrcでaliasを設定できることを教えてもらった

@xuwei_k の誕生日を祝う会 兼 Scalaハッカソン - PARTAKEに参加しました。 その懇親会で教えてもらった豆知識。 sbt0.10以降? ~/.sbtrc に alias c=compileと書くと c で compile できる! ちなみに alias c='compile'とかだとだめでした。

nautilus@Ubuntu11.10 の「別のアプリで開く」にコマンドを指定する

11.04までは当然のようにできたのに、 11.10 から設定項目が消えていた。。。 具体的には nautilus から emacsclient 使えなくて困る。 ~/.local/share/applications に *.desktop ファイルを作ればできました。 11.10 - File / Application association usi…

Geany で Scala のシンタックスハイライトが効くようになってたよ

最近リリースされた Geany 0.21でようやく Scala のシンタックスハイライトが効くようになりました。 Ubuntu11.10 で apt-get したら 0.20 が入っちゃったので、ソースで入れました。Geany : 20111002 Add support for real-time symbol parsing. Fix loadin…

picture-show でスライドを作りましょう

Scala勉強会第57回 in 秋葉原で picture-show について少ししゃべりました。 スライド A small introduction to picture show スライドのソース picture-show-introduction at master from tototoshi/slides - GitHub

【質問】scalaアクターのself.receive がREPLでブロックされちゃう件について

// sample1.scala import scala.actors.Actor._ self ! "Hello" self.receive { case x => println(x) } sample1.scala を $ scala sample1.scala として実行すると Hello という結果が得られるわけですが、 これをREPLで読み込ませると receive のとこでブ…

sbt の Build.scala を書く

sbt は 0.10 系から? build.sbt での設定と Build.scala での設定の両方が使えるようになりました。*1 使い分け方 基本的に build.sbt も Build.scala もできることに変わりはありません。 ただし build.sbt は記述が簡単な一方で制限があります。平たく言…

Ubuntu 11.10 でログインサウンドを無効にする方法

Ubuntu をインストールしたらまず、まずあの変な民族楽器風のログインサウンドを消さねばなりません。 アフリカのサバンナとかならわかりますがここはTokyoなのです。 あと、そもそも静かなところで起動したときに音がなると恥ずかしいです。 以前は Ubuntu …

Specs2を試す(10) - Layout -

参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Layout The rules Specs2 の Acceptance Specification を使うとソースコードに書いた Text および Example がほぼそのままの形でレポートに出る。 Specs2 のレポー…

Specs2を試す(9)

参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Shared+examples Declare arguments specの最初にarg(ほにゃらら=true)をくっつけることで、specの実行やレポートの挙動を返ることができる。コード1 は args(sequen…

Specs2を試す(8)

Single step Given/When/Then の3つのステップは GivenThen で1つにまとめることができる。 import org.specs2._ import specification._ class GivenThenSpec extends Specification { def is = "given the name: ${eric}, then the age is ${18}" ! new Gi…

Specs2を試す(7)

ScalaCheck values Given/When/Then シーケンスで scalacheck の generator を使う方法。 import org.scalacheck._ import org.scalacheck.Gen._ import org.scalacheck.Prop._ import org.specs2._ import org.specs2.specification.gen._ class GivenWhenT…

Specs2を試す(6)

Given/When/Then Given/When/Then というスタイルでspecを書くこともできる。 // コード1 import org.specs2._ import org.specs2.specification._ import org.specs2.execute._ class GivenWhenThenSpec extends Specification { def is = "A given-when-th…

Specs2を試す(5)

Pending until fixed 一時的にテストを実行したくないときは pendingUntilFixed が使える。 // テスト1 import org.specs2._ class HelloWorldSpec2 extends Specification { def is = "This is a specification to check the 'Hello world' string" ^ p^ "T…

Scalaでtrコマンドっぽいの

trコマンドみたいなことやりたかったんだけど、そのものズバリ的なものないですかね。 def transform[A](dict: List[(A, A)], xs: List[A]): List[A] = { def replace(t: (A, A), xs: List[A]): List[A] = xs.map { case x if x == t._1 => t._2 case x => x…

Specs2を試す(4)

参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Declare+examples Result // コード1 "this is my specification" ^ "and example 1" ! e1^ "and example 2" ! e2 def e1 = success def e2 = success 上の例の "and…

Specs2を試す(3)

Unit specification Unit specification はshould/inブロックを使ってFragments(Fragmentのリスト)を作る。 Acceptance Specification は org.specs2.Specification を継承しているのに対し、 Unit specification は org.specs2.mutable.Specification を継…

Specs2を試す(2)

Acceptance specification 参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Specification+structureAcceptance specification では、一つ一つの'frgment'を^でつなぎ、 'fragmentのリスト(flagments)'を作るという…