Skip to content

Instantly share code, notes, and snippets.

View gukandrew's full-sized avatar
🇺🇦

gukandrew

🇺🇦
View GitHub Profile
@gukandrew
gukandrew / easing.js
Created May 22, 2018 11:44 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
easeInQuad: function (t) { return t*t },
// decelerating to zero velocity
/*
Create a Mask for an email address using ES6 syntax
Could be used for confirmation of email address or preventing to public expose of address
Author: Andrew Guk https://gist.github.com/gukandrew
*/
function emailMask(email, mask = '*') {
let masked = '';
let prev;
@gukandrew
gukandrew / batch-rename-replace-string.sh
Created June 14, 2019 12:49
Shell Batch rename files using string replacement
for file in *string-to-replace*; do
newname=$(echo $file | sed "s/string-to-replace//");
mv $file $newname;
done;
@gukandrew
gukandrew / pure_es6_reject.js
Last active June 22, 2019 09:34
Pure JS ES6 realization of lodash reject() method. Filter iterable object by condition object (like sql where)
function filterWhere(inputObject, conditions = {}) {
return Object.values(inputObject).filter((r) => {
return !(Object.keys(conditions).every((v) => {
return String(r[v]) === String(conditions[v])
}))
})
}
const data = {
@gukandrew
gukandrew / smoothScrollAfterRender.js
Last active July 17, 2019 13:37
Smooth scrollToElement after browser render
# when pass id, mean click action on some link, scroll and replace hash in url
# when no id, gets element id to scroll from url hash
export const scrollToElementAfterBrowserRender = (id) => {
if (!window.requestAnimationFrame) {
return;
}
window.requestAnimationFrame(() => {
const url = new URL(document.location.href);
@gukandrew
gukandrew / pure_es6_parse_search_to_object.js
Created July 22, 2019 09:46
Parse url search query to js object (es6)
const parseSearchToObject = (urlSearch) => {
const fromPairs = (pairs) => pairs.reduce((cache, pair) => {
cache[pair[0]] = pair[1];
return cache;
}, {});
return fromPairs(urlSearch.replace('?', '').split('&').map((v) => v.split('=')));
};
// create a bookmark and use this code as the URL, you can now toggle the css on/off
// thanks+credit: https://dev.to/gajus/my-favorite-css-hack-32g3
javascript: (function() {
var styleEl = document.getElementById('css-layout-hack');
if (styleEl) {
styleEl.remove();
return;
}
styleEl = document.createElement('style');
styleEl.id = 'css-layout-hack';
@gukandrew
gukandrew / magento2_resave_all_products.php
Last active November 12, 2019 16:03
Force resave all products for store Magento 2 php script
<?php
use Magento\Framework\App\Bootstrap;
include 'app/bootstrap.php';
// config
$pageSize = 100;
// config end
@gukandrew
gukandrew / magento2_resave_all_products_with_custom_options.php
Created November 12, 2019 16:04
Force resave all products with custom options for store Magento 2 php script
<?php
use Magento\Framework\App\Bootstrap;
include 'app/bootstrap.php';
// config
$pageSize = 100;
// config end
@gukandrew
gukandrew / magento_quote_selected_custom_option_value.php
Created March 3, 2020 16:20
Get selected values of custom options from Magento2 Quote
<?php
$quoteId = 1;
$ObjectManager = \Magento\Framework\App\ObjectManager::getInstance();
$quoteCollectionFactory = $ObjectManager->create('\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory');
$QuoteRepository = $ObjectManager->create('\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory');
$quote = $quoteCollectionFactory->create()
->addFieldToFilter('quote_id', $quoteId)
->getFirstItem();