Skip to content

Instantly share code, notes, and snippets.

View prasanthnarasimha's full-sized avatar

Narasimha Prasanth Chintarlapalli Reddy prasanthnarasimha

View GitHub Profile
@benkehoe
benkehoe / timedelta_iso.py
Last active December 22, 2022 17:54
IS8601 functions for datetime.timedelta
# MIT No Attribution
#
# Copyright 2022 Ben Kehoe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
@khornberg
khornberg / encode_decode_dictionary.py
Created August 25, 2017 12:39
python 3 base64 encode dict
"""
Given a dictionary, transform it to a string. Then byte encode that string. Then base64 encode it and since this will go
on a url, use the urlsafe version. Then decode the byte string so that it can be else where.
"""
data = base64.urlsafe_b64encode(json.dumps({'a': 123}).encode()).decode()
# And the decode is just as simple...
data = json.loads(base64.urlsafe_b64decode(query_param.encode()).decode())
# Byte encode the string, base64 decode that, then byte decode, finally transform it to a dictionary