Skip to content

Instantly share code, notes, and snippets.

View makomweb's full-sized avatar
🌀

Martin Komischke makomweb

🌀
View GitHub Profile
@makomweb
makomweb / create_changelog.js
Last active December 31, 2015 15:09
Write all the GIT commit messages since the last tag (on the current branch) into a changelog file.
var usage_description = "Usage: node create_changelog.js MyChangelog.txt \"Changelog for nightly build version 0.9.0.1\"";
var args = ParseArguments();
var spawn = require('child_process').spawn;
var fs = require('fs');
var prc = spawn('git', ['describe', '--tags', '--abbrev=0']);
prc.stdout.setEncoding('utf8');
prc.stdout.on('data', function (data) {
var str = data.toString();
var lines = str.split(/(\r?\n)/g);
@makomweb
makomweb / rx_playground.cs
Last active December 17, 2020 10:09
Rx playground. Create a new Rx operator which can be used for processing data. It is parametrizable with a scheduler.
using System;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading.Tasks;
using FluentAssertions;
using NUnit.Framework;
namespace Tests
{
@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 / 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 / type_switch_playground.cs
Created December 9, 2014 10:40
Typeswitch play ground
namespace VisitorTests
{
public interface INt
{
}
public interface INtel
{
}