Skip to content

Instantly share code, notes, and snippets.

View madd0's full-sized avatar

Mauricio Díaz Orlich madd0

View GitHub Profile
@madd0
madd0 / queryString.cs
Created November 15, 2011 08:50
Create a URL query string from a NameValueCollection in C#
var nvc = new NameValueCollection
{
{ "key1", "value1" },
{ "key2", "value2" },
{ "key3", "" }
};
var builder = new UriBuilder("http://www.example.com");
@madd0
madd0 / md5.cs
Created November 15, 2011 09:06
Create an MD5 hash digest in C#
public static string MD5Hash(string toHash)
{
string hashed;
using (MD5 md5 = MD5.Create())
{
hashed = string.Join(string.Empty, md5.ComputeHash(Encoding.UTF8.GetBytes(toHash)).Select(b => b.ToString("x2")));
}
return hashed;
@madd0
madd0 / ShellIcon.cs
Created December 5, 2011 11:43
Get a small or large Icon with an easy C# function call that returns a 32x32 or 16x16 icon.
// -----------------------------------------------------------------------
// <copyright file="ShellIcon.cs" company="Mauricio DIAZ ORLICH ([email protected])">
// Distributed under Microsoft Public License (MS-PL).
// http://www.opensource.org/licenses/MS-PL
// </copyright>
// -----------------------------------------------------------------------
/// <summary>
/// Get a small or large Icon with an easy C# function call
// --------------------------------
// <copyright file="FacebookOAuthClient.cs" company="Thuzi LLC (www.thuzi.com)">
// Microsoft Public License (Ms-PL)
// </copyright>
// <author>Nathan Totten (ntotten.com), Jim Zimmerman (jimzimmerman.com) and Prabir Shrestha (prabir.me)</author>
// <license>Released under the terms of the Microsoft Public License (Ms-PL)</license>
// <website>http://facebooksdk.codeplex.com</website>
// ---------------------------------
namespace Facebook
@madd0
madd0 / ApplicationConfiguration.cs
Created March 26, 2012 13:26
Provides access to configuration files for applications that can be used on the cloud and on premise.
namespace Madd0.Azure
{
using System;
using System.Configuration;
using System.Globalization;
using Microsoft.WindowsAzure.ServiceRuntime;
/// <summary>
/// Provides access to configuration files for applications that can be used on the cloud and on premise.
/// </summary>
@madd0
madd0 / gist:2412241
Created April 18, 2012 09:14
Create VHD with diskpart
C:\>diskpart
Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: XXXXXX
DISKPART> create vdisk file=C:\VHDs\Win8CP.vhd type=expandable maximum=60000
100 percent completed
@madd0
madd0 / idisposable.cs
Created June 12, 2012 20:57
Implement IDispoable Correctly
// From http://msdn.microsoft.com/library/ms244737.aspx
public class Resource : IDisposable
{
private IntPtr nativeResource = Marhsal.AllocHGlobal(100);
private AnotherResource managedResource = new AnotherResource();
// Dispose() calls Dispose(true)
public void Dispose()
{
@madd0
madd0 / transactionutils.cs
Created November 9, 2012 10:03
Better TransactionScope
// As per http://blogs.msdn.com/b/dbrowne/archive/2010/06/03/using-new-transactionscope-considered-harmful.aspx
public class TransactionUtils {
public static TransactionScope CreateTransactionScope()
{
var transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted;
transactionOptions.Timeout = TransactionManager.MaximumTimeout;
return new TransactionScope(TransactionScopeOption.Required, transactionOptions);
}
}

Input Scopes

Default, AlphanumericHalfWidth, AlphanumericFullWidth, Hiragana, KatakanaHalfWidth, KatakanaFullWidth, Hanja, HangulHalfWidth, HangulFullWidth, ChineseHalfWidth, ChineseFullWidth, NativeScript

![Default](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAl8AAACTCAIAAAA/aOusAAA8P0lEQVR4Xux9BXhU19Z2xiczcSIkAQIJobiU4jVKobg7JUiQoC5BI2gSNLi7e5G2aIHS4i6BCBES4j7xTP43c77ON5f+zzXIGj5Y75M7zzmn3GftvfZevkVkYWFhYlQwGPn5+dWrV//222/x8MkygSEWi4uLi0+dOpWRkSGRSP5vNZ7BYDAYDAaDwWAwGAwGg8FgMBgMhuifE3Cp5KZUqrQlWprWoNiQkpyYlBwvvDo5VbIwtyrWFhNRF0syM9Pi3sQIrw72TtY2tsXFVNRF4pxcTXRMhPBqY21r7+BcXFxEVPIRiQoKCyIjw0p0Y21ubuXsVImM8yITkVZbHBkVVlRUiFdTU1Wliq7akhJCMRBFRYfn5+fiWSaTV67sji8lJiVUE0/8+nVktiZLqL1VdqkmlUrpqEsk8fGv09NT/xL5qkqlEsynoi5NTo5PTk4QXp2dXMzNLYq1WjKRz8hIexP/l8g7OFlbE4q8WKzJyY6JeSW82tjY2ds7kYp8QT6ErkQ31hYWVk6OVCJvfIhg+aKiw/Lz8/4JAek/J6BWm6nVFloqlkEpZGdl6V9VKjXGDNOFTFALC/P1r0qlqaWFVVFREZmgYsj0r3K5Qke9kGxBRF6efqLAQsgoOS8SiYqLivErvEolUlDXCiqSqgFisUTPCgtzS3wpobMQEqlUpm+JmZmFXC6Hm0ImdCkpiQYib65Wq8mYj45nZWX8TeSLyUS+oM

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>filehead</Title>
<Author>Mauricio Díaz Orlich</Author>
<Description>