Skip to content

Instantly share code, notes, and snippets.

View D2theR's full-sized avatar

Dan Rerko D2theR

View GitHub Profile
@rockavoldy
rockavoldy / 0-odoo-cheatsheet.md
Last active April 29, 2024 10:04
Odoo Cheatsheet
@jackton1
jackton1 / drf_optimize.py
Last active October 6, 2023 22:37
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`.
# example reading two serial devices using pyserial, asyncio and coroutines
import serial_asyncio
import asyncio
@asyncio.coroutine
def serial_read(device, **kwargs):
reader, writer = yield from serial_asyncio.open_serial_connection(url=device, **kwargs)
while True:
line = yield from reader.readline()
@kirkbushell
kirkbushell / Interceptor.js
Created January 7, 2016 22:41
Handling JWT, Vue JS and token refreshes
import Unauthorised from './Unauthorised'
export default function() {
return {
response: function(response) {
switch (response.status) {
case 401: return Unauthorised.handle();
}
return response;