Skip to content

Instantly share code, notes, and snippets.

View abrookins's full-sized avatar

Andrew Brookins abrookins

View GitHub Profile
In [10]: stats2 = SiteStatsSchema().load(data)
In [11]: stats == stats2
Out[11]: True
In [8]: data = SiteStatsSchema().dump(stats)
In [9]: data
Out[9]:
{'meter_reading_count': 5,
'min_wh_generated': 1.0,
'last_reporting_time': '2020-07-31T15:08:45.109063',
'max_wh_generated': 22.0,
'max_capacity': 100.0}
In [3]: import datetime
In [4]: now = datetime.datetime.now()
In [5]: stats = SiteStats(last_reporting_time=now, meter_reading_count=5, max_wh_generated=22, min_wh_generated=1, max_capacity=100)
In [6]: stats
Out[6]: SiteStats(last_reporting_time=datetime.datetime(2020, 7, 31, 15, 8, 45, 109063), meter_reading_count=5, max_wh_generated=22, min_wh_generated=1, max_capacity=100)
@dataclass(frozen=True, eq=True)
class SiteStats:
"""Reporting stats for a site."""
last_reporting_time: datetime.datetime
meter_reading_count: int
max_wh_generated: float
min_wh_generated: float
max_capacity: float
from peewee import *
import datetime
db = SqliteDatabase('my_database.db')
class User(Model):
username = CharField(unique=True)
@abrookins
abrookins / andrew.md
Last active July 15, 2020 03:11 — forked from gamesbrainiac/andrew.md
Andrew B Webinar Info

Date/Time

6th August 2020 - 7 PM CEST

Title

Database Performance Tips with Django

Description

Keybase proof

I hereby claim:

  • I am abrookins on github.
  • I am redis_andrew (https://keybase.io/redis_andrew) on keybase.
  • I have a public key ASC0tvyGuXJgPXJVzqX59sFJTHHXTMmgRVxkB3OaF7X_cwo

To claim this, I am signing this object:

@abrookins
abrookins / join_promotion
Created July 17, 2019 05:14 — forked from akaariai/join_promotion
Django join promotion
=========================
Join promotion in the ORM
=========================
[NOTE: We need better terms than promote and demote for changing the join
type. These terms are extremely easy to mix up. Maybe the ORM methods could
be to_inner_joins and to_louter_joins instead of promote_joins and demote_joins?
I tried to clean up the mis-usages of promotion/demotion but there could still
be some cases where these are mixed up]
set smoothscroll
let blacklists = ["https://mail.google.com/*", "*://mail.google.com/*", "@https://mail.google.com/mail/*"]
@abrookins
abrookins / sVimrc
Last active September 5, 2017 16:12
let mapleader = ","
let newtaburl = "https://google.com"
let blacklists = ["*://safari.atlassian.net/*", "*://mail.google.com/*", "*://inbox.google.com/*", "*://calendar.google.com/*", "*://*.slack.com/*"]
let scrollstep = 20
map "<Leader> m" zoomPageIn