Skip to content

Instantly share code, notes, and snippets.

View juristr's full-sized avatar

Juri Strumpflohner juristr

View GitHub Profile
@juristr
juristr / SmellyCodeReview.cs
Created December 31, 2010 08:25
Taken from a #smellycode post, just to demonstrate the usage fo gist in code reviews
public Account ReadCompleteAccountByADUsernameAndServiceUID(string adUsername, string serviceInstanceUID)
{
    IList<Address> addresses;
    IList<Contact> contacts;
 
//Attention, directly instantiating an object within the method may potentially create
//problems when doing testing 'cause its dependency cannot be mocked out.
    MasterDataBL masterDataBL = new MasterDataBL();
 
    Account result =  AccoDao.ReadCompleteAccountByADUsernameAndServiceUID(adUsername, serviceInstanceUID, ConnectionString.Master, out addresses, out contacts);
@juristr
juristr / IdentityStub.cs
Created August 10, 2012 05:47
Some helper classes to create a fake principal with roles
public class IdentityStub : IIdentity
{
private readonly string _name;
private readonly string _authenticationType;
private readonly bool _isAuthenticated;
public IdentityStub(string name, string authenticationType, bool isAuthenticated)
{
_name = name;
_isAuthenticated = isAuthenticated;
@juristr
juristr / gist:3812508
Created October 1, 2012 15:28
AutoMapper Bidirectional Mapping Extension
public static class AutoMapperExtensions
{
public static void Bidirectional<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression)
{
Mapper.CreateMap<TDestination, TSource>();
}
}
@juristr
juristr / jekyll_github.md
Created October 24, 2012 21:37
Jekyll Blogging Tips and Tricks

Setup Windows

If you need to update jekyll on windows, pay attention that you might get an ETIMEDOUT error. This is due to a proxy or firewall. In such case the --http-proxy option has to be used

gem update jekyll --http-proxy http://user:pwd@proxy-server:port

Writing Drafts using a separate Git Branch

@juristr
juristr / gist:3973479
Created October 29, 2012 13:15
Programmatic GZip Action Filter for ASP.net MVC3
public class GZipCompressionGlobalActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string acceptEncoding = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
if (string.IsNullOrEmpty(acceptEncoding)) return;
acceptEncoding = acceptEncoding.ToUpperInvariant();
@juristr
juristr / gist:3987994
Created October 31, 2012 16:17
Ellipsis function
function(text, maxLength){
if(typeof maxLength === 'undefined'){
maxLength = 9000; //a large number
}
if (text.length <= maxLength)
return text;
var xMaxFit = maxLength - 3;
var xTruncateAt = text.lastIndexOf(' ', xMaxFit);
@juristr
juristr / gist:4114109
Created November 19, 2012 21:30
jQuery Plugin Template
(function($, undefined){
$.fn.defaults = {};
$.fn.dots = function(options){
var opts = $.extend({}, $.fn.dots.defaults, options);
return this.each(function(){
$this = $(this);
@juristr
juristr / readme.md
Created December 11, 2012 07:41
ASP.net MVC: Completely Disable Caching
public class NoCacheGlobalActionFilter : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
//IE: http://support.microsoft.com/kb/316431
if (!(filterContext.Result is FileResult))
{
HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;
cache.SetCacheability(HttpCacheability.NoCache);
}
@juristr
juristr / JsonpResult.cs
Created December 19, 2012 06:51
A simple JsonpResult object for being used in ASP.net MVC applications
using System.Web.Mvc;
public class JsonpResult : JsonResult
{
public string Callback { get; set; }
public JsonpResult()
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet;
@juristr
juristr / gist:4337356
Created December 19, 2012 15:09
Verify whether an ExpandoObject has a property
private bool HasProperty(string propertyName, ExpandoObject expandoObj)
{
return ((IDictionary<string, object>)expandoObj).ContainsKey(propertyName);
}