Instantly share code, notes, and snippets.

View StringTrimmerInterceptor.cs
using System.Data.Entity;
using System.Data.Entity.Core.Common.CommandTrees;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure.Interception;
using System.Linq;
namespace gist
{
/// Adapted from https://stackoverflow.com/questions/20133696/how-can-i-configure-entity-framework-to-automatically-trim-values-retrieved-for/27504530#27504530
View DbContextExtensions.cs
using System.Data.Entity;
using System.Reflection;
namespace gist
{
public static class DbContextExtensions
{
public static string GetProviderName(this DbContext context)
{
var internalContextProperty = context.GetType().GetProperty("InternalContext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
View WindowsAuthorizationMiddleware.cs
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.Owin;
// ReSharper disable once CheckNamespace
namespace Owin
{
public static class WindowsAuthorizationAppBuilderExtensions
View install_mono_workarounds.sh
#!/bin/bash -e -x
# For System.Data.SQLite to work on Mono, see https://stackoverflow.com/questions/21293105/system-dllnotfoundexception-on-mono-sqlite/43173220#43173220
function Install_libSQLiteInterop
{
SQLITE_VERSION=1.0.108.0
SQLITE_DYLIB=sqlite-netFx-source-${SQLITE_VERSION}/bin/2013/Release/bin/libSQLite.Interop.dylib
pushd ~/Downloads
if [ ! -f "${SQLITE_DYLIB}" ]; then
View ForEachAsync.cs
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Parallel
{
public static class EnumerableExtensions
{
View DbEntityValidationException.cs
public partial class MyContext
{
// Adapted from https://blogs.infosupport.com/improving-dbentityvalidationexception/
public override Task<int> SaveChangesAsync()
{
try
{
return base.SaveChangesAsync();
}
catch (DbEntityValidationException exception)
View generate_storyboard_constants.py
#!/usr/bin/env python
# Adapted from https://joris.kluivers.nl/blog/2014/02/10/storyboard-identifier-constants/ (https://github.com/kluivers/storyboard-constants)
# * Support for accessibility identifiers and accessibility labels
# * Easily extendable with xpath definitions
# * Valid identifiers
# * Namespaced constants, idea from https://www.mikeash.com/pyblog/friday-qa-2011-08-19-namespaced-constants-and-functions.html
PREFIX = ''
SPACING = '\t'
View Emoji.json
{
"People" : [
"😀",
"😃",
"😄",
"😁",
"😆",
"😅",
"😂",
"🤣",
View ActuallyLocalizedStringForStatusCode.m
#import <Foundation/Foundation.h>
static NSString * _Nonnull ActuallyLocalizedStringForStatusCode(NSInteger statusCode)
{
static NSBundle *cfNetworkBundle;
static dispatch_once_t once;
dispatch_once(&once, ^{
cfNetworkBundle = [NSBundle bundleForClass:NSHTTPURLResponse.class];
});
NSString *httpError = [NSHTTPURLResponse localizedStringForStatusCode:statusCode];
View FromHeader.cs
using System;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Metadata;