Skip to content

Instantly share code, notes, and snippets.

View danielmackay's full-sized avatar

Daniel Mackay [SSW] danielmackay

View GitHub Profile
@danielmackay
danielmackay / EnumExt.cs
Last active December 21, 2015 18:59
Helper functions for pulling attributes from enums. #enum
/// <summary>
/// A helper class which helps conversion between enum and code.
/// </summary>
public static class EnumExt
{
/// <summary>
/// Get a description of Enum
/// </summary>
/// <param name="value">Enum value</param>
/// <returns>description</returns>
@danielmackay
danielmackay / StandardFields.sql
Last active December 21, 2015 18:59
Standard SQL table fields. #sql
Alter table XXX add [CreateID] [int] NOT NULL
Alter table XXX add [CreateTS] [datetime] NOT NULL constraint DefaultModifyID default getdate()
Alter table XXX add [ModifyID] [int] NULL
Alter table XXX add [ModifyTS] [datetime] NULL
Alter table XXX add [InactiveID] [int] NULL
Alter table XXX add [InactiveTS] [datetime] NULL
Alter table XXX add [StatusID] [int] NOT NULL constraint DefaultStatusID default 1
@danielmackay
danielmackay / IISWebDeployConfig.txt
Last active December 21, 2015 22:09
Web deploy troubleshooting
1. Web Management Service => Started?
2. IIS Management Service => Enable Remote Connections
3. Web Deploy Installer => Ensure all options are installed
4. Fire wall => Ensure TCP Port 8172 is open
5. EC2 => Ensure TCP Port 8172 is open
@danielmackay
danielmackay / WebApiWrap.cs
Last active December 22, 2015 19:29
Wrap function with Web API logging. #webapi
protected HttpResponseMessage Wrap<T>(Func<T> func)
{
try
{
var req = HttpContext.Current.Request;
Log.InfoFormat("Service: {0}", req.Path);
if (Log.IsDebugEnabled)
{
req.InputStream.Position = 0;
@danielmackay
danielmackay / FileDownloadHttpResponseMessage.cs
Created September 12, 2013 02:50
MVC HttpResponseMessage for returning content as a file. #attachment, #mvc.
public class FileDownloadHttpResponseMessage : HttpResponseMessage
{
public FileDownloadHttpResponseMessage(string fileName, string content)
: base(HttpStatusCode.OK)
{
Content = new StringContent(content);
// A text file is actually an octet-stream (pdf, etc)
Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
@danielmackay
danielmackay / style.less
Last active December 25, 2015 13:39
Responsive image centering. <li> is just the parent and can be any element. #css, #less, #center
.photo-fullscreen {
position: fixed;
z-index: 99;
color: white;
height: 100%;
width: 100%;
li {
text-align: center;
}
@danielmackay
danielmackay / ListItemSection.cs
Last active December 26, 2015 12:09
MVC Helpers for generating links or sections with toggleable css classes (e.g. for highlighting). #mvc
public class ListItemSection : DivSection
{
public ListItemSection(HtmlHelper self, string className = null)
: base(self, className, "li")
{
}
}
@danielmackay
danielmackay / EnumSelectList.cs
Last active December 26, 2015 12:09
MVC select list helper for enums. #mvc
public static class SelectListExt
{
public static SelectList ToSelectList<TEnum>(this TEnum enumObj)
where TEnum : struct, IComparable, IFormattable, IConvertible
{
var values = from TEnum e in Enum.GetValues(typeof(TEnum))
select new { Id = e, Name = e.ToString() };
return new SelectList(values, "Id", "Name", enumObj);
}
}
@danielmackay
danielmackay / QueryableExt.cs
Created October 30, 2013 23:31
Generic sorting method. #EF, #LINQ.
public static class QueryableExt
{
public static IOrderedQueryable<T> OrderBy<T>(IQueryable<T> source, string propertyName, bool descending, bool anotherLevel = false)
{
ParameterExpression param = Expression.Parameter(typeof(T), string.Empty); // I don't care about some naming
MemberExpression property = Expression.PropertyOrField(param, propertyName);
LambdaExpression sort = Expression.Lambda(property, param);
MethodCallExpression call = Expression.Call(
typeof(Queryable),
@danielmackay
danielmackay / CsvBuilder.cs
Last active December 27, 2015 01:09
CSV builder. #csv
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Utilities
{
public class CsvBuilder
{
private readonly string delimiter;