Skip to content

Instantly share code, notes, and snippets.

/**
* Unexpeced readline behavior in node.js:
*
* Let the first prompt time out
* Enter a value in the second prompt
* Enter a value in the third prompt
* The third prompt should hang and time out (unless terminal is set to false)
*
* Even without the abort at all it has the same behavior, not processing input.
* Setting terminal to `false` in createInterface() makes it work as expected
@swax
swax / EntityFramwork DbModelStore for loading cached db models.cs
Last active March 18, 2017 23:01 — forked from davidroth/EntityFramwork DbModelStore for loading cached db models.
EntityFramwork DbConfiguration with custom DbModelStore for loading cached db models. Fork: Instead of invalidating based on date, this version invalidates based on the hash of the model assembly.
public class MyContextConfiguration : DbConfiguration
{
public MyContextConfiguration()
{
HashedDbModelStore cachedDbModelStore = new HashedDbModelStore(MyContext.EfCacheDirPath); // possibly c:\temp\efcache
IDbDependencyResolver dependencyResolver = new SingletonDependencyResolver<DbModelStore>(cachedDbModelStore);
AddDependencyResolver(dependencyResolver);
}
/// <summary>
@swax
swax / book.md
Last active October 3, 2016 23:35
stuff

Style

Return early, hot potato

Treat the running procss like a hot potato. You want to minimize how much time the process spends in your function to minimize hitting any landmines. The longer something lives, the more errors accumulate.

Minimize nesting

Returning early lends itself well to minimizing nesting. Instead of handling a success condition in a nested if statement. Return early or throw an exception early for an error condition so you don't have to nest the success condition at all. Nested code is harder to read and by nature more complicated than small simple if conditions. The top of a f