Skip to content

Instantly share code, notes, and snippets.

>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
@gonzalodiaz
gonzalodiaz / new_environment.yml
Created June 7, 2020 16:24
NewEnvironment.yml
name: tutorial-python-quality-code-env
channels:
- defaults
- conda-forge
dependencies:
- python=3.8.3
- pre-commit=2.4.0
@gonzalodiaz
gonzalodiaz / pre-commit.yml
Created June 6, 2020 09:29
PreCommitYaml
name: pre-commit
on:
pull_request:
push:
branches: [master]
jobs:
pre-commit:
runs-on: ubuntu-latest
@gonzalodiaz
gonzalodiaz / pre-commit-config-final.yaml
Created June 6, 2020 09:25
PreCommitConfigFinalYaml
repos:
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.8
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.2
hooks:
- id: flake8
@gonzalodiaz
gonzalodiaz / pre-commit-config-default.yaml
Created June 6, 2020 09:25
PreCommitConfigDefaultYaml
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
#!/bin/bash -e
ROOT_DIR="$(git rev-parse --show-toplevel)"
echo "Running Linters..."
"${ROOT_DIR}"/scripts/linters.sh
#! /bin/bash -e
# workaround to have conda working
eval "$(conda shell.bash hook)"
environment_header=$(head -n 1 environment.yml)
environment_name=${environment_header/name: /}
conda activate "${environment_name}"
#! /bin/bash -e
environment_header=$(head -n 1 environment.yml)
environment_name=${environment_header/name: /}
conda remove --yes --quiet -n "${environment_name}" --all
conda env create --quiet --force -f environment.yml
@gonzalodiaz
gonzalodiaz / environment.yml
Created June 6, 2020 09:20
EnvironmentYml
name: tutorial-python-quality-code-env
channels:
- defaults
- conda-forge
dependencies:
- python=3.8.3
- flake8=3.8.2
- pydocstyle=4.0.1
- mypy=0.770
- black=19.10b
@gonzalodiaz
gonzalodiaz / population_fix.py
Last active June 6, 2020 09:19
PopulationFix
def population(self, year: int) -> int:
"""Obtain the population in the world for a given year.
:param year: Year of which the population wants to be known.
:returns: Population for that year. 0 if the year was not found.
"""
return self.yearly_population.get(year, 0)
def population_on_2020(self) -> int: