Skip to content

Instantly share code, notes, and snippets.

Avatar

Colin Webb cjwebb

View GitHub Profile
View pymeals_user_invite.bson
{
"_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"
}
View pymeals_user.bson
{
"_id" : ObjectId("504ae6e2001b9c0548ab0b64"),
"password" : "$2a$12$vCew7zzXqtyRGKQV4xfSZ.KbmmCRMx.pVJD6DesTLrOvuUghB5Oeu",
"email" : "an_email@address.com",
"created_date" : ISODate(“2012-09-18T18:59:31.753Z")
}
@cjwebb
cjwebb / pymeals_ttl_index.json
Created Sep 19, 2012
Pymeals User Invite TTL Index
View pymeals_ttl_index.json
{
"v" : 1,
"key" : { "expiry_time" : 1 },
"ns" : "pymeals.user_invites",
"name" : "expiry_time_1",
"expireAfterSeconds" : 1
}
@cjwebb
cjwebb / pymeals_create_ttl_index.txt
Created Dec 17, 2012
MongoDb: Create TTL index on collection
View pymeals_create_ttl_index.txt
db.user_invites.ensureIndex( { "expiry_time": 1 }, { expireAfterSeconds: 1 } )
View Akka Camel and ActiveMQ
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"
View Fibonacci Functions
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 {
View NinetyNineProblems.scala
/**
* 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 Dec 29, 2015
Solutions to the classic roman numerals problem
View RomanNumerals.scala
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 Aug 29, 2015
English Premier League results for the 2013-2014 season
View EPL-2013-2014.clj
({: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
View article-a1.json
{
"id": "a1",
"title": "Top 3 Sandwiches",
"content": "They all contain bacon.",
"product_list": [
"s1", "s2", "s3"
]
}