Skip to content

Instantly share code, notes, and snippets.

@distantcam
distantcam / SimpleConfig.cs
Created October 12, 2017 08:57
Simple config class
public static class SimpleConfig
{
static string configFilePath;
public static void InitializeInLocalApplicationData(string name)
{
Initialize(Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
name,
"config.xml"
using System.ComponentModel;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Exporters;
using BenchmarkDotNet.Running;
[MemoryDiagnoser]
[MarkdownExporter]
public class PropertyChangedArgBenchmarks
{
@distantcam
distantcam / CUI.cs
Last active February 14, 2017 04:54
CUI - A simple Console UI
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
using static System.ConsoleColor;
namespace CUI
{
public class ConsoleApplication<TScreen>
using System;
using System.Threading.Tasks;
class Program
{
static void Main()
{
Util.Method(() => ActionMethod());
Util.Method(ActionMethod); // Error CS0121 The call is ambiguous between the following methods or properties: 'Util.Method(Action)' and 'Util.Method(Func<Task>)'
}
@distantcam
distantcam / SequentialWhenAll.cs
Last active February 3, 2016 09:00
An example using `Task.WhenAll` that runs all the tasks on the same thread.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
class Program
{
static void Main()
{
public static class AkavacheExtensions
{
public static IObservable<string> GetOrFetchWithETag(this IBlobCache cache, string url)
{
var result =
// Get from cache
cache.GetObject<string>(url)
// Cached values are true
.Select(x => Tuple.Create(x, true))

Keybase proof

I hereby claim:

  • I am distantcam on github.
  • I am distantcam (https://keybase.io/distantcam) on keybase.
  • I have a public key whose fingerprint is F6C6 9E11 DC61 9DA7 B310 8417 875C C3D7 5421 5F94

To claim this, I am signing this object:

@distantcam
distantcam / DictionaryExtensions.cs
Created November 27, 2013 08:07
Dictionary Extensions
using System;
using System.Linq;
namespace System.Collections.Generic
{
public static class DictionaryExtensions
{
public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, Func<TKey, TValue> valueFactory)
{
TValue v;
@distantcam
distantcam / CecilExtensions.cs
Created August 21, 2013 03:09
Mono.Cecil Extension Methods
public static class CecilExtensions
{
/// <summary>
/// Finds a type within the references of an assembly.
/// </summary>
/// <param name="module">The module to search the references of.</param>
/// <param name="type">The type to look for.</param>
/// <returns>The found type definition, or null if the type is not found.</returns>
/// <example>To find <see cref="System.Object"/> within a module.
/// <code>module.Find(typeof(System.Object));</code>