Skip to content

Instantly share code, notes, and snippets.

View mattcanty's full-sized avatar
💭
Hello

Matt Canty mattcanty

💭
Hello
View GitHub Profile
@mattcanty
mattcanty / ConvertLocalBritishTimeToUtc
Last active August 29, 2015 14:01
Given a local british datetime, convert to UTC - take off an hour in summer
public static class DateTimeExtensions
{
private static readonly TimeZoneInfo TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
public static DateTime ConvertLocalBritishTimeToUtc(this DateTime dateTime)
{
var isSummer = TimeZoneInfo.IsDaylightSavingTime(dateTime);
if (isSummer)
{
mongodump
net stop MongoDB
rmdir C:\data\db /S /Q
mkdir C:\data\db
net start MongoDB
mongorestore
rmdir dump /S /Q
@mattcanty
mattcanty / Minify Json
Last active August 29, 2015 14:02
Minify Json
public static string MinifyJson(string unminifiedJson)
{
return Regex.Replace(unminifiedJson, "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");
}
public class Hello
{
public static void Main(string[] args)
{
if (args.Length > 0)
{
System.Console.WriteLine("Hello, " + args[0] + "!");
}
else
{
@mattcanty
mattcanty / Fix IIS
Last active August 29, 2015 14:03
Run command if IIS has been installed after .Net
%windir%\Microsoft.NET\Framework\%version%\aspnet_regiis.exe -i
Template including controller and service
@mattcanty
mattcanty / DownloadController.cs
Created September 25, 2014 13:11
MVC4 ApiController Download FIle
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;
namespace Web.Controllers
{
//usage: /download/report
[RoutePrefix("download")]
@mattcanty
mattcanty / Download.cs
Created October 30, 2014 16:28
Download from web service as an attachment
private static HttpResponseMessage DownloadResponse(string content, string fileName)
{
var downloadContent = new StringContent(content);
var mediaType = new MediaTypeHeaderValue("application/octet-stream");
var dispostition = new ContentDispositionHeaderValue("attachment") { FileName = fileName };
downloadContent.Headers.ContentType = mediaType;
downloadContent.Headers.ContentDisposition = dispostition;
@mattcanty
mattcanty / gist:16de2fc2153d6837ff46
Created November 7, 2014 17:07
Disabling TrustedInstaller
Disable these services:
Windows Installer
Windows Update
Windows Modules Installer
@mattcanty
mattcanty / FromCamelToSpaced.cs
Created November 19, 2014 12:07
Turn "SomethingLikeThis" into "Something Like This"
using System.Text.RegularExpressions;
namespace Spin.TradingServices.Common.Library.Extensions
{
public static class StringExtensions
{
private const string CamelToSpacedRegexString =
@"(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])";
private static readonly Regex CamelToSpacedRegex = new Regex(CamelToSpacedRegexString,