Skip to content

Instantly share code, notes, and snippets.

import time
import pytest
@pytest.hookimpl(hookwrapper=True)
def pytest_fixture_setup(fixturedef, request):
start = time.time()
yield
total = time.time() - start

Refactoring

These are abbreviated notes taken from Martin Fowler's Refactoring.

Replace Inline Code with Function Call

(This is an atomic refactoring.)

Rename Variable

(This is an atomic refactoring.)

Separate Query from Modifier

  1. Copy the function and rename as query
  2. Remove side effects from query
  3. Replace each call using return value with call to query plus call to modifier
@cjolowicz
cjolowicz / .pre-commit-config.yaml
Created April 15, 2020 15:02
pre-commit cannot install Prettier environment
repos:
- repo: https://github.com/prettier/prettier
rev: 2.0.4
hooks:
- id: prettier
FROM python:3.9.0a4
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
ENV PATH /root/.poetry/bin:$PATH
ENTRYPOINT ["poetry"]
@cjolowicz
cjolowicz / Dockerfile
Last active March 30, 2024 05:25
Multi-stage Docker build with Poetry and venv
FROM python:3.7.6-alpine3.11 as base
ENV PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1
WORKDIR /app
FROM base as builder
FROM python:3.8.1
RUN pip install virtualenv==20.0.2
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
ENV PATH "/root/.poetry/bin:$PATH"
RUN virtualenv /venv
ENV VIRTUAL_ENV /venv
ENV PATH "/venv/bin:$PATH"
RUN poetry new foobar
WORKDIR foobar
CMD ["poetry", "install", "-vvv"]
@cjolowicz
cjolowicz / installing-with-homebrew.sh
Last active December 29, 2015 22:49
Installing gtk2hs on Mac OS X 10.9
# Install XQuartz
wget http://xquartz.macosforge.org/downloads/SL/XQuartz-2.7.5.dmg
mkdir /Volumes/XQuartz-2.7.5
hdiutil attach -mountpoint /Volumes/XQuartz-2.7.5 XQuartz-2.7.5.dmg
sudo installer -pkg /Volumes/XQuartz-2.7.5/*.pkg -target /
hdiutil detach -mountpoint /Volumes/XQuartz-2.7.5 XQuartz-2.7.5.dmg
rmdir /Volumes/XQuartz-2.7.5
rm XQuartz-2.7.5.dmg
# Install GTK.