Skip to content

Instantly share code, notes, and snippets.

View markhibberd's full-sized avatar

markhibberd markhibberd

View GitHub Profile
@markhibberd
markhibberd / console
Created March 15, 2013 03:38
Minimal import for validation.
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz.std.string._
import scalaz.std.string._
scala> import scalaz.syntax.validation._
import scalaz.syntax.validation._
@markhibberd
markhibberd / Phantom.scala
Created March 18, 2013 10:32
Attempt at something to constrain setting of var. Still requires a significant amount of discipline to ensure var does not escape, but at least you can make sure (potentially large) parts of your system can not set the var. Not quite, set once, but if you have a specific flow it can sometimes help. Can be extended to ensure var is only read when…
object IsEmpty
class Holder[A, B](private var value: A) {
def set(a: A)(implicit ev: B =:= IsEmpty.type) {
value = a
}
}
object Holder {
def empty[A]: Holder[A, IsEmpty.type] =
@markhibberd
markhibberd / gist:5243403
Created March 26, 2013 05:43
silly implicits.
scala> implicit def x: String = "asgasgf"
x: String
scala> def foo(a: Int)(implicit x: Int, y: String = implicitly[String]): String = "a"
foo: (a: Int)(implicit x: Int, implicit y: String)String
scala> foo(1)(2)
res2: String = a
case class Utf8String(value: String)
object Utf8String {
implicit val ArbitraryUtf8String: Arbitrary[Utf8String] =
Arbitrary(arbitrary[String] map (k =>
Utf8String(k filter (c => c < '\ud800' || c > '\udfff'))))
}

Installation

FreeBSD

portmaster irc/irssi
portmaster irc/irssi-xmpp

OS X

brew install irssi

@markhibberd
markhibberd / learning-scala-project.md
Last active December 15, 2015 22:08
Learning Scala

A course aimed at learning Scala. Rather than a traditional set of canned exercises, we will spend approx 12 weeks (more or less as required) building a complete system, and a system that may even be useful. The exercise is still contrived, in that we will attempt to implement far more of the code by hand than would normally occur, but we will build a series of components that are likely to be similar to code produced in a production setting.

The proposed exercise is to build a source code search engine on top of the venerable Ctags index format. This will involve

@markhibberd
markhibberd / Blat.scala
Created April 10, 2013 03:56
Tail recursive loop example.
case class Blat[A](v: String \/ A) {
def isValue =
value.isDefined
def isMessage =
message.isDefined
def value: Option[A] =
v.toOption

Chef Cheat sheet

Configuring Chef

To install stuff needed to run chef in a solo mode (Small one or two server configuration):

gem install knife-solo

To setup chef after it has been installed:

@markhibberd
markhibberd / characters.md
Last active January 14, 2021 18:32
Haskell Character Data

Overview

There are lots of representations for strings. In most languages they pick one set of tradeoffs and run with it. In haskell the "default" implementation (at least the one in the prelude) is a pretty bad choice, but unlike most other languages (really) good implementations exist for pretty much every way you can twist these things. This can be a good thing, but it also leads to confusion, and frustration to find the right types and how to convert them.

Types

@markhibberd
markhibberd / vex.pub
Created May 4, 2013 04:58
public key for vex
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAKiDGY1h3sMbExSG8NM4LgMPzqj+AJJo8IfgTFZQ8I0p1XOQDoZc2UpxyOgBdTLCPdMUVn9mbZlibVfZNdKmB1axnff2+N6VGuaXe3q33mRK/acuOFMq/Z8jJzqliIv1jR6siOkag6Hvg+ZVB/dr/zSUbRSQCJQLOBFDephxfRA7kompB19ecIxL5EO9JGslFWEF9ttvhMF97j0Z7/YT7c27wVir1ETh4e68bCEBWfmbK+pNATNjaQAnatd5tGHxXGEN4kLJvoLKtyNKbZvRmxbl97o9VuFzLKwJArToMzM8esumn/xN82oqpfETGQfuH7RF9OjL+x3SrCKTkzctT mth@vex