Skip to content

Instantly share code, notes, and snippets.

David De Sloovere DavidDeSloovere

Block or report user

Report or block DavidDeSloovere

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@DavidDeSloovere
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 OFF
CLS
ECHO ---
ECHO This command needs scriptcs (see http://scriptcs.net/)
ECHO If it is not installed you will get an error
ECHO ---
scriptcs PrepResourceFilesForTranslator.csx
ECHO ---
PAUSE
@DavidDeSloovere
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));
}
}
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();
@DavidDeSloovere
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;
config.Formatters.Remove(xmlFormatter);
}
}
@DavidDeSloovere
DavidDeSloovere / web.config
Created Sep 3, 2014
Add caching for favicon in web.config
View web.config
<location path="favicon.ico">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" />
</staticContent>
</system.webServer>
</location>
@DavidDeSloovere
DavidDeSloovere / getversioninfo.cs
Last active Aug 29, 2015
Get the 3 versions that can be attached to an assembly via AssemblyInfo. Can be used in ASP.NET MVC to output the version in the footer.
View getversioninfo.cs
var assembly = Assembly.GetExecutingAssembly();
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
model.FileVersion = string.Format(CultureInfo.InvariantCulture, "v{0}", fvi.FileVersion);
model.ProductVersion = string.Format(CultureInfo.InvariantCulture, "v{0}", fvi.ProductVersion);
model.AssemblyVersion = string.Format(CultureInfo.InvariantCulture, "v{0}", assembly.GetName().Version);
@DavidDeSloovere
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
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
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
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;
You can’t perform that action at this time.