Skip to content

Instantly share code, notes, and snippets.

View wesort's full-sized avatar

Ben Edmonds wesort

View GitHub Profile
@wesort
wesort / static-site-section-of-nginx.conf
Last active April 14, 2025 13:26
The part of nginx.conf on forge.laravel.com for static sites.
location / {
if ($request_uri ~ ^/(.*)\.html$) {
return 302 /$1?$args;
}
try_files $uri $uri.html $uri/ =404;
}
error_page 404 /404.html;
@wesort
wesort / v1-statamic-section-of-nginx.conf
Last active July 3, 2019 08:37
The v1.Statamic part of nginx.conf file on forge.laravel.com
...
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.com/server/*;
# Start selecting and copying below
#################################################
# Edit the domain below
error_log /var/log/nginx/example.com-error.log error;
@wesort
wesort / v2-statamic-section-of-nginx.conf
Last active April 1, 2022 14:17
The v2.Statamic part of nginx.conf file on forge.laravel.com
...
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/example.com/server/*;
# For legacy URL redirect with query parameters
# - create a file called "legacy-redirect.map" with a new line for each redirect
# - example line: /old-url/with?query /new-url/without-a-query;
# - Add the following BEFORE the server block, update the path and uncomment the include line
map $uri$is_args$args $new_uri {
default 0;
@wesort
wesort / batch-images.md
Last active February 19, 2019 22:08
How to batch process images with bash & Imagemagick

Resize files and append height to filename with bash & Imagemagick

  • Run each command separately
  • Move files to correct directory mv * ~/path/to/image_directory

Resize keeping aspect ratio (useful for srcset)

NB: create each directory first

@wesort
wesort / .gitconfig
Last active September 2, 2025 13:20
git config with aliases
[user]
name = wesort
email = ben@wesort.co.uk
[push]
default = simple
[alias]
lg = "log --oneline -n 10 --decorate --graph --format=\"%C(auto)%h%Creset %C(auto)%d%Creset %s %C(auto)(%an, %ad)%Creset\" --date=format:\"%d %b %Y at %H:%M\""
lg-all = log --all --decorate --oneline --graph
conflict = diff --name-only --diff-filter=U
goback = !git reset --hard HEAD && git clean -fd
@wesort
wesort / https-redirects.txt
Last active May 17, 2018 14:55
HTTPS: htaccess redirect from http, http + www, and https + www
RewriteEngine On
#
# Redirect all http and www traffic to https non-www URL
# Ref for all but first line: https://simonecarletti.com/blog/2016/08/redirect-domain-http-https-www-apache/
# Ref to correct for Webfaction using nginx ssl proxy: cpbotha.net... https://goo.gl/Vnbdw9
#
RewriteCond %{HTTP:X-Forwarded-SSL} !on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
@wesort
wesort / html-crc-reload.js
Created January 2, 2018 14:02
JS to auto-refresh page on file changes
<script>
/*
crc-reload is a script to auto reload the current page when you save the html.
Version 0.1 - Initial release
Usage:
Requires jquery (stable with v1.6.2+)
Include this js file in your html page.
It will ajax GET poll the current page every second and if the html is different, reload itself.
Useful on a dev site within an environment conditional.
@wesort
wesort / autobackup.sh
Last active November 11, 2025 16:34
Automatic daily backup from production site to GitHub
# Shell script to automatically backup current branch to GitHub
# NB: artisan commands apply to Laravel projects
git add .
git commit -m "[BOT] Automatic daily backup via cronjob"
git push
php artisan optimize:clear
php artisan optimize
# Instructions
# 1. SSH into the server
@wesort
wesort / inbox-stats.js
Last active May 31, 2023 21:37
Google Apps Script to automatically get stats (count of threads, age in days of oldest message) on Gmail inbox
// Google Apps Script to automatically get stats within a Gmail inbox
// Stats logged:
// - current date & time
// - username / email address
// - # of message threads in inbox
// - Age in days of oldest message
// 1. Visit https://script.google.com and create a new project
// 2. Name the project
// 3. Copy and paste this gist