View Barrier.scala
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
// take() blocks until next* offer() | |
// (similar but not the conventional meaning of barrier) | |
def barrier() = new Gate[Unit, Long] { | |
private val state = new Transactor(0l) | |
val take = | |
for { | |
v0 <- state.transact(v => Observed(succeed(v))) | |
v1 <- state.transact { v => | |
if(v > v0) Observed(succeed(v)) |
View implicex.scala
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.collection.mutable.ListBuffer | |
object implicex { | |
trait ImplicitFunction1[-A, +B] { | |
def apply()(implicit a: A): B | |
} | |
def fn[A, B](f: A => B): ImplicitFunction1[A, B] = new ImplicitFunction1[A, B] { | |
def apply()(implicit a: A): B = f(a) | |
} |
View KeyFunctionDemo.scala
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 test | |
import scala.scalajs.js | |
import org.singlespaced.d3js.d3 | |
import org.singlespaced.d3js.selection.Update | |
object KeyFunctionDemo extends js.JSApp { | |
def main() = { | |
for(i <- 1 to 3) { |
View DT.scala
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
// Example from Odersky et al http://infoscience.epfl.ch/record/215280/files/paper.pdf | |
object DT { | |
trait Key { type Value } | |
class Setting(val str: String) extends Key | |
val sort = new Setting("sort") { type Value = String } | |
val width = new Setting("width") { type Value = Int } | |
val params = HMap.empty.add(width)(120).add(sort)("time") |
View git-log-consolidate.sh
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
#! /bin/bash | |
# git-log-consolidate | |
set -e | |
SINCE="Aug 25" | |
UNTIL="Sep 19" | |
LOG=~/git-log-consolidated.log | |
TMP=$LOG.tmp |
View thing.scala
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 thing | |
import scala.language.higherKinds | |
trait Thing[+T, Context[_]] { parent => | |
def foldish[S](s0: S)(f: (S, T) => Context[S]): Context[S] | |
def map[U](g: T => U) = new Thing[U, Context] { | |
def foldish[S](s0: S)(f: (S, U) => Context[S]) = | |
parent.foldish(s0)((s, t) => f(s, g(t))) |
View bash
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
decorate() { | |
for f in "$@" | |
do | |
echo -n "[$f] " | |
done | |
echo | |
} |
View CharSeqView.scala
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 au.com.langdale | |
package util | |
class CharSeqView( base: CharSequence, offset: Int, val length: Int) extends CharSequence { | |
def this(base: CharSequence) = this(base, 0, base.length) | |
def charAt(index: Int): Char = { | |
if( 0 <= index && index < length) | |
base.charAt(index + offset) | |
else |
View examples.scala
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 Pattern._ | |
import Family._ | |
def pattern[B](pf: PartialFunction[Name,B]) = new Extractor(pf.lift) | |
val Parents = new Extractor(parents.get) | |
val Children = new Extractor(children.get) | |
"Julie" match { | |
case Parents(p) => "Julies parents are: " + p |
View gist:574873
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.util.continuations._ | |
class Generator[A] extends Iterator[A] with (A => Unit @ suspendable) { | |
private var a: Option[A] = None | |
private var k: Option[Unit => Unit] = None | |
def next = { | |
val a0 = a.get | |
val k0 = k.get | |
a = None |
NewerOlder