Skip to content

Instantly share code, notes, and snippets.

View makomweb's full-sized avatar
🌀

Martin Komischke makomweb

🌀
View GitHub Profile
@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()
@makomweb
makomweb / json_with_cpp.cpp
Last active June 2, 2022 16:35
Some fun with JSON serialization/deserialization using C++ REST SDK (Codename "Casablanca").
#include <cpprest/json.h>
#include <sstream>
using namespace std;
typedef web::json::value JsonValue;
typedef web::json::value::value_type JsonValueType;
typedef std::wstring String;
typedef std::wstringstream StringStream;
String JsonValueTypeToString(const JsonValueType& type)
@makomweb
makomweb / wunderlist_login_with_cpp.cpp
Last active December 23, 2015 22:59
Perform a login to Wunderlist's Wunder API using pure C++, parallel patterns library, boost 1.54 and Casablanca C++ REST library
#include <cpprest/json.h>
#include <sstream>
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <iostream>
#include <map>
using namespace std;
using namespace web::http;
using namespace web::http::client;
@makomweb
makomweb / events_in_cpp.cpp
Last active August 2, 2017 08:03
Playing around with C++ events. Very similar to Qt's signal/slot mechanism.
#include <iostream>
#include <stdio.h>
using namespace std;
[event_source(native)]
class Sender
{
public:
__event void SendEvent(int value);
@makomweb
makomweb / pub_sub_cpp.cpp
Last active August 24, 2023 08:13
Fun with C++: implementing a pub/sub scenario using std::bind and other standard facilities. The approach is pretty similar to the well known .NET event mechanism.
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>
#include <memory>
using namespace std;
class EventArgs {
public:
@makomweb
makomweb / deserialize_with_annotations.cs
Last active December 28, 2015 07:39
Deserializing an old scheme with polymorphic types into a new one using .NET facilities. The basic problem is that the XML bears the xsi information inside the Person element which enables the deserializer to create concrete types. This way you can make the deserializer happy about even though you don't need the specific information from the con…
[TestFixture]
public class Deserialize_a_different_scheme
{
[XmlType("Archive")]
public class Archive
{
[XmlType("Person")]
[XmlInclude(typeof(Employee))]
public class Person
{
@makomweb
makomweb / overloaded_ctor_in_ioc_container.cs
Last active December 28, 2015 21:19
In case you have multiple constructors and you still want to take benefit of IoC you should not step into the trap of annotating your preferred constructor, because this makes your library code depend on a specific container implementation. Instead you should search for an alternative approach. Here it is: e.g. Unity's InjectionFactory.
public class FeatureService
{
public FeatureService(string accessToken)
{
// .. ommited internals
}
[InjectionConstructor] // <-- This annotation makes you depend on the IoC container's implementation!
public FeatureService(IFeatureDependency dependency)
{
@makomweb
makomweb / send_message_to_ws_server_and_receive_reply.cs
Last active December 30, 2015 05:59
Send a message to the WS server and receive a reply.
[Fact]
public async Task Getting_an_event_when_connecting_should_succeed()
{
using (var ws = new ReactiveWebSocket("ws://127.0.0.1:8080", true))
{
var man = new WebSocketManager(ws);
man.Send(new Message { Id = Guid.NewGuid().ToString() });
@makomweb
makomweb / datadriven_test_with_xUnit.net.cs
Last active December 31, 2015 03:29
Testing different serializers with xUnit.net.
public class SerializerTests
{
public static IEnumerable<object[]> Serializers
{
get
{
yield return new object[] { new NewtonsoftJson() };
yield return new object[] { new ServiceStackJson() };
}
}