Skip to content

Instantly share code, notes, and snippets.

View Soyuzbek's full-sized avatar
💭
I am a python backend developer

Soyuzbek Soyuzbek

💭
I am a python backend developer
  • Bishkek, Kyrgyzstan
View GitHub Profile
@Soyuzbek
Soyuzbek / pydantic partial update.py
Created May 19, 2022 17:19
Generate form for partial update with pydantic model
from typing import Optional
import pydantic
class AllOptional(pydantic.main.ModelMetaclass):
def __new__(mcs, name, bases, namespaces, **kwargs):
annotations = namespaces.get('__annotations__', {})
for base in bases:
annotations.update(base.__annotations__)
@Soyuzbek
Soyuzbek / python-alpine-dependencies.Dockerfile
Last active February 1, 2025 06:03
Python alpine base image requirements for most needed python libraries
FROM python:latest-alpine
### dependencies on alpine image ###
#poetry installation/(runtime?) dependencies
RUN apk add gcc musl-dev libffi-dev
# Pillow installation dependencies
RUN apk add --no-cache jpeg-dev zlib-dev
# Pillow runtime dependencies
from rest_framework.routers import SimpleRouter, Route, DynamicRoute
class LookupFreeRouter(SimpleRouter):
routes = [
# CRUD route.
Route(
url=r'^{prefix}{trailing_slash}$',
mapping={
'get': 'retrieve',
from typing import List
from exponent_server_sdk import (
PushClient,
PushMessage,
PushServerError,
)
from requests.exceptions import ConnectionError, HTTPError
def send_expo_message(tokens: List[str], message: str, extra=None):
"""
import os
import sys
import requests
VALID_IMAGE_EXTENSIONS = ('.png', '.jpg', '.jpeg')
def image_uploader(url, directory):
images = []
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=user-name
Group=www-data
WorkingDirectory=/home/user-name/myprojectdir
ExecStart=/home/user-name/myprojectdir/myprojectenv/bin/gunicorn \
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
@Soyuzbek
Soyuzbek / nginx-project_name.conf
Last active January 15, 2021 03:02
Configuration file for django api & vue spa server
server {
listen 80;
server_name your.ip.address.or.domain.name;
root /var/www/project_name/;
location / {
try_files /static/index.html =404;
}
location = /favicon.ico { access_log off; log_not_found off; }
@Soyuzbek
Soyuzbek / views.py
Last active December 16, 2020 07:20
from django.conf import settings
from django.shortcuts import redirect
def language_view(request, lang):
response = redirect(request.META.get('HTTP_REFERER', '/'))
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang)
return response
# © 2020 GitHub, Inc.