Skip to content

Instantly share code, notes, and snippets.

View cb372's full-sized avatar

Chris Birchall cb372

View GitHub Profile
@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
@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 {
@xuwei-k
xuwei-k / build.sbt
Last active June 24, 2021 01:09
show message when sbt build files changed
val buildFiles = SettingKey[Map[File, Seq[Byte]]]("build-files")
buildFiles := getBuildFiles((baseDirectory in ThisBuild).value)
def getBuildFiles(base: File) =
((base * "*.sbt") +++ ((base / "project") ** ("*.scala" | "*.sbt"))).get.map{
f => f -> collection.mutable.WrappedArray.make[Byte](Hash(f))
}.toMap
def changed(base: File, files: Map[File, Seq[Byte]]): Boolean =
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
@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
}
}
@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)
}
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@jarosan
jarosan / elasticsearch.rake
Created July 16, 2012 20:37
Elasticsearch reindex task
# Run with: rake environment elasticsearch:reindex
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
klass = Place
ENV['CLASS'] = klass.name
ENV['INDEX'] = new_index = klass.tire.index.name << '_' << Time.now.strftime('%Y%m%d%H%M%S')
@deverton
deverton / logstash-template.json
Created June 22, 2012 04:49
Logstash Elasticsearch Template
{
"template": "logstash-*",
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0,
"index" : {
"query" : { "default_field" : "@message" },
"store" : { "compress" : { "stored" : true, "tv": true } }
}
},
@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