Skip to content

Instantly share code, notes, and snippets.

@takezoe
takezoe / sample.scala
Created January 1, 2012 07:37
[scalaxb]How are repeated child elements mapped to case classes?
case class Person(personsequence1: jp.sf.amateras.scala.util.xsd.PersonSequence1*)
case class PersonSequence1(lang: jp.sf.amateras.scala.util.xsd.Lang)
case class Lang(value: String)
@takezoe
takezoe / BreakableIterationCallback1.java
Created January 16, 2012 09:38
Plan about breakable IterationCallback in Mirage
// SqlManager#iterate()内でBreakableIterationCallbackだったらisBreak()をチェックするようなイメージ。
public abstract class BreakableIterationCallback<A, B> implements IterationCallback<A, B> {
private boolean break = false;
public void setBreak(){
this.break = break;
}
public boolean isBreak(){
@takezoe
takezoe / gist:1621843
Created January 16, 2012 17:12
Trouble in the Anorm Parser Combinator API
// これはOK
val result = SQL("SELECT * FROM EMP E INNER JOIN DEPT D ON D.DEPT_ID = E.DEPT_ID ORDER BY EMP_ID")
.as(Emp ~< Dept *)
// これもOK
val result = SQL("SELECT * FROM EMP E " +
"INNER JOIN DEPT D ON D.DEPT_ID = E.DEPT_ID " +
"ORDER BY EMP_ID").as(Emp ~< Dept *)
// これはNG
@takezoe
takezoe / Book.scala
Created February 12, 2012 05:44
Getting Started of mirage-scala
case class Book(
@(PrimaryKey @field)(generationType = IDENTITY) bookId: Option[Long],
bookName: String,
author: String,
price: Option[Int]) {
// default constructor
def this() = this(None, null, null, None)
}
@takezoe
takezoe / build-count.xml
Created February 25, 2012 06:03
StepCounterTaskを使用するAntビルドファイルの例
<?xml version="1.0" encoding="UTF-8"?>
<project default="count" basedir="." >
<!-- 独自タスクの定義 相対パスからの target フォルダ配下にJARを置いてください。-->
<taskdef name="stepcounter" classname="jp.sf.amateras.stepcounter.ant.StepCounterTask"
classpath="target/stepcounter-3.0.1-SNAPSHOT-jar-with-dependencies.jar" />
<taskdef name="diffcounter" classname="jp.sf.amateras.stepcounter.ant.DiffCounterTask"
classpath="target/stepcounter-3.0.1-SNAPSHOT-jar-with-dependencies.jar" />
<target name="count">
@takezoe
takezoe / Pico.scala
Created April 7, 2012 16:04
Simple wrapper of PicoContainer for Scala
import org.picocontainer.DefaultPicoContainer
/**
* Simple wrapper of PicoContainer for Scala.
*
* {{{
* val pico = new Pico()
* .add[Apple]
* .add[Juicer]
* .add[Peeler]
@takezoe
takezoe / MacroSample.scala
Created April 26, 2012 18:25
Macro Example in scala-2.10.0-20120419
import language.experimental.macros
import scala.reflect.makro.Context
object MacroSample {
def compiledTime(): String = macro compiledTime_impl
def compiledTime_impl(c: Context)(): c.Expr[String] = {
import c.mirror._
import c.reify
@takezoe
takezoe / NotVar.scala
Created April 28, 2012 15:09 — forked from xuwei-k/NotVar.scala
not var macro scala
def NotVar(expr: Any): Any = macro NotVarImpl
def NotVarImpl(c: Context)(expr: c.Expr[Any]): c.Expr[Any] = {
import c.mirror._
import reflect.api.Modifier.mutable
Expr((new Transformer{
override def transform(tree:Tree):Tree = tree match{
case ValDef(m,_,_,_) if m.hasModifier(mutable) => sys.error("can't use var !!!")
case _ => super.transform(tree)
@takezoe
takezoe / RunScalaTest.scala
Created May 19, 2012 04:27
An example which runs ScalaTest by program
import org.scalatest._
import org.scalatest.events._
/**
* An example which runs ScalaTest by program.
*/
object RunScalaTest extends App {
// MySuite is a testsuite
new MySuite().run(None, new Reporter {
@takezoe
takezoe / gist:2793666
Created May 26, 2012 11:47
Case class support in solr-scala-client
case class Product(id: String, manu: String, name: String)
val client = new SolrClient("http://localhost:8983/solr")
val result = client.query("name: %name%")
.fields("id", "manu", "name")
.sortBy("id", Order.asc)
.getResultAs[Product](Map("name" -> "ThinkPad X201s"))
result.documents.foreach { product =>