Skip to content

Instantly share code, notes, and snippets.

trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
/*
The Oracle Java enum Planets example using the Klang DIY Enum, modified to include ordering.
*/
object KlangEnumPlanets extends App {
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
@petekneller
petekneller / Props.scala
Created February 23, 2015 15:56
Dumping system props (drop this in a dir and do "sbt run")
package props
object Main extends App {
import System._
import scala.collection.JavaConversions._
getProperties.stringPropertyNames().foreach{ pn => println(s"$pn -> ${getProperty(pn)}") }
}
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
@petekneller
petekneller / file1.scala
Created September 14, 2015 10:13
SBT BuildInfo example 2 - output in /src
object BuildInfo {
private def outputDir(baseDir: File): File = baseDir / "src_mananaged"
lazy val settings: Seq[Setting[_]] = Seq(
managedSourceDirectories in Compile <+= baseDirectory apply {baseDir => outputDir(baseDir)},
sourceGenerators in Compile <+= (streams, baseDirectory, version) map emitBuildInfo
)
def emitBuildInfo(logger: TaskStreams, baseDir: File, buildVersion: String): Seq[File] = {
@petekneller
petekneller / Nullable.scala
Created January 4, 2016 13:09 — forked from noelwelsh/Nullable.scala
Nullable types in Scala
object Nullable {
sealed trait NullableTag
type Nullable[A] = A with NullableTag
def nullAs[B]: Nullable[B] =
null.asInstanceOf[Nullable[B]]
implicit class ToNullable[A](val a: A) extends AnyVal {
def `?`: Nullable[A] = a.asInstanceOf[Nullable[A]]
}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Prelude hiding (log)
--------------------------------------------------------------------------------
-- The API for cloud files.
class Monad m => MonadCloud m where
saveFile :: Path -> Bytes -> m ()
@petekneller
petekneller / install-haskell-stack-arm.sh
Created January 2, 2017 20:30 — forked from tmspzz/install-haskell-stack-arm.sh
A scrip to install Haskell Stack and set up things properly on Raspbian
#!/bin/sh
# Install stack
curl -sSL https://get.haskellstack.org/ | sh
# Install LLVM
sudo apt-get install llvm-3.7
# Add symbolic links to opt and llc
ln -s /usr/bin/opt-3.7 /usr/bin/opt
@petekneller
petekneller / gist:1a6ecd2500d5c7cbd32cbc4866559a58
Created January 4, 2017 14:31 — forked from milessabin/gist:cadd73b7756fe4097ca0
A new approach to encoding dependently-typed chained implicits, using singleton types ...
object Demo {
// A couple of type classes with type members ...
trait Foo[T] {
type A
}
object Foo {
implicit val fooIS = new Foo[Int] { type A = String }
}
@petekneller
petekneller / svg-schematics.html
Last active April 17, 2018 21:58
SVG schematics
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Some experiments in how I might do multipart diagrams/schematics with SVG</title>
</head>
<body>
<h1>The problem</h1>
<p>I have a need/want to knock up schematic-like diagrams on the web with which I can: display either the whole or only parts of the diagram; zoom/scale or transform the part(s) being displayed. SVG seems to make sense a basis for this, so the question becomes one of: how do I do this with SVG?</p>