Skip to content

Instantly share code, notes, and snippets.

View mrl22's full-sized avatar
💭
Always coding

Richard Leishman mrl22

💭
Always coding
View GitHub Profile
@mrl22
mrl22 / install-wp-cli.sh
Created August 3, 2022 13:21
Install WP-CLI
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
@mrl22
mrl22 / script.sh
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
mrl22 / 2022_04_19_091631_encrypt_passwords.php
Last active April 19, 2022 09:27
Encrypt unencrypted passwords in Laravel migration with progress bar
<?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
mrl22 / AppServiceProvider.php
Last active April 14, 2022 15:51
keyValueBy macro for Laravel Collection
<?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
mrl22 / create-user.sh
Created March 1, 2022 16:54
Linux Backup server for Rsync and SSH Keys
#!/bin/bash
# ------------------------------------------------------------------
# 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
mrl22 / README.md
Last active June 9, 2023 10:45
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
mrl22 / README.md
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.

@mrl22
mrl22 / README.md
Last active March 14, 2024 14:32
PHP 8.1 Support for Apache and NGINX (OpenResty) on Moss.sh

Do not copy and paste this code, it requires changes

Other PHP versions available here: https://gist.github.com/search?q=user%3Amrl22+moss

As of writing this, Moss.sh does not support PHP 8.1 via the control panel even though Ubuntu does.

Set up your website using Moss.sh and select Apache with PHP 7.4.

Once complete, we need to install PHP 8.1 with all the packages moss installs for 7.4.

@mrl22
mrl22 / README.md
Last active April 11, 2023 12:06
PHP 8.0 Support for Apache and NGINX (OpenResty) on Moss.sh

Do not copy and paste this code, it requires changes

Other PHP versions available here: https://gist.github.com/search?q=user%3Amrl22+moss

As of writing this, Moss.sh does not support PHP 8.0 via the control panel even though Ubuntu does.

Set up your website using Moss.sh and select Apache with PHP 7.4.

Once complete, we need to install PHP 8.0 with all the packages moss installs for 7.4.

@mrl22
mrl22 / README.md
Created November 15, 2021 11:47
Replacing Latin1 with UTF8 characters in MySQL

If you happen to migrate content from an old database to a new one, you might come across some odd characters like — or ’. This is most likely due to the change if charsets of your database/tables.

The following code snippet can be used to replace odd characters in your database.

UPDATE table_name SET field_name = CONVERT(CAST(CONVERT(field_name USING latin1) AS BINARY) USING utf8)