Skip to content

Instantly share code, notes, and snippets.

View AlexeyRaga's full-sized avatar

Alexey Raga AlexeyRaga

  • Arbor Networks
  • Sydney, Australia
View GitHub Profile
let next = function
| d :: ds ->
let dss = Seq.append ds (Directory.GetDirectories d) |> List.ofSeq
let fss = Directory.GetFiles d
Some (fss, dss)
| [] -> None
Seq.unfold (next) ["/tmp"] |> Seq.concat
scala> trait Assoc[K] { type V ; val value: V }
defined trait Assoc
scala> def mkAssoc[V0](k: String, v: V0): Assoc[k.type] { type V = V0 } =
| new Assoc[k.type] { type V = V0 ; val value = v }
mkAssoc: [V0](k: String, v: V0)Assoc[k.type]{type V = V0}
scala> implicit def nameAssoc = mkAssoc("Name", "Mary")
nameAssoc: Assoc[String("Name")]{type V = String}
@AlexeyRaga
AlexeyRaga / SemiIdeomaticParsers.cs
Last active August 29, 2015 14:01
Semi-Ideomatic Parsers in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace SemiIdeomaticParsers
{
public delegate Tuple<T, string> Parser<T>(string value);

Better Git log

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

create an alias git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

git lg

git lg -p

Tuning Storm+Trident

Tuning a dataflow system is easy:

The First Rule of Dataflow Tuning:
* Ensure each stage is always ready to accept records, and
* Deliver each processed record promptly to its destination
@AlexeyRaga
AlexeyRaga / 1 - Composition Examples.cs
Last active August 29, 2015 14:02
C# without async/await
public static void MappingExample()
{
var averages = Html
.Download("http://github.com")
.Select(html => {
var links = Html.ParseLinks(html);
var averageLength = links.Average(x => x.Length);
return String.Format("{0} links found, average length is {1}", links.Count, averageLength);
});
@AlexeyRaga
AlexeyRaga / 1-Pipelines-FSharp-example.fs
Last active August 29, 2015 14:02
Pipelines and fluent interfaces
//already defined in F# base library, but I wanted to show how simple it is
let (|>) a f = f a
let latestRequest =
user
|> login
|> clickMenu "Forms"
|> waitPageLoad
|> openFilter ["Communication"; "Request"]
|> results
namespace Topshelf
[<AutoOpen>]
module Topshelf =
open System
open Topshelf.HostConfigurators
open Topshelf.Runtime
let configureTopShelf f =
{-# LANGUAGE TypeFamilies #-}
import Data.Function (on)
import Control.Applicative
data EventData e = EventData {
eventId :: Int,
body :: Event e
}