Instantly share code, notes, and snippets.

View AkkaSpecification.scala
import org.specs2.mutable._
import org.specs2.specification._
import org.specs2.matcher._
import org.specs2.execute._
import org.specs2.control.Debug
import org.specs2.main.ArgumentsShortcuts
import akka.testkit.TestKitBase
View Example.scala
class MyActor extends TypedMessageActor {
import MyActor._
def receive = ReceiveMessage[AllowedMessage] {
case Message1(text) =>
case Message2 =>
View RemoveByIndexImplicit.scala
// Scala - you gotta love it.
class MPSList[T](val list: List[T]) {
def removeByIndex(index: Int): MPSList[T] = {
new MPSList[T](list.remove(list.indexOf(_) == index))
object MPSList {
implicit def mpsListToScalaList[T](list: List[T]) = new MPSList[T](list)
View gist:562231
; It's a thing of beauty how easy it is to parse therapy intervals in Clojure.
; Therapy intervals are usually Strings like 1-0-3-0 or 1-0.5-1 to describe how many pills a patient is taking every day
(defn interval-value [interval] "Parses an interval String and returns its numerical value"
(reduce + (map #(Double/valueOf %) (re-seq #"[0-9]+(?:[\\.][0-9]+)?" interval))))
View gist:782684
// "Write less, do more" episode 1203: iterating Strings creates chars, yielding chars creates a String
def abbreviatedName(fullName: String) = for (ch <- fullName; if ch.isUpper) yield ch
View gist:784253
// Best of both worlds - WebObjects + Scala
// valueForKeyPath operators
def parameters: NSArray[Parameter] = ...
def maxSortOrder = parameters.valueForKeyPath("sortOrder.@max").asInstanceOf[Int]
// Clone attributes of an EnterpriseObject (aka DB row with all non-relationship columns)
trait Cloning extends EOEnterpriseObject {
type EOType <: EOEnterpriseObject
View dollybastard-4clojure-solution30.clj
;; marius' solution to Compress a Sequence
#(map last (partition-by str %))
View msoutier-4clojure-solution41.clj
;; msoutier's solution to Drop Every Nth Item
(fn [coll n]
(keep-indexed #(if (not= 0 (mod (inc %1) n)) %2 nil) coll))
View msoutier-4clojure-solution32.clj
;; msoutier's solution to Duplicate a Sequence
#(interleave % %)
View msoutier-4clojure-solution31.clj
;; msoutier's solution to Pack a Sequence
partition-by identity