Skip to content

Instantly share code, notes, and snippets.

Always coding

Richard Leishman mrl22

Always coding
View GitHub Profile
mrl22 /
Last active February 27, 2023 15:30
Remove WordPress Virus Malware PHP basename() include_once()
if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 
    include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 

You are probably here because you Google'd the above PHP code.

I searched Google, but couldn't find a working solution, so I wrote one!

View shopify-liquid-cheatsheet.liquid
Shopify objects that contain attributes that can be dynamically put on the page. For example, the product object contains an attribute called title that can be used to output the title of a product.
The handle is used to access the attributes of a Liquid object. By default, it is the object’s title in lowercase with any spaces and special characters replaced by hyphens (-). Every object in Liquid (product, collection, blog, menu) has a handle.
Collections & Products
Collection ►
all_types ►
Returns a list of all the product types for a collection
mrl22 /
Created September 2, 2022 19:53
First install

curl -s https://urlto/ | INSTALL_PUBLIC_KEY="ssh-rsa AAAAB3Nzwhatever mrl22@sfsdfsdfsdfsdf" bash -

mrl22 /
Created August 3, 2022 13:21
Install WP-CLI
curl -O
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
mrl22 /
Last active February 13, 2023 13:11
Find files by MD5 Checksum
# We have a client who came to us with a website which was infected with a virus, we found that the virus overwrote and created new files all with the same md5 checksum.
# here is a snippet of code showing how we found all infected files, which could then be modified to delete the files.
find . -name '*.php' -type f -exec bash -c 'md5sum "$0" | grep -q e23bb1f44089aa4aeca6fbd5cf5addd8 && echo $0' {} \;
# Other useful commands
grep -rnw 'md5( sha1' *
grep -rnw 'md5( sha1' * | cut -d ':' -f 1 | xargs -I{} echo {}
mrl22 / 2022_04_19_091631_encrypt_passwords.php
Last active April 19, 2022 09:27
Encrypt unencrypted passwords in Laravel migration with progress bar
View 2022_04_19_091631_encrypt_passwords.php
use App\Models\Company;
use Illuminate\Database\Migrations\Migration;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\ConsoleOutput;
class EncryptPasswords extends Migration
mrl22 / AppServiceProvider.php
Last active April 14, 2022 15:51
keyValueBy macro for Laravel Collection
View AppServiceProvider.php
// Add to public function boot()
Collection::macro('keyValueBy', function ($keyBy, $valueBy) {
$keyBy = $this->valueRetriever($keyBy);
$keyValue = $this->valueRetriever($valueBy);
$results = [];
foreach ($this->items as $key => $item) {
mrl22 /
Created March 1, 2022 16:54
Linux Backup server for Rsync and SSH Keys
# ------------------------------------------------------------------
# Am i Root user?
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
mrl22 /
Last active October 17, 2022 13:34
Server Backup - Files and MySQL to SSH Server using Rsync with Hardlink support to save space

Server Backup

Files and MySQL to SSH Server using Rsync with Hardlink support to save space.

Improved 06/10/2022

This script will keep six daily, three weekly and three monthly rsync hardlinked backup of /etc, /home, /var/www and /root. It will also create a gzipped MySQL dump of the whole server inside each backup.

You must have already have public key access to the remote user.

mrl22 /
Last active February 22, 2022 12:17
Magento Cache Warmer without the expense of a warmer plugin

Dirty, but it works. You do not need to run it until it finishes, a few hundred requests should be good enough.

The purpose is to get all the main pages cached.