Skip to content

Instantly share code, notes, and snippets.

@guz-anton
guz-anton / sorter.js
Created May 21, 2017 20:15
sorter.js
const byAge = guys => guys.sort( (Jonny, Tonny) => Jonny.age - Tonny.age );
@guz-anton
guz-anton / add-markup-by-canvas.ts
Created June 24, 2017 19:51
The plugin to jsPDF to print in pdf DOM element.
/**
* AddMarkupByCanvas v1.0.0
*
* The plugin print to jsPDF library that uses html2canvas to print DOM node to pdf.
*/
// import html2canvas from 'html2canvas'; // from v0.5.0
declare const html2canvas: any;
const fitPageSize = (pdfObj, options) => {
@guz-anton
guz-anton / flatten.js
Created June 27, 2017 04:38
A set of method to flatten arrays
const makeFlat = (array) => {
return array.reduce((all, current) => {
return Array.isArray(current)
? all.concat(makeFlat(current))
: all.push(current) && all;
},[]);
};
expect(makeFlat([[1,2,[3]],4])).toEqual([1,2,3,4]);
@guz-anton
guz-anton / finder.js
Created January 6, 2018 19:13
Find coords
/**
* dCoords returns array of coors of dot C, where angle ABC is 90°.
*
* @param {Array} A - array of coords dot A [x,y]
* @param {Array} B - array of coords dot B [x,y]
* @param {Number} BC - distance between B and C
* @returns {Array}
*/
export const dCoords = (A = [], B = [], BC = 0) => {
const bShifted = [- A[0] + B[0], - A[1] + B[1]];
@guz-anton
guz-anton / install.sh
Last active May 11, 2018 14:53
Magento instalation
# mysql -uroot -p
# CREATE DATABASE `magento_local` CHARACTER SET utf8 COLLATE utf8_general_ci;
# GRANT ALL PRIVILEGES ON magento_local.* TO magento@localhost IDENTIFIED BY 'magentoPass';
# GRANT SELECT, INSERT, UPDATE, DELETE, \
# CREATE, DROP, REFERENCES, INDEX, ALTER, \
# CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, \
# CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, \
# EVENT, TRIGGER \
# ON `magento_local`.* \
const isPolindrome = str => {
let is = true;
const mediana = Math.floor(str.length / 2);
const rIndex = x => str.length - x - 1;
const iterate = (a,b) => Array.prototype.some.call(a,b);
const polindromCheck = (letter, index, string) => {
return (index > mediana)
|| (letter !== string[rIndex(index)])
&& !(is = false)
};
@guz-anton
guz-anton / to-curry-any.js
Last active October 30, 2018 16:07
Redusing arguments
const curry = (fn, ...initialArgs) => {
let value;
const fnx = (...curryArgs) => {
value = fn.apply(null, initialArgs.concat(curryArgs));
return fnx;
}
Object.defineProperty(fnx, 'valueOf', {value: () => value});
return fnx;
@guz-anton
guz-anton / template.phtml
Created July 10, 2018 16:59
Magento's Product custom attribute
<?php
echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($product, $product->getConfigGroupCpLabel(), 'config_group_cp_label');
echo $product->getData(ProductAttributesInterface::CONFIG_GROUP_CP_LABEL);
echo '<br>z: ';
echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($product, $product->getConfigGroupCpOrder(), 'config_group_cp_order');
echo $product->getData(ProductAttributesInterface::CONFIG_GROUP_CP_ORDER);
echo '<br>y: ';
echo $this->getProduct()->getAttributeText('config_group_cp_order');
echo $product->getAttributeText('config_group_cp_order');
echo '<br>x: ';
@guz-anton
guz-anton / bash.sh
Created September 11, 2018 19:23
Scrape images with wget
# Scrape images with wget
# https://davidwalsh.name/scrape-images-wget
# $1 = url
# Example: scrapeimages https://davidwalsh.name/
scrapeimages() {
wget -nd -H -p -A jpg,jpeg,png,gif -e robots=off $1
}
@guz-anton
guz-anton / example.phtml
Last active March 23, 2021 09:53
Instagram feed. Magento 2 + instafeed.js snippet.
<div data-role="instafeed" class="instafeed-container"></div>
<script type="text/x-magento-init">
{
"[data-role=instafeed]": {
"instafeed-loader": {
"userId": "{{userId}}", // https://stackoverflow.com/q/11796349
"accessToken": "{{accessToken}}" // https://www.instagram.com/developer/authentication/
}
}
}