Skip to content

Instantly share code, notes, and snippets.

View mccv's full-sized avatar

Mark McBride mccv

View GitHub Profile
package org.mccv
/**
* A marker trait indicating an exception that is recoverable.
* Note that we could make this a trait as well.
*/
class RecoverableException extends Exception
/**
* Usage of our retryable class
package org.mccv
/**
* A marker trait indicating an exception that is recoverable.
* Note that we could make this a trait as well.
*/
class RecoverableException extends Exception
/**
* Usage of our retryable class
@mccv
mccv / CassidySamples.scala
Created August 18, 2009 21:48
Cassidy.scala
val c = new Cassidy(StackPool(SocketProvider("localhost", 9160)), Protocol.Binary, ConsistencyLevel.QUORUM)
c.doWork {
s => {
val key = "mccv"
println("exercising inserts")
s ++| ("Delicious", key, new ColumnPath("Users", null, "name"), "Mark McBride")
s / ("Delicious") ++| (key, new ColumnPath("Users", null, "location"), "Santa Clara")
s / ("Delicious") / (key) ++| (new ColumnPath("Users", null, "state"), "CA")
s/"Delicious"/key/"Users" ++| ("age","34-ish")
class GangliaLogger(config: ConfigMap) extends Thread {
val frequency = config.getInt("ganglia_frequency", 15000)
val gmetricExecutable = config.getString("gmetric_executable", "gmetric")
val logJvmStats = config.getBool("log_jvm_stats", true)
val logCounterStats = config.getBool("log_counter_stats", true)
val logTimingStats = config.getBool("log_timing_stats", true)
val logGaugeStats = config.getBool("log_gauge_stats", true)
val quit = new CountDownLatch(1)
val done = new CountDownLatch(1)
val runtime = Runtime.getRuntime()
package com.twitter.jetty
object OAuthEncoder {
val ALPHA = Set((0x41 to 0x5A):_*) ++ Set((0x61 to 0x7A):_*)
val DIGIT = Set((0x30 to 0x39):_*)
val HYPHEN = Set(0x2D)
val PERIOD = Set(0x2E)
val UNDERSCORE = Set(0x5F)
val TILDE = Set(0x7E)
val UNENCODED = ALPHA ++ DIGIT ++ HYPHEN ++ PERIOD ++ UNDERSCORE ++ TILDE
# need ruby, gems, and the json gem installed
function jsonator {
ruby -rubygems -r pp -e 'require "json"; ARGF.each {|l| puts JSON.pretty_generate(JSON.parse(l))}'
}
function jsoncurl {
curl -s $@ | jsonator
}
function jsontwurl {
def timeLoops (loops: Int)(f: => Any) = {
val t1 = System.currentTimeMillis
for(i <- 1 to loops)
f
val elapsed = System.currentTimeMillis - t1
println("executed %d loops in %d ms, or %.2f loops/sec".format(
loops, elapsed, loops/(elapsed/1000.0)))
}
val loops = 1000000
import sbt._
import com.twitter.sbt._
class OstrichProject(info: ProjectInfo) extends StandardProject(info) with TartifactoryPublisher with TartifactoryRepos {
val specs = "org.scala-tools.testing" % "specs" % "1.6.2.1"
val vscaladoc = "org.scala-tools" % "vscaladoc" % "1.1-md-3"
val twitterJson = "com.twitter" % "json" % "1.1.2"
// we declare a dependencies source location by adding an extra attribute
val configgy = "net.lag" % "configgy" % "1.5.5" extra(("source", "../configgy"))
val commonsLogging = "commons-logging" % "commons-logging" % "1.1"
@mccv
mccv / ensime-sbt.scala
Created December 15, 2010 18:12
.ensime generating task for sbt
// generate ensime config
lazy val genEnsime = task (args => {
if (args.length == 1) {
genEnsimeConstructor(args(0).toString)
} else {
task { Some("Usage: gen-ensime <project package name>") }
}
}) describedAs("Generate a .ensime file for this project")
def genEnsimeConstructor(packageName: String) = task {
@mccv
mccv / Send.scala
Created December 22, 2010 07:19
Hobo Ruby send equivalent. Really just syntactic sugar for standard reflection stuff
import java.lang.reflect.Method
class Sendable(a: AnyRef) {
val methods = a.getClass.getDeclaredMethods
def wrapByte(b: Byte) = new java.lang.Byte(b)
def wrapShort(s: Short) = new java.lang.Short(s)
def wrapInt(i: Int) = new java.lang.Integer(i)
def wrapLong(l: Long) = new java.lang.Long(l)
def wrapFloat(f: Float) = new java.lang.Float(f)