Skip to content

Instantly share code, notes, and snippets.

View Fristi's full-sized avatar

Mark Fristi

View GitHub Profile
@Fristi
Fristi / Main.scala
Last active August 27, 2015 15:31
(Parameterized) Eventstreams with akka-persistence-query
package base64
import akka.actor.{Actor, ActorSystem, Props}
import akka.persistence.PersistentActor
import akka.persistence.journal.WriteEventAdapter
import akka.persistence.journal.leveldb.Tagged
import akka.persistence.query.journal.leveldb.LeveldbReadJournal
import akka.persistence.query.scaladsl.ReadJournal
import akka.persistence.query.{EventsByTag, PersistenceQuery}
import akka.stream.ActorMaterializer
@Fristi
Fristi / ApplicativeFuture.scala
Last active August 29, 2015 14:01
scalaz: Applicative for Future[T]. Does not sequentially await, but executes futures concurrently
import java.util.concurrent.{Executors, TimeUnit}
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, ExecutionContext, Future}
import scalaz.Applicative
import scalaz.syntax.applicative._
object Main extends App {
implicit def applicativeFuture(implicit executionContext:ExecutionContext) = new Applicative[Future] {
override def point[A](a: => A): Future[A] = Future.successful(a)
@Fristi
Fristi / .zshrc
Created September 10, 2015 05:44
Zshrc file
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="philips"
# Uncomment the following line to use case-sensitive completion.
@Fristi
Fristi / gist:2384518
Created April 14, 2012 13:37
Autocomplete jQuery + RxJS + CoffeeScript
@searchBox.keyupAsObservable()
.select((ev) -> $(ev.target).val())
.where((text) -> text.length > 2)
.throttle(500)
.distinctUntilChanged()
.select(@searchItems)
.switchLatest()
.subscribe(@handleItemSearchAutoCompleteSuccess)
@Fristi
Fristi / AutofacScopedHubActivator.cs
Created October 25, 2012 19:16
Hub activation with metadata and decoupling of the hub deactivation
public class AutofacScopedHubActivator : IHubActivator
{
private readonly ILifetimeScope rootScope;
public AutofacScopedHubActivator(ILifetimeScope rootScope)
{
this.rootScope = rootScope;
}
public HubActivationResult Create(HubDescriptor descriptor)
@Fristi
Fristi / Elerea.scala
Created November 14, 2015 10:13
Transliteration of Elerea FRP to Scala
import scala.ref.WeakReference
import scala.util.Random
import scalaz.effect.{IO, IORef}
import scalaz._
import scalaz.Scalaz._
import scalaz.std.stream._
object Program extends App {
@Fristi
Fristi / Chunker.scala
Created November 18, 2015 12:22
Chunked responses in Spray
import java.io.{BufferedInputStream, InputStream}
import akka.actor._
import spray.can.Http
import spray.http.HttpEntity.Empty
import spray.http.MediaTypes._
import spray.http._
import spray.routing.{HttpService, RequestContext}
import scala.concurrent.duration._
@Fristi
Fristi / SystemTime.cs
Last active December 14, 2015 10:59
Time windows in C# - A time window is a constrained period of time.
public class SystemTime
{
private static Func<DateTime> now = () => DateTime.Now;
public static Func<DateTime> Now
{
get { return now; }
set { now = value; }
}
}
module Utils =
let private rng = new Random()
let rec PickRandomPair<'TKey when 'TKey : equality> (pool:('TKey * int) list) =
let decreasePair(needle:'TKey, pool:('TKey * int) list) =
let decrease (key:'TKey, value:int) = if key = needle then (key, value - 1) else (key, value)
pool |> Seq.fold (fun acc r -> (decrease(r) :: acc)) []
module BaseTest =
[<TestFixture>]
[<AbstractClass>]
type public AggregateTest<'TState, 'TCommand, 'TEvent>() =
abstract member For: Aggregate<'TState, 'TCommand, 'TEvent>
abstract member Given: 'TEvent list
abstract member When: 'TCommand
abstract member Then: ('TState -> unit)