Skip to content

Instantly share code, notes, and snippets.

View rbuckland's full-sized avatar

Ramon Buckland rbuckland

  • Inosion
  • Sydney Australia
View GitHub Profile
@rbuckland
rbuckland / SbtConfigurationforHeroku.scala
Last active March 12, 2016 11:39
This is some configuration I have used to run a a Scala base SBT webapp on Heroku. It mirrors that Java Maven way of using jetty-runner. The Heroku suggestion of using "sbt-start-script" is just bad.
/*
This is some configuration I have used to run a a Scala base SBT webapp on Heroku.
Heroku suggest using startscript. But this doesn;t work on Mac OSX *readline, it also uses an embedded jetty verison, and it uses the jetty distribution.
Instead, Heroku suggest using jetty-runner with Java Maven projects (and I liked that a lot) so I am replicating that setup here.
In short:
1. Ensure you have the xsbt-web-plugin
@rbuckland
rbuckland / H2DatabaseGenerator.scala
Created April 1, 2014 19:24
Creates a ZIP file from an XLS Spreadsheet uploaded to the client.Uses some magic foo and a spinkling of fun - see this at http://ete.straight.io
/**
* @author rbuckland
*/
trait H2DatabaseGenerator extends CommonHttpService {
val generateH2DbRoute = pathPrefix("h2generator") {
// headerValueByName("Upload-File-Name") { filename =>
// headerValueByName("DatabaseName") { dbname =>
@rbuckland
rbuckland / CampusMessages.scala
Created April 22, 2014 20:49
Sample to show / explain CommandMessage Enrichment of MetatData
import org.joda.time.DateTime
import com.soqqo.luap.model.common.Address
import io.straight.fw.model.Uuid
import java.util.Date
import akka.actor.ActorRef
/*
* file: CampusMessages.scala
*/
@rbuckland
rbuckland / sealed-abstract-case-class-copy for Command messages.scala
Last active September 30, 2021 10:36
Sometimes you just want to call the copy method for the same "parameters", but not care about what underlying type it is.Because case class .copy() methods are auto generated per case class, you can't call copy on the abstract class, so this approach uses some scala foo to generate a scala Function that generates the correct magic for you.
package com.soqqo.luap.messages
import com.soqqo.luap.messages.ContextMetaData
import com.soqqo.luap.messages.NoContextMetaData
import com.soqqo.luap.messages.RegisterNewPerson
import io.straight.fw.model.Uuid
import scala.reflect.api.JavaUniverse
import scala.reflect.api
import io.straight.fw.jackson.JacksonBindingSupport._
import scala.Some
@rbuckland
rbuckland / AddNewRegistrationSpec.scala
Created April 23, 2014 20:25
JacksonUnmarshallingSpec for Spray. Just making sure that it is all still working.
package com.soqqo.luap.web.marshalling
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import io.straight.fw.spray.marshalling.JacksonUnmarshaller
import com.soqqo.luap.messages.AddNewAccountTenantRegistration
import spray.httpx.unmarshalling._
import spray.util._
import spray.http._
import spray.http.MediaTypes.`application/json`
@rbuckland
rbuckland / spire-maths-gist.scala
Created February 24, 2015 23:28
compiler error with generics
def safeSum[A: Numeric](as: Seq[A]):Option[A] =
if (as.isEmpty) None else Some(as.qsum)
def safeDiv[A: Numeric](a:Option[A], b:Option[A]):Option[Double] = (a,b) match {
case (None,_) | (_,Some(0)) | (_,None) => None
case (Some(x),Some(y)) => Some((x / y).toDouble())
}
/**
scala> val x:Double = Long.MaxValue // x: Double = 9.223372036854776E18 (9223372036854775807)
scala> x == Long.MaxValue // Boolean = true
scala> x.longValue == Long.MaxValue // Boolean = true
scala> val y = 1234567890123456789L // y: Long = 1234567890123456789 // less than Long.MaxValue
scala> y < x // Boolean = true
scala> val z:Double = y // z: Double = 1.23456789012345677E18
scala> z == y // Boolean = true
scala> z.longValue == y // Boolean = false // why ? MaxValue fits in the Double
def doWork[A: Numeric, B: Numeric](values: Seq[Option[A]], op: String): Option[B] = {
import spire.implicits._
val v = values.flatten
if (v.isEmpty) {
None
} else {
op match {
case "sum" => Some(v.qsum) // returns A
case "avg" | "avg" => Some(v.qsum / v.length) // returns Double
case "max" => Some(v.qmin) // A
@rbuckland
rbuckland / 01. mr4c Install Notes for Ubuntu and RedHat.md
Last active December 2, 2020 09:14
Detailed notes for Installing mr4c on RedHat EL6 and Ubuntu 14.04

Installing mr4c - MapReduce for C/C++

https://github.com/google/mr4c http://google-opensource.blogspot.com.au/2015/02/mapreduce-for-c-run-native-code-in.html

General Notes

mr4c and it's dependencies will be required installs on all nodes that run your algorithms; This goes without saying, but of course if you get exceptions like below, then that is literally what is going on.

Caused by: java.lang.UnsatisfiedLinkError: Unable to load library '/data/nvme/yarn/nm/usercache/genuser/filecache/10/libmr4c.so': liblog4cxx.so.10: cannot open shared object file: No such file or directory

@rbuckland
rbuckland / README.md
Created December 16, 2015 22:43
Using Ammonite as a "Shell Script" Replacement (a test)

Overview

I have been working on a project with a number of docker containers that are either run on a local machine, or on a remote machine.

The process is fairly simple, I either need to "build" a docker image, "run" a container, from an image, and/ or push an image to a local docker repository.

The process is like this

dockers/