Skip to content

Instantly share code, notes, and snippets.

View sparkcodeuk's full-sized avatar

Dan sparkcodeuk

View GitHub Profile
@sparkcodeuk
sparkcodeuk / gist:c96cf28299779588711e9fac5539076d
Created June 29, 2021 10:18
Recursively PHP lint PHP files (not quitting out if errors are found)
find . -type f -name '*.php' -print0|xargs -0 -n1 -I{} bash -c "php -l {} || true"
@sparkcodeuk
sparkcodeuk / gist:c3f9f1694236b81a05575e416c1b8b81
Created June 29, 2021 10:18
Recursively remove PHP short tags from a codebase
find . -type f -name '*.php' -print0|xargs -0 -n1 perl -i -pe 's/<\?(?!(=|php))(\s?)/<?php$2/'
This tutorial encourages you to stupidly give S3 offload media full access to your S3 services in your AWS account.
Never, ever do this.
Here is a sane policy which will give S3 offload only the access it absolutely requires.
NOTE: this assumes you're uploading objects to /wp-content/... prefix and that you don't need to "browse existing buckets" in the setup.
Beyond this I would recommend enabling "Versioning" on the bucket and implementing an S3 lifecycle rule which performs object expiry of previous versions of objects. This will mitigate any obvious delete/overwrite attacks on your website uploads.
{
{
"Rules": [
{
"Status": "Enabled",
"Prefix": "",
"Destination": {
"Account": "DESTINATION_AWS_ACCOUNT_ID",
"Bucket": "arn:aws:s3:::DESTINATION_S3_BUCKET_NAME",
"AccessControlTranslation": {
"Owner": "Destination"
@sparkcodeuk
sparkcodeuk / floating-ip-gateway.sh
Created March 2, 2018 21:47
Digital Ocean floating IP gateway script (force droplet to use the assigned floating IP for outbound traffic as well as inbound traffic)
#!/bin/bash
# Force outbound traffic through the attached floating IP
NET_INT="eth0"
CURL_TIMEOUT=3
echo -n "Setting floating IP as the default gateway: "
# Check there's a floating IP attached to this droplet
if [ "$(curl -s --connect-timeout $CURL_TIMEOUT http://169.254.169.254/metadata/v1/floating_ip/ipv4/active)" != "true" ]; then

Keybase proof

I hereby claim:

  • I am sparkcodeuk on github.
  • I am sparkcode (https://keybase.io/sparkcode) on keybase.
  • I have a public key ASD5GyZNA7gAdm_QSS6aURZYlVb6t-Zj5qle5KrBCfLiNgo

To claim this, I am signing this object: