How to setup / enable Directory index listing?

When a web browser is pointed to a directory on your website which does not have an index.html file in it, the files in that directory can be listed on a web page.

Directory Lister is a simple PHP script that lists the contents of any web-accessible directory and allows navigating therewithin. Simply upload Directory Lister to any directory and get immediate access to all files and sub-directories under that directory. Directory Lister is written in PHP and distributed under the MIT License.

http://www.directorylister.com

Directory Lister requires PHP 5.3+ to work properly. For more information on PHP, please visit http://www.php.net.

steps to set up directory listing:

  1. Open “public_html” and Upload “index.php” and “resources” folder.
  2. Now go to “resources” directory and rename “default.config.php” to “config.php”.
  3. Also, upload additional files to the same directory as index.php.
  4. All Done!!!

Enable / Disable directory index listing.

enable:

To have the web server produce a list of files for directories, use the below line in your .htaccess  (can be found in FTP -> public_html folder):

Options +Indexes

disable:

To have an error (403 – Forbidden) returned instead, use this line:

Options -Indexes

When enabled you can visit your website to see Directory listing.

Hope, this post was helpful.

Thank You.

How to edit default python version for a linux user?

Edit the bash profile and add an alias using the following code

$ nano ~/.bashrc

Put the following line of code in .bashrc file and alter the python3.6 path as per your new installation

alias python='/usr/local/bin/python3.6'

Use CTRL x to exit and save
After that you need to reload the source, so use the following command and you are good to go.

$ source ~/.bashrc

How to increase EBS storage block size on a running spot instance in AWS?

So, you created a aws group with a small ebs storage size and now that the site is in production, storage disk is full and it was mounted as root storage, now you are asking “MY AWS INSTANCE STORAGE IS FULL, WHAT TO DO?”
or “How do I increase the EBS volume size of a running instance?”

So, here is the simple solution:

There are two commands which will help you

$ lsblk

and

# df -h

So, initially if you login via SSH (using PUTTY or anything else) you will see something like this:

So, what you need to do is, you need to go to aws console and edit block size in EC2 management

Go to EBS > Volumes
Right Click the volume you need to expand and choose MODIFY VOLUME
Enter the new size you want for your block

Now run the command lsblk and df -h and you will notice the old size and new size under xvda and xvda1

Size available but not used

If you dont see the updated new size, please use init 6 or restart the instance using any other command

You now need to use utility growpart so use command


sudo apt install cloud-utils

If you are out of space, please remove any old files which are of no use anymore to free up some Mega Bytes
After that, simply use


sudo growpart /dev/xvda 1

and
sudo resize2fs /dev/xvda1
resize2fs command
lsblk after resize
df command after resize

Reference: 
https://stackoverflow.com/a/43251901/2229148


tk120404

Removing extra digits after decimal and leave only two decimal places

^(.*?\..?.?).*?$

your first match will leave the number with max 2 decimal digits.
So find with ^(.*?\..?.?).*?$ and replace with \1

Input

27485.0375
75777.9125
10785.0125
13822.5
26700
41194.375
9375
4354.225
11564.475
12430.1
3246.4875
11596.3375
22466.0375

Output:

27485.03
75777.91
10785.01
13822.5
26700
41194.37
9375
4354.22
11564.47
12430.1
3246.48
11596.33
22466.03

How to save Windows 10 Lockscreen wallpaper image in laptop?

Windows 10 lockscreen feature is called spotlight and you see new beautiful pictures on your window 10 when ever it is locked.
These pics are present in Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy folder and are not having correct extensions as these are raw images and probably microsoft doesnt want them to be indexed in your gallery.
So, the process is simple, open Command Prompt
For opening command prompt, press windows button and then type cmd and click/enter on first result

OR Press Windows + R and then type cmd followed by Enter key.
After you see command prompt’s black screen,, copy and paste the following code in it and that is it.
You can find the lock screen pictures inside you “My Pictures” > “Lockscreenwallpapers” Folder.

mkdir "%userprofile%\Pictures\Lockscreenwallpapers"
copy "%userprofile%\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\*" "%userprofile%\Pictures\Lockscreenwallpapers\"
C:
cd "%userprofile%\Pictures\Lockscreenwallpapers\"
ren *.* *.jpg
exit
 

How to add colon separated hours in PHP using explode function twice?

Problem Statement

Tracking hours for multiple days are available in HH:MM:SS format separated by tab element. Add all the time to show total hours worked/tracked.

<?php
$a="03:23:28	03:58:54	00:00:00	03:10:49	02:17:33	03:56:38	02:18:23	06:15:42	00:00:00	00:00:00	06:04:51	07:41:09	03:23:15	06:12:59	03:51:27	00:00:00	04:30:06	05:00:23	00:00:00	04:34:25	05:17:02	01:36:21	00:00:00	03:53:20	06:30:52	06:21:47	04:54:16	03:22:28	03:10:35	00:00:00	06:37:11	02:14:22	03:06:49	03:05:44	02:35:54	04:03:22	00:00:00
";
#$a="04:05:21	06:25:39	03:02:36	04:01:17	03:03:21	02:00:36	04:21:54	04:21:35	00:00:00	00:00:00	03:39:21	04:19:17	03:08:14	01:44:48	03:28:11	00:00:00	03:05:53	03:05:34	00:00:00	02:09:17	05:01:13	01:02:20	00:00:00	04:30:51	06:03:49	06:36:35	02:14:01	03:06:38	04:02:09	00:00:00	02:34:29	03:36:30	05:10:17	06:46:19	07:48:08	09:13:34	00:00:00
#";
$a="07:28:49	10:24:33	03:02:36	07:12:06	05:20:54	05:57:14	06:40:17	10:37:17	00:00:00	00:00:00	09:44:12	12:00:26	06:31:29	07:57:47	07:19:38	00:00:00	07:35:59	08:05:57	00:00:00	06:43:42	10:18:15	02:38:41	00:00:00	08:24:11	12:34:41	12:58:22	07:08:17	06:29:06	07:12:44	00:00:00	09:11:40	05:50:52	08:17:06	09:52:03	10:24:02	13:16:56	00:00:00
";
$f=explode("\t",$a);
$th=$tm=$ts=0;
foreach($f as $ele){
	
	$ht=explode(":",$ele);
	$hours=intval($ht[0]);
	$minutes=intval($ht[1]);
	$seconds=intval($ht[2]);
	$th+=$hours;
	$tm+=$minutes;
	$ts+=$seconds;
}
$mm=intval($ts/60);
$ts=$ts%60;
$tm+=$mm;
$hh=intval($tm/60);
$tm=$tm%60;
$th+=$hh;

echo "$th:$tm:$ts";
?>

Extracting names from given list of URLs (using regex)

let us extract name form the URL
https://www.google.com/name?=rajiv
paste the URL in the notepad and press crtl+f , and select ‘regular expressions ‘ from search mode

find in notepad

now, enter the regex in the find tab to fetch names
.*?\?=(\w+)$

Now, the selected name will be fetched form regex as (\1).

it can work on numerous links like:-

https://www.google.com/name?=rajiv/
http://www.example.com/asdas?=borde/id=?
http://www.example.com/asdasd?=bordex
http://www.example.com/name?=bordet
http://www.example.com/asdasd?=border
http://www.example.com/jsciloji?=bordeeeee
http://www.example.com/name?=bordee
http://www.example.com/name?=bordeeeeeee
http://www.example.com/09328e?=bordeeee
http://www.example.com/name?=borde
http://www.example.com/lpaosd?=borde

And only the part after first “?=” will be fetched

MySQL error 1449: The user specified as a definer does not exist

Why this error happens?

Most of the times, reason is that your database dump through command line or PhpMyAdmin or even other libraries can have SQL’s Definer statements. Now, as per MySQL’s Official Documentation:

The DEFINER clause specifies the MySQL account to be used when checking access privileges at routine execution time for routines that have the SQL SECURITY DEFINER characteristic.

MySQL Reference Manual v8.0

Solution: MySQL mysqldump create a safe backup to ensure no corruption

Use the following command to create backup of your mysql database. Put the command in terminal

mysqldump -hHOST -uUSERNAME -p DATABASE_NAME | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > BACKUP_NAME.sql

With gzip compression > backup

mysqldump -hHOST -uUSERNAME -p DATABASE_NAME | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' | gzip > BACKUP_NAME.sql

Reference: https://stackoverflow.com/a/9447215/2229148

Magento 2 all cli commands

[~/www]# php bin/magento list
Magento CLI version 2.2.4
Usage:
command [options] [arguments]
Options:
-h, --help            Display this help message
-q, --quiet           Do not output any message
-V, --version         Display this application version
--ansi            Force ANSI output
--no-ansi         Disable ANSI output
-n, --no-interaction  Do not ask any interactive question
-v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help                                     Displays help for a command
list                                     Lists commands
admin
admin:user:create                        Creates an administrator
admin:user:unlock                        Unlock Admin Account
app
app:config:dump                          Create dump of application
app:config:import                        Import data from shared configuration files to appropriate data storage
cache
cache:clean                              Cleans cache type(s)
cache:disable                            Disables cache type(s)
cache:enable                             Enables cache type(s)
cache:flush                              Flushes cache storage used by cache type(s)
cache:status                             Checks cache status
catalog
catalog:images:resize                    Creates resized product images
catalog:product:attributes:cleanup       Removes unused product attributes.
config
config:sensitive:set                     Set sensitive configuration values
config:set                               Change system configuration
config:show                              Shows configuration value for given path. If path is not specified, all saved values will be shown
cron
cron:install                             Generates and installs crontab for current user
cron:remove                              Removes tasks from crontab
cron:run                                 Runs jobs by schedule
customer
customer:hash:upgrade                    Upgrade customer's hash according to the latest algorithm
deploy
deploy:mode:set                          Set application mode.
deploy:mode:show                         Displays current application mode.
dev
dev:di:info                              Provides information on Dependency Injection configuration for the Command.
dev:profiler:disable                     Disable the profiler.
dev:profiler:enable                      Enable the profiler.
dev:query-log:disable                    Disable DB query logging
dev:query-log:enable                     Enable DB query logging
dev:source-theme:deploy                  Collects and publishes source files for theme.
dev:template-hints:disable               Disable frontend template hints. A cache flush might be required.
dev:template-hints:enable                Enable frontend template hints. A cache flush might be required.
dev:tests:run                            Runs tests
dev:urn-catalog:generate                 Generates the catalog of URNs to *.xsd mappings for the IDE to highlight xml.
dev:xml:convert                          Converts XML file using XSL style sheets
i18n
i18n:collect-phrases                     Discovers phrases in the codebase
i18n:pack                                Saves language package
i18n:uninstall                           Uninstalls language packages
import
import:categories                        Run category importer script
indexer
indexer:info                             Shows allowed Indexers
indexer:reindex                          Reindexes Data
indexer:reset                            Resets indexer status to invalid
indexer:set-mode                         Sets index mode type
indexer:show-mode                        Shows Index Mode
indexer:status                           Shows status of Indexer
info
info:adminuri                            Displays the Magento Admin URI
info:backups:list                        Prints list of available backup files
info:currency:list                       Displays the list of available currencies
info:dependencies:show-framework         Shows number of dependencies on Magento framework
info:dependencies:show-modules           Shows number of dependencies between modules
info:dependencies:show-modules-circular  Shows number of circular dependencies between modules
info:language:list                       Displays the list of available language locales
info:timezone:list                       Displays the list of available timezones
maintenance
maintenance:allow-ips                    Sets maintenance mode exempt IPs
maintenance:disable                      Disables maintenance mode
maintenance:enable                       Enables maintenance mode
maintenance:status                       Displays maintenance mode status
module
module:disable                           Disables specified modules
module:enable                            Enables specified modules
module:status                            Displays status of modules
module:uninstall                         Uninstalls modules installed by composer
sampledata
sampledata:deploy                        Deploy sample data modules
sampledata:remove                        Remove all sample data packages from composer.json
setup
setup:backup                             Takes backup of Magento Application code base, media and database
setup:config:set                         Creates or modifies the deployment configuration
setup:cron:run                           Runs cron job scheduled for setup application
setup:db-data:upgrade                    Installs and upgrades data in the DB
setup:db-schema:upgrade                  Installs and upgrades the DB schema
setup:db:status                          Checks if DB schema or data requires upgrade
setup:di:compile                         Generates DI configuration and all missing classes that can be auto-generated
setup:install                            Installs the Magento application
setup:performance:generate-fixtures      Generates fixtures
setup:rollback                           Rolls back Magento Application codebase, media and database
setup:static-content:deploy              Deploys static view files
setup:store-config:set                   Installs the store configuration. Deprecated since 2.2.0. Use config:set instead
setup:uninstall                          Uninstalls the Magento application
setup:upgrade                            Upgrades the Magento application, DB data, and schema
store
store:list                               Displays the list of stores
store:website:list                       Displays the list of websites
theme
theme:uninstall                          Uninstalls theme
varnish
varnish:vcl:generate                     Generates Varnish VCL and echos it to the command line

RPM repo not found connection errors on Centos Redhat duplicate problems

yum -y update command failing

Command line will show messages like

xxx is outdated and v abc will be installed
but at the end it shows duplicate binary, please remove duplicate first.

Process

Backup first
Integrity Check
Find Problems
Identify duplicates
Clean duplicates
re build conf cache
update command
remove backup file .prev if successfully solved

\cp -r /var/lib/rpm /var/lib/rpm.prev
yum-complete-transaction
package-cleanup --problems
package-cleanup --dupes
package-cleanup --cleandupes
yum clean all
rpm --rebuilddb
yum update
# if all went OK run 'rm -rf /var/lib/rpm.prev'

Other possible solution

1. Update DNS to google dns 8.8.8.8 and 8.8.4.4 or freenom dns 80.80.80.80 and 80.80.81.81

system-config-network

2. Restart internet while maintaining SSH session (you wont be logged out)

/etc/init.d/network restart