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 scalaz._ | |
import Scalaz._ | |
import java.io._ | |
// http://groups.google.com/group/scalaz/msg/cb7a190b60b2518c?dmode=source | |
val reader = new BufferedReader(new FileReader("S.scala")) | |
val s: Stream[String] = Stream.continually(reader.readLine()).takeWhile(_ != null) | |
type X[x] = State[(Int, StringBuilder), x] |
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 Batcher[T](iter: Iterator[T]) { | |
def batch[U](size: Int, doWithBatch: IndexedSeq[T] => Seq[U]): Iterator[U] = | |
iter.grouped(size).map(g => doWithBatch(g.toIndexedSeq).toIterator).flatten | |
} | |
implicit def toBatcher[T](iter:Iterator[T]) = new Batcher(iter) | |
val iter = Iterator.from(1).take(20) | |
def step1(i: Int) = (i, "v" + i) |
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
#include <conio.h> | |
#include <ctype.h> | |
#include <stdio.h> | |
int main( void ) | |
{ | |
int ch; | |
_cputs( "Type 'Y' when finished typing keys: " ); | |
do |
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 Pi extends App { | |
println((0 to args(0).toInt).par.map(i => 4. * math.pow(-1, i) / (2. * i + 1.)).sum) | |
} | |
object Pi1 extends App { | |
println((0 to args(0).toInt).par.view.map(i => 4. * math.pow(-1, i) / (2. * i + 1.)).sum) | |
} | |
object Pi2 extends App { | |
println((0 to args(0).toInt).map(i => 4. * math.pow(-1, i) / (2. * i + 1.)).sum) |
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 HeapDumper { | |
import javax.management.MBeanServer | |
import java.lang.management.ManagementFactory | |
import com.sun.management.HotSpotDiagnosticMXBean | |
private val HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic"; | |
// field to store the hotspot diagnostic MBean |
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
// win 7 trunk | |
import collection.JavaConverters._ | |
val props = System.getProperties.asScala | |
props.filter(_._1.contains("path")) |
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
// http://stackoverflow.com/questions/5846208/mapvalues-on-innermost-map-of-nested-maps | |
case class SalesRow(val month:Int, val country:String, | |
val person:String, val amount:Float) | |
object Test { | |
def main(args:Array[String] = null) { | |
val list = new collection.mutable.ListBuffer[SalesRow]() | |
for (m <- 1 to 12; p <- List("Joe", "Bill")) { | |
val i = 2 * (if (p == "Joe") 7 else 13) |
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
// http://stackoverflow.com/questions/5715453/scala-xml-pull-parser-and-location | |
// Originally from Scala API copyrighted by LAMP/EPFL | |
// See http://www.scala-lang.org/node/146 for License | |
// Modified to get Source position | |
import scala.xml.pull._ | |
import scala.xml._ | |
import scala.io.{Position, Source} | |
import scala.xml.parsing.{ ExternalSources, MarkupHandler, MarkupParser } |
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
// scala -cp "jcl-core-2.2.2.jar;log4j-1.2.16.jar" | |
// http://sourceforge.net/projects/jcloader/files/jcl2/org/xeustechnologies/jcl/2.2.2/jcl-core-2.2.2.jar/download | |
// see http://jcloader.sourceforge.net/gettingstarted.html | |
import org.xeustechnologies.jcl._ | |
import java.lang.reflect.Method | |
// jline2 | |
//val t = new jline.WindowsTerminal | |
//t.getWidth |
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
// http://stackoverflow.com/questions/3956607/how-should-i-avoid-unintentionally-capturing-the-local-scope-in-function-literals | |
object Clos { | |
def method: Iterator[Int] = { | |
val huge = (1 to 2000000).toList | |
val n = huge.last | |
(1 to n).iterator map (_ + 1) | |
} | |
def gc() { println("GC!!"); Runtime.getRuntime.gc } |