Skip to content

Instantly share code, notes, and snippets.

@Brar
Brar / MigrateDb.ps1
Last active October 10, 2023 12:29
A PowerShell script to apply database migrations from files stored in the same directoy.
#Requires -Version 7.3
[CmdletBinding()]
Param(
[Version]$TargetVersion = [Version]::new([int]::MaxValue,[int]::MaxValue,[int]::MaxValue,[int]::MaxValue),
[string]$Server = 'localhost',
[ushort]$Port = 5432,
[string]$UserName = [Environment]::UserName,
[Parameter(Mandatory)][string]$Database,
[string]$ApplicationUser = $Database,
[string]$AdminUser = "$Database.Admin",
@Brar
Brar / .ohMyPoshTheme.omp.json
Last active September 6, 2024 05:51
My Oh My Posh theme
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"version": 2,
"auto_upgrade": true,
"final_space": true,
"shell_integration": true,
"patch_pwsh_bleed": true,
"blocks": [
{
"alignment": "left",
@Brar
Brar / Microsoft.PowerShell_profile.ps1
Created March 21, 2023 09:02
My PowerShell profile
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
Import-Module posh-git
Import-Module git-aliases -DisableNameChecking
Import-Module Terminal-Icons
# Oh My Posh configuration
$ohMyPoshTheme = Get-Item "$env:HOME/.ohMyPoshTheme.omp.json" -Force -ErrorAction Ignore
if (-not $ohMyPoshTheme) {
@Brar
Brar / CascadingStreamingReplication.ps1
Last active September 21, 2020 14:24
A PostgreSQL cascading streaming replication setup with failover in a PowerShell script
# Warning! Only start this in an empty directory as it creates and deletes files and directories
# This is tested on Windows and Linux.
# The PostgreSQL bin directory has to be in your PATH and you need a modern PowerShell (> 6.0)
$port = $mainServerPort = 5433
$mainServerId = 1
$mainServerName = "cluster " + $mainServerId
$mainServerPath = "cluster" + $mainServerId.ToString("000")
$previousPort = -1
@Brar
Brar / pitr.ps1
Last active September 21, 2020 12:18
A simple PostgreSQL point in time recovery roundtrip in a PowerShell script
# Warning! Only start this in an empty directory as it creates and deletes files and directories
# Choose a non-default port to avoid issues with a cluster that's already running
$port = 5433
$beforePointInTimeValue = "We want to keep this one!"
$afterPointInTimeValue = "We want to get rid of this one!"
# Initialize a new cluster
Write-Host "Initializing a new cluster..."
initdb -D pitr_cluster -A trust > $null
@Brar
Brar / postgres-configure-sspi.ps1
Last active January 27, 2025 06:57
PowerShell script to automate configuring PostgreSQL for SSPI authentication on Windows
# Requires PowerShell 6+
# Some commands will fail if the PostgreSQL bin directory is not in your PATH
# The pg_ctl reload command may require running it with Administrator rights
$data_directory, $pg_hba_conf_path, $pg_ident_conf_path = psql -c "SELECT setting FROM pg_settings WHERE name IN ('data_directory', 'hba_file', 'ident_file') ORDER BY name" -tU postgres |
%{ $_.Trim() } |
where { $_.Length -gt 0 } |
Convert-Path
# Add a user mapping for domain users (or local users if your computer is not in a domain) to your pg_ident.conf
@Brar
Brar / keybase.md
Last active April 28, 2020 16:40
Keybase proof

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@Brar
Brar / FormatArray.cs
Last active June 12, 2018 18:43
Better array formatting for NUnit
using System;
using System.Text;
namespace FormatArray
{
class Program
{
private const string THREE_DOTS = "...";
private const int StringLen30 = 30;
private const int StringLenUnlimited = 0;