Skip to content

Instantly share code, notes, and snippets.

View theonlyway's full-sized avatar

Anthony theonlyway

  • Queensland, Australia
View GitHub Profile
import botocore.waiter
import botocore.session
session = botocore.session.get_session()
client = session.create_client('ec2')
VOLUME_ID = ... # e.g. 'vol-049df61146c4d7901'
INSTANCE_ID = ... # e.g. 'i-1234567890abcdef0'
DEVICE = ... # e.g. '/dev/xvdba'
@theonlyway
theonlyway / postgres_queries_and_commands.sql
Created June 21, 2023 02:00 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- 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%'
@theonlyway
theonlyway / postgresql.md
Created June 21, 2023 01:49 — forked from mencargo/postgresql.md
PostgreSQL Queries

Useful PostgreSQL Queries & Commands

All sizes in MB, change /1024/1024 to /1024/1024/1024 for GB.

Databases sizes

Without system databases

select
datname as database,
(pg_database_size(datname)/1024/1024) as size
@theonlyway
theonlyway / excel.ps1
Last active January 18, 2022 10:41
Loop through list of password protected excel files and save them as a csv with new name
# path to the files with a wildcard at the end
$sourcePath = "C:\Repos\excelpassword\*"
# place to save the files
$destPath = "C:\Repos\excelpassword"
# gets a list of all the files but only includes files with the .xlsx extension
$items = Get-ChildItem -Path $sourcePath -Include *.xlsx
# password for the file(s)
$password = 'T&4gh!$Tnw'
# Creates the excel object
$excel = New-Object -comobject Excel.Application
Get-AWSSAMLAssertion -rolescope All
foreach ($stsrole in $global:stsroles)
{
Set-AWSCredentials -AccessKey $stsrole.credentials.AccessKeyId -SecretKey $stsrole.credentials.SecretAccessKey -SessionToken $stsrole.credentials.SessionToken
$checks = Get-ASATrustedAdvisorChecks -Language en
$i = 0
$account = Get-IAMAccountAlias
if ($stsrole.credentials.Expiration -gt (Get-Date))
{
# Installs the AzureRM PowerShell module from the PSGallery
Install-Module AzureRM -force
# Logs you in to Azure
Login-AzureRmAccount
# Gets your Azure subscription then selects it which essentially logs you in to it. Needs to be done if your account has access
# to multiple subscription
Get-AzureRmSubscription -SubscriptionName "enter your subscription name" | Select-AzureRmSubscription
# Gets a list of all the Azure VM's in your subscription
$vms = Get-AzureRmVM
# Initializes a empty variable for $details to give it the ability to add more than one item easily
$blah = @("<script>`n", 'cfn-init.exe -v -s ', ' -r WindowsServer2012R2 ', `
' --region ', "`n", '</script>')
#requires -Version 2.0
$logfiledate = Get-Date -Format 'yyyy-MM-dd %h-m-ss'
$logfile = "C:\Admin\Logs\Deployment Transcript $logfiledate.txt"
Start-Transcript -path $logfile
if ( (Get-PSSnapin -Name 'VMware.VimAutomation.Core' -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin -Name 'VMware.VimAutomation.Core'
}
Write-Host Connecting to server -ForegroundColor 'magenta'
connect-viserver blah -ErrorAction Stop
Function Get-LoggedOnUsers {
<#
.Synopsis
Queries a computer to check for interactive sessions
.DESCRIPTION
This script takes the output from the quser program and parses this to PowerShell objects
.NOTES
Name: Get-LoggedOnUser