Skip to content

Instantly share code, notes, and snippets.

@dfar-io
dfar-io / Switch-Stage-Db.ps1
Last active March 10, 2025 22:05
Updates dataSettings.json on an IIS server for NopCommerce to switch databases and restart the app.
<#
Changes staging to use a newly restored database
#>
param (
[Parameter(Mandatory, Position=0)][string]$newDbName
)
$appPoolName = 'NopAbc_Test'
$directory = 'C:\NopABC_Test'
# before running:
#
# 1. Install dependencies:
# cd remnant-2-video-analyzer
# pip install opencv-python pytesseract
# 2. Install Tesseract (https://github.com/tesseract-ocr/tesseract)
# 3. Run python script:
# python main.py
import cv2
'''
Clean up branches older than a specified time based on last commit.
Token rights required: api
'''
import sys
import os
import requests
from datetime import datetime
# Get personal access token from env. variables
@dfar-io
dfar-io / external-url-call-via-cloud-run-function
Created September 11, 2024 15:28
Calls an external URL using Cloud Run Functions
package.json
============
{
"dependencies": {
"@google-cloud/functions-framework": "^3.0.0",
"crypto-js": "4.2.0",
"node-fetch": "2.6.1"
}
}
<#
Backs up and optionally restores a SQL Server database.
#>
param (
[Parameter(Mandatory, Position=0)][string]$backupDbName,
[Parameter(Position=1)][string]$restoreDbName
)
$timestamp = $(((get-date).ToUniversalTime()).ToString("yyyyMMddTHHmmssZ"));
@dfar-io
dfar-io / list_lb_certs.py
Created August 21, 2024 15:10
Lists LB certs across multiple GCP projects.
#!/usr/bin/python
# Gets full list of ILB certs and provides days remaining until expiration
# Output breakout by index:
# 0: NAME header
# 1: TYPE header
# 2: CREATION_TIMESTAMP header
# 3: EXPIRE_TIME header
# 4: REGION header
@dfar-io
dfar-io / sp_index_maintenance.sql
Last active February 21, 2023 19:36
Stored Procedure for cleaning indexes for SQL Server
CREATE PROCEDURE sp_index_maintenance
AS
-- Drop temp table if it exists
IF OBJECT_ID(N'tempdb..#FragmentedIndexes') IS NOT NULL
BEGIN
DROP TABLE #FragmentedIndexes
END
-- Add fragmented indexes to temp table
CREATE TABLE #FragmentedIndexes
@dfar-io
dfar-io / create-pfx-cert.sh
Created February 1, 2022 15:46
Creates a PFX cert using Let's Encrypt
#!/bin/bash
# Creates a PFX certificate using CertBot
# exit when any command fails
set -e
if [ "$1" == "" ] || [ "$2" = "" ]
then
echo "Usage: pfxcert <domain> <output_filename>"
#!/bin/bash
# Adds the appropriate TXT record for creating a Let's Encrypt certificate.
# exit when any command fails
set -e
if [ "$1" == "" ] || [ "$2" == "" ]
then
echo "GODADDY_API_KEY and GODADDY_API_SECRET arguments required."
#!/bin/bash
# Deletes the appropriate TXT record after creating a Let's Encrypt certificate.
# exit when any command fails
set -e
if [ "$1" == "" ] || [ "$2" == "" ]
then
echo "GODADDY_API_KEY and GODADDY_API_SECRET arguments required."
exit 1