Skip to content

Instantly share code, notes, and snippets.

View maximgatilin's full-sized avatar

Maxim Gatilin maximgatilin

  • @hh.ru
View GitHub Profile
function roundPlus(x, n) { //x - число, n - количество знаков
if(isNaN(x) || isNaN(n)) return false;
var m = Math.pow(10,n);
return (Math.ceil(x*m)/m).toFixed(n); // в большую сторону
}
@maximgatilin
maximgatilin / docFrag.js
Last active August 20, 2020 02:12
Document fragment with jQuery
var documentFragment = $(document.createDocumentFragment());
for (var i = 0; i < 5; ++i) {
var span = $('<span>' + i + '</span>');
documentFragment.append(span);
}
console.info(documentFragment);
$('#result').append(documentFragment);
// Более легкий способ
var htmlStr = '';
@maximgatilin
maximgatilin / test.impex
Last active February 12, 2017 05:41
Test impex to create and paste CMS Component #tags:hybris
# Создается CMS компонент(если просто добавить то он будет мертвым, просто висеть в базе)
INSERT_UPDATE AccessoriesCMSComponent;$contentCV[unique=true];uid[unique=true];name;title
;;AccessoriesComponent;Accessories;Аксессуары
# Созается position и какие типы может принимать
INSERT_UPDATE ContentSlotName;name[unique=true];template(uid,$contentCV)[unique=true][default='ProductDetailsPageTemplate'];validComponentTypes(code);compTypeGroup(code);
;AccessoriesContainer;;AccessoriesCMSComponent;wide;
# Создаем ContentSlot и привязываем к нему компонент и position (При многократном добавлении cmsComponents нужно указываеть через лист, чтобы не перезаписать)
INSERT_UPDATE ContentSlot;$contentCV[unique=true];uid[unique=true];name;active;cmsComponents(uid,$contentCV);
@maximgatilin
maximgatilin / gist:5b47073690efe5c413be2311708f957c
Created December 30, 2016 13:27 — forked from chad3814/gist:2924672
deleting array items in javascript with forEach() and splice()
// This is from my comment here: http://wolfram.kriesing.de/blog/index.php/2008/javascript-remove-element-from-array/comment-page-2#comment-466561
/*
* How to delete items from an Array in JavaScript, an exhaustive guide
*/
// DON'T use the delete operator, it leaves a hole in the array:
var arr = [4, 5, 6];
delete arr[1]; // arr now: [4, undefined, 6]
@maximgatilin
maximgatilin / gist:8bdee110cb208fec5c5159f23044b646
Created January 22, 2017 08:29 — forked from realmyst/gist:1262561
Склонение числительных в javascript
function declOfNum(number, titles) {
cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
use:
declOfNum(count, ['найдена', 'найдено', 'найдены']);
@maximgatilin
maximgatilin / promises.js
Last active February 12, 2017 05:53
jquery promises #tags:promises
function getUserLocation() {
return $.ajax('https://www.example.com/location.json'); // note the `return`
}
function getCurrentWeather(userLocation) {
return $.ajax('https://www.example.com/weather' + userLocation + '.json');
}
getUserLocation().then(getCurrentWeather).then(function(data) {
// location data here
@maximgatilin
maximgatilin / app.js
Last active February 19, 2017 16:12
Express Simple Server #tags:express
'use strict';
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send("<h1>I love Treehouse!</h1>");
});
@maximgatilin
maximgatilin / app.js
Created February 19, 2017 16:12
Basic Express params #tags:express
'use strict';
var express = require('express'),
posts = require('./mock/posts.json');
var app = express();
app.get('/', function(req, res){
res.send("<h1>I am with!</h1>");
});
@maximgatilin
maximgatilin / jsonRepeat.xml
Created March 13, 2017 13:37
jsonRepeat.xml #tags:fiori
<List
headerText="{i18n>invoiceListTitle}"
class="sapUiResponsiveMargin"
width="auto"
items="{invoice>/Invoices}" >
<items>
<ObjectListItem
title="{invoice>Quantity} x {invoice>ProductName}"/>
</items>
</List>
@maximgatilin
maximgatilin / file.xml
Created March 13, 2017 13:43
Expression Binding #tags:fiori
<ObjectListItem
title="{invoice>Quantity} x {invoice>ProductName}"
number="{
parts: [{path: 'invoice>ExtendedPrice'}, {path: 'view>/currency'}],
type: 'sap.ui.model.type.Currency',
formatOptions: {
showMeasure: false
}
}"
numberUnit="{view>/currency}"