Skip to content

Instantly share code, notes, and snippets.

@geo909
geo909 / pre-commit
Created April 18, 2022 09:42
Pre-commit hook for clearing the output of jupyter notebooks
#!/bin/bash
# .git/hookds/pre-commit
# This pre-commit hook clears output cells in Jupyter notebooks
# setting bash strict mode
set -o errexit
set -o pipefail
set -o nounset
IFS=$'\n\t'
@geo909
geo909 / dict_remove_empty.py
Last active February 5, 2021 11:07
Efficiently remove empty values from nested structure
"""
Remove fields with empty strings recursively from
nested structure using boltons.iterutils.remap.
This comes in handy, for example, when bulk-indexing
to elasticsearch.
References:
* https://boltons.readthedocs.io/en/latest/iterutils.html#nested
* https://sedimental.org/remap.html#drop-empty-values
"""
@geo909
geo909 / pydantic_dynamic_hash_field.py
Created January 13, 2021 22:08
[pydantic] Dynamically create a hash field from other string fields
import hashlib
from pydantic import BaseModel, validator
from typing import Optional
class Person(BaseModel):
first: str
last: str
hash: Optional[str]