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
@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 {
@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
@migueldeicaza
migueldeicaza / gist:7594491
Last active December 29, 2015 01:39
For David Fowler
These instructions will get you Mono compiled from source.
Requirements:
Xcode installed
Command Line Tools installed (part of Xcode)
Then, create a text file with the contents of everything after "=====", save it as "build.sh" in your home directory
Open a terminal window, and type this in your shell:
@mausch
mausch / gist:7706117
Last active December 29, 2015 17:39
Draft/pseudocode for HTML type provider
// https://twitter.com/mausch/status/406420573518970880
// compiles to ModelLayout -> XElement where ModelLayout = { title: string; script: XAttribute; bodyAttrs: XAttribute list; body: XElement }
type Layout = HTML<"""
<html>
<head>
<title><x:text id="title"/></title>
<script x:attr="script"></script>
</head>
<body x:attrs="bodyAttrs">
@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()
//{
@mrange
mrange / json_transform.md
Last active January 23, 2017 06:53
Monadic JSON Transformers in F#
@dooglus
dooglus / bootstrap.cpp
Created February 21, 2013 06:44
create bootstrap.dat from bitcoin-qt's blk0000?.dat files
// g++ UniversalTimer.o BinaryData.o FileDataPtr.o BtcUtils.o BlockObj.o BlockUtils.o libcryptopp.a -o bootstrap.out -Icryptopp -DUSE_CRYPTOPP -D__STDC_LIMIT_MACROS -lpthread bootstrap.cpp
#include "BlockUtils.h"
int main(void)
{
string btcdir("/home/chris/.bitcoin");
string bootstrap(btcdir + "/" + "bootstrap.dat");
BlockDataManager_FileRefs::GetInstance().SelectNetwork("Main");
BlockDataManager_FileRefs & bdm = BlockDataManager_FileRefs::GetInstance();
@eulerfx
eulerfx / pfp.fs
Created November 9, 2016 18:16
Probabilistic functional programming F#
/// A probability is a number between 0 and 1 inclusive.
type Prob = float
/// A distribution is a sequence of outcome-probability pairs such that the
/// probabilities sum to 1.
type Dist<'a> = D of seq<'a * Prob>
/// A spread takes a sequence of elements and assigns probabilities.
type Spread<'a> = 'a list -> Dist<'a>
@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);
}
}
@ninjarobot
ninjarobot / RoadToFSharp.md
Last active June 2, 2020 09:21
How I ended up as an F# developer.

My Road to F#

I came from the OOP world, most of my professional work was in Java or C#. The languages were similar, and I could use them interchangably as I built software in each of them for several years. With enough experience in both, I was comfortable with either ecosystem and could generally be productive in either. Sometimes the job required one or the other. Sometimes the target OS constrained my choice to Java, which frustrated me a bit, because the languages were so similar, why would the runtime try to restrict a choice? I enjoyed writing server applications on Unix in college, and Linux afterwards, because the machines were so easy to configure compared to Windows machines that took a few hours to install and configure to get my software running. On Linux, I could type a handful of commands into a newly installed system and be up and running.

Sometime around 2005, Java had stagnated while C# was flourishing. They both released generics, but then C# came out with new features like