Skip to content

Instantly share code, notes, and snippets.

@tommorris
tommorris / gist:437512
Created June 14, 2010 10:05
talking to oauth-out-of-band fireeagle using scala's databinder dispatch oauth
// Welcome to Scala version 2.7.5.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20).
// Type in expressions to have them evaluated.
// Type :help for more information.
scala> import dispatch._
import dispatch._
scala> import oauth._
import oauth._
@momania
momania / gist:653276
Created October 29, 2010 10:14
HeartMonitor using Akka FSM
import akka.actor.{Actor, FSM}
import java.util.concurrent.TimeUnit
sealed trait Health
case object Stale extends Health
case object Alive extends Health
case object Dead extends Health
case object HeartBeat
@momania
momania / gist:661478
Created November 3, 2010 18:28
Akka FSM Goto 10 FTW!
class GotoFsm extends Actor with FSM[Int, Null] {
notifying {
case Transition(_, 10) => println("Goto 10 ftw!")
}
when(0) {
case _ => goto(10) until 5000
}
@nicoulaj
nicoulaj / build-zsh.sh
Created November 25, 2010 20:19
Build Zsh from sources on Ubuntu
#!/bin/sh​
# Build Zsh from sources on Ubuntu.
# From http://zsh.sourceforge.net/Arc/git.html and sources INSTALL file.
# Some packages may be missing
sudo apt-get install -y git-core gcc make autoconf yodl libncursesw5-dev texinfo
git clone git://zsh.git.sf.net/gitroot/zsh/zsh
cd zsh
@momania
momania / gist:896062
Created March 31, 2011 09:01
Over engineered Akka FSM scala Swing undecorated dialog using shapes and fading (why? because we can!)
package notification
import com.sun.awt.AWTUtilities
import java.awt.geom.RoundRectangle2D
import org.jdesktop.animation.timing.{TimingTarget, Animator}
import swing._
import event.MouseClicked
import com.efgfp.creditspy.util.GuiUtil
import akka.actor.{FSM, Actor}
import org.jdesktop.animation.timing.Animator.{Direction, RepeatBehavior}
@rossabaker
rossabaker / gist:1185548
Created September 1, 2011 05:55
Scala crossbuild conventions

To fight against SBT Case Statement Hell™ and unstable builds, the following guidelines are recommended for all Scala libraries:

  • A project must not release with snapshot dependencies, either indirect or transitive. Only snapshots may depend on snapshots. Rationale: We need repeatable builds. Snapshots are not repeatable.

  • Any library publishing under SBT crossbuild conventions commits to a prompt release for each new Scala version. Rationale: Do unto downstream projects as you would have upstream projects do unto you.

  • The release may be a new version or a new crossbuild of a previously released version. Rationale: Whatever gets it out the door quickest. You can always release again off your development branch later.

  • A release may depend on different versions of the same library for different cross builds. Rationale: You can't control when a dependency drops support for a certain version of Scala. That's fine, as long as your project still runs against the last supported version.

@ctcarrier
ctcarrier / spray_lift_json
Created October 20, 2011 04:32
Spray lift-json support
implicit def liftJsonUnmarshaller[A :Manifest] = new UnmarshallerBase[A] {
val canUnmarshalFrom = ContentTypeRange(`application/json`) :: Nil
def unmarshal(content: HttpContent) = protect {
val jsonSource = DefaultUnmarshallers.StringUnmarshaller.unmarshal(content).right.get
parse(jsonSource).extract[A]
}
}
implicit def liftJsonMarshaller[A <: AnyRef] = new MarshallerBase[A] {
val canMarshalTo = ContentType(`application/json`) :: Nil
@remeniuk
remeniuk / GlassfishDeployer.scala
Created November 18, 2011 09:52
Deploying to Glassfish remotely through SBT
trait GlassfishDeployer {
import com.sun.jersey.api.client.{Client, ClientResponse}
import com.sun.jersey.multipart.FormDataMultiPart
import com.sun.jersey.multipart.file.FileDataBodyPart
import javax.ws.rs.core.MediaType
import java.io.File
import scala.xml._
@dcsobral
dcsobral / WordCount.scala
Created November 25, 2011 13:00
WordCount
// Based on Fantom's word count example here: http://blog.joda.org/2011/11/guide-to-evaluating-fantom.html
// I'm commenting the lines that need changing, and leaving a few of them uncommented,
// as they are the same
// class WordCount {
object WordCount {
// Void main(Str[] args) {
def main(args: Array[String]) {
if (args.size != 1) {
@pchiusano
pchiusano / microbenchmark.markdown
Created December 2, 2011 13:49
Simple microbenchmarks comparing Scala vs Java mutable map performance

I was curious about the results reported here, which reports that Scala's mutable maps are slower than Java's: http://www.infoq.com/news/2011/11/yammer-scala

In my tests, Scala's OpenHashMap equals or beats java's HashMap:

Insertion 100k elements (String keys) time in ms:

  • scala HashMap: 92.75
  • scala OpenHashMap: 14.03125
  • java HashMap: 15.78125