Skip to content

Instantly share code, notes, and snippets.

View davidfowl's full-sized avatar

David Fowler davidfowl

View GitHub Profile
@davidfowl
davidfowl / failregex.cs
Last active June 22, 2016 01:17
Here's a regex that will max out your CPU (just one)
using System;
using System.Text.RegularExpressions;
namespace RegexFail
{
class Program
{
static void Main(string[] args)
{
var urlPattern = new Regex(@"(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'"".,<>?«»“”‘’]))", RegexOptions.Compiled | RegexOptions.IgnoreCase);
@davidfowl
davidfowl / Global.cs
Last active January 3, 2016 13:39
Shutdown issues
using System;
using System.Diagnostics;
using RestartIssue.Web;
namespace WebApplication1
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
@davidfowl
davidfowl / fastlinkedlist.cs
Created March 30, 2014 23:07
Specialized lock free linked list with 2 operations, Add and GetListAndClear. Useful for implementing batching.
public class FastLinkedList<T>
{
private Node Head;
public void Add(T value)
{
var node = new Node();
node.Value = value;
while (true)
@davidfowl
davidfowl / NowinServerFactory.cs
Created May 25, 2014 00:34
Nowin on ASP.NET vNext
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting.Server;
using Microsoft.AspNet.Owin;
using Microsoft.Framework.ConfigurationModel;
namespace Nowin.vNext
using System;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Versioning;
using System.Text;
using Microsoft.Framework.Runtime;
using System.IO;
using NuGet;
@davidfowl
davidfowl / dotnetlayout.md
Last active November 4, 2025 18:07
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
 tests/
@davidfowl
davidfowl / AzureStreamingLoggerProvider.cs
Created November 16, 2014 07:25
AzureStreamingLoggerProvider
public class AzureStreamingLoggerProvider : ILoggerProvider
{
public ILogger Create(string name)
{
return new AzureLogger(name);
}
private class AzureLogger : ILogger
{
private readonly string _name;
@davidfowl
davidfowl / Dumper.cs
Last active June 22, 2016 04:28
Data dump xbuild
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Framework;
using Microsoft.Build.BuildEngine;
using System.Collections;
@davidfowl
davidfowl / inferme.cs
Created February 9, 2015 04:59
C# type inference
public static class MyClass
{
public static void DoSomething<T>(Func<int, T, int> call)
{
}
public static void Example()
{
// This fails
Warning: FindPackagesById: System.Runtime.Handles
Error getting response stream (ReadDone1): ReceiveFailure
GET https://nuget.org/api/v2/FindPackagesById()?Id='System.Runtime.Handles'.
Warning: FindPackagesById: System.Diagnostics.Process
Error getting response stream (ReadDone1): ReceiveFailure
GET https://nuget.org/api/v2/FindPackagesById()?Id='System.Diagnostics.Process '.
Warning: FindPackagesById: System.Reflection.Primitives
Error getting response stream (ReadDone1): ReceiveFailure
GET https://nuget.org/api/v2/FindPackagesById()?Id='System.Reflection.Primitiv es'.
Warning: FindPackagesById: System.IO.FileSystem.Primitives