Skip to content

Instantly share code, notes, and snippets.

@defulmere
defulmere / install_gnupg.sh
Last active October 14, 2023 15:50
Install latest (as of 2023-02) gnupg on Opalstack
#!/bin/bash
mkdir -p ~/opt/{tmp,src}
export TMPDIR=~/opt/tmp
export CPPFLAGS="-I$HOME/opt/include $CPPFLAGS"
export LDFLAGS="-L$HOME/opt/lib $LDFLAGS"
export LD_LIBRARY_PATH=$HOME/opt/lib
export PATH=$HOME/opt/bin:$PATH
echo 'export PATH=$HOME/opt/bin:$PATH' >> ~/.bashrc
@defulmere
defulmere / masto_upgrade_353_to_4.md
Created November 15, 2022 22:48
tl;dr mastodon upgrade from 3.5.3 to 4.0.2

Adapted from the official upgrade notes and starting with a v3.5.3 non-Docker source install:

# back everything up first, then as mastodon user
cd ~/live
git fetch && git checkout v4.0.2
# do next step only if you're stuck on ruby 3.0.3
sed -e -i 's/3.0.4/3.0.3/' .ruby-version
bundle install
@defulmere
defulmere / add-security-headers.php
Created January 21, 2022 01:18
Simple plugin to enable security headers in Wordpress, drop into the plugins directory and then enable via your WP dashboard
<?php
/*
Plugin Name: Add Security Headers
Description: adds security headers to wordpress
*/
function add_security_headers() {
if ( $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on' ) {
header('Strict-Transport-Security: max-age=31536000');
header('X-XSS-Protection: 1; mode=block');
@defulmere
defulmere / drupal_open_social_opalstack.md
Last active September 6, 2021 23:11
drupal and open social on opalstack
  1. Create a new MariaDB database and user at https://my.opalstack.com/mariadb/ and make a note of the database name, database user name, and database user password.

  2. Create a new shell user at https://my.opalstack.com/apps/.

  3. SSH to the new shell user and run the following commands:

    cd ~
    # install composer
    mkdir -p ~/bin
    wget -O composer-setup.php https://getcomposer.org/installer
    php74 composer-setup.php --install-dir=$HOME/bin --filename=composer
    
@defulmere
defulmere / rabbitmq_on_opalstack.md
Last active January 30, 2024 17:39
rabbitmq on opalstack

RabbitMQ on Opalstack

  1. Some preparatory steps:

     mkdir -p ~/tmp ~/src ~/lib
     export TMPDIR=~/tmp
     export PATH=$HOME/bin:$PATH
    
  2. Create a 'nginx proxy port' application named 'epmd' in the dashboard to reserve a port for epmd. (11111 in the examples below)

@defulmere
defulmere / gist:438b3cf94cc725c6a67e40888e1e280a
Last active December 27, 2022 09:08
colored bar graph of system load over time in terminal with atopsar
np=$( nproc ); atopsar -p | grep ":[0-9]\{2\}\s\+[0-9]" | awk '{printf("\n%s %6.2f ",$1, $5); for (i = 0; i<$5; i++) {if (i<'$np'*.7) {printf "\033[32m"} else if (i<'$np') {printf "\033[33m"} else {printf "\033[31m"}; printf("█")}; printf "\033[0m"}'; echo ""
@defulmere
defulmere / nextcloud_on_opalstack.md
Last active August 24, 2022 01:49
Nextcloud on Opalstack

HOWTO install Nextcloud on Opalstack

  1. In your Opalstack dashboard create a new "Nginx Proxy Port" application and attach it to a site with Let's Encrypt enabled on the site. Make a note of the app's name and port assignment, and the site domain.

  2. In your Opalstack dashboard create a new MariaDB database and user. Make a note of the DB name, DB user name, and password.

  3. SSH to your app's shell user and run the following commands:

    cd ~/apps/appname
    git clone -b opalstack https://github.com/rsanden/userspace-fpm-installer.git
    cd userspace-fpm-installer
    
@defulmere
defulmere / github_post_recieve.php
Created December 7, 2020 01:16 — forked from cowboy/github_post_recieve.php
GitHub PHP webhook to auto-pull on repo push
<?php
// Use in the "Post-Receive URLs" section of your GitHub repo.
if ( $_POST['payload'] ) {
shell_exec( 'cd /srv/www/git-repo/ && git reset --hard HEAD && git pull' );
}
?>hi
@defulmere
defulmere / list_cloudflare_ips.py
Created February 27, 2020 21:50
Get a list of all cloudflare IPv4 addresses with python
import requests
from ipaddress import *
subnets = requests.get('https://www.cloudflare.com/ips-v4').content.split()
for s in subnets:
subnet = IPv4Network(s.decode())
for h in subnet.hosts():
print(h)
@defulmere
defulmere / settings.py
Last active April 19, 2024 15:00
How to override an old sqlite3 module with pysqlite3 in django settings.py
# ⚠️ USE AT YOUR OWN RISK
# first: pip install pysqlite3-binary
# then in settings.py:
# these three lines swap the stdlib sqlite3 lib with the pysqlite3 package
__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
DATABASES = {