Useful Stuff

Codeception: Tell Chrome to automatically accept desktop notifications

If you’re building a site that makes use of the handy Web Notifications API and want to test it in Codeception, you might want to tell your browser to enable notifications for the site. I had to fiddle a bit before getting this right, so hopefully it’ll help somebody. In your xxx-acceptance.suite.yml, here are a couple of flags :

class_name: AcceptanceTester
modules:
  enabled:
    - Asserts
    - WebDriver:
      url: '/'
      browser: chrome
      restart: true
      capabilities:
      # Accept any JS alert boxes by default
        unexpectedAlertBehaviour: 'accept'
        chromeOptions:
          args:
            - 'enable-strict-powerful-feature-restrictions'
            - 'window-size=1440,900'
            - 'window-position=0,0'
          prefs:
            # Automatically accept desktop notifications
            'profile.managed_default_content_settings.notifications': 1

LetsEncrypt on Amazon Linux

This one’s pretty simple.

I started with Ivo Petkov’s excellent notes and O-mkar’s question and self-answer to get LetsEncrypt up on my EC2 instance, then added a cron job.

TL;DR:


sudo bash
yum install python27-devel git
git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
unset PYTHON_INSTALL_LAYOUT
/opt/letsencrypt/letsencrypt-auto --debug
echo "rsa-key-size = 4096" >> /etc/letsencrypt/config.ini
echo "email = email@example.com" >> /etc/letsencrypt/config.ini
unset PYTHON_INSTALL_LAYOUT
/opt/letsencrypt/letsencrypt-auto certonly --webroot -w /var/www/yourdomainroot -d yourdomain.com -d www.yourdomain.com --config /etc/letsencrypt/config.ini --agree-tos
yum install mod24_ssl

Add the following to /etc/httpd/conf.d/vhost.conf:


<VirtualHost *:443>
ServerName yourdomain.com
DocumentRoot "/var/www/yourdomainroot"

AllowOverride All
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/yourdomain.com/chain.pem
SSLProtocol All -SSLv2 -SSLv3
SSLHonorCipherOrder on
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS"
</VirtualHost>

And finally, a renewal cron job:


echo > /opt/letsencrypt/autorenew <<EOF

#!/bin/bash
unset PYTHON_INSTALL_LAYOUT
/opt/letsencrypt/letsencrypt-auto renew --config /etc/letsencrypt/config.ini --agree-tos && apachectl graceful

EOF
chmod a+x /opt/letsencrypt/autorenew

Then run crontab -e and add the following entry:


0 0 * * * /opt/letsencrypt/autorenew

For bonus marks, since you’ve probably got HTTP vhost for port 80 something like:


<VirtualHost *:80>
DocumentRoot "/var/www/yourdomainroot"
ServerName yourdomain.com
ServerAlias yourdomain.com

<Directory "/var/www/yourdomainroot">
AllowOverride All
</Directory>
# Other directives here
</VirtualHost>>

Simply add the following into your .htaccess to redirect everybody hitting your formerly insecure site to https:


RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Stop OSX Photos.app opening every time you plug your (Android or IOS) device into your Mac

This has been driving me mad for ages, every time I plugged a test device in to debug a Cordova app.  I eventually found this solution on SE for El Capitan:

defaults -currentHost write com.apple.ImageCapture disableHotPlug -bool YES

Problem solved!