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:1603793
Created January 12, 2012 23:28
Repro for StackOverflow #8609110
using System;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Linq.Expressions;
namespace ConsoleApplication
{
class MyViewModel : INotifyPropertyChanged
{
public object Value { get; set; }
@Porges
Porges / generator.cs
Last active September 29, 2015 12:57
.NET Email Regex
var crlf = @"(\r\n)";
var wsp = @"[ \t]";
var vchar = @"[\u0021-\u007e]";
var obsNoWsCtl = @"[\u0001-\u0008\u000b\u000c\u000e-\u001f\u007f]";
var commentText = @"([\u0021-\u0027\u002a-\u005b\u005d-\u007e]|" + obsNoWsCtl + ")";
var quotedPair = @"\\(" + vchar + "|" + wsp + @"|[\r\n\0]|" + obsNoWsCtl + ")";
var quotedText = @"([\u0021\u0023-\u005b\u005d-\u007e]|"+obsNoWsCtl+")";
var domainText = "([\u0021-\u005A\u005e-\u007e]|" + obsNoWsCtl + ")";
var atomText = "[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]";
var fws = "(" + wsp + "+" + "(" + crlf + wsp + "+)?|(" + crlf + wsp + "+)+)";
@Porges
Porges / gist:1632136
Created January 18, 2012 09:26
Email address example #1
void SendEmail(string address)
{
// ...
}
@Porges
Porges / gist:2144059
Created March 21, 2012 03:32
Example for StackOverflow #9798033/
public static void Main(string[] args)
{
var s = "<x>els o, ø and y\u001a</x>".Replace((char)0x1a, ' ');
var utf8 = Encoding.UTF8.GetBytes(s);
var utf16 = Encoding.Unicode.GetBytes(s);
using (MemoryStream memoryStream = new MemoryStream(utf8))
using (XmlTextReader xsText = new XmlTextReader(memoryStream))
{
@Porges
Porges / gist:2581933
Created May 2, 2012 23:38
Objects can be collected while their instance methods are still executing
using System;
static class Program
{
public static void Main()
{
new Slow().Go();
}
}
@Porges
Porges / gist:2581936
Created May 2, 2012 23:39
'using' holds a reference to the object being disposed
using System;
static class Program
{
public static void Main()
{
using (new Slow()) ;
}
}
@Porges
Porges / gist:2582061
Created May 3, 2012 00:05
using statement transformation
{
Slow slow = null;
try
{
slow = new Slow();
}
finally
{
if (slow != null)
{
@Porges
Porges / gist:2582077
Created May 3, 2012 00:07
revised using statement transform
{
Slow slow = null;
try
{
slow = new Slow();
}
finally
{
if (slow != null)
{
@Porges
Porges / Generic Blow Out
Created November 13, 2012 23:54
How to stop generic blow outs
public interface IQueryHandler<in TQuery, QueryResult> // for some reason out parameters can't be 'out', I probably need to read up why
{
/// result indicates success?
bool Handle(TQuery query, out TQueryResult);
}
@Porges
Porges / gist:4129647
Created November 22, 2012 06:13
Ubuntu X11 Compose file
# UTF-8 (Unicode) compose sequence
# David.Monniaux@ens.fr
#
# Part 1 - Manual definitions
# Spacing versions of dead accents
<dead_tilde> <space> : "~" asciitilde # TILDE
<dead_tilde> <dead_tilde> : "~" asciitilde # TILDE
<dead_acute> <space> : "'" apostrophe # APOSTROPHE