Skip to content

Instantly share code, notes, and snippets.

View Porges's full-sized avatar
🏠
Working from home

George Pollard Porges

🏠
Working from home
View GitHub Profile
@Porges
Porges / life.fs
Last active August 29, 2015 14:09
module Life
open System
// A cell is either alive or dead
type Cell = Dead | Alive
// A board is an array of arrays of cells
type Board = Cell[][]
@Porges
Porges / smuggling.cs
Last active August 29, 2015 14:10
smuggling data in C#
using System;
using System.CodeDom;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Threading;
// The situation:
@Porges
Porges / implicitmodules.hs
Last active August 29, 2015 14:11
what am untouchables?
{-# LANGUAGE TypeFamilies, ImplicitParams, OverloadedStrings, ConstraintKinds, ExistentialQuantification, RankNTypes, TypeOperators #-}
import GHC.Prim (Constraint)
import Data.String (IsString)
import qualified Data.Text as T
type family XString m
type family XDouble m
@Porges
Porges / fact.cs
Last active August 29, 2015 14:13
pinvoking rust
using System;
using System.Runtime.InteropServices;
public static class Program
{
[DllImport("fact.dll")]
private static extern ulong fact(ulong x);
public static void Main()
{
open System
open System.Runtime.InteropServices
open Microsoft.Win32.SafeHandles
// Wrapping the fact.rs module...
[<DllImport("fact.dll")>]
extern uint64 fact(uint64)
[<DllImport("point.dll")>]
extern void free_point(IntPtr)
@Porges
Porges / passert.fs
Created January 22, 2015 04:08
PowerAssert for F#
open System
open System.Linq.Expressions
open Microsoft.FSharp.Quotations
open FSharp.Quotations.Evaluator
let toLinq (expr : Expr<bool>) =
let linq = expr.ToLinqExpressionUntyped()
let call = linq :?> Expression<Func<unit, bool>>
Expression.Lambda(call.Body) :?> Expression<Func<bool>>
public static void SafeDispose<T>(ref T disposable)
where T : class, IDisposable
{
Interlocked.Exchange(ref disposable, null)?.Dispose();
}
@Porges
Porges / owned.cs
Created January 29, 2015 21:48
disposables where ownership can be transferred
public struct Owned<T> : IDisposable
where T : class, IDisposable
{
private T _value;
public Owned(T value)
{
_value = value;
}
@Porges
Porges / echo-server.fs
Created February 5, 2015 21:02
A trivial HTTP server that echoes a fixed string
module Resourceful
open System
open System.Net.Sockets
open System.Text
open System.Threading
open System.Threading.Tasks
let response = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 5\r\n\r\nhello"
let responseBytes = Encoding.ASCII.GetBytes(response)

Keybase proof

I hereby claim:

  • I am Porges on github.
  • I am porges (https://keybase.io/porges) on keybase.
  • I have a public key whose fingerprint is 93E2 9078 0396 A546 0EE4 B579 54D0 F8E2 3B5B 567D

To claim this, I am signing this object: