Skip to content

Instantly share code, notes, and snippets.

Avatar

Chad Dupuis chaddupuis

View GitHub Profile
@chaddupuis
chaddupuis / settings.py
Created Dec 21, 2022
Django Recaptcha fix for SSL:CERTIFICATE_VERIFY_FAILED unable to get local issuer
View settings.py
'''
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 / nginx-ansible-server.yaml
Created Dec 21, 2022
Ansible to build an nginx server with certbot
View nginx-ansible-server.yaml
# 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 / renew-certs.sh
Created Dec 21, 2022
Lego (acme go client) bash script for renewals (with SAN lists)
View renew-certs.sh
#!/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 / blogmodel.py
Created Dec 21, 2022
Django Full Text Search using Postgres SearchQuery with Faceted and Paginated Results
View blogmodel.py
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 / push-django-updates.yaml
Last active Dec 21, 2022
Ansible to push code updates for Django running with unicorn/nginx behind a cloudflare load balancer
View push-django-updates.yaml
- 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 / load_remote_images.py
Created Dec 21, 2022
Django Image Scraping and Writing to S3 with NamedTemporaryFiles (no local copies)
View load_remote_images.py
from csv import DictReader
from django.core.files import File
import urllib.request
from urllib.request import urlopen
from tempfile import NamedTemporaryFile
from django.core.management.base import BaseCommand
import time
from PIL import Image
from io import BytesIO
from django.core.files.base import ContentFile
@chaddupuis
chaddupuis / bash_profile.sh
Created Dec 21, 2022
Use Google Drive from Linux as a Virtual Drive (Gnome GIO Library)
View bash_profile.sh
# alias to provide readable directory listings when using mounted google drives on linux
alias lg='gio list -a "standard::display-name"'
@chaddupuis
chaddupuis / create-products-from-csv.php
Created Dec 21, 2022
Processwire CLI - Example Processing a CSV to Processwire Fields
View create-products-from-csv.php
<?php namespace ProcessWire;
// This is an example of the transfer of product data (could be anything)
// from a csv to their corresponding fields in a processwire template
// and creating the pages. This uses the processwire feature of instantiating
// an instance from a command line script to access global variables
// (https://processwire.com/blog/posts/multi-instance-pw3/).
require('/var/www/dev.dev.com/wire/core/ProcessWire.php');
$st = new ProcessWire('/var/www/dev.dev.com/', 'https://dev.dev.com/');
@chaddupuis
chaddupuis / apt-update-upgrade.yml
Created Dec 21, 2022
Basic Ansible - APT Upgrade
View apt-update-upgrade.yml
---
- hosts: mytargets
become: true
tasks:
- name: update apt repo and cache
apt:
upgrade=dist
update_cache=yes
force_apt_get=yes
cache_valid_time=3600
@chaddupuis
chaddupuis / processwire-google-merchant-csv.php
Created Dec 21, 2022
Google Merchant CSV Creation from Processwire - For Inclusion in Google Shopping
View processwire-google-merchant-csv.php
<?php namespace ProcessWire;
require('/var/www/yourpw.com/wire/core/ProcessWire.php');
$st = new ProcessWire('/var/www/yourpw.com/', 'https://yourpw.com/');
// gmerchant header
//id title description link condition price availability image link gtin mpn brand google product category
//product_to_google is a pw field - if 1 send it to google, if 0 do not send
$myGmerchantProducts = $st->pages->find("template=page-general-product|page-other-product, product_to_google=1, sort=title");
$howMany = 0;