mysqlの権限設定

グローバルレベル
GRANT ALL ON *.* TO user;
GRANT SELECT, INSERT ON *.* TO user;

データベースレベル
GRANT ALL ON db_name.* TO user;
GRANT SELECT, INSERT ON mydb.* TO user;

テーブルレベル
GRANT ALL ON db_name.table_name TO user;
GRANT SELECT, INSERT ON db_name.mytbl TO user;

カラムレベル
GRANT SELECT (col1), INSERT (col1, col2) ON db_name.table_name TO user;

実際にやってみましょう。
mysql> create user saru@localhost identified by ‘monkey’;
Query OK, 0 rows affected (0.59 sec)

mysql> show grants for saru@localhost;
+————————————————————————————————————-+
| Grants for saru@localhost |
+————————————————————————————————————-+
| GRANT USAGE ON *.* TO ‘saru’@’localhost’ IDENTIFIED BY PASSWORD ‘*A5892368AE83685440A1E27D012306B073BDF5B7’ |
+————————————————————————————————————-+
1 row in set (0.09 sec)

mysql> grant create on *.* to saru@localhost;
Query OK, 0 rows affected (0.05 sec)

mysql> show grants for saru@localhost;
+————————————————————————————————————–+
| Grants for saru@localhost |
+————————————————————————————————————–+
| GRANT CREATE ON *.* TO ‘saru’@’localhost’ IDENTIFIED BY PASSWORD ‘*A5892368AE83685440A1E27D012306B073BDF5B7’ |
+————————————————————————————————————–+
1 row in set (0.00 sec)

なるほど、grant userの後に、grantで権限を付けるわけですね。
ちょっと感動しました。

RDSのエラーログ

cliでRDSのログを確認するには、describe-db-log-files

aws rds describe-db-log-files --db-instance-identifier rds001

jsonから、ログのみに変更することも可

aws rds describe-db-log-files --db-instance-identifier rds001 --filename-contains error --output text

エラーログはmysql-error-running.logという名前で1時間ごとに出力される。
エラーログの中身は download-db-log-file-portionというコマンドを使う。

aws rds download-db-log-file-portion --db-instance-identifier rds001 --log-file-name error/mysql-error-running.log.6

– Error logs are written to the mysql-error.log file.
– mysql-error.log is flushed every 5minutes.
– The flushed content is added to mysql-error-running.log
– mysql-error-running.log is rotated hourly.
– Rotaed logs are kept for 24 hours.
– Each log file has UTC time appended to the file name(% H of rotated UTC time)
– Writing to the error log is only performed at startup, at shutdown, and at error detection.

なんだこりゃ、超重要やんけ。

mysql show processlist

It is a command to view the list of currently running porcesses.
Used it to confirm that the batch is moving, or when didn’t get back a heavy query.

まず、show processlistとします。

mysql> show processlist
-> ;
+—-+——+———–+——+———+——+——-+——————+
| Id | User | Host | db | Command | Time | State | Info |
+—-+——+———–+——+———+——+——-+——————+
| 2 | root | localhost | demo | Query | 0 | init | show processlist |
+—-+——+———–+——+———+——+——-+——————+
1 row in set (0.21 sec)

続いて、別のユーザでログインしてみます。
mysql> show processlist;
+—-+——+———–+——+———+——+——-+——————+
| Id | User | Host | db | Command | Time | State | Info |
+—-+——+———–+——+———+——+——-+——————+
| 2 | root | localhost | demo | Query | 1 | init | show processlist |
| 3 | root | localhost | test | Sleep | 13 | | NULL |
+—-+——+———–+——+———+——+——-+——————+
2 rows in set (1.67 sec)

なるほど、状態が分かりますね。素晴らしい。

show grants

ユーザー権限の確認方法

show grants for [username]@[servername];

mysql> show grants for ‘root’@’localhost’;
+———————————————————————+
| Grants for root@localhost |
+———————————————————————+
| GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ WITH GRANT OPTION |
| GRANT PROXY ON ”@” TO ‘root’@’localhost’ WITH GRANT OPTION |
+———————————————————————+
2 rows in set (0.05 sec)

mysql> show grants
-> ;
+———————————————————————+
| Grants for root@localhost |
+———————————————————————+
| GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ WITH GRANT OPTION |
| GRANT PROXY ON ”@” TO ‘root’@’localhost’ WITH GRANT OPTION |
+———————————————————————+
2 rows in set (0.00 sec)

なるほどねー

Net::Amazon::S3::Signature::V4

cpanのサイトを見ます。
https://metacpan.org/pod/Net::Amazon::S3::Signature::V4Implementation

>Net::Amazon::S3::Signature::V4Implementation – Implements the Amazon Web Services signature version 4, AWS4-HMAC-SHA256

>This module signs an HTTP::Request to Amazon Web Services by appending an Authorization header. Amazon Web Services signature version 4, AWS4-HMAC-SHA256, is used.
なるほど、ヘッダね。
Net::Amazon::Signature::V4を使います。

use Net::Amazon::Signature::V4;

my $sig = Net::Amazon::signature::V4->new($access_key_id, $secret, $endpoint, $service);
my $req = HTTP::Request->parse( $request_string );
my $signed_req  $sig->sign($req);
...

ふむふむ、特に問題なさそうですね。。

とういか、AWSのSDK, CLIの使用に関するページだと、当然の如くperlはないな。ひどいな。。

Laravel 5’s Soft delete

Laravel 5’s Eloquent has a function called SoftDeletes that performs logical deletion instead of physically deleting data from a DB table.

If you do this soft delete, data will not be deleted from the table but it will not be able to be pulled by ordinary SELECT etc. It will behave the same as deleting it.
This function allows you to extract information once it is deleted, when it is needed again.

なるほどー、これ結構便利かも。

use Illuminate\Database\Eloquent\SoftDeletes;

class User extends Eloquent {
	use SoftDeletes;

	protected $dates = ['deleted_at'];
}

モデルに上記のように記述を追加し、SoftDeletesを使えるようにする。削除された場合は、deleted_atカラムにタイムスタンプがセットされる。

なるほどね。

binlogの保存期間

– RDSのbinlogの保存期間はデフォルト値では、NULLになっている。

binlogの保存期間を変更する際は、call mysql.rds_set_configurationで変更する。ふむふむ。

mysql> call mysql.rds_set_configuration('binlog retention hours', 24);

APNsとは

What is APNs?
Apple Push Notification Service (APNs) is the core of remote notification functionality. It is a robust, secure, and very efficient service for application developers to deliver information to iOS(and indirectly watchOS), tvOS, and macOS devices.
なるほど。

Datepickerの範囲指定

まず、普通のdatepicker

<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">

<input type="text" name="date" value="">
<script>
$("[name=date]").datepicker({
    // YYYY-MM-DD形式で入力されるように設定
    dateFormat: 'yy-mm-dd'
});
</script>

特に問題ありません。

で、これを今日からにするには、minDateを0dに指定します。

<script>
$("[name=date]").datepicker({
    // YYYY-MM-DD形式で入力されるように設定
    dateFormat: 'yy-mm-dd',
    minDate: '0d'
});
</script>

年末を指定するにはどうするかだな。
+1y -1dだと駄目みたい。
ちょっとあかんあー

倍マーチンアルゴリズムと条件分岐

例えば、持ってるポジションから逆方向に0.6%以上動いたら、倍マーチンを打つと仮定しよう。

ポジション:109.958円
現在値:109.327円

# 手持ち資金が50万円とする
$cash = 500000;
$leverage = 25;

$lot = 200000;
$long = 1;
$short = -1*0;

# ドル円価格
$dollyen = 109.958;
# 現在価格
$current = 109.327;

if(abs($current – $dollyen)/$current > 0.006){
echo “倍マーチン”;
} else {
echo “ポジション:” . $dollyen.”円
“;
echo “ロット:”. $lot. “
“;
$sum = $dollyen * $lot * $long;
$multi = $sum / $cash;
if($multi < 25){ echo "投資額:" .$sum. "円
“;
echo “

現在値:” . $current . “円

“;
$total = $current * $lot * $long;
$deposit = $cash + ($total – $sum);
echo “口座残高:” . $deposit . “円

“;
$rmargin = $total * 0.04;
echo “必要証拠金:” .$rmargin . “円
“;
$mrate = ($cash + ($total – $sum)) / $rmargin;
echo “証拠金維持率:” .$mrate * 100 . “%
“;

if ($mrate < 0.5){ echo "ロスカットが発生しました"; } else { echo "※証拠金維持率が50%を割とロスカットとなります。ロスカットに注意してください。"; } } else { echo "レバレッジを25倍以下に抑えてください"; } } [/php]

例えばこれ、連続3回までの倍マーチン自動アルゴリズムと考えると、
1 + 2 + 4 + 8 = 15 だから、
初回のエントリーは、現在資産 * 25 / 15 = 1.6
手持ちが50万だったら、1ロットってことになる。
つまり、ドル円で考えるなら、種が60万くらいないと、連続3回の倍マーチンが成立しないってことだ。
1ロットで0.6%なら6000円くらい。手持ち50万で6000円の勝ち負けなら、許容範囲というか、妥当なところだろう。

倍マーチンはとりあえず0.6%としておこう。
考えなければいけないのは、
初回のエントリーのタイミングと、利確のタイミング。
倍マーチンのラインが0.6%なら、損切の2倍ルールを応用すると、1.2%で利確、となる。しかし、0.6の1.2%だとドル円だと厳しいな。。あんまりチャリンチャリンしなさそうだ。
エントリーのタイミングは、フィボナッチ、移動平均線など議論しつくされているからな~ ただ、自動売買のエントリーとなると話がちょっと違うか。イメージとしては標準偏差を使うイメージなんだが。。