Skip to content

Instantly share code, notes, and snippets.

@metamorph
metamorph / Code
Created January 16, 2012 15:20
Dynamic remote deployment in Akka
package ring
import akka.actor._
import akka.routing.NoRouter
import akka.remote.{RemoteScope, UnparsedTransportAddress, UnparsedSystemAddress}
/**
// application.conf:
akka {
actor {
@metamorph
metamorph / Output
Created December 5, 2012 18:12
Akka - Resume in supervisor. I would expect MESSAGE_2 to reach the 'Node' actor.
[INFO] [12/05/2012 19:11:03.478] [Resume-akka.actor.default-dispatcher-1] [akka://Resume/user/super/manager] Relaying to node: MESSAGE_1
[INFO] [12/05/2012 19:11:03.478] [Resume-akka.actor.default-dispatcher-3] [akka://Resume/user/super/manager/node] Node got message: MESSAGE_1
[ERROR] [12/05/2012 19:11:03.479] [Resume-akka.actor.default-dispatcher-1] [akka://Resume/user/super/manager] java.lang.Exception: Crash
java.lang.RuntimeException: java.lang.Exception: Crash
at foo.Manager$$anonfun$receive$2.apply(Resume.scala:42)
at foo.Manager$$anonfun$receive$2.apply(Resume.scala:41)
at akka.actor.Actor$class.apply(Actor.scala:318)
at foo.Manager.apply(Resume.scala:37)
at akka.actor.ActorCell.invoke(ActorCell.scala:626)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)
case class RegisterDispatcher(ref: ActorRef, matcher: String)
class MasterActor extends Actor {
def receive = {
case RegisterDispatcher(ref, matcher) => //.. add ref to registry. watch the ref to remove the entry should the actor terminate.
case s: String => // look in the registry for a match amd dispatch accordingly.
}
}
@metamorph
metamorph / gist:5003153
Created February 21, 2013 08:21
Tiny embryo for an IRC bot using Akka I/O
import akka.actor.ActorSystem
import akka.io.IO
import akka.io._
object Boot extends App {
import akka.io.Tcp._
implicit val sys = ActorSystem("io")
import akka.actor.{Actor, Props, ActorRef}
@metamorph
metamorph / .spacemancs
Created May 8, 2015 09:08
Spacemacs - disable flyspell by default
;; Remove fly-spell for markdown and text-files.
(remove-hook 'text-mode-hook 'enable-flyspell-mode)
(remove-hook 'markdown-mode-hook 'enable-flyspell-mode)
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
;; Configuration Layers
;; --------------------
(setq-default
;; List of additional paths where to look for configuration layers.
;; Paths must have a trailing slash (ie. `~/.mycontribs/')
(ns amaze-me.core
(:require [quil.core :as q]
[quil.middleware :as m]))
(defn ball-setup
"initial state of tha ball."
[]
(q/smooth)
(q/background 255)
{:direction {:x 4 :y 5}
@metamorph
metamorph / core.clj
Last active October 1, 2015 06:23
Binary Tree in Clojure. Comments on how to improve the code are welcome. It feels like it's somewhat repetitive, and maybe not fully idiomatic Clojure?
(ns test-bench.core)
(defprotocol BinaryTree
(member? [_ e] "Check if e is a member of the BinaryTree")
(insert [_ e] "Insert an element in the tree")
(delete [_ e] "Remove element from tree"))
;; Need to forward declare factory functions.
(declare leaf node delete)
@metamorph
metamorph / Main.java
Last active May 23, 2017 10:03
Laziness in Java and Clojure (with, and without, Transducers)
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
public class Main {
public static void main(String[] args) {
Predicate<Integer> isOdd = i -> {