Skip to content

Instantly share code, notes, and snippets.

@viktorklang
viktorklang / minscalaactors.scala
Last active March 25, 2024 19:01
Minimalist Scala Actors
/*
Copyright 2012-2021 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@eed3si9n
eed3si9n / source-dep.sbt
Created December 31, 2011 20:30
displays internal source deps
TaskKey[Unit]("source-dep") <<= (fullClasspath in Runtime) map { (cp) =>
cp map { dir =>
val analysis = Defaults.extractAnalysis(dir)._2
analysis.relations.allSources map { file =>
println(file.getName.toString + " depends on " + analysis.relations.internalSrcDeps(file))
}
}
()
}
@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
@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) {
@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._
@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
@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.

@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}
@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: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
}