Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
anaisbetts / AsyncReaderWriterLock.cs
Created March 12, 2014 20:45
Async reader/writer lock via abusing ConcurrentExclusiveSchedulerPair
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@markrendle
markrendle / MaybeMonad.cs
Created October 18, 2011 11:25
Maybe Monad in C#
namespace MaybeMonad
{
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
static class Monads
{
/// <summary>
@shiftkey
shiftkey / gist:3337426
Created August 13, 2012 06:30
My Ideal MVVM Framework
Things you need:
- a base implementation of ICommand - for Win8 I'd recommend asynchronous support. For early frameworks I'd say no.
- an interface for messaging between components - current favourite interface is MvvmLight's Messenger
- a base implementation of this messenger
Things you don't need:
- a base implementation of INotifyPropertyChanged - just IL weave and [don't think too hard about it](brendanforster.com/inotifypropertychanged-stop-the-madness.html)
@mikeminutillo
mikeminutillo / AwesomeWeb.cs
Created December 11, 2013 07:23
Create a new Console App, Install all of the Packages (or enable package restore and hand-edit the packages.config file), Create a Web Folder and move your Scripts folder into it, Create Home.html in the root of /Web, mark all of the child files of /Web as Copy Always. Hit F5 and go to your browser for NancyFx, SignalR and static file hosting on…
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Hosting;
using Nancy;
using Nancy.Owin;
using Owin;
using System;
using System.IO;
using System.Reflection;
public class Program
@dgrunwald
dgrunwald / awaitableWPF.cs
Created March 2, 2012 20:30
Awaitable WPF Dispatcher
public static class WpfExtensions
{
public static DispatcherAwaiter GetAwaiter(this Dispatcher dispatcher)
{
return new DispatcherAwaiter(dispatcher, DispatcherPriority.Normal);
}
public static Tuple<Dispatcher, DispatcherPriority> WithPriority(this Dispatcher dispatcher, DispatcherPriority priority)
{
return Tuple.Create(dispatcher, priority);
@SimonCropp
SimonCropp / gist:8485964
Last active April 30, 2016 08:55
Roslyn weaver

Roslyn Weaver

deployed

As a nuget package the same as Fody

Injection into the pipeline

Optionally replace/add cs files to the build pipeline in a similar wat to GFV

@mgravell
mgravell / more awaiting.md
Last active April 20, 2017 07:08
More comparisons of async/await implementations

Objective:

For Task<T> and ValueTask<T> (T=int as a common non-trivial but inlineable case), compare async performance in the synchronous scenario (i.e. where data happens to be buffered - common in deserialization etc code) for 3 implementations:

  • using await throughout
  • using synchronous code until incompleteness detected (via IsCompleted); switch via local async Awaited if needed
  • using synchronous code until incompleteness detected (via IsCompletedSuccessfully); switch via local async Awaited if needed

Note:

@soemarko
soemarko / theme.html
Created November 26, 2011 16:18
embed github gist to tumblr
<!-- Add the following lines to theme's html code right before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="http://static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
<!--
Usage: just add <div class="gist">[gist URL]</div>
Example: <div class="gist">https://gist.github.com/1395926</div>
-->
// Only let input Observable fire every 'n' seconds at most
// but unlike Throttle, items fire immediately when they aren't
// rate-limited.
public IObservable<T> RateLimit<T>(this IObservable<T> This, TimeSpan interval, IScheduler scheduler)
{
var slot = default(IObservable<Unit>);
var input = This.Publish().RefCount();
return input.Window(input, _ => {
if (slot != null) return slot;
@appakz
appakz / countLOC.ps1
Created January 25, 2012 03:13
Quick and dirty powershell script for counting lines in each file of a folder
#Quick and dirty PS script for counting lines of code in a directory. Output is dumped to a simple CSV file.
#Note that this script doesn't count blank lines.
#Parameters:
# path - the path containing the code files (note that the script will recurse through subfolders
# outputFile - fully qualified path of the file to dump the CSV output
# include (Optional) - file mask(s) to include in the count (deafults to *.*)
# exclude (Optional) - file mask(s) to exclude in the count (defaults to none)
# Example (count lines in target path including *.cs but excluding *.designer.cs)
# .\countLOC.ps1 -path "C:\code\MyProject" -outputFile "C:\code\loc.csv" -include "*.cs" -exclude "*.designer.cs"
param([string]$path, [string]$outputFile, [string]$include = "*.*", [string]$exclude = "")