Skip to content

Instantly share code, notes, and snippets.

View clemensv's full-sized avatar
🏠
Working from home

Clemens Vasters clemensv

🏠
Working from home
View GitHub Profile
@clemensv
clemensv / gist:4655204
Last active December 11, 2015 20:28
Service Bus Notification Hubs with Windows 8 and Templates. Toasts and Live Tile. Either or both. With peek and pictures. One input message.
async Task InitNotificationsAsync()
{
await notificationHub.RefreshRegistrationsAsync();
if (!await notificationHub.RegistrationExistsForApplicationAsync("myUrgentToast"))
{
await notificationHub.CreateTemplateRegistrationForApplicationAsync(
CreateToastTemplate(), "myUrgentToast", new string[]{"urgent", "alert"});
}
@clemensv
clemensv / gist:4967845
Created February 16, 2013 17:37
Versatile way to wrap, mock and partially override message senders in SB
using Microsoft.ServiceBus.Messaging;
using System;
using System.Collections.Generic;
namespace MockMessageSender
{
public class MutableMessageSender
{
public delegate void _Send(BrokeredMessage message);
@clemensv
clemensv / sqlfiltersandrules.cs
Created February 21, 2013 12:35
I should talk about this more. SQL filters and rules on Service Bus Topics subscriptions. SQL action syntax http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.messaging.sqlruleaction.sqlexpression.aspx
namespace SqlFiltersAndRules
{
using System;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
class Program
{
static void Main(string[] args)
{
@clemensv
clemensv / gist:6367476
Created August 28, 2013 15:38
Tiny web service switching an LED made based on https://github.com/sirleech/Webduino
/* Tiny web service switching an LED made based on https://github.com/sirleech/Webduino */
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#define DEBUG
static uint8_t mac[6] = { 0x90, 0xA2, 0xDA, 0x0D, 0xBC, 0xAE };
static uint8_t ip[4] = { 192, 168, 2, 107 };
@clemensv
clemensv / gist:6554605
Last active April 6, 2018 03:16
using Task.WhenAny to drive a pump of multiple async operations in the same context (such as an I/O pump)
/*
Example use (from an email I sent)
I’m using WhenAny to either register for a callback on any of the pending operations and to use
the IO thread that comes up with their respective completion or to execute handling of completed
work on the current thread (‘borrowing’ the IO thread).
So if I read from a socket and from a queue, first both ops hang. Queue read completes and I get
called back on an IO thread which continues the await. I process that completion in the loop.
Meanwhile the socket read completes. That IO thread pops up and just registers the fact that it’s
“What was the deal with the Halloween Documents?”
* I can also sell you a very fine 1998 Ford F-150. My team is committing to Apache
Qpid Proton. Maybe go talk to the NodeJS folks.
“So, when is the last time you hacked on a project in Visual Studio?”
* Yesterday. I'm writing this at breakfast.
“Do you have code on GitHub?” (GitHub, not CodePlex)
@clemensv
clemensv / azureobd
Created December 12, 2013 13:50
azureobd startup script to be placed into init.d replace {KEY}, {NAMESPACE}, and {QUEUE}
#! /bin/bash
### BEGIN INIT INFO
# Provides: azureobd
# Required-Start: $remote_fs $syslog $network $all
# Required-Stop: $remote_fs $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start AzureOBD at boot time
# Description: Start AzureOBD at boot time.
### END INIT INFO
@clemensv
clemensv / gist:9953010
Last active January 3, 2017 14:11
However often you call me, I'm only going to flush every 200msec from the first flush call
Task flushingTask = null;
public override Task FlushAsync(CancellationToken cancellationToken)
{
Interlocked.CompareExchange(
ref flushingTask,
Task.Delay(200, cancellationToken).ContinueWith(
async (t) =>
{
await write.FlushAsync(cancellationToken);
@clemensv
clemensv / gist:10841337
Last active August 29, 2015 13:59
Cross-AppDomain Marshaling friendly TPL wrappers for APM
//FromAsync variant that can be used with APM across M<arshaling boundaries (you make your own TArgX overloads, please)
static class MarshalTask
{
public static Task<TResult> FromAsync<TArg1, TArg2, TResult>(Func<TArg1, TArg2, AsyncCallback, object, IAsyncResult> beginFunc, Func<IAsyncResult, TResult> endFunc, TArg1 arg1, TArg2 arg2)
{
var cp = new Completer<TResult>(endFunc);
var tcs = new TaskCompletionSource<TResult>(cp);
cp.TaskCompletionSource = tcs;
@clemensv
clemensv / gist:dd1d629beec9d38b747d
Created August 27, 2014 13:51
SAS in namespace root
NamespaceManager nsm = NamespaceManager.CreateFromConnectionString(serviceBusConnectionString);
string name = nsm.Address.Host.Substring(0, nsm.Address.Host.IndexOf(".", System.StringComparison.Ordinal));
var sendKey = SharedAccessAuthorizationRule.GenerateRandomKey();
var listenKey = SharedAccessAuthorizationRule.GenerateRandomKey();
var manageKey = SharedAccessAuthorizationRule.GenerateRandomKey();
CreateSharedAccessRuleOnNamespaceRoot(name, "send", sendKey, AccessRights.Send, subscriptionId, publisherCertificate);
CreateSharedAccessRuleOnNamespaceRoot(name, "manage", manageKey, AccessRights.Manage|AccessRights.Send|AccessRights.Listen, subscriptionId, publisherCertificate);
CreateSharedAccessRuleOnNamespaceRoot(name, "listen", listenKey, AccessRights.Listen, subscriptionId, publisherCertificate);