Skip to content

Instantly share code, notes, and snippets.

View stronk7's full-sized avatar

Eloy Lafuente stronk7

View GitHub Profile
@stronk7
stronk7 / compare_images_rmse.php
Created March 4, 2023 10:43
Compare / calculate the difference between 2 images using the Root Mean Squared Error (RMSE) metric
<?php
/**
* Calculate the Root Mean Squared Error (RMSE) metric between 2 images.
*
* Quick and dirty pure PHP implementation
* of the Root Mean Squared Error metric (RMSE)
* used to compare two images and calculate their difference:
* - Requires the php-gd extension to be available.
* - Using the four (RGB+A) channels.
# Clean any directory only containing phpunit.xml
# sure it was created for another branch and does
# not exist in current one.
candidates=$(find . -name phpunit.xml -not -path "./vendor/*" | xargs dirname | sort -r)
for candidate in ${candidates}; do
numfiles=$(ls -1 ${candidate} | wc -l)
if [[ ${numfiles} -eq 1 ]]; then
echo "Deleting empty ${candidate}"
rm -fr ${candidate}
# if that leads to an empty parent, delete it too
diff --git a/admin/cli/fix_orphaned_calendar_events.php b/admin/cli/fix_orphaned_calendar_events.php
index 8a203b74391..20f83d5170a 100644
--- a/admin/cli/fix_orphaned_calendar_events.php
+++ b/admin/cli/fix_orphaned_calendar_events.php
@@ -113,7 +113,7 @@ if (moodle_needs_upgrading()) {
// Report current site status.
cli_heading('Checking the site status');
-upgrade_calendar_site_status();
+$needsfix = upgrade_calendar_site_status();
@stronk7
stronk7 / check_controller_workers_versions.groovy
Last active March 11, 2023 14:45
Check controller/workers agent versions
import jenkins.model.*
import hudson.remoting.Launcher
import hudson.slaves.SlaveComputer
def expectedVersion = Launcher.VERSION
for (computer in Jenkins.instance.getComputers()) {
if (! (computer instanceof SlaveComputer)) continue
if (!computer.getChannel()) continue
def version = computer.getSlaveVersion()
@stronk7
stronk7 / gist:ba898eb5b239b06b0b234c6e0ca373d3
Created March 31, 2021 21:31
fix calendar events real site
$ php admin/cli/fix_orphaned_calendar_events.php --fix
== Checking the site status ==
This site has executed the problematic upgrade step 2020061504.08 present in 3.9.5.
Fix upgrade steps were NOT found.
This site NEEDS to run the calendar events fix!
You can use this CLI tool or upgrade to a version of Moodle that includes
the fix and will be executed as part of the normal upgrade procedure.
$ php admin/cli/fix_orphaned_calendar_events.php --fix
== Checking the site status ==
This site has executed the problematic upgrade step 2020061504.08 present in 3.9.5.
Fix upgrade steps were NOT found.
This site NEEDS to run the calendar events fix!
You can use this CLI tool or upgrade to a version of Moodle that includes
the fix and will be executed as part of the normal upgrade procedure.
@stronk7
stronk7 / process_print_error_moodle_exception_cases.sh
Last active March 2, 2021 23:01
Look for all the print_error() / moodle_exception() uses, detecting lang strings used, or literals or missing lang strings
#!/usr/bin/env bash
# This script must be put in dirroot, so it's able to find lang files in expected locations.
basepath=${1:-.} # Defaults to current directory, relative dir to look for uses.
pe=0 # print_error() calls
petra=0 # translated print_error() calls
pelit=0 # literal passed in print_error() calls
me=0 # moodle_exception() calls
@stronk7
stronk7 / compare_2_normalised_branches.sh
Created February 22, 2021 16:48
Compare 2 development branches (before they diverge with new features)
#!/bin/bash
# Note this is useful when comparing 2 development branches that other than versions and upgrade lines shoudl be 99%
# the same. Of course before they really begin to diverge, then the utility is not useful any more.
# Setup the desired branches
branch1=MOODLE_311_STABLE
branch2=master
# Prepare branches
@stronk7
stronk7 / cirunner.sh
Created September 14, 2020 09:05
Simple wrapper over moodle-ci-runner for easy launch phpunit/behat dockerised runs locally
#!/opt/local/bin/bash
export WORKSPACE=/tmp/ws
export CODEDIR=/Users/stronk7/git_moodle/ci-tests
export BUILD_ID=cirunner
export PHP_VERSION=${PHP_VERSION:-7.3}
export DBTYPE=${DBTYPE:-pgsql}
@stronk7
stronk7 / .vim-after-syntax-php.vim
Last active December 10, 2021 14:16
My IDE (vim) configuration as of 20200805, mainly for PHP (autocompletion, jump to definition, quick search, LSP integration, Vundle packages, Dash, Spelling on comments, git support... and other personal tricks/niceties). Note that "-" in the file names means "/" (dirs)
" Override the default @Spell on strings via after syntax.
" The lines are 100% the original ones, just changing @Spell by @NoSpell
" Maybe this can be done simpler, but it's easier to just keep a copy
" of the original php.vim code and perform the replacement to @NoSpell.
if (exists("php_parent_error_open") && php_parent_error_open)
syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained keepend
syn region phpBacktick matchgroup=phpStringDelimiter start=+`+ skip=+\\\\\|\\"+ end=+`+ contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained keepend
syn region phpStringSingle matchgroup=phpStringDelimiter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=@NoSpell,@phpAddStrings,phpStrEsc contained keepend
else
syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\