Snippets: a simple tech blog.
-
Overflow both sides in CSS
Normally, when content or an image overflows outside a div, the overflowing content is shown on the right outside the “box”. If you want to position the content to the center, so that overflow is on both sides, you can use this class. This is useful to position an image such that the centre of…
-
Make an inner div full width in CSS
Make an inner div expand to the full-width of the page. When a div is inside another div, adding width: 100% will only stretch it to the width of its container. To make the stretch to the full width of the page (or viewport), use this:
-
Add custom post types to WordPress search
Include custom post types in the search using WordPress hooks To include custom post types in the default search, we need to modify the search function using an action hook. Post types that we want to search through are added to the search query in an array. The array needs to include WordPress’s default post…
-
Check disk usage in Linux command line
View total disk usage Disk free space can be checked in the Linux command line using the df and du commands. df stands for disk free. du stands for disk usage. The -h flag stands for human. It shows the sizes in human readable formats like MB or GB instead of bytes. Disk usage by…
-
MySQL user management from the command line
If phpMyAdmin is not installed on your server or if you don’t have access to it but instead have shell access, you can easily manage your MySQL database users from the command line. MySQL stores the list of users in the mysql.user table. List of all databases are stored in the mysql.db table. Show list…
-
Export / Import a MySQL database between remote server and local machine
Upload or download a MySQL database between a remote server and localhost using the Linux command line. Download a remote MySQL database Download a remote MySQL database using mysqldump dump. The output of the dump is compressed using gzip. This compressed file is then unzipped and downloaded into the file remotedb.sql. Copy local database to…
-
Create a new MySQL user from the command line
Create and add a user to a MySQL database using the command line. Run MySQL Open MySQL using the below command. The username should be your root user or an admin user with access for creating other users. Create a database and a user Create a new database (if required) and create a new user.…
-
Start WSL cron in a hidden window
Enable cron to run without asking for password Normally running sudo service cron start in WSL will ask for the sudo password. This is an issue when we want to run cron from the script below. To fix this, we need to enable cron service to run without asking for the password by adding it…
-
Align second line of bullet points in CSS
HTML aligns the lines after the first line flush with the bullet point (the dot) instead of the text. You can fix this with the class below. text-indent property applies only to the first line of a text-block. So we first “pull” the first-line back along with the dot. Then we push the entire text-block…