Skip to content

Instantly share code, notes, and snippets.

View Horusiath's full-sized avatar

Bartosz Sypytkowski Horusiath

View GitHub Profile
@Horusiath
Horusiath / gist:36ab3ef3f1989f8b46ce
Created July 6, 2014 17:24
F#/C# OO syntax comparison
// class inheritance - C#
public abstract class Ancestor {}
public class Descendant: Ancestor, IDisposable
{
public void Dispose() {}
public virtual void MyVirt() {}
}
// class inheritance - F#
@Horusiath
Horusiath / gist:bd00d33a130e4add2491
Created April 3, 2015 15:23
At least once delivery snapshoting desync
import akka.persistence.AtLeastOnceDelivery.AtLeastOnceDeliverySnapshot
import akka.persistence.{SnapshotOffer, PersistentActor, AtLeastOnceDelivery}
import akka.actor.{Props, ActorSystem, ActorPath, Actor}
case class Message(data: String)
case class Confirmable(deliveryId: Long, data: String)
case class Confirmation(deliveryId: Long)
case class Snap(snapshot: AtLeastOnceDeliverySnapshot)
class ExampleAtLeastOnceDeliveryActor(val deliveryPath: ActorPath) extends PersistentActor with AtLeastOnceDelivery {
@Horusiath
Horusiath / gist:2f6deda8daae44f37c16
Created May 18, 2015 17:07
Akka.NET F# Actor with state
type State = { X: int; Y: int }
let system = ConfigurationFactory.Default() |> System.create "FSharpActors"
let aref =
spawn system "actor"
<| fun mailbox ->
let rec loop state =
actor {
public class Guest : ReceiveActor
{
public Guest()
{
Receive<Badge>(badge =>
{
// ... do something with received badge
});
@Horusiath
Horusiath / Program.fs
Created July 13, 2015 08:30
Akkling perisistence example
open System
open System.Threading
open Akkling
open Akkling.Persistence
let system = System.create "persistent-system" (Configuration.defaultConfig())
type Event =
| Added of int
| Removed of int
@Horusiath
Horusiath / client
Created August 20, 2015 12:23
Akka.Fsharp remote deployment
open Akka.FSharp
open Akka.Actor
// return Deploy instance able to operate in remote scope
let deployRemotely address = Deploy(RemoteScope (Address.Parse address))
let spawnRemote systemOrContext remoteSystemAddress actorName expr =
spawne systemOrContext actorName expr [SpawnOption.Deploy (deployRemotely remoteSystemAddress)]
let config =
Configuration.parse
@"akka {
@Horusiath
Horusiath / example.fs
Last active May 30, 2022 13:03
Akka.NET F# API PreStart and PostStop handling
let aref =
spawn system "actor"
<| fun mailbox ->
printf "pre-start" // this section works like pre-start
mailbox.Defer (fun () -> printf "post-stop") // this registers a function to be called on PostStop
let rec loop () =
actor {
let! msg = mailbox.Receive ()
// do some work
return! loop ()
@Horusiath
Horusiath / Tasks.cs
Last active September 14, 2015 19:54
Set of extensions (for missing methods) necessary for running Akka.NET < .NET 4.5
//-----------------------------------------------------------------------
// <copyright file="TaskExtensions.cs" company="Akka.NET Project">
// Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
// Copyright (C) 2013-2015 Akka.NET project <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Net.Mime;
Starting Target: GenerateReferenceDocs (==> RunTests, GenerateHelp)
FSharp.Formatting Information: 0 : FSharp.Formatting Logging setup!
Yaaf.FSharp.Scriping Information: 0 : Yaaf.FSharp.Scripting Logging setup!
Copying file: D:\projects\dev\Akkling\docs\output\img\logo-template.pdn
Copying file: D:\projects\dev\Akkling\docs\output\img\logo.png
Copying styles and scripts: D:\projects\dev\Akkling\docs\output\content\style.css
Copying styles and scripts: D:\projects\dev\Akkling\docs\output\content\style_light.css
Copying styles and scripts: D:\projects\dev\Akkling\docs\output\content\tips.js
Copying styles and scripts: D:\projects\dev\Akkling\docs\output\content\img\github-blue.png
Copying styles and scripts: D:\projects\dev\Akkling\docs\output\content\img\github.png
@Horusiath
Horusiath / gist:484f37f9ae92a220fb7b
Last active December 2, 2015 22:07
Get list of project contributors by added/removed lines and display summary
# output line format: <added+removed> <added> <removed> <author>
git log <past_last_release_tag_here>..HEAD --oneline --numstat --pretty=format:%an --no-merges --abbrev-commit | gawk 'author == "" { author = $0; next } /^$/ { author = ""; next} {added[author] += $1; removed[author] +=$2 } END { for(author in added) { printf "%s\t%s\t%s\t%s\n", added[author]+removed[author], added[author], removed[author], author } }' | sort -n -k1 -r