Skip to content

Instantly share code, notes, and snippets.

@mastoj
mastoj / ClientWrapperUsage.cs
Created December 6, 2010 20:05
Generic service client base class for WCF
public class ClientWrapperUsage
{
public static void main(string[] args)
{
using(var clientWrapper = new ServiceClientWrapper<ServiceType>())
{
var response = clientWrapper.Channel.ServiceCall();
}
}
}
@gregoryyoung
gregoryyoung / gist:1500720
Created December 20, 2011 08:00
Greg's Stop Loss Kata
Greg's Stop Loss Kata
Testing is very hard when time is involved ...
A trailing stop loss is a term used in financial trading. For a very in depth explanation you can read here http://www.investopedia.com/articles/trading/03/080603.asp and http://en.wikipedia.org/wiki/Order_(exchange)#Stop_orders
However we do not need a huge amount of background in order to do the kata as we are going to limit the problem a bit.
The general idea is that when you buy into a stock at a price say $10. You want it to automatically get sold if the stock goes below $9 (-$1). If we use the term "trailing" that means that id the price goes up to $11 then the sell point becomes $10.
@nickalbrecht
nickalbrecht / SelectListExtensionMethods.cs
Last active November 5, 2022 19:57
SelectListItem Extension Methods for DropDowns in MVC Core. Added ability to specify the option's Group, and for some bug fixes, more XML docs
public static class SelectListExtensionMethods
{
/// <summary>
/// The SelectListItem to use by default as the placeholder for select lists generated by these extension methods when the user needs to pick a value.
/// </summary>
public static readonly SelectListItem DefaultEmptySelectListItem = new SelectListItem() { Text = "-- Pick One --", Value = string.Empty };
/// <summary>
/// The SelectListItem to use by default as the placeholder for select lists generated by these extension methods when not picking a value is the same as using as of the possible choices (meant for filtering typically)
/// </summary>
public static readonly SelectListItem AnySelectListItem = new SelectListItem() { Text = "-- Any --", Value = string.Empty };
@DamianEdwards
DamianEdwards / gist:4030394
Created November 7, 2012 09:31
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"),
@DamianEdwards
DamianEdwards / gist:4032179
Created November 7, 2012 15:14
Some Model Binding helpers for ASP.NET Web Forms 4.5
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.ModelBinding;
namespace VS11BetaTAPWebForms
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Text;
using System.Threading;
@osuritz
osuritz / ValidateJsonAntiForgeryTokenAttribute.cs
Created December 16, 2012 01:40
.NET 4.5 / MVC4-compatible version of ValidateKsonAntiForgeryTokenAttribute
namespace Casero.Web.Mvc
{
using System;
using System.Collections.Specialized;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
// Checks the User's CSRF token
// http://haacked.com/archive/2011/10/10/preventing-csrf-with-ajax.aspx
@dannylloyd
dannylloyd / SQL Table to VB Class.sql
Last active December 15, 2015 02:58
Converts SQL table to VB class
declare @TableName sysname
set @TableName = 'TableName'
declare @Namespace varchar(50)
set @Namespace = 'Namespace'
declare @prop varchar(max)
PRINT 'Imports PetaPoco '
PRINT ''
PRINT 'Namespace ' + @Namespace
PRINT '<TableName("' + @TableName + '")>'
@anaisbetts
anaisbetts / funcioc.cs
Created March 24, 2013 22:36
Literally everything I ever wanted out of an IoC container
public class FuncServiceLocator
{
Dictionary<Tuple<Type, string>, List<Func<object>>> _registry;
public void Register(Func<object> factory, Type type, string contract = null)
{
var pair = Tuple.Create(type, contract ?? "");
if (!_registry.ContainsKey(pair)) _registry[pair] = new List<Func<object>>();
_registry[pair].Add(factory);
@jordangray
jordangray / jquery.shimFormAction.coffee
Last active February 1, 2017 17:16
A simple shim for the HTML5 formaction attribute.
# Test for formaction attribute support in Modernizer.
Modernizr.addTest 'formaction', 'formaction' of document.createElement('input')
# Shim for formaction attributes on buttons and inputs.
$.fn.shimFormAction = ->
return this if Modernizr.formaction
this.each ->
$(this).find 'input,button'
.filter '[formaction!=""][formaction]'