Skip to content

Instantly share code, notes, and snippets.

View vsego's full-sized avatar

Vedran Šego vsego

View GitHub Profile
@vsego
vsego / last-session-aware-class.py
Created April 3, 2019 11:27
Last-session aware class
"""
A proof of concept: ability to have `X.f(...) == X.sess.f(...)`, but also be
able to use `x = X(); y = X(); x.f(...)` in the expected way.
"""
import inspect
class _X:
"""
@vsego
vsego / howto.md
Last active February 11, 2019 13:21
Google Groups horizontal scrollbar

Posts in Google Groops lack horizontal scrollbar, which can be a pain (I use private groups for various notification emails that need to be read and managed in one spot by different people). In Chrome, this can be fixed in two simple steps:

  1. Install Stylebot extension.
  2. Reload the page if it's already loaded, then right-click it, pick "Stylebot" > "Style Element", then click "Edit CSS" button at the bottom of the sidebar, and set this for groups.google.com:
#tm-tl > div > div > div > div > div > div:nth-child(4) > div > div {
    width: fit-content;
}
@vsego
vsego / lock_mode.py
Created August 9, 2018 13:41
A context manager for easily locking model instances
@contextmanager
def lock_model(model_class, **kwargs):
with transaction.atomic():
yield model_class.objects.select_for_update().get(**kwargs)
# Usage
with lock_model(ModelClass, pk=some_pk) as instance:
do something with instance