Skip to content

Instantly share code, notes, and snippets.

View lucamilan's full-sized avatar
🏠
Working from home

Luca Milan lucamilan

🏠
Working from home
View GitHub Profile
@JoshClose
JoshClose / Audit.sql
Created November 15, 2011 04:02
Audit Trail with NHibernate Using a Custom log4net Appender
CREATE TABLE [dbo].[Audit]
(
[Id] INT NOT NULL IDENTITY,
[User] NVARCHAR( 100 ) NOT NULL,
[Trail] NVARCHAR( MAX ) NOT NULL,
[Created] DATETIME NOT NULL
)
ALTER TABLE [dbo].[Audit]
ADD CONSTRAINT [PK_Audit_Id]
@JoshClose
JoshClose / ScreenShot.cs
Created November 15, 2011 05:38
Programmatically Taking a Full Web Page Screenshot
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class ScreenShot
{
[ComImport]
[InterfaceType( ComInterfaceType.InterfaceIsIUnknown )]
[Guid( "0000010d-0000-0000-C000-000000000046" )]
@JoshClose
JoshClose / File1.cs
Created November 15, 2011 15:02
ASP.NET MVC, Ninject.Web.Mvc and 404’s
protected void Application_Error( object sender, EventArgs e )
{
var exception = Server.GetLastError();
Response.Clear();
var httpException = exception as HttpException;
var routeData = new RouteData();
routeData.Values.Add( "controller", "Error" );
@nberardi
nberardi / SequentialNumberGenerator.cs
Created January 19, 2012 17:39
Sequential Number Generator for RavenDB
private static readonly object GeneratorLock = new object();
///<summary>
/// Create the next id (numeric)
///</summary>
private int NextAccountNumber()
{
lock (GeneratorLock)
{
using (new TransactionScope(TransactionScopeOption.Suppress))
@nul800sebastiaan
nul800sebastiaan / InitContentController.cs
Created February 13, 2012 15:46
Creating a content node in Umbraco v5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Umbraco.Cms.Web.Model.BackOffice.Editors;
using Umbraco.Framework;
using Umbraco.Framework.Context;
using Umbraco.Framework.Persistence.Model;
using Umbraco.Framework.Persistence.Model.Attribution.MetaData;
using Umbraco.Framework.Persistence.Model.Constants;
@rdingwall
rdingwall / DropAllRavenDatabases.bat
Created February 29, 2012 13:15
Fast Raven DB sandbox database helpers
@echo off
rem Warning: this batch file deletes ALL Raven DB data and databases, leaving you with a totally empty (but ready to use) Raven DB instance.
net stop RavenDB
rd /S /Q C:\RavenDB\Server\Data
rd /S /Q C:\RavenDB\Server\Tenants
net start RavenDB
@haacked
haacked / ServiceResolverAdapter.cs
Created March 11, 2012 19:34
ServiceResolverAdapter: Allows you to use the ASP.NET MVC DependencyResolver for ASP.NET Web API
public class ServiceResolverAdapter : IDependencyResolver
{
private readonly System.Web.Mvc.IDependencyResolver dependencyResolver;
public ServiceResolverAdapter(System.Web.Mvc.IDependencyResolver dependencyResolver)
{
if (dependencyResolver == null) throw new ArgumentNullException("dependencyResolver");
this.dependencyResolver = dependencyResolver;
}
@leegould
leegould / CommandLineArgs.cs
Created March 13, 2012 10:24
Command Line Args
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace CommandLineUtils
{
/// <summary>
/// Arguments class.
/// </summary>
/// <seealso cref="http://www.codeproject.com/Articles/3111/C-NET-Command-Line-Arguments-Parser"/>
@SlyNet
SlyNet / gist:2036300
Created March 14, 2012 13:01
Making asp.net validation work with twitter bootstrap
$.validator.setDefaults({
highlight: function (element) {
$(element).closest(".control-group").addClass("error");
},
unhighlight: function (element) {
$(element).closest(".control-group").removeClass("error");
}
});
$(function () {
$('span.field-validation-valid, span.field-validation-error').each(function () {
@NOtherDev
NOtherDev / gist:2274614
Created April 1, 2012 11:00
Strongly typed and well-controlled links within ASP.NET MVC areas
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class LinkWithinAreaAttribute : Attribute
{
public string AreaName { get; private set; }
public string OrSwitchTo { get; set; }
public LinkWithinAreaAttribute(string areaName)
{
AreaName = areaName;
}