Skip to content

Instantly share code, notes, and snippets.

View jamesthompson's full-sized avatar

James Thompson jamesthompson

View GitHub Profile
@jamesthompson
jamesthompson / RedisFreeAlgebra
Created January 19, 2015 22:00
An example toy algebra for Redis actions
// This should work with Scala 2.10.4 & scalaz 7.1, core, effect and concurrent packages
import scalaz.{ concurrent, Free, Functor, Monad, syntax }
import concurrent.Task
import Free.{freeMonad => _, _}
import syntax.monad._
// Describe the set of actions - which are functors
sealed trait RedisF[+A] {
def map[B](fn: A => B): RedisF[B]
@jamesthompson
jamesthompson / EncodingCheck.scala
Created March 24, 2015 16:56
Testing JSON encoding using Lenses and Arbitrary Generators
import argonaut._, Argonaut._
import org.scalacheck._, Prop._
import scalaz._, Scalaz._
object EncodingTestExample extends Properties("Encoding Json Test Example") {
case class Vehicle(
wheelsCount: Option[Int],
engineParts: List[String]
)
let
region = "us-west-2";
accessKeyId = "CORRECTAWSKEY";
defaults =
{ config, pkgs, resources, ... }:
{ deployment.targetEnv = "ec2";
deployment.ec2.accessKeyId = accessKeyId;
deployment.ec2.region = region;
@jamesthompson
jamesthompson / machines.nix
Created May 1, 2015 19:06
machine network def
{ numZookeeperNodes ? 1 }:
with import <nixpkgs/lib>;
let
makeMachine = n: nameValuePair "zk-${toString n}"
({ config, pkgs, nodes, ... }:
{
defaults =
{ config, pkgs, ... }:
{ deployment.targetEnv = "virtualbox";
deployment.virtualbox.memorySize = 2048; # Mb
deployment.virtualbox.headless = true;
};
}
@jamesthompson
jamesthompson / TrentTree.hs
Created September 6, 2015 16:19
Dir Tree Prog
module TrentTree where
import Control.Monad.Trans.Class -- from the `transformers` package
import Control.Monad.Trans.Except -- from the `errors` package
import Data.Monoid ((<>))
import Data.Tree
import System.Directory (doesDirectoryExist,
getDirectoryContents)
import System.FilePath (combine, takeFileName)
@jamesthompson
jamesthompson / Leg.scala
Created June 10, 2012 19:00
Legendre Polynomials
def leg(mode:Int, angle:Double) : IndexedSeq[Double] = {
val cosAngle = math.cos(angle)
lazy val stream: Stream[Double] = {
def loop(last:Double, curr:Double, k:Double = 0.0) : Stream[Double] = curr #:: loop(curr, ((2 * k + 1) * cosAngle * curr - k * last) / (k + 1), k + 1)
loop(0.0, 1.0)
}
stream.take(mode + 1).toIndexedSeq
}
@jamesthompson
jamesthompson / Track.scala
Created July 18, 2012 22:20
Tracking class
package Spots
import collection.mutable.ArrayBuffer
/**
* Track class
* Author: James R. Thompson, D.Phil
* Date: 7/16/12
* Time: 9:31 AM
* USC Mork Family Dept. of Chem. Eng. & Mat. Sci.
@jamesthompson
jamesthompson / FFT.scala
Created August 20, 2012 18:48
Cooley-Tukey FFT - Scala
import scala.math._
case class Complex(re: Double, im: Double = 0.0) {
def +(x: Complex): Complex = Complex((this.re+x.re), (this.im+x.im))
def -(x: Complex): Complex = Complex((this.re-x.re), (this.im-x.im))
def *(x: Complex): Complex = Complex(this.re*x.re-this.im*x.im, this.re*x.im+this.im*x.re)
}
def transformReal(input:IndexedSeq[Double]) = {
val data = padder(input.map(i => Complex(i)).toList)
@jamesthompson
jamesthompson / JFXImageUtil.scala
Created September 5, 2012 15:53
JavaFX images from byte array data in Scala
import javafx.scene.image.Image
import javax.imageio.ImageIO
import java.awt.image._
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, IOException}
import java.util.logging.{Level, Logger}
object JFXImageUtil {
def getJavaFXImage(rawPixels:Array[Byte], width:Int, height:Int) = {
val out = new ByteArrayOutputStream