Skip to content

Instantly share code, notes, and snippets.

View gregmac's full-sized avatar

Greg MacLellan gregmac

View GitHub Profile
@gregmac
gregmac / signtool.msbuild.tasks
Created December 12, 2014 01:40
SignTool MSBuild Task
<!--
Sign .exe files using signtool.exe.
(c) 2014 Greg MacLellan, Licensed under MIT http://opensource.org/licenses/MIT
Features:
* Hides password from being displayed in build output
* Retries against multiple timestamp servers if the server returns an invalid response (fairly common)
Usage:
@gregmac
gregmac / OhMyPosh SetupGuide.md
Last active April 28, 2023 15:35
Oh-my-posh Config
  • Originally adapteed from Scott Hanselman's excellent guide.
  • Updated in 2021-08 for oh-my-posh v3.
  • Uses a theme based on Paradox theme
    • Short folder names, special icons for Registry, Home, etc
    • Different prompt icon when running as admin
    • Shows last exit code
    • Timing info for long-running commands
    • Git status

@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)
@gregmac
gregmac / ProcessInfo.ps1
Created December 12, 2019 23:12
Get CPU, Memory and Command Line using PowerShell
$sampleTime = 2; # timespan to use for CPU%
$cmds = @{}; Get-CimInstance Win32_Process | %{ $cmds[$_.ProcessId.ToString()] = $_.CommandLine; };
$cpu1 = @{}; Get-Process | %{ $cpu1[$_.Id.ToString()] = $_.CPU }
start-sleep -seconds $sampleTime
Get-Process | select `
Id, `
Name, `
@{Name="CPU";Expression={ (($_.CPU-$cpu1[$_.Id.ToString()]) / $sampleTime / [System.Environment]::ProcessorCount / 100) }}, `
WorkingSet64, `
@{Name="CommandLine";Expression={$cmds[$_.Id.ToString()]}} `
@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:
screen mode id:i:2
span monitors:i:1
use multimon:i:1
selectedmonitors:s:1,2
pinconnectionbar:i:0