add an external md file to a php page

… and, of course see it as html, with the same graphical appearance of any other web text.

A way can be use a very light javascript, md-block.js, di Lea Verou.

Then you can add a function to your php website, like the following:

<?php
/* to call a file Markdown from a given folder */

function scheda_md($file)
{
    global $yourwebsite;

    $file = basename($file);

    return '<md-block src="' .
           $yourwebsite .
           '/the-path/where-are-md-files/from-yourwebsite-root' .
           htmlspecialchars($file, ENT_QUOTES, 'UTF-8') .
           '"></md-block>';
}
?>

And in the page where you want to show that md file you can use this code:

<?= scheda_md('the-md-name.md') ?>



“enter” key in phpmyadmin

If, in show view (not editing a single item) of PhpMyAdmin (i.g. with Firefox), you have a strange behavior of enter key, that is if enter add a new row inside a column, instead of confirm modifications you made, you can try to modify absolute right click settings.
In this way: Run on sites with restrictions -> Don’t Allow

Now your PhpMyAdmin should work as expected.

copyq problems

In you have linux, flatpack installation of copyq can solve many possible problems, but it has also some disadvantage.

The best choice, then, is to install copyq according to its website:

Ubuntu and Debian users can add the official PPA:

sudo add-apt-repository ppa:hluk/copyq
sudo apt update && sudo apt install copyq

In same cases it could be not enough the above code. Then you can try with something like:

QT_QPA_PLATFORM=xcb copyq

You can set permanently in KDE menu with a config like in the below image

Fix a corrupt innodb

Today happened that mariadb worked almost correctly, but two wordpress db were incorrectly managed. Indeed I could modify a post, but I couldn’t add a new one.

In another PC I, luckily, had the good wp db (perfectlty working with its innodb). So, it was possible to fix this problem. With the following steps:

a) in the well working device dump (from a teminal) the working wp db:

mysqldump -u root -p --single-transaction --routines --triggers your-db-name > dump-yourdbname.sql

b) in the bad working device

  • activate (if not already active) mariadb
  • in a terminal: mysql -u root -p (of course you have to provide your mysql psw)
  • and then, within mysql, you have to delete the old, bad, db, and create a new one:
    • DROP DATABASE IF EXISTS yourdbname;
    • CREATE DATABASE yourdbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    • EXIT;
  • Now you have a new, good but empty db. You have now to import the content of it, with this code: mysql -u root -p yourdbname < dump-yourdbname.sql

Now all should work 🙂.

External markdown file in WordPress

If you want keep an external markdown file and include it in a WordPress page, you can follow these steps:

  • add a js file, such as md-block.js, in your js theme folder (typically /wp-content/themes/your-theme/js/ )
  • modify the functions.php file, in your root theme folder,. adding this code:
// per markdown BEGIN

function carica_md_block() {
    wp_enqueue_script(
        'md-block',
        get_stylesheet_directory_uri() . '/js/md-block.js',
        array(),
        null,
        true
    );
}
add_action('wp_enqueue_scripts', 'carica_md_block');

add_filter('script_loader_tag', function($tag, $handle, $src) {
    if ($handle === 'md-block') {
        return '<script type="module" src="' . esc_url($src) . '"></script>';
    }
    return $tag;
}, 10, 3);

function shortcode_scheda_md($atts) {
    $atts = shortcode_atts(array(
        'file' => ''
    ), $atts);

    $file = basename($atts['file']);

    if (empty($file) || pathinfo($file, PATHINFO_EXTENSION) !== 'md') {
        return '';
    }

    $url = content_url('/uploads/some-path/' . rawurlencode($file));

    return '<md-block src="' . esc_url($url) . '"></md-block>';
}
add_shortcode('scheda_md', 'shortcode_scheda_md');

// per markdown END
  • you can put your md files in the path above set: /uploads/some-path/ . Note that the folder some-path could be a symlinked one, from your local PC.
  • in the wordpress page when you want include a md file you can write,
    • using HTML (customized), [scheda_md file="the-name-of-the-file.md"],
    • or the code visualizaztion: something like[scheda_md]the-name-of-the-file.md[/scheda_md]
  • where that file, obviously, should be in /some-path/ folder.

mysql multiple tables rename

To rename many mysql/mariadb tables with a same prefix, you can uso this script (in a terminal)

mysql -u root -p -N -e " SELECT CONCAT('RENAME TABLE \', table_name, '\ TO \', REPLACE(table_name, 'oldprefix_', 'newprefix_'), '\;') FROM information_schema.tables WHERE table_schema = 'your-database' AND table_name LIKE 'oldprefix_%'; " > renamed.sql 

In this way will created the file renamed.sql (same tables, with different names), that you then can use to replace your database, with

mysql -u root -p yourdatabase < renamed.sql

If you have a wordpress database you have also to check options and meta tables, removing oldprefixes, with:

UPDATE oldprefix_options
SET option_name = REPLACE(option_name, 'oldprefix_', 'newprefix_')
WHERE option_name LIKE 'oldprefix\_%';

and

UPDATE abc_usermeta
SET meta_key = REPLACE(meta_key, 'oldprefix_', 'newprefix_')
WHERE meta_key LIKE 'oldprefix\_%';

And finally, you could check if there are any oldprefix, in options with

SELECT option_name FROM newprefix_options WHERE option_name LIKE 'oldprefix\_%';

same for meta:

SELECT meta_key FROM newprefix_usermeta WHERE meta_key LIKE 'oldprefix\_%';

Disable Caps Lock

It could happen that you inadvertently press and it turn out all the word you write are are UPPERCASE.
To avoid this, in Linux, you can

  • go to System Settings > Input Devices > Keyboard -> Key bindigs
  • in Key bindings -> Configure Keybord options -> Caps Lock behavior -> Caps Lock disabled.
  • and then, always in Configure Keybord options -> switching to another layout -> select both
    • Both Shifts together
    • Caps Lock.

In this way your Caps Lock will be usually disabled, but you can use it by pressing both the shift keys.

BUT…
If you have wayland and espanso the upper configuration can give problems.
So the simpler way is:

  • to disable (permanently) caps lock : Key bindings -> Configure Keybord options -> Caps Lock behavior -> Make Caps Lock an additional Ctrl

Innodb: pros and cons

If you have to sync different devices you could have many problems with Innodb engine.

But on the other hand, it has some advantages: is more modern than MyIsam, and support foreign keys.

A compromise can be have Innodb as engine, but all the tables in MyIsam.
You should in any way be careful with some files, as already explained, in particular ibdata1.

how get rid of Innodb

If you don’t need foreign kayes, you can get rid of Innodb in /etc/my.cnf, with these instructions (stop mariadb before, and restart after):

default-storage-engine=MyISAM