Skip to content

Instantly share code, notes, and snippets.

View stronk7's full-sized avatar

Eloy Lafuente stronk7

View GitHub Profile
@stronk7
stronk7 / check_lang_string_uses.sh
Last active May 4, 2017 21:24
Basic script to detect (by commit) uses of deleted lang strings within behat .feature files
#!/bin/bash
# Find uses in .feature files corresponding to deleted strings for a given commit.
# Far from ideal for multiline strings, but does its work for 1 line ones.
# Usage: within a git repo: check_lang_string_uses.sh <commit>. Look for ERROR @ output.
commit=${1:-HEAD}
count=0
retcode=0
@stronk7
stronk7 / testbackup.php
Created November 14, 2014 10:58
Simple scripts to quickly test backup & restore from terminal
<?php
define('CLI_SCRIPT', true);
require_once('config.php');
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
$course_module_to_backup = 1;
$section_to_backup = 2;
$course_to_backup = 2;
@stronk7
stronk7 / dommagic.php
Created April 8, 2015 00:06
Fix broken HTML using DOM hidden superpowers...
<?php
$brokenhtml = '<p>this is broken</p>because i want to </div></div></div><script><script type="text/javascript"><!--';
echo fixhtmlplz($brokenhtml) . "\n\n";
$brokenhtml = '<b>because <i>I can leave <p>everything <div> unclosed
using many <span> lines and <ul> more yet <li> lists
<li> more and
<li> more';
echo fixhtmlplz($brokenhtml) . "\n\n";
@stronk7
stronk7 / pre-push
Last active December 20, 2020 23:18
pre-push hook to avoid Moodle upstream branches to perform travis/github actions builds all the time
#!/bin/bash
# pre-push hook to enable/disable travis and github actions push builds
# based on the nature of the pushed branches.
# - upstream and deleted ones won't be built.
# - development ones will be built.
# Requires travis (client) gem binary installed.
# Requires gh (client) binary installed.
# Useful for people wanting to keep their upstream branches updated,
# and not causing them to perform travis/github actions builds all the time, like me :-)
IFS=' '
#!/bin/bash
while read -r line; do
echo Processing: $line
if [[ ${line} =~ ^\"MDL-[0-9]*\",\"(.*)\" ]]; then
versions=${BASH_REMATCH[1]}
echo Versions: ${versions}
IFS=',' read -ra versionsarr <<< "$versions"
for version in "${versionsarr[@]}"; do
echo $version
#!/bin/bash
# Find uses of deleted strings for a given commit within codebase.
# May lead to false positives but easily detectable in any case.
#
# Usage: within a git repo: verify_deprecated_string_uses.sh <commit>. Look for ERROR @ output or exit code.
commit=${1:-HEAD}
status=0
pushd "$(git rev-parse --show-toplevel)" > /dev/null
echo "Checking commit ${commit}"
while read -r line; do
@stronk7
stronk7 / hide and lock grade items example
Last active September 9, 2016 09:07
hide and lock grade items example
diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php
index 18e7c16..a246696 100644
--- a/grade/report/grader/lib.php
+++ b/grade/report/grader/lib.php
@@ -838,6 +838,12 @@ class grade_report_grader extends grade_report {
}
} else {
// Element is a grade_item
+ if ($element['object']->itemname == 'One database') {
+ $element['object']->itemname = 'Deletion in progress';
@stronk7
stronk7 / Dockerfile
Created April 10, 2017 07:39
A very simple docker image to use unoconv easily
FROM ubuntu:xenial
RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y unoconv && \
apt-get clean && \
rm -rf /var/lib/apt/lists/
# Get latest unoconv script and hack it to use python3.
# (it fixes an issue about unoconv listener failing first time with libreoffice).
/usr/local/bin/salt-cron.sh:
file.managed:
- user: root
- group: root
- source: salt://system/cron/salt-cron.sh
- mode: 755
/usr/bin/chronic /usr/local/bin/salt-cron.sh | /usr/bib/logger -t salt-cron:
cron.present:
- identifier: SALT
@stronk7
stronk7 / gist:c19466f7f43faf532d719670a94b7dfb
Created March 27, 2019 09:53
With phpunit 7.x assertEquals(string, string) comparisons now being strict (===), we need to keep them lazy (coz DB returns strings)
Reference: https://github.com/sebastianbergmann/phpunit/issues/3185
stronk7@~/git_moodle/moodle (phpunit70 *$%)$ git diff mod/quiz
diff --git a/mod/quiz/tests/attempt_walkthrough_from_csv_test.php b/mod/quiz/tests/attempt_walkthrough_from_csv_test.php
index 3556793f612..029dbd2ffb1 100644
--- a/mod/quiz/tests/attempt_walkthrough_from_csv_test.php
+++ b/mod/quiz/tests/attempt_walkthrough_from_csv_test.php
@@ -338,7 +338,7 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
$this->assertEquals((bool)$value, $attemptobj->is_finished());
break;