Skip to content

Instantly share code, notes, and snippets.

View ericacm's full-sized avatar

Some Dude ericacm

View GitHub Profile
@retronym
retronym / config.scala
Last active May 9, 2018 05:47
Styles of config propagation: Manual, Implicits, DynamicVariable, Reader
package scalaz.example
object Reader extends App {
/**
* Manual propagation of the environment (in the example, `contextRoot`.)
*/
object Config0 {
def fragment1(contextRoot: String) = <a href={contextRoot + "/foo"}>foo</a>
@viktorklang
viktorklang / swingactors.scala
Created April 19, 2012 17:25
Swing Actors using Akka
// ©2012 Viktor Klang
package akka.klang
import akka.dispatch.{ DispatcherPrerequisites, ExecutorServiceFactory, ExecutorServiceConfigurator }
import com.typesafe.config.Config
import java.util.concurrent.{ ExecutorService, AbstractExecutorService, ThreadFactory, TimeUnit }
import java.util.Collections
import javax.swing.SwingUtilities
@viktorklang
viktorklang / swingfutures.scala
Created April 19, 2012 17:58
Akka Futures in the Swing Event Dispatch Thread
// © 2012 Viktor Klang
import akka.dispatch.ExecutionContext
import javax.swing.SwingUtilities
import java.util.concurrent.Executor
//
object SwingExecutionContext {
implicit val swingExecutionContext: ExecutionContext = ExecutionContext.fromExecutor(new Executor {
def execute(command: Runnable): Unit = SwingUtilities invokeLater command
@stonegao
stonegao / AkkaKafkaMailboxTest.scala
Created May 1, 2012 07:24 — forked from mardambey/AkkaKafkaMailboxTest.scala
Akka 2.0 actors with Kafka backed durable mailboxes.
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.agent.Agent
import com.typesafe.config.ConfigFactory
import akka.event.Logging
import akka.actor.Props
import kafka.utils.Utils
import java.nio.ByteBuffer
@jboner
jboner / latency.txt
Last active April 18, 2024 17:18
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@chrsan
chrsan / AkkaSourceDiscriminator.java
Created September 27, 2012 13:14
A logback discriminator for the akkaSource MDC value.
package se.fishtank;
import java.net.URI;
import java.util.Map;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.sift.Discriminator;
import ch.qos.logback.core.spi.ContextAwareBase;
public class AkkaSourceDiscriminator extends ContextAwareBase implements Discriminator<ILoggingEvent> {
@folone
folone / gist:3911448
Created October 18, 2012 12:21
State exercise
case class State[S, +A](run: S ⇒ (A, S)) {
def map[B](f: A => B): State[S, B] =
State(s ⇒ {
val (a, t) = run(s)
(f(a), t)
})
def flatMap[B](f: A ⇒ State[S, B]): State[S, B] =
State(s ⇒ {
val (a, t) = run(s)
@ymasory
ymasory / scala-irc
Last active August 30, 2017 21:16
List of all Scala-related IRC channels.
Please help compile a list of all Scala-related IRC rooms.
All of these channels are on Freenode.
#akka | concurrency & distribution framework
#argonaut | json library
#fp-in-scala | the book Functional Programming in Scala
#geotrellis | geoprocessing library
#indyscala | regional scala group
#json4s | json library
/**
* "Select" off the first future to be satisfied. Return this as a
* result, with the remainder of the Futures as a sequence.
*
* @param fs a scala.collection.Seq
*/
def select[A](fs: Seq[Future[A]])(implicit ec: ExecutionContext): Future[(Try[A], Seq[Future[A]])] = {
@tailrec
def stripe(p: Promise[(Try[A], Seq[Future[A]])],
heads: Seq[Future[A]],