Skip to content

Instantly share code, notes, and snippets.

View ochoto's full-sized avatar

Xabi Ochotorena ochoto

View GitHub Profile
@raulraja
raulraja / EmailService.scala
Last active October 19, 2018 06:57
EmailService.scala improved with Exception Handling and Routes
/*
* Copyright (C) 2012 47 Degrees, LLC
* http://47deg.com
* [email protected]
*
* 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
@patriknw
patriknw / PeekMailbox.scala
Created November 21, 2012 14:20
PeekMailbox example
package example
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import akka.actor.Actor
import akka.actor.ActorContext
import akka.actor.ActorRef
import akka.actor.ActorSystem
@patriknw
patriknw / ClusterWatch.scala
Created October 8, 2012 13:12
Spotlight for Cluster Death Watch
case object BackendRegistration
case class Job(text: String)
class Frontend extends Actor {
var backends = IndexedSeq.empty[ActorRef]
var jobCounter = 0
def receive = {
case job: Job if backends.isEmpty =>
@patriknw
patriknw / ClusterListener.scala
Created October 8, 2012 12:48
Spotlight for Cluster Membership
import akka.cluster.Cluster
import akka.cluster.ClusterEvent._
val clusterListener = system.actorOf(Props(new Actor with ActorLogging {
def receive = {
case state: CurrentClusterState ⇒
log.info("Current members: {}", state.members)
case MemberUp(member) ⇒
log.info("Member is up: {}", member)
// send a message to the "world" actor running at the member node
@patriknw
patriknw / CircuitBreakerSpotlight.scala
Created October 3, 2012 11:19
Circuit Breaker Spotlight
import akka.pattern.CircuitBreaker
val breaker =
CircuitBreaker(system.scheduler,
maxFailures = 5,
callTimeout = 10.seconds,
resetTimeout = 1.minute)
def dangerous: Future[String] =
breaker.withCircuitBreaker(Future(dangerousCall))
@gclaramunt
gclaramunt / gist:3789915
Created September 26, 2012 19:06
Install Scala support for VIM in one line
mkdir -p ~/.vim/{ftdetect,indent,syntax} && for d in ftdetect indent syntax ; do wget -O ~/.vim/$d/scala.vim https://raw.github.com/scala/scala-dist/master/tool-support/src/vim/$d/scala.vim ; done
@rkuhn
rkuhn / dsl-demo.scala
Created September 26, 2012 18:47
actor dsl demo
import akka.actor.ActorDSL._
val ref = actor("fred")(new Act {
become {
case "hello" => sender ! "world!"
}
})
implicit val recv = inbox()
ref ! "hello" // uses the `recv` as sender ref
@neotyk
neotyk / README
Created September 17, 2012 19:06
WebSocket based browser-connected REPL
This ClojureScript REPL is able to work in restrictive environment, like Chrome Extension.
Requirements:
- WebSocket :: to receive JavaScript forms and send results back,
- 'unsafe-eval' :: Content Security Policy needs to allow 'unsafe-eval' for script-src
Security warning: Do *not* use in production!
Tested on Chrome, might work on other HTML5 enabled browsers.
@jeffreyolchovy
jeffreyolchovy / RecursiveStreams.scala
Created August 30, 2012 15:15
Recursive Streams in Scala
import scala.math.{BigInt, BigDecimal}
object RecursiveStreams
{
// natural numbers
lazy val N: Stream[BigInt] = Stream.cons(BigInt(1), N.map(_ + 1))
// fibonacci series
lazy val fib: Stream[BigInt] = Stream.cons(BigInt(0), Stream.cons(BigInt(1), fib.zip(fib.tail).map(a => a._1 + a._2)))
@hoffrocket
hoffrocket / StreamingDump.scala
Created August 29, 2012 20:33
Mongo streaming dump in scala
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.EOFException
import java.io.InputStream
import java.io.OutputStream
import org.bson.BSONCallback
import org.bson.BSONObject
import com.mongodb.DBCallback