Skip to content

Instantly share code, notes, and snippets.

@jobel-code
jobel-code / load_yaml.py
Created October 19, 2020 13:31
Load yaml file from filepath
import yaml
import os
def load_yaml(filepath: str) -> dict:
"""Loads a yaml file.
Can be used as stand alone script by
:params filepath: file path to the yaml file to be loaded.
@jobel-code
jobel-code / SessionState.py
Created August 3, 2020 12:04 — forked from tvst/SessionState.py
A possible design for doing per-session persistent state in Streamlit
"""Hack to add per-session state to Streamlit.
Usage
-----
>>> import SessionState
>>>
>>> session_state = SessionState.get(user_name='', favorite_color='black')
>>> session_state.user_name
''
@jobel-code
jobel-code / interactive_google_oauth2.py
Created June 18, 2020 08:40 — forked from frankie567/interactive_google_oauth2.py
Interactive Google OAuth2 flow with Streamlit
import asyncio
import streamlit as st
from httpx_oauth.clients.google import GoogleOAuth2
st.title("Google OAuth2 flow")
"## Configuration"
client_id = st.text_input("Client ID")
import base64
import hashlib
input = "string to encode"
result = base64.b64encode(hashlib.sha1(str.encode(input)))
print(result)
# Google Cloud Storage transfer requires a base64-encoded MD5 hash of 24 characters long
hash = hashlib.md5()
hash.update('string_chunk')
@jobel-code
jobel-code / add_module_path_into_jupyter_notebook.py
Created August 16, 2019 09:03
Ensures that a modulle path, relative two levels down from the running jupyter notebook is accessible from the Jupyter Notebook. Assumes that you have a file directory that follows the [cookiecutter-data-science repo](https://drivendata.github.io/cookiecutter-data-science/#cookiecutter-data-science)
import os
import sys
# Cookicutter `data_science` Making the /src/ available as module from `/notebooks/dashboards/`
module_path = os.path.abspath(os.path.join('../..'))
print('{}'.format(module_path))
if module_path not in sys.path:
sys.path.append(module_path)
@jobel-code
jobel-code / show_project.py
Created April 3, 2019 14:53 — forked from timlinux/show_project.py
Load and show a QGIS project in python
# coding=utf-8
# A simple demonstration of how to load a QGIS project and then
# show it in a widget.
# This code is public domain, use if for any purpose you see fit.
# Tim Sutton 2015
import os
from qgis.core import QgsProject
from qgis.gui import QgsMapCanvas, QgsLayerTreeMapCanvasBridge
@jobel-code
jobel-code / TestingDashboard.ipynb
Created March 4, 2019 10:47 — forked from fperez/TestingDashboard.ipynb
Testing Dashboard to pull data from a Google form into Pandas and do simple analytics of human-driven tests
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jobel-code
jobel-code / nbmerge.py
Created March 4, 2019 10:46 — forked from fperez/nbmerge.py
Merge/concatenate multiple IPython notebooks into one.
#!/usr/bin/env python
# Note, updated version of
# https://github.com/ipython/ipython-in-depth/blob/master/tools/nbmerge.py
"""
usage:
python nbmerge.py A.ipynb B.ipynb C.ipynb > merged.ipynb
"""
import io
@jobel-code
jobel-code / NewCodeCellWidget.ipynb
Created March 4, 2019 10:44 — forked from fperez/NewCodeCellWidget.ipynb
Automatic creation of new code cells via widgets.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jobel-code
jobel-code / LogisticRegressionPart2.ipynb
Created February 25, 2019 13:24 — forked from fperez/LogisticRegressionPart2.ipynb
LogisticRegression notebook from Data100 - test for load/kernel creation time on JupyterLab. On my system (2017 13" MBP) this nb takes 14s to open and 15s *extra* to get a kernel with JLab 0.35.4, and 4s total in Classic (no extra time for kernel)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.