Skip to content

Instantly share code, notes, and snippets.

View channingwalton's full-sized avatar
🏠
Working from home

Channing Walton channingwalton

🏠
Working from home
View GitHub Profile
21:15:22.745 ERROR akka://ENSIME/user/$b o.e.s.SocketHandler - Error in socket reader:
java.lang.NumberFormatException: For input string: "new Wo"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_31]
at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_31]
at java.lang.Integer.valueOf(Integer.java:740) ~[na:1.8.0_31]
at org.ensime.server.FramedStringProtocol$class.readString(FramedStringProtocol.scala:39) ~[server_2.11-0.9.10-SNAPSHOT.jar:0.9.10-SNAPSHOT]
at org.ensime.server.SwankProtocol.readString(SwankProtocol.scala:10) ~[server_2.11-0.9.10-SNAPSHOT.jar:0.9.10-SNAPSHOT]
at org.ensime.server.S≈wankProtocol.read(SwankProtocol.scala:15) ~[server_2.11-0.9.10-SNAPSHOT.jar:0.9.10-SNAPSHOT]
at org.ensime.server.SocketHandler$$anon$1.run(SocketHandler.scala:43) ~[server_2.11-0.9.10-SNAPSHOT.jar:0.9.10-SNAPSHOT]
@channingwalton
channingwalton / Reverse.idr
Created September 29, 2014 21:15
Reverse an Idris Vect
module Main
rev : Vect n a -> Vect n a
rev Nil = Nil
rev (x :: xs) = (rev xs) ++ (x :: Nil)
main : IO ()
main = putStrLn $ show $ rev [1,2,3]
fails to compile with
@channingwalton
channingwalton / Console.scala
Last active October 30, 2016 22:21
Alternatives to GADTs in Scala
// No case classes
object Consoles {
trait ConsoleAlg[F[_]] {
def readLine: F[Option[String]]
def printLine(line: String): F[Unit]
}
trait Console[+A] {
@channingwalton
channingwalton / LensFu.scala
Created May 19, 2014 09:48
Path-aware Lens
import scalaz._
object LensFu extends App {
case class FieldValue[T](name: String, v: T)
case class Field[T, F](name: String, lens: Lens[T, F]) {
def >=>[G](field: Field[F, G]): Field[T, G] = Field(name + "." + field.name, lens >=> field.lens)
def get(v: T): FieldValue[F] = FieldValue(name, lens.get(v))
def set(a: T, b: F): T = lens.set(a, b)
@channingwalton
channingwalton / shapelessy.scala
Last active August 29, 2015 14:00
Replacing boilerplate with shapeless
case class Foo[T](x: T) {
def map[B](f: T => B) = Foo(f(x))
}
object OldWay {
def combineLatest[T1, T2](e1: Foo[T1], e2: Foo[T2]): Foo[(T1, T2)] = Foo((e1.x, e2.x))
def combineLatest[T1, T2, T3](e1: Foo[T1], e2: Foo[T2], e3: Foo[T3]): Foo[(T1, T2, T3)] =
combineLatest(combineLatest(e1, e2), e3) map {
@channingwalton
channingwalton / MonoidHomomorphism.scala
Created March 7, 2014 17:52
Turning nulls into zeroes, zeroes into empties
object MonoidHomomorphism extends App {
import scalaz._
import Scalaz._
/**
* Turn any null into the Zero value for its type
*/
def nullAsZero[T: Monoid : Equal](a: T) = if (a == null) implicitly[Monoid[T]].zero else a
@channingwalton
channingwalton / AutomountMaverick.md
Last active September 20, 2017 22:11
Automounting in OSX Maverick

What Changed

I used to automount on OSX by sudo vifs and adding a line like vault.local:/backup /Volumes/backup url auto,url==afp://;AUTH=No%20User%20Authent@vault.local/backup 0 0. But that no longer works on Maverick because the system deletes everything in /Volumes on wake/restart/something-or-other.

We are going to create a mount at /mnt/Resources. We need to edit the auto_master to tell it where the automount config for /mnt/Resources lives:

sudo vi /etc/auto_master

Now add this line at the top

// ------------------------------------------------------
// Combined List/Option/Either
// ------------------------------------------------------
object MonadTransformers extends App {
import scalaz._, Scalaz._
import EitherT._
type OptionTList[α] = ({ type λ[α] = OptionT[List, α] })#λ[α]
val c1: EitherT[OptionTList, String, String] = eitherT[OptionTList, String, String](OptionT[List, \/[String, String]](List(some(\/-("c1a")), some(\/-("c1b")))))
@channingwalton
channingwalton / Trees.scala
Last active December 19, 2015 13:19
An implementation of creating a Christmas tree. The idea was to try to create a solution by composing reusable functions as an alternative to the example here http://sortega.github.io/programming/2013/07/06/functional-tree/
object Trees extends App {
def zero = '0'
def repeat(c: Char)(n: Int) = c.toString * n
def reflect(centre: Char)(s: String) = s.reverse + centre + s
def pad(w: Int, c: Char)(s: String) = s.padTo(w - 1, c)
@channingwalton
channingwalton / PartialLens.scala
Last active December 18, 2015 03:19
Partial Lens example
object PartialLensExample extends App {
import scalaz._
import Lens._
import PLens._
case class Bar(blub: Option[String])
case class Foo(bar: Option[Bar])