Skip to content

Instantly share code, notes, and snippets.

View tvst's full-sized avatar
🦙

Thiago Teixeira tvst

🦙
View GitHub Profile
import streamlit as st
import pandas as pd
@st.cache
def get_data():
return pd.read_csv('https://datahub.io/core/gdp/r/gdp.csv')
'# World GDP'
@tvst
tvst / gmail_inbox_bookmarklet
Last active October 11, 2019 04:41
Make Gmail more Inbox-like (RIP)
javascript:(() => {
/* Autohide header */
const header = document.querySelector('.nH.w-asV.aiw');
hide = () => {
header.style.transition = 'opacity 300ms 300ms, transform 300ms 300ms';
header.style.opacity = 0;
header.style.transform = 'translateY(-50px)';
@tvst
tvst / github_projects_bookmarklet
Created October 11, 2019 04:58
Make Github Projects a little easier to read
javascript:(() => {
const css = document.createElement('style');
css.innerText = `
/* Change background */
.js-project-header {
background: #23527b!important;
}
.project-columns {
background: #23527b!important;
@tvst
tvst / timeit.py
Last active October 11, 2019 07:21
An easy-to-use poor-man's profiler using Streamlit. See: https://discuss.streamlit.io/t/how-to-tell-which-variables-are-being-recomputed/359
import streamlit as st
import time
class TimeIt(object):
"""Simple timer for profiling Streamlit apps.
Usage
-----
# ---
# From https://gist.github.com/tvst/036da038ab3e999a64497f42de966a92
import streamlit.ReportThread as ReportThread
from streamlit.server.Server import Server
class SessionState(object):
def __init__(self, **kwargs):
"""A new SessionState object.
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
@tvst
tvst / is_running_in_streamlit.py
Created May 20, 2020 20:35
Function to detect if the current script is running inside Streamlit
import threading
def is_running_in_streamlit():
thread = threading.current_thread()
return type(thread).__module__.startswith('streamlit.')
@tvst
tvst / thread_safe_st.py
Created October 8, 2019 03:38
Hack to write to Streamlit app from another thread. See: https://discuss.streamlit.io/t/live-plot-from-a-thread/247
import streamlit.ReportThread as ReportThread
from streamlit.server.Server import Server
class ThreadSafeSt():
def __init__(self):
"""Object that write to a Streamlit app outside the main thread.
This object must be created from the main thread, and then passed
around to other threads so they can write to the Streamlit app.
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 = ""
"""Adds an st.rerun() command to Streamlit.
Usage:
import streamlit as st
import st_rerun_patch
# ...
st.rerun()