Skip to content

Instantly share code, notes, and snippets.

View MaxLaurieHutchinson's full-sized avatar

Max Hutchinson MaxLaurieHutchinson

View GitHub Profile
@KevinMcDonnell-BC
KevinMcDonnell-BC / Checking User ID
Created September 20, 2018 11:24
BCServerlessDemo DataAndFunctions
public async Task<UserDigest> CurrentUserAsync(HttpRequestMessage req)
{
var userIssuer = ClaimsPrincipal.Current.Claims.Where(f => f.Type.Contains("name")).FirstOrDefault();
if (userIssuer != null && userIssuer.Issuer.ToUpper() == "LOCAL AUTHORITY")
{
if (req != null)
{
IEnumerable<string> ids = new List<string>();
req.Headers.TryGetValues("UserId", out ids);
@KevinMcDonnell-BC
KevinMcDonnell-BC / Body content example
Last active January 9, 2021 04:06
BCServerlessDemo DataAndFunctions API
// from https://github.com/BallardChalmers/BCServerlessDemo.DataAndFunctions/blob/master/BCServerless.DataAndFunctions.Functions/Api/JourneysApi.cs
public async Task<HttpResponseMessage> Post(HttpRequestMessage req, TraceWriter log)
{
var payload = await req.Content.ReadAsAsync<Journey>();
var item = await _JourneyService.CreateAsync(payload, req);
return req.CreateResponse(HttpStatusCode.Created, item);
}
@cocowalla
cocowalla / ClaimsIdentity.cs
Last active November 9, 2018 15:49
Attempt at adding a custom ClaimsIdentity to the Principal
builder.AddOpenIdConnect(options =>
{
options.Events = new OpenIdConnectEvents
{
OnTokenValidated = async ctx =>
{
var db = ctx.HttpContext.RequestServices.GetRequiredService<DataContext>();
// Get the user's Azure Active Directory ID
var userId = Guid.Parse(ctx.Principal.FindFirst(OBJECT_ID_CLAIM_TYPE).Value);
@nertim
nertim / CSVToJsonArray.cs
Created December 11, 2017 23:40
CSV To Json Array Azure Function
#r "newtonsoft.json"
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
@wojteklu
wojteklu / clean_code.md
Last active February 12, 2026 23:37
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@altrive
altrive / ToastNotification_Windows10.ps1
Last active May 12, 2024 09:34
Windows 10 toast notification sample
$ErrorActionPreference = "Stop"
$notificationTitle = "Notification: " + [DateTime]::Now.ToShortTimeString()
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
#Convert to .NET type for XML manipuration
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null