Skip to content

Instantly share code, notes, and snippets.

View Krabaton's full-sized avatar
:dependabot:
Working

Yurii Kuchma Krabaton

:dependabot:
Working
View GitHub Profile
@Krabaton
Krabaton / after_res_hooks.js
Created May 6, 2017 09:05 — forked from pasupulaphani/after_res_hooks.js
Mongoose connection best practices
var db = mongoose.connect('mongodb://localhost:27017/DB');
// In middleware
app.use(function (req, res, next) {
// action after response
var afterResponse = function() {
logger.info({req: req}, "End request");
// any other clean ups
@Krabaton
Krabaton / _singelton.js
Last active October 5, 2018 19:47
singelton
var counterModule = (function () {
var instance,
counter = 0;
var getCounter = function () {
return counter;
}
var increaseCounter = function () {
counter ++;
@Krabaton
Krabaton / gulp-task
Created July 15, 2017 19:30
сТатия ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΎΠΊ ΠΊΠ°ΠΊ Ρƒ tiny
module.exports = function () {
$.gulp.task('copy:img', function () {
return $.gulp.src('app/img/**/*.*')
.pipe($.gp.cache($.gp.imagemin([
$.gp.imagemin.gifsicle({
interlaced: true
}),
$.gp.imagemin.jpegtran({
progressive: true
}),
@Krabaton
Krabaton / tokens.md
Created August 27, 2017 10:12 — forked from zmts/tokens.md
ΠŸΡ€ΠΎ Ρ‚ΠΎΠΊΠ΅Π½Ρ‹, JSON Web Tokens (JWT), Π°ΡƒΡ‚Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΡŽ ΠΈ Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·Π°Ρ†ΠΈΡŽ

Token-Based Authentication(JWT)

Preconditions:

Π’ Π΄Π°Π½Π½ΠΎΠΉ Π·Π°ΠΌΠ΅Ρ‚ΠΊΠ΅ рассматриваСтся Ρ€Π°Π±ΠΎΡ‚Π° JWT с симмСтичным Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌΠΎΠΌ ΡˆΠΈΡ„Ρ€ΠΎΠ²Π°Π½ΠΈΡ (HS256/HS384/HS512)

ΠžΡΠ½ΠΎΠ²Ρ‹:

АутСнтификация(authentication, ΠΎΡ‚ Π³Ρ€Π΅Ρ‡. Ξ±α½ΞΈΞ΅Ξ½Ο„ΞΉΞΊΟŒΟ‚ [authentikos] – Ρ€Π΅Π°Π»ΡŒΠ½Ρ‹ΠΉ, ΠΏΠΎΠ΄Π»ΠΈΠ½Π½Ρ‹ΠΉ; ΠΎΡ‚ αὐθέντης [authentes] – Π°Π²Ρ‚ΠΎΡ€) - это процСсс ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠΈ ΡƒΡ‡Ρ‘Ρ‚Π½Ρ‹Ρ… Π΄Π°Π½Π½Ρ‹Ρ… ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ (Π»ΠΎΠ³ΠΈΠ½/ΠΏΠ°Ρ€ΠΎΠ»ΡŒ). ΠŸΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° подлинности ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ ΠΏΡƒΡ‚Ρ‘ΠΌ сравнСния Π²Π²Π΅Π΄Ρ‘Π½Π½ΠΎΠ³ΠΎ ΠΈΠΌ пароля с ΠΏΠ°Ρ€ΠΎΠ»Π΅ΠΌ, сохранённым Π² Π±Π°Π·Π΅ Π΄Π°Π½Π½Ρ‹Ρ… ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ;

Авторизация(authorization β€” Ρ€Π°Π·Ρ€Π΅ΡˆΠ΅Π½ΠΈΠ΅, ΡƒΠΏΠΎΠ»Π½ΠΎΠΌΠΎΡ‡ΠΈΠ²Π°Π½ΠΈΠ΅) - это ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΠ° ΠΏΡ€Π°Π² ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ Π½Π° доступ ΠΊ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½Ρ‹ΠΌ рСсурсам.

function delay(ms) {
return () => {
return new Promise(resolve => setTimeout(() => {
resolve();
console.log('!!!');
}, ms));
}
}
function waterfall(list) {
@Krabaton
Krabaton / gist:3750369b215f35d4a6205b9364179dbc
Created February 11, 2018 15:40 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: πŸ˜„ :smile: πŸ˜† :laughing:
😊 :blush: πŸ˜ƒ :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
πŸ˜† :satisfied: 😁 :grin: πŸ˜‰ :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: πŸ˜€ :grinning:
πŸ˜— :kissing: πŸ˜™ :kissing_smiling_eyes: πŸ˜› :stuck_out_tongue:
There have been proposals about exposing these variables through import.meta, but for now, you need a hacky workaround that I found here:
// expose.js
module.exports = {__dirname};
// use.mjs
import expose from './expose.js';
const {__dirname} = expose;
In Node.js 10 there's an alternative that doesn't require creating multiple files:
@Krabaton
Krabaton / node-setup-pm2-nginx.md
Created June 16, 2018 12:05 — forked from tomysmile/node-setup-pm2-nginx.md
Setup NodeJS Production with PM2, Nginx in Ubuntu 16.04

How To Set Up a Node.js Application for Production on Ubuntu 16.04

with PM2 & Nginx

Create User

as a root, run below commands on server:

# adduser tomy
@Krabaton
Krabaton / app.js
Created October 7, 2020 12:18
Upload Multer
const createError = require('http-errors')
const express = require('express')
const path = require('path')
const fs = require('fs').promises
const app = express()
const multer = require('multer')
const uploadDir = path.join(process.cwd(), 'uploads')
const storeImage = path.join(process.cwd(), 'images')
const storage = multer.diskStorage({
@Krabaton
Krabaton / app.js
Created October 7, 2020 12:21
Upload formidable
const createError = require('http-errors')
const express = require('express')
const path = require('path')
const fs = require('fs').promises
const formidable = require('formidable')
const app = express()
const uploadDir = path.join(process.cwd(), 'uploads')
const storeImage = path.join(process.cwd(), 'images')