マイナスの投票

星新一あたりの作品にあったような気もするが、マイナスの投票というのが面白いと思う。選挙で候補者に1票ではなくて、マイナス1票を投じる。結果は普通に集計する。総計でマイナスの候補者は、順位に関わらず落選。
投票率は格段にあがるよね。どうせ差し引きの選択しかできないなら、それをダイレクトに反映できる方が自然でもある。

SierraにHomebrewでMySQL, Apache,PHPをインストール

Homebrew自体の準備

brew update
brew doctor

MySQL

brew install mysql
mysql_secure_installation
mysql.server start
//loginで開始するように設定
brew services start mysql

Apache

brew tap homebrew/dupes
brew tap homebrew/apache
//デフォルト8080で動作
brew install httpd24
//loginで開始するように設定
brew services start homebrew/apache/httpd24

PHP

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
//既存のPHPがあれば
brew unlink php55
//httpd.confに php7_module の行を追加
brew install php71 --with-httpd24

Apacheの設定
/usr/local/etc/apache2/2.4/httpd.conf

//設定済のはず
LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
//修正する
ServerName localhost:8080
//index.phpを書き加える
DirectoryIndex index.php index.html
//コメント解除
Include /usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf
LoadModule rewrite_module libexec/mod_rewrite.so
//末尾に追加
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>

vhostの設定
/usr/local/etc/apache2/2.4/extra/httpd-vhosts.conf

<VirtualHost *:8080>
    ServerName localhost
    DocumentRoot "/usr/local/var/www/htdocs"
    <Directory "/usr/local/var/www/htdocs">
        AllowOverride All
        Require all granted
    </Directory>
    CustomLog "/usr/local/var/log/apache2/localhost.access.log" common 
    ErrorLog "/usr/local/var/log/apache2/localhost.error.log"
</VirtualHost>
 
<VirtualHost *:8080>
    ServerName SSS.dev
    DocumentRoot "XXX/public"
    <Directory "XXX/public">
        AllowOverride All
        Require all granted
    </Directory>
    CustomLog "/usr/local/var/log/apache2/SSS.dev.access.log" common 
    ErrorLog "/usr/local/var/log/apache2/SSS.dev.error.log"
</VirtualHost>

PHPの設定
/usr/local/etc/php/7.1/php.ini

date.timezone = Asia/Tokyo
default_charset = "UTF-8"
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.detect_order = UTF-8,SJIS,EUC-JP,JIS,ASCII

その他、PHP開発用

brew install php71-xdebug

brew update で …/kernel_require.rb:55:in `require’: cannot load such file …

brew update で、以下のエラーが出る場合の対処。
Sierra

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require’: cannot load such file — mach (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require’
from /usr/local/Library/Homebrew/extend/pathname.rb:2:in `
….

cd /usr/local
git reset --hard && git clean -df

brew doctor してみると異なるエラーになるので、さらに対処

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don’t worry and just ignore them. Thanks!

Warning: The /usr/local directory is not writable.

sudo chown -R $(whoami):admin /usr/local

その後に 
brew update
brew upgrade

Tableのrowを増減する

    $('a.addrow').on('click', function(event){
        event.preventDefault();
        var curTable = $(this).closest('table');
        var tmplateRow = curTable.find('thead > tr.template');
        curTable.find('tbody').append('<tr>' + tmplateRow.html() + '</tr>');
    });

    $('a.removerow').on('click', function(event){
        event.preventDefault();
        $(this).closest('table').find('tbody tr:last').remove();
    });