Skip to content

Instantly share code, notes, and snippets.

@t0yv0
t0yv0 / gist:192353
Created September 23, 2009 22:39
another take on F# monads
module Monad =
type M<'T,'B when 'B :> Sig<'B>> =
interface end
and Sig<'B when 'B :> Sig<'B>> =
abstract member Return<'X> : 'X -> M<'X,'B>
abstract member Bind<'X,'Y> :
M<'X,'B> -> ('X -> M<'Y,'B>) -> M<'Y,'B>
#if INTERACTIVE
#r "Microsoft.CSharp.dll"
#endif
open System
open System.Dynamic
open System.Linq.Expressions
open System.Reflection
open System.Runtime.CompilerServices
open Microsoft.CSharp.RuntimeBinder
load_assembly 'System.Core'
load_assembly 'System.CoreEx, Version=1.0.2521.104, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
load_assembly 'System.Reactive, Version=1.0.2521.104, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
using_clr_extensions System
using_clr_extensions System::Linq
include System
include System::Linq
@isaacs
isaacs / node-and-npm-in-30-seconds.sh
Last active March 8, 2024 02:11
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
#!/usr/bin/ruby
require 'rubygems'
require 'net/http'
require 'yaml'
require 'cgi'
require 'bossman'
include BOSSMan
require 'igraph'
open System
type Cont<'T> =
abstract Call<'R> : ('T -> 'R) * (exn -> 'R) -> 'R
let protect f x cont econt =
let res = try Choice1Of2 (f x) with err -> Choice2Of2 err
match res with
| Choice1Of2 v -> cont v
| Choice2Of2 v -> econt v
@creationix
creationix / chatServer.js
Created November 19, 2010 20:47
A simple TCP based chat server written in node.js
// Load the TCP Library
net = require('net');
// Keep track of the chat clients
var clients = [];
// Start a TCP Server
net.createServer(function (socket) {
// Identify this client
@panesofglass
panesofglass / IApplication.cs
Created November 30, 2010 16:59
.NET Web Abstractions
// Func<IRequest, IResponse>
public interface IApplication {
IAsyncResult BeginInvoke(IRequest request, AsyncCallback callback, object state);
IResponse EndInvoke(IAsyncResult result);
}
@jasonmead
jasonmead / gist:733877
Created December 8, 2010 20:37
OWIN GetBody Handler
namespace Owin
{
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
public interface IResponseHandler
{
Type TypeToHandle { get; }
public Result App1(IDictionary<string, object> env) {
var request = new Request(env);
request.Logger.Info("Calling " + request.ScriptName);
return new Result(
200,
new Dictionary<string, object>{{"Content-Type","text/plain"}},
new[]{"<p>You are looking at", request.ScriptName, "</p>"});
}