Skip to content

Instantly share code, notes, and snippets.

@jsuereth
jsuereth / scalaz-nio.scala
Created April 22, 2011 05:03
Scalaz Iteratee NIO
Welcome to Scala version 2.8.1.final (OpenJDK 64-Bit Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz.io.ByteBuffers._
import scalaz.io.ByteBuffers._
scala> import scalaz.Scalaz._
import scalaz.Scalaz._
@jsuereth
jsuereth / ExampleSocketServer.scala
Created May 14, 2011 02:14
IterateeNonBlockingEchoServer
package scalaz.example.nio
import scalaz._
import concurrent.Promise
import effects.IO
import nio.sockets._
import nio.Channels._
import Scalaz._
import iteratees._
import java.nio.channels.SocketChannel
@jsuereth
jsuereth / ApplicativeMagic.scala
Created August 4, 2011 17:33
reason #37 Why macros against Function1->22 would be useful..
trait ApplicativeMagic[F[_]] {
def apply[C](f: ApplicativeMagicFunctionHolder[FunctionArg => C]): F[C]
type FunctionArg
}
class ApplicativeMagicFunctionHolder[F](val f: F)
object ApplicativeMagicFunctionHolder {
implicit def fix2[A,B,C](f: (A,B) => C): ApplicativeMagicFunctionHolder[Tuple2[A,B] => C] =
new ApplicativeMagicFunctionHolder({ case (a,b) => f(a,b) })
implicit def fix3[A,B,C,D](f: (A,B,C) => D): ApplicativeMagicFunctionHolder[Tuple2[Tuple2[A,B],C] => D] =
new ApplicativeMagicFunctionHolder({ case ((a,b),c) => f(a,b,c) })
@jsuereth
jsuereth / varargs.scala
Created August 13, 2011 02:23
Demystifying varags... hopefully..
scala> def foo[A](x: A*): Seq[A] = x
foo: [A](x: A*)Seq[A]
scala> foo(1,2,3,4,5,6)
res0: Seq[Int] = WrappedArray(1, 2, 3, 4, 5, 6)
scala> def foo[A](x: A*) = x
foo: [A](x: A*)A*
scala> foo(1,2,3,4,5)
@jsuereth
jsuereth / generic-iteratees.scala
Created September 13, 2011 18:57
A prototype iteratee library that uses Scala traits as an abstract module system
package scalax.io
/**
* A generic set of iteratees for general purpose usage. These iteratees
* make no assumption on error types and do not do any specialized communication
* between producers and consumers.
*/
trait GenericIteratees extends Iteratees {
/**
@jsuereth
jsuereth / ControlContext.scala
Created September 17, 2011 19:27
Docspree comments for ControlContext
// $Id$
package scala.util.continuations
import annotation.{ Annotation, StaticAnnotation, TypeConstraint }
/** This annotation is used to mark a parameter as part of a continuation context.
*
* The type `A @cps[B,C]` is desugared to `ControlContext[A,B,C]` at compile time.
*
* @tparam B The type of computation state after computation has executed, and before control is returned to the shift.
@jsuereth
jsuereth / record-all.sh
Created November 29, 2011 23:46
Testing out pulse audio automated record *everything* script
#!/bin/bash
MONITORS=$(pactl list | egrep -A2 '^(\*\*\* )?Source #' | grep 'Name: .*$' | awk '{print $NF}')
if [[ "$1" == "" ]]; then
echo "Must specify a recording directory!"
echo ""
echo "Usage: ./record-all.sh <directory>"
exit 1
@jsuereth
jsuereth / scala-merge-integration.sh
Created December 6, 2011 19:24
Merge script to make sure develop commits actually build before pushing to master.
#!/bin/bash
# TODO - Create a branch by build number?
declare -r integration_branch="integration"
declare -r remote_devel_branch="develop"
declare -r remote_master_branch="master"
declare -r origin_url="git@github.com:scala/scala.git"
declare -r build_opts="all.clean test"
declare -r logfile="$(pwd)/integration.log"
@jsuereth
jsuereth / trust.sbt
Created January 23, 2012 15:09
xsbt-gpg-plugin's new "check-pgp-signatures" command
[info] ----- PGP Signature Results -----
[info] com.jsuereth : scala-arm_2.9.1 : 1.2 : jar [OK]
[info] com.novocode : junit-interface : 0.7 : jar [MISSING]
[info] javax.transaction : jta : 1.0.1B : jar [MISSING]
[info] org.scala-lang.plugins : continuations : 2.9.1 : jar [MISSING]
[info] org.apache.derby : derby : 10.5.3.0_1 : jar [UNTRUSTED(0x98e21827)]
[error] {file:/home/josh/projects/typesafe/test-signing/}test-gpg/*:check-pgp-signatures: Some artifacts have bad signatures or are signed by untrusted sources!
[error] Total time: 1 s, completed Jan 23, 2012 10:05:52 AM
@jsuereth
jsuereth / iteratees.scala
Created February 13, 2012 16:50
Simplified Iteratees using trait modules
// Note: "Context" is the Monad through which these classes are threaded. There also exists a type alias for the error channel between
// consumers and producers so that Consumers can be random-access. That code lives in the "randomaccess" universe for Iteratees, which is
// an extension of the sequential "nio" universe.
// Note: I don't have a ConsumerT, ProducerT, or StreamConverterT yet.
trait Consumer[I,O] {
/** Fold takes a function that matches the current state of this Consumer and produces a result. */
def fold[R](f: ConsumerState[I,O] => Context[R]): Context[R]
}