Skip to content

Instantly share code, notes, and snippets.

@cjwebb
cjwebb / pymeals_user_invite.bson
Created September 19, 2012 19:22
Pymeals User Invite
{
"_id" : ObjectId(“505a1614001b9c1a9cb10803"),
"password" : "$2a$12$vCew7zzXqtyRGKQV4xfSZ.KbmmCRMx.pVJD6DesTLrOvuUghB5Oeu",
"expiry_time" : ISODate(“2012-10-21T18:59:31.753Z"),
"invite_code" : "an-invite-code",
"activation_code" : "cbcff14"
}
@cjwebb
cjwebb / pymeals_user.bson
Created September 19, 2012 19:29
Pymeals User
{
"_id" : ObjectId("504ae6e2001b9c0548ab0b64"),
"password" : "$2a$12$vCew7zzXqtyRGKQV4xfSZ.KbmmCRMx.pVJD6DesTLrOvuUghB5Oeu",
"email" : "[email protected]",
"created_date" : ISODate(“2012-09-18T18:59:31.753Z")
}
@cjwebb
cjwebb / pymeals_ttl_index.json
Created September 19, 2012 19:35
Pymeals User Invite TTL Index
{
"v" : 1,
"key" : { "expiry_time" : 1 },
"ns" : "pymeals.user_invites",
"name" : "expiry_time_1",
"expireAfterSeconds" : 1
}
@cjwebb
cjwebb / pymeals_create_ttl_index.txt
Created December 17, 2012 21:34
MongoDb: Create TTL index on collection
db.user_invites.ensureIndex( { "expiry_time": 1 }, { expireAfterSeconds: 1 } )
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"
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 {
/**
* 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)
@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
}
@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 / 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"
]
}