Skip to content

Instantly share code, notes, and snippets.

View makomweb's full-sized avatar
🌀

Martin Komischke makomweb

🌀
View GitHub Profile
@makomweb
makomweb / observable_null_vs_empty.cs
Created April 8, 2016 17:00
Observable null vs. empty
public class MyTests
{
public class Package { }
public class Service
{
public IObservable<Package> DeliverRegular()
{
return DeliverRegularAsync().ToObservable();
}
public class LoginExplorations
{
public async Task<DataContracts.List[]> FetchListsAsync(string accessToken, string deviceId)
{
var info = new TestSystemInfo(
userAgent: "Wunderlist.Sdk/" + new AssemblyInfoHelper(typeof (RestClient)).AssemblyVersion,
clientId: "01d4f9dcdafd531da497",
clientProductGitHash: new AssemblyInfoHelper(typeof (RestClient)).InformationalVersion,
clientDeviceId: deviceId,
clientSystem: "Windows RT device",
@makomweb
makomweb / ViewModelBase.cs
Created November 23, 2015 10:28
Updated ViewModelBase
namespace Sandbox
{
public class ExampleViewModel : ViewModelBase
{
public string Title
{
get { return GetValue(() => Title); }
set { SetValue(() => Title, value); }
}
}
@makomweb
makomweb / type_switch_playground.cs
Created December 9, 2014 10:40
Typeswitch play ground
namespace VisitorTests
{
public interface INt
{
}
public interface INtel
{
}
@makomweb
makomweb / ViewModelBase.cs
Last active March 28, 2020 22:22
This is a view model base implementation which can be used in well known MVVM scenarios. It stores all the values in a backing dictionary and accesses it through the property name specified by the lambda expression.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq.Expressions;
namespace Playground {
// Notice the 3 occurrencies of the Title identifier and the abscence of additional backing fields!
public class ExampleViewModel : ViewModelBase {
public string Title {
@makomweb
makomweb / reissue.cs
Created October 9, 2014 08:34
Issue, cancel and reissue async operation
public class WorkerCancellationTests
{
[Test]
public async Task When_running_async_then_result_should_be_true()
{
var worker = new Worker();
var result = await worker.DoAsync(100.Milliseconds());
result.Should().BeTrue();
}
@makomweb
makomweb / rx_cancel.cs
Last active August 29, 2015 14:07
Rx operator which evaluates cancellation
public class RxPlayground
{
public static class MyReactiveExtensions
{
public static IObservable<T> ToCancellable<T>(this IObservable<T> source, CancellationToken cancellationToken)
{
var obj = new ThrowWhenCancelled<T>(source);
cancellationToken.Register(obj.Cancel);
return obj.ToObservable();
}
@makomweb
makomweb / boost_date_time.cpp
Created June 30, 2014 19:41
boost date time UTC versus local time
#include <iostream>
#include <string>
#include "boost/date_time/local_time/local_time.hpp"
#include "boost/date_time/c_local_time_adjustor.hpp"
boost::posix_time::time_duration get_utc_offset(const boost::posix_time::ptime& time_stamp)
{
using boost::posix_time::ptime;
const ptime local_time = boost::date_time::c_local_adjustor<ptime>::utc_to_local(time_stamp);
return local_time - time_stamp;
@makomweb
makomweb / late_binding_playground.cpp
Created June 3, 2014 16:11
Late binding playground
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>
#include <memory>
using namespace std;
using namespace std::placeholders;
class receiver
@makomweb
makomweb / drafted_extension_property.cs
Last active August 29, 2015 13:57
Extension property playground: using a conversion operator
using NUnit.Framework;
namespace Spikes
{
public class Foo
{
public Foo(string name)
{
Name = name;
}