Skip to content

Instantly share code, notes, and snippets.

@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" />
@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.
@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)
@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?

@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)
}
@retronym
retronym / sbt-quickstart.txt
Created January 22, 2013 21:27
try a library with sbt-extras
~/code/scratch1 sbt -sbt-create -scala-version 2.10.0 'set libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.0-M7"' 'console'
Detected sbt version 0.12.2-RC2
Using /Users/jason/.sbt/0.12.2-RC2 as sbt dir, -sbt-dir to override.
[info] Set current project to default-821d14 (in build file:/Users/jason/code/scratch1/)
[info] Defining */*:log-level
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...
[info] Set current project to default-821d14 (in build file:/Users/jason/code/scratch1/)
[info] Defining {.}/*:scala-version
[info] The new value will be used by no settings or tasks.
@dscleaver
dscleaver / Fib.scala
Created February 27, 2013 14:45
Port of http://t.co/KvoY7PDGSg. Created in a Scala IDE worksheet.
import scalaz._
import Scalaz._
object monads {
def fix[A](f: (=> A) => A): A = f(fix(f)) //> fix: [A](f: => A => A)A
type Gen[A] = (=> A) => A
def gFib: Gen[Int => Int] = (self) => n =>
@travisbrown
travisbrown / noncompilation.scala
Last active January 13, 2016 18:00
Testing for compiler errors with untyped macros.
scala> import scala.language.experimental.macros
import scala.language.experimental.macros
scala> import scala.reflect.macros.{ Context, TypecheckException }
import scala.reflect.macros.{Context, TypecheckException}
scala> object NoncompilationTests {
| def compiles(code: _): Boolean = macro compiles_impl
| def compiles_impl(c: Context)(code: c.Tree) = c.literal(
| try {
@folone
folone / gist:6258410
Last active April 27, 2018 14:09
Ackermann function
def ackermann(m: Int, n: Int): Int = {
(m, n) match {
case (0, _) ⇒ n + 1
case (m, 0) if m > 0 ⇒ ackermann(m - 1, 1)
case (m, n) if m > 0 && n > 0 ⇒ ackermann(m - 1, ackermann(m, n - 1))
}
}
import scalaz._, Scalaz._, Free.{suspend ⇒ _, _}, Trampoline._
def ackermannTramp(m: Int, n: Int): Trampoline[Int] = {
@pchiusano
pchiusano / scodec-streaming.markdown
Last active December 30, 2015 12:19
Some early design notes on adding a streaming layer to scodec

Much of this is out of date, but leaving it here for posterity. See the scodec-stream and scodec-bits projects, where all the details got worked out.


Current signature of Codec in scodec is:

trait Codec[A] {
  /** Attempts to encode the specified value in to a bit vector. */
 def encode(a: A): String \/ BitVector