Skip to content

Instantly share code, notes, and snippets.

using Web.AppStart;
using WebActivator;
[assembly: PostApplicationStartMethod(typeof(Bundles), "Start")]
namespace Web.AppStart
{
using System.Collections.Generic;
using System.Web;
@bitsprint
bitsprint / global.asax.cs
Created June 14, 2013 09:21
ASP.NET MVC Application Global
namespace Web
{
using System;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using NLog;
@bitsprint
bitsprint / DependencyInjection.cs
Created June 14, 2013 10:33
Windsor Dependency Injection Setup
using System.Web;
using Web.AppStart;
[assembly: WebActivator.PreApplicationStartMethod(typeof(DependencyInjection), "BootstrapContainer")]
namespace Web.AppStart
{
using System;
using System.IO;
@bitsprint
bitsprint / MoqVerifier.cs
Created June 20, 2013 08:25
Test With Mocks base class (inherit from test)
namespace Core.Tests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Moq;
public static class MoqVerifier
@bitsprint
bitsprint / HtmlHelperExtensions.cs
Created June 27, 2013 14:10
HtmlHelper Extensions
namespace Web.Extensions.Control
{
public static partial class HtmlHelperExtensions
{
// Usage: @Html.ListBoxWithAttributesFor(m => m.Foo, Model.Foos, false)
// See SelectListItemWithAttributes
public static MvcHtmlString ListBoxWithAttributesFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, IEnumerable<SelectListItemWithAttributes> selectList, bool multiple = true)
{
if (expression == null)
{
@bitsprint
bitsprint / ControlExtensions.cs
Created June 27, 2013 14:16
Control Extensions
namespace Web.Extensions.Control
{
using System.Collections.Generic;
using System.Web.Mvc;
// Usage: foos.Select(x => new SelectListItemWithAttributes
// {
// Attributes = new Dictionary<string, object>() { { "foootherid", x.SomeOtherId } },
// Text = x.Name,
@bitsprint
bitsprint / Utils.Tables.1.sql
Created August 1, 2013 12:54
Truncate all the tables
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
@bitsprint
bitsprint / Types.Dictionary.1.sql
Last active December 20, 2015 23:28
Indexed Dictionary (User Defined Table Type)
/****** Object: UserDefinedTableType [dbo].[IndexedDictionary] ******/
IF EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'IndexedDictionary' AND ss.name = N'dbo')
DROP TYPE [dbo].[IndexedDictionary]
GO
/****** Object: UserDefinedTableType [dbo].[IndexedDictionary] ******/
CREATE TYPE [dbo].[IndexedDictionary] AS TABLE(
[Index] [int] NULL,
[Key] [nvarchar](255) NULL,
[Value] [nvarchar](255) NULL
@bitsprint
bitsprint / CsvParser.cs
Created September 16, 2013 13:02
Csv Parser
using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser("C:\\testfile.txt")) {
parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
parser.SetDelimiters(",");
string[] currentRow = null;
while (!parser.EndOfData) {
try {
currentRow = parser.ReadFields();
string currentField = null;
foreach (string field in currentRow) {
currentField = field;
@bitsprint
bitsprint / Utils.Date.sql
Created September 17, 2013 09:26
Round date to midnight
-- SQL 2008
DECLARE @CurrentDate DATETIME = (cast(GETDATE() as date))
-- Pre SQL 2008
DECLARE @CurrentDate DATETIME = DateAdd(Day, Datediff(Day, 0, GetDate()), 0)