Skip to content

Instantly share code, notes, and snippets.

Avatar
😃

Thiago Teixeira tvst

😃
View GitHub Profile
@tvst
tvst / downloader.py
Created Jun 20, 2020
A simple file downloader for Python
View downloader.py
import os
import requests
def download_file(url, folder, filename):
"""Downloads a file from the internet, but only if it doesn't already exist on disk.
Parameters
----------
url : str
View Example plots with Streamlit
import streamlit as st
import pandas as pd
from vega_datasets import data
"""
# Using different charting libraries
"""
@st.cache
View submit_button_example.py
import streamlit as st
# Grab SessionState.py from here:
# https://gist.github.com/tvst/036da038ab3e999a64497f42de966a92
# (This is a temporary solution until we provide an official API for this)
import SessionState
DEFAULT_FOO = ""
DEFAULT_BAR = ""
@tvst
tvst / is_running_in_streamlit.py
Created May 20, 2020
Function to detect if the current script is running inside Streamlit
View is_running_in_streamlit.py
import threading
def is_running_in_streamlit():
thread = threading.current_thread()
return type(thread).__module__.startswith('streamlit.')
View st_rerun_patch.py
"""Adds an st.rerun() command to Streamlit.
Usage:
import streamlit as st
import st_rerun_patch
# ...
st.rerun()
@tvst
tvst / st_state_patch.py
Last active Nov 1, 2020
Another possible design for doing per-session persistent state in Streamlit.
View st_state_patch.py
"""Another prototype of the State implementation.
Usage
-----
How to import this:
import streamlit as st
import st_state_patch
View ScreenCastRecorder.js
const MEDIA_TYPE = "video/webm;codecs=vp9,opus"
//const MEDIA_TYPE = "video/webm;codecs=h264"
const BLOB_TYPE = "video/webm"
class ScreenCastRecorder {
constructor({ recordAudio }) {
this.recordAudio = recordAudio
this.inputStream = null
View st_rerun.py
from streamlit.ScriptRequestQueue import RerunData
from streamlit.ScriptRunner import RerunException
from streamlit.server.Server import Server
import streamlit.ReportThread as ReportThread
def rerun():
"""Rerun a Streamlit app from the top!"""
widget_states = _get_widget_states()
raise RerunException(RerunData(widget_states))
View timeit.py
import streamlit as st
import time
class TimeIt(object):
"""Simple timer for profiling Streamlit apps.
Usage
-----
@tvst
tvst / github_projects_bookmarklet
Created Oct 11, 2019
Make Github Projects a little easier to read
View github_projects_bookmarklet
javascript:(() => {
const css = document.createElement('style');
css.innerText = `
/* Change background */
.js-project-header {
background: #23527b!important;
}
.project-columns {
background: #23527b!important;
You can’t perform that action at this time.