Skip to content

Instantly share code, notes, and snippets.

View AndreiTelteu's full-sized avatar

Andrei Telteu AndreiTelteu

View GitHub Profile

In your theme's functions.php file, or in a custom plugin insert this code:

<?php

add_filter( 'rank_math/frontend/title', function( $title ) {
    $translatepress_translation = custom_get_translatepress_translation($title);
    if ($translatepress_translation != null) {
        $title = $translatepress_translation;
@AndreiTelteu
AndreiTelteu / react js laravel mix loading screen with progressbar .blade.php
Last active July 14, 2021 12:24
Saves the laravel mix versioned url in localstorage and compares it with current version url in order to activate browser cache if version is the same
<div id="app">
{{-- this loader gets automatically replaced by the react app after loading --}}
<div style="background:#1C9EF2; width:100vw; height:100vh;">
<div id="loading" style="position: absolute; top:46%; left:50%; transform: translateX(-50%) translateY(-50%); text-align: center;">
<img src="/images/logo-white.png"><br>
<div style="display: inline-block; width: 80px; height: 80px; border-radius: 100%; background: white; display: flex; margin: auto; align-items: center; justify-content: center; margin-top: 20px;">
<img src="/images/loader.svg" style="width: 50px; height: 50px; margin-bottom: 10px;">
</div>
@AndreiTelteu
AndreiTelteu / PHP image cut split in parts stack on top .php
Created July 19, 2021 21:59
With this script you can split a super long image in how many parts you want, and stack them. Like a long ecg chart: https://i.imgur.com/ZlwMNRz.png
<?php
$source_path = 'super-long-image.png';
$destination_path = 'new-image.png';
$parts = 3; // in how many parts you want to split the image
$source = imagecreatefrompng($source_path);
$width = imagesx($source);
$height = imagesy($source);
$newWidth = $width / $parts;
$newHeight = $height * $parts;
@AndreiTelteu
AndreiTelteu / Docker exec yarn commands from fnm .md
Created July 27, 2021 10:50
If you have fnm inside a docker container and you want to run a node/npm/yarn command using a specific version of node, fron the host, using docker exec

Example of how to run yarn run prod using yarn package from fnm:

docker exec -i -w /home/of/your/project docker-container-name bash -c "/root/.fnm/fnm exec --using 12 yarn run production"
@AndreiTelteu
AndreiTelteu / WooCommerce make cart session functional inside an iframe .md
Last active February 20, 2024 17:40
WooCommerce make cart session functional inside an iframe .md

If you need your woocommerce cart functions to work while inside an iframe, you have to add this code in your theme's functions file (or plugin's function file):

function iframe_cookies_samesite_filter_wc_session($enabled, $name, $value, $expire, $secure)
{
    if ( ! headers_sent() ) {
        setcookie($name, $value, [
            'secure'   => true,
            'httponly' => apply_filters( 'woocommerce_cookie_httponly', $httponly, $name, $value, $expire, $secure ),
useIpInProxyHeader 2
accessControl {
allow ALL, 173.245.48.0/20T, 103.21.244.0/22T, 103.22.200.0/22T, 103.31.4.0/22T, 141.101.64.0/18T, 108.162.192.0/18T, 190.93.240.0/20T, 188.114.96.0/20T, 197.234.240.0/22T, 198.41.128.0/17T, 162.158.0.0/15T, 104.16.0.0/13T, 104.24.0.0/14T, 172.64.0.0/13T, 131.0.72.0/22T
}
@AndreiTelteu
AndreiTelteu / Reboot server is the average load is greater than x .md
Last active November 5, 2021 11:12
Bash script to restart the server if the load is greater than x

Put the following script in a .sh file, for example in /root/reboot-load.sh.

#!/usr/bin/bash
LOAD=`uptime |awk '{print $NF}'`
LOADCOMP=`echo "($LOAD * 100) / 1" | bc`
echo "Load is: $LOAD"
if [[ $LOADCOMP -ge 2000 ]]
then echo "Greater than 20 ! Reboot !"
fi

If you use a ecosystem file, add the following lines to your app:

      interpreter: '/home/forge/.fnm/fnm',
      interpreter_args: 'exec --using=14 node',

14 is the node version. You can be more specific like --using=12.22.4

Example configuration:

@AndreiTelteu
AndreiTelteu / How to install vs code server and setup supervisor with fnm .md
Last active February 6, 2022 15:44
Install vs code-server with fnm and yarn, and keep it runing always with supervisor (on ubuntu)

Install build requirements (python3 and build essential)

sudo apt-get install -y build-essential pkg-config python3

Install fnm to manage multiple nodejs versions (uninstall nodejs or nvm if you have it installed)

curl -fsSL https://fnm.vercel.app/install | bash
@AndreiTelteu
AndreiTelteu / aaPanel howto install latest swoole version .md
Last active November 28, 2021 18:23
How to install swoole v4.8.2 on aapanel with php 8.0

As a root user, download this script and put it in /www/server/panel/install/modified-swoole-install.sh

cd /www/server/panel/install/
wget https://gist.githubusercontent.com/AndreiTelteu/c92ef2414cc97e2c76f539cc988652d0/raw/abf316cd872ad75be34ce5572bb7ff3dac6819ce/modified-swoole-install.sh
chmod +x modified-swoole-install.sh
bash modified-swoole-install.sh install 80