xenogenesi::blog
memento
3d adt android apache2 app apt aria2 build bullet cflags chromium codeigniter debian demoscene dependencies dpkg driver emulator freeglut gcc gfx git glut htaccess javascript json kernel linux make metalink minimal mysql opengl php python raspbian realtime rpi specs template toolchain update-alternatives video wifi wordpress

SSL Let’s encrypt on Debian stretch with dehydrated

Assuming you’ve apache2 already installed and a reachable internet server running

apt-get install dehydrated

Add/edit /etc/apache2/conf-available/letscrypt.conf (notice the difference between the alias and the real directory which is plural acme-challenges):

Alias /.well-known/acme-challenge/ "/var/lib/dehydrated/acme-challenges/"
<Directory "/var/lib/dehydrated/acme-challenges/">
        Options None
        AllowOverride None
        # Apache 2.x
        <IfModule !mod_authz_core.c>
                Order allow,deny
                Allow from all
        </IfModule>
        # Apache 2.4
        <IfModule mod_authz_core.c>
                Require all granted
        </IfModule>
</Directory>

Add/edit /etc/dehydrated/conf.d/99_email.sh:

CONTACT_EMAIL="anymail@yourdomain"

Edit /etc/dehydrated/domains.txt, set the domains for which generate certificates.

Restart apache2 and run dehydrated -c, it should create the domain certs.

Edit your apache’s host file (/etc/apache2/sites-available/default-ssl.conf), replace DOMAIN with your domains:

SSLCertificateFile /var/lib/dehydrated/certs/DOMAIN/fullchain.pem
SSLCertificateKeyFile /var/lib/dehydrated/certs/DOMAIN/privkey.pem

Add/edit /etc/cron.daily/dehydrated:

#!/bin/sh

exec /usr/bin/dehydrated -c >/var/log/dehydrated-cron.log 2>&1

Run chmod 0755 /etc/cron.daily/dehydrated

Add/Edit /etc/logrotate.d/dehydrated:

/var/log/dehydrated-cron.log
{
        rotate 12
        monthly
        missingok
        notifempty
        delaycompress
        compress
}

git dynamic mail by url using the post-checkout hook

mkdir ~/.git-templates

git config --global init.templatedir ~/.git-templates

git config -l

mkdir -p ~/.git-templates
tar -xvzf git-templates.tgz -C ~/.git-templates

get the url

cd ~/some-git-repo
git ls-remote --get-url 'origin'

EDIT ~/.gitconfig and add an entry

[user "url-from--get-url"]
    email = sample@eml
    name = name surname

check it is working

git clone <url-from--get-url> 

references: git-templates.tgz

picocom and tmux

~/ttyACM0:

#!/bin/sh
exec /usr/bin/picocom -b 115200 /dev/ttyACM0

initialization:

ATZ
AT+VCID=1
ATS0=0

attach tmux:

tmux attach

detach from tmux:

Ctrl+b d

phpunit with phpstorm < 9.5

PhpStorm versions older than 9.5 may have some trouble running phpunit tests:

PHP Fatal error:  Call to undefined method PHP_CodeCoverage_Filter::addFileToBlacklist()

so:

composer require --dev "phpunit/phpunit=4.*" # to install phpunit as dev dependency then...
# not working with phpunit 5
composer require --dev phpunit/php-code-coverage dev-master#b8436b000263f6d72fbad1d36890e247ce84857e

reference

composer and phpunit

The initial directory tree:

- packages/
  - xpackage/

- projects/
  - xproject/

(may have more packages and/or more projects)

installing composer globally

mkdir -p $HOME/.composer/vendor/bin
curl -sS https://getcomposer.org/installer | php
mv composer.phar $HOME/.composer/vendor/bin/composer

and add the path to the environment variable PATH

export PATH=$PATH:$HOME/.composer/vendor/bin

installing phpunit globally with composer

composer global require "phpunit/phpunit=4.7.*"

xpackage tree:

composer.json
phpunit.xml
bootstrap.php
- src/
  - XClass.php

- tests/
  - OutputTest.php

src/XClass.php:

namespace XVendor\XPackage;

class XClass {
   public static function test() {
      echo "should work";
   }
}

composer.json:

{
    "name": "xvendor/xpackage",
    "description": "package description",
    "authors": [
        {
            "name": "Author",
            "email": "[email protected]"
        }
    ],
    "minimum-stability": "dev",
    "require": {
      "php": ">=5.3.0"
    },
    "autoload": {
      "psr-4": {
        "XVendor\\XPackage\\": "src/"
      }
    }
}

phpunit.xml

<phpunit bootstrap="bootstrap.php">
  <testsuites>
    <testsuite name="xpackage">
      <directory>tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

bootstrap.php

spl_autoload_register(function ($class) {
    $dirs = explode("\\", $class);
    if ($dirs[0] !== 'XVendor')
        return;
    array_splice($dirs, 0, 2); /* drop vendor & package */
    $file = dirname(__FILE__).'/src/'.implode('/',$dirs).'.php';
    include $file;

tests/OutputTest.php

use XVendor\XPackage\XClass;

class OutputTest extends PHPUnit_Framework_TestCase
{
    /* @covers XClass:test */
    public function testExpectFooActualFoo()
    {
        $this->expectOutputString('should work');
        print XClass::test();
    }
}

xpackage version control with git

cd xpackage/
git init
git add .
git commit -m 'initial import'

versioning the package is required

xproject tree

- composer.json
- phpunit.xml
- bootstrap.php
- src/
  - index.php

- tests/
  - OutputTest.php

# created on composer install
- vendor/*
- composer.lock

composer.json

{
    "repositories": [
    { "packagist": false },
        {
            "type":"vcs",
            "url":"../../packages/xpackage"
        }
    ],
    "require": {
        "xvendor/xpackage": "@dev"
    }
}

create it then install the dependency

composer install

(will create composer.lock and vendor/)

phpunit.xml

<phpunit>
  <testsuites>
    <testsuite name="xproject">
      <directory>tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

src/index.php

require_once __DIR__ . '/../vendor/autoload.php';

use \XVendor\XPackage\XClass;

function test() {
    XClass::test();
}

tests/OutputTest.php

require __DIR__.'/../src/index.php';

class OutputTest extends PHPUnit_Framework_TestCase
{
    /* @covers XClass:test */
    public function testExpectShouldWork()
    {
        $this->expectOutputString('should work');
        print test();
    }
}

auto loader optimization with class maps

On production you should optimize loader performances creating a class map file

composer dumpautoload -o