Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
magnetikonline / README.md
Last active April 29, 2024 23:45
PowerShell execute command (.exe) with arguments safely (e.g. with spaces).

PowerShell execute command with arguments safely

In my opinion this is the best way for executing external commands from PowerShell with arguments in a safe manner - via the use of an array to hold the arguments.

Consider this one a PowerShell gem to keep in the toolbox.

Note

The example below makes use of EchoArgs.exe - a small utility that simply echoes back arguments passed to it. Utility is part of the PowerShell Community Extensions, or the exe alone can be downloaded at https://ss64.com/ps/EchoArgs.exe.

Example

@bo67192
bo67192 / powershellgetec2instancefilter.ps1
Created November 3, 2016 23:30
Powershell AWS get-ec2instance example with filter
(Get-EC2Instance -filter @( @{name='tag:Name';values="*Webserver*"})).instances
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active July 5, 2024 10:02
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
CREATE DATABASE [٠০౦০٠];
GO
USE [٠০౦০٠];
GO
CREATE SCHEMA [٠০౦০٠];
GO
CREATE TABLE [٠০౦০٠].[٠০౦০٠]([٠০౦০٠] NVARCHAR(20), [۰০౦০٠] NVARCHAR(20), [٠০౦০۰] NVARCHAR(20), [۰০౦০۰] NVARCHAR(20));
GO
CREATE UNIQUE CLUSTERED INDEX [٠০౦০٠] ON [٠০౦০٠].[٠০౦০٠]([٠০౦০٠], [۰০౦০٠], [٠০౦০۰], [۰০౦০۰]);
GO
@guzmanda
guzmanda / Replace-DatabaseNames.ps1
Last active August 8, 2022 16:38
Replace database name in T-SQL Scripts containing 3-part object name with specified database name
# Modify T-SQL scripts to replace database name in 3-part object names with specified value using T-SQL script DOM.
param (
# Path to folder containing the scripts to modify. Files with .sql extension in this folder and subfolders will be processed.
$scriptFolderPath = "C:\source\repos\DatabaseProjects\AdventureWorks2014",
# Original database name to replace.
$originalDatabaseName = "AdventureWorks2014",
# New database name or SQLCMD variable name.
$newDatabaseName = "[`$(DatabaseName)]",
# Location of Microsoft.SqlServer.TransactSql.ScriptDom.dll assembly.
hass:account
hass:alert
hass:alert-circle
hass:altimeter
hass:apple-safari
hass:apps
hass:arrow-bottom-left
hass:arrow-down
hass:arrow-left
hass:arrow-right
@gideonshaked
gideonshaked / docker-compose.yml
Last active August 2, 2020 20:02
Docker-Compose for adblocking DoH with WireGuard
version: "3"
services:
# pihole
pihole:
container_name: pihole
image: pihole/pihole:latest
restart: always
privileged: true
ports:
- "53:53/tcp"
@potatoqualitee
potatoqualitee / settings.json
Created July 23, 2020 14:16
My Windows Terminal Preview settings.json File
// This file was initially generated by Windows Terminal Preview 1.1.1812.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@matthew-n
matthew-n / ErrorHandler.sql
Last active March 21, 2024 01:28
SQL Server: TSQL Callstack Emulation
IF OBJECT_ID('dbo.ErrorHandler') IS NULL BEGIN
EXEC ('CREATE PROCEDURE dbo.ErrorHandler AS BEGIN SELECT 1; END;');
END
GO
--our error handling procedure
ALTER PROCEDURE dbo.ErrorHandler @procName NVARCHAR(128), @ErrorMessage NVARCHAR(4000) OUTPUT, @ErrorSeverity INT OUTPUT, @ErrorState INT OUTPUT
AS
BEGIN
/* declare sessions keys that are safe for multiple sessions on a single connection */
@leblocks
leblocks / Watch-Files.ps1
Last active February 2, 2024 18:18
multi file tail for powershell core
<#
.SYNOPSIS
Watches text files for changes and prints the specified number of lines from the end of the file.
.DESCRIPTION
This function monitors a set of text files for changes and prints the content to the console.
Each line printed is prefixed by the filename.
.PARAMETER Paths
An array of paths to text files to monitor. This parameter is mandatory.