Skip to content

Instantly share code, notes, and snippets.

View dz0's full-sized avatar

Jurgis Pralgauskis dz0

  • 11:13 (UTC +02:00)
View GitHub Profile
@dz0
dz0 / DRF Serializer validation stack.md
Last active March 14, 2019 11:03
DRF Serializer validation stack.md

Serializer:

  • is_valid(self, raise_exception=False) # usually called before self.save(..)
    • run_validation(self, data=empty)
      • validate_empty_values(self, data)
      • to_internal_value(self, data)
        • each DRF Field:
          • run_validation(self, data=empty)
            • validate_empty_values(self, data)
            • to_internal_value(self, data)
  • run_validators(self, value)
@dybber
dybber / parse-datetime-micropython.py
Created August 24, 2018 07:07
parse-datetime-micropython.py
import ure
def parseDateTime(datestr):
regex = ("^(19|2[0-9][0-9][0-9])-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
"T(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(.([0-9]*))?"
"((\\+|-)[0-1][0-9]:[0-9][0-9])?$")
match = ure.match(regex, datestr)
if match:
year = int(match.group(1))
month = int(match.group(2))
@jackton1
jackton1 / drf_optimize.py
Last active August 20, 2025 18:03
Optimize Django Rest Framework model views queries.
from django.db import ProgrammingError, models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.query import normalize_prefetch_lookups
from rest_framework import serializers
from rest_framework.utils import model_meta
class OptimizeModelViewSetMetaclass(type):
"""
This metaclass optimizes the REST API view queryset using `prefetch_related` and `select_related`
if the `serializer_class` is an instance of `serializers.ModelSerializer`.
@wojteklu
wojteklu / clean_code.md
Last active December 12, 2025 01:36
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@erikroyall
erikroyall / textbooks.md
Last active September 8, 2025 14:56
Alex Stef's list of freely-available mathematics textbooks

Textbooks in Mathematics

A list of links to useful mathematical textbooks available for free on the Internet. They are all legal and maintained by their authors or by the legitimate publisher.

All the documents are in English. They are in a printable format - Postscript or Adobe Portable Document Format. You are free to download, read and print them. Here are some links to other sites offering lists of free mathematical textbooks.

For any comments, please, contact me: [email protected]

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active December 5, 2025 09:56
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@OnesimusUnbound
OnesimusUnbound / quote.txt
Last active September 3, 2024 12:53
Programming Quotes
[T]he difference between a bad programmer and a
good one is whether he considers his code or his
data structures more important. Bad programmers
worry about the code. Good programmers worry about
data structures and their relationships.
-- Linus Torvalds
~~~
Clarity and brevity sometimes are at odds.
When they are, I choose clarity.
-- Jacob Kaplan-Moss