Skip to content

Instantly share code, notes, and snippets.

View jamesthompson's full-sized avatar

James Thompson jamesthompson

View GitHub Profile
let
region = "us-west-2";
accessKeyId = "CORRECTAWSKEY";
defaults =
{ config, pkgs, resources, ... }:
{ deployment.targetEnv = "ec2";
deployment.ec2.accessKeyId = accessKeyId;
deployment.ec2.region = region;
@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]
)
@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 / GetRedis.scala
Created March 18, 2014 16:17
Get all keys and values from Redis
using: "net.debasishg" %% "redisclient" % "2.11"
// GetRedis.apply will print out all the keys and values in a csv list
object GetRedis {
import com.redis.{RedisClient, RedisClientPool}
def apply = {
val rcp = new RedisClientPool(
sys.env.getOrElse("REDIS_HOST", "localhost"),
6379
)
@jamesthompson
jamesthompson / sbt.sublime-build
Last active January 3, 2016 05:08
sbt build file for sublime if sbt script is present in project path
{
"cmd": ["sbt"],
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"variants": [
{
"name": "sbt_compile",
"cmd": ["${project_path:${folder}}/sbt compile"],
@jamesthompson
jamesthompson / sublime prefs
Created November 7, 2013 20:49
My sublime prefs
{
"color_scheme": "Packages/Color Scheme - Default/Monokai Bright.tmTheme",
"dictionary": "Packages/Language - English/en_GB.dic",
"font_face": "Monaco",
"font_size": 10,
"ignored_packages":
[
"Vintage",
"Theme - Refined"
],
@jamesthompson
jamesthompson / sublimecheatsheet.md
Created November 4, 2013 18:22
Sublime Text 3 Command Sheet

Sublime Text 3 Cheat Sheet

Files and Tokens

  • Command palette ⌘⇧P
  • Search files ⌘P
  • Search file symbols ⌘R
  • Search project symbols ⌘⇧R
  • Goto definition ⌘⌥↓
scala> p
res6: spire.math.poly.MultivariatePolynomial[Double] = (2.0x + 5.0 + 3.0y)
scala> q
res7: spire.math.poly.MultivariatePolynomial[Double] = (xy + 2.0x + 1.0 + 5.0y)
scala> p * q
res8: spire.math.poly.MultivariatePolynomial[Double] = (2.0x^2y + 4.0x^2 + 3.0xy^2 + 21.0xy + 12.0x + 28.0y + 5.0 + 15.0y^2)
scala> p + q
@jamesthompson
jamesthompson / gist:6625529
Created September 19, 2013 15:52
Lines of code in Sublime Text 3
find regex: ^(.*)$
where: *.scala, *.java etc etc...
@jamesthompson
jamesthompson / LegSpire.scala
Created July 25, 2013 22:51
Bonnet's Recursion Formula using Spire for Polynomials... Legendre Polynomials
def legendres(i: Int) : List[Polynomial[Rational]] = {
val one = Polynomial(0 -> r"1/1")
val x = Polynomial(1 -> r"1/1")
lazy val leg : Stream[Polynomial[Rational]] = {
def loop(pnm1: Polynomial[Rational], pn: Polynomial[Rational], n: Int = 1) : Stream[Polynomial[Rational]] = {
pn #:: loop(pn, Polynomial(0 -> Numeric[Rational].fromInt(n + 1).reciprocal) * (
(Polynomial(1 -> Numeric[Rational].fromInt(2 * n + 1)) * pn) +
(Polynomial(0 -> Numeric[Rational].fromInt(n).unary_-) * pnm1)), n + 1)
}
one #:: loop(one, x)