This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class You { | |
private ICar myCar; | |
public You(ICar car) | |
{ | |
myCar = car; | |
} | |
public void Drive(IList<Person> passengers, Location destination) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class You { | |
private Car myCar = new Car(); | |
public void Drive(IList<Person> passengers, Location destination) | |
{ | |
foreach (var passenger in passengers) | |
myCar.AddPassenger(passenger); | |
myCar.Drive(destination); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void Application_EndRequest() | |
{ | |
// Make sure to dispose of NHibernate session if created on this web request | |
ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void Application_Start() | |
{ | |
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory()); | |
ObjectFactory.Initialize(x => | |
{ | |
// ISessionFactory is expensive to initialize, so create it as a singleton. | |
x.For<ISessionFactory>() | |
.Singleton() | |
.Use(CreateSessionFactory()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ISessionFactory CreateSessionFactory() | |
{ | |
return Fluently.Configure() | |
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(c => c.FromConnectionStringWithKey("InsertConnectionString"))) | |
.Mappings(m => | |
{ | |
// Include both standard NHibernate mapping files and Fluent NHibernate mapping files | |
m.HbmMappings.AddFromAssemblyOf<User>(); | |
m.FluentMappings.AddFromAssemblyOf<User>(); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void Application_Start() | |
{ | |
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StructureMapControllerFactory : DefaultControllerFactory | |
{ | |
public override IController CreateController(RequestContext requestContext, string controllerName) | |
{ | |
try | |
{ | |
var controllerType = base.GetControllerType(requestContext, controllerName); | |
return ObjectFactory.GetInstance(controllerType) as IController; | |
} | |
catch (Exception) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// square root of n with Newton-Raphson approximation | |
r = n / 2; | |
while ( abs( r - (n/r) ) > t ) { | |
r = 0.5 * ( r + (n/r) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r = n / 2; // Set r to n divided by 2 | |
// Loop while r - (n/r) is greater than t | |
while (abs( r - (n/r) ) > t) { | |
r = 0.5 * ( r + (n/r) ); // Set r to half of r + (n/r) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Greed is a dice game where you roll up to five dice to accumulate | |
# points. The following "score" function will be used to calculate the | |
# score of a single roll of the dice. | |
# | |
# A greed roll is scored as follows: | |
# | |
# * A set of three ones is 1000 points | |
# | |
# * A set of three numbers (other than ones) is worth 100 times the | |
# number. (e.g. three fives is 500 points). |
NewerOlder