Category: Uncategorized


In PHPStorm, you can do a regex find and replace. To upgrade a crappy old site using <?, just use the following regex:

#<\?(?!=|php|xml)#

https://regex101.com/r/yD6dK5/5

Apple Wireless Mouse on Windows

So I left my work laptop’s PSU in Scotland. Oops! I also left my cheap mouse alongside it (I hate the touchpad thingy). So that left me with my Apple Wireless Magic Mouse, the touch sensitive one.

Once you hook it up with Bluetooth, you’ll notice the touch scroll doesn’t work. 😦
So let’s fix that!

As you know, Mac can run Windows using a thing called Bootcamp, which has the drivers we need. Download either the 32 or 64 bit version depending which Windows you are running. https://support.apple.com/kb/DL1336?locale=en_US

Using 7-zip or something similar, right click the downloaded exe and and extract it somewhere. Once extracted, go into the BootCamp31ToBootCamp303 folder.

Look for a file called Binary.MultiTouchMouse_Bin. Right click on that, and extract the files somewhere. These are our drivers!

Once you’ve done that, run DPInst.exe, which will install the drivers.

Scroll now works! But ah! Macs scroll the opposite way around, like a touch screen, we push the page up or down. If you’d like to flip the scroll “wheel”, do the following:

  • Open Control Panel > Devices & Printers > Bluetooth Devices
  • Right click and choose Properties
  • Select HID compliant mouse, and click properties
  • Choose the Details Tab
  • Select Device Instance Path, note the value
  • Open regedit (Start > regedit)
  • HKEY_LOCAL_MACHINE
  • System
  • Current Control Set
  • Enum
  • HID
  • Now follow the device instance path from the mouse properties
  • Device Parameters
  • Double Click FlipFlopWheel
  • Change 0 to 1 (turn flip flop wheel on)
  • Now disconnect and reconnect your mouse

Your mouse now works exactly the same way in Windows as it does on your Mac. Have fun!

DOMDocuments are cool, and a really nice way of dealing with HTML in an OO fashion. However, sometimes, we have an HTML string element which we need to add to our Document. Here’s how you do it:

    function createNodesFromHTML(DOMDocument $doc,$str) 
    {
        $nodes = array();
        $d = new DOMDocument();
        $d->loadHTML("<html>{$str}</html>");
        $child = $d->documentElement->firstChild->firstChild;
        while($child) {
            $nodes[] = $doc->importNode($child,true);
            $child = $child->nextSibling;
        }
        return $nodes;
    }


        $dom = new DOMDocument();
        $icon = '<i class="fa fa-remove"></i>'; // This is our string

        $button = $dom->createElement('a');
        $button->setAttribute('href', '/whatever/delete/12345');
        $button->setAttribute('class', 'btn btn-sm btn-danger');
        
        // This is us turning the string(s) into nodes we can add
        $nodes = createNodesFromHTML($dom, $icon);
        $button->appendChild($nodes[0]);
        
        $dom->appendChild($button);
        echo $dom->saveHTML();

Editing CSV’s in PHPStorm

I was looking for a CSV plugin for PHPStorm, but it turns out there is no need. Open your CSV (which you associate with a plain text file), right click, and select edit as table!

Notice how much better that looks!

table

Now that my VM is completely configured through puPHPet’s puphpet/files/exec-once shell scripts, I had to change PHP settings for the legacy 5.3 install. At first I echoed the setting out and concatenated it onto the end of the string, however the setting was already uncommented above.

The answer is to use sed to find and replace the line of text, like this!

cat /etc/php.ini | sed -e "s/short_open_tag = Off/short_open_tag = On/" >> /etc/php.ini

Git tree view in CLI

Easy. Create an alias:

git config --global alias.tree "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative —branches”

then just run

git tree

Screen Shot 2016-02-09 at 15.49.21

cat ~/.ssh/id_rsa.pub | ssh user@host ‘cat >> .ssh/authorized_keys’

fix puphpet bind error

The bind command `bindfs --perms=u=rwX:g=rwX:o=rD --user=www-data --group=www-data /mnt/vagrant-vflsf_hshd6x5eenjw /var/www` failed to run!

I still don’t know exactly why it’s happening, it’s like deprecation warnings or something! I am using too new a version of something.

Until I do know for certain, this is what I do to fix it:

sudo bindfs --perms=u=rwX:g=rwX:o=rD --force-user=www-data --force-group=www-data /mnt/vagrant-vflsf_hshd6x5eenjw -o nonempty /var/www

 

Source: Using LetsEncrypt to get a free SSL Certificate (on VestaCP)

This is real easy, but i keep forgetting which option to use!

If you have separated some of your code into a composer vendor package, and are currently using it in a project, it can be annoying if you need to update it. First you need to open that project up, make your changes, commit, push, wait for tests to pass on travis etc, tag a new version (depending), update packagist if it hasn’t automatically already, and then you can go back into composer and update.

So to save that hassle, composer has the –prefer-source option (–prefer-dist is the one that confused me). This puts the .git folder in your vendor package folder, allowing you to edit, commit, and push from there. Much better.

If you already have the package installed, just delete it. If you haven’t installed it yet, just require it. Both with the –prefer-source option.

composer require delboy1978uk/user --prefer-source
// or
composer update delboy1978uk/user --prefer-source

Replacing my own package above with the one you need, of course. Have fun!Screen Shot 2016-01-14 at 20.26.55