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
@liammclennan
liammclennan / blog_backbone_app_framework.md
Created July 12, 2012 01:39
A Backbone Application Framework

Backbone is a library of tools that simplify the design and implementation of client-side web applications. It is explicitly not a framwework. Backbone does not provide guidance about how to assemble an application. This post will be an initial attempt at filling that gap. It assumes an intermediate level of Backbone.js knowledge. If you have never used Backbone.js try Backbone.js Basics or the Backbone.js homepage.

The Application Root

I like to provide a root object/namespace for my application. Let's call it app.

var app = {};

Register Components on the Application Object

@lucamilan
lucamilan / gist:2898045
Created June 8, 2012 20:43
Web.Config Mail Settings Section
<system.net>
<mailSettings>
<smtp from="X" deliveryMethod="Network">
<network defaultCredentials="false"
host="smtp.gmail.com"
port="587"
userName="username"
password="pwd"
enableSsl="true" />
</smtp>
@PaulStovell
PaulStovell / Edit.cshtml
Created April 13, 2012 19:19
How can I clean up this simple ASP.NET MVC pattern?
@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.Select(c => new SelectListItem { Value = c.Id, Text = c.Name })
@lucamilan
lucamilan / gist:2304623
Created April 4, 2012 18:41 — forked from Buthrakaur/gist:1613003
NHibernate QueryOver.List extension to support casting to anonymous types
public static IList<TRes> ListAs<TRes>(this IQueryOver qry, TRes resultByExample)
{
var ctor = typeof (TRes).GetConstructors().First();
return qry.UnderlyingCriteria
.SetResultTransformer(Transformers.AliasToBeanConstructor(ctor))
.List<TRes>();
}
[Fact]
public void ListAs_Should_CastQueryOverResultToTypeSameAsSupliedExampleInstance()
@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;
}
@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 () {
@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"/>
@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;
}
@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
@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;