Skip to content

Instantly share code, notes, and snippets.

View DavidDeSloovere's full-sized avatar

David De Sloovere DavidDeSloovere

View GitHub Profile
@DavidDeSloovere
DavidDeSloovere / dump-env-variables.ps1
Last active February 5, 2017 09:55
TEAM BUILD PowerShell: Output all documented environment variables
# Team Foundation Build environment variables
# http://msdn.microsoft.com/en-us/library/hh850448.aspx
Write-Host "TF_BUILD : $Env:TF_BUILD "
Write-Host "TF_BUILD_BINARIESDIRECTORY : $Env:TF_BUILD_BINARIESDIRECTORY "
Write-Host "TF_BUILD_BUILDDEFINITIONNAME : $Env:TF_BUILD_BUILDDEFINITIONNAME "
Write-Host "TF_BUILD_BUILDDIRECTORY : $Env:TF_BUILD_BUILDDIRECTORY "
Write-Host "TF_BUILD_BUILDNUMBER : $Env:TF_BUILD_BUILDNUMBER "
Write-Host "TF_BUILD_BUILDREASON : $Env:TF_BUILD_BUILDREASON "
Write-Host "TF_BUILD_BUILDURI : $Env:TF_BUILD_BUILDURI "
@DavidDeSloovere
DavidDeSloovere / getversioninfo.cs
Last active August 29, 2015 14:28
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.
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 / web.config
Created September 3, 2014 07:32
Add caching for favicon in web.config
<location path="favicon.ico">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" />
</staticContent>
</system.webServer>
</location>
#####################
# BEGIN CONFIGURATION
#####################
Update-ExecutionPolicy Unrestricted
Set-WindowsExplorerOptions -DisableShowHiddenFilesFoldersDrives -DisableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar
Disable-InternetExplorerESC
Disable-UAC
# Disable defrag (no need when having an SSD)
@DavidDeSloovere
DavidDeSloovere / WebApiConfigCamelCaseJson.cs
Created August 21, 2014 14:57
Camelcase JSON in Web Api
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 August 29, 2015 14:05 — forked from beyond-code-github/WebApiConfig.cs
Remove the XML formatter so content is always returned as JSON.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
var xmlFormatter = config.Formatters.XmlFormatter;
config.Formatters.Remove(xmlFormatter);
}
}
@DavidDeSloovere
DavidDeSloovere / AutoMapperConfiguration.cs
Created August 20, 2014 13:19
AutoMapperConfiguration Put AutoMapperConfiguration.Configure(); in global.asax
public static class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.CreateMap<OriginalEntity, DtoEntity>()
.ForMember(dest => dest.EntityId, source => source.MapFrom(s => s.Id));
}
}
@DavidDeSloovere
DavidDeSloovere / PrepResourceFilesForTranslator.bat
Created February 26, 2014 08:25
This ScriptCS code copies files into a folder while renaming them, and then compresses them into a zip file.
@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 / gist:6277610
Last active December 21, 2015 08:19
System.Net.HttpResponseMessage set custom status code like 429
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
DavidDeSloovere / JsonNetResult
Created June 1, 2013 09:39
JsonNetResult for ASP.NET MVC - correct formatting of dates and camel cased properties Got most of the code from Stack Overflow.
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)
{