Skip to content

Instantly share code, notes, and snippets.

View gbezyuk's full-sized avatar
💭
Müssen wissen, werden wissen. 12:45 Less Wrong: restate my assumptions. ~1/137

Grigoriy Beziuk gbezyuk

💭
Müssen wissen, werden wissen. 12:45 Less Wrong: restate my assumptions. ~1/137
View GitHub Profile
@gbezyuk
gbezyuk / jwt-auth-memo.ru.md
Last active August 21, 2023 13:04
ЛикБез по Аутентификации, Авторизации и JWT (Django4, Nuxt2, RU)

ЛикБез по Аутентификации, Авторизации и JWT

Версия на русском языке с использованием Django4 и Nuxt2.

Эта дока покрывает JWT auth workflow, но не затрагивает вопросы кастомных юзеров и кастомных методов аутентификации Django. На их счёт — по первому вопросу https://testdriven.io/blog/django-custom-user-model/, а по второму — https://docs.djangoproject.com/en/4.1/topics/auth/customizing/.

Вводная

Об Аутентификации и Авторизации

  1. Есть Аутентификация, и есть Авторизация. Их часто путают и сливают в единое понятие, и с этим приходится жить. Но по идее это два ортогональных явления.
function randInt (n) {
return Math.floor(Math.random() * n)
}
function randChoice (array) {
return array[randInt(array.length)]
}
function allTheSame (array) {
if (!array.length) {
function randInt (n) {
return Math.floor(Math.random() * n)
}
function randChoice (array) {
return array[randInt(array.length)]
}
function generateFamily (numberOfKids, possibleGenders) {
const result = []
@gbezyuk
gbezyuk / c_addresses_arrays_and_pointers.c
Created May 12, 2017 03:59
C language addresses, arrays and pointers explained in details.
#include <stdio.h>
/*int part1 () {
int var = 15;
printf("var: value is %d, address is %p\n", var, &var);
// changing var directly
var = 20;
printf("var value was changed directly and now is %d, but the address is still %p\n", var, &var);
*(&var) = 30;
printf("var value was changed indirectly and now is %d, but the address is still %p\n", var, &var);
@gbezyuk
gbezyuk / django_to_dict_v03.py
Last active November 26, 2016 10:46
A mixin for customized to_dict() methods for Django models
from filebrowser.fields import FileBrowseField # not really a dependency, will be extracted before packaging
class ToDictMixin:
def to_dict(self):
opts = self._meta
data = {}
# initializing manually specified field grouping
if self.TO_DICT_GROUPING:
# we can dramatically reduce the possible answers space
# using a simple heuristic instead of straightforward permutation generation
# here we have 360 variants instead of 40K using the bruteforce approach
LEN = 8
def generate_possible_positions(digit):
start = 0
while start + digit + 1 < LEN:
➜ puzzles python bruteforce-for-julia-ogun.py| grep True | uniq
((2, 3, 4, 2, 1, 3, 1, 4), True)
((4, 1, 3, 1, 2, 4, 3, 2), True)