This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.specs2.mutable._ | |
import org.specs2.specification._ | |
import org.mockito.Mockito._ | |
import com.mongodb.casbah.Imports._ | |
import com.twitter.finagle.http._ | |
import com.twitter.finagle.http.path._ | |
import com.twitter.finagle.{ Service, Filter, SimpleFilter } | |
import com.twitter.util.{ Future, FuturePool, Eval } | |
import scala.util.control.Exception._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def string2Int(sizeString: Option[String]): Option[Int] = { | |
sizeString match { | |
case Some(a) => | |
try { | |
val size = a.toInt | |
Option(size) | |
} catch { | |
case _ => | |
None | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._, Scalaz._ | |
import java.util.Date | |
case class Student(name: String, grade: Int, birthday: Date) | |
object Student { | |
implicit object StudentInstance extends Show[Student] with Order[Student] { | |
def show(s: Student) = s.toString.toList | |
def order(s1: Student, s2: Student) = | |
s1.grade ?|? s2.grade |+| s1.birthday ?|? s2.birthday | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
import sbt.Keys._ | |
object Scala210Build extends Build { | |
lazy val scala210 = Project( | |
id = "scala-210", | |
base = file("."), | |
settings = Project.defaultSettings ++ Seq( | |
name := "Scala 210", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.control.Exception._ | |
object Main { | |
def main(args : Array[String]) : Unit = { | |
args.toList.filter(allCatch either _.toInt isRight).sorted.foreach(println) | |
} | |
} | |
// 数値かどうかをチェックするのに、toInt関数を呼んで例外が発生するかどうかでチェックするとか | |
// 良いやりかたでは無いと思います。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val op: Pair[BigInt, BigInt] = Pair(1, 1) | |
(0 until 10).foldLeft(op) { (ab, x) => | |
println(ab._1) | |
Pair[BigInt, BigInt](ab._2, ab._2 + ab._1) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example | |
import org.apache.log4j.Logger | |
object Log4jproject extends App { | |
val logger: Logger = Logger.getLogger(this.getClass.getName) | |
logger.info("log4j test") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path = 'http://api.tumblr.com/v2/blog/%s.tumblr.com/post/edit' % [user] | |
header = { | |
'reblog_key'=> reblog_key, | |
'id' => postid, | |
'state' => 'published' | |
} | |
response = @access_token.post(path, header) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<source> | |
type tail_ex | |
path /log_dir/postlog/%Y/%m/%d.txt | |
tag posts | |
format /^(?<user>.*)\t(?<postid>.*)\t(?<date>.*)\t(?<rk>.*)\t(?<offset>.*)\t(?<count>.*)$/ | |
pos_file /var/tmp/fluentd_quote.pos | |
refresh_interval 1800 | |
</source> | |
# <match debug.**> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'logger' | |
class MyFormatter < Logger::Formatter | |
def call(severity, timestamp, progname, msg) | |
if String === msg then | |
if msg.nil? or msg.empty? then | |
return "\n" | |
else | |
return "%s %s\n" % [timestamp.strftime("%H:%M:%S"), msg] | |
end |