Skip to content

Instantly share code, notes, and snippets.

Avatar

Colin Webb cjwebb

View GitHub Profile
View jsonschema.scala
import com.github.fge.jsonschema.core.report.ProcessingMessage
import scala.collection.JavaConversions._
import com.fasterxml.jackson.databind.JsonNode
import com.github.fge.jsonschema.main.JsonSchemaFactory
import org.json4s._
import org.json4s.jackson.JsonMethods._
@cjwebb
cjwebb / Scala.Dockerfile
Created Aug 25, 2018
Scala SBT dockerfile - runs SBT to build, and then copies on the jar to the alpine java image
View Scala.Dockerfile
# This uses the Docker builder pattern.
# The first container runs SBT to stage our application.
# todo - use a Docker image that has already downloaded SBT
FROM hseeberger/scala-sbt AS builder
WORKDIR /app
COPY src src
COPY project project
COPY build.sbt build.sbt
RUN sbt stage
View tail-kinesis.sh
if [ -z "$1" ]
then
echo "Usage: ./kinesis-messages.sh <stream-name>"
exit 1
fi
streamname=$1; aws kinesis describe-stream --stream-name $streamname --output text | grep SHARDS | awk '{print $2}' | while read shard; do aws kinesis get-shard-iterator --stream-name $streamname --shard-id $shard --shard-iterator-type LATEST --output text | while read iterator; do while output=`aws kinesis get-records --shard-iterator $iterator --output text`; do iterator=`echo "$output" | head -n1 | awk '{print $2}'`; echo "$output" | awk 'NR > 1' | grep RECORDS | while read record; do echo $record | awk '{print $3}' | base64 -D | jq .; done; done; done; done
@cjwebb
cjwebb / cilic_v_berankis.txt
Created Jan 6, 2016
tennis scores, point by point, of a match at wimbledon 2015
View cilic_v_berankis.txt
Berankis 15:0 15:15 15:30 15:40, BP 6-3 4-6 7-6 4-6 7-5
Cilic 0:15 15:15 15:30 15:40 30:40 40:40 A:40 6-3 4-6 7-6 4-6 6-5
Berankis 15:0 30:0 40:0 40:15 6-3 4-6 7-6 4-6 5-5
Cilic 15:0 30:0 40:0 6-3 4-6 7-6 4-6 5-4
Berankis 15:0 30:0 40:0 6-3 4-6 7-6 4-6 4-4
Cilic 15:0 15:15 30:15 40:15 40:30 6-3 4-6 7-6 4-6 4-3
Berankis 0:15 15:15 30:15 40:15 6-3 4-6 7-6 4-6 3-3
Cilic 0:15 15:15 15:30 15:40 30:40 40:40 A:40 40:40 A:40 6-3 4-6 7-6 4-6 3-2
Berankis 15:0 15:15 30:15 40:15 6-3 4-6 7-6 4-6 2-2
Cilic 15:0 30:0 40:0 6-3 4-6 7-6 4-6 2-1
@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
}
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)
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 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 graph.elm
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
main : Element
main =
collage 300 300
[ blueLine
, xAxis
, yAxis
@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 } )