Skip to content

Instantly share code, notes, and snippets.

@takezoux2
takezoux2 / repl_support.scala
Created November 16, 2011 03:53
Scala's REPL support script.You can use file easily.
import scala.io.Source
import java.io.{FileInputStream,FileOutputStream,InputStream,OutputStream,File}
import scala.xml.{XML,Elem}
// usage
// val fileAsText = "clannad.txt" loadText
// "air.txt" << "This text is written to file air.txt"
//
class FileObject( filePath : String) {
@takezoux2
takezoux2 / SimpleHttpServer
Created November 22, 2011 10:55
Simple server which prints received headers
import cgi
import BaseHTTPServer,CGIHTTPServer
class MyHandler(CGIHTTPServer.CGIHTTPRequestHandler):
def printPath(self):
print "Path:",self.path
def printHeaders(self):
headers = self.headers
@takezoux2
takezoux2 / SimpleArgsParser.scala
Created January 31, 2012 03:04
Simple command line args parser.
/*
{{{
def main(args : Array[String]) = {
val aMap = SimpleArgsParser.parse(args)
...
}
}}}
Parse command line args and convert to Map
For example
"scala hoge.scala -f fuga.txt --help -v"
@takezoux2
takezoux2 / MavenToSBTDependencies.scala
Created February 16, 2012 13:42
Extract dependencies from pom file and convert to sbt dependencies.
import scala.xml.Elem
import scala.xml.XML
/**
* From console.
* scala MavenToSBTDependencies _pom_file_ {sbt or scala}
*/
object MavenToSBTDependencies{
case class Dep(scala_? : Boolean, vals : List[String]){
@takezoux2
takezoux2 / ConnectionWrapper.scala
Created June 12, 2012 15:21
simplest java.sql.Connection wrapper for scala
import java.sql.{Savepoint, Connection}
import java.util.{Properties, Map}
import java.util.concurrent.Executor
class ConnectionWrapper(connection : Connection) extends Connection{
def setReadOnly(v0 : Boolean) = connection.setReadOnly(v0)
def close() = connection.close()
def isValid(v0 : Int) = connection.isValid(v0)
def isReadOnly() = connection.isReadOnly()
@takezoux2
takezoux2 / build.sbt
Created October 23, 2012 03:43
Error occurs while compile in sbt 0.12.X
libraryDependencies := Seq("org.specs2" %% "specs2" % "1.11" % "test") // regardless of libraries
/*
This build.sbt works well in sbt 0.11.X.
But in sbt 0.12.X this build.sbt throws below Exception while compiling
> compile
[info] Compiling 1 Scala source to PROJECT_PATH\target\scala-2.9.2\classes...
@takezoux2
takezoux2 / ReflectionSample.scala
Last active December 9, 2015 18:39
Sample code for scala reflection.
import scala.reflect.runtime.universe._
import scala.reflect._
object App{
def main(args : Array[String]){
val m = toMap(User("Kudo",2,false))
println(m)
@takezoux2
takezoux2 / detect-jdbc-driver-name.scala
Created February 13, 2013 04:42
Detect jdbc driver name from jdbc url.
def detectDriverNameFromUrl(url : String) : Option[String] = {
val splits = url.split(":")
if(splits.length < 2){
return None
}
if(splits(0) != "jdbc"){
return None
}
Wifi
SSID:LabWirelessFree
PASS:なし
Twitterハッシュタグ: #rpscala
飲食は可ですが、ごみは持ち帰りです。
コンビニは、ラクーアの方へ坂おりる途中にローソンがあります。
ランチは適当に各自行ってください。
@takezoux2
takezoux2 / SealedClassEnum
Last active December 17, 2015 14:49
scala勉強会で出た話題のコード。 sealed classを使ってEnumerationと同じようなことを行う。
object App
{
def main(args : Array[String]){
doMatch(args[0].toInt)
}
def doMatch( id : Int) = {
id match{
// scala2.10では()つけないとコンパイルエラーなのであまりいけてない?
case Status.OK() => println("OK")