Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Hutmacher dhmacher

View GitHub Profile
@dhmacher
dhmacher / New-MastodonPost.ps1
Created December 19, 2022 07:01
Powershell function to post a simple, plaintext status to a Mastodon instance
View New-MastodonPost.ps1
<#
To create an access token,
* go to settings -> Development
* Click "New Application"
* Enter a name
* Allow "write:statuses"
* Click Submit
* Click on the new application to review the keys
* The "Access token" is the one you need
@dhmacher
dhmacher / New-PasswordLink.ps1
Created December 16, 2022 13:53
Powershell code to generate a password pusher URL (using pw.strd.co)
View New-PasswordLink.ps1
View dbo.Template_Split.sql
/*
Copyright Daniel Hutmacher under Creative Commons 4.0 license with attribution.
http://creativecommons.org/licenses/by/4.0/
Source: https://github.com/sqlsunday/sp_ctrl3
DISCLAIMER: This script may not be suitable to run in a production
environment. I cannot assume any responsibility regarding
the accuracy of the output information, performance
View Find primary key candidates.sql
-- Source: https://sqlsunday.com/2017/02/21/finding-primary-key-candidates/
IF (OBJECT_ID('dbo.FindPrimaryKey') IS NULL)
EXEC('CREATE PROCEDURE dbo.FindPrimaryKey AS --');
GO
/*
This stored procedure is used to identify primary key candidates.
Copyright Daniel Hutmacher under Creative Commons 4.0 license with attribution.
@dhmacher
dhmacher / Agent job visualization.sql
Created October 22, 2021 08:37
Visualize agent jobs as a gannt chart
View Agent job visualization.sql
--- Read more: https://sqlsunday.com/2016/11/17/visual-representation-of-sql-server-agent-jobs/
/*
Copyright Daniel Hutmacher under Creative Commons 4.0 license with attribution.
http://creativecommons.org/licenses/by/4.0/
Source: http://sqlsunday.com/downloads/
DISCLAIMER: This script may not be suitable to run in a production
@dhmacher
dhmacher / LoadTableBlobs.sql
Created October 22, 2021 08:34
Imports an XML blob into a set of relational tables.
View LoadTableBlobs.sql
--- Read this first: https://sqlsunday.com/2016/06/16/copying-data-with-foreign-keys-and-identity-columns/
IF (OBJECT_ID('dbo.LoadTableBlobs') IS NULL) EXEC('CREATE PROCEDURE dbo.LoadTableBlobs AS --')
GO
/*
Copyright Daniel Hutmacher under Creative Commons 4.0 license with attribution.
http://creativecommons.org/licenses/by/4.0/
Source: http://sqlsunday.com/downloads/
View Decrypt T-SQL modules.sql
-- More information: https://sqlsunday.com/2013/03/24/decrypting-sql-objects/
SET NOCOUNT ON
DECLARE @owner sysname='dbo', @name sysname='sp_someprocedure';
-----------------------------------------------------------
--- Declarations:
DECLARE @offset int=1;
DECLARE @datalength int;
@dhmacher
dhmacher / Extract-WooCommerceOrders.ps1
Created October 12, 2021 13:12
Generates a SIE accounting file from WooCommerce sales orders.
View Extract-WooCommerceOrders.ps1
# Provided as-is, without any warranty, implied or express.
# General:
$file = "Precon-" + (Get-Date).toString("yyyyMMdd-HHmmss") + ".se"
$baseUri = "https://example.com/wp-json/wc/v3/"
# WooCommerce authentication:
$key = "cs_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
$secret = "cs_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $key, $secret)))
View dbo.Partition_Boundary_Values.sql
-------------------------------------------------------------------------------
---
--- Reverse $PARTITION function - returns the boundary values for a given
--- partition function and partition number.
---
--- Returns:
---
--- Lower_Boundary sql_variant NULL for first partition
--- Lower_Boundary_Condition varchar(2) "<=" or "<"
@dhmacher
dhmacher / ConvertTo-UTF8
Created June 30, 2021 19:33
Converts an ISO-8859-1 string to UTF-8. Handy on when you receive a response from a web API that does not specify the codepage.
View ConvertTo-UTF8
# https://stackoverflow.com/a/53034595/5471286
function ConvertTo-UTF8 {
param(
[Parameter(ValueFromPipeline)] [string]$ISOString
)
return ([Text.Encoding]::UTF8.GetString( `
[Text.Encoding]::GetEncoding(28591).GetBytes($ISOString)))
}