Skip to content

Instantly share code, notes, and snippets.

View ademar's full-sized avatar
👻
Building stuff

Ademar Gonzalez ademar

👻
Building stuff
View GitHub Profile
@jcdickinson
jcdickinson / IAmDisposable.cs
Created December 3, 2012 18:22
Disposers done right.
class IAmDisposable : IDisposable
{
private int _isDisposed;
private SomeDisposableThing _disposable1;
private SomeDisposableBar _disposable2;
private SomeDisposableBaz _disposable3;
// Only if you **need** it. You don't though, use SafeHandle.
//~IAmDisposable()
//{
@tonymorris
tonymorris / TreeComonad.hs
Created October 17, 2012 23:12
Tree Comonad
class Functor f => Extend f where
-- CoSelectMany
extend ::
(f a -> b)
-> f a
-> f b
-- CoFlatten?
duplicate ::
f a
@sebfisch
sebfisch / gist:2235780
Created March 29, 2012 10:47
Laymans explanation of delimited continuations with examples of using them for exception handling and nondeterministic programming.

Delimited Continuations

Delimited continuations manipulate the control flow of programs. Similar to control structures like conditionals or loops they allow to deviate from a sequential flow of control.

We use exception handling as another example for control flow manipulation and later show how to implement it using delimited continuations. Finally, we show that nondeterminism can also be expressed using delimited continuations.

Exception Handling

@ry
ry / fib.js
Created March 12, 2012 00:17
a proper fibonacci server in node. it will light up all your cores.
var http = require('http')
var fork = require('child_process').fork;
function fib(n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}
@ademar
ademar / gist:1016874
Created June 9, 2011 14:49
Combinators for logic programming
// Based on the article 'Combinators for logic programming' by Michael Spivey and Silvija Seres.
let rec inf_seq n = seq { yield n; yield! inf_seq (n+1) }
let rec lzw f l1 l2 =
LazyList.delayed ( fun () ->
match l1,l2 with
|LazyList.Nil, _ -> l2
|_, LazyList.Nil -> l1
|LazyList.Cons(p1,tail1),LazyList.Cons(p2,tail2)
@ademar
ademar / gist:898038
Created April 1, 2011 12:00
One-Way File Synchronization
// Learn more about F# at http://fsharp.net
open Microsoft.FSharp.Control
open System.Collections.Generic
open System.Threading
open System.IO
type RequestGate(n:int) =
let semaphore = new Semaphore(initialCount=n,maximumCount=n);
member x.AcquireAsync(?timeout) =
async {
In this gist we will first show that we can beat the arc challenge
(http://www.paulgraham.com/arcchallenge.html), and then build the library that
shows how we did it. This gist is Literate Haskell and is of course executable. The packages needed are happstack-server and applicative-extras, installable using cabal.
Let's start with some imports (for now, you can ignore these)
> {-# LANGUAGE GADTs, TypeSynonymInstances #-}
> module ArcChallenge where
>
> import Control.Applicative