Skip to content

Instantly share code, notes, and snippets.

View Alexzanderk's full-sized avatar
:octocat:

Alexander Kotsarev Alexzanderk

:octocat:
View GitHub Profile
@Alexzanderk
Alexzanderk / passwords.md
Created June 22, 2025 08:57 — forked from zmts/passwords.md
Про хранение паролей в БД

Про хранение паролей в БД

При создании нового юзера

  1. При регистрации юзер вводит некий пароль
  2. Генерим случайную соль индивилуально для каждого юзера
  3. Создаем хеш на основе введенного юзером пароля и соли
  4. Записываем хеш(не пароль) в БД + соль в отдельном филде

Авторизация существующего юзера

  1. Юзер вводит в поле авторизации некий пароль
@Alexzanderk
Alexzanderk / tokens.md
Created August 2, 2024 11:21 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

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

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
@Alexzanderk
Alexzanderk / discord-workaround-puppeteer-fail.js
Created June 2, 2024 19:49 — forked from Mathspy/discord-workaround-puppeteer-fail.js
A Discord login workaround that failed but contains many valuable knowledge I guess
const puppeteer = require("puppeteer");
// This works around Discord's security measurements
// to set values on localStorage before we go to discord.com/login
const setDomainLocalStorage = async (browser, url, values) => {
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on("request", r => {
r.respond({
status: 200,

Summary of issue(s)

CLICKUP TASK: XX

Type of change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Tech Debt / Refactor
  • Minor changes shouldn't affect anything

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do:

@Alexzanderk
Alexzanderk / Git aliases
Created April 7, 2022 08:39
Git aliases
[alias]
delete-merged = git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
var nextChar = c=>c?String.fromCharCode(c.charCodeAt(0)+1):'A';
var nextCol = s=>s.replace(/([^Z]?)(Z*)$/, (_,a,z)=>nextChar(a) + z.replace(/Z/g,'A'));
//test:
nextCol(''); //A
nextCol('A'); //B
nextCol('Z'); //AA
nextCol('AA'); //AB
nextCol('XYZ'); //XZA
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
@Alexzanderk
Alexzanderk / repositoryService.ts
Created March 1, 2021 13:56
sequelize generic repository service
type Constructor<T> = new (...args: any[]) => T;
type ModelType<T extends Model<T>> = Constructor<T> & typeof Model;
export interface IRepository<T extends Model> {
get(id: string): Promise<T| null>;
find(where: FindOptions<T>): Promise<T>;
create(model: T): Promise<T>;
update(key: any, model: T): Promise<T>;
}
@Alexzanderk
Alexzanderk / generateSertificate.sh
Created December 9, 2020 08:44
Generate sertificate
openssl req -new -x509 -nodes -newkey rsa:1024 -keyout server.key -out server.crt