Skip to content

Instantly share code, notes, and snippets.

View Vitaliy-Lazarev's full-sized avatar

Lazariev Vitaliy Vitaliy-Lazarev

View GitHub Profile
@josephrocca
josephrocca / escapeUnicode.js
Created June 18, 2020 11:18
Replace all Unicode characters with escape codes (JavaScript function)
// This function matches all non-ASCII characters after splitting the string in a "unicode-safe" way (using `[...str]`).
// It then splits each unicode character up into its code-points, and gets the escape code for each, and then joins all
// all the ASCII characters and Unicode escapes into one string.
function escapeUnicode(str) {
return [...str].map(c => /^[\x00-\x7F]$/.test(c) ? c : c.split("").map(a => "\\u" + a.charCodeAt().toString(16).padStart(4, "0")).join("")).join("");
}
// Based on discussion in this thread: https://gist.github.com/mathiasbynens/1243213
@alecarg
alecarg / m2-mixin-uicomponent.js
Last active February 26, 2021 09:17
Magento 2 mixins (extend/override for UIComponents)
/*
* Magento 2 mixins for js files that return an UIComponent
* (based on https://alanstorm.com/the-curious-case-of-magento-2-mixins/)
* (for files that return an object literal: https://gist.github.com/alecarg/71a28b6d0ce2c3b7073481cc52fe1e23)
* (for files that return a function: )
*/
define([
], function () {
'use strict';
@alecarg
alecarg / m2-mixin-object-literal.js
Last active July 28, 2021 09:18
Magento 2 mixins (extend/override for object literals)
/*
* Magento 2 mixins for js files that return an object literal
* (based on https://alanstorm.com/the-curious-case-of-magento-2-mixins/)
* (for files that return an UIComponent: https://gist.github.com/alecarg/ed0516132e9c8a31c66f13fbccd292cf)
* (for files that return a function: )
*/
define([
'mage/utils/wrapper'
], function (wrapper) {
@firestar300
firestar300 / nextAll.js
Created January 15, 2019 08:50
nextAll method with Vanilla JS
export const nextAll = element => {
const nextElements = []
let nextElement = element
while(nextElement.nextElementSibling) {
nextElements.push(nextElement.nextElementSibling)
nextElement = nextElement.nextElementSibling
}
return nextElements
@6ui11em
6ui11em / copyright.phtml
Last active December 29, 2022 22:16
Magento 2: Dynamic copyright year in footer #magento2 #copyright #year
@dannygsmith
dannygsmith / valet-plus-destroy
Last active July 18, 2023 09:07
Remove valet-plus - reboot required
#!/usr/bin/env bash
#styles
VP_NONE='\033[00m'
VP_RED='\033[01;31m'
VP_GREEN='\033[01;32m'
VP_YELLOW='\033[01;33m'
VP_PURPLE='\033[01;35m'
VP_CYAN='\033[01;36m'
VP_WHITE='\033[01;37m'
@ethyde
ethyde / debounce.js
Created November 1, 2016 15:31
JS Native debounce function
// from : http://qnimate.com/javascript-limit-function-call-rate/
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this,
args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
@Trshant
Trshant / print js
Created March 22, 2016 08:30
Detecting Print Requests with JavaScript
(function() {
var beforePrint = function() {
console.log('Functionality to run before printing.');
};
var afterPrint = function() {
console.log('Functionality to run after printing');
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
@jkubacki
jkubacki / gist:e2dd904bd648b0bd4554
Created January 21, 2015 18:47
Mac uninstall elasticsearch
#!/usr/bin/env sh
# checks to see if running
launchctl list | grep elasticsearch
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
launchctl remove homebrew.mxcl.elasticsearch
pkill -f elasticsearch
@branneman
branneman / call-apply-bind-proxy.js
Last active February 22, 2024 21:06
JavaScript call() vs apply() vs bind() vs $.proxy()
var fn = function(arg1, arg2) {
var str = '<p>aap ' + this.noot + ' ' + arg1 + ' ' + arg2 + '</p>';
document.body.innerHTML += str;
};
var context = {
'noot': 'noot'
};
var args = ['mies', 'wim'];
// Calls a function with a given 'this' value and arguments provided individually.