Skip to content

Instantly share code, notes, and snippets.

View brendanjerwin's full-sized avatar

Brendan Erwin brendanjerwin

View GitHub Profile
@brendanjerwin
brendanjerwin / example_usage.rb
Created February 27, 2009 13:42
A super-simple "ORM" (Object Row Mapper)
require 'simple_entity'
#Example Usage
obj = SimpleEntity.new("SELECT * FROM Payers WHERE PayerID = 'dg8gfb01-fgba-48ge-be5d-02d5dfg9hh7d'")
puts obj.PayerName + "\n\n"
puts obj.inspect #See all the columns
@brendanjerwin
brendanjerwin / gist:72872
Created March 2, 2009 17:25
A better approach than loading associations into ViewData
//Loading associations into ViewData
public ActionResult Edit(Guid id)
{
var model = Repositories.Model.GetById(id);
ViewData["Association"] = model.Association; //Gah! Magic Strings
return View(model);
}
//In the view:
Html.Grid<AssociationType>(
@brendanjerwin
brendanjerwin / gist:73141
Created March 3, 2009 02:26
CSS for embedding fonts in Internet Explorer and good browsers too.
<!--[if !IE]><!-->
<style type="text/css" media="screen, print">
@font-face {
font-family: "My Custom Font";
src: url("http://brendanjerwin.github.com/VeraMono.ttf");
}
</style>
<!-- <![endif]-->
<!--[if IE]>
@brendanjerwin
brendanjerwin / gist:77853
Created March 12, 2009 01:14
Initializing both Fluent NHibernate and NHibernate Validator
private static ISessionFactory ConfigureNHibernate(IPersistenceConfigurer databaseConfigurer,
out ValidatorEngine validatorEngine,
NHibernate.Cfg.Configuration cfg)
{
ValidatorEngine ve = null;
var factory = Fluently.Configure(cfg)
.Database(databaseConfigurer)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<PatientMap>())
.ExposeConfiguration(c =>
{
@brendanjerwin
brendanjerwin / Configuration.cs
Created March 12, 2009 01:52
A configuration class I use to configure my applications at startup.
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Validator.Cfg;
using NHibernate.Validator.Engine;
using StructureMap;
using StructureMap.Attributes;
namespace Models.Data.Util
@brendanjerwin
brendanjerwin / gist:77865
Created March 12, 2009 01:58
An example of using the Configuration class with an In-Memory SQLite DB
[TestFixtureSetUp]
public void FixtureSetUp()
{
Configuration cfg;
Models.Data.Util.Configuration.ConfigureDataAccess(SQLiteConfiguration.Standard.InMemory(),
InstanceScope.Singleton, out cfg);
session = ObjectFactory.GetInstance<ISession>();
IDbConnection connection = session.Connection;
@brendanjerwin
brendanjerwin / anonymous_generic.cs
Created March 19, 2009 04:42
An example of a neat trick to get a generic to work with an anonymous type.
using System;
namespace TestAnonymousGeneric
{
internal class MyClass<T>
{
public T val { get; set;}
public static MyClass<ET> Build<ET>(ET valValue)
{
using System;
namespace TestAnonymousGeneric
{
internal static class MyClass
{
public static MyClass<ET> Build<ET>(ET valValue)
{
return new MyClass<ET> { val = valValue };
@brendanjerwin
brendanjerwin / create_update_script.cs
Created March 19, 2009 17:06
An example of how to get NHibernate to spit out database schema update scripts.
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using NHibernate.Dialect;
using NHibernate.Tool.hbm2ddl;
using StructureMap.Attributes;
using System;
namespace Machine.Specifications.Example
{
[Subject(typeof(Account), "Funds transfer")]
public class when_transferring_between_two_accounts
: with_from_account_and_to_account
{
Because of = () =>
fromAccount.Transfer(1m, toAccount);