Skip to content

Instantly share code, notes, and snippets.

View cb372's full-sized avatar

Chris Birchall cb372

View GitHub Profile
@lloydmeta
lloydmeta / gist:11280714
Created April 25, 2014 07:30
Results of https://github.com/derekwyatt/spray-json-vs-argonaut on my work MBR 15, Java7, 8GB ram, 2Ghz Core i7
[info] Json4sJacksonSpec:
[info] Json4sJackson
[info] - should parse it 1,000 times (01) (713 milliseconds)
[info] - should parse it 1,000 times (02) (248 milliseconds)
[info] - should parse it 1,000 times (03) (84 milliseconds)
[info] - should parse it 1,000 times (04) (77 milliseconds)
[info] - should parse it 1,000 times (05) (73 milliseconds)
[info] - should parse it 1,000 times (06) (77 milliseconds)
[info] - should parse it 1,000 times (07) (62 milliseconds)
[info] - should parse it 1,000 times (08) (59 milliseconds)
@lloydmeta
lloydmeta / lazyDropMax.scala
Last active August 29, 2015 14:03
Lazy generic dropMax in Scala so you can work with infinitely (why? dunno) long traversables. Should be fairy efficient wrt traversal complexity, stack and heap used.
import scala.collection.generic.CanBuildFrom
import scala.language.higherKinds
/**
* Returns the input collection without the biggest element.
*/
def dropMax[A, T[A] <: Traversable[A]](coll: T[A])(implicit ord: Ordering[A], cbf: CanBuildFrom[_, A, T[A]]): T[A] = {
def streamWithoutMax(currentMax: A, listTail: Traversable[A]): Stream[A] = {
if (listTail.isEmpty) {
Stream.Empty
} else {
@daggerrz
daggerrz / MemoryMappedFile.scala
Created June 11, 2012 21:00
Memory mapping files larger than Integer.MAX_VALUE
import java.io.RandomAccessFile
import java.nio.channels.FileChannel
import org.jboss.netty.buffer.{ByteBufferBackedChannelBuffer, ChannelBuffer, ChannelBuffers}
/**
* Maps a the filename to a memory mapped random access file across 1 or more buffers.
* Support files up to Long.MAX_VALUE.
*
* @param filename the file to map
* @param maxBufferSize the maximum number of bytes to map per buffer
@tobnee
tobnee / gist:3675523
Created September 8, 2012 14:40
Basic wrapping of guava cache in Scala
import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader
import com.google.common.cache.LoadingCache
import com.google.common.cache.Cache
object CacheUtil {
implicit def functionToCacheLoader[F, T](f: F => T) = {
new CacheLoader[F, T] {
def load(key: F) = f(key)
}
#!/bin/bash
#
# Open a URL in Chrome after SSH'ing to the URL's host and setting up a SOCKS proxy.
if [ $# -ne 1 ]
then
echo "usage: browse-with-proxy.sh <URL>"
echo
echo "Opens the given URL in a browser using an SSH tunnel to the host as a proxy"
echo
sealed trait Status
sealed trait HasID extends Status
sealed trait NoID extends Status
case class User[S <: Status](
firstName: String,
lastName: String,
age: Int,
createdAt: java.util.Date,
private val _id: Int = 0
@Rogach
Rogach / ShowTree.scala
Created September 10, 2013 04:30
Macro to display case class hierarchy as Swing JTree.
package dxf.macros
import scala.language.experimental.macros
import scala.reflect.macros.Context
import scala.swing._
import scala.swing.Swing._
import javax.swing._
import javax.swing.tree.DefaultMutableTreeNode
object ShowTree {
@kimble
kimble / ApplicationGuiceModule.java
Created May 6, 2012 19:01
Dropwizard instrumentation of Guice beans annotated with @timed
package com.developerb.dropbot;
import com.developerb.dropbot.instrumentation.MethodInvocationTimingInterceptor;
import com.google.inject.AbstractModule;
import com.yammer.metrics.annotation.Timed;
import static com.google.inject.matcher.Matchers.annotatedWith;
import static com.google.inject.matcher.Matchers.any;
/**
@propensive
propensive / json.scala
Created November 26, 2012 14:53
Rapture I/O JSON extraction example
import rapture.io._
// Let's parse some JSON
val src: Json = Json.parse("""
{
"foo": "Hello world",
"bar": {
"baz": 42
}
}
@asselstine
asselstine / rbenv.yml
Created November 28, 2013 22:42
Ansible script to install rbenv. Intended for CentOS images.
---
# file ruby.yml
- hosts: all
gather_facts: false
sudo: true
vars:
# Where to install rbenv
- rbenv_root: /usr/local/rbenv
# The version of Ruby to install