Skip to content

Instantly share code, notes, and snippets.

View sunmeat's full-sized avatar
🐈
MEOW

Oleksandr Zahoruiko sunmeat

🐈
MEOW
View GitHub Profile
@sunmeat
sunmeat / different files.kt
Created March 29, 2026 11:33
jetpack compose example
build.gradle.kts (Project):
plugins {
alias(libs.plugins.android.application) apply false
kotlin("plugin.compose") version "2.0.21" apply false // !!!
}
==================================================================================================================
build.gradle.kts (Module:app):
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0A0A0F">
<!-- Декоративне коло вгорі -->
<View
@sunmeat
sunmeat / different files.cpp
Created March 27, 2026 09:04
one server multiple clients C++ example (UDP) mac os version
SERVER SIDE:
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
@sunmeat
sunmeat / different files.cpp
Created March 27, 2026 06:49
client server UDP C++ example mac os version
CLIENT SIDE:
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
using namespace std;
@sunmeat
sunmeat / views.py
Created March 25, 2026 14:09
запити1-М та агрегування + raw queries
from datetime import datetime
from django.shortcuts import render
from django.http import HttpRequest
from django.db.models import Avg, Count, Sum, Max, Min, F, Q
from app.models import Author, Book
# =============================================================================
# CRUD ДЛЯ AUTHOR (це було вже :)
# =============================================================================
@sunmeat
sunmeat / views.py
Last active May 20, 2026 15:45
розширені запити
на всякий випадок:
env\Scripts\activate
python manage.py shell
from app.views import author_filter_advanced, author_order_by, author_in, author_startswith, author_bulk_create, author_values, author_first_last, author_exists, author_union
...
# ── РОЗШИРЕНІ ЗАПИТИ ──────────────────────────────────────────────────────────
@sunmeat
sunmeat / views.py
Created March 25, 2026 12:56
CRUD операції. одна таблиця. команди для python manage.py shell
from datetime import datetime
from django.shortcuts import render
from django.http import HttpRequest
from app.models import Author
# ── CREATE ────────────────────────────────────────────────────────────────────
def author_create_method1(request):
"""Вставка автора через objects.create() - один рядок, одразу зберігає в БД"""
from django.core.management.base import BaseCommand
from django.apps import apps
from app.models import Author, Book
class Command(BaseCommand):
help = 'Наповнює базу даних початковими авторами та книгами'
def handle(self, *args, **options):
self.stdout.write(self.style.SUCCESS('Ласкаво просимо в кастомний шелл!'))
@sunmeat
sunmeat / models.py
Created March 25, 2026 11:51
налаштування констрейнтів
from django.db import models
from django.db.models import Q, F # для складних запитів, наприклад, для перевірки умов у CheckConstraint
# Q використовується для створення складних умов, F використовується для посилання на інші поля в моделі при створенні обмежень або запитів
# https://docs.djangoproject.com/en/6.0/ref/models/querysets/#django.db.models.Q
# https://docs.djangoproject.com/en/6.0/ref/models/expressions/#django.db.models.F
class Author(models.Model):
name = models.CharField(max_length=100, unique=True)
birth_year = models.IntegerField(null=True, blank=True)
rating = models.DecimalField(max_digits=3, decimal_places=1, default=5.0)
@sunmeat
sunmeat / settings.py
Created March 25, 2026 11:27
налаштування .env
import os
from dotenv import load_dotenv
load_dotenv()
.....
DATABASES = {
'default': {
'ENGINE': os.getenv('DB_ENGINE'),