This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plural_days(n): | |
days = ['день', 'дня', 'дней'] | |
if n % 10 == 1 and n % 100 != 11: | |
p = 0 | |
elif 2 <= n % 10 <= 4 and (n % 100 < 10 or n % 100 >= 20): | |
p = 1 | |
else: | |
p = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import pathlib | |
if __name__ == "__main__": | |
# загрузка библиотеки | |
libname = pathlib.Path().absolute() / "libcadd.so" | |
c_lib = ctypes.CDLL(libname) | |
x, y = 6, 2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState, useEffect} from 'react'; | |
function Example() { | |
const [count, setCount] = useState(0); | |
useEffect(() => { | |
document.title = `Нажато ${count} раз`; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
function Counter() { | |
// Определение переменной-счётчика | |
const [count, setCount] = useState(0); | |
return ( | |
<div> | |
<p>Вы нажали {count} раз</p> | |
<button onClick={() => setCount(count + 1)}> | |
Нажми меня |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Welcome extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {}; | |
} | |
render() { | |
return ( | |
<div> | |
<h1>Hello, world!</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Time extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {date: date: new Date()}; | |
} | |
render() { | |
return ( | |
<div> | |
<h1>It is {this.state.date.toLocaleTimeString()}</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post extends Component { | |
constructor(props){ | |
super(props); | |
this.state = {} | |
} | |
render(){ | |
// код пользовательского интерфейса | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useParams, useLocation } from "react-router-dom"; | |
import React from 'react'; | |
const Profile = () => { | |
// Используйте хук useParams для получения имени пользователя из URL. | |
// Имя пользователя должно быть применено в качестве именованного параметра в маршруте. | |
let { username } = useParams(); | |
// useLocation применяется для захвата состояния из входных данных в объект. | |
// Так можно захватить каждое поле в объекте, используя то же имя, что и имя переменной. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExampleMiddleware: | |
def _init_(self, get_response): | |
self.get_response = get_response | |
def _call_(self, request): | |
# Код, вызываемый перед представлением при каждом запросе. | |
response = self.get_response(request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def simple_middleware(get_response): | |
# Инициализация и настройка | |
def middleware(request): | |
# Код, вызываемый перед представлением при каждом запросе. | |
response = get_response(request) | |
# Код, вызываемый после представления при каждом запросе. |
NewerOlder