Skip to content

Instantly share code, notes, and snippets.

Avatar

James Thompson jamesthompson

View GitHub Profile
View ec2.nix
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 Mar 24, 2015
Testing JSON encoding using Lenses and Arbitrary Generators
View EncodingCheck.scala
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 Jan 19, 2015
An example toy algebra for Redis actions
View RedisFreeAlgebra
// 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 Mar 18, 2014
Get all keys and values from Redis
View GetRedis.scala
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 Jan 3, 2016
sbt build file for sublime if sbt script is present in project path
View sbt.sublime-build
{
"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"],
View 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 Nov 4, 2013
Sublime Text 3 Command Sheet
View sublimecheatsheet.md

Sublime Text 3 Cheat Sheet

Files and Tokens

  • Command palette ⌘⇧P
  • Search files ⌘P
  • Search file symbols ⌘R
  • Search project symbols ⌘⇧R
  • Goto definition ⌘⌥↓
View repl.scala
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 Sep 19, 2013
Lines of code in Sublime Text 3
View gist:6625529
find regex: ^(.*)$
where: *.scala, *.java etc etc...
@jamesthompson
jamesthompson / LegSpire.scala
Created Jul 25, 2013
Bonnet's Recursion Formula using Spire for Polynomials... Legendre Polynomials
View LegSpire.scala
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)