Skip to content

Instantly share code, notes, and snippets.

View jhoneill's full-sized avatar

James O'Neill jhoneill

View GitHub Profile
$query = "Hp850 g5"
$Content = '{"requests":[{"indexName":"prod_cex_uk","params":"attributesToRetrieve=%5B%22boxBuyAllowed%22%2C%22boxName%22%2C%22boxSaleAllowed%22%2C%22boxWebBuyAllowed%22%2C%22boxWebSaleAllowed%22%2C%22cannotBuy%22%2C%22cashPrice%22%2C%22categoryFriendlyName%22%2C%22categoryName%22%2C%22collectionQuantity%22%2C%22ecomQuantity%22%2C%22exchangePrice%22%2C%22imageUrls%22%2C%22isNewBox%22%2C%22masterBoxId%22%2C%22masterBoxName%22%2C%22outOfEcomStock%22%2C%22superCatFriendlyName%22%2C%22superCatName%22%2C%22boxId%22%2C%22outOfStock%22%2C%22sellPrice%22%2C%22exchangePerc%22%2C%22cashBuyPrice%22%2C%22scId%22%2C%22discontinued%22%2C%22new%22%2C%22cashPriceCalculated%22%2C%22exchangePriceCalculated%22%2C%22rating%22%2C%22ecomQuantityOnHand%22%2C%22priceLastChanged%22%2C%22isImageTypeInternal%22%2C%22imageNames%22%2C%22Grade%22%5D&clickAnalytics=true&facets=%5B%22*%22%5D&filters=boxVisibilityOnWeb%3D1%20AND%20boxSaleAllowed%3D1&hitsPerPage=100&maxValuesPerFacet=1000&page=0&query=QQQQQ&userToken=819
@jhoneill
jhoneill / Tied_Variables.Ps1
Last active June 26, 2025 22:50
Demonstration of PowerShell Tied / automatic variables
<# The template for our class looks like this
// Constructor for our variable calls PSVariables' constructor with Name, value, options
public class XYZVariable : System.Management.Automation.PSVariable {
public XYZVariable () : base("XYZ", / Name
0, // Value
ScopedItemOptions.ReadOnly | // Options
ScopedItemOptions.AllScope){}
// variable objects have a value property, override it to return our value
public override object Value {
get {
A0034
A0035
A0057
A0066
A0087
A0088
A0115
A0116
A0121
A0206
using namespace System.Windows.Forms.DataVisualization.Charting
using namespace System.Windows.Forms
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PsUseShouldProcessForStateChangingFunctions','',Justification='False positive. New-object does not change system state ')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSPossibleIncorrectUsageOfAssignmentOperator','',Justification='False positive. New-object does not change system state ')]
param()
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms.DataVisualization
function New-FormWithSave {
[outputType([System.Windows.Forms.Form])]
# Use Set-thread-execution-state to prevent the computer sleeping. From something of Den Delimarsky's at https://den.dev/blog/caffeinate-windows/
Param ([switch]$Now, [switch]$AndDisplay )
if (-not ('win32.system' -as [type])) {Add-Type -Name System -Namespace Win32 -MemberDefinition @"
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern void SetThreadExecutionState(uint esFlags);
"@}
function Suspend-Sleep {
param ([switch]$AndDisplay)
function Expand-PropertyTree {
<#
.Synopis
Unrolls an object with many sub-objects.
.Example
C:> Get-Process -id $PID | Expand-PropertyTree | ft -a Path,value
Outputs the paths and values for the unrolled properties for a process object and displays path and value as a table.
By default the modules and threads properties are limited to showing on 2 of their many members
We can use -MaxArrayItems to get a different number 0 won't expand at all, and a negative number will expand ALL of them.
<#
.Synopsis
Signs a script
.DESCRIPTION
Gets a users code signing certificate, (if there is just one in "Cert:\CurrentUser\My" it will be selected automatically)
and uses it to sign a script file using a timestamping service.
Without the Time Stamp (Comodo CA is used by default) the signature is only valid for the range of dates on the certificate
If -passthrough is specified, retuns the certificate object
Else, if -quiet is specified doesn't reurn anything
Otherwise outputs the detail of the signature
#experimental response to https://github.com/PowerShell/PowerShell/issues/20750
function TabExpansion2 {
<# Options include:
RelativeFilePaths - [bool]
Always resolve file paths using Resolve-Path -Relative.
The default is to use some heuristics to guess if relative or absolute is better.
To customize your own custom options, pass a hashtable to CompleteInput, e.g.
return [System.Management.Automation.CommandCompletion]::CompleteInput($inputScript, $cursorColumn,
@{ RelativeFilePaths=$false }
using namespace System.Data
class QueryColumnCache {
#region properties. Static params for Get-SQL, query, column to use, values of that col, when to refresh
static [hashtable]$QueryParams
hidden [string]$SQLQuery
hidden [string]$SQLColumnName
hidden [timeSpan]$MaxAge
[datetime]$_LastRefresh
hidden [String[]]$Values
class SmartBuilder { # A string builder with a progress bar that automatically fluses periodically.
[System.Text.StringBuilder] hidden $Builder # The builder itself - its a sealed class otherwise the smartbuilder would be based on it.
#region supporting properties
[string]$RepeatingHeader = '' # If set, the repeating header is re-added as the first line after each flush
[scriptblock]$OnFlush = {$this.ToString()} # What to do when we flush the data (besides clearing the builder and re-adding any header) - should return a string or nothing.
[bool] hidden $_ShowProgress = $true # If false, don't show the progress bar
[string] hidden $_Activity = 'Building' # Displayed on the progress bar - accessed via $ProgressStatus
[string] hidden $_Status = 'Items so far' # Displayed on the progress bar with ": <ItemCount>" - accessed via $ProgressStatus