Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / gist:1058974
Created July 1, 2011 17:09
EF CodeFirst - Generating a Database in F#
// This will generate a database, but EF will not materialize the objects
// because our types do not have default parameterless constructors
namespace DataModel
open System
open System.ComponentModel.DataAnnotations
open System.Data.Entity
type User = { mutable ID : int; mutable Name: string; mutable DB: DateTime; mutable Tasks: Task[];
mutable Projects: Project[] }
@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();
}

Keybase proof

I hereby claim:

  • I am sgoguen on github.
  • I am sgoguen (https://keybase.io/sgoguen) on keybase.
  • I have a public key ASB7lHbtpeTVKV_POAjX-YXpSjuk3i7VMIMeAKJ0cFCrOgo

To claim this, I am signing this object: