Skip to content

Instantly share code, notes, and snippets.

View jessielw's full-sized avatar
🖥️
Coding

Jessie Wilson jessielw

🖥️
Coding
View GitHub Profile
@jessielw
jessielw / gist:c26957eb30f0dc8c9c401b7b3e1ae200
Created January 19, 2026 00:08 — forked from hest/gist:8798884
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()
@jessielw
jessielw / progress.py
Created December 2, 2024 17:14 — forked from vladignatyev/progress.py
Python command line progress bar in less than 10 lines of code.
# The MIT License (MIT)
# Copyright (c) 2016 Vladimir Ignatev
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#