Skip to content

Instantly share code, notes, and snippets.

View juristr's full-sized avatar

Juri Strumpflohner juristr

View GitHub Profile
@juristr
juristr / gist:4986075
Created February 19, 2013 13:52
Copy one stream onto the other
private static void CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[32768];
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
}
@juristr
juristr / ModelBinder.cs
Created February 19, 2013 10:07
Model Binder for properly handling null values. See this post here for more details: http://juristr.com/blog/2012/02/aspnet-mvc3-doesnt-deserialize-nullable
public class ModelBinder : IModelBinder
{
private IModelBinder fallbackModelBinder;
public ModelBinder(IModelBinder fallbackModelBinder)
{
this.fallbackModelBinder = fallbackModelBinder;
}
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
@juristr
juristr / IngoreMemberAutoMapperExtension.cs
Last active December 12, 2015 07:38
Utility for more easily ignore certain members using AutoMapper
public static class MappingExpressionExtensions
{
public static IMappingExpression<TSource, TDest> IgnoreMember<TSource, TDest>(this IMappingExpression<TSource, TDest> expression, Expression<Func<TDest, object>> destinationMember)
{
expression.ForMember(destinationMember, opt => opt.Ignore());
return expression;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace Juristr.Mvc
{
/// <summary>

In order to uninstall packages you need to go to

/Library/Receipts

where there should be a list of installed applications. By invoking

sbom -fls  some_app.pkg/Contents/some-path/somefile.bom

you get the list of installed files and their corresponding paths. As such, a command like

@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);
}
@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 / 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 / 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 / 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);