Skip to content

Instantly share code, notes, and snippets.

@jonleigh
jonleigh / 503.json
Created September 1, 2016 11:44
Blog - A Serverless Maintenance Website with S3 and CloudFront
{
"Name": "Platform Maintenance",
"Message": "Please be patient, we'll be back shortly",
"ValidationErrors": []
}
<appSettings>
<!-- Disables EF model validation to allow for zero downtime deploys)-->
<add key="DatabaseInitializerForType Moneybox.Core.Data.MoneyBoxContext, Moneybox.Core" value="Disabled" xdt:Transform="Insert" />
</appSettings>
@jonleigh
jonleigh / select-n+1-fix.cs
Created July 25, 2016 08:20
Blog - EF Perf - Select N+1 Fix
var users = await _db.Users.Include(x => x.Payments).Where().ToListAsync();
foreach (var user in users)
{
foreach (var payment in user.Payments)
{
...
}
}
@jonleigh
jonleigh / select-n+1.cs
Created July 25, 2016 07:58
Blog - EF Perf - Select N+1
var users = await _db.Users.Where(...).ToListAsync();
foreach (var user in users)
{
foreach (var payment in user.Payments)
{
...
}
}
gulp.task('uncss', function () {
return gulp.src([
'assets/styles/main.css'
])
.pipe(uncss({
html: [
'http://localhost:59994/',
'http://localhost:59994/another-url',
...
]
@jonleigh
jonleigh / Bootstrapper.cs
Created July 16, 2016 16:09
NancyFX Performance Boost - Part Deux
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
container.Register<IUserMapper, UserMapper>();
container.Register<IEmailer, Emailer>();
// Any other dependencies you require
}
@jonleigh
jonleigh / Bootstrapper.cs
Created July 16, 2016 16:08
NancyFX Performance Boost - Part 1
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
base.ConfigureApplicationContainer(container);
container.Register<IEmailer, Emailer>();
// Any other dependencies you require
}
@jonleigh
jonleigh / WelcomePartial.cshtml
Last active March 20, 2016 14:04
Blog - RazorMailer Creation - A layout and partial template
@{
Layout = "_WelcomeLayout";
}
<p>Hi @Model.Name,</p>
<p>Welcome to my website.</p>
<p>Have a nose around and let me know what you think!</p>
@jonleigh
jonleigh / RazorMailerTest.cs
Last active April 4, 2016 16:37
Blog - RazorMailer Creation - Simple test
var dispatcher = new Mock<IEmailDispatcher>();
var mailer = new RazorMailer("templates", dispatcher.Object, "hello@sampleapp.com", "SampleApp");
var email = mailer.Create("joe@blogs.com", "WelcomePartial", "Welcome to our service", new WelcomeModel { Name = "Joe Blogs" });
mailer.Send(email);
dispatcher.Verify(x => x.Send(It.IsAny<MailMessage>()), Times.Once);
Assert.Contains("Joe Blogs", email.Body);
@jonleigh
jonleigh / CreateEmail.cs
Last active April 4, 2016 16:38
Blog - RazorMailer Creation - Creating an email
public MailMessage Create<T>(string to, string emailTemplate, string subject, T model)
{
var key = _service.GetKey(emailTemplate);
var body = _service.RunCompile(key, typeof(T), model);
return CreateMailMessage(to, subject, body);
}