setting virtual host

# sudo cat /etc/httpd/conf.d/hoge.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/tv
DirectoryIndex index.html index.php
ServerName www.hoge
ServerAlias on-tv.fun
CustomLog logs/hoge-access.log common
ErrorLog  logs/hoge-error.log
AddDefaultCharset UTF-8
<Directory "/var/www/html/tv/">
AllowOverride All
</Directory>
</VirtualHost>

# /etc/init.d/httpd graceful

Not reflected unless restart.
Also modify google developer console.

headless chrome 2

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl.google.com/linux/linux_signing_key.pub

$ sudo yum update

$ sudo yum install google-chrome-stable

rpm -Va –nofiles –nodigest

[vagrant@localhost ~]$ google-chrome –disable-setuid-sandbox –no-sandbox –headless –disable-gpu –dump-dom https://www.chromestatus.com/
-bash: google-chrome: コマンドが見つかりません

なんじゃこりゃーーーーーーーーーーーー

Headless chrom on CentOS

I would like to operate headless chrome on CentOS.

About Headless Chrome
It is a mode to operate without displaying the secreen, which will be available from Google Chrome 59. Useful for automated testing and web scraping.

Just because it’s Headless doesn’t change much from using regular Chrome. Control Chrome from Selenium through ChromeDriver. Pass ChromeOptions as an argument when creating a Chrome WebDriver, and specify the Chrome path and arguments to be executed in it.

Install required library.

$ sudo yum install -y libX11 GConf2 fontconfig
...
依存性関連をインストールしました:
  ConsoleKit.x86_64 0:0.4.1-6.el6      ConsoleKit-libs.x86_64 0:0.4.1-6.el6
  ORBit2.x86_64 0:2.14.17-7.el6        dbus.x86_64 1:1.2.24-9.el6
  eggdbus.x86_64 0:0.6-3.el6           libIDL.x86_64 0:0.8.13-2.1.el6
  polkit.x86_64 0:0.96-11.el6_10.1     sgml-common.noarch 0:0.6.3-33.el6

完了しました!

ほう。

[vagrant@localhost ~]$ cd /etc/yum.repos.d
[vagrant@localhost yum.repos.d]$ sudo touch google-chrome.repo
[vagrant@localhost yum.repos.d]$ ls
CentOS-Base.repo jenkins.repo remi-glpi92.repo
CentOS-Debuginfo.repo kibana.repo remi-glpi93.repo
CentOS-Media.repo logstash.repo remi-php54.repo
CentOS-Vault.repo mariadb.repo remi-php70.repo
CentOS-fasttrack.repo mysql-community-source.repo remi-php71.repo
elasticsearch.repo mysql-community.repo remi-php72.repo
epel-testing.repo nginx.repo remi-php73.repo
epel.repo nodesource-el.repo remi-safe.repo
google-chrome.repo remi-glpi91.repo remi.repo

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/x86_64
enabled=1
gpgcheck=1
gpgkey=https://dl.google.com/linux/linux_signing_key.pub

$ sudo yum update

Google Map API

<!DOCTYPE html>
<html lang="ja">
<head>
	<meta charset="utf-8">
	<title>GoogleMap</title>
	<script src="http://maps.google.com/maps/api/js?key={api code}&language=ja"></script>
	<style>
	html {
		height:100%;
	}
	body {
		height:100%;
	}
	#map {
		height:100%;
		width:100%;
	}
</style>
</head>

<body>
<div id="map"></div>
<script>
var MyLatLng = new google.maps.LatLng(35.6811673, 139.7670516);
var Options = {
	zoom: 15,
	center: MyLatLng,
	mapTypeId: 'roadmap'
};
var map = new google.maps.Map(document.getElementById('map'), Options);
</script>
</body>
</html>

Google Translation Toolbar settings

There are times when I am dealing with multiple languages at work, and when want to translate all at once to turn on pop of “このページを翻訳しますか?”.

Open google chrome setting screen.

Next will look at the detailed setting.

Check the section “Use translation tools on pages other than my mother tongue”.

As offshore development increases, opportunities to use translation tools increase.

PHP google translate API

How to use PHP Google translation?

mkdir a directory and clone the repo

[vagrant@localhost translation]$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
Initialized empty Git repository in /home/vagrant/app/translation/php-docs-samples/.git/
remote: Enumerating objects: 79, done.
remote: Counting objects: 100% (79/79), done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 10046 (delta 27), reused 35 (delta 9), pack-reused 9967
Receiving objects: 100% (10046/10046), 10.07 MiB | 530 KiB/s, done.
Resolving deltas: 100% (6246/6246), done.

[vagrant@localhost php-docs-samples]$ ls
CONTRIBUTING.md bigtable error_reporting logging trace
LICENSE cloud_sql favicon.ico monitoring translate
README.md compute firestore pubsub video
appengine datastore iap spanner vision
asset debugger iot speech
auth dialogflow jobs storage
bigquery dlp kms testing
bigquerydatatransfer endpoints language texttospeech

translate.php

/**
 * Copyright 2016 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require __DIR__ . '/vendor/autoload.php';

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

$application = new Application('Google Cloud Translate API');

// Add Detect Language command
$application->add(new Command('detect-language'))
    ->setDescription('Detect which language text was written in using Google Cloud Translate API')
    ->addArgument('text', InputArgument::REQUIRED, 'The text to examine.')
    ->setHelp(<<<EOF
The <info>%command.name%</info> command detects which language text was written in using the Google Cloud Translate API.

    <info>php %command.full_name% "Your text here"</info>

EOF
    )
    ->setCode(function ($input, $output) {
        $text = $input->getArgument('text');
        require __DIR__ . '/src/detect_language.php';
    });

// Add List Codes command
$application->add(new Command('list-codes'))
    ->setDescription('List all the language codes in the Google Cloud Translate API')
    ->setHelp(<<<EOF
The <info>%command.name%</info> command lists all the language codes in the Google Cloud Translate API.

    <info>php %command.full_name%</info>

EOF
    )
    ->setCode(function ($input, $output) {
        require __DIR__ . '/src/list_codes.php';
    });

// Add List Languages command
$application->add(new Command('list-langs'))
    ->setDescription('List language codes and names in the Google Cloud Translate API')
    ->addOption('target-language', 't', InputOption::VALUE_REQUIRED,
        'The ISO 639-1 code of language to use when printing names, eg. \'en\'.')
    ->setHelp(<<<EOF
The <info>%command.name%</info> lists language codes and names in the Google Cloud Translate API.

    <info>php %command.full_name% -t en</info>

EOF
    )
    ->setCode(function ($input, $output) {
        $targetLanguage = $input->getOption('target-language');
        require __DIR__ . '/src/list_languages.php';
    });

// Add Translate command
$application->add(new Command('translate'))
    ->setDescription('Translate text using Google Cloud Translate API')
    ->addArgument('text', InputArgument::REQUIRED, 'The text to translate.')
    ->addOption('model', null, InputOption::VALUE_REQUIRED, 'The model to use, "base" for standard and "nmt" for premium.')
    ->addOption('target-language', 't', InputOption::VALUE_REQUIRED,
        'The ISO 639-1 code of language to use when printing names, eg. \'en\'.')
    ->setHelp(<<<EOF
The <info>%command.name%</info> command transcribes audio using the Google Cloud Translate API.

    <info>php %command.full_name% -t ja "Hello World."</info>

EOF
    )
    ->setCode(function ($input, $output) {
        $text = $input->getArgument('text');
        $targetLanguage = $input->getOption('target-language');
        $model = $input->getOption('model');
        if ($model) {
            require __DIR__ . '/src/translate_with_model.php';
        } else {
            require __DIR__ . '/src/translate.php';
        }
    });

// for testing
if (getenv('PHPUNIT_TESTS') === '1') {
    return $application;
}

$application->run();

Google Translate API Pricing

This is a Google Cloud Translating API page
Cloud Translation API document

I would like to Transtaion API for slack.

function that to make
– when user write Japanese in slack, slack bot change sentence into English.

Official document
0-1 billion characters(1,000,000,000)
Translation $20 per 1,000,000 characters
Language Detection $20 per 1,000,000 characters

What is language detection?
-> Determine what language is.

What should I do?
-> Check PHP sample for google translation API.

Here is GHE repository and get code.
https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/translate

Translation API is convenient, but it feel like somewhat expensive.

エンジニアが断捨離するとこうなる(その2)

そろそろ断捨離する物がなくなってきたので、行動面での断捨離を考えたい。
エンジニアは合理的であるべき。とすると、無駄な行動もバッサリ捨てたい。
で、何を捨てたいか?

コンビニ
– コンビニで立ち読みするのが癖で、直したい。 ザファブル、アフロ田中、BLUE GIANT、フルーツ宅急便が気になって仕方がない。
→ 漫画って無意識に思考に影響与えるから、できるだけ読みたくないなー
→ この悩みを解決するソフトウェアを作りたい
案1) コンビニに入ると、GPSで地震警報並みの警報がスマホから流れる
案2) コンビニに入ると、GPSで自動的にクレジットカードで課金されるようにする
案3) rizapのように、毎日コンビニに入った回数を誰かに報告する

あ、GoogleのGoogle Place APIというのがあるらしい。これ、ガチで使ってみたい。
https://developers.google.com/places/

断捨離をプログラミングで解決する、そういう流れにしたいですねー

Google FormのURLを他のユーザーに送る

割と簡単にできます。
(1)Google Formをつくる
(2)画面右上の「送信」ボタンをクリックします。

(3)ポップアップが表示されたら、メールアイコンの横のリンクアイコンをクリックします

(4)リンクURLが表示されます