Skip to content

Instantly share code, notes, and snippets.

View chaddupuis's full-sized avatar

Chad Dupuis chaddupuis

View GitHub Profile
@chaddupuis
chaddupuis / push-django-updates.yaml
Last active December 21, 2022 19:15
Ansible to push code updates for Django running with unicorn/nginx behind a cloudflare load balancer
- hosts: webservers
become: yes
vars:
my_ip_range: x.x.x.x/24
my_db: x.x.x.x
#following from cloudflare.com/ips
cf_1: 173.245.48.0/20
cf_2: 103.21.244.0/22
cf_3: 103.22.200.0/22
cf_4: 103.31.4.0/22
@chaddupuis
chaddupuis / blogmodel.py
Created December 21, 2022 19:18
Django Full Text Search using Postgres SearchQuery with Faceted and Paginated Results
from django.db import models
from django.utils.text import slugify, Truncator
from django.db.models.functions import Lower
from django.db.models.signals import pre_save, post_save, post_delete, m2m_changed
from django.contrib.postgres.search import SearchVectorField, SearchVector
from django.contrib.postgres.indexes import GinIndex
from django.db.models import Value
import re
@chaddupuis
chaddupuis / renew-certs.sh
Created December 21, 2022 19:21
Lego (acme go client) bash script for renewals (with SAN lists)
#!/bin/bash
# Likely in a cron job to handle cert renewals.
# The acme go client is here - https://github.com/go-acme/lego
lego_bin=/etc/goclient/lego/lego
lego_path=/etc/goclient/lego
lego_certs="$lego_path/certificates"
web_root=/var/www/html
our_kid=""
@chaddupuis
chaddupuis / nginx-ansible-server.yaml
Created December 21, 2022 19:23
Ansible to build an nginx server with certbot
# post base server setup
# nginx, pulls confs from git repo
# certbot setup and general firewall conf
#
- hosts: nginxweb
become: yes
vars:
my_ip_range: x.x.x.x/24
my_jump_ip: x.x.x.x
@chaddupuis
chaddupuis / settings.py
Created December 21, 2022 19:26
Django Recaptcha fix for SSL:CERTIFICATE_VERIFY_FAILED unable to get local issuer
'''
There are likely a few fixes for this but you are likely to see this error
if your app needs to reach out to an https server (in this case https://google.com)
and it cannot verify the ssl certificate.
The certifi package ( https://pypi.org/project/certifi/ ) provides a
curated collection of Root Certificates that avoids this.
pip install certifi - then in your settings you just need to set
the environmental variable for REQUESTS_CA_BUNDLE and SSL_CERT_FILE.
@chaddupuis
chaddupuis / getdatafromqemu.md
Last active July 13, 2023 15:10
Recover Data From A Multipass Qemu VM Image That Won't Start on MacOS M1/M2 (using linux)

Multipass on MacOS m1/m2 machines has had some ongoing issues with VM's working for awhile then failing to start. Previously, through some combination of these steps, I could get multipass working again and access my previous builds. After losing some data a couple of times this way, I've decided to ditch multipass for now. Unfortunately, this one time I had some data from an unfinished build that I had to get off one of the vm images that I could no longer start.

I tried a few ways of doing this solely on the mac, but I ended up copying the image file over to a desktop running suse/tumbleweed (distro shouldn't matter for these) and accessing the files there. Here are the general steps:

  • Find your vm image (need sudo). On a mac these should be in /var/root/Library/Application\ Support/multipassd/qemu/vault/instances/ - then in a folder with the name of your vm, grab the .img file and copy it somewhere and chown it to your local account.

  • Copy the

@chaddupuis
chaddupuis / pipupdater.sh
Created August 2, 2023 20:35
Update outdated python packages in docker container and write out new requirements.txt
#!/usr/bin/env bash
#set -euo pipefail
# no set -e has diff results in non-zero
echo "Checking Inside of Container For Outdated Pip"
hostdatetime=$(date +"%d-%m-%y-%H-%M-%S")
docker exec -i yourcontainer /bin/sh -c 'python3 -m pip list --outdated'
@chaddupuis
chaddupuis / lstocsv.sh
Created August 7, 2023 14:37
linux - ls files into a csv (without dot files and without the created csv)
#!/bin/bash
find . -type f \( ! -iname ".*" ! -iname "mydir.csv" \) -exec basename {} \; | xargs | tr -s ' ' , > mydir.csv
@chaddupuis
chaddupuis / docker-fix-networking.sh
Created November 14, 2023 21:11
Docker - Allow Communication Between Two Bridged Networks On Same Host (via iptables)
#!/bin/bash
## If docker containers are running on two separate bridge networks,
## by default they cannot communicate
## To selectively allow this you can use iptables rules to allow communication.
## This script, connects an app ("webapp") to a database ("postgres") running on separate networks.
postgresip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' postgres)
webappip=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' webapp)
@chaddupuis
chaddupuis / macos-ciscovpn-connect.sh
Last active November 30, 2023 23:04
macOS Cisco AnyConnect CLI Connect Without Password (using macOS keychain)
#!/bin/sh
VPNNUM=#you might not have a choice here, so possibly not needed
ADDRESS=vpn.com
USER=yourusername
PASS=$(security find-generic-password -a yourusername -l yourkeylistitem -w)
/usr/bin/expect -f - <<EOD
set timeout 20