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 / 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.
function df_tweetEntrant($user) {
// Tweet Entrant
// Follow Entrant
//Sanatize $user
$user = trim($user);
if (strpos($user,'@') !== false) {
@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 / README.md
Last active August 11, 2017 09:34
I'd like a bit of help refactoring a couple of bash scripts

Backup Script

What is this?

These two files are what I use to create regular backups on our websites. They create a sql dump of the database, and then a tarball of the directory structure.

Specific Help required

This is all fine, but I want to find a way that a message will be sent to slack if one of the other commands (or the whole script) fails. EG - tar failed because filesystem run out of space; or mysqldump failed because wrong password? or simply 'couldn't find folder!?, etc!

@fredbradley
fredbradley / cors-policy-oddities.md
Last active June 26, 2017 14:12
Can you help? I have a CDN which hosts some CSS files that references some

There are seemingly two ways to allow Cross Origin domains...

OPTION ONE

My preferred way of doing it, because it locks access down to only the specified domains that I allow.

  1. Set Origin Environment
SetEnvIf Origin "http(s)?://(www\.)?(([a-z0-9-]+).domain1.org|([a-z0-9-]+).domain2.org|test.devserver.org)$" AccessControlAllowOrigin=$0
  1. Use that Environment variable to add the header dynamicially
@fredbradley
fredbradley / .htaccess
Last active November 3, 2016 14:58
I'm really hoping someone with more htaccess knowledge than me can help me out!
######
# Ok I'm hoping someone might be able to help. Here's the final require scenario
# 1. If someone tries to visit either www.domain1.org/ar or www.domain2.org/ar it should take them to www.domain3.org/specificpage
# 2. But only if they're from two certain IP ranges (our internal IP ranges).
# 3. It might only be if it's like 'www.domain1.org/ar'... if the user requests something further like 'www.domain1.org/archie-is-cool' it needs to go that that page.
# Background
# It's on a Wordpress Multisite install hence why there's more than one domain that could be request to the same doc_root
# I'm putting this above the Wordpress htaccess stuff, so that it picks it up before trying to compute Wordpress redirects.