How Email Took Over Our Lives

Luca Sartoni

When you recognize a task as complete, your brain releases dopamine, which makes you feel good and makes you want to repeat the behavior again to feel more pleasure.

Eye-opening article by Jocelyn K. Glei on how email took over our lives. Quick insightful read on, don’t miss it!

View original post

Posted in Uncategorized | Leave a comment

New path for MySQL query log on OSX

Sometimes during development I need to see what SQL queries are executed and listing them in is maybe the most convenient solution on OSX.

To see queries in Console

mysqld query log OSX

I just created /etc/mysql/my.cnf with:

general_log = 1
# general_log_file = /usr/local/mysql/data/mysqld.query.log
general_log_file = /var/log/mysql/mysqld.query.log

slow_query_log = 1
long_query_time = 1 # second
# slow_query_log_file = /usr/local/mysql/data/mysqld.slow.log
slow_query_log_file = /var/log/mysql/mysqld.slow.log
log_queries_not_using_indexes = 0

MySQL server needs own permissions on the parent log dir so:

sudo mkdir /var/log/mysql
sudo chown -R _mysql:_mysql /var/log/mysql

Last step is server restart.

sudo launchctl unload -F /Library/LaunchDaemons/
sudo launchctl load -F /Library/LaunchDaemons/

On a Linux machine I use multitail as an alternative.

Posted in log, osx, Uncategorized | Tagged , , , , | Leave a comment

WooCommerce check if product in cart is in stock

Check if product in cart is in stock:

foreach (WC()->cart->cart_contents as $item) {
    $product_id = isset($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
    $product = new \WC_Product_Factory();
    $product = $product->get_product($product_id);
    if ($item['quantity'] > $product->get_stock_quantity()) {
        $inStock = false;
Posted in Uncategorized, woocommerce | Tagged , , , | Leave a comment

WordPress custom search for custom post type

After creating a custom post type for an Inventory plugin the client needed also customized search for the columns.

Custom search for custom post type

First the pre_get_posts looked as a good candidate for hooking, but ended up with filtering via posts_clauses_request

add_filter('posts_clauses_request', 'customSearchClause');
function customSearchClause($query)
    global $wp_query;

    if (!is_search()) {
        return $query;

    $term = $wp_query->query['s'];
    $query['join'] = 'INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)';
    $query['where'] = "AND wp_posts.post_type = '$this->post_type'
    AND (
        (wp_posts.post_title LIKE '%{$term}%')
        OR (wp_postmeta.meta_key = 'product' AND wp_postmeta.meta_value LIKE '%{$term}%')
        OR (wp_postmeta.meta_key = 'product_code' AND wp_postmeta.meta_value LIKE '%{$term}%')

    return $query;

Posted in Uncategorized, wordpress | Tagged , , | Leave a comment

Custom PHP errors with int value

I needed custom PHP errors set via .htaccess

<IfModule mod_php5.c>
php_value error_reporting 674

According to docs about errors predefined constants I had to add the values of errors I wanted to see.
Inspiration for the number came from comment.

So I ran it via CLI (fastest possible way I think)


and finally got the int value I needed.

Posted in php, Uncategorized | Tagged , | Leave a comment

Turning XSD into documentation file

This XSD stuff is not for me, f*cking unreadable:/ Thanks god there is a stylesheet that makes it prettier, like a documentation.
First download it due browser cross domain restriction, so you can avoid (fastest solution for me now)

Unsafe attempt to load URL from frame with URL http://localhost/kovoinox/temp/stock.xsd. Domains, protocols and ports must match.

After download put it next to the XSD file and insert the following line as the 2nd row in the XSD:

<?xml version="1.0" encoding="Windows-1250"?>
<?xml-stylesheet type="text/xsl" href="xsd.xsl"?>
<xsd:schema xmlns:xsd=""
 ... the rest of the XSD ...

After opening the XSD in the browser you get a much nicer interpretation.


Solution from

Posted in bestpractice, Uncategorized | Tagged , , | Leave a comment

Solving No matching global declaration available for the validation root.

Had to create a custom XML for Pohoda accounting software, but hit some errors so I decided to make a PHPUnit test for validating it against its XML schema definition (XSD) with PHPs DOMDocument::schemaValidate

/** @test */
public function validateStockXml()
$xml = new \DOMDocument();

$isValid = $xml->schemaValidate('');

Stuck with the following error for a couple of hours😦

Element ‘{}dataPack’: No matching global declaration available for the validation root.

After a lot of trial and error decided to google more and more I finally found the solution at

Changing the schema URL to instead using solved the problem.

So easy, huh🙂 Always learning.

Posted in php, Uncategorized | Tagged , , , , | Leave a comment