Skip to content

Instantly share code, notes, and snippets.

View kevinhowbrook's full-sized avatar
☯️

Kevin kevinhowbrook

☯️
  • localhost
  • 03:38 (UTC +01:00)
View GitHub Profile
@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 = """
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';
@rezafarhadur
rezafarhadur / install virtualenv ubuntu 16.04.md
Last active July 17, 2025 07:53
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 
@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
@tomdyson
tomdyson / wagtail-on-zappa.md
Last active February 18, 2025 15:12
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
@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-import-data.md
Last active April 18, 2026 20:49
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: