Skip to content

Instantly share code, notes, and snippets.

@pszaflarski
pszaflarski / quick_docker_postgres.sh
Last active June 2, 2020 20:59
spin up postgres on linux/mac without having to download it
docker pull postgres
mkdir -p $HOME/docker/volumes/postgres_dh
docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5433:5432 -v $HOME/docker/volumes/postgres_dh:/var/lib/postgresql/data postgres
@pszaflarski
pszaflarski / _remap_dict.py
Created July 9, 2018 17:49
remap a python dictionary with new keys
def _remap_dict(d, fromto_mapping, method='delete'):
"""
Remap dictionary keys from a certain set of keys to a new set of keys
:param d: the dictionary that needs to be remapped
:param fromto_mapping: a dictionary mapping of keys in the original dictionary to the output dictionary
:param method: what do do with keys that aren't found in the mapping
'delete' means that they will be removed from the output dictionary
'remain' means that they will have their original names in the output dictionary
:return: the output dictionary with keys remapped, will return None if method is not recognized
"""
@pszaflarski
pszaflarski / dict_to_bash_json.py
Created October 24, 2017 15:50
convert a python dictionary to a bash/cmd compatible json for setting complicated environment variables
import json
def to_bash_json(d):
return json.dumps({'i': json.dumps(d)})[6:-1]
if __name__ == '__main__':
S3_CREDS = {
"aws_access_key_id": "AKA",
"aws_secret_access_key": "CWW"