ksino's diary

覚えたことを忘れないように、小さなことでも書いていく。

Ubuntu 16.04にpyenvを導入し、Pythonを切り替えられるようにする

勉強しようしようと思いつつ長らく手がついていなかったPython。一念発起して勉強することにしました。とりあえず書籍を購入。

みんなのPython 第4版

みんなのPython 第4版

導入手順についてはいろいろ調べてみた結果、pyenvなるものが便利そうだったので使ってみます。

pyenvの導入

$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo '#pyenv' >> ~/.bashrc
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc

導入後、シェルの再起動

$ exec "$SHELL"

導入できるバージョンのリストアップ

$ pyenv install -l

指定のバージョンを導入

$ pyenv install anaconda3-5.0.1 

導入されているバージョンの確認

$ pyenv versions

指定したバージョンを有効化

$ pyenv global anaconda3-5.0.1 
$ python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

ハンドスピナー買ってみました。

巷で人気とのことで、いろいろ見てたらほしくなってしまい…。
amazonで各商品のレビューを調べてみても、怪しげな中華コメントが氾濫していて、どれを買えばいいものやら。
悩んだ末に、若干お高めのものを選びました。
f:id:ksino:20170512215135j:plainf:id:ksino:20170512215206j:plain
金属製で重厚感があり、回転もなめらかで満足です。

飯盒でオイルサーディン飯を作る

見た目は悪いけど美味しく作れたのでとりあえずメモ。
もう一度作ったら写真も載せる。。。

使用した用具

  • 炊飯に使用

  • 具材の調理に使用

trangia(トランギア) メスティン TR-210 【日本正規品】

trangia(トランギア) メスティン TR-210 【日本正規品】

  • コンロ

  • 燃料は100均の固形燃料(旅館の料理とかでよく出てくる青いやつ。25g、3個入り)

食材

  • 米1合
  • オイルサーディン缶詰
  • ネギ適量
  • 醤油、料理酒 各大さじ1杯

調理手順

ご飯を炊く

  1. 米を研ぎ、水200mlとともにロスコの飯盒に投入。30分程度待って吸水させる。(固形燃料での飯盒炊飯は吸水が重要らしい)
  2. コンロに固形燃料をセットし、飯盒を火にかける。
  3. 火が消えるまで待ち(ただ待つだけ!)、消えたら飯盒を逆さにしてタオル等にくるんで蒸らす。
  4. 蒸らしている間に具材を調理。

具材の調理

  1. トランギアメスティンにオイルサーディン缶詰をすべて投入。汁も入れる。
  2. コンロに新しい燃料をセットし、火にかける。
  3. サーディンを炒め(身が崩れても気にしない)、醤油と料理酒を投入。引き続き、水分が軽く飛ぶ程度に炒める(煮詰める?)。

盛り付け

  1. ご飯を炊いた飯盒に具材とネギを投入。見た目を気にせずぐるぐるかきまぜて出来上がり。

反省

  • 油っこいのが苦手な人はオイルサーディン缶詰の汁を減らした方が良さそう。
  • ネギも一緒に炒めてもいいかも。あるいは万能ネギの方がいいかも。。
  • 固形燃料25gの燃焼時間は炊飯には調度良いが、具材の調理に対しては長いのでもったいない。

Ubuntu 16.04 LTSにMySQLをインストールする

インストール

sudo apt update
sudo apt install mysql-server mysql-client

インストール中にrootユーザのパスワード入力を求められる。

DBの作成

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu)

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.

mysql> create database test_db;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on test_db.* to 'user' identified by 'password';
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test_db            |
+--------------------+
5 rows in set (0.03 sec)

mysql> quit
Bye

DBを使用してみる

$ mysql -u user -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.16-0ubuntu0.16.04.1 (Ubuntu)

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.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test_db            |
+--------------------+
2 rows in set (0.00 sec)

mysql> connect test_db;
Connection id:    6
Current database: test_db

mysql> create table emp (id INT, name varchar(20));
Query OK, 0 rows affected (0.32 sec)

mysql> insert into emp values(1, 'aaa');
Query OK, 1 row affected (0.08 sec)

mysql> insert into emp values(2, 'bbb');
Query OK, 1 row affected (0.04 sec)

mysql> select * from emp;
+------+------+
| id   | name |
+------+------+
|    1 | aaa  |
|    2 | bbb  |
+------+------+
2 rows in set (0.00 sec)

mysql> quit
Bye

MySQLの停止/起動/再起動/ステータス

$ sudo systemctl stop mysql
$ sudo systemctl start mysql
$ sudo systemctl restart mysql
$ sudo systemctl status mysql

自動起動の無効化/有効化

$ sudo systemctl disable mysql
$ sudo systemctl enable mysql

半年ほど前に流行ったズンドコキヨシをJSで

遅ればせながら、いまごろ知ったのでやってみる。

var array = [];
for (var i = 0; ; i++) {
  var s;
  var random = Math.round(Math.random());
  if (random == 0) {
    s = 'ズン';
  } else {
    s = 'ドコ';
  }
  console.log(s);
  array.push(s);
  if (array.length > 5) {
    array.shift();
  }

  if (array.join('') === 'ズンズンズンズンドコ') {
    console.log('キ・ヨ・シ!');
    break;
  }
}