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
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 / 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:
function delay(ms) {
return () => {
return new Promise(resolve => setTimeout(() => {
resolve();
console.log('!!!');
}, ms));
}
}
function waterfall(list) {
@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 — разрешение, уполномочивание) - это проверка прав пользователя на доступ к определенным ресурсам.

@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 / _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 / 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 / app.js
Created February 17, 2017 01:08 — forked from sogko/app.js
gulp + expressjs + nodemon + browser-sync
'use strict';
// simple express server
var express = require('express');
var app = express();
var router = express.Router();
app.use(express.static('public'));
app.get('/', function(req, res) {
res.sendfile('./public/index.html');
@Krabaton
Krabaton / array_iteration_thoughts.md
Created January 16, 2017 09:53 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@Krabaton
Krabaton / debounce.js
Created January 11, 2017 18:31
Debouncing
// debounce function that will wrap our event
function debounce(fn, delay) {
// maintain a timer
let timer = null;
// closure function that has access to timer
return function() {
// get the scope and parameters of the function
// via 'this' and 'arguments'
let context = this;
let args = arguments;