Skip to content

Instantly share code, notes, and snippets.

View Digiover's full-sized avatar
💭
☕️

Jan Reilink Digiover

💭
☕️
View GitHub Profile
@Digiover
Digiover / add-aspnet-gctrimcommitonlowmemory.ps1
Created February 22, 2024 09:19
Add gcTrimCommitOnLowMemory runtime Aspnet configuration
# https://www.saotn.org/aspnet-performance-what-to-keep-in-mind/#highdensitywebhosting
$bitness = @("64", "")
foreach ($bits in $bitness) {
$xml = New-Object xml
$xml.Load("C:\Windows\Microsoft.NET\Framework${bits}\v4.0.30319\Aspnet.config")
# Check whether the runtime control gcTrimCommitOnLowMemory is already registered
$nodeGcTrimCommitOnLowMemory = $xml.SelectSingleNode("configuration/runtime/gcTrimCommitOnLowMemory")
@Digiover
Digiover / add-aspnet-highdensitywebhosting-performancescenario.ps1
Last active February 22, 2024 09:07
Add Aspnet.config HighDensityWebHosting performanceScenario
# https://www.saotn.org/aspnet-performance-what-to-keep-in-mind/#highdensitywebhosting
$bitness = @("64", "")
foreach ($bits in $bitness) {
$xml = New-Object xml
$xml.Load("C:\Windows\Microsoft.NET\Framework${bits}\v4.0.30319\Aspnet.config")
# Check whether HighDensityWebHosting performanceScenario is already registered
$nodePerformanceScenario = $xml.SelectSingleNode("configuration/performanceScenario")
@Digiover
Digiover / Get-RandomString.ps1
Created June 7, 2023 08:27
Easily create a random string (or secure password) using PowerShell. Add to your PS profile
# Add to your PS profile to create random strings / secure passwords
# from within your PowerShell shell.
#
# Source / Author: Daniel Kåven
# https://teams.se/powershell-script-generate-a-random-password/
function Get-RandomString {
param (
[CmdletBinding(PositionalBinding=$false)]
[Parameter(Position=0)]
[ValidateRange(8, 256)]
@Digiover
Digiover / iis-discover-websites.ps1
Created February 6, 2024 09:34
Zabbix auto discovery for IIS websites
# Query Win32_PerfRawData_W3SVC_WebService for all metric labels (names), including all website names hosted in IIS
#
# The Web Service object includes counters specific to the World Wide Web Publishing Service.
(Get-CimInstance -EA SilentlyContinue -Query "select * from Win32_PerfRawData_W3SVC_WebService" -Namespace root\cimv2).Name
# https://www.saotn.org/monitor-website-performance-in-iis-with-zabbix/
@Digiover
Digiover / Import-PfxCertificateAutomation.ps1
Created June 7, 2023 08:21
Import a PFX certificate into Windows Server and change its FriendlyName property in PowerShell
# Import a PFX certificate into Windows Server and change its
# FriendlyName property in PowerShell.
#
# Using Get-Credential here ensures the password doesn't get saved
# into PowerShell's history file.
# -- see https://www.saotn.org for more PowerShell goodness :)
#
$CommonName = "CHANGEME"
$CertFileName = "CHANGEME.pfx"
@Digiover
Digiover / clear-opcode-caches.php
Last active January 27, 2024 14:05
WordPress: Clear PHP opcode caches before updates are applied, ease the updating process (https://www.saotn.org/wordpress-plugin-flush-php-opcache/)
<?php
/**
* Plugin Name: Clear PHP opcode caches
* Plugin URI: https://www.saotn.org/wordpress-plugin-flush-php-opcache/
* Donate URI: https://www.paypal.me/jreilink
* Description: Purges various PHP opcode and user caches. Currently it tries to clear / purge / flush PHP OPcache and WinCache caches from your web server's memory. This should ease WordPress updates and plugin activation / deactivation.
* Network: True
* Version: 1.2
* Author: Jan Reilink
* Author URI: https://www.saotn.org
@Digiover
Digiover / saotn-wpdb-optimizer.php
Last active June 7, 2023 08:35
Executes an OPTIMIZE TABLE statement on all WordPress MySQL database tables, for instance from within a plugin: https://www.saotn.org/optimize-wordpress-mysql-tables-cron/
/**
* Executes an OPTIMIZE TABLE statement on all WordPress database
* tables.
*/
public static function saotn_wpdb_optimizer() {
global $wpdb;
$tables = $wpdb->get_col( "SHOW TABLES" );
foreach ( $tables as $table ) {
$wpdb->query( "OPTIMIZE TABLE $table" );
}
@Digiover
Digiover / Ansible: Use a custom ssh config file
Created April 12, 2023 22:08
Configure and use a custom ssh config file with Ansible in Windows WSL 2
# Ansible can use a custom ssh config file if you configure its
# ANSIBLE_SSH_ARGS environment variable. Add to your `~/.bashrc`
#
# source: Windows 11/10 and WSL 2 DevOps environment
# - Sysadmins of the North
# https://www.saotn.org/windows-11-10-and-wsl-2-devops-environment/
#
export ANSIBLE_SSH_ARGS="-F ~/.ssh/wsl_config"
@Digiover
Digiover / cleanup-wordpress-database.sql
Created March 8, 2023 10:48
Clean up WordPress meta data, like comment and post meta. Don't forget to set your table prefix
-- Clean WordPress Post Meta Data
SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
-- Clean WordPress Comment Meta Data
SELECT * FROM wp_commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM wp_comments );
DELETE FROM wp_commentmeta WHERE comment_id NOT IN ( SELECT comment_id FROM wp_comments );
SELECT * FROM wp_commentmeta WHERE meta_key LIKE '%akismet%';
DELETE FROM wp_commentmeta WHERE meta_key LIKE '%akismet%';
@Digiover
Digiover / check-website-availability.php
Last active January 15, 2022 07:17
PHP/cURL function to check a web site status. If HTTP status is not 200 or 302, or the requests takes longer than 10 seconds, the website is unreachable. See https://www.saotn.org/php-curl-check-website-availability/.
<?php
/**
* PHP/cURL function to check a web site status. If HTTP status is not 200 or 302, or
* the requests takes longer than 10 seconds, the website is unreachable.
*
* Follow me on Twitter: @Jan_Reilink
*
* @param string $url URL that must be checked
*/
function url_test($url) {