Skip to content

Instantly share code, notes, and snippets.

View tototoshi's full-sized avatar

Toshiyuki Takahashi tototoshi

View GitHub Profile
@tototoshi
tototoshi / AA.txt
Created September 14, 2012 15:41
join(1) in scala
AA 100円
BB 300円
CC 200円
DD 400円
EE 500円
@tototoshi
tototoshi / CSVImplicits.scala
Created August 25, 2012 14:48
CSV Parser in scala
object CSVImplicits {
implicit def toCSVIterator(it: Iterator[String]): toCSVIterator = new toCSVIterator(it)
class toCSVIterator(it: Iterator[String]) {
def asCSV: CSVIterator = new CSVIterator(it)
}
}
@tototoshi
tototoshi / try1.scala
Created August 23, 2012 12:16
Trying scala.util.Try
import scala.util.{ Try, Success }
import scala.util.control.Exception._
object Main extends App {
val result = for {
i <- Try("abc".toInt) recover {
case e: NumberFormatException => 1
}
j <- Try("2".toInt)
@tototoshi
tototoshi / sawk.scala
Created August 15, 2012 03:27
scala で awk っぽいの
package sawk
import scala.io.Source
import scala.collection.mutable.Map
object Sawk {
def apply(script: SawkScript): Unit = {
script.run
}
}
@tototoshi
tototoshi / KeyedEntityDefExample.scala
Created August 11, 2012 06:53
Squeryl's KeyedEntityDef
import org.squeryl.annotations.Column
import org.squeryl.PrimitiveTypeMode._
import org.squeryl.{ Session, SessionFactory, Schema, KeyedEntityDef }
import org.squeryl.adapters.{ PostgreSqlAdapter }
import java.util.Date
object KeyedEntityDefsExample extends App {
class Member (
val name: String,
@tototoshi
tototoshi / example2.scala
Created August 5, 2012 08:32
start_scalaz
import scalaz._, Scalaz._
case class User(id: String, pass: String)
object Main extends App {
implicit object userShow extends Show[User] {
def show(u: User) = u.toString.toList
}
@tototoshi
tototoshi / named_capture.rb
Created July 30, 2012 12:51
named capturing in ruby's regexp
s = "abc:123"
p = /(?<alpha>[a-z]+):(?<num>\d+)/
m = p.match(s)
puts m[:alpha] #=> abc
puts m[:num] #=> 123
@tototoshi
tototoshi / Hello, world
Created July 26, 2012 11:40
O/R Broker examples
import org.orbroker._
import org.orbroker.config._
object HelloWorld {
def main(args: Array[String]) {
val jdbcURL = args(0)
val config = new BrokerConfig(jdbcURL)
val broker = Broker(config)
val count = broker.readOnly() { session =>
@tototoshi
tototoshi / trying_string_interpolation.scala
Created July 17, 2012 14:52
trying string interpolation in scala 2.10
/* SIP11 https://docs.google.com/document/d/1NdxNxZYodPA-c4MLr33KzwzKFkzm9iW9POexT9PkJsU/edit?hl=en_US */
toshi@/home/toshi% ./opt/scala-2.10.0-M5/bin/scala
Welcome to Scala version 2.10.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_32).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val n = 10
n: Int = 10
@tototoshi
tototoshi / trouble_with_jgit_and_JavaConversions.scala
Created July 16, 2012 02:42
trouble with jgit & scala.collection.JavaConversions
// import scala.collection.JavaConversions._
scala> val git = new Git(new FileRepositoryBuilder().findGitDir(new java.io.File("/path/to/repos")).readEnvironment().build())
git: org.eclipse.jgit.api.Git = org.eclipse.jgit.api.Git@18ed36fb
scala> git.log.addPath("foo").call.head
res49: org.eclipse.jgit.revwalk.RevCommit = commit c4554d9f46de49e449242a2aa75d39874dc99498 1342332998 ----sp
scala> git.log.addPath("foo").call.headOption
res50: Option[org.eclipse.jgit.revwalk.RevCommit] = Some(commit d3107ef998b25d70f86f1a5d530c31c02507d59e 1342012813 ----sp)