Skip to content

Instantly share code, notes, and snippets.

View tonidy's full-sized avatar

toni dy tonidy

View GitHub Profile
@tonidy
tonidy / json_uniq.sql
Created February 10, 2022 06:52 — forked from DaveKin/json_uniq.sql
SQL function to remove duplicate entries from a JSON array. Based on MYSQL 5.7+
CREATE FUNCTION JSON_UNIQ(arr JSON) RETURNS json
BEGIN
SET @arr = arr;
SET @a_length = JSON_LENGTH(@arr);
SET @loop_index = @a_length;
WHILE @loop_index >= 0 DO
SET @item = JSON_UNQUOTE(JSON_EXTRACT(@arr, concat('$[',@loop_index,']')));
@tonidy
tonidy / ch-swagger.json
Last active January 23, 2022 14:06
CH Swagger
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Companies House Public Data API",
"description": "An API suite providing read only access to search and retrieve public company data"
},
"host": "api.company-information.service.gov.uk",
"schemes": [
"https",
@tonidy
tonidy / mock.cs
Created January 21, 2022 13:17 — forked from umair-me/mock.cs
Mock Configuration.GetSection
Mock<IConfiguration> configuration = new Mock<IConfiguration>();
configuration.Setup(c => c.GetSection(It.IsAny<String>())).Returns(new Mock<IConfigurationSection>().Object);
@tonidy
tonidy / EnumerablePaginationExtensions.cs
Created January 12, 2022 07:16 — forked from SaxxonPike/EnumerablePaginationExtensions.cs
C# forward pagination extension method
using System.Collections.Generic;
namespace Extensions
{
public static class EnumerablePaginationExtensions
{
public static IEnumerable<IEnumerable<T>> Paginate<T>(this IEnumerable<T> items, int pageSize)
{
var page = new List<T>();
foreach (var item in items)
@tonidy
tonidy / Info.cshtml
Created October 20, 2021 16:49 — forked from mika76/Info.cshtml
phpinfo like page for .net core
@page
@{
Layout = "";
}
@using System.Linq;
@using System.Collections;
@using System.Reflection;
<html>
@tonidy
tonidy / Makefile
Last active August 2, 2021 03:25
Merge 2 kubernetes config files
## Using:
## to see newconfig
## make view newconfig=~/new-config.yaml
## to merge configs
## make merge newconfig=~/new-config.yaml
view::
cp ~/.kube/config ~/.kube/config.bak && KUBECONFIG=~/.kube/config:$(newconfig) kubectl config view --flatten > /tmp/config && cat /tmp/config
merge::
cp ~/.kube/config ~/.kube/config.bak && KUBECONFIG=~/.kube/config:$(newconfig) kubectl config view --flatten > /tmp/config && mv /tmp/config ~/.kube/config
@tonidy
tonidy / fcos-qemu-demo
Created May 25, 2021 05:41 — forked from mpreu/fcos-qemu-demo
Fedora CoreOS - Example script to setup a FCOS virtual machine using QEMU. Originates from this blog post: https://www.matthiaspreu.com/posts/fedora-coreos-first-steps/.
#!/bin/env bash
set -eo pipefail
#
# Part of an introductory Fedora CoreOS blog post on my website:
# https://www.matthiaspreu.com/posts/fedora-coreos-first-steps/
#
# Script sets up a FCOS virtual machine using QEMU.
#
# Initial user "matthias" with password "test" can be used.
@tonidy
tonidy / homebrew-install-mkpasswd.md
Last active August 30, 2021 12:34 — forked from mcandre/homebrew-install-mkpasswd.md
Homebrew install mkpasswd
brew tap tonidy/tools-tap
brew install mkpasswd
#!/bin/sh
# NB: When editing this file, be careful to preserve the original whitespace (especially newlines).
HDXRTME_install_loadstrings_en()
{
HDXRTME_install_yeschoices="yes,YES,Yes,y,Y"
HDXRTME_install_nochoices="no,NO,No,n,N, " # <-- trailing comma+space indicates empty input defaults to N
//taken from https://blogs.msmvps.com/kenlin/2018/01/18/2694/
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
//These headers are handling the "pre-flight" OPTIONS call sent by the browser
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Allow‌​-Credentials", "true");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");