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
Created March 21, 2023 10:01
My Oh My Posh theme
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "#ffffff",
"style": "plain",
"template": "<#CB4B16>[</>{{ .UserName }} ({{ .OS }}-{{ .Shell }})<#CB4B16>]</>",
@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 March 21, 2024 12:52
PowerShell script to automate configuring PostgreSQL for SSPI authentication on Windows
# Requires PowerShell 6+
# Run in your PostgreSQL data directory
# The pg_ctl reload command may require running it with Administrator rights
# Add a user mapping for domain users (or local users if your computer is not in a domain) to your pg_ident.conf
(Get-Content -Path pg_ident.conf -Encoding utf8NoBOM) `
-replace "# MAPNAME SYSTEM-USERNAME PG-USERNAME",`
"# MAPNAME SYSTEM-USERNAME PG-USERNAME`r`nDomainOrLocalUser /^(.*)@$env:USERDOMAIN \1" | `
Set-Content -Path pg_ident.conf -Encoding utf8NoBOM
@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;