Skip to content

Instantly share code, notes, and snippets.

View khellang's full-sized avatar

Kristian Hellang khellang

View GitHub Profile
AppDomainAssemblyTypeScanner.DefaultAssembliesToScan = new Func<Assembly, bool>[]
{
x => x == typeof(NancyEngine).Assembly,
x => ShouldReference(x)
};
public static bool ShouldReference(Assembly assembly)
{
var assemblyName = assembly.GetName().Name;
public class PasswordHash
{
private const int SaltSize = 10;
private const int HashSize = 40;
private const int Iterations = 10000;
private PasswordHash(byte[] hashBytes, byte[] saltBytes)
{
public class AppSettings : IAppSettings
{
private readonly ConcurrentDictionary<string, object> _cachedValues = new ConcurrentDictionary<string, object>();
private readonly Func<ISettingsRepository> _repositoryFactory;
public AppSettings(Func<ISettingsRepository> repositoryFactory)
{
_repositoryFactory = repositoryFactory;
}
// Before:
public static class StringExtensions
{
public static string Join(this string separator, params string[] values)
{
return Join(separator, values.AsEnumerable());
}
public static string Join(this string separator, IEnumerable<string> values)
{
@khellang
khellang / iffe.md
Last active January 3, 2016 20:59
IFFE termination

IIFE Termination

If you don't care about the return value of the IIFE, it could be any of the following:

!function(){}();  // => true
~function(){}(); // => -1
+function(){}(); // => NaN
-function(){}();  // => NaN

Let's explore this a bit more.

public class MyModule : NancyModule
{
public MyModule()
{
Post["/scores"] = _ =>
{
var queries = this.Bind<IEnumerable<QueryParameters>>();
return queries.Select(GetResult);
}
public static class RequestExtensions
{
public static bool IsLocal(this Request request)
{
var remoteAddress = request.UserHostAddress;
if (string.IsNullOrEmtpy(remoteAddress))
{
return false;
}
public class ExampleUsage
{
private readonly IPasswordHasher _hasher;
public ExampleUsage(IPasswordHasher hasher)
{
_hasher = hasher;
}
public void Register(string username, string password)
public class DemoBoostrapper : DefaultNancyBootstrapper
{
protected override NancyInternalConfiguration InternalConfiguration
{
get
{
return NancyInternalConfiguration.WithOverrides(x => x.StatusCodeHandlers.Clear());
}
}
}
public class YsodStatusCodeHandler : IStatusCodeHandler
{
public bool HandlesStatusCode(HttpStatusCode statusCode, NancyContext context)
{
return statusCode == HttpStatusCode.InternalServerError;
}
public void Handle(HttpStatusCode statusCode, NancyContext context)
{
object error;