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
object Conf extends ScallopConf(List("-a","3","-b","5","tree")) { | |
val apples = opt[Int]("apples") | |
val bananas = opt[Int]("bananas") | |
verify | |
} | |
Conf.apples() // 3 | |
Conf.bananas.get // Some(5) |
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 LogConfig(configItem: String, configValue: Any) = { | |
val logString = configValue match { | |
case configValueMap: Map[_,_] => "Configured " + configItem + " to " + configValueMap.mkString("{",", ","}") + "." | |
case _ => "Configured " + configItem + " to " + configValue + "." | |
} | |
info(logString) | |
} |
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 readConfig(lines:List[String]):mutable.Map[String,Map[String,String]] = { | |
// assuming that *all* properties have their sections | |
if (lines.isEmpty) Map() | |
else { | |
val sectionRgx = """\s*\[(.*)\]\s*""".r | |
val sectionRgx(sectName) = lines.head | |
val pairs = lines.tail.takeWhile(!_.startsWith("[")).map(_.split("=")).map(a => (a(0),a(1))).toMap | |
Map(sectName -> pairs) ++ readConfig(lines.tail.dropWhile(!_.startsWith("[")) | |
} | |
} |
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 javax.xml.parsers.SAXParser; | |
import javax.xml.parsers.SAXParserFactory; | |
import org.xml.sax.Attributes; | |
import org.xml.sax.SAXException; | |
import org.xml.sax.helpers.DefaultHandler; | |
object ReadXMLFile { | |
def main(argv: Array[String]) { | |
try { | |
val factory = SAXParserFactory.newInstance |
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 AfterInit extends DelayedInit { | |
def afterInit | |
def afterInitLevel = 1 | |
private var initCount = 0 | |
private def getInitNumber(clazz: Class[_]):Int = | |
if (clazz.getSuperclass == classOf[java.lang.Object]) 0 else getInitNumber(clazz.getSuperclass) + 1 | |
final def delayedInit(x: => Unit) { | |
x | |
initCount += 1 | |
if (getInitNumber(this.getClass) + afterInitLevel == initCount) afterInit |
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
#!/usr/bin/scala | |
!# | |
val activities = Seq( | |
("blogging", "chrome", "^Blogger".r), | |
("games", "chrome", "Game".r), | |
("guake", "python", "^Guake!$".r) | |
) | |
io.Source.fromFile(args(0)).getLines.toList // read the file |
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
assoc .svg=SvgGraphicsFile | |
ftype SvgGraphicsFile=C:\Program Files\Internet Explorer\iexplore.exe "www.someplace.ru/index.html?file=" "%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
class SlidingWindowMap(keys: Set[String], maxCount: Int, periodMs: Int) { | |
val times = collection.mutable.Map(keys.map(k => (k, Vector[Long]())).toList:_*) | |
def nextKey: Option[String] = { | |
val now = System.currentTimeMillis | |
this.synchronized { | |
val key = times.find(_._2.dropWhile(_ < now - periodMs).size < maxCount).map(_._1) | |
key.foreach { k => times(k) = times(k).dropWhile(_ < now - periodMs) :+ now } | |
key | |
} | |
} |
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 simple | |
package even.simpler | |
import scala.collection._ | |
import scala.util.{Random => Rnd} | |
import scala.collection.mutable.Map | |
object Simple { | |
type TP = Seq[String] |
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
git clone git://github.com/scala/scala.git scala-tuplicity | |
cd scala-tuplicity | |
git checkout v2.9.2 | |
export ANT_OPTS="-Xmx8192m -Xss25M -Xms4096M -XX:MaxPermSize=512M" | |
VERS="-Dbuild.release=true -Dversion.number=2.9.2-tuplicity -Dmaven.version.number=2.9.2-tuplicity" | |
ant build | |
sed -i 's/\(val MaxTupleArity, .*\) 22/\1 222/' src/compiler/scala/tools/nsc/symtab/Definitions.scala | |
ant build | |
ant replacelocker | |
sed -i 's/\(MAX_ARITY .*\) 22/\1 222/' src/build/genprod.scala |