Skip to content

Instantly share code, notes, and snippets.

@nuttycom
nuttycom / gist:4507997
Created January 11, 2013 04:41
This is a bit of a curiosity exploring the space of the expression problem by using a fold to define an algebra over multiple subtrees (and multiple levels) of an inheritance hierarchy. I'm not sure if it's good for anything yet, but it does allow for some interesting patterns using the combination of polymorphic dispatch and a fold.
trait A {
// define an algebra over the known space of subtypes
def fold[X](af: A => X, bf: B => X, cf: C => X): X
}
trait B extends A {
def fold[X](af: A => X, bf: B => X, cf: C => X): X = bf(this)
}
@arvearve
arvearve / gist:4158578
Created November 28, 2012 02:01
Mathematics: What do grad students in math do all day?

Mathematics: What do grad students in math do all day?

by Yasha Berchenko-Kogan

A lot of math grad school is reading books and papers and trying to understand what's going on. The difficulty is that reading math is not like reading a mystery thriller, and it's not even like reading a history book or a New York Times article.

The main issue is that, by the time you get to the frontiers of math, the words to describe the concepts don't really exist yet. Communicating these ideas is a bit like trying to explain a vacuum cleaner to someone who has never seen one, except you're only allowed to use words that are four letters long or shorter.

What can you say?

@robinp
robinp / StateTRunner.scala
Created September 8, 2012 12:38
Runs a StateT while some state condition is met
object stateTRunner {
def runWhileUsing[F[+_], S, A, B](st: StateT[F, S, A])(init: S, p: S => Boolean, f: (S, A) => B)(implicit F: Monad[F]): F[List[B]] = {
def runWhile0(st: StateT[F, S, A], init: S, accum: List[B]): F[List[B]] = {
if (!p(init)) F.point(accum.reverse)
else F.bind(st.run(init)) {
case (s, a) => runWhile0(st, s, f(s, a) :: accum)
}
}
runWhile0(st, init, Nil)
@jamie-allen
jamie-allen / IoManagerBootstrap.scala
Created August 10, 2012 20:37
Simple example of how to use Akka IOManager Iteratee and exporting work to another actor
import akka.actor._
import akka.pattern.ask
import akka.util._
import akka.util.duration._
import scala.util.control.Exception._
/**
* To test, execute this code and use this command in a shell: "telnet localhost 8080"
* At the prompt, type in numbers and press enter, and they will be accumulated, returning
* the total value each time.
@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" />