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
  • localhost
  • 01:45 (UTC +01:00)
View GitHub Profile
@kevinhowbrook
kevinhowbrook / deploy.yaml
Last active April 11, 2021 16:57
git hub action to deploy yaml site
name: Deploy to heroku
on:
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
@kevinhowbrook
kevinhowbrook / speedy.md
Created July 9, 2020 14:39
Speed up django tests

add the following to test settings

# By default, Django uses a computationally difficult algorithm for passwords hashing.
# We don't need such a strong algorithm in tests, so use MD5
PASSWORD_HASHERS = [
    "django.contrib.auth.hashers.MD5PasswordHasher",
]
@kevinhowbrook
kevinhowbrook / make_pages.py
Created June 25, 2020 21:35
wagtail management command for pages with images
from django.core.management.base import BaseCommand
from wagtail.core.models import Page
from django.core.files.images import ImageFile
from projects.models import ProjectPage
from home.models import HomePage
from images.models import CustomImage
from io import BytesIO
import requests
from django.core.files.images import ImageFile
@kevinhowbrook
kevinhowbrook / mock.md
Last active March 21, 2020 20:15
Python Django mock request eg

How to test a class method using mock:

You can patch the entire requests module with:

@mock.patch('requests.get')

But it's better to keep it specific as per:

@mock.patch('rca.shortcourses.access_planit.requests.get')
@kevinhowbrook
kevinhowbrook / pltips.md
Last active September 30, 2019 11:10
Helpful pattern lab tips

Some various tips on writing yaml for template tags.

Looping over a template tag

HTML

{% social_media_links as social_links %}
<ul class="footer__social-links">
    {% for link in social_links %}
from django.db import models
from wagtail.core.models import Page
from wagtail.admin.edit_handlers import FieldPanel
class HomePage(Page):
publication_date = models.DateTimeField(null=True, blank=True)
updated_date = models.DateTimeField("Modified date", blank=True, null=True)
@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

j = 0 # vertical counter
k = 0 # horizontal counter
for i,v in enumerate(convert()):
if i % squares_per_row == 0 and i != 0: # if i is a multiple of squares per row
j += 1 # increments after the squares per row is hit like 0,0,0,1,1,1,2,2,2...
if i % squares_per_row == 0 and i != 0:
k = 0 # increments after the squares per row is hit like 0,1,2,0,1,2...
points = ((k*s,j*s), (k*s, j*s+s),(k*s+s,j*s+s),(k*s+s, j*s)) #set points with incrementing values :/
draw.polygon((points[0], points[1], points[2], points[3]), outline='black', fill = (v[0],v[1],v[2])) # outline='red', fill='blue'
#borders so redraw the same plots with white lines
@kevinhowbrook
kevinhowbrook / gridcalc.py
Last active June 2, 2018 14:01
#onmedium
def calculate_m():
# get a list of possible squared numbers, this give us the number of
# rows and columns to use for the canvas, eg 4 = 2 x 2, 6 = 3 x 3...
# Return: [] of squared numbers up to 10000 (hopefully we don't get that high!)
m = []
for i in range(1,10000):
m.append(i*i)
return(m)
def grid(n,m):