Skip to content

Instantly share code, notes, and snippets.

View Tobi-De's full-sized avatar
👁️‍🗨️
Trade-offs everywhere!

Tobi Tobi-De

👁️‍🗨️
Trade-offs everywhere!
View GitHub Profile
@Tobi-De
Tobi-De / GitCommitEmoji.md
Created May 10, 2022 14:52 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji
def decorator(arg1, arg2):
def wrapper(func):
def inner(*args, **kwargs):
...
@decorator(1, 2) # my_func = decorator(my_func)(1,2)
def my_func():
{
"data": [
{
"type": "hotel-offers",
"hotel": {
"type": "hotel",
"hotelId": "MCLONGHM",
"chainCode": "MC",
"dupeId": "700031300",
"name": "JW Marriott Grosvenor House London",
@Tobi-De
Tobi-De / detail.md
Last active October 11, 2022 10:53
This not explains the reason behind the get_price method needed by dj-shop-cart

Ok first of all, what is the get_price method ?

The get_price is a method required by the dj-shop-cart package that you must implement on your django model representing the products that you are adding to the cart. The signature is as follow:

class Product(models.Model):
 price = models.DecimalField(decimal_places=2, max_digits=10)
@Tobi-De
Tobi-De / filters.py
Created February 15, 2023 11:15
filter in multiple fields with django-filter
class LocationFilter(django_filters.FilterSet):
q = django_filters.CharFilter(method='my_custom_filter', label="Search")
class Meta:
model = Location
fields = ['q']
def my_custom_filter(self, queryset, name, value):
return queryset.filter(
Q(loc__icontains=value) |
pg_dump "sslmode=require host=<host> dbname=leerming user=leerming" --data-only -f leerming.sql
psql "host=<host> dbname=leerming user=leerming" < leer.sql
from typing import TYPE_CHECKING
import structlog
from .config import get_redis_url, get_client_tracking_enabled
from functools import wraps
import threading
import redis
import asyncio
if TYPE_CHECKING:
from .brokers import Broker
sse-starlette
starlette
redis
psycopg[c]
@Tobi-De
Tobi-De / sse_litestar.py
Created December 8, 2023 11:30
sse litestar
import time
from litestar import Litestar, get
from litestar.channels.backends.redis import RedisChannelsPubSubBackend
from litestar.channels.plugin import ChannelsPlugin
from litestar.response.sse import ServerSentEvent
import redis.asyncio as Redis
from typing import Generator, AsyncGenerator
import json
from contextlib import asynccontextmanager
@Tobi-De
Tobi-De / bulk.py
Last active April 3, 2024 08:36
Account Update without explicit lock
from django.db.models import Case, Value, When, F, Q
def transfer(from_account: Account, to_account: Account, amount: int):
with transaction.atomic():
count = Account.objects.filter(
Q(pk=from_account.pk, balance__gte=amount) | Q(pk=to_account.pk)
).update(
balance=Case(