Skip to content

Instantly share code, notes, and snippets.

@geirsagberg
geirsagberg / recursiveDelete.js
Created June 8, 2016 09:18
Immutable recursive delete
function rec (state, key) {
return state.update(function (current) {
return current.delete(key).map(function (item) {
return Iterable.isIterable(item) ? rec(item, key) : item
});
});
}
function recursiveDelete (state, key) {
return state.update(function (current) {
@geirsagberg
geirsagberg / PropertyInjectionDisabler.cs
Created August 11, 2016 09:06
Disable property injection in LightInject
internal class PropertyInjectionDisabler : IPropertyDependencySelector
{
public IEnumerable<PropertyDependency> Execute(Type type)
{
return new PropertyDependency[0];
}
}
@geirsagberg
geirsagberg / MigrationExtensions.cs
Created September 12, 2016 09:46
Extensions to fluent migrator
internal static class MigrationExtensions
{
internal const string IdColumnName = "Id";
public static ICreateTableColumnOptionOrWithColumnSyntax WithIdColumn(this ICreateTableWithColumnSyntax syntax) => syntax
.WithColumn(IdColumnName)
.AsInt32()
.NotNullable()
.PrimaryKey()
.Identity();
@geirsagberg
geirsagberg / transactionfactory.cs
Created September 30, 2016 07:40
TransactionFactory for ambient transactions
public class TransactionFactory : ITransactionFactory
{
public ITransaction BeginTransaction(TransactionScopeOption option = TransactionScopeOption.Required, IsolationLevel isolationLevel = IsolationLevel.Unspecified)
{
var currentTransaction = System.Transactions.Transaction.Current;
if (currentTransaction != null && option == TransactionScopeOption.Required)
{
if (isolationLevel == IsolationLevel.Unspecified || currentTransaction.IsolationLevel == isolationLevel)
isolationLevel = currentTransaction.IsolationLevel;
else
@geirsagberg
geirsagberg / MockObjectSet.cs
Created October 26, 2016 12:13
Mock of IObjectSet
public class MockObjectSet<T> : IObjectSet<T> where T : class
{
private readonly ICollection<T> _collection = new List<T>();
public MockObjectSet()
{
}
public MockObjectSet(ICollection<T> collection)
{
// Somewhere in assembly
[assembly: AspMvcViewLocationFormat(@"~\Features\{1}\{0}.cshtml")]
[assembly: AspMvcViewLocationFormat(@"~\Features\Shared\{0}.cshtml")]
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(o => {
o.Conventions.Add(new FeatureConvention());
public static class HostingEnvironmentExtensions
{
public static void UseRootNodeModules(this IHostingEnvironment hostingEnvironment)
{
var nodeDir = Path.Combine(hostingEnvironment.ContentRootPath, "../node_modules");
Environment.SetEnvironmentVariable("NODE_PATH", nodeDir);
}
}
@geirsagberg
geirsagberg / Container.tsx
Last active September 27, 2017 17:48
React Redux boilerplate
import React from 'react'
class Container extends React.Component {
render () {
return (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<h1>Submission</h1>
<input type="text" placeholder="First name" />
<input type="text" placeholder="Last name" />
<input type="text" placeholder="Title" />
{
"version": 8,
"name": "Positron",
"metadata": {
"mapbox:autocomposite": false,
"mapbox:type": "template",
"mapbox:groups": {
"b6371a3f2f5a9932464fa3867530a2e5": {
"name": "Transportation",
"collapsed": false
app.Use(async (context, next) =>
{
try
{
await next();
}
catch (Exception ex)
{
context.Response.Clear();
context.Response.StatusCode = 500;