Skip to content

Instantly share code, notes, and snippets.

@sunmeat
sunmeat / App.jsx
Last active October 28, 2025 19:40
tanstack query example react + dexie.js
import {useState, useEffect} from 'react';
import {QueryClient, QueryClientProvider, useQuery} from '@tanstack/react-query';
import Dexie from 'dexie';
import './App.css';
// ініціалізація Dexie, npm install dexie
// https://dexie.org/
const db = new Dexie('CartDatabase');
db.version(1).stores({
cart: '++id, title, price, image', // схема для таблиці кошика
@sunmeat
sunmeat / different files.jsx
Last active October 28, 2025 20:16
react + php + files
создать папку files в папке react на atwebpages.com
=======================================================================================
App.jsx:
import { useState, useEffect } from 'react';
import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query';
import './App.css';
@sunmeat
sunmeat / App.jsx
Last active October 28, 2025 20:49
IntersectionObserver
import { useState, useEffect, useRef } from 'react';
import { QueryClient, QueryClientProvider, useQuery } from '@tanstack/react-query';
import './App.css';
const API_URL = 'http://sunmeat.atwebpages.com/react/api.php';
// екземпляр QueryClient
const queryClient = new QueryClient();
const truncateText = (text, maxLength) =>
text.length > maxLength ? text.slice(0, maxLength) + '...' : text;
@sunmeat
sunmeat / different files.jsx
Last active October 28, 2025 21:00
REACT: pythonanywhere server example + fetch API + вирішення проблеми CORS
https://www.pythonanywhere.com/user/sunmeat/files/home/sunmeat/alex.py?edit:
from flask import Flask, jsonify
from flask_cors import CORS
app = Flask(__name__)
# Enable CORS for all routes, allowing all origins
CORS(app, resources={r"/api/*": {"origins": "*"}})
@sunmeat
sunmeat / different files.jsx
Last active October 27, 2025 20:15
інтернет магазин на класових компонентах
App.jsx:
import React, {Component} from 'react';
import {QueryClient, QueryClientProvider, useQuery, useMutation, useQueryClient} from '@tanstack/react-query'; // npm install @tanstack/react-query
import Dexie from 'dexie'; // npm install dexie
import './App.css';
const db = new Dexie('CartDatabase');
db.version(1).stores({
cart: 'id, title, price, image, quantity',
@sunmeat
sunmeat / different files.jsx
Last active October 28, 2025 21:33
simple redux example
App.jsx:
// імпортуємо хуки та компонент Provider з react-redux
import {useSelector, useDispatch, Provider} from 'react-redux'
// !!! npm install react-redux @reduxjs/toolkit !!!
// хук useSelector дозволяє отримати доступ до стану сховища - єдиного центру даних для всього додатка
// у сховищі (store) зазвичай лежить один великий об'єкт - дерево стану, для всього
// useSelector "селектить" (вибирає) потрібний шматок даних із цього глобального стану
@sunmeat
sunmeat / Program.cs
Created October 2, 2025 09:44
довга арифметика C#
using ExtendedNumerics; // BigDecimal - ставимо через Nuget
using System.Numerics; // BigInteger - вбудований тип
using System.Text;
class Program
{
static void Main()
{
Console.OutputEncoding = Encoding.UTF8;
@sunmeat
sunmeat / Program.cs
Last active October 29, 2025 20:37
введення даних в консоль
using System.Runtime.InteropServices; // DllImport
using System.Text; // Console.InputEncoding = Encoding.UTF8;
namespace ConsoleIO
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct ConsoleFont
{
public uint Index;
public short SizeX, SizeY;
@sunmeat
sunmeat / Program.cs
Created October 2, 2025 10:41
умови: іф та свіч
using System.Text;
namespace Conditions
{
class TestClass
{
}
class Program
{
@sunmeat
sunmeat / Program.cs
Created October 2, 2025 10:47
цикли в сішарп
using System.Reflection;
using System.Text;
namespace Cycles
{
static class Input
{
static int number;
public static int Number()