Skip to content

Instantly share code, notes, and snippets.

View Mte90's full-sized avatar
🎯
Creating new open source stuff that you will like

Daniele Scasciafratte Mte90

🎯
Creating new open source stuff that you will like
View GitHub Profile
@Mte90
Mte90 / clean.sh
Created March 17, 2020 19:58
Clips dataset parser and cleaner
#!/usr/bin/env bash
function extract() {
echo "Estraggo $1.rar"
unrar e "./$1.rar" \*.txt \*.wav './clips-mitads/' -o+
}
if [ ! -d './clips-mitads' ]; then
mkdir './clips-mitads'
fi
@Mte90
Mte90 / php-error-in-wp.php
Last active April 14, 2020 06:09
PHP error in WordPress backend wrapped as native notice. Refer/screenshot on https://core.trac.wordpress.org/ticket/35155
<?php
/*
Plugin Name: Error For WP backend
Plugin URI: https://github.com/Mte90/
Description: Wrap the PHP errors in the WP admin backend with the native notice
Author: Mte90
Version: 1.0.0
*/
@Mte90
Mte90 / remove_gutenberg_block.php
Created June 11, 2020 15:51
Remove WordPress Gutenberg block in content
<?php
function remove_block_gutenberg( $content, $blockname ) {
$blockname = str_replace('/', '\/',preg_quote($blockname));
return preg_replace('/\<\!\-\- ' . $blockname . '[^)]+\/' . $blockname . ' \-\-\>/', '', $content);
}
// Based on this ticket https://wordpress.org/support/topic/strip-table-of-content-from-excerpt/
// There is a block that we don't want on excerpt automatically generated,
// Automatic excerpt cut the content and this can generate a broken content
@Mte90
Mte90 / backup.sh
Created July 7, 2020 14:17
Backup to webdav files and WordPress DB
#!/bin/sh
today=$(date +"%Y-%m-%d")
path=$(date +"%Y/%m/%d")
rm -rf ./backups
mkdir ./backups
tar --exclude='./public_html/cgi-bin' --exclude='*.zip' --exclude='./public_html/wp-content/cache' -zcvf ./backups/$today.tar.gz ./public_html > /dev/null
./wp db export --add-drop-table --path=./public_html/ - | gzip > "./backups/$today.sql.gz"
curl --user "user:pass" -T "./backups/$today.tar.gz" "https://domain.com/remote.php/webdav/folder/$path/domain-$today.tar.gz"
@Mte90
Mte90 / opensupport-cron.sh
Last active September 15, 2020 09:30
OpenSupports Cron to activate users
#!/bin/bash
mysql --user='[users]' --password='[psw]' --database='[db]' --execute="UPDATE user SET verification_token = NULL WHERE user.verification_token IS NOT NULL;"
@Mte90
Mte90 / pre-push.sh
Last active October 2, 2020 10:21
pre-push
#!/bin/sh
# If the branch is not master, execute phpmetrics and upoload everything on the VPS
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $current_branch != "master" ]; then
sshpass -p your-password ssh user@domain.tld mkdir -p /var/www/your-path/status/master/
sshpass -p your-password rsync --progress -avzP /home/your-user/.cache/QualityAnalyzer/assets -e ssh user@domain.tld:/var/www/your-metrics/status/$current_branch/ > /dev/null
sshpass -p your-password rsync --progress -avzP /home/your-user/.cache/QualityAnalyzer/index.html -e ssh user@domain.tld:/var/www/your-metrics/status/$current_branch/ > /dev/null
/usr/bin/phpmd /var/www/VVV/www/site/public_html/wp-content/plugins/your-plugin/ xml /CodeatCS/codeat-phpmd.xml --exclude vendor,tests --reportfile /tmp/phpmd-analysis.xml
/home/your-user/.cache/QualityAnalyzer/bin/analyze analyze /var/www/VVV/www/site/public_html/wp-content/plugins/your-plugin/ --exclude=vendor,tests --exclude_analyzers=cpd,pdepend,checkst
@Mte90
Mte90 / update-bot.sh
Last active January 28, 2021 09:55
Auto update Mozilla Italia bot and restart them on unix system
#!/usr/bin/env bash
cd /opt/mozita/
cd ./mozitaantispam_bot/
git fetch --all
if [[ $(git rev-list HEAD...origin/master --count) -ne 0 ]]; then
pkill -f antispam_mozita.py
git stash
git pull
#!/usr/bin/env bash
#
# This script injects a file into the current Apache2 environment temporarily
# in order to check its syntax.
#
# INSTALL:
# sed -i "2i ServerName example.com" /etc/apache2/sites-available/000-default.conf
# Require adding this line to the example conf
#
# USAGE:
@Mte90
Mte90 / snippet.php
Last active February 24, 2021 18:25
Custom WordPress Error Handler. Support Query Monitor and can be used as mu-plugin.
<?php
/*
* Plugin Name: Better errors
* Description: Better errors in log
* Author: Daniele Scasciafratte
* Version: 1.0
* Author URI: http://codeat.co
*/
function handleError($code, $description, $file = null, $line = null, $context = null) {
@Mte90
Mte90 / woo-iva.php
Last active March 24, 2021 17:17
Esempio plugin per WooCommerce che aggiunge una colonna
<?php
/**
* Plugin Name: WooCommerce Colonna IVA
* Description: Aggiunge una colonna nei prodotti WooCommerce
* Version: 1.0.0
* Author: LUGRieti
* Author URI:
* Requires at least: 4.9
* Tested up to: 4.9
*