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
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 / 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
@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
CREATE DATABASE [OrderedInsert]
GO
ALTER DATABASE [OrderedInsert] SET ALLOW_SNAPSHOT_ISOLATION ON
GO
USE [OrderedInsert]
GO
CREATE TABLE [dbo].[Test](
@afifmohammed
afifmohammed / SimpleFlakeTest.cs
Last active August 29, 2015 14:22
A test for how far we can go before SimpleFlake returns a duplicate
void Main()
{
var d = new Dictionary<BigInteger, BigInteger>();
var t = DateTime.Now;
int? howfar = null;
var attempts = 10000000;
for (int x = 0; x < 1000; x++)
{
d.Clear();
@afifmohammed
afifmohammed / autofacdecoration.cs
Created May 4, 2015 03:24
autofac docoration by hand
void Main()
{
var c = new ContainerBuilder();
c.RegisterInLifetimeScope<Handler, ConcreteReflectionActivatorData>(x => x.RegisterType<Handler>());
var scope = c.Build();
scope.Resolve<IHandler>().Dump();
}
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;
@afifmohammed
afifmohammed / mastermasteridentitytest.cs
Last active August 29, 2015 13:56
Testing sequential generation of ids when storing documents with master master setup in parallel execution
void Main()
{
var orders = false;
if(orders)
ParallelExecute(db => {
using(var session = db.OpenSession())
{
var list = new [] {new Order(), new Order()};
foreach (var order in list)
@afifmohammed
afifmohammed / stacktest.cs
Last active August 29, 2015 13:56
Test that proves using a Stack<T> as a property on a document does not work with RavenDB
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Raven.Imports.Newtonsoft.Json;
using Raven.Tests.Helpers;
using Xunit;
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