Skip to content

Instantly share code, notes, and snippets.

View textbook's full-sized avatar

Jonathan Sharpe textbook

View GitHub Profile
@textbook
textbook / cypress-cra.md
Last active September 28, 2023 20:16
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.

import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { useState } from "react";
const App = () => {
const [count, setCount] = useState(0);
return (
<div>
<div>{count}</div>
<button onClick={() => setCount((c) => c + 1)}>Click me!</button>

Hi here is some text this is red.

@textbook
textbook / SDLT.md
Last active August 8, 2022 08:54
SDLT UK

Stamp Duty Land Tax

A TDD journey through a changing tax.

Step 1

In 2003, Stamp Duty Land Tax (SDLT) was introduced.

House price Rate (%)
const express = require("express");
const request = require("supertest");
const StatusCodes = { CREATED: 201 };
const fakeUserData = {};
const app = express();
it("returns a 201 on successful signup", (done) => {
request(app)
FOO=123
BAR=hello, world!
@textbook
textbook / PULL_REQUEST_TEMPLATE.md
Last active January 7, 2022 11:47
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
textbook / ProblemSet4.py
Created October 23, 2012 22:08
MIT 6.00x - PSet 4 answers by jonrsharpe
# 1. Word Scores
def getWordScore(word, n):
return (len(word) * sum(SCRABBLE_LETTER_VALUES[x] for x in word)) + (50 if len(word) == n else 0)
# Test implementation
def getFrequencyDict(aStr):
return dict((letter, aStr.count(letter)) for letter in aStr)
# 2. Dealing with hands
def updateHand(hand, word):
@textbook
textbook / imdb_venn.py
Last active February 19, 2021 23:41
Want to identify an actor from multiple movies they've been in? I've got your back.
"""Find the overlap of actors between multiple movies."""
from __future__ import print_function
import argparse
from operator import itemgetter
from sys import argv, exit
try:
from imdb import IMDb
@textbook
textbook / docker.sh
Last active October 27, 2020 21:10
Easy commands to clean up Docker containers and images
docker rm $(docker ps --all --quiet --filter status=exited)
docker rmi $(docker images --quiet --filter dangling=true)