うちのいぬ Tech Blog

Tech Blog of Uchinoinu/My dog

HomebrewでインストールしたMySQLを自動起動設定する

之だけで済むようです

$ brew services start mysql

==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 10 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
Checking connectivity... done.
Tapped 0 formulae (26 files, 32.4K)
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

OSX El Capitan に MySQL をインストールして、ちょっと使ってみる

Install

$ brew install mysql

==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.16.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.7.16.el_capitan.bottle.tar.gz
==> Using the sandbox
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

To connect run:
    mysql -uroot

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To start mysql:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
  /usr/local/Cellar/mysql/5.7.16: 13,511 files, 439M
  • 確認
mysql: stable 5.7.16 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/5.7/en/
Conflicts with: mariadb, mariadb-connector-c, mysql-cluster, mysql-connector-c, percona-server
/usr/local/Cellar/mysql/5.7.16 (13,511 files, 439M) *
  Poured from bottle on 2016-11-25 at 21:15:10
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb
==> Dependencies
Build: cmake ✘
Required: openssl 
==> Requirements
Required: macOS >= 10.7 
==> Options
--with-archive-storage-engine
    Compile with the ARCHIVE storage engine enabled
--with-blackhole-storage-engine
    Compile with the BLACKHOLE storage engine enabled
--with-debug
    Build with debug support
--with-embedded
    Build the embedded server
--with-local-infile
    Build with local infile loading support
--with-test
    Build with unit tests
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

To connect run:
    mysql -uroot

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To start mysql:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

Usage

Start MySQL Server

$ mysql.server start
Starting MySQL
.. SUCCESS! 

Entry to MySQL

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 Homebrew

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

[(none)] mysql> exit
Bye

Stop MySQL Server

$ mysql.server stop
Shutting down MySQL
.. SUCCESS! 

Make Security Powerful

mysql_secure_installation
mysql_secure_installation: [ERROR] unknown option '--show-warnings'
mysql_secure_installation: [ERROR] unknown variable 'prompt=[\d] mysql> '

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

---

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: y

---

Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

---

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

---

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

---

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

---

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

Create Database

[(none)] mysql> show databases;
+-----------------------------------+
| Database                          |
+-----------------------------------+
| information_schema                |
| mysql                             |
| performance_schema                |
+-----------------------------------+
3 rows in set (0.02 sec)

[(none)] mysql> create database foobar;
Query OK, 1 row affected (0.00 sec)

[(none)] mysql> show databases;
+-----------------------------------+
| Database                          |
+-----------------------------------+
| information_schema                |
| foobar                            |
| mysql                             |
| performance_schema                |
+-----------------------------------+
4 rows in set (0.02 sec)

Create User with privilege

[(none)] mysql> create user
    -> 'retriever'@'localhost' identified by 'ぱすわあど';

[(none)] mysql> select User,Host from mysql.user;
+-----------------+-----------+
| User            | Host      |
+-----------------+-----------+
| root            | 127.0.0.1 |
| root            | ::1       |
| retriever       | localhost |
| root            | localhost |
+-----------------+-----------+
4 rows in set (0.00 sec)

[(none)] mysql> grant all privileges on `foobar`.* TO 'retriever'@'localhost';
[(none)] mysql> FLUSH PRIVILEGES;

[(none)] mysql> show grants for 'retriever'@'localhost';
+-----------------------------------------------------------------------+
| Grants for retriever@localhost                                        |
+-----------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'retriever'@'localhost'                         |
| GRANT ALL PRIVILEGES ON `foobar`.* TO 'retriever'@'localhost' |
+-----------------------------------------------------------------------+
2 rows in set (0.00 sec)

自動起動設定

http://qiita.com/satomyumi/items/43c83658a3e5bcc820ec

PHPを5.5系から5.6系へバージョンアップする

前置き

Laravel5.2を使うに当たって、ElCapitanデフォルトのPHPのバージョンでは古いらしく、PHPを5.6系にバージョンアップします。(7系じゃないです)

手順

Homebrewのアップデート

$ brew tap homebrew/versions
$ brew tap homebrew/dupes
$ brew tap homebrew/php
$ brew update

PHP 5.6のインストール

$ brew install homebrew/php/php56-amqp

色々とインストールされます

TerminalをRestart

$ php -v
PHP 5.6.27 (cli) (built: Oct 15 2016 09:29:55) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

Composer本体をインストールする方法の1つ

前置き

Laravel 5.2を使うことになり、LaravelはComposerを使ってインストールするようなので、Composerをインストールしてみた。

環境

Composerとは

  • PHPのパッケージ管理システム。依存性を含めて管理できるので、とても楽。
  • RubyにおけるBundlerやJavaScriptにおけるnpmと同様のもの

参考

手順

composerをインストールして、通常パスが通ってるディレクトリに移動させます

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

疎通確認

$ composer                                                                                                           
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.2.2 2016-11-03 17:43:15

Composerのアップデート

$ composer self-update

d3.js初心者が3時間でRails5.1に複数のグラフを実装した際に参考にした記事

最新版は v4 ですが、参考になる資料がまだ潤沢ではないので、 v3 を使いました。 作ったグラフを行動軌跡図と棒グラフです。

References

Path

Grouped Bar Chart

既存プロジェクトをRails5.1にアップデートしたので、webpackerを使って、楽できる感じの JS(ES6)とRailsの開発環境を構築してみた

qiita.com

経緯

環境を以下のようにアップデートしたので、webpackerを導入しました。 - Rails 5.1.3 - Ruby 2.4.1

既存プロジェクトにwebpackerを導入する

  • 基本的に README を見れば問題ないです
    • またのコマンドを打てば、サンプル(大元になるガイド)ファイルも出力してくれるので、乗っかればやりやすいです。
gem 'webpacker', '~> 2.0'
# OR if you prefer to use master
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'

gem 'foreman'
bundle install
./bin/rails webpacker:install

vueを導入

  • elmやreactも導入するコマンドがあります
./bin/rails webpacker:install:vue
const { env, settings } = require('../configuration.js')

const isProduction = env.NODE_ENV === 'production'
const extractCSS = !settings.dev_server.hmr

module.exports = {
  test: /\.vue$/,
  loader: 'vue-loader',
  options: {
    extractCSS: isProduction || extractCSS
  }
}

既存環境との両立

  • 既存の古いJSもたくさんあったので、一気にwebpacker環境に持っていくのは大変そうだったため、共存させつつ、少しずつ移行していくことにしました。
  • webpacker環境のファイル構成を app/frontend 以下に構築します。
  • app/frontend/packs 以下のファイルを、 public/packs 以下に、 Compileした後に 出力します。
default: &default
  source_path: app/frontend
  source_entry_path: packs
  public_output_path: packs
  cache_path: tmp/cache/webpacker

.
.
.
// Note: You must restart bin/webpack-dev-server for changes to take effect

const webpack = require('webpack');
const merge = require('webpack-merge');
const sharedConfig = require('./shared.js');
const { settings, output } = require('./configuration.js');

module.exports = merge(sharedConfig, {
  devtool: 'cheap-eval-source-map',

  output: {
    pathinfo: true
  },
.
.
.


});

viewファイルからのインクルード

= stylesheet_pack_tag 'hoge/style/main' # /public/packs/hoge/style/main.css を読みます
= javascript_pack_tag 'hoge/main' # /public/packs/hoge/main.js を読みます
= javascript_include_tag 'http://d3js.org/d3.v3.min.js' # おなじみのタグも使えます

開発の為の工夫

webpacker環境下のファイルを編集したらブラウザがライブリロードされてほしい

  • rails s と合わせて、 webpackerもwatchしたまま走らせたい
    • formanを使って、両方を一つの npm run script で叩く
web: bundle exec rails s
# watcher: ./bin/webpack-watcher
webpacker: ./bin/webpack-dev-server
{
  "scripts": {
    "dev": "bundle install && bundle exec foreman start -f Procfile.dev",
    "build": "bundle exec rails webpacker:compile",
  },
}

開発の際は

yarn dev を叩いて開発

eslintを入れる

yarn add babel-eslint eslint eslint-config-standard eslint-friendly-formatter eslint-loader eslint-plugin-html eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard --D
module.exports = {
  test: /\.(js|ts|vue)$/,
  loader: 'eslint-loader',
  enforce: 'pre',
  options: {
    formatter: require('eslint-friendly-formatter')
  }
}

でもwebpackerに乗せたくなかったので、コメントアウトしておきました。

.eslintrc はいい感じに

UnityのTutorialを1つこなしてみた

前置き

  • Unityはじめました(今日から)
  • 早速作りたいものを作ろうとしたけど、Unityの操作に自信をなくしてTutorialからやり直すことにしました

やったこと

Tutorialの中でも一番最初にやるであろうものに取り組みました。

f:id:susanne:20170706223544p:plain

unity3d.com

ビデオレクチャーになっていてショートムービーを8本見て、簡単な玉転がしアプリを作りました。

www.youtube.com

学んだこと

  • Unity IDEの使い方を少々
  • SceneとObject(Model)とMaterialの操作の仕方を少々
  • ScriptとGUIのつなぎ方を少々
  • UIの設置の方法

感想

  • 今のところ難しく感じませんでしたが、今後どうなるかって感じです
  • 物理関係のロジックや、ゲームロジックに関してはUnityであってもなくても同様に実装できるっぽいので、問題なさそうです
    • むしろライブラリが整ってて楽かも?
  • C#ってこんなに書きづらかったっけ?というモヤモヤ…

わんこを見て癒やされます

f:id:susanne:20160624221446j:plain