This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compare file names only, without comparing the contents - good for a quick diff | |
diff <(cd folder1 && find . | sort) <(cd folder2 && find . | sort) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for f in *; do mv "$f" `echo $f | tr ' ' '_'`; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Round 0.035 up to the nearest 0.01 | |
echo ceil( 0.035 / 0.01 ) * 0.01; | |
// 0.04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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\]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find all file types recursively within a directory | |
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 protected]' -d 'key=<ip>' | |
actionunban = curl https://www.cloudflare.com/api_json.html -d 'a=nul' -d 'tkn=1234567890' -d '[email protected]' -d 'key=<ip>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 "[email protected]" /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 - |
NewerOlder