Skip to content

Instantly share code, notes, and snippets.

View hansthen's full-sized avatar

Hans Then hansthen

View GitHub Profile
@hansthen
hansthen / fitbounds.py
Created January 15, 2025 06:30
realtime + fitbounds
realtime = Realtime(source, on_each_feature=on_each_feature, interval=10000).add_to(m)
realtime.on(
update=folium.JsCode(
"""
(e) => {
console.log('update ', e.target._map);
var map = e.target._map;
var realtime = e.target;
map.fitBounds(realtime.getBounds(), {maxZoom: 3});
}
@hansthen
hansthen / draw.py
Last active November 13, 2024 21:36
s2 draw support
import streamlit as st
from folium import JsCode
import streamlit_folium
import json
st.set_page_config(
page_title="streamlit-folium documentation: Draw Support",
page_icon=":pencil:",
layout="wide",
)
https://docs.google.com/document/d/e/2PACX-1vSx0Ecngn28f8x2mzn55oZmlITHIcXvsce0xLYnpUmqQJgALVE7GM260Jq9iuEGC1pwG6z-3AtNXUus/pub
import streamlit as st
>>from st_aggrid import AgGrid, JsCode, GridOptionsBuilder
>>import pandas as pd
>>df = pd.read_csv('https://raw.githubusercontent.com/fivethirtyeight/data/master/airline-safety/airline-safety.csv')
gb = GridOptionsBuilder.from_dataframe(df)
gb.configure_selection('single', pre_selected_rows=[], use_checkbox=False)
gridOptions = gb.build()
gridOptions['rowClassRules'] = {
import streamlit as st
import streamlit.components.v1 as components
from streamlit_extras.row import row
from streamlit_extras.stylable_container import stylable_container
with st.sidebar:
st.markdown("""
<style>
:root {
--header-height: 50px;
@hansthen
hansthen / gtfs.py
Last active February 10, 2024 19:09
GTFS realtime
import gtfs_realtime_OVapi_pb2 as ovapi
import requests
import urllib.request
from datetime import datetime
import time
from google.protobuf.json_format import MessageToJson, MessageToDict
from IPython import embed
@hansthen
hansthen / dimension2timeline
Created January 22, 2024 20:02
jq for converting timedimension format to timeline format
cat track_bus699.geojson | jq '[([.geometry.coordinates, .properties.times] | transpose | .[] | {"coordinates": .[0], "start": .[1]}) as $features | del(.geometry.coordinates, .properties.times) | .geometry += {"coordinates": $features.coordinates} | .properties += {"start": $features.start, "end": ($features.start | (gsub("\\s"; "T") + "Z") as $date | $date | fromdate | . + 2)}]
@hansthen
hansthen / css.py
Last active December 17, 2023 20:02
Streamlit css
with st.sidebar:
st.markdown("""
<style>
:root {
--header-height: 50px;
}
[data-testid="stHeader"] {
background-image: url(/app/static/icons8-astrolabe-64.png);
background-repeat: no-repeat;
background-size: contain;
@hansthen
hansthen / app.py
Created December 5, 2023 03:49
Customize styling for Aggrid
import streamlit as st
from st_aggrid import AgGrid
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/fivethirtyeight/data/master/airline-safety/airline-safety.csv')
custom_css = {
".ag-row-even": {"background-color": "rgba(0,0,0,0.2) !important"},
".ag-header-cell": {"background-color": "orange !important"},
".ag-theme-streamlit": {"--ag-borders": "none",
@hansthen
hansthen / flow.py
Created December 3, 2023 17:41
Page flow
import streamlit as st
class App():
def __init__(self, default=None):
self.page = default
self.args = []
self.kwargs = {}
def goto(self, page, *args, **kwargs):
self.page = page