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>

UTF8 and Shift_JIS

Shift_JIS
Merit
-The number of bytes consumed is relatively small.
-Code that can be read on domestic mobile phones.

Demerit
It is garbled by how to use it.
Since encoded data often contains control characters, they may malfunction or be garbled in environments where they are not assumed.
The character type is about 9000.

UTF-8
The character range is wide and the characters of any contry can not be garbled.
It can be read by default in almost any PC environment.

PHPUnit

Using PHPUnit does not mean that you can test any source code. You should have designed your classes to be easy to test. Also, there are places where you can not put them into Unit test even if you have designed that way. If you can not put in the Unit test, you must divide it. Rather, how much code can I put in a unit test?

Unit test here refers to “method-only test” and “class-only test”.

object
setting value
external system(DB, API, file, command)
We separate those “dense dependencies” and “design the class”, “implement the class” and “make a test of the class”. “Dense dependence” refers to, for example the following.

The method using the object directly news the object(depends on the object)
Directly reference configuration files(file_get_contents, json_decode) in logic(depends on file system)
Where file(file_put_contents) directly in logic(depends on file system)
Peek directly into DB(mysqli, PDO) in logic(depends on network and database)
Direct API(file_get_contents, curl) in logic(depends on network and API)
Hit command(system) directly in logic(depends on OS)

namespace UnitTest\Sample;

class Hoge {
	protected $settings = null;
	protected $fileManager = null;
	protected $dbManager = null;
	protected $apiManger = null;
	protected $commandManager = null;

	public function __construct (
		$settings,
		$fileManager,
		$dbManager,
		$apiManager,
		$commandManager){

		$this->settings = $settings;
		$this->fileManager = $fileManager;
		$this->dbManager = $dbManager;
		$this->apiManager = $apiManager;
		$this->commandManager = $commandManager;
		}
}
namespace UnitTest\Sample;
class DatabaseSession
{
		private $connection = null;
		public function __construct($connection)
		{
				$this->connection = $connection;
		}

		public function save($tableName, $object)
		{
				if(!$tableName || !is_scalar($tableName)|| !$object){
						throw new \InvalidArgumentException('$tableName or $object is empty or invalid type');

				}
				if(is_object($object) && $object instanceof \stdClass){
						$ojbect = (array)$object;
				}

				if(!is_array($object)){
						throw new \InvalidArgumentException('$object must be array or \stdClass');
				}

				$values = array_values($object);
				$tableName = '`' . str_replace('`', '\\`', $tableName).'`';
				$columnBlock = implode(',', array_map(function($col) {return '`' . str_replace('`', '\\`',  $col) . '`';}, array_keys($object)));
		        $valueBlock  = implode(',', array_map(function($val) {return '?'; }, $values));
		        $valueMarker = implode('', array_map(function($val) {return strval(intval($val)) === strval($val) ? 'i' : 's'; }, $values));
		        $stmt = $this->connection->prepare("REPLACE INTO $tableName ($columnBlock) VALUES ($valueBlock);");
		        array_unshift($values, $valueMarker);
		        $pointer = array();
		        foreach($values as $key => $val){
		        	$pointer[$key] = &$val;
		        }
		        call_user_func_array(array($stmt, 'bind_param'), $pointer);
		        $stmt->execute();
		        $stmt->close();
		}	
}

Diffrence between external and internal design

External Design
External design is also called basic design or external design, and generally up to external design is included in the upstream process.
The basic design of the system is performed based on the functions, performance, and constraints determined in the requirements definition. Basically, the specifications for the user are designed, such as determining the specifications of the interface part that can be seen by the user such as the operation screen, operation method, data output etc., designing security and operation rules, schedule and expenses of system development, etc. It is external design to do.

Internal Design
The internal design is based on the external design to design details that are difficult for the user to see, such as the operation and functions inside the system and physical data. Although this is a process between external design and detailed design to performed afterward, it is sometimes treated as the same process as detailed design because it is specialized for internal system. Divide program functions into single units and design physical data and input / output to be used there. The role of internal design is to make the result of external design easy to program.

ummmmm,
I would like to accumulate more know-how and knowledge on internal design.

Excel Mapping

VLOOKUP
-> In a table created in Excel, data is arranged vertically(rows) and horizontally(columns). From the table, hear that “extract data corresponding to a specific value”, and think the first thing that comes to mind is the “VLOOKUP(Buoy lookup) function.”

If want to process data in Excel, when write in a program, can we use in functions processed by excel itself together??

hash variable

A hash, also called an associative array, is an array in which “key” and “values” are associated as a pair. However, the array itself is characterized by being unordered. A hash variable is called a hash variable, which starts with %(percent) + 1 alphabetic character, and can use numbers, alphabetic characters and underscores (_) thereafter. Also, because case is distinguished, % and % A, for example, are treated as different things.

%fruit = ("red"=>"apple", "yellow"=>"banana");
print "$fruit{'red'}\n";

$fruit{"red"} = "apple";
$fruit{"yello"} = "banana";

%fruit = (red => "apple", yellow => "banana", purple => "grape");
@file = keys %fruit;

@file = values %fruit;
print "@file\n";

($key, $val) = each %fruit;
print "$key: $val\n";

Exclusive control

Exclusive control is the exclusive control of a resource when a conflict arises due to simultaneous access from multiple processes to shared resources that can be used by multiple processes in the execution of a computer program. While it is used as it is, it means the things of processing that maintains consistency by making other processes unavailable. Also called mutual exclusion or mutual exclusion. The case where up to k processes may access shared resources is called k-mutual exclusion.

Datatype: Time

The TIME type is a data type used to store time. The format in which ‘HH:MM:SS’ is the basis when inputting time as a string.

here is a sample.

mysql> create table timetest(
    -> id int auto_increment primary key,
    -> starttime time,
    -> endtime time
    -> )
    -> ;
Query OK, 0 rows affected (0.17 sec)

mysql> select * from timetest;
Empty set (0.00 sec)

mysql> describe timetest;
+-----------+---------+------+-----+---------+----------------+
| Field     | Type    | Null | Key | Default | Extra          |
+-----------+---------+------+-----+---------+----------------+
| id        | int(11) | NO   | PRI | NULL    | auto_increment |
| starttime | time    | YES  |     | NULL    |                |
| endtime   | time    | YES  |     | NULL    |                |
+-----------+---------+------+-----+---------+----------------+
3 rows in set (0.07 sec)

mysql> insert into timetest(starttime, endtime) values('08:00', '12:00');
Query OK, 1 row affected (0.07 sec)

mysql> select * from timtetest;
ERROR 1146 (42S02): Table 'test.timtetest' doesn't exist
mysql> select * from timetest;
+----+-----------+----------+
| id | starttime | endtime  |
+----+-----------+----------+
|  1 | 08:00:00  | 12:00:00 |
+----+-----------+----------+
1 row in set (0.00 sec)

I see.