Skip to content

Instantly share code, notes, and snippets.

@cjwebb
cjwebb / country-codes.txt
Created August 18, 2014 09:47
Valid ISO 316601 2 Letter Country Codes
AC
AD
AE
AF
AG
AI
AL
AM
AN
AO
@cjwebb
cjwebb / product-s3.json
Created June 8, 2014 09:52
GET /product/s3
{
"id": "s3",
"name": "BLT",
"image": "img/sandwich/s3.jpg"
}
@cjwebb
cjwebb / product-s2.json
Created June 8, 2014 09:52
GET /product/s2
{
"id": "s2",
"name": "Chicken & Bacon",
"image": "img/sandwich/s2.jpg"
}
@cjwebb
cjwebb / product-s1.json
Created June 8, 2014 09:51
GET /product/s1
{
"id": "s1",
"name": "Club Sandwich",
"image": "img/sandwich/s1.jpg"
}
@cjwebb
cjwebb / article-a1.json
Created June 8, 2014 09:49
GET /article/a1
{
"id": "a1",
"title": "Top 3 Sandwiches",
"content": "They all contain bacon.",
"product_list": [
"s1", "s2", "s3"
]
}
@cjwebb
cjwebb / EPL-2013-2014.clj
Last active August 29, 2015 13:59
English Premier League results for the 2013-2014 season
({:date Monday 31 March 2014, :location Stadium of Light, :away-team West Ham, :score 1 - 2, :home-team Sunderland, :time 20:00}
{:date Sunday 30 March 2014, :location Anfield, :away-team Spurs, :score 4 - 0, :home-team Liverpool, :time 16:00}
{:date Sunday 30 March 2014, :location Craven Cottage, :away-team Everton, :score 1 - 3, :home-team Fulham, :time 13:30}
{:date Saturday 29 March 2014, :location Emirates Stadium, :away-team Man City, :score 1 - 1, :home-team Arsenal, :time 17:30}
{:date Saturday 29 March 2014, :location Selhurst Park, :away-team Chelsea, :score 1 - 0, :home-team Crystal Palace, :time 15:00}
{:date Saturday 29 March 2014, :location St. Mary's Stadium, :away-team Newcastle, :score 4 - 0, :home-team Southampton, :time 15:00}
{:date Saturday 29 March 2014, :location Britannia Stadium, :away-team Hull, :score 1 - 0, :home-team Stoke, :time 15:00}
{:date Saturday 29 March 2014, :location Liberty Stadium, :away-team Norwich, :score 3 - 0, :home-team Swansea, :time 15:00}
{:date Saturday 29 Ma
@cjwebb
cjwebb / RomanNumerals.scala
Last active December 29, 2015 15:39
Solutions to the classic roman numerals problem
class RomanNumerals {
def toInt(romanNumerals: String): Int = {
@annotation.tailrec
def recur(l: List[Int], total: Int): Int = {
l match {
case h :: Nil => total + h
case h :: tail if h < tail.head => recur(tail, total - h)
case h :: tail => recur(tail, total + h)
case Nil => total // romans didn't have zero though
}
/**
* Problems from
* http://aperiodic.net/phil/scala/s-99/
*/
object NinetyNine extends App {
// P02
def penultimate[A](l: List[A]): A = l match {
case h :: _ :: Nil => h
case h :: tail => penultimate(tail)
package io.github.cjwebb
import scala.annotation.tailrec
object Fibonacci extends App {
/** Get the nth fibonacci number */
def fib_iter(n: Int) = {
if (n < 2) n
else {
import akka.actor._
import akka.camel.{CamelExtension, CamelMessage, Consumer, Producer, Oneway}
import org.apache.activemq.camel.component.ActiveMQComponent
import org.apache.activemq.ScheduledMessage
case class Message(body: String)
class SimpleConsumer() extends Actor with Consumer {
def endpointUri: String = "activemq:foo.bar"