Skip to content

Instantly share code, notes, and snippets.

View ijoyce's full-sized avatar
😎

Ian Joyce ijoyce

😎
View GitHub Profile
@ijoyce
ijoyce / PerIpRateLimithandler.cs
Last active December 18, 2015 02:29
Implementation of the leaky bucket algorithm for per ip request rate limiting. (http://en.wikipedia.org/wiki/Leaky_bucket). Needs burst checking. [Untested].
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Timers;
using System.Web;
namespace LeakyBucket
{
public class PerClientRateLimitHandler : IHttpHandler
{
@ijoyce
ijoyce / RateLimitHandler.cs
Last active December 17, 2015 13:29
Implementation of the leaky bucket algorithm for request rate limiting. (http://en.wikipedia.org/wiki/Leaky_bucket). Needs burst checking. [Untested].
using System;
using System.Threading;
using System.Timers;
using System.Web;
namespace LeakyBucket
{
public class RateLimitHandler : IHttpHandler
{
private static System.Timers.Timer timer;
namespace ScratchPad
{
class Program
{
public static void Main(string[] args)
{
var str = "-";
int? x;
x = str == "-" ? (int?) null : 3;
<script type="text/template" class="template">
<% _.each(rc, function(endpoint) { %>
<% var isEndpointHealthy = !_.find(endpoint.Results, function(result) { return !result.IsHealthy; }) %>
<h4><%- endpoint.EndPoint %> <% if (!isEndpointHealthy) { %>Not <% } %>Healthy</h4>
<% _.each(endpoint.Results, function(result) { %>
<h5><%- result.Name %></h5>
<ul>
<li>Healthy: <%- result.IsHealthy %></li>
<li>Messsage: <%- result.Message%></li>
<li>Exception: <%- result.Exception %></li>
@ijoyce
ijoyce / runTestsInParallel.xml
Created December 20, 2012 19:21
Parallel test execution in visual studio. <Execution parallelTestCount="4"> is the line of note.
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="TestSettings" id="c988b33e-e14f-4f61-9675-c0bac08f1429" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment enabled="false" />
<Execution parallelTestCount="4">
<Timeouts runTimeout="60000" testTimeout="0" />
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
@ijoyce
ijoyce / gist:2005193
Created March 9, 2012 05:35
Primitives Considered Evil
using System;
namespace ThePast
{
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
@ijoyce
ijoyce / GetOrElseExtension.cs
Created November 15, 2011 03:07
GetOrElse extension method for c#
using System;
namespace GetOrElse
{
public static class GetOrElseExtension
{
public static T GetOrElse<T>(this Nullable<T> instance, T orElse) where T: struct
{
if (instance == null)
return orElse;