Skip to content

Instantly share code, notes, and snippets.

package core.dao
import scala.concurrent.Future
import play.api.Logger
import reactivemongo.core.commands.LastError
import reactivemongo.core.errors.DatabaseException
import core.db.MongoHelper
@pchiusano
pchiusano / buffer.scala
Created August 6, 2014 01:21
Buffer type with purely functional API, using a mutable buffer and cheap copy-on-write scheme
import java.util.concurrent.atomic._
import collection.mutable.ArrayBuffer
/**
* Buffer type with purely functional API, using mutable
* `ArrayBuffer` and cheap copy-on-write scheme.
* Idea described by Bryan O'Sullivan in http://www.serpentine.com/blog/2014/05/31/attoparsec/
*/
class Buffer[A](id: AtomicLong, stamp: Long, values: ArrayBuffer[A], size: Int) {
@marthakelly
marthakelly / boto-fab
Created August 9, 2012 15:46
Creating EC2 instance with Boto and Fabric
from fabric.api import *
from fabric.colors import green as _green, yellow as _yellow
import boto
import boto.ec2
from config import *
import time
def create_server():
"""
Creates EC2 Instance
Versioning is an anti-pattern
=============================
We often say "use the right tool for the job", but when managing change
in software systems, we always use versioning. Hypermedia APIs are
actually hindered by introducing versioning and manage change in a
different way. With that in mind, there are also a lot of options for
managing change in a Hypermedia API. We'd like to change our service and
break as few clients as possible. Versioning is only one way to manage
change, though... and my contention is that it's not appropriate for
@milessabin
milessabin / gist:25b7b669b5a9ac051a71
Created June 5, 2015 14:32
A safe ADT+shapeless drop-in replacement for the unsafe standard Scala Enumeration ...
// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration.
//
// First the unsafe standard Scala Enumeration ...
//
object ScalaEnumDemo extends App {
// Example from scala.Enumeration scaladoc. Terse ...
object WeekDay extends Enumeration {
type WeekDay = Value
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
@ismell
ismell / README.md
Last active September 10, 2016 15:39
Docker Ubuntu upstart scripts

Production Ready Process Monitoring

  1. Install docker-manger.conf and docker-instance.conf in /etc/init

  2. Create a containers file in /etc/docker/ with the following format

     name: image cmd
    

    The name must be unique.

  3. sudo service docker-manager start

Hi, looking for scalac flags?

This gist has been upgraded to a blog post here.

@ochrons
ochrons / gist:10681050
Last active March 26, 2018 15:21
Super thin Scala wrapper for common DataStax Cassandra Java driver functionality.
object CassandraWrapper {
import scala.language.implicitConversions
import scala.language.postfixOps
/**
* Converts a `ResultSetFuture` into a Scala `Future[ResultSet]`
* @param f ResultSetFuture to convert
* @return Converted Future
*/
implicit def resultSetFutureToScala(f: ResultSetFuture): Future[ResultSet] = {
val p = Promise[ResultSet]()
@jrudolph
jrudolph / JsonRejectionHandler.scala
Created March 6, 2014 11:29
Custom rejection handler that returns JSON
case class ErrorMessage(message: String, cause: String)
object ErrorMessage {
import spray.json.DefaultJsonProtocol._
implicit val errorFormat = jsonFormat2(ErrorMessage.apply)
}
import spray.httpx.SprayJsonSupport._
implicit val jsonRejectionHandler = RejectionHandler {
case MalformedRequestContentRejection(msg, cause) :: Nil =>
complete(StatusCodes.BadRequest, ErrorMessage("The request content was malformed", msg))