Skip to content

Instantly share code, notes, and snippets.

View phuf's full-sized avatar

Paul Huf phuf

View GitHub Profile
@phuf
phuf / .ps1
Created April 19, 2024 13:13
How to display ASCII control characters in caret notation
(0..31) | ForEach-Object { "^$([char](64 + $_)) - $_" }
@phuf
phuf / Get-ClassWithAtLeastOneField.ps1
Created November 7, 2023 20:37
PowerShell cmdlet that returns .NET classes with at least one public field.
#Requires -Version 7
<#
.SYNOPSIS
Return list of classes declared within the specified assembly that have at
least one public field.
.DESCRIPTION
Return list of classes within an assembly that have at least one field.
The use case is discovering fields that really should be properties.
@phuf
phuf / bridge-from-tap0.sh
Last active March 27, 2020 10:12
bridge-from-tap0
echo "$(ip link show tap0 | grep --only-matching "master [^ ]*" | cut --delimiter ' ' --fields 2)"
// sudo apt install uuid-dev
// g++ hack.cpp -luuid
#include <iostream>
#include <sstream>
#include <math.h>
#include <memory>
#include <memory.h>
#include <uuid/uuid.h>
#include <unordered_map>
@phuf
phuf / hack
Created February 20, 2019 03:33
#include <iostream>
#include <sstream>
#include <math.h>
#include <memory>
#include <memory.h>
using namespace std;
struct shared_memory {
shared_memory() {
$scriptPath = Join-Path (Get-Location) "TestEditDistance.sql";
$response = Invoke-WebRequest "https://raw.githubusercontent.com/GlobalNamesArchitecture/damerau-levenshtein/master/spec/files/damerau_levenshtein_test.txt" -UseBasicParsing;
$lines = $response.Content.Split() | Where-Object { $_ -like "*|*|*|*" };
@"
DECLARE @test_cases TABLE
(
Word1 NVARCHAR(128),
Word2 NVARCHAR(128),
ExpectedEditDistance INT
@phuf
phuf / Install-VIM.ps1
Created January 7, 2017 02:18
Install VIM on Windows Server Core
Set-ExecutionPolicy Unrestricted;
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression;
choco install vim
choco update vim
$command = (Get-itemProperty -LiteralPath "HKLM:\SOFTWARE\Classes\`*\shell\Vim\Command").'(default)';
if ($command -match "`"([^`"]+)`".*") {
$expression = "Set-Alias -Name 'vim' -Value '$($Matches[1])';"
@phuf
phuf / powershell-fizzbuzz.md
Created January 1, 2017 13:25
Fizzbuzz in PowerShell.

Fizzbuzz in PowerShell:

(1..100) | % {
  if ($_ % 3 -eq 0 -and $_ % 5 -eq 0) {
    "fizz-buzz"
  } elseif ($_ % 3 -eq 0) {
    "fizz"
  } elseif ($_ % 5 -eq 0) {
 "buzz"