Skip to content

Instantly share code, notes, and snippets.

@natenho
natenho / html-to-json.go
Created December 23, 2022 15:35
A way to convert HTML into json using go, extracted from chatGPT
package main
import (
"encoding/json"
"fmt"
"io"
"strings"
"golang.org/x/net/html"
)
@natenho
natenho / differences.sh
Created December 22, 2022 16:39
Git - Get the list of modified directories from the last tag (ou last commit)
#!/bin/bash -x
# Get the last tag
last_tag=$(git describe --tags 2> /dev/null)
# If the last tag does not exist, get the commit hash of the last commit
if [ $? -ne 0 ]; then
last_tag="HEAD~1"
fi
@natenho
natenho / buildver.sh
Created September 18, 2022 19:21
Bash git version bump
#!/bin/sh
# Prints the next version based on git tags in the pattern v0.0.0
# Uses regexp to infer which part of the version will be incremented
# Inspired by https://gitversion.net/docs/reference/version-increments
MAJOR_REGEXP="\+semver:\s?(breaking|major)"
MINOR_REGEXP="\+semver:\s?(feature|minor)"
COMMIT_TAG=$(git describe --exact-match --tags HEAD 2>/dev/null || true)
@natenho
natenho / ap2_flash
Created January 3, 2022 05:27
A bash script useful to flash Anne Pro 2 keyboard using a docker environment
#!/bin/bash
./build || exit 1 && clear
wait_device() {
while lsusb -d $1; [ $? -ne 0 ]; do
echo $2;
sleep 1;
done
}
@natenho
natenho / bt-profile-switch.sh
Last active July 22, 2022 08:11 — forked from OndraZizka/switchHeadphones.sh
Bluetooth headset - switch between quality sound + no mic (A2DP) and crappy sound and mic (HSP/HFP)
#!/bin/bash
CARD=$(pactl list | grep bluez_card | awk '{print $NF}')
BLUETOOTH_DEVICE=$(pacmd list-sinks | grep -o '<bluez_sink[^>]*' | cut -d\< -f2)
PROFILE_A2DP="a2dp_sink"
PROFILE_HEADSET_UNIT="headset_head_unit"
if [ "${1}" == "" -o "${1}" == "toggle" ] ; then
if $(pacmd list-sinks | grep -o "<bluez_sink\..*\.$PROFILE_A2DP>" &> /dev/null) ; then
@natenho
natenho / SingleOrMultipleInputFormatter.cs
Created August 15, 2020 00:25
Allow a controller method receive both single or multiple models
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
async Task ProcessMultipleAtOnce<T>(int maxDegreeOfParallelism, IEnumerable<T> items, Func<T, Task> func)
{
var actionBlock = new ActionBlock<T>(func, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism });
foreach (T item in items)
{
await actionBlock.SendAsync(item);
}
actionBlock.Complete();
@natenho
natenho / gist:3d7a8193ae1c5782e244e9fddb6f5949
Last active March 24, 2019 19:42
Integrating MEF with DependencyInjection
// Taken from https://weblogs.asp.net/ricardoperes/integrating-managed-extensibility-framework-with-the-net-service-provider
// Other interesting links:
// https://weblogs.asp.net/ricardoperes/dynamically-loading-middleware-in-asp-net-core
// https://weblogs.asp.net/ricardoperes/using-mef-in-net-core
public static class ContainerConfigurationExtensions
{
public static ContainerConfiguration WithAssembliesInPath(this ContainerConfiguration configuration, string path, SearchOption searchOption = SearchOption.TopDirectoryOnly)
{
return WithAssembliesInPath(configuration, path, null, searchOption);