Skip to content

Instantly share code, notes, and snippets.

@sgoguen
sgoguen / triggered-task.cs
Last active February 16, 2017 16:52
A lightweight data structure for creating tasks that are completed elsewhere
// A poor reimplementation of IAsyncResult. It was a fun exercise though
public interface ITaskTrigger<T> {
void SetComplete(T value);
void ThrowException(Exception ex);
}
public class AsyncRequest<T, U> : ITaskTrigger<U> {
public readonly T Request;
public readonly ITaskTrigger<U> Trigger;
@sgoguen
sgoguen / memoize-fib.fsx
Last active February 16, 2017 20:02
Memoize ala Ivanek
// Today's example is courtesy of @jindraivanek
// https://gist.github.com/jindraivanek/5ff029577d2b544b2cd739d994750a18#file-memoizerec-fsx
// As you remember, there was a warning on line 14
// For a good explaination, see @tomaspetricek's Stack Overflow post.
// http://stackoverflow.com/questions/8636630/recursive-objects-in-f
@sgoguen
sgoguen / merkle-tree.fsx
Created February 16, 2017 21:30
Merkle Trees
open System.IO
open System.Collections.Concurrent
// A Merkle tree for a file system might look like this
// PASTE!!
let isDirectory(path:string) =
let attr = File.GetAttributes(path)
attr.HasFlag(FileAttributes.Directory)
public class Nav {
public static HelperResult NavAndPrint(object obj, string path) {
var printer = Nav.GetPrinter().SetValue(obj);
return printer.NavigateTo(path).TryToShowObject();
}
private static UiContext GetPrinter() {
return new UiContext(
displayRules: new Func<UiContext, Maybe<HelperResult>>[] {
@sgoguen
sgoguen / _article.md
Last active June 23, 2017 01:24
Multiple File Test

A Better Way to Compose Web Applications

I don't care for the MVC pattern most of us use for building web applications. What I like about frameworks like ASP.MVC is how is automatically maps URLs to an idiomatic C# method.

public class PersonController : Controller {
  public ActionResult Get(int id) {
     return View(new { Id = id, Name = "Bob" });
 }
@import url( https://fonts.googleapis.com/css?family=Raleway:200,600 );
html, body { height: 100%; }
.wrapper {
position: absolute;
width: 727px !important;
left:-233px !important;
top: 0;
right: 0;
@sgoguen
sgoguen / _about.md
Last active November 2, 2022 13:23
A Small Elm-like DSL in F#

Making Toys with F# - A Small Elm-like DSL in F#

A Small Elm-Like DSL in F#

I've been working on a talk about the virtues of building toy examples for the purpose of communicating ideas with simple interactive examples.

The toys I talk about in my presentation are based my interest in tools that allow programmers to quickly build web applications that allow them to explore their architecture. So to kickstart this series off, I want to introduce a simple

@sgoguen
sgoguen / index.html
Created September 29, 2017 21:55
Observable Webserver
<!DOCTYPE html>
<html>
<head>
<title>Object Watcher</title>
</head>
<body>
<div id="output"></div>
<!--Script references. -->
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-2.0.3.min.js"></script>
@sgoguen
sgoguen / enumInvalidInstances.fs
Created October 17, 2017 17:52
Using FsCheck to Enumerate Invalid Instances
// In this example, we're using FsCheck in an unorthodox way.
// Typically you tell FsCheck to look for something that violates
// your rule. Here, we're reappropriating FsCheck's fuzz testing
// capabilities to enumerate everything that has been deemed
// "valid" to see if it's actually valid to help us figure out the rules.
type Money = decimal
type CouponType = FreeMail | FreeSide
type PaymentOption =
@sgoguen
sgoguen / livehub.cs
Created October 25, 2017 22:53
Livehub
void Main() {
Util.CurrentQueryPath.Dump();
string url = "http://localhost:8080";
using (WebApp.Start(url, Configuration)) {
//Task.Run(DoTask);
Console.ReadLine();
}