Skip to content

Instantly share code, notes, and snippets.

View tcartwright's full-sized avatar

Tim Cartwright tcartwright

  • Houston, Texas
View GitHub Profile
@tcartwright
tcartwright / TestJWKS.ps1
Created June 14, 2025 19:52
POWERSHELL: Test SSO Server JWKS
param (
[string]$JwksUrl = "https://sso.server.com/.well-known/openid-configuration/jwks"
)
Clear-Host
try {
Write-Host "Fetching JWKS from $JwksUrl ..."
$jwksJson = Invoke-RestMethod -Uri $JwksUrl -UseBasicParsing
@tcartwright
tcartwright / ClaimsAuthWithRoleGroups.md
Last active May 27, 2025 16:49
GENERAL: Claims Based Auth with Role Management

Claims-Based Authentication with Roles, Negations, and Custom Claims

This approach uses claims-based authentication for the API, with roles as a convenient way to manage claims.

Each user or authenticating entity can be assigned one or more roles, and each role maps to a predefined set of claims that represent specific permissions (e.g., can_view_reports, can_edit_users, etc.).

Advanced Features

Two advanced features will be supported:

@tcartwright
tcartwright / CreateDtoFromQuery.sql
Created May 23, 2025 17:34
SQL SERVER: Create DTO from query
/* JUST CHANGE THE CONTENTS OF THE @tsql variable to your query. It does not even need to produce rows */
DECLARE @tsql NVARCHAR(MAX) = N'
SELECT TOP 10 [t].[name],
[t].[object_id],
[t].[schema_id],
[t].[type],
[t].[type_desc],
[t].[create_date]
FROM sys.[tables] AS [t]
@tcartwright
tcartwright / ConfigureIISSiteAlwaysRunning.bat
Last active May 27, 2025 14:20
IIS: Configure web site to always be running, and never spin down
%windir%\system32\inetsrv\appcmd.exe set apppool "POOL_NAME" -startMode:AlwaysRunning
%windir%\system32\inetsrv\appcmd.exe set apppool "POOL_NAME" -processModel.idleTimeout:00:00:00
%windir%\system32\inetsrv\appcmd.exe set apppool "POOL_NAME" -processModel.idleTimeoutAction:Suspend
%windir%\system32\inetsrv\appcmd.exe set app "SITE_NAME/" -preloadEnabled:true
%windir%\system32\inetsrv\appcmd.exe set site "SITE_NAME" -applicationDefaults.preloadEnabled:true
@tcartwright
tcartwright / AssIgnUserAndRoles.sql
Last active April 16, 2025 18:37
SQL SERVER: Map logins to dbs, and assign roles
--SELECT [sp].[name], [sp].[type_desc] FROM sys.[server_principals] AS [sp] WHERE type_desc LIKE 'windows%' ORDER BY [sp].[name]
-- SELECT * FROM sys.[server_principals] AS [sp] WHERE type_desc = 'WINDOWS_LOGIN' AND name LIKE '%.%'
DECLARE @username sysname = '****',
@role_name sysname = 'db_owner'
IF NOT EXISTS (SELECT * FROM sys.[server_principals] AS [sp] WHERE [sp].[name] = @username) BEGIN
RAISERROR('The user [%s] does not exist as a server login.', 16, 10, @username)
RETURN;
END
@tcartwright
tcartwright / GenerateMarkdown.ps1
Last active April 9, 2025 14:57
POWERSHELL: Generate markdown from query
Clear-Host
# UPDATE QUERY / SERVER / DB
$serverInstance = "..."
$database = "..."
$query = "
SELECT * FROM sys.tables
"
# UPDATE QUERY / SERVER / DB
@tcartwright
tcartwright / FromProcedure.sql
Last active June 3, 2025 14:00
SQL: Generate Dapper Params from SQL Server Objects
DECLARE @procedure_name sysname = 'dbo.procedure_name'
SELECT
OBJECT_SCHEMA_NAME([p].[object_id]) AS [schema],
OBJECT_NAME([p].[object_id]) AS [procedure_name],
[p].[name] AS [parameter_name],
CONCAT('sqlParams.Add("', [p].[name] ,'", ', [p].[name], ', ', [fn].db_type, ');')
FROM sys.[parameters] AS [p]
INNER JOIN sys.[types] AS [t]
ON [p].[system_type_id] = [t].[system_type_id]
AND [p].[user_type_id] = [t].[user_type_id]
@tcartwright
tcartwright / ColumnAliasing.sql
Last active March 21, 2025 19:07
SQL SERVER: The various ways to alias a column
-- Examples of the various ways to alias columns. All other methods except for #1 are deprectated or older styles
SELECT
1 AS [one],
2 [two],
3 AS 'three',
4 'four',
5 AS "five",
6 "six",
[seven] = 7,
@tcartwright
tcartwright / postman_load_cdn_js.js
Created March 12, 2025 17:23
POSTMAN: Global functions from CDN javascript file
// can be used at a collection level pre-request script to pull a js from a cdn, and expose the methods to all your requests
// can also use a script package instead of a CDN.
await (async () => {
const requestPromise = new Promise((resolve, reject) => {
pm.sendRequest("https://cdn.foo.com/foo_utils.js", (err, res) => {
if (err) {
console.error(err);
return reject(err);
}
@tcartwright
tcartwright / postman_collection_init.js
Last active March 12, 2025 19:55
POSTMAN: Set up date and lorem variables
// clear out all the current date vales and then re-add them
let vars = JSON.parse(JSON.stringify(pm.globals.values));
vars.forEach((variable) => {
let keyName = variable.key;
if (keyName.match(/^currentdate|^lorem/i)) {
pm.globals.unset(keyName);
}
});