Skip to content

Instantly share code, notes, and snippets.

David De Sloovere DavidDeSloovere

View GitHub Profile
DavidDeSloovere / gist:1893621
Created Feb 23, 2012
Sample CacheAttribute for ASP.NET Web Api - i'm not saying this is the best way
View gist:1893621
namespace ProjectName.WebApi.Infrastructure
using System;
using System.Net;
using System.Net.Http.Headers;
using System.Web.Http.Filters;
public class CacheAttribute : ActionFilterAttribute
public CacheAttribute()
DavidDeSloovere / CopyChmLocalAndOpen.ps1
Created Jan 4, 2013
Open up an old school .CHM help file from a network path. Put the Powershell in the folder of the .CHM file and any user can launch the help file via right-click on the .PS1 and selecting 'Run with Powershell'. (Set-ExecutionPolicy might need to be set first)
View CopyChmLocalAndOpen.ps1
$tempfolder = $env:TEMP
$chmfile = Get-ChildItem | Where-Object {$_.Extension -match "chm"}
"Copying to local temp folder: $tempfolder"
Copy-Item $chmfile $tempfolder
"Opening $chmfile"
Start-Process $tempfolder\$chmfile
DavidDeSloovere / JsonNetResult
Created Jun 1, 2013
JsonNetResult for ASP.NET MVC - correct formatting of dates and camel cased properties Got most of the code from Stack Overflow.
View JsonNetResult
using System;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
public class JsonNetResult : JsonResult
public override void ExecuteResult(ControllerContext context)
DavidDeSloovere / gist:6277610
Last active Dec 21, 2015
System.Net.HttpResponseMessage set custom status code like 429
View gist:6277610
var response = new HttpResponseMessage
StatusCode = (HttpStatusCode)429,
ReasonPhrase = "Too Many Requests",
Content = new StringContent(string.Format(CultureInfo.InvariantCulture, "Rate limit reached. Reset in {0} seconds.", data.ResetSeconds))
response.Headers.Add("Retry-After", data.ResetSeconds.ToString(CultureInfo.InvariantCulture));
actionContext.Response = response;
DavidDeSloovere / PrepResourceFilesForTranslator.bat
Created Feb 26, 2014
This ScriptCS code copies files into a folder while renaming them, and then compresses them into a zip file.
View PrepResourceFilesForTranslator.bat
ECHO ---
ECHO This command needs scriptcs (see
ECHO If it is not installed you will get an error
ECHO ---
scriptcs PrepResourceFilesForTranslator.csx
ECHO ---
DavidDeSloovere / AutoMapperConfiguration.cs
Created Aug 20, 2014
AutoMapperConfiguration Put AutoMapperConfiguration.Configure(); in global.asax
View AutoMapperConfiguration.cs
public static class AutoMapperConfiguration
public static void Configure()
Mapper.CreateMap<OriginalEntity, DtoEntity>()
.ForMember(dest => dest.EntityId, source => source.MapFrom(s => s.Id));
DavidDeSloovere / WebApiConfigRemoveXmlFormatter.cs
Last active Aug 29, 2015 — forked from beyond-code-github/WebApiConfig.cs
Remove the XML formatter so content is always returned as JSON.
View WebApiConfigRemoveXmlFormatter.cs
public static class WebApiConfig
public static void Register(HttpConfiguration config)
var xmlFormatter = config.Formatters.XmlFormatter;
View WebApiConfigCamelCaseJson.cs
public static class WebApiConfig
public static void Register(HttpConfiguration config)
// just camel case
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
// or camel case plus nicer formatting
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
View boxstarter_apps
Update-ExecutionPolicy Unrestricted
Set-WindowsExplorerOptions -DisableShowHiddenFilesFoldersDrives -DisableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar
# Disable defrag (no need when having an SSD)
DavidDeSloovere / web.config
Created Sep 3, 2014
Add caching for favicon in web.config
View web.config
<location path="favicon.ico">
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" />
You can’t perform that action at this time.