Skip to content

Instantly share code, notes, and snippets.

View afifmohammed's full-sized avatar
💭
(+2)(-3)

Afif Mohammed afifmohammed

💭
(+2)(-3)
View GitHub Profile
namespace Sagas
{
using System;
using System.Collections.Generic;
class Program
{
static ActivityHost[] processes;
public class ConcurrentGateway
{
private ConcurrentQueue<Action> _workQueue = new ConcurrentQueue<Action>();
private int _writeLock = 0;
private static AutoResetEvent _waitEvent = new AutoResetEvent(false);
protected static AutoResetEvent GetThreadWaitEvent()
{
//returns same event for all threads ,but we could easily provide a
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Collections.Concurrent;
using System.Reflection.Emit;
using System.Threading;
CREATE DATABASE [OrderedInsert]
GO
ALTER DATABASE [OrderedInsert] SET ALLOW_SNAPSHOT_ISOLATION ON
GO
USE [OrderedInsert]
GO
CREATE TABLE [dbo].[Test](
@afifmohammed
afifmohammed / BuildAllProjectsFromACleanState.ps1
Created November 5, 2015 02:42 — forked from RhysC/BuildAllProjectsFromACleanState.ps1
Make sure that each project can be built from a clean state (ie no rouge dlls from previous builds)
$ErrorActionPreference = "Stop"
function cleanBin {
param ([string]$path)
write-host "Cleaning bin from: $path"
get-childitem $path -include bin -recurse | remove-item -force -confirm:$false -recurse
write-host "Cleaning obj from: $path"
get-childitem $path -include obj -recurse | remove-item -force -confirm:$false -recurse
@afifmohammed
afifmohammed / PureIO.cs
Created April 20, 2016 06:32 — forked from tonymorris/PureIO.cs
A demonstration of pure-functional I/O using the free monad in C#
using System;
namespace PureIO {
/*
C# does not have proper sum types. They must be emulated.
This data type is one of 4 possible values:
- WriteOut, being a pair of a string and A
- WriteErr, being a pair of a string and A
- readLine, being a function from string to A
using System;
namespace Funcs {
public static class Funcs {
public static Func<A, C> Select<A, B, C>(this Func<A, B> f, Func<B, C> g) {
return a => g(f(a));
}
public static Func<C, B> SelectMany<A, B, C>(this Func<C, A> f, Func<A, Func<C, B>> g) {
return a => g(f(a))(a);
@afifmohammed
afifmohammed / ReaderMonad.cs
Last active January 24, 2017 21:50 — forked from vmarquez/ReaderMonad.cs
This is an example of using the Reader Monad for Dependency Injection using LINQ in C#. I learned about this from Tony Morris and Rúnar Bjarnason's video here: http://www.youtube.com/watch?v=ECPGTUa1WAI To figure out the (slightly weird) SelectMany peculiarities I found http://mikehadlow.blogspot.com/2011/01/monads-in-c-4-linq-loves-monads.html
public static class ReaderMonadExt
{
public static Func<T, C> SelectMany<T, A, B, C>(this Func<T, A> t_a, Func<A, Func<T, B>> a_t_b, Func<A, B, C> ab_c)
{
return t =>
{
var a = t_a(t);
return ab_c(a, a_t_b(a)(t));
};
}
@afifmohammed
afifmohammed / AsyncMonad.cs
Created February 13, 2017 01:38 — forked from hodzanassredin/AsyncMonad.cs
tutorial2 finished monad transformer
using System;
using System.Threading.Tasks;
namespace GenericMonad
{
public class Async
{
Async ()
{
//
// See https://github.com/louthy/language-ext
//
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using LanguageExt;
using static LanguageExt.Prelude;