This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * World's simplest express server | |
| * - used to serve index.html from /public | |
| */ | |
| var express = require('express'); | |
| var serveStatic = require('serve-static'); | |
| var app = express(); | |
| app.use(serveStatic(__dirname + '/public')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ajax.js ---------------------------- сторона клиента | |
| function get(url, data) { | |
| return new Promise(function(resolve, reject) { | |
| var req = new XMLHttpRequest(); | |
| req.open('POST', url); | |
| req.setRequestHeader('content-type', 'application/json'); // очень важно укзать заголовок !!! | |
| req.onload = function() { | |
| if (req.status == 200) { | |
| resolve(req.response); // в случае успеха получаем ответ сервера | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*! | |
| * JavaScript preload() function – http://mths.be/preload | |
| * Preload images, CSS and JavaScript files without executing them | |
| * Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/ | |
| * Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/ | |
| */ | |
| function preload(array) { | |
| var length = array.length, | |
| document = window.document, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Lasy load by David Walsh | |
| /* | |
| <img data-src="/path/to/image.jpg" alt=""> | |
| img { | |
| opacity: 1; | |
| transition: opacity 0.3s; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // которая проверяет длину строки str, и если она превосходит maxlength – заменяет конец str на "...", | |
| // так чтобы ее длина стала равна maxlength. | |
| function truncate(str, maxlength) { | |
| if (str.length > maxlength) { | |
| return str.slice(0, maxlength - 3) + '...'; | |
| // итоговая длина равна maxlength | |
| } | |
| return str; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function truncate(str, maxlength) { | |
| if (str.length > maxlength) { | |
| var arr = str.split(''), | |
| count = arr.length / maxlength | 0, | |
| result = ''; | |
| for (var i=1; i<= count; i++) { | |
| var part = ''; | |
| if(arr[i * maxlength] !== ' ') { | |
| part = arr.splice(0, i * maxlength + 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var rp = require('request-promise') | |
| var url1 = {} | |
| var url2 = {} | |
| var url3 = {} | |
| rp(url1) | |
| .then(response => { | |
| // add stuff from url1 response to url2 | |
| return rp(url2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function declOfNum(number, titles) { | |
| const cases = [2, 0, 1, 1, 1, 2]; | |
| return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ]; | |
| } | |
| // declOfNum(11, ['фотография','фотографии','фотографий']) => фотографий |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function priceFormat(price) { | |
| const arr = []; | |
| String(price).split('').reverse().forEach((c, i) => { | |
| if (i % 3 === 0 ) { | |
| arr.push(' ') | |
| } | |
| arr.push(c) | |
| }); | |
| return arr.reverse().join('').trim() | |
| } |