Skip to content

Instantly share code, notes, and snippets.

View McKabue's full-sized avatar

Kabue Charles McKabue

View GitHub Profile
@AArnott
AArnott / Cancellation.cs
Last active December 12, 2023 16:33
Graceful console app cancellation on Ctrl+C
class Program
{
static async Task Main(string[] args)
{
// Add this to your C# console app's Main method to give yourself
// a CancellationToken that is canceled when the user hits Ctrl+C.
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) =>
{
Console.WriteLine("Canceling...");
@slayer
slayer / cloudflare-delete-all-records.sh
Last active March 21, 2024 10:17
Delete all DNS records for specified zone
#!/bin/bash
TOKEN="xxxxxxxxxxxxxxxxxxx"
ZONE_ID=2222222222222222222222222
# EMAIL=me@gmail.com
# KEY=11111111111111111111111111
# Replace with
# -H "X-Auth-Email: ${EMAIL}" \
# -H "X-Auth-Key: ${KEY}" \
type TemplateParameterType = { [key: string]: string };
/**
* If the template from @member CompiledRouteType.template
* is an object, this type will be extended with all the
* members of that object.
*/
type TemplateMatchResponseType = {
params: TemplateParameterType,
/**
@McKabue
McKabue / Get_All_Routes_in_ASP.NET_MVC_Core_2.cs
Last active May 11, 2023 07:16
Get all routes, including default routes specified at start up
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System;
using System.Linq;
using System.Threading.Tasks;

How to turn off Webpack code-splitting

Using Webpack import()

The following code will produce code-splitting in Webpack, which means that the source code will be split into several files that will be loaded async at runtime.. More info here;

import('./some-module').then((SomeModule) => {});
@kakoma
kakoma / reconfigure-virtualbox-dkms
Last active March 15, 2022 10:15
Reconfigure Ubuntu's virtualbox-DKMS after a kernel upgrade
#!/bin/bash
# Description: Everytime the Kernel is upgraded (which is quite often), virtualbox stops working and throws the following error:
#
# The provider 'virtualbox' that was requested to back the machine
# 'default' is reporting that it isn't usable on this system. The
# reason is shown below:
#
# VirtualBox is complaining that the installation is incomplete. Please
# run `VBoxManage --version` to see the error message which should contain
# instructions on how to fix this error.
@rjz
rjz / ngrok_hostname.sh
Created August 9, 2016 16:20
Get ngrok hostname from command line
#!/bin/sh
# ngrok's web interface is HTML, but configuration is bootstrapped as a JSON
# string. We can hack out the forwarded hostname by extracting the next
# `*.ngrok.io` string from the JSON
#
# Brittle as all get out--YMMV. If you're still reading, usage is:
#
# $ ./ngrok_hostname.sh <proto> <addr>
#
@kyranjamie
kyranjamie / keycodes.ts
Created August 3, 2016 10:07
TypeScript Browser Key Codes Enum
enum keyCodes {
BACKSPACE: 8,
TAB: 9,
ENTER: 13,
SHIFT: 16,
CTRL: 17,
ALT: 18,
PAUSE: 19,
CAPS_LOCK: 20,
ESCAPE: 27,
@joar
joar / jq-insert-var.sh
Last active May 3, 2024 13:41
Add a field to an object with JQ
# Add field
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
# {
# "hello": "world",
# "foo": "bar"
# }
# Override field value
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
{
@rdavisau
rdavisau / EnumerableStream.cs
Created October 26, 2015 12:18
EnumerableStream.cs
/// <summary>
/// Provides a convenience method for constructing an EnumerableStream<T>.
/// </summary>
public static class EnumerableStream
{
public static EnumerableStream<T> Create<T>(IEnumerable<T> source, Func<T, List<byte>> serializer)
{
return new EnumerableStream<T>(source, serializer);
}
}