Skip to content

Instantly share code, notes, and snippets.

@SamWM
SamWM / QueryStringOrRouteValue.cs
Created March 16, 2012 12:46
Get Query String Or Route Value (HtmlHelper extension method)
public static MvcHtmlString QueryStringOrRouteValue(this HtmlHelper htmlHelper, string key)
{
string output = string.Empty;
var qs = htmlHelper.ViewContext.RequestContext.HttpContext.Request.QueryString[key];
if (!string.IsNullOrEmpty(qs))
{
output = qs;
}
@SamWM
SamWM / MonthPicker.cshtml
Created March 16, 2012 11:52
Month Picker (Razor view)
@using System.Collections.Generic;
@using System.Globalization;
@{
int month = DateTime.Now.Month;
if (!string.IsNullOrEmpty(Request.QueryString["month"]))
{
month = int.Parse(Request.QueryString["month"]);
}
@SamWM
SamWM / DateLoop.cs
Created March 16, 2012 11:17
Show dates a year before and after current date
DateTime currentDate = DateTime.Now;
DateTime loopDate;
for (loopDate = currentDate.AddMonths(-11); (loopDate - currentDate).Days < 365; loopDate = loopDate.AddMonths(1))
{
if(loopDate == currentDate)
{
Console.Write("<<");
}
Console.Write(loopDate.ToString("MMMM yyyy"));
if(loopDate == currentDate)
@SamWM
SamWM / LinqExtensionMethods.cs
Created March 13, 2012 16:42
Linq Extension Methods
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
public static class LinqExtensionMethods
{
public static Expression<Func<T, bool>> CombineOr<T>(params Expression<Func<T, bool>>[] filters)
{
return filters.CombineOr();
@SamWM
SamWM / gist:1869756
Created February 20, 2012 15:48
jQuery UI DatePicker - only allow Monday to be selected
$(".week").datepicker("option", {
beforeShowDay: function (date)
{
return [date.getDay() == 1, ''];
}
});
// prevent changing weeks and months
var weekOptions = { "changeMonth": false, "changeYear": false, "stepMonths": 0, beforeShowDay: function (date) {
return [date.getDay() == 1, ''];
@SamWM
SamWM / gist:1869751
Created February 20, 2012 15:46
jQuery UI DatePicker - only show current month
$(".month").datepicker("option", { "changeMonth": false, "changeYear": false, "stepMonths": 0});
@SamWM
SamWM / extractmsi.cmd
Created February 20, 2012 14:42
Extract MSI Contents
msiexec /a "c:\path\to\setupfile.msi" /qb TARGETDIR="c:\temp folder"
@SamWM
SamWM / CleanWordHtml.cs
Created February 1, 2012 10:02
Clean Up Words Messy HTML
using System;
using System.Reflection;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
[assembly: AssemblyTitle("CleanWordHtml")]
[assembly: AssemblyDescription("Cleans up HTML generated by Microsoft Word")]
[assembly: AssemblyVersion("1.0.1.*")]
@SamWM
SamWM / smtp.config
Created January 26, 2012 11:54
ASP.NET SMTP Config
<?xml version="1.0" encoding="utf-8" ?>
<smtp from="[email protected]">
<network host="mailserver" password="" userName=""/>
</smtp>
@SamWM
SamWM / gist:1219289
Created September 15, 2011 13:58
DataTable Methods (.NET)
public object RowData(object row, string column)
{
object output = string.Empty;
if (row is DataRow)
{
DataRow v = row as DataRow;
if (v.Table.Columns.Contains(column))
{
output = v[column];
}