Skip to content

Instantly share code, notes, and snippets.


Jonathan Sharpe textbook

View GitHub Profile
textbook /
Last active Apr 18, 2021
Proposed PR template for CYF tech project repos

This is a:

  • New feature - new behaviour has been implemented
  • 🐛 Bug fix - existing behaviour has been made to behave
  • ♻️ Refactor - the behaviour has not changed, just the implementation
  • Test backfill - tests for existing behaviour were added but the behaviour itself hasn't changed
  • ⚙️ Chore - maintenance task, behaviour and implementation haven't changed
textbook /
Last active May 26, 2021
Adding Cypress to a Create React App app

Here is how to add Cypress E2E tests to a Create React App bootstrapped application. Assumes the *nix command line, you may need to adapt this for a Windows command line (or use WSL or Git Bash).

  1. Install Cypress and the Testing Library utilities for it (to match the helpers CRA installs):

    $ npm i {,@testing-library/}cypress

    i is short for install, and the braces {} are expanded by brace expansion to cypress @testing-library/cypress.

textbook /
Last active Aug 23, 2020
Pipes in tables


| Escaped |
| \| |
textbook /
Last active Aug 13, 2020
Let's be evil coders!
👩‍💻 Tester 👹 Evil Coder 👨‍🏫 Invigilator
Write a failing test Don’t read the exercise! No talking
Keep it simple Make the test pass Don't take large steps
Try to drive the code writer to the expected solution Try to do it in a surprising way Don't ignore bad test feedback
No more than 3 || or &&
  • Exercise: [Password Validator][1]
  • Single file test framework: [Proctor][2]
textbook / index.html
Last active Jun 23, 2020
Rewriting Proofpoint/Safelinks URLs so you can see where they actually go...
View index.html
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<title>URL Extractor</title>
<link rel="stylesheet" href="">
View demo.service.spec.ts
import { TestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { DemoService } from './demo.service';
fdescribe('DemoService', () => {
let service: DemoService;
let httpMock: HttpTestingController;
beforeEach(() => {
textbook /
Created Apr 29, 2020
Simple Python password creator
from itertools import cycle
from random import choice, shuffle
from string import ascii_lowercase, ascii_uppercase, digits, punctuation
def generate_password(length: int = 20, *, use_symbols: bool = True) -> str:
"""Generate random passwords, with or without symbols.
Implementation ensures a fairly even balance of each character
class, at the cost of entropy (e.g. for a four-character password
with symbols there are only 5,191,680 possible combinations, rather
textbook /
Created Oct 2, 2019
How to create a pandas Series of ONS CPIH data