Category: Programming & Development

  • Windows 10 Subsystem for Linux Ubuntu

    I have always been more of a Windows based developer and used Linux based systems for server technologies, I have tried in the past to move to Linux but I am to fixed in my way and prefer the tools I have on windows! Is that a bad thing, I dont no? however with Windows 10 comes Subsystems which allows you to run a Linux based Ubuntu as part of a subsystem working jointly with your windows 10 operating system.

    Im not talking about a VM or dual booting, I am talking about the ability to go to windows command line and type “ubuntu” and a full fledged ubuntu system from the command line starts up and allows you to run various tools, applications and services all within Ubuntu within Windows 10!

    Microsoft site has a simple guide to follow to install the linux subsystem here.

     

    1. Enabled windows subsystems for Linux

     

    2. Install Ubuntu via Windows Store

    Open Microsoft Store and search for Ubuntu and click install
     

    3. Initialise Setup

    Open command line and type ubuntu to start the ubuntu instance, it will take you throught a initialisation stage

     

    What next? have play around with Ubuntu on windows. For development purposes I am going to be using it with Docker! allowing me to control my Windows Docker environment from the Ubuntu Linux, as it allows me to use all the Linux based command structures and pipes making the experience even smoother and more powerful.

  • Fix for WooCommerce schema data missing brand and mpn

    Fix for WooCommerce schema data missing brand and mpn

    UPDATED 25/10/2021 to comply with latest google changes.

    Today I came across and issue where Google Search Console was complaning products “brand” and “mpn” where missing from the products schema / rich snippets data. You can checking using the rich snippet testing tool by Google found here.

    https://search.google.com/structured-data/testing-tool

    I fixed my issue by adding a WordPress filter using the “woocommerce_structured_data_product” filter option. This allows you to add new data to the already generated WooCommerce data.

    This is an example. You will need to change for your implementation.

  • Twitter Bootstrap 3 Media Queries

    Some useful bootstrap 3 media queries for both mobile first and non mobile first development styles, to make modifications to your front end simplier and follow the bootstrap 3 standard breakpoints.

    Origional article can be found here.

    Min-Width: Refers to everything greater than or equal to the amount given.
    Max-Width: Refers to everything less than or equal to the amount given.

  • htaccess: Block bad bots for security purposes

    Please double check any bots you wish to allow are not in the block list. This is a list of known bots, as well as default user agents.

    I have had a scenario where a website was getting scraped by a number of bots, causing excessive resource usage on the server and disrupting sales and bad experience for real customers.

    Here is a basic technique to stop those pesky bots, simply add the following to your .htaccess file. You may need to modify the exceptions at the top if you do require certain files to be accessed by bots. Currently it will allow access to robots.txt and acme-challenge for LetsEncrypt.

  • 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!

  • Local website & services remotely accessible via secure tunnels with ngrok

    Need an easy way to allow external network users to access services or websites on your local machine? ngrok allows you to easily create a secure tunnel from ngroks servers to your machine. For a web developer, this is a dream come true, this is a great way to demo a development whilst in the early stages, saves time uploading to a server.

    • Allows access to your locally hosted web server from a unique domain
    • Can use your own domains
    • Works with vHost files
    • Allows testing of website which require an external accessible point such as payment gateways or oAuth
    • Can tunnel other services such as PhoneGap allowing users external to your network to test your mobile app
    • Various API and IoT implementations
    • Easy / quick private networking, VPN benefits

    These are only a short list of what is possible using ngrok. Look at their website for a full list of its powerful features and get started.

    https://ngrok.com/

  • 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.