Skip to content

Instantly share code, notes, and snippets.

@etorreborre
etorreborre / PragmaticIoSpec.scala
Created December 5, 2011 23:22
Scalaz different behaviors when traversing a Stream/Seq with Option/IO and folding left or right.
"traverse left with Stream and IO" >> {
implicit def traverseImplicit = StreamLeftTraverse
var result: Seq[Int] = Seq()
val f = (i: Int) => (result = result :+ i).pure[IO]
(1 to 3).toStream.map(f).sequence.unsafePerformIO
result must_== Seq(3, 2, 1)
}
"traverse right with Stream and IO" >> {
@casualjim
casualjim / actor_specification.scala
Created November 30, 2011 13:42
Specs2 with Akka and jodatime support
trait ActorSpecification extends BaseSpecification
with ArgumentsArgs
with ArgumentsShortcuts
with MustThrownMatchers
with ShouldThrownMatchers
with FormattingFragments
with StandardResults
with StandardMatchResults
with PendingUntilFixed
with TimeHelpers
@softprops
softprops / build.sbt
Created November 27, 2011 05:35
unfiltered embedded jetty
libraryDependencies += Seq(
"net.databinder" %% "unfiltered-filter" % "0.5.1",
"net.databinder" %% "unfiltered-jetty" % "0.5.1",
)
@retronym
retronym / config.scala
Last active May 9, 2018 05:47
Styles of config propagation: Manual, Implicits, DynamicVariable, Reader
package scalaz.example
object Reader extends App {
/**
* Manual propagation of the environment (in the example, `contextRoot`.)
*/
object Config0 {
def fragment1(contextRoot: String) = <a href={contextRoot + "/foo"}>foo</a>
@gclaramunt
gclaramunt / Circularbuffer.scala
Created November 23, 2011 17:33
circular buffer
package my.collections
class CirculrBufferIterator[T](buffer:Array[T], start:Int) extends Iterator[T]{
var idx=0
override def hasNext = idx<buffer.size
override def next()={
val i=idx
idx=idx+1
buffer(i)
}
@retronym
retronym / log.txt
Created October 20, 2011 22:03
sbt-classifiers
>show update
[info] commons-io:commons-io:1.2:
[info] (Artifact(commons-io,jar,jar,None,ArraySeq(),None,Map()),project/.ivy/cache/commons-io/commons-io/jars/commons-io-1.2.jar)
[info] (Artifact(commons-io,src,jar,Some(sources),ArraySeq(),None,Map()),project/.ivy/cache/commons-io/commons-io/srcs/commons-io-1.2-sources.jar)
[info] (Artifact(commons-io,doc,jar,Some(javadoc),ArraySeq(),None,Map()),project/.ivy/cache/commons-io/commons-io/docs/commons-io-1.2-javadoc.jar)
> show update-sbt-classifiers
...
[info] commons-collections:commons-collections:3.2.1:
[info] (Artifact(commons-collections,src,jar,Some(sources),ArraySeq(),None,Map()),project/.ivy/cache/commons-collections/commons-collections/srcs/commons-collections-3.2.1-sources.jar)
@dholbrook
dholbrook / SleepingBarber.scala
Created October 12, 2011 03:03
Sleeping Barber Problem, Akka actor implementation
import java.lang.Thread
import scala.collection.mutable.Queue
import akka.actor.Uuid
import akka.actor.scala2ActorRef
import akka.actor.Actor
import akka.event.EventHandler
/*
* Sleeping Barber Code Club Problem
* See (http://en.wikipedia.org/wiki/Sleeping_barber_problem)
@jskorpan
jskorpan / StringTokenizer.java
Created June 30, 2011 11:37 — forked from cgbystrom/StringTokenizer.java
Ultra fast Java string tokenizer
public class StringTokenizer {
private static ThreadLocal<String[]> tempArray = new ThreadLocal<String[]>();
public static String[] tokenize(String string, char delimiter)
{
String[] temp = tempArray.get();
int tempLength = (string.length() / 2) + 2;
if (temp == null || temp.length < tempLength)
{
@oxbowlakes
oxbowlakes / ScalaSolarizedDark.xml
Created June 20, 2011 13:13
ScalaSolarizedDark.xml
<?xml version="1.0" encoding="UTF-8"?>
<scheme name="OxbowSolarizedDark" version="1" parent_scheme="Default">
<option name="LINE_SPACING" value="1.2" />
<option name="EDITOR_FONT_SIZE" value="13" />
<option name="EDITOR_FONT_NAME" value="Consolas" />
<colors>
<option name="ADDED_LINES_COLOR" value="" />
<option name="ANNOTATIONS_COLOR" value="2b36" />
<option name="ANNOTATIONS_MERGED_COLOR" value="" />
<option name="CARET_COLOR" value="dc322f" />
@akihiro4chawon
akihiro4chawon / parasort.scala
Created May 19, 2011 16:09
practical implementation of parallel sorting algorithm in Scala
import java.util.Arrays
abstract class Sorter {
def sorted(a: Array[Int]): Array[Int]
}
object SimpleSorter extends Sorter {
def sorted(a: Array[Int]) = {
Arrays.sort(a)
a