Skip to content

Instantly share code, notes, and snippets.

View gregmac's full-sized avatar

Greg MacLellan gregmac

View GitHub Profile
@gregmac
gregmac / ! Genmon ESP32 Serial Bridge.md
Last active July 9, 2022 01:05
Project to use an ESP32 as a RS232-to-Wifi bridge for Genmon
@gregmac
gregmac / README.md
Last active June 23, 2022 01:57
esphome ESP32 Water Level Sensor

Sump pit water level sensor

This is an ESPHome configuration for an ESP32 that monitors a sump pump pit, using the ESP32 capacitive touch sensors, with a level being reported to Home Assistant.

ESP32 Wiring

The ESP32 is mounted on a piece of PVC pipe, with wires extending down to different lengths. I used a length of old ethernet cable I had sitting around.

There's also a wire at the bottom connected to the ground pin, and this gives more reliable touch sensor values. The USB32 is powered from USB.

@gregmac
gregmac / main.cpp
Created March 9, 2022 03:21
PlatformIO IDE Upload with AsyncElegantOTA
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
// Port to listen on
#define WEBSERVER_PORT 80
AsyncWebServer server(WEBSERVER_PORT);
void initWiFi() {
WiFi.mode(WIFI_STA);
@gregmac
gregmac / LinqpadExtensions.cs
Created February 3, 2022 01:24
LINQPad Extensions
public static class MyExtensions
{
// Write custom extension methods here. They will be available to all queries.
/// <summary>Dump a string using wrapping</summary>
public static string DumpWrapped(this string value, string title = null, int width = 120)
{
string.Join("\n", value.Select((x, i) => i)
.Where(i => i % width == 0)
@gregmac
gregmac / CleanupNugetCache.ps1
Created February 1, 2022 20:21
Cleanup Nuget Cache
# cleanups up the .nuget\packages directory
# * Keeps anything added within 120 days
# * Keeps the most recently used of every package
$maxAge = (Get-Date).AddDays(-120);
$deleted = 0;
$deletedMb = 0;
Get-ChildItem -Directory -Path ([IO.Path]::Combine($HOME, ".nuget", "packages")) | ForEach-Object {
Get-ChildItem -Directory -Path $_.Fullname | Sort-Object -Property LastWriteTime -Descending | ForEach-Object {$i=0} {
$sizeMb = [Math]::Round((Get-ChildItem -Path $_.FullName -Recurse | Measure-Object -Sum Length).Sum / 1MB, 2)
screen mode id:i:2
span monitors:i:1
use multimon:i:1
selectedmonitors:s:1,2
pinconnectionbar:i:0
<#
Create a Start Menu shortcut for the settings for each camera on the system.
Requires ffmpeg installed via https://scoop.sh/
(or modify to point at the proper ffmpeg.exe location)
#>
$ffmpeg = "`$env:USERPROFILE\scoop\apps\ffmpeg\current\bin\ffmpeg.exe"
@gregmac
gregmac / .Windows10 Setup.md
Last active September 27, 2021 13:44
Windows 10 Setup

Install:

  • Powershell 7
  • Windows Terminal
  • Rename computer: Rename-Computer -NewName "Server044" -Restart
  • Scoop
    • scoop install sudo
  • Run Reclaim windows 10 script
  • More Scoop apps:
public static class TaskExtensions
{
public static async Task WaitSlowTask(this Task waitTask, TimeSpan slowTime, Action slowAction)
{
var taskCompleted = new CancellationTokenSource();
if (slowAction != null)
{
_ = Task.Delay(slowTime, taskCompleted.Token).ContinueWith(_ => slowAction.Invoke(), TaskContinuationOptions.OnlyOnRanToCompletion);
@gregmac
gregmac / awesome-nuget.md
Last active August 14, 2021 00:11
Awesome C# Packages

A (very) incomplete list of useful packages, mostly as a bookmark for myself.

Async

HTTP