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>
@willurd
willurd / web-servers.md
Last active April 26, 2024 18:00
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@PeteGoo
PeteGoo / Global.asax.cs
Created April 9, 2012 00:24
ProtobufNetFormatter for Web API
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
@danielmarbach
danielmarbach / SafeObservableCollection
Created May 17, 2011 18:18
Thread safe observable collection
[DebuggerDisplay("Count = {Count}")]
[ComVisible(false)]
public class SafeObservableCollection<T> : ObservableCollection<T>
{
private readonly Dispatcher dispatcher;
public SafeObservableCollection()
: this(Enumerable.Empty<T>())
{
}