Carbonを使ってみよう

require "vendor/autoload.php";

use Carbon\Carbon;

$dt = new Carbon();
echo $dt . "<br>";

$dt = Carbon::now();
echo $dt . "<br>";

$dt = new Carbon("2019-05-09");
echo $dt . "<br>";

$dt = Carbon::today();
echo $dt . "<br>";

$dt = Carbon::tomorrow();
echo $dt . "<br>";

$dt = Carbon::yesterday();
echo $dt . "<br>";

$dt = Carbon::parse("2019-05-07 10:30:30");
echo $dt . "<br>";

2019-05-07 20:54:17
2019-05-07 20:54:17
2019-05-09 00:00:00
2019-05-07 00:00:00
2019-05-08 00:00:00
2019-05-06 00:00:00
2019-05-07 10:30:30

なるほどー、確かに使いやすいかもね~

Carbon and php

Carbon is a package that extends PHP’s DataTime class, making it possible to manipulate dates and times more intuitively and more simply.

なるほど、道理でLaravelに使われている訳だ。

composerを入れます。

[vagrant@localhost test]$ curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 1.8.5) successfully installed to: /home/vagrant/local/app/test/composer.phar
Use it: php composer.phar

続いて、carbonを入れます。
[vagrant@localhost test]$ php composer.phar require nesbot/carbon
No composer.json in current directory, do you want to use the one at /home/vagrant/local/app? [Y,n]? y
Using version ^2.17 for nesbot/carbon
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
– Installing symfony/polyfill-mbstring (v1.11.0): Loading from cache
– Installing symfony/contracts (v1.0.2): Loading from cache
– Installing symfony/translation (v4.2.8): Downloading (100%)
– Installing nesbot/carbon (2.17.1): Downloading (100%)
symfony/contracts suggests installing psr/cache (When using the Cache contracts)
symfony/contracts suggests installing psr/container (When using the Service contracts)
symfony/contracts suggests installing symfony/cache-contracts-implementation
symfony/contracts suggests installing symfony/service-contracts-implementation
symfony/translation suggests installing symfony/config
symfony/translation suggests installing symfony/yaml
symfony/translation suggests installing psr/log-implementation (To use logging capability in translator)
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files


Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.

ん、間違えたか。jsonの使うところが違うな。

やり直します。
[vagrant@localhost test]$ php composer.phar require nesbot/carbon
No composer.json in current directory, do you want to use the one at /home/vagrant/local/app? [Y,n]? n
Using version ^2.17 for nesbot/carbon
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 4 installs, 0 updates, 0 removals
– Installing symfony/polyfill-mbstring (v1.11.0): Loading from cache
– Installing symfony/contracts (v1.0.2): Loading from cache
– Installing symfony/translation (v4.2.8): Loading from cache
– Installing nesbot/carbon (2.17.1): Loading from cache
symfony/contracts suggests installing psr/cache (When using the Cache contracts)
symfony/contracts suggests installing psr/container (When using the Service contracts)
symfony/contracts suggests installing symfony/cache-contracts-implementation
symfony/contracts suggests installing symfony/service-contracts-implementation
symfony/translation suggests installing symfony/config
symfony/translation suggests installing symfony/yaml
symfony/translation suggests installing psr/log-implementation (To use logging capability in translator)
Writing lock file
Generating autoload files

OK、上手くいきましたね^^
では早速使っていきましょう~

CloudWatchを使っていこう

まずコンソールにログインします。

ダッシュボードに入ります。

なるほど、確かに魅力あるね。

メトリクスを押下します。

ほほう、インフラエンジニアが好きそうや。

ログも見れますよ、と。なるほどねー

CloudWatch

CloudWatch is a monitoring service for AWS resources and applications running on AWS. You can collect and monitor metrics and log files of various AWS services and set alarms. When you start the corresponding AWS service, data points are regularly sent to CloudWatch, so you can view and analyze the metrics on a graphical screen without being particularly aware. With custom metrics, you can use graphical graphs for metrics collected from your own application. Using the alarm function, not only notification using SNS, addition of EC2 instance by Auto Scaling, or recovery of EC2 instance is also possible.

Data points, metrics
When you start a supported AWS service, data points (monitoring data) are sent to CloudWatch stores data points in metrics.
Metrics can be thought of as monitored variables, and data points can be thought of as the values of variables over time. Data points are not necessarily related to AWS services. It may be the data sent by the script created by the user. In other words, the metric may be the CPU utilization of an EC2 instance, or it may be the response speed of the application or room temperature.
Metrics are identified by name, namespace, and one or more dimensions. Metrics are stored for two weeks.

Name space
Namespaces store metrics. The metric name [CPUUtilization] is used in EC2 and RDS. The namespace [AWS/EC2] or [AWS/RDS] is used as one element to identify metrics.

Dimension
Dimensions are categories of metrics. Statistical monitoring is possible using dimensions. Use the dimension [InstanceId] to check the metrics of an instance. You can use the dimension [AutoScalingGroupName] to monitor data for each autoscaling group.

EC2 Metrics Dimension

AutoScalingGroupName
ImageId
InstanceId
InstanceType

では早速触っていきましょう。

PHP Excel download

$template_path = "entrysheet.xlsm";
$filename = "職務経歴書.xlsm";
$extension = pathinfo($template_path)['extension'];
$file_size = filesize($template_path);

header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Length: {$file_size}");
header("Content-Disposition: attachment; filename={$filename}");
readfile($template_path);

openxmlformatsを使うのかー
なるほどねー これでトップ側はOKかな。

Phone number

The size attribute specifies the width of the input field in characters.
The width of 17 characters is specified.

<p>
								電話番号(必須)<br>
								<input class="long-text" value="080-1234-5678" type="tel" size="17" required>
							</p>

うん、よい感じ。

Validate email address with JavaScript

Function to check if valid e-mail address format in input form etc.

function checkEmailAddress(str){
	if(str.match(/.+@.+\..+/)==null){
		return false;
	} else {
		return true;
	}
}

正規表現ですね。
input type=”email”でも良いような気がしますが。。

Specifying multiple elements in CCS

Specify CCS by separating element name + class name with comma.
The same style can be applied by separating element name + class name with comma.
[ccs]
#right-contents input[type=”text”], #right-contents input[type=”email”], #right-contents [type=”number”] {
width: 45%;
height: 3.5%;
border-radius: 5px;
background-color: #a9a9a9;
color: #f5f5f5;
padding-left: 3%;
font-size: 15px;
}
[/ccs]

なるほど~

Radio button selected

Can create a radio button by specifying type=”radio” for input element.

Enter “checked” to specify the selected state

<p id="radio">
								お仕事を探すエリア<br>
								<label><input name="job-place" class="radio" type="radio" checked>関東</label>
								<label><input name="job-place" type="radio">関西</label>
								<label><input name="job-place" type="radio">名古屋</label>
								<label><input name="job-place" type="radio">その他</label>
							</p>

ほう、いいんじゃーないでしょうか!?