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
^(?'xmlDecl'<\?xml(?'versionInfo'([\u0020\u0009\u000d\u000a]+)version(?'eq'([\u0
020\u0009\u000d\u000a]+)?=([\u0020\u0009\u000d\u000a]+)?)('1\.[0-9]+'|"1\.[0-9]+
"))(?'encodingDecl'([\u0020\u0009\u000d\u000a]+)encoding(?'eq'([\u0020\u0009\u00
0d\u000a]+)?=([\u0020\u0009\u000d\u000a]+)?)("(?'encName'[A-Za-z][A-Za-z0-9._-]*
)"|'(?'encName'[A-Za-z][A-Za-z0-9._-]*)'))?(?'sddecl'([\u0020\u0009\u000d\u000a]
+)standalone(?'eq'([\u0020\u0009\u000d\u000a]+)?=([\u0020\u0009\u000d\u000a]+)?)
("(yes|no)"|'(yes|no)'))?([\u0020\u0009\u000d\u000a]+)?\?>)?(?'misc'(?'comment'<
!--((?!--)([\u0009\u000a\u000d\u0020-\ud7ff\ue000-\ufffd]|([\ud800-\udbff][\udc0
0-\udfff])))*-->)|(?'PI'<\?(?'pitarget'(?![xX][mM][lL])(?'name'([:A-Z_a-z\u00C0-
\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u
operator implicit
@Porges
Porges / lens_sketch.cs
Last active December 25, 2015 03:59
sketch of doing lenses in C#
using System;
using System.Collections.Generic;
using System.Linq;
namespace Lens
{
class Program
{
class Foo
{
@Porges
Porges / gist:7247250
Created October 31, 2013 10:05
Where we're going we don't need FileStreams
public Task Write(ArraySegment<byte> buffer)
{
unsafe
{
fixed (byte* thing = buffer.Array) // this fixed expires but the real fixed is that done by Pack (lives until callback)
{
var tcs = new TaskCompletionSource<uint>();
var overlapped = new Overlapped((int)_pos, (int)(_pos>>32), IntPtr.Zero, null);
_pos += (ulong)buffer.Count;
@Porges
Porges / 7yearsofbadluck.cs
Last active December 27, 2015 08:39
part 9 in a series of stupid gists
using System;
using System.Linq;
class Program
{
static void Main()
{
var s = "hello";
@Porges
Porges / mutorere.cs
Created November 11, 2013 19:25
A transcription of a BASIC program into C#. This is buggy (wins happen when they shouldn't) but I'm not sure if it's a typo or an error in the printed version (or a misunderstanding of a BASIC construct). Original: http://www.atariarchives.org/bigcomputergames/showpage.php?page=43
using System;
// Mu-Torere
// in terrible C#
// transcribed from: http://www.atariarchives.org/bigcomputergames/showpage.php?page=43 (and following)
class MuTorere
{
static int[] H;
static int[] A;
@Porges
Porges / syntax.cs
Last active August 29, 2015 13:57
some syntactical ideas for C#
class Example
{
// "init-anywhere" syntax (along the lines of Haskell)
[Implemented(true)]
Foo Do()
{
var x = new Foo { bar = 1 }; // <- currently available
return x { bar = 3 }; // <- proposed (note that this mutates unlike Haskell)
}
@Porges
Porges / output
Last active August 29, 2015 13:57
iteration 1 of experimental_syntax
System.Tuple`2[System.Int32,System.Int32]
System.Tuple`1[System.Int32]
hello, foo: 2 - (1, 2), (1), (1, hello)
4294967295
@Porges
Porges / enum_parser.cs
Last active August 29, 2015 13:57
If you didn't have Enum.(Try)Parse?
static bool TryParseEnum<T>(string input, out T parsedValue)
{
input = input.Trim();
foreach (T value in Enum.GetValues(typeof(T)))
{
if (value.ToString() == input)
{
parsedValue = value;
return true;
}
template <class PtrType, PtrType>
// e.g. this could be "template<class PtrType, PtrType second>"
// the second arg has the type of the first argument, but isn't a type itself
struct eq {};
struct Foo
{
int val() { return -31; }
};