Skip to content

Instantly share code, notes, and snippets.

@sean-m
sean-m / PSAssert.ps1
Last active April 14, 2021 17:21
Don't use this! Use Pester. Simple functions for writing assertion tests that will throw exceptions in a composable way without any external dependencies. All test functions return $true if passed so they can be used as a predicate, they throw on failure to stop script execution. This exists to simplify testing for invariants in production scrip…
class AssertionException : System.Exception {
AssertionException ([string]$Message, [System.Exception]$InnerException) : base($Message,$InnerException) { }
}
function Assert-Contains {
param (
[object[]]$Collection,
[string]$Property=$null,
$Pattern,
@sean-m
sean-m / zip.ps1
Created June 22, 2020 23:43
helper for using Linq zip in powershell, short enough to write manually but easier to paste one that already behaves.
function Zip {
param ([object[]]$first, [object[]]$second)
[Func[object,object,object]]$zipper = { param ($a, $b) New-Object PSObject -Property @{First=$a;Second=$b} }
[System.Linq.Enumerable]::Zip($first, $second, $zipper)
}
@sean-m
sean-m / sshtunnel.sh
Last active May 31, 2020 20:18
Simple script for tunneling ports over ssh so I don't have to look up the ssh switches each time.
#!/usr/bin/env bash
showhelp=0
verbose=0
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
@sean-m
sean-m / ping_log.ps1
Created April 29, 2020 17:33
One-liner for continuous ping with logging. Use it all the time and need a place to put it.
ping /t 192.168.1.1 | select -Skip 2 | % { "$(Get-Date -Format 'o'),$_" } | Tee-Object -FilePath "$env:temp\ping-$(Get-Date -UFormat %s).csv"
@sean-m
sean-m / HeaderComment.ps1
Last active October 5, 2020 23:21
It gets old trying to do these by hand all the time, pipe to clip.exe and call it a day.
## Generate comment blocks that can denote regions in your script
filter HeaderComment {
[Alias('HC')]
param(
[Parameter(Position=0, ValueFromRemainingArguments)]
$msg
)
$msg = $msg -join ' '
@"
################################################################################
@sean-m
sean-m / motionsickness.lua
Last active April 3, 2020 00:14
dinking around with lua
function lerp(a,b,t) return (1-t)*a + t*b end
function new_star()
local rx = love.math.random() * 20
local ry = love.math.random() * 12
{
"packages": [
{
"name": "Maixduino",
"maintainer": "Sipeed",
"websiteURL": "https://maixduino.sipeed.com",
"email": "[email protected]",
"help": {
"online": "https://maixduino.sipeed.com"
},
@sean-m
sean-m / IsValidEmail.ps1
Last active August 1, 2019 17:29
RegexUtility.IsValidEmail MSDN example as PowerShell
Add-Type -Language CSharp -TypeDefinition @"
using System;
using System.Globalization;
using System.Text.RegularExpressions;
public static class RegexUtilities
{
// Examines the domain part of the email and normalizes it.
private static string DomainMapper(Match match)
{
@sean-m
sean-m / hist.sh
Created March 6, 2019 06:18
Modification of the histogram bar chart script found here: http://heyrod.com/snippets/tag-awk.html. Removed dependency on 'bc' because it's not made for humans.
#!/bin/bash
#-------------------------------------------------------------------------------
# draw-histogram - generates an ASCII-art histogram (bar chart) from input data.
#-------------------------------------------------------------------------------
# Expects a series of lines of the form `<category-name> <count>` to passed
# via stdin.
#
# Generates a table the looks something like the following:
#
# +-------+----+
using System;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
namespace SMM.Helper
{
public static class CredentialsUI
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]