Skip to content

Instantly share code, notes, and snippets.

@lzybkr
lzybkr / Solve-KenKen.ps1
Last active January 18, 2022 16:41
Using Z3 w/ PowerShell to solve a KenKen puzzle
using namespace Microsoft.Z3
using namespace System.Collections.Generic
using namespace System.Management.Automation.Language
function GetZ3Ast([System.Management.Automation.Language.Ast]$ast, $ctx)
{
$typeName = $ast.GetType().Name
switch ($typeName)
@lzybkr
lzybkr / ProxyStaticMembers.ps1
Created December 12, 2019 02:00
Create a proxy object for static members of a .Net type
param([type]$Type)
$result = [pscustomobject]@{}
foreach ($property in $type.GetProperties([System.Reflection.BindingFlags]::Public -bor [System.Reflection.BindingFlags]::Static)) {
$name = $property.Name
$params = @{
InputObject = $result
MemberType = 'ScriptProperty'
Name = $property.Name
}
@lzybkr
lzybkr / Invoke-WithEnvironment.ps1
Created October 3, 2019 19:09
Invoke a script block with a temporary environment
param(
[Parameter(Position=0, Mandatory)]
[hashtable]
$private:Environment,
[Parameter(Position=1, Mandatory)]
$private:ScriptBlock
)
end {
@lzybkr
lzybkr / OneShotEnvVar.ps1
Created October 1, 2019 21:18
Hack to enable FOO=bar syntax in PowerShell
$ExecutionContext.InvokeCommand.CommandNotFoundAction =
{
param([string]$commandName,
[CommandLookupEventArgs]$eventArgs)
if ($commandName -match "(.*)=(.*)") {
$var = $matches[1]
if ($var.StartsWith("get-")) {
$var = $var.Substring(4)
}
@lzybkr
lzybkr / ClangAutocompletion.ps1
Created May 8, 2019 02:07
# Autocompletion for clang
# Autocompletion for clang - only works in pwsh
Register-ArgumentCompleter -CommandName clang -Native -ScriptBlock {
param($wordToComplete, $commandAst)
if ($wordToComplete.StartsWith('-')) {
$p,$a = $wordToComplete -split '=',2
if ($null -ne $a) {
$clangArg = "$p=,$a"
$type = [System.Management.Automation.CompletionResultType]::ParameterValue
@lzybkr
lzybkr / format.xsd
Created September 12, 2018 00:42
Types/Format xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Configuration">
<xs:complexType>
<xs:all>
<xs:element name="DefaultSettings" type="DefaultSettings" minOccurs="0" maxOccurs="1"/>
<xs:element name="SelectionSets" type="SelectionSets" minOccurs="0" maxOccurs="1"/>
<xs:element name="Controls" type="Controls" minOccurs="0" maxOccurs="1"/>
<xs:element name="ViewDefinitions" type="ViewDefinitions" minOccurs="0" maxOccurs="1"/>
@lzybkr
lzybkr / Out-Default.ps1
Created March 21, 2018 21:38
Quick and dirty timestamp on output
function Out-Default
{
[CmdletBinding(HelpUri='https://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability='None')]
param(
[switch]
${Transcript},
[Parameter(ValueFromPipeline=$true)]
@lzybkr
lzybkr / Get-AmIPwned.ps1
Last active August 21, 2023 08:16
Query haveibeenpwned.com
<#
.SYNOPSIS
Reports if your password is pwned by querying haveibeenpwned.com
.DESCRIPTION
Query haveibeenpwned.com to see if a password has appeared in a breach.
The query sends the first 5 characters of the SHA1 hash, so the query should be considered safe and anonymous.
@lzybkr
lzybkr / GitHub_DownloadCounts.fsx
Created December 12, 2017 03:40
Get Download counts of all releases for a user/repo
#r "./FSharp.Data.2.4.3/lib/net45/FSharp.Data.dll"
open FSharp.Data
let (user,repo) =
match fsi.CommandLineArgs with
| [| _; arg1; arg2 |] -> (arg1, arg2)
| _ -> failwithf "usage: gh user repo"
@lzybkr
lzybkr / print_tree.ps1
Last active January 4, 2018 02:03
Print a tree with any Key and Parent properties.
# .SYNOPSIS
# Print a tree given a key property and parent property
#
# .PARAMETER InputObject
#
# The object to print.
#
# .PARAMETER KeyProperty