Skip to content

Instantly share code, notes, and snippets.

var ClientSecret = "kSRsdf7rU323rf2ff2gfdssfdAnKI1mcOf98djfidIGx38="; // A key you add for your AAD app.
var ClientId = "17dfab36-1c33-4ffe-9ddd-533ddddfs378"; // The unique identifier for your AAD app..
var userObjectId = "12345667-1234-1234-1234-123412341234"; // LET'S SAY YOU WANNA GET A USER'S GROUPS... You'll need their ObjectId for querying later.
var authority = "https://login.microsoftonline.com/{tenant guid}/oauth2/authorize?api-version=1.0"; // This is the "OAuth Authorize" Endpoint for your AAD app.
var authContext = new AuthenticationContext(authority);
// Graph endpoint comes from Azure Portal "Graph Connection Endpoint"
var client = new ActiveDirectoryClient(new Uri("https://graph.windows.net/{tenant guid}"), () =>
@TheWorstProgrammerEver
TheWorstProgrammerEver / StorageAccountType.cs
Last active August 29, 2015 14:27
Create Azure storage accounts automatically. Mmm...
// Only here because the library doesn't provide an enum or anything.
public static class StorageAccountType
{
public readonly static string LocallyRedundant = "Standard_LRS";
public readonly static string GeographicallyRedundant = "Standard_GRS";
public readonly static string ReadAccessGeographicallyRedundant = "Standard_RAGRS";
public readonly static string ZoneRedundant = "Standard_ZRS";
}
@TheWorstProgrammerEver
TheWorstProgrammerEver / Scanner.cs
Created February 6, 2017 22:09
Symantec Protection Engine - scan stream in chunks
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
//-------------------------------------------------------
// You'll need this thing from Symantec!
//-------------------------------------------------------
using com.symantec.scanengine.api;
@TheWorstProgrammerEver
TheWorstProgrammerEver / CreateSP_DropUnnamedDefaultConstraint.sql
Created April 18, 2018 23:33
SQL Stored Proc - Drop Unnamed Default Constraint
CREATE PROCEDURE DropUnnamedDefaultConstraint (@Table NVARCHAR(MAX), @Column NVARCHAR(MAX))
AS
BEGIN
DECLARE @Drop NVARCHAR(MAX) = (
SELECT TOP 1 'ALTER TABLE ' + @Table + ' DROP CONSTRAINT '+name
FROM sys.default_constraints A
JOIN sysconstraints B on A.parent_object_id = B.id
WHERE id = OBJECT_ID(@Table)
AND COL_NAME(id, colid) = @Column
AND OBJECTPROPERTY(constid, 'IsDefaultCnst') = 1
const usingSorter = <T>(...selectors: ((t: T) => string | number)[]) => (a: T, b: T): -1 | 0 | 1 => {
for (const selector of selectors) {
const sa = selector(a)
const sb = selector(b)
if (sa < sb) return -1
if (sa > sb) return 1
}
return 0
}
public static class ObjectExtend
{
public static dynamic Extend(this object source, params object[] objs)
{
var result = new ExpandoObject();
var props = (IDictionary<string, object>)result;
foreach (var o in new[] { source }.Union(objs))
{
var expandoProperties = (
@TheWorstProgrammerEver
TheWorstProgrammerEver / colour-contrast.js
Last active November 14, 2022 12:59
WCAG Colour Contrast Checker in JS.
// https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
const contrastLightAndDark = (lighter, darker) => (lighter + 0.05) / (darker + 0.05)
const relativeLuminance = (r, g, b) => 0.2126 * C(r) + 0.7152 * C(g) + 0.0722 * C(b)
const C = c => {
const colourScalar = c / 255
return colourScalar <= 0.03928
? colourScalar / 12.92
@TheWorstProgrammerEver
TheWorstProgrammerEver / UrlTemplate.swift
Last active March 5, 2022 07:56
Type-driven URL templating in Swift
import Foundation
struct StringTemplate<T> {
var template: String
init(_ template: String) {
self.template = template
}
func fill(_ t: T) -> String {
@TheWorstProgrammerEver
TheWorstProgrammerEver / Proof.swift
Created February 19, 2021 05:17
SwiftUI Sheet NavigationView NavigationLink EnvironmentObject Environment presentationMode bug.
/*
Found a weird AF SwiftUI bug today.
It's hard to articulate succinctly. I have a demo project that replicates it.
Basically if you:
- Have a modally presented (via sheet) view which contains a NavigationView and a NavigationLink which leads to a destination view which has an EnvironmentObject dependency AS WELL AS a dependency on the .presentationMode environment value, and...
- The user partially dismisses the modally presented view (with the swipe down gesture) without committing to the dismissal, and
- Your code inside the modally presented view hierarchy accesses the EnvironmentObject dependency...
@TheWorstProgrammerEver
TheWorstProgrammerEver / URLSession-MultipartFormData.swift
Last active March 5, 2022 08:01
Swift URLRequest Multipart Form-Data
import Foundation
import UIKit
extension URLRequest {
typealias BuilderFunction = ((MultipartFormDataInclusion) -> Void) -> Void
struct MultipartFormDataInclusion {
var data: Data