Skip to content

Instantly share code, notes, and snippets.

View patroza's full-sized avatar

Patrick Roza patroza

View GitHub Profile
#!/bin/bash
command=`basename "$0"`
run-windows-command "$command" "$@"
public static IObservable<TResult> FromTdf<T, TResult>(this IObservable<T> source,
Func<IPropagatorBlock<T, TResult>> blockFactory) => Observable.Create<TResult>(observer => {
var block = blockFactory();
var dsp1 = block.AsObservable().Subscribe(observer.OnNext);
var dsp2 = source.Subscribe(block.AsObserver());
return new CompositeDisposable {dsp2, dsp1};
});
public static IObservable<TResult> FromTdf<T, TResult>(this IObservable<T> source,
IPropagatorBlock<T, TResult> block) => source.FromTdf(() => block);
@patroza
patroza / SpecsFor.cs
Created January 25, 2016 09:07
A slightly improved SpecsFor class
/// <summary>
/// A more closed version of the official SpecsFor class,
/// with some additional helpers
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class SpecsFor<T> : SpecsFor.SpecsFor<T>, IAnd<T> where T : class
{
protected abstract override void Given();
protected abstract override void When();
public sealed override void TearDown() => base.TearDown();
@patroza
patroza / linq.d.ts
Last active September 22, 2015 19:19
declare module 'linq4es2015/linq' {
export default class Linq {
static setExtensions(): void;
static repeat<T>(element: T, count: number): Enumerable<T>;
static range(start: number, count: number): Enumerable<number>;
static empty<T>(): Enumerable<T>;
static asEnumerable<T>(source: T[]): Enumerable<T>;
static aggregate(): any;
static all(): any;
@patroza
patroza / gist:f58e682c5bac47ff5c6f
Created February 1, 2015 12:16
ReactiveProcess
/// <summary>
/// Uses character by character parsing for StandardOutput and StandardError, so \r can be processed.
/// Uses observables instead of eventhandlers. Do not call BeginReadStandardOutput and BeginReadStandardError etc
/// </summary>
public class ReactiveProcess : Process
{
readonly CompositeDisposable _observables;
readonly Subject<string> _standardErrorObserable;
readonly Subject<string> _standardOutputObserable;
readonly ICollection<Action> _transactionCallbacks = new Collection<Action>();
public override int SaveChanges() {
int r;
try {
ExecuteDomainEvents();
r = base.SaveChanges();
} catch (Exception) {
_transactionCallbacks.Clear();
throw;
@patroza
patroza / BaseHub.cs
Last active September 4, 2015 07:08 — forked from lethek/AirtimeHub.cs
Using Mef to inject dependencies into SignalR hubs and manage dependency lifetimes. Currently makes assumptions based on using the request scoped container implementation from https://github.com/sickboy/Heliar-Web-Composition/tree/develop
public abstract class BaseHub : Hub
{
public EventHandler Disposing;
bool _disposed;
protected override void Dispose(bool disposing) {
if (_disposed)
return;
_disposed = true;
public class TestViewModel : ReactiveObject
{
const int _intVal = 1;
public int IntVal { get { return _intVal; } }
ObservableAsPropertyHelper<int> _MyReactiveVal;
public int MyReactiveVal
{
get { return _MyReactiveVal.Value; }
}
@patroza
patroza / gist:4031046
Created November 7, 2012 11:48
Initialize First RXUI Object on UI Thread
// Workaround for RXUi, first object initialization must be on UI Thread
private class DummyModel : BindableBase
{
private ObservableAsPropertyHelper<string> _propertyHelper;
public string PropertyHelper
{
get { return _propertyHelper.Value; }
}
private string _Name;
Type: System.Exception
Message: An OnError occurred on an object (usually ObservableAsPropertyHelper) that would break a binding or command. To prevent this, Subscribe to the ThrownExceptions property of your objects
Source: ReactiveUI
TargetSite: Void <.cctor>b__2()
Data: System.Collections.ListDictionaryInternal
RubyMessage: An OnError occurred on an object (usually ObservableAsPropertyHelper) that would break a binding or command. To prevent this, Subscribe to the ThrownExceptions property of your objects
Inner Exception:
Type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: System