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 / gist:4679582
Created January 31, 2013 03:02
a pseudo-pattern for 'external' interfaces
/* Given: */
// An interface
interface ICountable
{
int Count { get; }
}
// A class that 'should' implement the interface
class Foo
{
@Porges
Porges / gist:5384727
Created April 14, 2013 23:41
example of delta that works
using System;
namespace DeltaExample
{
class Program
{
static void Main(string[] args)
{
Δ();
}
class Program {
static bool M(out int x)
{
x = 123;
return true;
}
static int N(EvilBool d)
{
@Porges
Porges / gist:5972846
Last active December 19, 2015 14:59
I call it... stack-continuation programming!
using System;
static class Program
{
internal delegate D D(D d);
static void Main(string[] args)
{
for (var d = Count(10, (Print("hello")))(Print("done"))(Done); ;)
{
@Porges
Porges / smuggle.cs
Created July 23, 2013 00:38
Smuggling a GCHandle as an IntPtr.
using System;
using System.Runtime.InteropServices;
class Foo
{
}
class Program
{
static IntPtr AllocAndGetPointer()
@Porges
Porges / csharpcode.cs
Last active December 20, 2015 02:49
Receive an object passed from a C function to a callback. (Alternate definition using struct)
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
struct Foo
{
public int Value;
}
class Program
@Porges
Porges / gist:6059207
Created July 23, 2013 01:33
Accept a handle 'inside' a .NET class...
using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
struct Foo
{
private IntPtr _realFoo;
public override string ToString()
{
@Porges
Porges / Haywire.cs
Created July 23, 2013 20:42
sketch of C# version of example program
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ExampleApplication
{
public class Haywire
{
private readonly List<RouteCallback> _routeCallbacks = new List<RouteCallback>(); // store these in here to prevent them being GC'd
private ResponseCompleteCallback _responseCompleteCallback; // ditto, but I've assumed only one can be active at any one time
@Porges
Porges / example.cs
Last active December 20, 2015 08:39
A property type for people who are scared of Observables
using System;
using System.Drawing;
using Properties;
namespace Example
{
class Program
{
static void Main(string[] args)
{
Does:
- Support AtomPub.
- Ensure this works with Windows Live writer.
- Content-negiotiate everything.
- Atom (also supplied when requesting XML)
- HTML (via Razor templates, or XSLT transforms of XML content)
- JSON (just works, but needs tidying up)
- Output caching on server side.
- DNSBL.
- GZIP compression (needs to do in-proc to work around IIS bug regarding Vary header).