Skip to content

Instantly share code, notes, and snippets.


Fred Bradley fredbradley

View GitHub Profile
View function.php
* 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.
View Df.php
function df_tweetEntrant($user) {
// Tweet Entrant
// Follow Entrant
//Sanatize $user
$user = trim($user);
if (strpos($user,'@') !== false) {
fredbradley / DownloadStats.php
Last active Apr 3, 2021
Dashboard Widget showing Download Stats for all Download Monitor Downloads in Wordpress
View DownloadStats.php
* Created by PhpStorm.
* User: fredbradley
* Date: 05/10/2017
* Time: 11:43
namespace FredBradley\CranleighWPAdmin;
fredbradley /
Last active Aug 11, 2017
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 /
Last active Jun 26, 2017
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...


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-]+)|([a-z0-9-]+)|$" AccessControlAllowOrigin=$0
  1. Use that Environment variable to add the header dynamicially
fredbradley / .htaccess
Last active Nov 3, 2016
I'm really hoping someone with more htaccess knowledge than me can help me out!
View .htaccess
# Ok I'm hoping someone might be able to help. Here's the final require scenario
# 1. If someone tries to visit either or it should take them to
# 2. But only if they're from two certain IP ranges (our internal IP ranges).
# 3. It might only be if it's like ''... if the user requests something further like '' 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.
View Button
<a target="_blank" href="" style="color:#0c223f;background-color:#ffc627;border-color:#f3b300;padding:5px 10px;font-size:1.2em;line-height:1.5;border-radius: 3px;display: inline-block;text-align: center; border-width: 1px;border-style: solid;text-decoration:none;vertical-align: middle;">Visit:</a>
View dbeonnect.php
// Database Connection Stuff
define('DB_HOST', 'localhost');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('DB_NAME', 'databasename');
// Global Definitions that are needed for both entry and judging system
define('GROUP_INCLUDES_PATH', '/var/www/html/webvid-awards/group-includes/');
define('PATH_TO_JUDGING', '/var/www/html/judging/');
define('PATH_TO_ENTRIES', '/var/www/html/entries-dev/');
fredbradley /
Last active Nov 4, 2019
Disk Space Checker


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.


This class was developed by Fred Bradley -

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 /
Last active Jun 12, 2018 — forked from mattmezza/
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.
# This script is used for create virtual hosts on CentOs.
# Created by alexnogard from
# Improved by mattmezza from
# Feel free to modify it
# $usr - User
# $dir - directory of web files
# $servn - webserver address without www.