Skip to content

Instantly share code, notes, and snippets.

Avatar
✏️
working on https://writiny.com in my sparse spare time

Jay Caines-Gooby jaygooby

✏️
working on https://writiny.com in my sparse spare time
View GitHub Profile
@jaygooby
jaygooby / netblock-from-whois
Last active Aug 2, 2022
Gets and caches the netblock owner from `whois` for an IP address
View netblock-from-whois
#!/bin/bash
#
#
# MIT License
#
# Copyright (c) 2022 Jay Caines-Gooby, @jaygooby, jay@gooby.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
@jaygooby
jaygooby / nginx-google-domain-csp-map.sh
Created Feb 6, 2020
Use the correct google country domain in your nginx content-security-policy header, instead of all of them
View nginx-google-domain-csp-map.sh
#!/bin/bash
#
# Generates an nginx compatible map that you can use to
# put the relevant Google country code in your Content-Security-Policy
# instead of having them all.
#
# Add these to your nginx config:
# geoip2 /path/to/GeoLite2-Country.mmdb {
# $geoip2_country_code default=US source=$remote_addr country iso_code;
# $geoip2_country_name country names en;
@jaygooby
jaygooby / git_notes.md
Last active Jul 26, 2022
Git, you bloody git
View git_notes.md

Initialising a new repo with a different initial branch

After working on some new code, I realised I wanted to push it to an existing remote git repo, but in a branch that didn't exist. The code hadn't been pulled from anywhere - it was newly written in a directory.

Initialise the directory with the branch that you want it to become, commit the code, add the existing remote and push:

git init --initial-branch=my-fun-feature

git add -A && git commit -m "WIP"

@jaygooby
jaygooby / percona-xtrabackup.sh
Last active May 9, 2022
Call via crontab on whatever schedule suits you; keep n full mysql Percona xtrabackups of your mysql database, with binary logs applied. Also does a full mysqldump that can then have the binary logs applied to restore to a point-in-time backup via the binlogs. Copy all of this (backup, mysqldump, binlogs) to S3.
View percona-xtrabackup.sh
#!/bin/bash
#
# Carries out a full mysqldump, calls percona-xtrabackup and then
# copies the sql dump, the percona backup and your mysql bin logs
# to S3 using s3cmd http://s3tools.org/s3cmd
#
# TODO: extract out the S3 backup stuff to make it optional, and so
# other s3 programs can replace the s3cmd call.
# TODO: the if [ $? == 0 ] alert blocks should be a function
# TODO: make the if [ $? == 0 ] if [ $? != 0 ] more consistent - test
View unknown-host
#!/bin/bash
#
# https://jay.gooby.org/2021/02/10/unknown-host
#
# Use this to remove the offending line from your
# ~/.ssh/known-hosts file when you know the host
# has actually changed and you get the
#
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@jaygooby
jaygooby / log4j-jndi.conf
Last active Feb 2, 2022
fail2ban filter rule for the log4j CVE-2021-44228 exploit
View log4j-jndi.conf
# log4j jndi exploit CVE-2021-44228 filter
# Save this file as /etc/fail2ban/filter.d/log4j-jndi.conf
# then copy and uncomment the [log4j-jndi] section
# to /etc/fail2ban/jail.local
#
# jay@gooby.org
# https://jay.gooby.org/2021/12/13/a-fail2ban-filter-for-the-log4j-cve-2021-44228
# https://gist.github.com/jaygooby/3502143639e09bb694e9c0f3c6203949
# Thanks to https://gist.github.com/kocour for a better regex
#
View interesting-referers
#!/bin/bash
#
# MIT License
#
# Copyright (c) 2021 Jay Caines-Gooby, @jaygooby, jay@gooby.org
#
# The one-liner from https://jay.gooby.org/2021/11/30/find-interesting-referers-in-access-log
#
# Usage: interesting-referers /path/to/access.log
# interesting-referers /path/to/access.log example.com
@jaygooby
jaygooby / what-user-agent
Last active Dec 15, 2021
bash script to humanize user-agent strings using the whatismybrowser.com API
View what-user-agent
Moved to https://github.com/jaygooby/what-user-agent
@jaygooby
jaygooby / kaslurp
Last active Dec 8, 2021
A REPL wrapper for kaput-cli to download files from put.io
View kaslurp
Now https://github.com/jaygooby/kaslurp
@jaygooby
jaygooby / src-hilite-lesspipe.sh
Last active Sep 3, 2021
A modified version of gnu source-highlight's src-hilite-lesspipe.sh that also works with piped files and files with no extensions. It uses the file command to guess the language. This means you can use source-highlight in conjunction with commands like "git show"
View src-hilite-lesspipe.sh
#! /bin/bash
#
# Based on http://git.savannah.gnu.org/cgit/src-highlite.git/tree/src/src-hilite-lesspipe.sh.in
# by Lorenzo Bettini
#
# Modified by Jay Caines-Gooby to support piped files
# jay@gooby.org
# @jaygooby
#
# Typically called by setting: