Skip to content

Instantly share code, notes, and snippets.

Oli Mortimer olimortimer

Block or report user

Report or block olimortimer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@olimortimer
olimortimer / gist:e867231fd7b19d17780e
Created Nov 5, 2015
Shell: Compare file names only
View gist:e867231fd7b19d17780e
# Compare file names only, without comparing the contents - good for a quick diff
diff <(cd folder1 && find . | sort) <(cd folder2 && find . | sort)
@olimortimer
olimortimer / gist:38a65007235718482fed
Created Oct 12, 2015
PHP: Round X to the nearest Y
View gist:38a65007235718482fed
<?php
// Round 0.035 up to the nearest 0.01
echo ceil( 0.035 / 0.01 ) * 0.01;
// 0.04
@olimortimer
olimortimer / cloudflare_check.php
Last active Apr 7, 2019
PHP: Check IP is CloudFlare
View cloudflare_check.php
<?php
function cidr_match($ip) {
foreach(file('https://www.cloudflare.com/ips-v4') as $cidr) {
list($subnet, $mask) = explode('/', $cidr);
if ((ip2long($ip) & ~((1 << (32 - $mask)) - 1) ) == ip2long($subnet)) {
return true;
View gist:948bc47d4034b2c7e682
# Magic Git
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOUR="\[\033[0m\]"
View gist:b283d270a4ecce9d51f8
# Force SSL
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Stop browsing of CDN
RewriteCond %{HTTP_HOST} ^cdn\.host\.co\.uk$ [NC]
RewriteCond $1 !\.(css|htc|less|js|js2|js3|js4|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$
RewriteRule ^(.*)$ https://www.host.co.uk/$1 [R=301,L]
@olimortimer
olimortimer / gist:3c675a367b3e3e9f0103
Last active Aug 29, 2015
JS: Pre-populate Fields
View gist:3c675a367b3e3e9f0103
// Populate our field
function populateField($container, name, value) {
var $field = $container.find('[name="'+name+'"]');
// Skip if our field doesn't exist
if($field.length == 0) return false;
if($field.is(':radio')) {
$field.filter('[value="'+value+'"]').prop('checked', true);
@olimortimer
olimortimer / gist:75361ce5959045fd1f5f
Created May 29, 2015
Shell: Find unique file types
View gist:75361ce5959045fd1f5f
# Find all file types recursively within a directory
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u
@olimortimer
olimortimer / cloudflare-api.local
Last active Aug 29, 2015
Shell: Fail2Ban WordPress Logins
View cloudflare-api.local
# Ban IP via Cloudflare API: /etc/fail2ban/action.d/cloudflare-api.local
[Definition]
actionban = curl https://www.cloudflare.com/api_json.html -d 'a=ban' -d 'tkn=1234567890' -d 'email=cloudflare@email.com' -d 'key=<ip>'
actionunban = curl https://www.cloudflare.com/api_json.html -d 'a=nul' -d 'tkn=1234567890' -d 'email=cloudflare@email.com' -d 'key=<ip>'
@olimortimer
olimortimer / gist:e68ffe4aa8009a223c9d
Last active Aug 29, 2015
Shell: Cleaning Email Queue
View gist:e68ffe4aa8009a223c9d
# Delete emails from the queue where the addresses or TO or FROM;
mailq | tail -n +2 | awk 'BEGIN { RS = "" } / name@domain\.co\.uk$/ { print $1 }' | tr -d '*!' | postsuper -d -
mailq | tail -n +2 | awk 'BEGIN { RS = "" } / domain\.co\.uk$/ { print $1 }' | tr -d '*!' | postsuper -d -
mailq | tail -n +2 | awk 'BEGIN { RS = "" } / MAILER-DAEMON@mail\.domain\.com$/ { print $1 }' | tr -d '*!' | postsuper -d -
# Find all IP addresses against the sasl_username and put them into iplist.txt
grep "sasl_username=name@domain.co.uk" /var/log/mail.log | sort -u > iplist.txt
# Go through all the IPs and delete the emails from the queue
grep -wFf /iplist.txt | cut -f 6 -d ' ' | cut -f 1 -d ':' | postsuper -d -
You can’t perform that action at this time.