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 / main.cpp
Created February 26, 2026 07:13
це моє ДЗ по С++ на тему сокетів
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
@sunmeat
sunmeat / main.cpp
Created February 26, 2026 06:27
TCP + threads: CLIENT SIDE (MacOS)
// client.cpp
// компілювати: clang++ -std=c++17 -o client client.cpp -pthread
// запуск: ./client
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@sunmeat
sunmeat / main.cpp
Created February 26, 2026 06:26
TCP + threads: SERVER SIDE (MacOS)
// server.cpp
// компілювати: clang++ -std=c++17 -o server server.cpp -pthread
// запуск: ./server
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@sunmeat
sunmeat / views.py
Created February 25, 2026 13:41
перетворення об'єкта класу в словник для повернення JSON
from django.http import (
HttpResponse,
JsonResponse,
HttpResponseRedirect,
FileResponse,
StreamingHttpResponse,
)
from django.shortcuts import render
import os
import time
@sunmeat
sunmeat / different files.py
Created February 25, 2026 13:15
Django Response Classes
urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name='home'), # головна сторінка
path('json/', views.json_response, name='json-response'), # JsonResponse
path('redirect/', views.redirect_example, name='redirect'), # HttpResponseRedirect
path('file/', views.file_response, name='file-response'), # FileResponse
@sunmeat
sunmeat / different files.py
Created February 25, 2026 12:58
HttpRequest в джанго
NewApp / weather / urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.request_demo, name='request-demo'),
path('submit/', views.handle_form, name='submit-form'),
]
@sunmeat
sunmeat / different files.py
Created February 25, 2026 12:15
особливості маршрутів
NewApp / weather / urls.py:
from django.urls import path, re_path, register_converter
from django.http import HttpResponse
from . import views
# кастомний конвертер
class FourDigitYearConverter:
"""Кастомний конвертер для років 1000–9999"""
regex = r'[1-9]\d{3}' # чотири цифри, перша не нуль
@sunmeat
sunmeat / different files.py
Created February 25, 2026 08:27
показ сторінки з окремого додатку
NewApp / weather / views.py:
from django.shortcuts import render
from django.http import HttpResponse
def hello(request):
return HttpResponse("<h1>Привіт! Це сторінка з додатка weather 🌤️</h1>")
##############################################################################################
@sunmeat
sunmeat / task.md
Last active February 24, 2026 11:16
ДЗ: знайомство з фреймворком django

Вебдодаток «Інформація про компанію» на Django

Мета проєкту

Створити простий багатороздільний вебсайт компанії з чіткою структурою URL та коректною обробкою неіснуючих (помилкових) адрес.

Вимоги до розділів та адрес

Розділ Базова адреса Приклади неправильних адрес, які все одно показують розділ
@sunmeat
sunmeat / different files.py
Created February 24, 2026 08:48
передача параметру в адресний рядок та гет-запит (прогноз погоди)
views.py:
from django.http import HttpResponse
import requests # для запитів в інтернет
# cd C:\Users\Alex\Desktop\DjangoWebProject1
# env\Scripts\activate
# py -m pip install requests
def main_page(request): # http://localhost:58566
return HttpResponse("головна сторінка!")