Skip to content

Instantly share code, notes, and snippets.

@6ui11em
6ui11em / sibilings.js
Created September 4, 2018 20:17
Javascript get siblings og an element #javascript #vanilla #sibilings
var item = document.querySelector('#find-me');
var prev = item.previousElementSibling;
var next = item.nextElementSibling;
@6ui11em
6ui11em / copyright.phtml
Last active December 29, 2022 22:16
Magento 2: Dynamic copyright year in footer #magento2 #copyright #year
@6ui11em
6ui11em / remove-top_links.xml
Created August 28, 2018 10:48
Magento 2: Remove top links #magento2 #layout #toplinks #remove
@6ui11em
6ui11em / console_dir.js
Created July 31, 2018 21:30
Javascript console log element DOM #javascript #log #console
console.dir(document.body);
@6ui11em
6ui11em / customer_logged_in.php
Created July 17, 2018 14:04
Magento 2: Check if customer is logged in #magento2 #cache #customer
// To avoid problems with full page cache
// https://github.com/magento/magento2/blob/4d2609343a950e9ee6b50cc4444469d50d82b139/app/code/Magento/Customer/Block/Account/Customer.php#L52
public function customerLoggedIn()
{
return (bool)$this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
}
@6ui11em
6ui11em / print_collection_sql.php
Created July 4, 2018 09:56
Magento 2 print collection SQL #magento2 #sql #debug
$collection->load();
// the following statements are equivalent
$collection->getSelect()->assemble();
$collection->getSelect()->__toString();
echo $collection->getSelect();
@6ui11em
6ui11em / is_out_viewport.js
Created June 18, 2018 20:37
Javascritp check if element is outside the viewport #javascript #js #ouside #viewport
/*!
* Check if an element is out of the viewport
* (c) 2018 Chris Ferdinandi, MIT License, https://gomakethings.com
* @param {Node} elem The element to check
* @return {Object} A set of booleans for each side of the element
*/
var isOutOfViewport = function (elem) {
// Get element's bounding
var bounding = elem.getBoundingClientRect();
@6ui11em
6ui11em / shuffle_array.js
Created June 14, 2018 09:08
Javascript shuffle array. #javascript #js #shuffle #array
/**
* Randomly shuffle an array
* https://stackoverflow.com/a/2450976/1293256
* @param {Array} array The array to shuffle
* @return {String} The first item in the shuffled array
*/
var shuffle = function (array) {
var currentIndex = array.length;
var temporaryValue, randomIndex;
@6ui11em
6ui11em / allow_invalid_dates.sql
Created May 29, 2018 14:28
MySQL allow invalid dates. #mysql #date
SET SQL_MODE='ALLOW_INVALID_DATES';
@6ui11em
6ui11em / force_unlock_tables.sql
Created May 29, 2018 11:39
MySQL force unlock tables. #mysql
mysql -u your_user -p
mysql> show open tables where in_use>0;
mysql> show processlist;
mysql> kill put_process_id_here;