Skip to content

Instantly share code, notes, and snippets.

View kevinhowbrook's full-sized avatar
☯️
...probably writing a test

Kevin kevinhowbrook

☯️
...probably writing a test
View GitHub Profile
@tomdyson
tomdyson / wagtail-import-data.md
Last active May 7, 2024 12:35
Create 35k Wagtail pages of Wikipedia film plots

Create Wagtail pages programmatically

This short recipe demonstrates how to create Wagtail pages programmatically. It may also be useful for testing Wagtail development against a reasonable volume of page data (about 35,000 film plots, from English Wikipedia).

Instructions

In a virtualenv:

@kevinhowbrook
kevinhowbrook / wagtail-process-tips.md
Last active March 26, 2019 18:44
Wagtail local process tips

pipenv for function/code completion

When using vagrant, vscode won't be able to map to the vm, well not yet anyway. A way around this is to checkout a branch called pipenv, run pipenv --python 3 to create a virtual environment. Then run pipenv install -r requirements.txt to install everything in the project.

After doing this, in vscode ctrl+p then search for >python: select interpreter. Select the virtual env python, it will look something like this: /home/yourname/.local/share/virtualenvs/project-foo-JbRjzqlX/bin/python.

Just don't commit the pipenv stuff.

Flake8

Place the following in .git/hooks/pre-commit

@tomdyson
tomdyson / wagtail-on-zappa.md
Last active June 20, 2023 02:22
Wagtail on AWS Lambda, with Zappa

Wagtail on AWS Lambda, with Zappa

Install Wagtail and Zappa, and create an empty site:

pip install wagtail zappa zappa-django-utils
pip install pip==9.0.3 # see https://github.com/Miserlou/Zappa/issues/1471
wagtail start foo
@isyufu
isyufu / grep.sh
Created October 16, 2017 03:45
grep cheat sheet
#!/bin/sh
#http://www.thegeekstuff.com/2011/01/advanced-regular-expressions-in-grep-command-with-10-examples-%E2%80%93-part-ii/
# GENERAL
# print lines begining with range of letters
grep ^[A-D] table.txt
# REGEX
@frfahim
frfahim / install virtualenv ubuntu 16.04.md
Last active May 20, 2024 06:45
How to install virtual environment on ubuntu 16.04

How to install virtualenv:

Install pip first

sudo apt-get install python3-pip

Then install virtualenv using pip3

sudo pip3 install virtualenv 
sudo apt-get update
sudo apt-get install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx
sudo -u postgres psql
- paste this code in postgres console:
CREATE DATABASE django_project;
CREATE USER username WITH PASSWORD 'pass1234';
ALTER ROLE username SET client_encoding TO 'utf8';
ALTER ROLE username SET default_transaction_isolation TO 'read committed';
@marcoala
marcoala / command_name.py
Last active May 23, 2021 16:48
Base structure of a django management command, use transaction to rollback every change if an exception is raised and track time of execution.
import sys
import traceback
from django.utils import timezone
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
# django will strip new lines split helptext in 80 char lines
HELP_TEXT = """
@eyesee1
eyesee1 / wagtail_remote_image.py
Created October 17, 2016 20:23
Grabbing image data from a URL and saving into Wagtail CMS - example code
from io import BytesIO
import requests
from django.core.files.images import ImageFile
from wagtail.wagtailimages.models import Image
# event is a model object, substitute your model
# filename and title are up to you
# in my model, event.event_image is a ForeignKey to wagtailimages.Image
response = requests.get(url)
@yosemitebandit
yosemitebandit / crop_to_path.py
Created November 18, 2015 04:51
cut an image out based on a path in python with Pillow, Numpy and Shapely
"""Crop a polygonal selection from an image."""
import numpy as np
from PIL import Image
from shapely.geometry import Point
from shapely.geometry import Polygon
im = Image.open('bird.jpg').convert('RGBA')
pixels = np.array(im)
im_copy = np.array(im)
@wdullaer
wdullaer / install.sh
Last active June 29, 2024 11:54
Install Latest Docker and Docker-compose on Ubuntu
# Ask for the user password
# Script only works if sudo caches the password for a few minutes
sudo true
# Install kernel extra's to enable docker aufs support
# sudo apt-get -y install linux-image-extra-$(uname -r)
# Add Docker PPA and install latest version
# sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
# sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"