Skip to content

Instantly share code, notes, and snippets.

View shamanengine's full-sized avatar
:octocat:
script_kiddie

Artem Tymchenko shamanengine

:octocat:
script_kiddie
View GitHub Profile
@shamanengine
shamanengine / view.py
Created August 15, 2022 17:59
Views API
# Multiple Questions: Add imports here
import json
from http import HTTPStatus
from django.http import JsonResponse, HttpResponse, HttpResponseNotAllowed
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.views.decorators.csrf import csrf_exempt
from .models import fruit_to_dict, Fruit
"""This module helps manitulate requirements files from different projects"""
def str2dict(req: str) -> dict:
result = list()
for req in req.split():
if '==' in req:
result.append(tuple(req.split('==')))
else:
result.append((req, None))

How to Learn Python Junior path

Getting acquainted

  1. Pick up something relatively easy what you can accomplish within a very limited amount of time just to get the taste of language syntax. Timeframe examples:
  • one full day of dedicated time or
  • one weekend of relatively dedicated time or
  • one week spending 1-2 hours each day

My weapon of choice was Codecademy.

  • There is a free course on Python 2. The syntax is not that different from Python 3, difference under the hood at this point is neglectable and you'll figure out the difference between Python 2 and 3 earlier which is good for general literacy.
'''
Необходимо написать клиент к API VK , который будет считать распределение возрастов друзей для указанного пользователя.
На вход подается username или user_id пользователя.
На выходе получаем список пар (<возраст>, <количество друзей с таким возрастом>),
отсортированный по убыванию по второму ключу (количество друзей) и по возрастанию по первому ключу (возраст).
Например:
[(26, 8), (21, 6), (22, 6), (40, 2), (19, 1), (20, 1)]
@shamanengine
shamanengine / RegEx essentials
Created July 3, 2019 15:13
RegEx essentials
# Найти все действительные числа, например: -100; 21.4; +5.3; -1.5; 0
res = re.findall(r"[-+]?\d+(?:\.\d+)?", test_str)
# Проверить, что строка это серийный номер вида 00XXX-XXXXX-XXXXX-XXXXX, где X - шестнадцатиричная цифра
if re.match(r"^00[\da-f]{3}(?:-[\da-f]{5}){3}$", serial_str, re.IGNORECASE):
# Проверить, что строка является корректным IPv4 адресом
if re.match(r"^((25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(\.|$)){4}(?<!\.)$", ip_str):
python3 KickStarter.py
Traceback (most recent call last):
File "/home/pi/code/pyprojects/4inarow/venv/lib/python3.5/site-packages/numpy/core/__init__.py", line 16, in <module>
from . import multiarray
File "/home/pi/code/pyprojects/4inarow/venv/lib/python3.5/site-packages/numpy/core/multiarray.py", line 12, in <module>
from . import overrides
File "/home/pi/code/pyprojects/4inarow/venv/lib/python3.5/site-packages/numpy/core/overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory
@shamanengine
shamanengine / 4inrow
Created December 12, 2018 20:11
4inrow
print(0b1 + 0b10);
b = bin(11)
print(b)
# void makeMove(int col) {
# long move = 1L << height[col]++; // (1)
# bitboard[counter & 1] ^= move; // (2)
# moves[counter++] = col; // (3)
@shamanengine
shamanengine / test2.py
Created September 10, 2018 10:41
Random Stuff
print(bool(1)) # True
print(bool(1 - 1)) # False
print(bool(-3331)) # True
print(bool(-0.000)) # False
print(bool(-0.0000_001)) # True
print(12 or 5) # 12
print(0 or 5) # 5
_name = "Artem"
@shamanengine
shamanengine / decorator_chained.py
Last active September 9, 2018 20:47
Decorators
def bold(func):
def wrapped():
return "<b>" + func() + "</b>"
return wrapped
def italic(func):
def wrapped():
return "<i>" + func() + "</i>"
return wrapped