Allow SVG uploads to WordPress Media Library

upload-svg-wordpress-media-library
This function allows you to upload svg files to your wordpress media library.
You can this function to your theme’s functions file (functions.php)

function my_custom_mime_types($mimes) {
	$mimes['svg'] = 'image/svg+xml';
	return $mimes;
}
add_filter('upload_mimes', __NAMESPACE__ . '\\my_custom_mime_types');

Responsive Bootstrap hover dropdowns

Bootstrap 3 Responsive Hover Dropdowns
This adds hover behaviour to bootstrap’s dropdown menus using the built in ‘open’ class.
We will do it based on a responsive breakpoint.
In this example the hover behaviour should only happen if the screen is wider than 600px.
At the end we reset to the default behaviour on small screens.


        // Show menus on hover
        function hoverMenu(){
          var breakpoint = 600;
          var dropdown = $('ul.nav li.dropdown');
          if ( $(window).width() > breakpoint ){
            dropdown.hover(function() {
              $(this).addClass('open');
            }, function() {
              $(this).removeClass('open');
            });
          } else {
            // Remove hover behaviour
            dropdown.unbind( "mouseenter mouseleave" );
          }
        }

        //Do it!
        $(document).ready(function(){
          hoverMenu();
        });
        $(window).resize(function(){
          hoverMenu();
        });

If you use a debounce function I recommend you use it as you may not want the screen width to be calculated per pixel when the screen size changes.

...
        //Do it!
        $(document).ready(function(){
          hoverMenu();
        });
        $(window).resize(function(){
          debounce(hoverMenu(), 300);
        });

Add EBS based swap to an EC2 instance

Add EBS Swap To AWS EC2 Instance
1. Create a new EBS volume of around 4-8GB and attach it to your instance.
We will assume the volume is /dev/xvdb
To check wether it is mounted use lsblk

2. If your volume is mounted, unmount it

sudo umount /dev/xvdb

3. Turn this volume into swap

sudo mkswap /dev/xvdb

4. Enable this volume as swap

sudo swapon /dev/xvdb

5. Make sure it is working as swap

swapon -s

6. Use this disk as swap if instance is restarted

sudo vim /etc/fstab

Add this:

/dev/xvdb       none    swap    sw  0       0