how to use?
# inside your test
detector = LazySQLDetector()
with detector.track(), no_dirty_allowed():
your_heavy_read_only_api()
import enum | |
from datetime import datetime | |
from sqlalchemy import Column | |
from sqlalchemy import DateTime | |
from sqlalchemy import Enum | |
from sqlalchemy import event | |
from sqlalchemy import func | |
from sqlalchemy import select | |
from sqlalchemy import String |
from sqlalchemy import select, text | |
def reset_sequences(engine, schema="public", gap=10000): | |
""" | |
Reset all sequences in a given schema to 10000, 20000, etc. so that ids won't overlap easily. | |
Ensures we don't get "lucky" and crossing ids between tables works because they are both id=1, | |
passing a test that should fail. | |
""" | |
with engine.connect() as conn: |
function deflate(obj) { | |
function _deflate(obj, _sofar = new Map(), _cur_ref = [0]) { | |
if (obj === null || typeof obj !== 'object') { | |
return obj; | |
} | |
if (Array.isArray(obj)) { | |
return obj.map(v => _deflate(v, _sofar, _cur_ref)); | |
} |
# I was looking for a rate limiting library to call rate limited apis as closely | |
# as possible to their enforced limits. I looked at the first few python libraries | |
# that I found, and when I glanced at the source, they were all clearly broken. | |
# Curious how this could be, I took all the top google and pip search results for: python rate limiting | |
# and tried to get them to do the wrong thing and fail to rate limit in situations that could come up | |
# in normal use (though in some cases very specific use) | |
# https://github.com/tomasbasham/ratelimit | |
# Where broken: |
I heard some points of criticism to how React deals with reactivity and it's focus on "purity". It's interesting because there are really two approaches evolving. There's a mutable + change tracking approach and there's an immutability + referential equality testing approach. It's difficult to mix and match them when you build new features on top. So that's why React has been pushing a bit harder on immutability lately to be able to build on top of it. Both have various tradeoffs but others are doing good research in other areas, so we've decided to focus on this direction and see where it leads us.
I did want to address a few points that I didn't see get enough consideration around the tradeoffs. So here's a small brain dump.
"Compiled output results in smaller apps" - E.g. Svelte apps start smaller but the compiler output is 3-4x larger per component than the equivalent VDOM approach. This is mostly due to the code that is usually shared in the VDOM "VM" needs to be inlined into each component. The tr
""" "Writing SQL is just as fast as using an ORM" proof of concept | |
Below is a simple Python object model, where we represent a database that | |
stores the names of employees at a company, some of whom are "engineers", | |
and a list of the jobs they do and the programming languages they use. | |
We'd like to persist the state represented by this Python object model | |
in a relational database, using our Python objects as a start. Then we'd | |
like to write SQL queries for rows in this database, and we get back instances | |
of Python objects exactly as they were created. |
# note: we are using SQLAlchemy that includes _cache_key | |
# currently at: | |
# https://gerrit.sqlalchemy.org/#/c/sqlalchemy/sqlalchemy/+/1204/5/ | |
import typing | |
from sqlalchemy import bindparam | |
from sqlalchemy import Column | |
from sqlalchemy import func | |
from sqlalchemy import inspection |
# Uses the Python Imaging Library | |
# `pip install Pillow` works too | |
from PIL import Image | |
image_filename = "picture_with_EXIF.jpg" | |
image_file = open('image_filename) | |
image = Image.open(image_file) | |
# next 3 lines strip exif | |
image_data = list(image.getdata()) |