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,

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 / launch.json
Created July 28, 2020 20:26 — forked from joelharkes/launch.json
Debug ts-mocha in vs code (visual studio code)
{
"version": "0.2.0",
"configurations": [
{
"name": "Run ts-mocha File",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/ts-mocha",
"runtimeArgs": [
"${file}"
@Alexzanderk
Alexzanderk / app.get.js
Last active June 6, 2021 14:47 — forked from BetterProgramming/app.get.js
Video online
app.get('/video', function(req, res) {
const path = 'assets/sample.mp4'
const stat = fs.statSync(path)
const fileSize = stat.size
const range = req.headers.range
if (range) {
const parts = range.replace(/bytes=/, "").split("-")
const start = parseInt(parts[0], 10)
const end = parts[1]
? parseInt(parts[1], 10)
@Alexzanderk
Alexzanderk / ES6-Setup with nodemon.md
Last active February 19, 2020 07:13 — forked from rahman541/ES6-Setup.md
ES6 Setup with nodemon

ES6 Setup

npm init -y
npm i --save-dev nodemon
npm add babel-preset-env babel-cli

Create a .babelrc config in your project root. Insert the following

{
 "presets": ["env"]
@Alexzanderk
Alexzanderk / emit.js
Created November 28, 2019 09:39 — forked from aheckmann/emit.js
mongoose update,new,remove events
var mongoose = require('mongoose');
mongoose.connect('localhost', 'testing_emitUpdate');
var Schema = mongoose.Schema;
var schema = new Schema({
name: String
});
// plumbing
schema.pre('save', function (next) {
@Alexzanderk
Alexzanderk / UploadFileComponent.tsx
Created September 24, 2019 12:05 — forked from vdelacou/UploadFileComponent.tsx
React / Typescript / Material UI / Upload file / Custom Button / Async /
// import .....
const inputUploadFile: CSSProperties = {
display: 'none',
};
const buttonUploadFile: CSSProperties = {
margin: 8,
};
@Alexzanderk
Alexzanderk / eslint.json
Last active August 19, 2018 12:25 — forked from BilalBudhani/eslint.json
Wesbos' eslint + prettier config
{
"extends": [
"airbnb",
"prettier",
"prettier/react"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {