Skip to content

Instantly share code, notes, and snippets.

View gr1zix's full-sized avatar
🎯
Focusing

Grizix gr1zix

🎯
Focusing
View GitHub Profile
@gr1zix
gr1zix / function.php
Created July 25, 2024 18:53
Lazyload images for content in WordPress
<?php
add_filter('the_content', 'add_loading_attribute_to_content_images_for_lazyload');
function add_loading_attribute_to_content_images_for_lazyload($content) {
// Find all images in the content
preg_match_all('/<img[^>]+>/i', $content, $images);
if (!empty($images[0])) {
foreach ($images[0] as $index => $image) {
// Check if image already has loading attribute
if (str_contains($image, 'loading=')) {
@gr1zix
gr1zix / solution.md
Created July 14, 2024 15:59
Way to regain access to Mysql in Docker (Laradock) when database was change from Mysql 8 to 9

Way to regain access to mysql in Docker (Laradock)

It's short tutorial for you if your database was created in Mysql 8, and now it upgraded to Mysql 9 where native password plugin was removed.

How it happened:

I was using Mysql 8. But today I noticed that my Docker has grown too much, so I decided to clean up the outdated files. But I accidentally deleted the built images.

After that, I've re-build my Laradock stack and noticed that the Mysql container started to give an error, as it turned out it was an error about the unknown variable mysql_native_password.

I tried different approaches that I used to fix it before and nothing helped. Later, I searched a ton of material, but nothing really worked.

@gr1zix
gr1zix / index.js
Last active July 7, 2024 19:34
Stop all active Ajax requests in jQuery + Prevent Wordpress request abuse
$.xhrPool = {
pool: [],
abortAll: function() {
$.each(this.pool, function(idx, jqXHR) {
jqXHR.abort();
});
this.pool = [];
},
add: function(jqXHR) {
this.pool.push(jqXHR);
@gr1zix
gr1zix / MyToken.sol
Created June 8, 2024 19:50
Solidity token contract example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount)
external
returns (bool);
function allowance(address owner, address spender)
@gr1zix
gr1zix / MyNFT.sol
Created June 8, 2024 19:31
NFT Smart-contract example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IERC165 {
function supportsInterface(bytes4 interfaceID)
external
view
returns (bool);
}
@gr1zix
gr1zix / gutenberg-button.js
Created June 2, 2024 11:54 — forked from junaidbhura/gutenberg-button.js
WordPress Gutenberg open button in a new window
/**
* Button.
*/
import wp from 'wp';
const { __ } = wp.i18n;
const { addFilter } = wp.hooks;
const { createHigherOrderComponent } = wp.compose;
const { Fragment, cloneElement } = wp.element;
@gr1zix
gr1zix / function.php
Created April 16, 2024 17:04 — forked from mattclements/function.php
Wordpress Disable Comments (add to function.php)
<?php
add_action('admin_init', function () {
// Redirect any user trying to access comments page
global $pagenow;
if ($pagenow === 'edit-comments.php') {
wp_redirect(admin_url());
exit;
}
@gr1zix
gr1zix / ba.sh
Created January 8, 2024 20:27 — forked from bvolpato/ba.sh
Install Chrome Driver with Xvfb (Ubuntu Server)
#!/bin/bash
# Chrome Repo
sudo apt-get install fonts-liberation xdg-utils libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt-get update
# Download
@gr1zix
gr1zix / robots.txt
Created October 30, 2023 15:02
Wordpress robots.txt basic
User-agent: *
Disallow: /cgi-bin
Disallow: /?
Disallow: /admin/
Disallow: /login/
Disallow: /wp-
Disallow: *?p=
Disallow: *?s=
Disallow: *&s=
Disallow: /search/
@gr1zix
gr1zix / index.html
Created September 12, 2021 21:08
Async custom or external scripts & styles loading which need to be used after website interact (Best way to load big files like lottie scenes on Base64 stored in json which have size ~10M)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
// Async custom or external scrips & styles loading
(function() {
var lazyLoaded = false;