Category: Hints, Tips & Techniques

  • NCDU – Find what’s using all your disk space on linux based system

    NCDU – Find what’s using all your disk space on linux based system

    NCDU is a text-based user interface, it allows you to visually see how and where disk space is being used via an easy-to-use interface. Simple run the command in the current directory to see a directory tree of folders & files and their space usage.

    I use this tool mainly for analysing why a server is running out of disk space, determine the reason why and if it’s simply expanded the disk space or is there unused files / massive logs which can be purged.

    Install

    Run the required command for your linux OS version.

    sudo apt install ncdu

    sudo yum install ndcu

    How to use

    Simple navigate to a directory you want to check and run the command:

    ncdu

    If you want to scan the whole system go to the root directory:

    cd /
    ncdu

    You can also specify a directory if you don’t want to change directory:

    ncdu /home

    Windows Server / PC

    For windows-based machines I use a bit of software called TreeSize, it does the same thing as NCDU, allowing you to see how your disk space is being used on a windows based OS.

    TreeSize on windows PC showing disk space usage
    TreeSize on windows PC showing disk space usage

     

    This is provided as it and may require changes to work for your needs.

     

  • htaccess: HTTP to HTTPS redirect

    It is recommended to you SSL on your website even when not required. Google Chrome and other browsers have begun to flag non-SSL websites as insecure. Don’t lose your visitors due to appearing as an insecure website.

    With the introduction of LetsEncyrpt and other free SSL certificate providers, there is no reason for websites to not be secured. Google Chrome is now beginning to flag websites which are non-HTTPS as secure leading to your visitors and customers believe your website is insecure. Make sure your using and SSL and redirecting all non-HTTP traffic to HTTPS using the below htaccess config setting for Apache.

  • Automatic MySQL database backups and zipping on windows with a bat file

    Automatic MySQL database backups and zipping on windows with a bat file

    It is important you double check your configuration before running this script! We cannot be held responsible for any damage this may cause.

    Need to backup all your databases on a MySQL windows server? Red Olive have created a simple windows batch file to export all database tables and zip, including deleting older backups! It’s quite simple to setup look at their website.

    https://www.redolive.com/utah-web-designers-blog/automated-mysql-backup-for-windows/

    Their version is configured for a US date/time format, I am in the UK with UK based date/time formats, I have made a modified version of the script available below.

    You should setup a scheduled task to run the bat file on a regular interval, the more often you perform backups the easier it will be for you if there is a failure and you require to restore a backup.

    We also advise you look at a process for storing backups at remote location, if you backup to a Dropbox folder your backups will be uploaded to the cloud, protecting you if the server dies or has disk failure!

  • Laravel, time zones and carbon

    Laravel defaults to storing all dates in UTC format, this is highly recommended as UTC time never changes unlike other time zones which have daylight savings. It is best practice to store and read dates in UTC, and then convert UTC to your required time zone for the user interface.

    Great article below of a good way to implement time zones using Carbon within your Laravel app.

    https://andrew.cool/blog/49/Easy-timezones-in-Laravel-with-Carbon

  • Repairing damaged or crashed MySQL tables

    Always remember, regular backups of your databases are best practice, in the event the below fail, backups may be the only method you have to restore a working table or database.

    Damaged or crashed MySQL tables due to an unsafe server shut downs, disk space limits or general MySQL failures? You will normally see something along the lines of “marked as crashed and should be repaired when using LOCK TABLES” within your MySQL log files.

    MySQL has a number of tools to try and repair crashed / damaged tables. Log into your server as root and run the following commands. Replacing “/var/lib/mysql/” with the location of your DB files.

    Check what tables need repaired:

    myisamchk –check /var/lib/mysql/*/*.MYI

    Try a safe recovery:

    myisamchk –safe-recover /var/lib/mysql/*/*.MYI

    Try a normal recovery (if safe recovery fails):

    myisamchk –recover /var/lib/mysql/*/*.MYI

    Try a force recovery (as a final last step):

    myisamchk –safe-recover –extend-check –force /var/lib/mysql/*/*.MYI

    or:

    myisamchk –recover –extend-check –force /var/lib/mysql/*/*.MYI

  • Easy mobile browser detection for several major languages and web servers

    All app’s and websites these days need to work for several devices including desktop, tablets and mobiles. It’s not always simple detecting the type of device being used and it can sometimes be tedious adding support to your app for something which seems very simple.

    Does your chosen platform not have a pre-defined way of detecting a mobile browser? Check out Detect Mobile Browsers, has several copy / paste examples for several programming languages.

    http://detectmobilebrowsers.com/

    Remember Apache, IIS and nginx detection examples also present for doing for pesky redirects.

  • Progressive JPEGs for fast website image loading and ux design

    Want to Speed up your website images and improve user experience? Make sure you use progressive JPEGs (or interlaced JPEGs), it could help make your website load faster and retain visitors for a longer duration.

    Take a look at the example below showing a normal baselayer JPEG and a progressive JPEG LOADING side by side.

    http://pooyak.com/p/progjpeg/

    Instead of delaying page loading for high quality images, we can display lower quality and load the high quality whilst the user can still browser, view, read and purchase. Remember your visitors may be on a slow mobile connection! They don’t want to wait!

    Some further reading? Take a look at the website below.

    https://www.thewebmaster.com/dev/2016/feb/10/how-progressive-jpegs-can-speed-up-your-website/