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.swing.{ Component, Swing, event } | |
import javax.swing.JComboBox | |
/** | |
* Very basic Mutable ComboBox for Scala. | |
* <p>Sample usage:<p> | |
* <pre> | |
* val box = new MutableComboBox[String] | |
* box.items = List("1", "11", "222") | |
* listenTo(box) |
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
// A function to parse page set defintion, which supports [overlapping] ranges | |
def pageSet(definition: String) = { | |
def pageDefToSet(pageDef: String): Set[Int] = { | |
val rangeExtractor = """[^\d]*([\d]+).*-[^\d]*([\d])+[^\d]*""".r | |
val numberExtractor = """[^\d]*([\d]+)[^\d]*""".r | |
pageDef match { | |
case rangeExtractor(from, to) => (from.toInt to to.toInt).toSet | |
case numberExtractor(num) => Set(num.toInt) | |
case _ => Set() | |
} |
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 java.util.{ Collection => JCollection } | |
import java.lang.{ Long => JLong } | |
import java.sql.Timestamp | |
import scala.collection.JavaConversions._ | |
import org.squeryl.Query | |
import com.vaadin.data._ | |
import scala.reflect.ClassTag | |
import org.squeryl.dsl.ast.OrderByArg | |
import org.squeryl.dsl.ast.ExpressionNode |
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
trait XsnTypeMode extends PrimitiveTypeMode { | |
import com.codahale.jerkson.Json._ | |
import scala.collection.mutable.HashMap | |
import scala.language.implicitConversions | |
implicit val jsonTEF = new NonPrimitiveJdbcMapper[String,HashMap[String, Any],TString](stringTEF, this) { | |
def convertFromJdbc(v: String) = if(v == null) null else parse[HashMap[String, Any]](v) | |
def convertToJdbc(v: HashMap[String, Any]) = if(v == null) null else generate(v) | |
override def sample = new HashMap[String, Any]() | |
} |
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
/** Test results: | |
Benchmark Mode Samples Mean Mean error Units | |
c.t.MyBenchmark.testString thrpt 200 391517.835 3311.834 ops/ms | |
c.t.MyBenchmark.testSymbol thrpt 200 36618.384 193.733 ops/ms | |
*/ | |
package com.test { | |
import org.openjdk.jmh.annotations.GenerateMicroBenchmark |
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
Sample benchmark: https://gist.github.com/voronaam/11273582 | |
Setup instruction: http://blog.vorona.ca/measuring-scala-performance-with-jmh.html | |
Regexp benchmark: | |
someString.split("[_,;,-]"); | |
vs | |
private static final Pattern PATTERN = Pattern.compile("[_,;,-]"); | |
PATTERN.split(someString); |
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
/** | |
* This is a benchmark to gauge if there is any performance hit into using Option.apply() in Scala. | |
* Use JMH to build it: http://blog.vorona.ca/measuring-scala-performance-with-jmh.html | |
*/ | |
package org.sample | |
import org.openjdk.jmh.annotations._ | |
import java.util.concurrent.TimeUnit |
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 com.test; | |
import java.util.Arrays; | |
import java.util.Random; | |
import java.util.concurrent.TimeUnit; | |
import org.openjdk.jmh.annotations.Benchmark; | |
import org.openjdk.jmh.annotations.BenchmarkMode; | |
import org.openjdk.jmh.annotations.Fork; | |
import org.openjdk.jmh.annotations.Measurement; |
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.eclipse.mat.ui.snapshot.actions; | |
import java.io.BufferedOutputStream; | |
import java.io.BufferedWriter; | |
import java.io.DataOutputStream; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.OutputStreamWriter; | |
import java.io.PrintWriter; | |
import java.util.HashSet; |
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.sample; | |
/** | |
* Results: | |
* Benchmark Mode Cnt Score Error Units | |
* MyBenchmark.testChain avgt 200 0.019 ± 0.001 us/op | |
* MyBenchmark.testNoChain avgt 200 0.019 ± 0.001 us/op | |
*/ | |
import org.openjdk.jmh.annotations.Benchmark; |
OlderNewer