Skip to content

Instantly share code, notes, and snippets.

View falexandrou's full-sized avatar

Fotis Alexandrou falexandrou

View GitHub Profile
@falexandrou
falexandrou / stock_sales.sql
Created September 22, 2017 07:48
[WooCommerce] Get current values for a product's sales and stock quantity
SELECT
p.post_title AS "Product title",
t1.meta_value AS "Items Sold",
t2.meta_value AS "Current Stock Quantity",
NOW() AS "Current Date"
FROM
wp_posts p
LEFT JOIN (SELECT meta_value, post_id FROM wp_postmeta WHERE meta_key='total_sales') t1 ON t1.post_id=p.ID
LEFT JOIN (SELECT meta_value, post_id FROM wp_postmeta WHERE meta_key='_stock') t2 ON t2.post_id=p.ID
WHERE p.ID=102176;
@falexandrou
falexandrou / jetpack.php
Created September 18, 2017 23:55
Reduce Database load caused by Jetpack
<?php
// Jetpack custom cron schedule to reduce cron load
// Add it in your site-speicic plugin or the theme's functions.php
add_filter( 'jetpack_sync_incremental_sync_interval', function() { return 'hourly'; } );
add_filter( 'jetpack_sync_full_sync_interval', function() { return 'daily'; } );
add_filter( 'jetpack_sync_listener_should_load', '__return_false' );
add_filter( 'jetpack_sync_sender_should_load', '__return_false' );
add_filter( 'pre_option_jetpack_sync_settings_sync_via_cron', '__return_zero' );
@falexandrou
falexandrou / gc.php
Last active April 5, 2018 14:19
PHP Force Garbage Collection
<?php
# If you've exceeded the number of inodes on your server,
# you could as well run `php -a` so you get the interactive shell running
# and then copy & paste the following lines into
# Make sure we're using files as a session save handler
ini_set('session.save_handler', 'files');
ini_set("session.save_path", "/var/lib/php/session");
# The probability of performing garbage cleanup is the ratio:
@falexandrou
falexandrou / view-pdf.js
Last active August 29, 2015 13:57
Display PDF files inline
/**
* When browser supports inline pdfs
* There is no need to append a large jquery plugin that displays them inline.
*
* You can actually use an iframe (and style it appropriately)
* or a link whenever inline PDF viewing is not supported
*
* This function is fairly simple and it's only for demo purposes
*/
function appendPdf(id, url) {
@falexandrou
falexandrou / sendfile.sh
Last active October 16, 2019 06:34
Turn Sendfile to "off" for vagrant boxes
# A VirtualBox bug forces vagrant to serve
# corrupt files via Apache or nginx
# The solution to that would be to turn off
# the SendFile option in apache or nginx
#
# If you use apache as your main web server
# add this directive in your httpd.conf (or apache.conf)
# configuration file name may vary in various systems
#
EnableSendfile off
@falexandrou
falexandrou / gist:5529114
Last active December 17, 2015 01:29
Locked out of kloxo
# If you've been locked out of kloxo and you've tried everything google suggested for you
# then most likely it's a database problem. Please try the following at your own will
# and hit cmd+y (or ctrl+w) if you don't know the impact this will have on your system.
# Disclaimer: if you break your server it won't be my fault. you've been warned
#
# The "recommended" way to login to your kloxo installation is the following:
# as described in http://wiki.lxcenter.org/Change+Password+via+SSH
[root@server]$ sh /script/resetpassword master {newpassword}
# if this doesn't work try the following:
@falexandrou
falexandrou / .htaccess
Created November 14, 2012 21:00
Rewrite to a separate Wordpress installation dir
# When installing wordpress on a separate dir inside your $_SERVER['DOCUMENT_ROOT']
# you may need to create a rewrite rule, otherwise wordpress will start complaining...
#
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress-installation-dir/wordpress/$1 [L]