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
@ToJans
ToJans / Nat.cs
Last active August 29, 2015 14:12
Natural numbers and vectors in C# , the Idris way
// Data Nat = Z | S Nat
//
// plus : Nat -> Nat -> Nat
// plus Z y = y
// plus (S k) y = S (plus k y)
abstract class Nat {
}
class Zero : Nat {
void Main()
{
var d = new Dictionary<BigInteger, BigInteger>();
var t = DateTime.Now;
var howfar = 0;
var r = 0;
for (int x = 0; x < 100000; x++)
{
for (int i = 0; i < 10000000; i++)
{
@kijanawoodard
kijanawoodard / LastInWinsReplicationConflictResolver.cs
Created April 4, 2013 01:54
Last One Wins Raven Resolver - Updated for 2.x
using System;
using System.Linq;
using Raven.Abstractions.Data;
using Raven.Abstractions.Logging;
using Raven.Bundles.Replication.Plugins;
using Raven.Json.Linq;
namespace RavenConflictResolverPlugin
{
public class LastInWinsReplicationConflictResolver
@PaulStovell
PaulStovell / Tasks.cs
Last active January 27, 2016 17:48
An example using RavenDB's changes API to implement a queue of tasks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using Raven.Abstractions.Data;
using Raven.Client.Embedded;
using Raven.Client.Indexes;
namespace OctoQueues
@lafar6502
lafar6502 / gist:8105682
Last active January 26, 2021 06:10
some messy code of a synchronization gateway that allows only a single thread of execution for all passed callbacks. It allows new callbacks to be enqueued while they are being executed by another thread. This implementation is almost certainly broken because I didn't care if it compiles at all and if all closure stuff is done correctly, but hop…
public class ConcurrentGateway
{
private ConcurrentQueue<Action> _workQueue = new ConcurrentQueue<Action>();
private int _writeLock = 0;
[ThreadStatic]
private static AutoResetEvent _waitEvent = new AutoResetEvent(false);
protected static AutoResetEvent GetThreadWaitEvent()
{
@louthy
louthy / CSharp Free Monad.cs
Last active April 2, 2022 16:20
C# Free Monad
//
// 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;
@tonymorris
tonymorris / PureIO.cs
Last active April 2, 2022 16:23
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
@dadhi
dadhi / FreeIOMonad.cs
Last active October 9, 2022 03:05
Example of Free IO monad in pure C# with separated re-usable monad implementation
/*
Modified from the original https://gist.github.com/louthy/524fbe8965d3a2aae1b576cdd8e971e4
- removed dependency on [language-ext](https://github.com/louthy/language-ext)
- separated monadic boilerplate, so you may concentrate on describing the operations and interpretation of the program
- removed `IO<A>.Faulted` to simplify the examples. It can be added back in straightforward manner.
Useful links:
- [John DeGoes: Beyond Free Monads - λC Winter Retreat 2017](https://www.youtube.com/watch?v=A-lmrvsUi2Y)
- [Free and tagless compared - how not to commit to a monad too early](https://softwaremill.com/free-tagless-compared-how-not-to-commit-to-monad-too-early)
@rodneyrehm
rodneyrehm / gist:40e7946c0cff68a31cea
Last active November 7, 2022 09:11
Diagrams for Documentation

some tools for diagrams in software documentation

Diagrams For Documentation

Obvious Choices

ASCII