Skip to content

Instantly share code, notes, and snippets.

@ToJans
ToJans / Paycento.API.Tasks.cs
Created June 14, 2012 12:10
Testing difference between sync and async
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Paycento.API.Tasks
{
public static class Wait
{
#!/usr/bin/env escript
%%! -pa ebin
main(_) ->
{ok, [T]} = file:consult("ebin/mimetypes.app"),
{application, mimetypes, PL} = T,
DynMods = [mimetypes:dmodule(),mimetypes:mmodule()],
BaseModules = proplists:get_value(modules, PL) -- DynMods,
Modules = DynMods ++ BaseModules,
@ToJans
ToJans / infrastructure.erl
Created October 1, 2012 11:55
Attempt for CQRS in erlang
%% INFRASTRUCTURE CRAP
load(Events) ->
load(#state{},Events).
load(State,[]) ->
State;
load(State,[Event|RemainingEvents]) ->
NewState = change(State,Event),
load(NewState,RemainingEvents).
@ToJans
ToJans / console.erl
Created October 2, 2012 10:14
Attempt for CQRS in erlang
Erlang R13B04 (erts-5.7.5) [smp:8:8] [rq:8] [async-threads:0]
Eshell V5.7.5 (abort with ^G)
1> cd('/blah/erlang/CQRS').
C:/blah/erlang/CQRS
ok
2> ls().
item.erl item.hrl
ok
3> c(item).
@ToJans
ToJans / ConsoleSpinner.cs
Created October 10, 2012 13:48 — forked from robashton/ConsoleSpinner.cs
ConsoleSpinner
using System;
namespace Spinner
{
class Program
{
static void Main(string[] args)
{
Console.Write("Working... ");
int spinIndex = 0;
@ToJans
ToJans / ring.erl
Created October 23, 2012 17:46 — forked from stiiifff/ring.erl
Erlang process ring (Erlang programming, Chapter 4, Ex 4.2)
-module (ring).
-export ([start/3, first_proc/3, first_loop/4, proc_start/3, proc_loop/2]).
start(MsgCount, ProcCount, Msg) ->
spawn(ring, first_proc, [MsgCount, ProcCount, Msg]).
first_proc(MsgCount, ProcCount, Msg) ->
io:format("First process ~w created, setting up the rest of the ring ...~n", [self()]),
NextPid = spawn(ring, proc_start, [self(), self(), ProcCount-1]),
LastPid = receive
@ToJans
ToJans / SimpleMessaging.MessageBox.cs
Created November 15, 2012 15:53
Too much protocol - I need better specs - feel free to fork & adjust
using System;
namespace SimpleMessaging
{
public class MessageBox
{
Func<dynamic,bool?> Handle;
public MessageBox()
{
@ToJans
ToJans / AutoBDD.Specs.cs
Created November 23, 2012 12:28
If I could get this to work, this would be awesome IMO
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
namespace AutoBDD.Specs
{
[TestClass]
public class Parse_some_specs
{
AutoBDD.Runner SUT = new AutoBDD.Runner();
@ToJans
ToJans / guard.cs
Created December 10, 2012 11:15
Ugly or not
//Add a comment
using System;
namespace Example
{
public static class Guard
{
public static void Against(bool assertion, string message)
{
if (assertion)
@ToJans
ToJans / curry.cs
Last active December 10, 2015 01:19
Currying in C#... yes or no ?
dynamic fizzbuzz = new Curry()
.On<int>()
.When(x => x % 15 == 0).Do(x => "fizzbuzz")
.When(x => x % 3 == 0).Do(x => "fizz")
.When(x => x % 5 == 0).Do(x => "buzz")
.Do(x=>x)
.On<IEnumerable<int>>()
.Do((s, r) => from val in r select s(r))
.On<string>()
.When("fizzbuzz").Do(x => "Aha, you found the easter egg!")