Skip to content

Instantly share code, notes, and snippets.

View bradwilson's full-sized avatar
🤘
All metal, all the time!

Brad Wilson bradwilson

🤘
All metal, all the time!
View GitHub Profile
@bradwilson
bradwilson / bat.ps1
Created March 17, 2024 21:34
Replace cat with bat in PowerShell (and my personal bat config file)
# This is to replace PowerShell's 'cat' with 'bat'. Install from here: https://github.com/sharkdp/bat
#
# This code goes into my $profile. If you put this into a separate file, you will need to dot source
# that file so that the function shows up in the global namespace. I only replace the cat alias,
# so Get-Content still performs its standard behavior.
#
# I use a pipeline to capture all the file content (so you can do things like `dir *.ps1 | cat` as well
# as `cat *.ps1`). If there's a single file, then the contents are displayed raw; if there are multiple files,
# then it uses bat's header to discriminate the content of multiple files from each other. I also replicated
# a few of the more common (for me) command line switches that I'd want to use to influence bat's behavior,
@bradwilson
bradwilson / get-mkvinfo.ps1
Last active January 27, 2024 08:08
get-mkvinfo.ps1 (automating mkvmerge)
param(
[Parameter(ValueFromPipeline)]$values,
[switch]$All
)
# It's worth noting that this script is useful for me, because I speak English. So I show all audio
# tracks and just the English subtitle tracks, and just make note when one of my rips includes non-
# English subtitle tracks (usually indicting I forgot to reduce the things I ripped).
#
# This is a pipeline-compatible script, so my usage is typically:
@bradwilson
bradwilson / EnumerableExtensions.cs
Last active January 21, 2024 16:45
Enumerable/AsyncEnumerable conversions
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
internal static class EnumerableExtensions
{
public static IAsyncEnumerable<T>? ToAsyncEnumerable<T>(IEnumerable<T>? data) =>
data == null ? null : ToAsyncEnumerableImpl(data);
async static IAsyncEnumerable<T> ToAsyncEnumerableImpl<T>(IEnumerable<T> data)
@bradwilson
bradwilson / Benchmark.cs
Last active January 10, 2024 07:10
Benchmarking OfType() vs. custom WhereNotNull() to discard null values
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
public static class EnumerableExtensions
{
static readonly Func<object, bool> notNullTest = x => x is not null;
@bradwilson
bradwilson / disable-ipv6.reg
Created December 11, 2023 02:23
Disable IPv6 on Windows
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters]
"DisabledComponents"=dword:000000ff
@bradwilson
bradwilson / custom.css
Last active November 22, 2023 05:30
Refined GitHub custom CSS
pre,
pre code,
.blob-code,
.blob-code-content,
.blob-code-marker,
.cm-editor .cm-line,
.react-blob-print-hide,
.react-code-text {
font-family: 'MonaspiceNe NFM', monospace !important;
}
@bradwilson
bradwilson / remove-all-boms.ps1
Created November 2, 2022 01:09
Quick script to find files with UTF-8 BOMs and rewrite them without the BOM
param(
[string] $Folder = ".",
[string] $Filter = "*.*"
)
Get-ChildItem -Path $Folder -Recurse -File -Filter $Filter -Exclude @('obj','bin') | Foreach-Object {
$contents = [System.IO.File]::ReadAllBytes($_.FullName)
if ($contents.Length -gt 2 -and $contents[0] -eq 0xEF -and $contents[1] -eq 0xBB -and $contents[2] -eq 0xBF) {
Write-Host $_.FullName
[System.IO.File]::WriteAllBytes($_.FullName, $bytes[3..$($bytes.Length)])
@bradwilson
bradwilson / 1 - In Code.cs
Created August 18, 2020 23:21
Skip attribute: enable or no?
public class SampleTests
{
public bool SomeCondition => ...;
[Fact]
public void MySkipWhen()
{
Assert.SkipWhen(SomeCondition, "This is dynamically skipped when SomeCondition is true");
}
@bradwilson
bradwilson / settings.json
Last active April 16, 2024 16:14
Ubuntu color scheme for Windows Terminal
{
"$help": "https://aka.ms/terminal-documentation",
"$schema": "https://aka.ms/terminal-profiles-schema",
"actions": [
{
"command": "copy",
"keys": "ctrl+shift+c"
},
{
"command": "paste",
@bradwilson
bradwilson / profile.ps1
Last active March 21, 2024 07:24
Downloadable files for bradwilson.io/blog/prompt/powershell
######## POSH-GIT
# ... Import-Module for posh-git here ...
# Background colors
$GitPromptSettings.AfterStash.BackgroundColor = 0x5F5FAF
$GitPromptSettings.AfterStatus.BackgroundColor = 0x5F5FAF
$GitPromptSettings.BeforeIndex.BackgroundColor = 0x5F5FAF
$GitPromptSettings.BeforeStash.BackgroundColor = 0x5F5FAF