Skip to content

Instantly share code, notes, and snippets.

@codedecay
codedecay / BaseController.cs
Last active August 29, 2015 14:27 — forked from jpoehls/BaseController.cs
Newtonsoft Json Results for MVC
using System;
using System.Linq;
using System.Web.Mvc;
public abstract class BaseController : Controller
{
protected override JsonResult Json(object data, string contentType, System.Text.Encoding contentEncoding)
{
return new JsonNetResult
{
@codedecay
codedecay / TypeSwitch.cs
Last active August 29, 2015 14:27 — forked from Virtlink/TypeSwitch.cs
Switch on type. The order of the Case() methods is important.
using System;
namespace Virtlink
{
/// <summary>
/// Executes a particular piece of code based on the type of the argument.
/// </summary>
/// <example>
/// Usage example:
/// <code>
@codedecay
codedecay / FindConflictingReferences.cs
Last active August 29, 2015 14:27 — forked from brianlow/FindConflictingReferences.cs
Find conflicting assembly references
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
namespace MyProject
{
[TestFixture]
@codedecay
codedecay / Either.cs
Last active August 29, 2015 14:27 — forked from siliconbrain/Either.cs
Implemetation of Haskell's Either type in C#
/// <summary>
/// Interface definition of Either
/// </summary>
/// <typeparam name="Tl">type of the Left value</typeparam>
/// <typeparam name="Tr">type of the Right value</typeparam>
public interface IEither<out Tl, out Tr>
{
/// <summary>
/// Check the type of the value held and invoke the matching handler function
/// </summary>
@codedecay
codedecay / gist:23548b798672c796c419
Last active August 29, 2015 14:27 — forked from DamianEdwards/gist:4030394
Async site scraping in ASP.NET 4.5
public class SiteScrape : HttpTaskAsyncHandler
{
public override async Task ProcessRequestAsync(HttpContext context)
{
using (var http = new HttpClient())
{
var downloadTasks = new List<Task<string>> {
http.GetStringAsync("http://bing.com"),
http.GetStringAsync("http://google.com"),
http.GetStringAsync("http://oredev.org"),
@codedecay
codedecay / Cacheability.cs
Last active August 29, 2015 14:27 — forked from bradwilson/Cacheability.cs
Using chaining to create cached results in ASP.NET Web API v2
public enum Cacheability
{
NoCache,
Private,
Public,
}
@codedecay
codedecay / EventStoreService.cs
Last active August 29, 2015 14:27 — forked from trbngr/EventStoreService.cs
EventStore as a windows service w/ TopShelf
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
namespace EventStoreService
{
public class EventStoreService
{
@codedecay
codedecay / LogModule.cs
Last active August 29, 2015 14:27 — forked from pawelpabich/LogModule.cs
Log4Net and NLog modules for Autofac
using System;
using System.Linq;
using Autofac;
using Autofac.Core;
using NLog;
using log4net;
using LogManager = NLog.LogManager;
namespace AutofacIdea
{
@codedecay
codedecay / clojure.md
Last active August 29, 2015 14:27
Setting Up Clojure on OS X

Setting Up Clojure on OS X

I spent a lot of time trying to find a pretty optimal (for me) setup for Clojure… at the same time I was trying to dive in and learn it. This is never optimal; you shouldn't be fighting the environment while trying to learn something.

I feel like I went through a lot of pain searching Google, StackOverflow, blogs, and other sites for random tidbits of information and instructions.

This is a comprehensive "what I learned and what I ended up doing" that will hopefully be of use to others and act as a journal for myself if I ever have to do it again. I want to be very step-by-step and explain what's happening (and why) at each step.

Step 1: Getting Clojure (1.3)

@codedecay
codedecay / plot-compound-interest.py
Last active August 29, 2015 14:27 — forked from tom-galvin/plot-compound-interest.py
A Python/matplotlib script to animate compound interest with an increasing number of terms
# Python code to generate an animation showing compound interest taking place with
# increasingly smaller terms. You will require matplotlib to run this code.
# You'll also require ImageMagick installed to generate the .gif animation.
# You can find this at http://usn.pw/blog/maths/2015/04/09/compound-interest
import matplotlib.pyplot as mp
import matplotlib.animation as ma
def gen_data(steps):
"""Creates the data to be plotted in this animation frame."""