Skip to content

Instantly share code, notes, and snippets.

@DerfJagged
DerfJagged / remove_duplicate_files.py
Last active June 27, 2025 05:01
Finds duplicate files on your MediaWiki instance, deletes the newer one, and adds a redirect on the new page to the first uploaded version.
#!/usr/bin/python3
# By Derf Jagged
# Update the two EXAMPLE entries, BOT_USERNAME_HERE, and PASSWORD_HERE
import requests
import json
import mwclient
from datetime import datetime
def parse_iso_timestamp(ts_str):
@DerfJagged
DerfJagged / tag_namespace_with_category.py
Created June 25, 2025 05:35
Python script to tag MediaWiki pages with a category matching the page's namespace.
#!/usr/bin/python3
import requests
import mwclient
import re
import os
os.system('cls')
# Variables
excluded_namespaces = {"MediaWiki", "Media", "Template", "Module", "Topic", "Talk", "User", "File", "Category", "Special", "Translations", "Hidden"}
@DerfJagged
DerfJagged / Emoji_Time.ps1
Last active June 12, 2025 18:36
Lets you set text or an emoji for every hour's AM/PM indicator. It's pizza time.
# Must save as UTF-8 with BOM
# Set as hourly scheduled task
# Updates after a minute has passed
$OutputEncoding = [System.Text.UTF8Encoding]::new()
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
$hour_labels = @{
'0' = "🌜"
'1' = "🛌"
@DerfJagged
DerfJagged / Get_Dates_for_Upcoming_Weekdays.ps1
Created November 7, 2024 17:27
Get Dates for Upcoming Weekdays
$currentDate = Get-Date
$currentDate9am = $currentDate.Date.AddHours(9)
$weekendDaysEncountered = 0
$nextDayOccurrance = @("NULL","NULL","NULL","NULL","NULL")
for ($i = 0; $i -le 7; $i++) {
$targetDate = $currentDate9am.AddDays($i)
Write-Host $target-Date.DayOfWeek
switch ($targetDate.DayOfWeek) {
'Monday' {$nextDayOccurrance[0] = $targetDate.ToString("MM/dd")}
'Tuesday' {$nextDayOccurrance[1] = $targetDate.ToString("MM/dd")}
@DerfJagged
DerfJagged / Run_PowerShell_Script_from_ToastNotification.ps1
Created November 7, 2024 16:27
Run PowerShell Script from Windows ToastNotification
This example shows a toast with a button for each day of the week. When selected, it runs a script called WindowsUpdatePS1.ps1, passing it the day of the week as an argument.
You have to create a registry entry for this.
<toast>
...
<actions>
<action content="Mon" arguments="ToastUpdateWindows:,Monday" activationType="protocol" />
<action content="Tues" arguments="ToastUpdateWindows:,Tuesday" activationType="protocol" />
<action content="Wed" arguments="ToastUpdateWindows:,Wednesday" activationType="protocol" />
<action content="Thurs" arguments="ToastUpdateWindows:,Thursday" activationType="protocol" />
@DerfJagged
DerfJagged / Rename_Windows_Profile_in_Registry.ps1
Created November 2, 2024 04:26
Rename Windows Profile in Registry
# Script to change all registry entries containing old username to new username.
#
# 1. Create a second admin account on your PC
# 2. Log out of your primary account and into the secondary account
# 3. Rename profile via Control Panel > User Accounts
# 4. Rename old username in C:\Users\ to new username
# 5. Change the two variables below and run the script in Admin PowerShell. It will take a long time.
# 6. Log into the renamed profile and run the script again. This will change the registry entries that may be only editable by the owner account.
# Define the old and new user paths
@DerfJagged
DerfJagged / Delete_Duplicate_Files.py
Created November 1, 2023 02:10
MediaWiki Delete Duplicate Files Script
#!/usr/bin/python3
import requests
import json
import mwclient
################### CONFIGURE ME ###################
site = mwclient.Site('YOUR_WEBSITE.com', path='/wiki/')
site.login(username='USERNAME_HERE', password='PASSWORD_HERE')
URL = "https://YOUR_WEBSITE.com/wiki/api.php"