Run command on Ubuntu startup as superuser

vi /etc/rc.local

Flush Redis cache

redis-cli flushall

Joomla check if admin logged-in

<?php
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..' ));
 
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
 
$mainframe =& JFactory::getApplication('administrator');
$mainframe->initialise();
 
$app =& JFactory::getApplication();
$user =& JFactory::getUser();
 
if($app->isAdmin() && !$user->id) {
header('Location: /administrator');
exit();
}
?>

Dig to query specific dns server

dig mydomain.com @ns.myserver.com

Updating custom db table in WordPress

function my_function() {
global $wpdb;
$wpdb->update('wp_my_appointments', array(
                            'title' => 'Msc',
                            'msg' => 'Message'
                            ),array(id => 3));
}

Inserting in custom db table in WordPress

function my_function() {
global $wpdb;
$wpdb->insert('wp_my_appointments', array(
                            'title' => 'Mr',
                            'msg' => 'Message'
                            ),array(
                            '%s',
                            '%s'));
}

Selecting from db custom table in WordPress

function my_function() {
global $wpdb;
$appointments = $wpdb->get_results("SELECT * FROM wp_my_appointments;");
echo '<pre>';
print_r($appointments);
}

Sending email in WordPress

$to = 'your@emailaddress.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
 
wp_mail( $to, $subject, $body, $headers );

How to find package by filename

user@laptop:/var/www# dpkg -S /usr/bin/firefox
diversion by firefox-mozilla-build from: /usr/bin/firefox
diversion by firefox-mozilla-build to: /usr/bin/firefox.ubuntu
firefox-mozilla-build: /usr/bin/firefox
user@laptop:/var/www# apt-get remove firefox-mozilla-build

Remove duplicates

DELETE
FROM main_table USING main_table,
    main_table e1
WHERE main_table.id > e1.id
    AND main_table.entity_id = e1.entity_id;