Skip to content

Instantly share code, notes, and snippets.

View MarcelMalik's full-sized avatar

Marcel MarcelMalik

View GitHub Profile
@robfe
robfe / Extensions.cs
Created October 11, 2010 08:45
ObservePropertyChanged extension method (INotifyPropertyChanged.Property => IObservable)
public static class Extensions
{
public static IObservable<TProperty> ObservePropertyChanged<TNotifier, TProperty>(
this TNotifier notifier,
Expression<Func<TNotifier, TProperty>> propertyAccessor,
bool startWithCurrent = false)
where TNotifier : INotifyPropertyChanged
{
// Parse the expression to find the correct property name.
public static class HttpClientRxMixins
{
public static IObservable<T> RequestAsync<T>(this HttpClient This, string requestUri)
{
return This.GetAsync(requestUri).ToObservable()
.ThrowOnRestResponseFailure()
.SelectMany(x => x.Content.ReadAsStringAsync().ToObservable())
.SelectMany(x => JsonConvert.DeserializeObjectAsync<T>(x).ToObservable());
}
using System;
using ReactiveUI.Routing;
using ReactiveUI.Xaml;
namespace ReactiveUI.Samples.Routing.ViewModels
{
public interface IWelcomeViewModel : IRoutableViewModel
{
ReactiveCommand HelloWorld { get; }
}
@DamianEdwards
DamianEdwards / gist:4030394
Created November 7, 2012 09:31
Async site scraping in ASP.NET 4.5
public class SiteScrape : HttpTaskAsyncHandler
{
public override async Task ProcessRequestAsync(HttpContext context)
{
using (var http = new HttpClient())
{
var downloadTasks = new List<Task<string>> {
http.GetStringAsync("http://bing.com"),
http.GetStringAsync("http://google.com"),
http.GetStringAsync("http://oredev.org"),
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Text;
using System.Threading;
public IObservable<Unit> CreateRecursive(string path)
{
var paths = path.Split('\\');
var firstFolderThatExists = Observable.Range(0, paths.Length - 1)
.Select(x =>
StorageFolder.GetFolderFromPathAsync(String.Join("\\", paths.Take(paths.Length - x)))
.ToObservable()
.LoggedCatch(this, Observable.Empty<StorageFolder>()))
.Concat()
@anaisbetts
anaisbetts / KeyedOperationQueue.cs
Last active December 10, 2015 10:39
A non-blocking version of @praeclarum's SqliteAsync.cs using Rx
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using ReactiveUI;
namespace Akavache.Sqlite3
@DamianEdwards
DamianEdwards / gist:4499713
Created January 10, 2013 05:37
SignalR chat using Knockout sync models idea
<form data-bind="submit: sendMessage">
<input type="text" data-bind="value: newMessage" />
<input type="submit" value="Send" />
</form>
<ul data-bind="foreach: messages">
<li data-bind="text: $data"></li>
</ul>
<script src="Scripts/jquery-1.8.3.js"></script>
@DamianEdwards
DamianEdwards / ChatHub.cs
Created January 10, 2013 06:10
SignalR peer-to-peer using class-less hubs idea
// This hub is optional, it's not required for the client to work.
// The client's call to "all.newMessage" will result in this Hub's
// NewMessage method being called so it can persist the message.
public class Chat : Hub
{
public void NewMessage(string message)
{
MyDataLayer.SaveMessage(message);
}
}
@grenade
grenade / robocopy.ps1
Last active March 12, 2024 15:22
Wrap robocopy in powershell to get standard (0/1) exit codes.
<#
.Synopsis
Robocopy wrapper with standard 0 (success) and 1 (failure) exit codes.
.Parameter source
Defines the source folder
.Parameter target
Defines the target folder
.Parameter include
Defines the files to include. Accepts wildcards. Eg: -include *.dll,*.pdb
Optional, Default value is $null and will include all files from source.