Skip to content

Instantly share code, notes, and snippets.

View bot-unit's full-sized avatar
🐾
У меня лапки

Unit bot-unit

🐾
У меня лапки
  • Spain
View GitHub Profile
@tvst
tvst / SessionState.py
Last active April 14, 2024 20:24
DO NOT USE!!! Try st.session_state instead.
"""Hack to add per-session state to Streamlit.
Usage
-----
>>> import SessionState
>>>
>>> session_state = SessionState.get(user_name='', favorite_color='black')
>>> session_state.user_name
''
@treuille
treuille / confirm_button_hack.py
Last active August 25, 2023 14:38
Hack to implement a confirm_button in Streamlit v0.35
"""
THIS HAS BEEN DEPRECATED!
We propose you use st.form() instead:
https://blog.streamlit.io/introducing-submit-button-and-forms/
"""
import streamlit as st
import collections
@felangel
felangel / main.dart
Last active June 29, 2024 04:27
showDialog sample
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:bloc/bloc.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@phizaz
phizaz / talk.md
Created June 20, 2017 04:03
BKKMLMEETUP: Q-Learning for Trading

Q-Learning for algorithm trading

Q-Learning background

by Konpat

Q-Learninng is a reinforcement learning algorithm, Q-Learning does not require the model and the full understanding of the nature of its environment, in which it will learn by trail and errors, after which it will be better over time. And thus proved to be asymtotically optimal.

  • you need first to understand the Markov Decision Process, which is a graph consisting of (states, actions, rewards) denoting {S}, {A}, {R}
  • State (S)
@phizaz
phizaz / async.py
Last active April 3, 2024 15:44
Python turn sync functions to async (and async to sync)
import functools
def force_async(fn):
'''
turns a sync function to async function using threads
'''
from concurrent.futures import ThreadPoolExecutor
import asyncio
pool = ThreadPoolExecutor()
@phizaz
phizaz / cacher.py
Last active June 7, 2018 16:55
A simple memory (with storage) python cache system with live cache update.
from database import pickledb
from os.path import exists, join, dirname
from os import makedirs
from null import Null
import uuid
class CacheObject:
def __init__(self, cacher, key, val):
assert isinstance(cacher, Cacher)
@internaut
internaut / pandas_crossjoin_example.py
Last active June 12, 2020 14:30
Shows how to do a cross join (i.e. cartesian product) between two pandas DataFrames using an example on calculating the distances between origin and destination cities. See https://mkonrad.net/2016/04/16/cross-join--cartesian-product-between-pandas-dataframes.html
"""
Shows how to do a cross join (i.e. cartesian product) between two pandas DataFrames using an example on
calculating the distances between origin and destination cities.
Tested with pandas 0.17.1 and 0.18 on Python 3.4 and Python 3.5
Best run this with Spyder (see https://github.com/spyder-ide/spyder)
Author: Markus Konrad <post@mkonrad.net>
April 2016
@opie4624
opie4624 / commandline.py
Last active May 24, 2024 04:36
Base Python Command Line template
#!/usr/bin/env python
#
# import modules used here -- sys is a very standard one
import sys, argparse, logging
# Gather our code in a main() function
def main(args, loglevel):
logging.basicConfig(format="%(levelname)s: %(message)s", level=loglevel)