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 / README.md
Created December 16, 2024 10:18
Laravel 9+ Rollback previous up() migration

How to rollback to previous created migrations. This works on Laravel 8.37 and above, since anonymous migration classes were introduced.

@mrl22
mrl22 / deploy.sh
Created November 15, 2024 17:43
Deploy script for custom php application
#!/usr/bin/bash
BASE_DIR="/home/user/sites/site.com"
GIT_SSH=""
BRANCH="master"
SHARED=("failed" "temp" "uploads" "working") # root directories that will be moved into shared storage and symlinked on each deploy
# Dont forget to setup your SSH key in Github
##############################
@mrl22
mrl22 / script.sh
Created November 3, 2024 16:31
Multithreaded recursive upload to dropbox using dbxcli with resume
# Uploads everything in the current directory to Dropbox UPLOAD directory (change line 7)
# Configured for 2 threads, any more and you get api throttling errors
find . -type f -print0 | xargs -0 -n 1 -P 2 -I {} sh -c '
file="{}"
log_file="uploaded_files.log"
dropbox_path="UPLOAD${file#.}"
# Check if file is already in log
if grep -qxF "$file" "$log_file"; then
@mrl22
mrl22 / README.md
Last active November 5, 2024 16:42
Laravel Forge Zero-Downtime Deploy Script with Releases and Persistant Storage

Laravel Forge Zero-Downtime Deploy Script

Features

  • Zero Downtime - Gets everything ready, and then switches the current directory symolic link
  • NPM Install
  • Composer Install
  • Persistant storage at /storage/
  • 5 most recent releases are stored in /releases/ for quick rollback
@mrl22
mrl22 / updatephp.sh
Last active July 23, 2024 12:38
Forge Recipe: Update PHP-FPM Settings - All Installed PHP Versions
#!/usr/bin/env bash
declare -A replacers
# Define the settings to be replaced or added
replacers[upload_max_filesize]=500M
replacers[post_max_size]=500M
replacers[max_input_vars]=5000
replacers[memory_limit]=512M
replacers[max_execution_time]=360
@mrl22
mrl22 / main.go
Last active July 21, 2024 21:54
Connect to Laravel Reverb from Golang for two-way communication
package main
import (
"encoding/json"
"github.com/gorilla/websocket"
"log"
"net/url"
"os"
"os/signal"
"syscall"
@mrl22
mrl22 / searchNumber.sql
Created July 2, 2024 14:05
3CX CRM MySQL Query for WHMCS Contacts
select id as contactid, firstname, lastname, email, phonenumber as phonebusiness from tblcontacts where CONCAT('44',TRIM(LEADING '0' FROM TRIM(LEADING '+44.' FROM REPLACE(phonenumber, ' ', '')))) = '@Number';
@mrl22
mrl22 / README.md
Last active May 22, 2024 17:56
PHP 8.3 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 STILL does not support anything above PHP 7.4 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.3 with all the packages moss installs for 7.4.

@mrl22
mrl22 / battery.sh
Created February 2, 2024 20:50
APCUPSD / APCACCCESS - Get power consumption in Watts.
#!/usr/bin/sh
APC=$(apcaccess status)
NOMPOWER=$(echo "$APC"|grep NOMPOWER|cut -d' ' -f3)
LOADPCT=$(echo "$APC"|grep LOADPCT|cut -d' ' -f4)
WATTS=$(echo "$NOMPOWER / $LOADPCT"|bc)
echo "$WATTS Watts"
@mrl22
mrl22 / SimpleCacheBridge.php
Last active February 25, 2024 14:48
Psr\SimpleCache\CacheInterface implementation for Laravel - Tested on Laravel 10 with PHP 8.2
<?php
/**
* Created by PhpStorm.
* User: leo108
* Date: 2017/8/14
* Time: 15:44
*
* Updated by Richard Leishman to support PHP 8.2
*/