Skip to content

Instantly share code, notes, and snippets.

View makomweb's full-sized avatar
🌀

Martin Komischke makomweb

🌀
View GitHub Profile
@makomweb
makomweb / csharp_implicit_type_conversion.cs
Last active August 29, 2015 13:56
C# implicit type conversion (see http://msdn.microsoft.com/en-us/library/zk2z37d3.aspx for a more detailed explanation)
public class ImplicitConversionTest
{
public class A
{
public string Member { get; set; }
public static implicit operator string(A self)
{
return self.Member;
}
@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;
}
@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 / 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 / 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 / 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 / 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
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 / gravatar.cs
Last active December 17, 2015 22:48
Gravatar URI fallback extension.
public static class AvatarUriExtensions
{
public static string GetAvatarUri(this User user)
{
return GetAvatarUri(user.AvatarUri, user.Email);
}
/// <summary>
/// Returns the uri or the Gravatar address as a fallback.
/// </summary>
@makomweb
makomweb / wunderlist_account_confirmation.cs
Last active December 18, 2015 04:49
Account confirmation for WL accounts.
[TestFixture]
public class ConfirmAccount
{
private const string _server = "http://www.example.com"
private const string _email = "foo@bar.com";
private const string _password = "12345";
private Client _client;
[SetUp]
public void SetUp()