Skip to content

Instantly share code, notes, and snippets.

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active Oct 21, 2021
Useful PostgreSQL Queries and Commands
View postgres_queries_and_commands.sql
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
View xpath-cheatsheet.js
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
@indented-automation
indented-automation / Get-CommandParameter.ps1
Last active Oct 4, 2021
PowerShell version 2 param block parser
View Get-CommandParameter.ps1
function Get-CommandParameter {
# .SYNOPSIS
# A PowerShell version 2 compatible parameter block parser.
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 1, ValueFromPipelineByPropertyName = $true)]
[String]$Definition
)
@mattifestation
mattifestation / WMI_persistence_template.ps1
Created Mar 20, 2016
Fileless WMI persistence payload template (CommandlineEventConsumer, __IntervalTimerInstruction trigger, w/ registry payload storage)
View WMI_persistence_template.ps1
# Step #1 - Prep payload
$Hive = 'HKLM'
$PayloadKey = 'SOFTWARE\PayloadKey'
$PayloadValue = 'PayloadValue'
$TimerName = 'PayloadTrigger'
$EventFilterName = 'TimerTrigger'
$EventConsumerName = 'ExecuteEvilPowerShell'
switch ($Hive) {
'HKLM' { $HiveVal = [UInt32] 2147483650 }
@indented-automation
indented-automation / Get-CommandParameter.ps1
Created Jul 28, 2018
Gets the parameters for a command from the default parameter set
View Get-CommandParameter.ps1
function Get-CommandParameter {
param (
[Parameter(Mandatory = $true)]
[String]$Command,
[Switch]$GetDefaultValues
)
$commonParameters = ([System.Management.Automation.Internal.CommonParameters]).GetProperties().Name
$shouldProcessParameters = ([System.Management.Automation.Internal.ShouldProcessParameters]).GetProperties().Name
$defaultParams = $commonParameters + $shouldProcessParameters
View Get-NumberRange.ps1
function Get-NumberRange
{
[cmdletbinding()]
Param()
DynamicParam {
$Dictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
$NewDynParam = @{
Name = "Firstnumber"
Alias = "int"
@jkdba
jkdba / AutomaticJobCleanup.ps1
Last active Mar 13, 2019
PowerShell Automatically Cleanup Job on Completion Using a Registered Object StateChanged Event
View AutomaticJobCleanup.ps1
#Build Job Name to be unique
$JobName = "ExampleJob"
$JobNameCount = (get-job | Where-Object Name -like $JobName*).Count
$JobName = "$($JobName)_$($JobNameCount)"
#Define and Start job
$Job = Start-Job -Name $JobName -ScriptBlock { Start-Sleep 60 }
#Create Event to clean up job after complete
Register-ObjectEvent -InputObject $Job -EventName "StateChanged" -Action {
@mxpv
mxpv / windows_build_numbers.txt
Last active Feb 19, 2019
Windows build numbers
View windows_build_numbers.txt
Windows Name or Service Pack Version Number
---------------------------- --------------
Windows 1.0 1.04
Windows 2.0 2.11
Windows 3.0 3
Windows NT 3.1 3.10.528
Windows for Workgroups 3.11 3.11
@jkdba
jkdba / ToastNotification_Windows10.ps1
Created May 9, 2016 — forked from altrive/ToastNotification_Windows10.ps1
Windows 10 toast notification sample
View ToastNotification_Windows10.ps1
$ErrorActionPreference = "Stop"
$notificationTitle = "Notification: " + [DateTime]::Now.ToShortTimeString()
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
#Convert to .NET type for XML manipuration
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null