Skip to content

Instantly share code, notes, and snippets.

@ryantanner
ryantanner / AnalyticsLeader.scala
Last active March 19, 2021 18:27
Conspire's implementation of work pulling
class AnalyticsLeader(supervisor: ActorRef) extends Leader[ProcessUser, AnalyticsNode, AnalyticsMessage](supervisor)
@ryantanner
ryantanner / README.md
Created March 13, 2020 17:51
Creating a "hot mic" icon with BetterTouchTool

This describes how to create a hot mic icon in the Touch Bar, like this: https://twitter.com/youfoundryan/status/1238507646677700608

  1. Install BetterTouchTool (https://folivora.ai/)
  2. Create a new Touch Bar widget of type "Apple Script/Javascript Widget". You don't need a trigger.
  3. Paste the contents of mic_state.scpt into the script box.
  4. Set the "Alternate Color Regex" to "off".
  5. Switch to the "common" widget settings pane. Set the button background color to red. Set the "Select Button Icon" to the mic and the "Alternate Button Icon" to the mic with a line through it.
  6. Check "show only icon, no text"

I also assigned a FN key on my external keyboard to toggle the mic:

/** Reads queue of new users to index */
class NewUserQueue extends Actor with ActorLogging { ... }
// Define our messages for the NewUserQueue
object NewUserQueue {
case class Listen(ref: ActorRef)
case class StopListen(ref: ActorRef)
case class NewUsers(users: Seq[User])
}
case class User(id: Long, name: String)
class Work { /* ... */ }
class Result { /* --- */ }
case class WorkToBeDone(user: User, work: Work)
case class WorkIsDone(user: User, result: Result)
class Worker extends Actor { /* ... */ }
class BadWorkerCoordinator extends Actor {
akka.actor.deployment {
/analytics/leader {
router = round-robin
nr-of-instances = 100
cluster {
enabled = on
max-nr-of-instances-per-node = 3
allow-local-routees = off
use-role = analytics
}
@ryantanner
ryantanner / Pipeline.scala
Last active December 25, 2015 15:39
Why We Use Actors at Conspire
object UserPipeline {
case class Listen(ref: ActorRef)
case class Start(user: User)
case class Success(user: User)
}
class UserPipeline(
val source: ActorRef // This is an actor that produces a stream of users to be processed
@ryantanner
ryantanner / Actors.scala
Last active December 25, 2015 01:09
Akka stuff
class MyCounter extends Actor {
var count = 0
def receive = {
case Add => count + 1
case GetCount = sender tell count
}
}
val some5: Option[Int] = Some(5)
val missingInt: Option[Int] = None
val i: Int = 42 // Good
val i: Int = "Hello" // Compiler error
String st = "Hello" // Compiles
String st = null // Danger! Also compiles!
def findUserById(id: Int): Option[User] = {
@ryantanner
ryantanner / application.conf
Created September 12, 2013 22:32
Conspire Akka Configs
akka {
log-config-on-start = on
actor {
provider = "akka.cluster.ClusterActorRefProvider"
}
remote {
log-remote-lifecycle-events = off
netty.tcp {
// Play controller
def source(flightIdent: String) = Action {
Async {
for {
flight <- Flight.findByIdent(flightIdent)
source <- (eventSource ? Track(flight))
} yield source match { case Connected(stream) =>
Ok.feed((stream &> EventSource[JsValue]()(