Skip to content

Instantly share code, notes, and snippets.

Avatar
☘️
Practice Lead for Digital Services at Intergen

Gavin Foley GFoley83

☘️
Practice Lead for Digital Services at Intergen
  • Practice Lead at Intergen
  • Wellington, New Zealand (From Dublin, Ireland)
View GitHub Profile
@GFoley83
GFoley83 / mtls-policy.xml
Created Apr 20, 2020 — forked from nov/mtls-policy.xml
Azure API Management Policy for MTLS
View mtls-policy.xml
<policies>
<inbound>
<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",""))" />
<choose>
<when condition="@(context.Request.Certificate != null && context.Request.Certificate.NotAfter > DateTime.Now)">
<set-header name="Client-Certificate" exists-action="override">
<value>@(context.Request.Certificate.GetRawCertDataString())</value>
</set-header>
@GFoley83
GFoley83 / DbDeadlockRetryHandlerProcessor.cs
Last active Apr 13, 2020
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
GFoley83 / AsyncConsoleAppWithCancellationTokenSupport-Legacy.cs
Last active May 30, 2019
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 - https://docs.microsoft.com/en-us/previous-versions/dd997289(v=vs.110)
private static readonly CancellationTokenSource canToken = new CancellationTokenSource();
View azcopy-script.ps1
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $requestBody.name
# GET method: each querystring parameter is its own variable
if ($req_query_name)
{
$name = $req_query_name
}
@GFoley83
GFoley83 / LinkedIn - Remove crap posts.js
Created Sep 30, 2018
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
GFoley83 / LinkedIn - Remove crap posts.js
Created Sep 30, 2018
Unlike facebook, LinkedIn creates entire posts just for likes and comments which fills up the feed with crap. This snippet removes posts from the feed that aren't proper content.
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
GFoley83 / deferred-promise.ts
Created Apr 26, 2018
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
GFoley83 / JsonSchemaToPocos.cs
Created Sep 14, 2017 — forked from rushfrisby/JsonSchemaToPocos.cs
Converts a JSON schema to C# POCO classes
View JsonSchemaToPocos.cs
class Program
{
private const string Cyrillic = "Cyrillic";
private const string Nullable = "?";
static void Main()
{
string schemaText;
using (var r = new StreamReader("schema.txt"))
@GFoley83
GFoley83 / statuses.md
Created Apr 27, 2017 — forked from vkostyukov/statuses.md
HTTP status codes used by world-famous APIs
View statuses.md
API Status Codes
[Twitter][tw] 200, 304, 400, 401, 403, 404, 406, 410, 420, 422, 429, 500, 502, 503, 504
[Stripe][stripe] 200, 400, 401, 402, 404, 429, 500, 502, 503, 504
[Github][gh] 200, 400, 422, 301, 302, 304, 307, 401, 403
[Pagerduty][pd] 200, 201, 204, 400, 401, 403, 404, 408, 500
[NewRelic Plugins][nr] 200, 400, 403, 404, 405, 413, 500, 502, 503, 503
[Etsy][etsy] 200, 201, 400, 403, 404, 500, 503
[Dropbox][db] 200, 400, 401, 403, 404, 405, 429, 503, 507