Skip to content

Instantly share code, notes, and snippets.

View jboner's full-sized avatar

Jonas Bonér jboner

View GitHub Profile
<!-- Example of Akka/Spring integration -->
<beans>
<!-- Create an active object -->
<akka:active-object id="myActiveObject"
target="com.biz.MyPOJO"
transactional="true"
timeout="1000" />
import java.util.zip._
import java.io._
class InMemZip(compressionLevel: Int) {
private val _outBytes = new ByteArrayOutputStream
private val _zipOutStream = {
val s = new ZipOutputStream(_outBytes)
s.setLevel(compressionLevel)
s
}
// Shutdown HawtDispatch GlobalQueue
org.fusesource.hawtdispatch.ScalaDispatch.globalQueue.asInstanceOf[org.fusesource.hawtdispatch.internal.GlobalDispatchQueue].shutdown
// Clear Thread.subclassAudits
val tf = classOf[java.lang.Thread].getDeclaredField("subclassAudits")
tf.setAccessible(true)
val subclassAudits = tf.get(null).asInstanceOf[java.util.Map[_,_]]
subclassAudits.synchronized {subclassAudits.clear}
// Clear and reset j.u.l.Level.known (due to Configgy)
import scala.collection.mutable.ListBuffer
import akka.actor.{Actor,ActorRef}
import akka.actor.Actor._
import akka.routing.{ Listeners, Listen }
//Represents a domain event
trait Event
//A builder to create domain entities
trait EntityBuilder[Entity] {
@jboner
jboner / cloc-akka.txt
Created October 3, 2012 15:42
cloc on akka
jboner at sarek in ~/src/akka-stuff/akka on master
[130] $ cloc . 5244 text files.
2647 unique files.
3822 files ignored.
http://cloc.sourceforge.net v 1.56 T=52.0 s (41.8 files/s, 13040.5 lines/s)
--------------------------------------------------------------------------------
Language files blank comment code
--------------------------------------------------------------------------------
HTML 1473 39655 1 529371
@jboner
jboner / VendingMachine.scala
Last active November 13, 2015 17:04
Vending Machine Akka Supervision Demo
import akka.actor._
import akka.actor.SupervisorStrategy._
import scala.concurrent.duration._
// Coffee types
trait CoffeeType
case object BlackCoffee extends CoffeeType
case object Latte extends CoffeeType
case object Espresso extends CoffeeType
case class MyMessage(val id: String, val value: Tuple2[String, Int]) extends ScalaJSON
val message = MyMessage("id", ("hello", 34))
val json = message.toJSON
val messageCopy = Serializer.ScalaJSON.in(json)
@jboner
jboner / SimpleAkkaIoHttpClient.scala
Created January 4, 2013 10:17
Nice simple Akka IO HTTP Client by @patriknw
import akka.actor._
import java.net.InetSocketAddress
import akka.util.ByteString
class SimpleClient(destAddress: InetSocketAddress) extends Actor {
val socket = IOManager(context.system) connect (destAddress)
val state = IO.IterateeRef.sync()
@jboner
jboner / lostincallbackhell.js
Created April 26, 2013 13:10
Lost In Callback Hell
lost(arg, function(err, result) {
if(err) return console.log(err);
In(result, function(err, result) {
if(err) return console.log(err);
callback(result, function(err, result) {
if(err) return console.log(err);
hell(result);
});
});
});
@jboner
jboner / keybase.md
Last active January 6, 2016 01:10
Keybase proof

Keybase proof

I hereby claim:

  • I am jboner on github.
  • I am jonas (https://keybase.io/jonas) on keybase.
  • I have a public key ASB-dCL3b2wk3TzgiVeoHmmp_s-ZM004MVmlztARjGu-pAo

To claim this, I am signing this object: