Skip to content

Instantly share code, notes, and snippets.

@lilumi
lilumi / .htaccess
Created December 6, 2023 13:25
Apache, WP, get file from uploads from production site if doesn't exists on local env
## get file from production if doesn't exist on dev environment
RewriteCond %{HTTP_HOST} =site1.xyz
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} .(gif|jpe?g|png|bmp|tiff|xcf|psd|ico|svg|pdf|mp4)$ [NC]
RewriteRule ^(.*)$ https://www.productionsite.com/$1?from=dev [R=301,L]
@lilumi
lilumi / query-hook.php
Last active May 5, 2023 16:44
Remove counting author posts on users.php
<?php
function interceptQuery( $query ) {
if ( $GLOBALS['pagenow'] === 'users.php' && strpos( $query, 'SELECT post_author, COUNT(*) FROM' ) === 0 ) {
echo '<h3>count_many_users_posts disabled for performance reasons</h3>';
return false;
}
return $query;
}
@lilumi
lilumi / hooks.php
Created April 8, 2023 14:42
Disable WPML String Translations for Gutenberg Blocks
<?php
/*
WPML checks for gutenberg like this:
\WPML_Page_Builders_Defined->has()
```
if ( 'gutenberg' === $page_builder ) {
if ( version_compare( $wp_version, '5.0-beta1', '>=' ) ) {
return true;
}
}
@lilumi
lilumi / deffered-styles.html
Last active September 29, 2021 19:21
Load deffered styles using js
<noscript id="deferred-styles">
<link rel="stylesheet" href="/assets/styles/slick/slick-all.min.css" type="text/css" media="all" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&display=swap&subset=cyrillic,cyrillic-ext,latin-ext" rel="stylesheet">
</noscript>
<script>
var loadDeferredStyles = function() {
var addStylesNode = document.getElementById("deferred-styles");
var replacement = document.createElement("div");
replacement.innerHTML = addStylesNode.textContent;
document.body.appendChild(replacement)
@lilumi
lilumi / mysql-docker.sh
Created April 3, 2021 11:20 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
(function() {
var throttle = function(type, name, obj) {
obj = obj || window;
var running = false;
var func = function() {
if (running) { return; }
running = true;
requestAnimationFrame(function() {
obj.dispatchEvent(new CustomEvent(name));
running = false;
@lilumi
lilumi / lilumi-ahk.ahk
Last active June 12, 2020 13:59
my Autohotkey config
;Make Alt to work as Ctrl (for similar hotkeys as on Mac)
$!a::Send, ^a
$!b::Send, ^b
$!c::Send, ^c
$!+c::Send, ^+c
$!d::Send, ^d
$!f::Send, ^f
$!g::Send, ^g
@lilumi
lilumi / measue-php-code.php
Created April 4, 2020 10:58
measure php code
<?php
$start = microtime(true);
$cycles = 0;
$elapsed = 0;
do {
$loops = 1000;
$begin = microtime(true);
do {
// Тестируемая операция
@lilumi
lilumi / viewport-el.js
Created February 23, 2020 17:35
Check if element is in a viewport
/*
No jQuery necessary.
Thanks to Dan's StackOverflow answer for this:
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
*/
function isOneHundredPercentOfElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
@lilumi
lilumi / scroll.js
Created February 19, 2020 21:45
Scroll arrow hides on scroll (optimized for passive listeners)
//scroll arrow hides on scroll
function hideOnScroll() {
var scroll_el = document.getElementById('scroll');
if ( document.getElementById('app').scrollTop > 20 ) {
scroll_el.style.display = "none";
} else {
scroll_el.style.display = "block";
}
}