Skip to content

Instantly share code, notes, and snippets.

View cilliemalan's full-sized avatar

Cillié Malan cilliemalan

View GitHub Profile
@cilliemalan
cilliemalan / MainView.cs
Last active July 1, 2020 17:35
A workaround for multisampling in MonoGame under UWP by rendering to texture first.
/*
One cannot use multisampling directly in a UWP application because
of reasons stipulated here:
https://docs.microsoft.com/tr-tr/windows/uwp/gaming/multisampling--multi-sample-anti-aliasing--in-windows-store-apps
The workaround is to create a render target with multisampling, render to that
and then render the render target as a sprite
*/
using System;
using System.Collections.Generic;
@cilliemalan
cilliemalan / asyncawaiter.cs
Created November 18, 2019 12:01
An awaiter for CancellationToken
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Core
{
public class MyBackgroundService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
using var disposer = messageQueue.Subscribe(async (msg) =>
{
await ProcessMessageAsync(msg, stoppingToken);
});
// Nasty!
public class MyBackgroundService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await DoWorkAsync(stoppingToken);
}
}
}
public class MyBackgroundService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
// run until stoppingToken is cancelled???
}
}
public class MyBackgroundService : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
// run until stoppingToken is cancelled???
}
}
@cilliemalan
cilliemalan / LICENSE
Last active December 12, 2017 06:48
C++ base project
Copyright 2017 Cillié Malan
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@cilliemalan
cilliemalan / digest.js
Created May 15, 2017 11:36
how to digest a PEM key
/**
* returns a base64url based digest of a PEM file
* @param {*} key
*/
function digestKey(key) {
let meat = key.match(/^-{5}[A-Z ]+-{5}[\r\n]{1,2}([a-zA-Z0-9/+\r\n]+={0,3})[\r\n]{1,2}-{5}[A-Z ]+-{5}/)[1];
if (!meat) throw "unrecognized format";
meat = meat.replace(/[\r\n]{1,2}/g, '');
var buf = Buffer.from(meat, 'base64');
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace DataProcessorTemplate
{
/// <summary>
/// Program that counts the number of lines in which each word occurs.

OAuth server-server authentication

In order to communicate to a web service that has OAuth authentication, one may use the following procedures. Note that this is only for server to server communication on a service account. This is not for making calls on behalf of a client. So scopes and claims are typically not relevant in this context.

Authentication happens in two steps:

  • Getting a token
  • Making calls with that token