Skip to content

Instantly share code, notes, and snippets.

View kamranayub's full-sized avatar

Kamran Ayub kamranayub

View GitHub Profile
@kamranayub
kamranayub / machine.js
Created April 28, 2021 13:36
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@kamranayub
kamranayub / README.md
Last active March 11, 2021 19:05
Enable Grammarly on Ghost Blog Admin Editor
@kamranayub
kamranayub / next.config.js
Last active September 20, 2023 20:45
React Production Profiling Support for Next.js
//
// See: https://kentcdodds.com/blog/profile-a-react-app-for-performance#build-and-measure-the-production-app
// See: https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config
const TerserPlugin = require('next/dist/compiled/terser-webpack-plugin');
module.exports = {
webpack: (config, options) => {
//
// Use profiler-enabled React builds
@kamranayub
kamranayub / msbuild.js
Last active May 20, 2020 15:14
Make MSBuild 2020 player stretch across the window and chat below. Hit F12 and paste into console.
// F12 Dev Tools and copy and paste into console!
// Stretches studio player 100% and chat below.
var studioPlayer = document.querySelector("studio-player");
var studioVideo = document.querySelector(
".home-page__live-stream--content__video"
);
var chat = document.querySelector(".home-page__live-stream__info");
if (studioPlayer && studioVideo && chat) {
studioPlayer.style.display = "block";
@kamranayub
kamranayub / makefile
Last active August 1, 2017 19:20
Makefile for using ansible-playbook to do syntax checking for YAML playbooks
# Collect top-level YAML files under plays/ folder
# e.g. plays/upgrade_ansible_tower/upgrade_ansible_tower.yml
# These should only be Ansible playbook files
# i.e. store includes in child includes/ dir
playbooks := $(wildcard plays/*/*.yml)
# Check YAML syntax using ansible-playbook
syntax: $(playbooks)
@GREEN='\033[0;32m'; \
NC='\033[0m'; \
@kamranayub
kamranayub / Get-TfsGitLfsFile.ps1
Created June 15, 2017 04:29
Download Git LFS file from TFS/VSTS
<#
.SYNOPSIS
Downloads a blob item from TFS Git LFS
.DESCRIPTION
This script performs a 4-step process to download a LFS-hosted file from TFS. It fetches the item metadata
then downloads the LFS pointer. After it validates the pointer file, it preps a LFS batch download and finally
downloads the file to the specified OutFile. You can use this cmdlet in a pipeline as it passes a Get-Item call
at the end.
@kamranayub
kamranayub / ConfigSecretsProvider.cs
Created February 24, 2016 00:27
Secrets provider interface
public class ConfigSecretsProvider : ISecretsProvider
{
private readonly NameValueCollection _secretCollection;
public ConfigSecretsProvider() {
_secretCollection = ConfigurationManager.GetSection("appSecrets") as NameValueCollection;
}
public string GetSecret(string key) {
return Environment.GetEnvironmentVariable(key) ?? _secretCollection[key];
@kamranayub
kamranayub / Pkcs12ProtectedConfigurationProvider.cs
Created February 21, 2016 21:24
A modified PKCS12 provider that can use CurrentUser or LocalMachine store.
/*
Microsoft Limited Permissive License (Ms-LPL)
This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
1. Definitions
The terms “reproduce,” “reproduction,” “derivative works,” and “distribution” have the same meaning here as under U.S. copyright law.
A “contribution” is the original software, or any additions or changes to the software.
A “contributor” is any person that distributes its contribution under this license.
@kamranayub
kamranayub / 1_TestingContext.cs
Last active October 23, 2020 15:37
Example using Ninject and Moq to create a TestingImpersonationContext. All it does is replace the bound dependency with a new impersonated mock and then replaces it once disposed. Relies on a testing context that is available to any test class (could also be a test base class). `UserRepository` is just an example of code that retrieves a user fr…
public class TestingContext {
private IKernel _kernel;
public TestingContext() {
// create initial Strict mock that can always be setup outside impersonation context
UserContext = new Mock<IUserContext>(MockBehavior.Strict);
// register dependencies
_kernel = CreateKernel();
@kamranayub
kamranayub / App.config
Created November 5, 2015 05:06
Example self-hosting a Web API endpoint in a Windows Service using TopShelf (https://topshelf.readthedocs.org) and TopShelf.Owin package.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Port" value="1337"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">