Skip to content

Instantly share code, notes, and snippets.

View vexx32's full-sized avatar
💜
Turn your faults into faultlore and share them with the world.

Rain Sallow (/u/ta11ow) vexx32

💜
Turn your faults into faultlore and share them with the world.
View GitHub Profile
@vexx32
vexx32 / BenchMarkDotNet.ParseBinary.cs
Created October 4, 2018 15:53
benchmark for binary parsing in PS Core
///////////////////////////////////////
////////// BENCHMARK RESULTS //////////
///////////////////////////////////////
// * Summary *
BenchmarkDotNet=v0.11.1, OS=Windows 10.0.17134.286 (1803/April2018Update/Redstone4)
Intel Core i3-3240 CPU 3.40GHz (Ivy Bridge), 1 CPU, 4 logical and 2 physical cores
Frequency=3312801 Hz, Resolution=301.8594 ns, Timer=TSC
.NET Core SDK=2.1.402
@vexx32
vexx32 / Invoke-PSNotification.ps1
Last active November 9, 2018 14:08 — forked from TylerLeonhardt/Invoke-PSNotification.ps1
Show notifications on Linux using PowerShell! Thanks to notify-send(1)
function Invoke-PSNotification {
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
param(
[Parameter(Position=0, Mandatory, ValueFromPipeline)]
[object[]]
$Body,
[string]
$Summary = 'PowerShell Notification',
# allow self-referential definitions
[Flags()]
enum Food {
Apple
Banana
Celery
Grape
Fruit = Apple -bor Banana -bor Grape
}
type TransformToSKColorAttribute() =
inherit ArgumentTransformationAttribute()
let matchColor name =
seq {
match name with
| knownColor when ColorNames.Contains(knownColor) -> yield ColorLibrary.[knownColor]
| clear when String.Equals(clear, "transparent", StringComparison.OrdinalIgnoreCase) -> yield SKColor.Empty
| patternString when WildcardPattern.ContainsWildcardCharacters(patternString) ->
let pattern = WildcardPattern(patternString, WildcardOptions.IgnoreCase)
function Test-PasswordLeaked {
[CmdletBinding()]
param(
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[PSCredential]
$Credential
)
begin {
$SHA1 = [System.Security.Cryptography.SHA1Managed]::new()
}
$LiveCred = Get-Credential
$Results = Invoke-Command -ComputerName ComputerA -ScriptBlock {
[PSCustomObject]@{
IP = Get-NetIPConfiguration |
Where-Object { $_.IPv4DefaultGateway -and $_.NetAdapter.Status -ne "Disconnected" } |
ForEach-Object {
$_.IPv4Address.IPAddress
}
LastBoot = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
#Requires -Modules ThreadJob
using namespace System.Collections.Generic
function Invoke-AutoCrop {
<#
.SYNOPSIS
Uses the Python AutoCrop tool to crop images down to faces found in the image.
.DESCRIPTION
Using the AutoCrop tool, images are stripped down to just detected faces and either saved over the original
$PrimeNode = nslookup dockerhost.mycorp.com 192.168.31.67 |
Select-String -Pattern Address |
Where-Object LineNumber -eq 5 |
ForEach-Object { $_.Line.Split(' ')[-1] }
$SshData = ssh -q docker@$PrimeNode "cat /dns/zones/db.192.168.169" |
Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}"
$IPList = $SshData -split '; ' | Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}"
$Number = 11
$Property = [PSNoteProperty]::new("IsNumber", $true)
$Number.PSObject.Properties.Add($Property)
$Number # Gives back 11, as you'd expect
$Number | Format-List -Force # shows the hidden property
#Bonus: ScriptProperties can use $this to refer to the object they're attached to
$Number = 7
$AnotherNumber = 42
# Simple approach - let PS's type conversion logic handle it.
# Pitfall: someone can just supply arbitrary text to the function, which is a bit unfortunate.
function Get-Factorial {
param($Number)
if ($Number -eq 0) {
1
}
else {