Skip to content

Instantly share code, notes, and snippets.

@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
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: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));
}
@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: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 / 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(),
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
<UserSettings>
<ApplicationIdentity version="9.0"/>
<ToolsOptions>
<ToolsOptionsCategory name="Environment" RegisteredName="Environment">
<ToolsOptionsSubCategory name="Documents" RegisteredName="Documents" PackageName="Visual Studio Environment Package">
<PropertyValue name="ShowMiscFilesProject">false</PropertyValue>
<PropertyValue name="AutoloadExternalChanges">false</PropertyValue>
<PropertyValue name="CheckForConsistentLineEndings">false</PropertyValue>
<PropertyValue name="SaveDocsAsUnicodeWhenDataLoss">false</PropertyValue>
<PropertyValue name="InitializeOpenFileFromCurrentDocument">true</PropertyValue>
@jdaigle
jdaigle / gist:1083608
Created July 14, 2011 22:20
No Frills JQuery/HTML5 Validation
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
if (typeof (nfvalidate) == "undefined") nfvalidate = {};
// An array of validators to push your validators to
nfvalidate.validators = new Array();
nfvalidate.validators.push({
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SplitGuids]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[SplitGuids]
GO
CREATE FUNCTION [dbo].[SplitGuids]
(
@List varchar(2000)
)
RETURNS
@ParsedList table