Skip to content

Instantly share code, notes, and snippets.

View apalii's full-sized avatar
🐍
focusing

Andrii Palii apalii

🐍
focusing
View GitHub Profile
@apalii
apalii / zsh.md
Last active December 4, 2023 16:33
MacBook Onboarding

Base

BREW xcode

brew install gcc 
brew install git
brew install postgresql@14
brew install wget

Terminal

@apalii
apalii / celery.sh
Created September 24, 2019 12:27 — forked from amatellanes/celery.sh
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@apalii
apalii / tokens.md
Created July 18, 2019 09:26 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Основы:

Аутентификация(authentication, от греч. αὐθεντικός [authentikos] – реальный, подлинный; от αὐθέντης [authentes] – автор) - это процесс проверки учётных данных пользователя (логин/пароль). Проверка подлинности пользователя путём сравнения введённого им логина/пароля с данными сохранёнными в базе данных.

Авторизация(authorization — разрешение, уполномочивание) - это проверка прав пользователя на доступ к определенным ресурсам.

Например после аутентификации юзер sasha получает право обращатся и получать от ресурса "super.com/vip" некие данные. Во время обращения юзера sasha к ресурсу vip система авторизации проверит имеет ли право юзер обращатся к этому ресурсу (проще говоря переходить по неким разрешенным ссылкам)

@apalii
apalii / pythononeliners.txt
Created May 8, 2019 13:24
python one liners!
Some useful Python one-liners taken from http://www.reddit.com/r/Python/comments/fofan/suggestion_for_a_python_blogger_figure_out_what/
All modules listed are part of the standard library and should work with Python 2.6+
How to use:
$ python -m [module] [arguments]
calendar - does default to displaying a yearly calendar, but it has a bunch of options (args are year or year month, options are HTML output, calendar locale, encoding, and some type-specific stuff, see python -m calendar -h)
cgi, dumps a bunch of information as HTML to stdout
@apalii
apalii / postgres-cheatsheet.md
Last active January 15, 2021 11:47 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

How to drop database in docker

docker ps
docker exec -it 8464180ab144 psql -U postgres -d postres

docker exec -it $(docker ps | grep postgres | awk '{print $1}') psql -U postgres -d postgres
@apalii
apalii / caching decorator.py
Last active July 31, 2017 11:17
decorator with parameters for caching data
CACHE = dict()
def cached(ttl, cache, logger=None):
"""Caching decorator with parameters
:param ttl: time to live for the data
:type int
:param cache: cache object
:type dict
:param logger: logger to use
# -*- coding: utf8 -*-
import json
from datetime import datetime
import requests
class MyShows(object):
API_URL = 'https://api.myshows.me/v2/rpc/'
@apalii
apalii / gen_conf.sh
Created May 17, 2016 08:48
jinja2 config generator example
# ll
-rwxr--r-- 1 root root 305 May 17 04:45 gen_conf.py
drwxr-xr-x 2 root root 4096 May 17 03:24 templates
-rw-r--r-- 1 root root 6 May 17 03:15 vars.csv
# cat templates/test.conf
line 1
line 2
{% for item in items %}line {{ item }}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import math
class TriangleError(Exception):
"""docstring for TriangleError
error.args - single element tuple which conteins the msg passed to
the constructor"""
def __init__(self, text, sides):
super().__init__(text)
self.sides = tuple(sides)