Skip to content

Instantly share code, notes, and snippets.

@johnallers
johnallers / UnityRegisterGenericType
Created December 7, 2011 17:41
Registering generic types using Unity
IUnityContainer container = new UnityContainer();
container.RegisterType(typeof(IRepository<>), typeof(EfRepository<>));
@johnallers
johnallers / gist:1570772
Created January 6, 2012 14:09
Disable optimizations when debugging reference source
@echo off
set COMPLUS_ZapDisable=1
cd /d "%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\ide\"
echo.
echo Be sure to uncheck "Enable the Visual Studio Hosting Process" in Project Properties.
echo.
pause
@johnallers
johnallers / theme.html
Created January 14, 2012 14:33 — forked from soemarko/theme.html
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
@johnallers
johnallers / gist:1674845
Created January 25, 2012 05:06
Demonstration of the C# compiler using duck typing for the foreach keyword.
namespace Samples
{
using System;
using System.Collections.Generic;
public class CustomEnumerableDemoConsole
{
public static void Main(params string[] args)
{
CustomEnumerable enumerable = new CustomEnumerable("One", "Two", "Three");
@johnallers
johnallers / gist:1742936
Created February 5, 2012 04:59
Tests I threw together to verify behavior of Unity.
namespace GenericInterfacesWithUnity
{
using Microsoft.Practices.Unity;
using NUnit.Framework;
[TestFixture]
public class UnityWithRegularInterfaceTests
{
private UnityContainer container;
@johnallers
johnallers / OptionParametersOnInterface.cs
Created February 9, 2012 01:15
Quick demo of how optional parameters work with interfaces.
namespace OptionalParametersOnInterface
{
using System;
public interface IFoo
{
void DoStuff(bool someBit = true);
}
public class Foo : IFoo
@johnallers
johnallers / gist:2009359
Created March 9, 2012 23:48
JavaScript trim()
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
@johnallers
johnallers / gist:2190635
Created March 25, 2012 01:29
jQuery.localize with string supplanting
// sample application-en.json file
/*
{
Title : "Welcome to {CurrentSite}"
}
*/
if (typeof String.prototype.supplant === 'undefined') {
String.prototype.supplant = function (o, defaultIfMissing) {
return this.replace(/{([^{}]*)}/g,
@johnallers
johnallers / gist:2473052
Created April 23, 2012 18:54
KnockoutJS binding debugging
<!-- http://stackoverflow.com/questions/9261296/any-good-techniques-to-debug-template-binding-faults-for-knockout-js -->
<pre data-bind="text: JSON.stringify(ko.toJS($data), null, 2)"></pre>
@johnallers
johnallers / jquery.readOnlySuffix.js
Created May 22, 2012 02:14
Add a suffix to an text input, which cannot be overwritten.
(function( $ ) {
$.fn.readOnlySuffix = function(suffix) {
return this.each(function() {
var $this = $(this),
suffixLength = suffix.length,
oldValue = suffix,
mouseIsDown = false;
// Must be a text input or text area
if (!($this.is(":text") || $this.tagName.toLowerCase() == "textarea")){