Skip to content

Instantly share code, notes, and snippets.

View tlockney's full-sized avatar

Thomas Lockney tlockney

View GitHub Profile
@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)
@mariofusco
mariofusco / MnemonicsCoder.scala
Created June 12, 2011 16:23
Encodes a number in one (or more) list of words corresponding to its phone mnemonic code
class MnemonicsCoder(words: List[String]) {
private val mnemonics = Map('2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
/** Invert the mnemonics map to give a map from chars 'A' ... 'Z' to '2' ... '9' */
private val charCode: Map[Char, Char] =
for ((digit, str) <- mnemonics; letter <- str) yield (letter -> digit)
/** Maps a word to the digit string it can represent */
// see https://github.com/gseitz/Lensed
object Lensed {
import scalaz._
import Scalaz._
case class Address(street: String)
case class Person(name: String, address: Address)
@gseitz
gseitz / ShellPrompt.scala
Created July 23, 2011 15:58
SBT shell prompt respecting -Dsbt.nologformat
import sbt._
import Keys._
// source of the actual shell modification take from Daniel C. Sobral's gist:
// https://gist.github.com/996474
// prompt looks like:
// $PROJECTNAME:$GITBRANCH>
object ShellPrompt extends Plugin {
@dysinger
dysinger / xmonad.hs
Created August 4, 2011 19:33
Simple XMonad/Gnome Config File ( with windows-key instead of alt-key )
module Main where
import XMonad
import XMonad.Config.Gnome
main :: IO ()
main = xmonad $ gnomeConfig { modMask = mod4Mask }
@gkossakowski
gkossakowski / FactoryManifests.scala
Created August 11, 2011 11:19
Scala Manifests without reflection.
package scala.tools.nsc
package backend.jribble
import scala.collection.mutable
import scala.tools.nsc.transform.{Transform, TypingTransformers}
/**
* Implements 'factorymanifests' compiler phase that provides alternative implementation of
* Manifests that use static factories for Array creation.
*
* Canonical Manifest implementation in Scala uses reflection for generic Array creation.
(defvar *default-font-size* 13)
(defvar *default-font-name* "Menlo")
(defun increase-default-font-size ()
"Increase font size"
(interactive)
(incf *default-font-size*))
(defun decrease-default-font-size ()
"Decrease default font size"
@gseitz
gseitz / ActorMetrics.scala
Created October 3, 2011 05:38
Trait for exposing metrics for akka-actors.
import akka.actor.Actor
import com.yammer.metrics.Instrumented
// Useful for monitoring the mailbox size of actors.
// Just fire up your favorite JMX client and watch the pretty graph (which hopefully is a flatline at 0).
trait ActorMetrics extends Instrumented { actor: Actor =>
metrics.gauge("mailbox size", self.id){actor.self.dispatcher.mailboxSize(actor.self)}
}
@mccv
mccv / gist:1259343
Created October 3, 2011 15:14
OAuth with finagle streaming
import java.net._
import java.util.UUID
import com.twitter.conversions.time._
import com.twitter.finagle.builder.ClientBuilder
import com.twitter.util._
import java.nio.charset.Charset
import org.jboss.netty.buffer.{ChannelBuffers, ChannelBuffer}
import org.jboss.netty.handler.codec.http._
import com.twitter.finagle.stream.Stream
@retronym
retronym / Bundle.scala
Created October 15, 2011 10:09
Outline of a OSGi BND plugin for SBT 0.11
import sbt._
import Keys._
import java.util.jar.Attributes.Name._
import sbt.Defaults._
import sbt.Package.ManifestAttributes
import sbt.Fork.ForkJava
object Bundle extends Plugin {