Skip to content

Instantly share code, notes, and snippets.

@reidev275
reidev275 / ClientError.cs
Last active August 29, 2015 13:55
ClientError
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Web.Http;
namespace DocSol.Webservice.Controllers
{
public class ClientError : HttpResponseException
{
@reidev275
reidev275 / arraySearch.js
Last active August 29, 2015 13:56
Simple javascript searching
var MyNamespace = (function(namespace) {
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp */) {
"use strict";
if (this == null) throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
@reidev275
reidev275 / ajax.js
Last active August 29, 2015 14:01
ajax without jQuery
var ajax = (function (ajax, json) {
ajax.send = function (obj) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status >= 200 && xmlhttp.status < 300 && obj.complete) {
obj.complete(json.parse(xmlhttp.responseText));
}
if (xmlhttp.status < 200 || xmlhttp.status >= 300) {
@reidev275
reidev275 / app.config
Last active August 29, 2015 14:01
network logging
<system.diagnostics>
<sources>
<source name="System.Net" tracemode="protocolonly" maxdatasize="1024">
<listeners>
<add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="System.Net"/>
@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>