Skip to content

Instantly share code, notes, and snippets.

@reidev275
reidev275 / Global.asax.cs
Last active August 29, 2015 14:01
Catches otherwise uncaught TaskCanceledException objects. Useful with WebApi and async await programming. We get a handle to the buffer so that we can replay the reading of the buffer for logging purposes later.
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
//...
GlobalConfiguration.Configuration.MessageHandlers.Add(new TaskCanceledExceptionHandler());
}
}
@reidev275
reidev275 / EasyNetQAutoSubscriber.cs
Last active August 29, 2015 14:03
EasyNetQ AutoSubscriber
class Program
{
static void Main(string[] args)
{
using (var bus = RabbitHutch.CreateBus("host=localhost"))
{
var subscriber = new AutoSubscriber(bus, "Subscriber");
subscriber.SubscribeAsync(Assembly.GetExecutingAssembly());
Console.WriteLine("Listening for messages. Hit <return> to quit.");
Console.ReadLine();
public class ImageProcessRequestConsumer : IConsumeAsync<ImageProcessRequest>
{
Command command = new Command("connectionString");
public async Task Consume(ImageProcessRequest message)
{
await command.ExecuteScalarAsync(
@"Insert into Images(TrackingNumber, Format, Image)
Values(@TrackingNumber, @Format, @Image)",
message);
public static class RabbitMQ
{
public static IBus Bus { get; private set; }
static RabbitMQ()
{
Bus = RabbitHutch.CreateBus("host=localhost");
}
}
@reidev275
reidev275 / TemporaryDirectory.cs
Created July 17, 2014 15:44
TemporaryDirectory - safe, self cleaning sandbox for file manipulation
public class TemporaryDirectory : IDisposable
{
readonly string _directory;
public TemporaryDirectory()
{
_directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(_directory);
}
@reidev275
reidev275 / AnimatedHierarchy.html
Last active August 29, 2015 14:08
Animated traversing through a hierarchy
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Animated Hierarchy</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
@reidev275
reidev275 / Atom.cs
Created December 19, 2014 14:27
Descriptive responses from methods. Rather than returning null return an Atom or a Result<T>
public enum Atom
{
OK, Unauthorized, NotFound, Forbidden
}
@reidev275
reidev275 / git.config
Created December 19, 2014 14:57
git aliases
[alias]
cm = !git add -A && git commit -m
co = checkout
cob = "!f() { git checkout ${2-develop} && git up && git checkout -b ${1}; }; f"
ec = config --global -e
undo = reset HEAD~1 --mixed
up = pull --rebase --prune
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard
var Ar = {
filter: function(fn, list) {
if (!list[0]) return [];
if (fn(list[0])) return [list[0]].concat(Ar.filter(fn, list.slice(1)));
return [].concat(Ar.filter(fn, list.slice(1)));
},
first: function(fn, list) {
if (!list[0]) return null;
if (fn(list[0])) return list[0];
return Ar.first(fn, list.slice(1));
System.IO.Directory.SetCurrentDirectory (__SOURCE_DIRECTORY__)
#r "Microsoft.Office.Interop.Excel"
#r "office"
open System
open Microsoft.Office.Interop.Excel
let xlApp = new ApplicationClass()
let workbook = xlApp.Workbooks.Open(@"C:\Dev\ExcelRedirects\ExcelRedirects\redirects.xls")
let sheet = workbook.Worksheets.[1] :?> Worksheet