Skip to content

Instantly share code, notes, and snippets.

View fredbradley's full-sized avatar

Fred Bradley fredbradley

View GitHub Profile
<?php
namespace App\Actions\GuessWho;
use Illuminate\Support\Collection;
class GenerateGame
{
public Collection $answers;
@fredbradley
fredbradley / backup.sh
Created August 10, 2023 08:18
Old Backup Shell Script
#!/bin/sh
##########################################################################
## IF YOU CHANGE THE PROCESS PLEASE WRITE ABOUT IT ##
## https://wiki.cranleigh.org/doku.php?id=website-2016-backup-process ##
##########################################################################
# 1. SET VARIABLES
BACKUPTIME="www.cranleigh.org-$(date +"%Y-%m-%d")"
BACKUP_DIRECTORY="/var/www/vhosts/www.cranleigh.org/auto_backups"
#!/bin/sh
## When the Senior School Database was overloading some tables and we weren't sure why we have to optimize the DB every day.
## This was the code I used.
mysql -e "SELECT TABLE_NAME FROM (SELECT TABLE_SCHEMA,TABLE_NAME,Round(Sum(data_length + index_length) / 1024 / 1024 / 1024, 2) 'TABLEsizeGB' FROM information_schema.tables WHERE TABLE_SCHEMA='seniorschool' GROUP BY TABLE_SCHEMA,TABLE_NAME HAVING Round(Sum(data_length + index_length) / 1024 / 1024 / 1024, 2) > 0.05 ORDER BY TABLEsizeGB DESC) as A;" | while read TABLE_NAME; do
if [ $TABLE_NAME != 'TABLE_NAME' ]
then
mysqlcheck --optimize seniorschool $TABLE_NAME
fi
@fredbradley
fredbradley / README.md
Last active March 10, 2022 09:44
Disk Space Checker

class.DiskSpaceCheck.php

This class is quick and simple to install into any PHP application, and is easy to customise to the display you require.

The script finds the amount of total disk space on your system, and then the total free space. We then calculate the used space and give it to you as a percentage.

Developer

This class was developed by Fred Bradley - http://twitter.com/fredbradley

Setting the path to check

You can choose the path of the disk that you want to check (if you have multiple disks mounted, for example). You can do this by setting the first paramater when calling calling the Class to the directory that you want to check. EG: $disk = new DiskSpaceCheck('/var/www/vhosts/');

@fredbradley
fredbradley / DownloadStats.php
Last active April 3, 2021 18:13
Dashboard Widget showing Download Stats for all Download Monitor Downloads in Wordpress
<?php
/**
* Created by PhpStorm.
* User: fredbradley
* Date: 05/10/2017
* Time: 11:43
*/
namespace FredBradley\CranleighWPAdmin;
@fredbradley
fredbradley / function.php
Created December 15, 2020 08:59
FRB's De S'er
/**
* We were auditing ~1000 iPads, and found that if you use a Barcode Scanner to
* get the Serial number of a product, it tended to prefix the serial number
* with "S". This was annoying as we were then trying to programatically
* match Serial Numbers against a 3rd party API which didn't have the
* S prefixed!.
*
* This gets rid of the S. We found that all our iPad serial numbers
* started with either "DM" or "F9", but you can change that by
* setting your own $startingChars.
<html>
<head>
<style>
/**
* Update: July 2020
* I have converted this into it's own separate project now: https://github.com/fredbradley/tfl-colours
*/
</head>
<body>
<!-- Here is an example of how the above styles can be implmented!
@fredbradley
fredbradley / create_vhost.sh
Last active June 12, 2018 23:24 — forked from mattmezza/vhost.sh
I have edited @matmezza's code to put the documentroot inside an htdocs subfolder so that you can store other non public files (database connection details or such) outside of public view.
#!/bin/bash
# This script is used for create virtual hosts on CentOs.
# Created by alexnogard from http://alexnogard.com
# Improved by mattmezza from http://you.canmakethat.com
# Feel free to modify it
# PARAMETERS
#
# $usr - User
# $dir - directory of web files
# $servn - webserver address without www.
function df_tweetEntrant($user) {
// Tweet Entrant
// Follow Entrant
//Sanatize $user
$user = trim($user);
if (strpos($user,'@') !== false) {