Skip to content

Instantly share code, notes, and snippets.

View globax89's full-sized avatar

Sergey globax89

  • Saint Petersburg
View GitHub Profile
@globax89
globax89 / gist:7c51a82dae551a54ee6ddc940e591db7
Created December 16, 2020 20:00 — forked from timonweb/gist:2623793
Django: Programmatically saving image from URL to FileField or ImageField http://twigstechtips.blogspot.com/2012/04/django-programmatically-saving-image.html
class Product(models.Model):
# other fields
image = models.FileField(storage = MogileFSStorage(), upload_to = 'product_images')
from django.core.files import File
from django.core.files.temp import NamedTemporaryFile
product = Product()
# set all your variables here
product.save()
@globax89
globax89 / aiohttp-server.py
Created November 2, 2020 21:45 — forked from rcarmo/aiohttp-server.py
Example: asyncio and aiohttp, handling longpoll, eventsource and websocket requests with a queue and background workers
from aiohttp import web
from threading import Thread
import asyncio
import time, uuid
loop = asyncio.get_event_loop()
def long_blocking_thing(sleep):
time.sleep(sleep)
return 42
@globax89
globax89 / decorators.py
Created September 9, 2020 20:23 — forked from RodrigoEspinosa/decorators.py
Cache for Django model properties.
from __future__ import unicode_literals
import functools
from django.core.cache import cache
class cached(object):
"""Save the return of the function on the cache.
"""
import functools
from channels.handler import AsgiRequest
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.settings import api_settings
authenticators = [auth() for auth in api_settings.DEFAULT_AUTHENTICATION_CLASSES]
@globax89
globax89 / tokens.md
Created February 7, 2020 21:33 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

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

Last major update: 21.10.2019

Основы:

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

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

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

@globax89
globax89 / deploy-create-react-app-with-nginx.md
Created February 6, 2020 09:22 — forked from huangzhuolin/deploy-create-react-app-with-nginx.md
[Deploy create-react-app(react-router) with nginx] #react #nginx

Create-react-app

Create React apps with no build configuration.

Thanks to create-react-app. It's saves a lot of my time. I remember several months ago I had to setup a lot just for a react app, webpack, babel, test environment and so on... Fortunately, everything becomes easy now. Though you have many choices of start boiler plate, you worth trying this.

React router

If you are build a SPA with react, you probably use react-router.

@globax89
globax89 / Readme.md
Created September 8, 2019 19:54 — forked from Dmitriy-8-Kireev/Readme.md
Docker Шпаргалка