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 / dims.cpp
Last active January 21, 2016 09:01
#include <ratio>
#include <type_traits>
namespace units {
template<class T, int V, class Scale>
struct unit
{
static_assert(V != 0, "uint with exponent of 0 must be replaced by void");
let bindArgumentsAndGenerateScript (args : Dictionary<string, _>) t =
let generateCall c = c |> bindArgument args <!> (sprintf "CALL %s")
let appendLine (stringBuilder : string) s = stringBuilder + s + "\n"
let generateTryCatchBlock (i, c) s =
let successLabel = sprintf "_success_%d" i
let errorLabel = sprintf "_error_%d" i
controlled {
let! sb = c.Try |> generateCall <!> appendLine s
// ...
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Lib
import Control.Applicative
import Data.ByteString (ByteString)
import qualified Data.Attoparsec.ByteString as A
using System;
namespace Immutable
{
enum Qux { Qux1, Qux2 }
class Baz
{
public Baz(Qux qux)
{
using System;
using System.Runtime.CompilerServices;
namespace BadIdeas
{
using static Props; // Boo, C#, why does this need to be located here?
interface IReadable<TName, out T> { }
interface IWritable<TName, in T> { }
open System
type IMonoid<'t> =
abstract Zero : 't
abstract Combine : 't -> 't -> 't
let sumMonoid : IMonoid<int> =
{ new IMonoid<int> with
member __.Zero = 0
member __.Combine x y = x + y }
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
@Porges
Porges / successful_hresult
Created April 8, 2016 01:16
successful_hresult
struct successful_hresult
{
HRESULT hr_;
HRESULT throw_if_failed(HRESULT hr)
{
if (FAILED(hr))
{
throw ...;
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
namespace ConsoleApplication
{
class PropertyComparer : IEnumerable
{
private readonly Dictionary<string, Func<object, object, bool>> _except = new Dictionary<string, Func<object, object, bool>>();
@Porges
Porges / evil.cs
Last active October 2, 2017 21:56
unsafe void Main()
{
var s = "hello world";
Console.WriteLine($"String hash code: {s.GetHashCode()}");
var hashCode = RuntimeHelpers.GetHashCode(s);
Console.WriteLine($"Object hash code: {hashCode}");
Console.WriteLine("Poking string...");
fixed (char* cs = s)