Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Threading.Tasks;
namespace System.Collections.Concurrent
{
public static class ConcurrentDictionaryExtensions
{
/// <summary>
/// Provides an alternative to <see cref="ConcurrentDictionary{TKey, TValue}.GetOrAdd(TKey, Func{TKey, TValue})"/> that disposes values that implement <see cref="IDisposable"/>.
/// </summary>
@attilah
attilah / X.Y.Z.Sources.csproj
Last active April 18, 2024 08:52
X.Y.Z.Sources nuget package
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
<IsPackable>true</IsPackable>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>contentFiles</ContentTargetFolders>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
public class BetterDefaultModelBinder : DefaultModelBinder
{
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
{
var model = base.CreateModel(controllerContext, bindingContext, modelType);
if (model == null || model is IEnumerable)
return model;
foreach (var property in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
@davidfowl
davidfowl / gist:4015810
Created November 5, 2012 07:33
Detect ASP.NET shutdown
internal class ShutdownDetector : IRegisteredObject, IDisposable
{
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
private Timer _checkAppPoolTimer;
private static readonly TimeSpan _appPoolCheckInterval = TimeSpan.FromSeconds(10);
public CancellationToken Token
{
get { return _cts.Token; }
}
@benfoster
benfoster / gist:3905658
Created October 17, 2012 14:01
jQuery UI Autocomplete, Twitter Bootstrap Style
.ui-autocomplete {
position: absolute;
cursor: default;
list-style: none;
display: block;
outline: none;
padding: 5px 0;
margin: 2px 0 0;
background-color: @dropdownBackground;
border: 1px solid #ccc; // Fallback for IE7-8
@drusellers
drusellers / flow.sh
Created July 24, 2012 16:52
git flow
#git is aliased as 'g'
#g co == git checkout
#g c = git commit -m
#g rom = git rebase origin/master
g clone <your repo>
g co -b feature-branch
#work
#work
@e-tobi
e-tobi / StronglyTypedDocumentQueryExtensions.cs
Created May 10, 2012 11:26
type safe RavenDb Advanced.LuceneQuery
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Raven.Abstractions.Data;
namespace Raven.Client
{
public static class StronglyTypedDocumentQueryExtensions
{
@staxmanade
staxmanade / Where.ps1
Created April 5, 2012 03:23 — forked from ferventcoder/Where.ps1
Somebody's where.exe implementation as powershell ;)
function where-is($command) {
(ls env:\path).Value.split(';') | `
where { $_ } | `
%{ [System.Environment]::ExpandEnvironmentVariables($_) } | `
where { test-path $_ } |`
%{ ls "$_\*" -include *.bat,*.exe,*cmd } | `
%{ $file = $_.Name; `
if($file -and ($file -eq $command -or `
$file -eq ($command + '.exe') -or `
$file -eq ($command + '.bat') -or `
@DerAlbertCom
DerAlbertCom / blendfix.bat
Created November 24, 2011 17:06
Fixes Expression Blend 4 crashes on startup when you have installed .NET Framework 4.5 Developer Preview
cd %windir%\Microsoft.NET\Framework\v4.0.30319
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Blend.dll"
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Code.dll"
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.DesignModel.dll"
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.DesignSurface.dll"
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Extensibility.Designer.dll"
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Extensibility.dll"
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Extensibility.Project.dll"
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Framework.dll"
ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Importers.dll"
@jsadeli
jsadeli / RootBindingExtension.cs
Created July 15, 2011 14:37
XAML markup extension to bind directly to root object's datacontext
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Markup;
using System.Xaml;
namespace YourNamespace.MarkupExtensions