Skip to content

Instantly share code, notes, and snippets.

View hest's full-sized avatar

Dongmin Jang hest

View GitHub Profile
@hest
hest / umqtt_sub.py
Created January 8, 2022 09:35
MicroPython MQTT subscribe
try:
from umqtt.robust import MQTTClient
except ImportError:
import upip
upip.install(['umqtt.robust', 'umqtt.simple'])
from umqtt.robust import MQTTClient
SERVER = '127.0.0.1'
USER = 'mqtt-test'
@hest
hest / flask_arrow.py
Last active January 4, 2022 01:39
SQLAlchemy-Utils ArrowType with Flask-Babel Timezone
from flask import Flask, g
from flask_babel import Babel
"""
Use At Your Own Risk
"""
app = Flask(__name__)
# app.config.from_object(config)
babel = Babel(app)

Keybase proof

I hereby claim:

  • I am hest on github.
  • I am hest (https://keybase.io/hest) on keybase.
  • I have a public key ASAZ_nZh69YK6afHocv1aIFAmtg5UKMGjzMLK4thpiPlXgo

To claim this, I am signing this object:

@hest
hest / gist:8798884
Created February 4, 2014 06:08
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()