Skip to content

Instantly share code, notes, and snippets.

@olegpolyakov
olegpolyakov / bootstrap-mq.scss
Last active May 3, 2019 01:55
Bootstrap Sass Media Query Variables
//== Media queries breakpoints
// Extra small screen / phone
$screen-xs: 480px;
$screen-xs-min: $screen-xs;
// Small screen / tablet
$screen-sm: 768px;
$screen-sm-min: $screen-sm;
.mouse-icon {
position: relative;
border: 2px solid #fff;
border-radius: 16px;
height: 50px;
width: 30px;
margin: 0 auto;
display: block;
z-index: 10;
}
@olegpolyakov
olegpolyakov / server.js
Created March 16, 2017 21:30
Node app using vhost
'use strict';
const express = require('express');
const vhost = require('vhost');
const site = require('./site');
const app = require('./app');
const api = require('./api');
const admin = require('./admin');
@olegpolyakov
olegpolyakov / webpack.config.js
Created March 16, 2017 21:31
Webpack configuration for React
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
library: './src/library/index.jsx',
player: './src/player/index.jsx',
vendor: ['react', 'react-dom']
@olegpolyakov
olegpolyakov / react-jwt-auth.js
Last active December 17, 2018 22:52
JWT for React
import React from 'react';
let cachedToken;
function setToken(token) {
cachedToken = token;
localStorage.setItem('authToken', token);
}
function getToken() {
@olegpolyakov
olegpolyakov / .eslintrc
Created March 22, 2017 12:36
ES List configuration
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2017
},
"rules": {
form#login-form(method='post')
input(type='hidden' name='_csrf' value=_csrfToken)
+input('text', 'username', 'Имя пользователя', null, 'Только маленькие латинские буквы и цифры без пробелов')(minlength='2' maxlength='32' pattern='^[a-z0-9]+$')
+input('password', 'password', 'Пароль')(required maxlength='128')
button#submit(type='submit').mdc-button.mdc-button--accent.mdc-button--raised.mdc-button--full-width Войти
a(href='/auth/reset-password').mdc-button Забыли пароль?
a(href='/auth/register').mdc-button Зарегистрироваться
@olegpolyakov
olegpolyakov / jset-test-runner.js
Last active October 2, 2019 12:49
Jest test runner
describe('Функции:', () => {
[].forEach((filename, index) => {
let exercise = require(`../exercises/${filename}/test`);
describe(`Упражнение ${index + 1}: ${exercise.title}`, () => {
let solution;
beforeEach(() => solution = require(`../exercises/${filename}`));
exercise.tests.forEach(({ description, assertion, async }) => {
@olegpolyakov
olegpolyakov / promise.js
Last active August 19, 2019 04:09
Promises/A+ Implementation
class Promise {
static state = {
PENDING: 'PENDING',
FULFILLED: 'FULFILLED',
REJECTED: 'REJECTED'
};
static defer(fn) {
setTimeout(fn, 0);
}
@olegpolyakov
olegpolyakov / create-element.js
Last active July 14, 2022 21:10
A utility function for creating dom elements similar to `React.createElement`
export function createElement(tag, props, ...children) {
const element = document.createElement(tag);
if (props) {
Object.entries(props).forEach(([key, value]) => {
if (key.startsWith('on') && typeof value === 'function') {
element.addEventListener(key.substring(2), value);
} else if (key.startsWith('data-')) {
element.setAttribute(key, value);
} else {