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 / ColorHelper.php
Created October 23, 2023 16:38
Laravel / PHP - Check if a hexidecimal colour is dark
<?php
namespace App\Helpers;
class ColorHelper
{
// This function tell you if a color is dark or light.
// It is useful when you want to change the text color to white or black depending on the background color.
public static function isColorDark($hexColor = '#ffffff') {
@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 / check.sh
Last active March 11, 2024 10:52
Borg Backup Server + Synology Hyper Backup - Check if there has been a backup in the last 48 hours - NO ENCRYPTION PASS NEEDED
#!/bin/bash
RED="\e[31m"
GREEN="\e[32m"
ENDC="\e[0m"
# Threshold for 48 hours in seconds
threshold=$(( 48 * 3600 ))
# Loop through user directories in /home/
@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
*/
@mrl22
mrl22 / move-storage.sh
Last active February 22, 2024 05:58
Bash script to move storage of all Proxmox Virtual Machines to different storage
#!/bin/sh
movefrom='micronssd'
moveto='wdredpro'
for vm in $(qm list | awk '{print $1}' | grep -Eo '[0-9]{1,3}');
do
for storage in $(qm config $vm | grep $movefrom: | awk '{print $1}' | grep -Eo '[a-z0-9]+');
do
echo Moving VM$vm Storage $storage
@mrl22
mrl22 / README.md
Last active February 6, 2024 12:51
Borgmatic config /etc/borgmatic/config.yaml

apt update

apt install python3-pip borgbackup

pip3 install --user --upgrade borgmatic

pip3 install --upgrade requests

@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 / README.md
Last active January 31, 2024 18:43
Backup your Synology to Linux with Encryption using Hyper Backup

How to Backup Your Synology to Linux with Encryption Using Hyper Backup

This guide has been created to assist those seeking a solution for backing up their Synology NAS to an offsite Ubuntu 22.04 server. Many guides are available for achieving this without encryption, but this guide focuses on incorporating encryption for added security.

Configuring Linux

  1. Setting Up Your Ubuntu Server
    • Begin by configuring your Ubuntu server in the usual manner.
    • Ensure that SSHD is running on a port of your choice, making sure the chosen port is open in the firewall or, for enhanced security, allow access from the public IP of your Synology NAS.
  • It's recommended to disable PasswordAuthentication for improved security.
@mrl22
mrl22 / DialogUserDelete.php
Created January 12, 2024 17:21
Delete User Modal
<?php
namespace App\Http\Livewire\Modals;
use App\Http\Controllers\UserController;
use App\Models\User;
use App\View\Components\Modal;
use Livewire\Component;
class DialogUserDelete extends Component
@mrl22
mrl22 / nginx.conf
Created December 25, 2023 14:05
Nginx Proxy, Hide the real server
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name myrealdomain.com;
ssl_certificate_by_lua_block {
auto_ssl:ssl_certificate()
}
ssl_certificate /etc/ssl/resty-auto-ssl-fallback.crt;
ssl_certificate_key /etc/ssl/resty-auto-ssl-fallback.key;