Skip to content

Instantly share code, notes, and snippets.

CTO @ Educa

Gavin Foley GFoley83

CTO @ Educa
View GitHub Profile
GFoley83 / deferred-promise.ts
Created April 26, 2018 07:37
Deferred Promise for Typescript
View deferred-promise.ts
* A new instance of deferred is constructed by calling `new DeferredPromse<T>()`.
* The purpose of the deferred object is to expose the associated Promise
* instance APIs that can be used for signaling the successful
* or unsuccessful completion, as well as the state of the task.
* @export
* @class DeferredPromise
* @implements {Promise<T>}
* @template T
* @example
GFoley83 / AwsV4SigningExample.cs
Created February 9, 2022 23:02
Full example showing how to sign AWS requests with Signature Version 4 using .NET
View AwsV4SigningExample.cs
using System.Globalization;
using System.Net.Mime;
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Mvc;
namespace EvaporateJSTest.Controllers;
GFoley83 / DbDeadlockRetryHandlerProcessor.cs
Last active January 29, 2021 17:24
MediatR pipeline for retrying Db deadlocks
View DbDeadlockRetryHandlerProcessor.cs
using System;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
namespace Foo
public class DbDeadlockRetryHandlerProcessor<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
View Builder.cs
using System;
using System.Collections.Generic;
namespace builder
/// <summary>
/// MainApp startup class for .NET optimized
/// Builder Design Pattern.
/// </summary>
public class MainApp
GFoley83 / message-bus.service.ts
Last active June 2, 2020 12:55
Angular 2 Message Bus / PubSub ex.
View message-bus.service.ts
import { Injectable } from "@angular/core";
import { ReplaySubject, Observable } from "rxjs/Rx";
interface Message {
channel: string;
data: any;
export class MessageBus {
GFoley83 / mtls-policy.xml
Created April 20, 2020 23:43 — forked from nov/mtls-policy.xml
Azure API Management Policy for MTLS
View mtls-policy.xml
<base />
<!-- TODO: limit by client_id, not token itself -->
<rate-limit-by-key calls="30" renewal-period="10" counter-key="@(context.Request.Headers.GetValueOrDefault("Authorization",""))" />
<when condition="@(context.Request.Certificate != null && context.Request.Certificate.NotAfter > DateTime.Now)">
<set-header name="Client-Certificate" exists-action="override">
GFoley83 / LinkedIn - Remove crap posts.js
Created September 30, 2018 22:52
Unlike facebook, LinkedIn creates entire posts just for likes and comments which fills up the feed with crap. This snippet removes those posts from the feed. Best used with an Chrome extension like "Custom JavaScript for Websites".
View LinkedIn - Remove crap posts.js
const removeCrap = () => {
const $crapSelector = $(`
span.ember-view span:contains(" likes this"),
span.ember-view span:contains(" commented on this"),
span.ember-view span:contains(" liked "),
span.ember-view span:contains("Short course you may like"),
div.feed-shared-text-view span:contains("Promoted")
const crapCount = $crapSelector.length;
GFoley83 / location-finder.js
Last active January 22, 2020 11:55
A function which returns a jQuery promise that resolves when a user's location has been found. Also handles the scenario where by when not clicking allow/deny the browser never fires the timeout option of `getCurrentPosition()`. If `getCurrentPosition()` fails then the fallback lat lng is used instead.
View location-finder.js
Sample use:
var loc = new LocationFinder(-41.29247, 174.7732);
$.when(loc.findUserLocationAsync()).then(function (lat, lng) {
// console.log("Lat & lng set as: ", loc.usersPosition())
GFoley83 / AsyncConsoleAppWithCancellationTokenSupport-Legacy.cs
Last active May 30, 2019 08:39
Gracefully handle exiting an async ASP.NET console app with CancellationTokenSource support
View AsyncConsoleAppWithCancellationTokenSupport-Legacy.cs
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp
class Program
// Cancellation Tokens -
private static readonly CancellationTokenSource canToken = new CancellationTokenSource();
View azcopy-script.ps1
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $
# GET method: each querystring parameter is its own variable
if ($req_query_name)
$name = $req_query_name