Skip to content

Instantly share code, notes, and snippets.

View zmnv's full-sized avatar
🔮
Creative Developer

zmnv zmnv

🔮
Creative Developer
View GitHub Profile
@zmnv
zmnv / ng-paste-image-from-clipboard.ts
Last active February 25, 2022 19:40
Paste image into DOM as base64 img src="" by ctrl+c ctrl+v clipboard. Angular TS, JS example by (paste)
/* Click by div'container' or any element inside in browser and ctrl+v to paste image. */
/* Pls copy any image in clipboard before :) */
import { Component, OnInit, ElementRef, ViewChild } from '@angular/core';
@Component({
selector: 'catalog-page-upload',
template: /*html*/`
<div class="container" (paste)="onPaste($event)">
<h1>Привет , мир!</h1>
@zmnv
zmnv / gulp-4-scss.js
Last active February 7, 2019 14:39
Gulp 4 CSS to SCSS with watch
const gulp = require('gulp'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
prefix = require('gulp-autoprefixer'),
rename = require('gulp-rename');
plumber = require('gulp-plumber');
function css() {
return gulp
.src('./scss/**/*.scss')
{
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
@zmnv
zmnv / sleep.js
Created December 29, 2018 16:50
Sync waiting time
function sleep(milliseconds) {
const initiation = new Date().getTime();
while ((new Date().getTime() - initiation) < milliseconds);
}
module.exports = sleep;
@zmnv
zmnv / group-array.js
Created December 29, 2018 16:46
Group array elemens by elements size
function groupArray(array = [], size = 10) {
const res = array.reduce((p, c) => {
if (p[p.length - 1].length == size) {
p.push([]);
}
p[p.length - 1].push(c);
return p;
}, [[]]);
@zmnv
zmnv / cuteNumbers.js
Last active December 29, 2018 16:32
Cute Numbers with spaces. Cyrillic labels by last number.
function cuteNumber(num) {
num = ''+num;
return num.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');;
}
function cuteNumberObjects(num, replacer = ['объект', 'объекта', 'объектов']) {
num = cuteNumber(num);
switch(num[num.length - 1]) {
case '1':
/*
Пример жёсткой связанности.
Переменная state и функция связаны из-за того,
что сама переменная используется в функции.
*/
let state = 0;
function updateState() {
state++;
@zmnv
zmnv / observable-1-basic.js
Last active October 13, 2018 07:00
Что такое Observable. Примитивная реализация. https://www.youtube.com/watch?v=NK-WzH3RBds
'use strict';
/* Исходная задача */
for (let letter of 'Hello, world!') {
console.log(letter);
}
/* Добавляем гибкости */
/* Original:
┌──────────────────────────────────────────────────────┐
│ _____ _ _ _____ _ 1.0.0 │
│ | _ |___ ___ |_|___ ___| |_ | __| |___ _ _ _ │
│ | __| _| . | | | -_| _| _| | __| | . | | | | │
│ |__| |_| |___|_| |___|___|_| |__| |_|___|_____| │
│ |___| │
│ │
│ © Valeriy Zimnev (@zmnv), 2018 │
└──────────────────────────────────────────────────────┘
@zmnv
zmnv / JS Simple Colorizer
Created April 15, 2018 04:17
Разукрашивает текст
'use strict';
const cs = (text, colorForeground, colorBackground) =>
colorBackground ?
`\x1b[${colorForeground}m\x1b[${colorBackground}m${text}\x1b[0m` :
`\x1b[${colorForeground}m${text}\x1b[0m`;
module.exports = cs;