Skip to content

Instantly share code, notes, and snippets.

@esedic
esedic / oc_mods.js
Created April 25, 2024 17:38
JavaScript for triggering Clear & Refresh modifications buttons
// 1. Clear mods
const chkBoxes = document.querySelectorAll('#tab-general .table tbody tr td:first-child input[type="checkbox"]');
chkBoxes.forEach(
chkBox => {
chkBox.checked = true;
}
);
const clrBtn = document.querySelector('.page-header > .container-fluid > .pull-right > a[data-original-title="Clear"]');
clrBtn.click();
@esedic
esedic / yt_lightbox.html
Created April 25, 2024 08:40
Lightbox for 'Panel Slider', 'Slideshow' and 'Overlay Slider' Yootheme Pro Element
<!-- Yootheme Pro sliders with lightbox -->
<!--
1. For the 'Overlay Slider' or 'Panel Slider' Element:
-Add Link to the Image which has to be shown in the Lightbox
-Add element Attribute:
uk-lightbox="toggle: .uk-slider-items a"
2. For the 'SlideShow' Element:
-Add Link to the Image which has to be shown in the Lightbox
@esedic
esedic / gist:8f50ddfb2497961434bf891ac2c6395d
Created April 17, 2024 12:29 — forked from vdrover/gist:ebdbf65f5f4e9ee5545255e9c36bd422
Wordpress - Backdate scheduled posts
// Adds a meta box to the post editing screen for changing the post's publication
// date and time after it has initially been published.
// Only visible to administrators.
// Place in functions.php file.
function cdap_add_meta_box() {
// Check if the current user is an administrator
if (current_user_can('administrator')) {
add_meta_box(
'cdap_meta_box', // ID of the meta box
@esedic
esedic / removeel.js
Created March 8, 2024 18:19
Find and remove DOM elements with JavaScript
/**
* Find all the elements, that match any of the classes that are specified in the array
* and remove all the matching elements from the DOM
*/
// Step 1: Define the array of class names
const classesToRemove = ['elem1', 'elem2'];
// Step 2: Create the selector string
// This will create a string like ".class1,.class2,.class3"
@esedic
esedic / wpcli.txt
Created March 7, 2024 12:23
Install WP-CLI and check if WP-CRON works
1. Download wp-cli.phar using wget or curl:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
2. Check if it works:
php wp-cli.phar --info
3. To be able to type just wp, instead of php wp-cli.phar, you need to make the file executable and move it to somewhere in your PATH. For example:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
@esedic
esedic / getYear.html
Last active March 3, 2024 18:17
Insert current year in HTML with JavaSCript
<!-- v1 -->
<p>&copy; <script>
document.currentScript.insertAdjacentHTML('afterend', '<time datetime="' + new Date().toJSON() + '">' + new Intl.DateTimeFormat(document.documentElement.lang, {
year: 'numeric'
}).format() + '</time>');
</script> All rights reserved.</p>
<!-- v2 -->
<p>&copy; <script>document.write(new Date().getFullYear());</script> All rights reserved</p>
@esedic
esedic / sameday.sql
Created February 29, 2024 11:08
Select items/articles that were created on the same day
SELECT * FROM mytable WHERE MONTH(created) = MONTH(CURDATE()) AND DAY(created) = DAY(CURDATE()));
@esedic
esedic / map.js
Created February 9, 2024 11:01
Javascirpt if/else vs switch vs object mapping
// Scenario, wher we need to determine a discount based on a customer's loyalty level
// 1. Traditional if-else approach:
function calculateDiscount(loyaltyLevel) {
console.time('if else time');
if (loyaltyLevel === 'GOLD') {
applyGoldDiscount();
} else if (loyaltyLevel === 'SILVER') {
applySilverDiscount();
} else if (loyaltyLevel === 'BRONZE') {
@esedic
esedic / mysqlpw.txt
Created February 7, 2024 13:30
Change MySQL root password
sudo mysql
// get MySQL user accounts
SELECT user,authentication_string,plugin,host FROM mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;
// you should see the change
@esedic
esedic / detect_touch.js
Created September 6, 2019 11:34
Various JavaScript methods for detecting touch/mobile devices
// Method 1
var isTouchDevice =
(('ontouchstart' in window) ||
(navigator.MaxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0));
if(!isTouchDevice){
console.log('is not touch');
}else{
console.log('is touch');
}