Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Configuration;
using System.Web;
using System.Web.Mvc;
namespace Example.Web {
public class MvcApplication : HttpApplication {
protected void Application_EndRequest() {
var context = new HttpContextWrapper(Context);
// If we're an ajax request, and doing a 302, then we actually need to do a 401
@jdaigle
jdaigle / gist:1601581
Created January 12, 2012 16:54
jquery async callback manager
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
if (window.myCode == undefined) window.myCode = function () { }
myCode.asyncManager = function () {
}
myCode.asyncManager.prototype = {
waitingOn: 0,
waitingFor: new Array(),
@jdaigle
jdaigle / gist:1664126
Created January 23, 2012 16:34
one-to-many efficient query
CREATE TABLE [Foo] (
[FooId] [int] NOT NULL,
[SomeDateTime] [datetime2](7) NOT NULL,
-- ... OTHER COLUMNS
[Version] rowversion NOT NULL,
CONSTRAINT [PK_Foo] PRIMARY KEY CLUSTERED ([FooId])
)
CREATE TABLE [FooBar] (
[FooBarId] [int] NOT NULL,
@jdaigle
jdaigle / bootstrap.sortablelist.js
Created February 22, 2012 19:15
sortablelist plugin based on twitter's bootstrap JS conventions
!function ($) {
"use strict"
/* SORTABLELIST PUBLIC CLASS DEFINITION
* ============================== */
var SortableList = function (element, options) {
//this.$element = $(element)
//this.options = $.extend({}, $.fn.sortableList.defaults, options)
@jdaigle
jdaigle / gist:1979064
Created March 5, 2012 16:16
find types implementing generic interface
private readonly static Type messageHandlerOpenGenericType = typeof(IMessageHandler<>);
public static IEnumerable<Type> WhereMessageHandlerType(this IEnumerable<Type> types) {
return types.Where(x => x.IsClass &&
!x.IsAbstract &&
x.GetInterfaces().Any(i => i.IsGenericType &&
i.GetGenericTypeDefinition() == messageHandlerOpenGenericType));
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Clearwave.ServiceBus {
public class MessageHandlerCollection {
private readonly static Type messageHandlerOpenGenericType = typeof(IMessageHandler<>);
private IDictionary<Type, ISet<DispatchInfo>> messageHandlers = new Dictionary<Type, ISet<DispatchInfo>>();
@jdaigle
jdaigle / gist:2032837
Created March 14, 2012 00:02
Cross-domain requests
1. load document in domain.com which contains iframe that points to sub.domain.com
2. document loaded from sub.domain.com should automatically set document.domain=domain.com
- this is required so that the parent frame can access the child frame
3. from parent document: new frames[0].XMLHttpRequest()
- now you have an XHR document which can open and send to sub.domain.com
4. if uses jquery, pass this XHR into $.ajax() via options
This should work in every modern web browser, including IE7
@jdaigle
jdaigle / gist:2222148
Created March 28, 2012 00:35
Coding Conventions

Stolen from: http://aspnetwebstack.codeplex.com/wikipage?title=CodingConventions

= C# coding conventions =

In general, we have strived to use a style which is compatible with the out-of-the-box defaults for Visual Studio. In particular, this means we use Allman bracing style.

Some other rules we follow:

  • Private fields are prefixed with an underscore and camel-cased.
  • Always include curly braces around blocks, even when they would be optional.
<html>
<head><title></title></head>
<body>
<form method="post" action="https://apollo.tfs2.com/Secure/login.aspx">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" />
</form>
</body>
</html>
@jdaigle
jdaigle / gist:2781344
Created May 24, 2012 12:38
SQL Server Service Broker: Short Script to clear DISCONNECTED_INBOUND conversations
DECLARE @handle UNIQUEIDENTIFIER;
WHILE (SELECT COUNT(*) from sys.conversation_endpoints (nolock) where state_desc = 'DISCONNECTED_INBOUND') > 0
BEGIN
SELECT TOP 1 @handle = conversation_handle from sys.conversation_endpoints (nolock) where state_desc = 'DISCONNECTED_INBOUND';
END CONVERSATION @handle WITH CLEANUP
END