Skip to content

Instantly share code, notes, and snippets.

@amogram
amogram / EnumHelper.cs
Created April 6, 2012 13:27
Get System.ComponentModel.DescriptionAttribute value of T
public static class EnumHelper<T>
{
public static string GetEnumDescription(T _enum)
{
Type type = _enum.GetType();
var memInfo = type.GetMember(_enum.ToString());
if (memInfo.Length > 0)
{
@amogram
amogram / BuildExtensions
Created April 24, 2012 13:53
Get Build Number of Assembly
public static string GetBuildNumber()
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
@amogram
amogram / gist:2577862
Last active October 4, 2015 04:28
Umbraco Folder Permissions
icacls app_code /grant "IIS APPPOOL\umbraco":(OI)(CI)RX
icacls app_browsers /grant "IIS APPPOOL\umbraco":(OI)(CI)RX
icacls app_data /grant "IIS APPPOOL\umbraco":(OI)(CI)M
icacls bin /grant "IIS APPPOOL\umbraco":(OI)(CI)M
icacls config /grant "IIS APPPOOL\umbraco":(OI)(CI)M
icacls css /grant "IIS APPPOOL\umbraco":(OI)(CI)M
icacls data /grant "IIS APPPOOL\umbraco":(OI)(CI)M
icacls macroscripts /grant "IIS APPPOOL\umbraco":(OI)(CI)M
icacls masterpages /grant "IIS APPPOOL\umbraco":(OI)(CI)M
icacls media /grant "IIS APPPOOL\umbraco":(OI)(CI)M
@amogram
amogram / SafeExtensions.cs
Last active December 15, 2015 10:19
Safe Casting ToList<T>() in C#
public static class SafeExtensions
{
public static IEnumerable<T> SafeToList<T>(this IEnumerable<T> source)
{
return source != null ? source.ToList() : null;
}
public static T[] SafeToArray<T>(this IEnumerable<T> source)
{
return source != null ? source.ToArray() : null;
@amogram
amogram / gist:5389180
Created April 15, 2013 16:02
Quick and dirty Timestamp extension method.
public static class DateTimeExtensions
{
public static String GetTimestamp(this DateTime value)
{
return value.ToString("yyyyMMddHHmmssffff");
}
}
@amogram
amogram / chocolatey-env-setup.ps1
Last active August 17, 2021 14:19
A Chocolatey script for PowerShell I use to set up my Windows development environment. I use this when setting up my own Dev VMs. Use at your own risk.See http://bit.ly/1a301JK and http://chocolatey.org/ for more information.
# Simple environment setup script
# Install Applications
choco install fiddler4
choco install notepadplusplus
choco install visualstudiocode
choco install greenshot
choco install GoogleChrome
choco install putty
choco install ccleaner
@amogram
amogram / stringAggregate
Created April 15, 2014 15:01
DIsplay items in dictionary in order.
string res = "";
var displayOrder = new Dictionary<string, int>(){{"string two",2},{"string 1",1},{"string 3",3}};
res = "Person ID" + displayOrder.OrderBy(x => x.Value).Aggregate(res, (current, x) => current + " - " + x.Key);
// for demo in LINQPad
res.Dump();
@amogram
amogram / stringjoin
Created April 15, 2014 15:08
Using string.Join to flatten dictionary of strings, ordered by value.
string res = "";
var displayOrder = new Dictionary<string, int>(){{"string 2",2},{"string 1",1},{"string 3",3}};
res= string.Join(" - ",displayOrder.OrderBy(x => x.Value).Select(x=>x.Key));
// dump to LINQPad
res.Dump();
@model UserViewModel
@using (Html.BeginForm())
{
<div>
@Html.HiddenFor(m => m.Id)
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
@Html.DropDownListFor(m => m.CountryId, Model.Countries)
@model EditUserModel
@using (Html.BeginForm())
{
<div>
@Html.HiddenFor(m => m.Id)
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
@Html.DropDownListFor(m => m.CountryId, Model.Countries)