xargs

The command “xargs” reads the list from standard input or a file, and creates and executes a command line.
For example, the output of one command can be piped into an xargs command and specified as an argument of another command.

[vagrant@localhost ~]$ cd /var/www/cgi-bin
[vagrant@localhost cgi-bin]$ find . -name “*” | xargs grep select
grep: .: ディレクトリです
./app.cgi:my $sth = $db->prepare(“select * from name;”);

Perl DBIでselect

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| items          |
| name           |
| news           |
| user           |
+----------------+
4 rows in set (0.00 sec)

mysql> select * from items;
+---------+---------+-------+
| item_id | name    | price |
+---------+---------+-------+
|       1 | U+1F363 |  NULL |
+---------+---------+-------+
1 row in set (0.00 sec)

#!/usr/bin/perl --

use CGI;
use DBI;

print "Content-type:text/html\n\n";
print "hello";
my $user = 'root';
my $passwd = '';
my $db = DBI->connect('DBI:mysql:test:localhost', $user, $passwd);
my $sth = $db->prepare("select * from items;");
$sth->execute();
while (my $ary_ref = $sth->fetchrow_arrayref){
	my($a, $b) = @$ary_ref;
	print "$a, $b\n";
}
$sth->finish;
$dbh->disconnect;

OKなんだけど、これ、tableで表示するとき、whileが2つになるけど、どうするんだっけ?

print "<table>";
while (my $ary_ref = $sth->fetchrow_arrayref){
	my($a, $b) = @$ary_ref;
	print "<tr><td>$a</td><td>$b</td></tr>\n";
}
print "</table>";

tableはtableで良いんだが。。

Perl mysqlで文字化けするとき

Perlで入れて、文字化けしてる!?

my $user = 'root';
my $passwd = '';
my $db = DBI->connect('DBI:mysql:click:localhost', $user, $passwd);
my $sth = $db->prepare("INSERT INTO _mng(user_id, password, last_name, first_name, dept) VALUES (?, ?, ?, ?, ?)");
$sth->execute($user_id, $password, $last_name, $first_name, $dept);
+---------+----------+----------------+--------------+---------------------+----------------------+------------------------+----------------+----------------------+-----------------------+---------------------------+---------------+-------------+---------------+-------------+
| aaa     | hoge     | �田         | 太郎       | 管�部           | NULL                 | NULL                   |           NULL | NULL                 | NULL                  | NULL                      | NULL          | NULL        | NULL          | NULL        |
| eda     | hoge     | 江藤         | �          | 管�部           | NULL                 | NULL                   |           NULL | NULL                 | NULL                  | NULL                      | NULL          | NULL        | NULL          | NULL        |
| hoge    | hoge     | 山田         | 太郎       | 管�部           | NULL                 | NULL                   |           NULL | NULL                 | NULL                  | NULL                      | NULL          | NULL        | NULL          | NULL        |
| ykk     | hoge     | 高橋         | �          | 管�部           | NULL                 | NULL                   |           NULL | NULL                 | NULL                  | NULL                      | NULL          | NULL        | NULL          | NULL        |
+---------+----------+----------------+--------------+---------------------+----------------------+------------------------+----------------+----------------------+-----------------------+---------------------------+---------------+-------------+---------------+-------------+
4 rows in set (0.00 sec)

set name utf8がない模様

my $user = ‘root’;
my $passwd = ”;
my $db = DBI->connect(‘DBI:mysql:click:localhost’, $user, $passwd);
my $sth = $db->prepare(“INSERT INTO mng(user_id, password, last_name, first_name, dept) VALUES (?, ?, ?, ?, ?)”);
$db->do(“set names utf8”);
$sth->execute($user_id, $password, $last_name, $first_name, $dept);

+———+———-+—————-+————–+———————+———————-+————————+—————-+———————-+———————–+—————————+—————+————-+—————+————-+
| aaa | hoge | �田 | 太郎 | 管�部 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| eda | hoge | 江藤 | � | 管�部 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| hoge | hoge | 山田 | 太郎 | 管�部 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| sakura | sakura | さくら | たかし | 管理部 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| ykk | hoge | 高橋 | � | 管�部 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
+———+———-+—————-+————–+———————+———————-+————————+—————-+———————-+———————–+—————————+—————+————-+—————+————-+
5 rows in set (0.00 sec)

日本語で入りましたねー

jsからCanvas

<!DOCTYPE html>
<html lang="ja">
<head>
	<meta charset="UTF-8">
	<title>JavaScriptでスクリーンショット</title>
</head>

<body>
	<hr>
	<div style="background-color : #AAEEDD"><h1>JavaScriptで撮るスクリーンショット</h1></div>
	<div id="target">
	<h2>導入方法と処理概要</h2>
	<table border="1" width="500" cellspacing="0" cellpadding="5" bordercolor="#333333" style="table-layout: fixed;">
	<tr>
		<th bgcolor="#7b9ad0" width="40"><font color="#FFFFFF">No</font></th>
		<th bgcolor="#7b9ad0" width="230"><font color="#FFFFFF">概要</font></th>
		<th bgcolor="#7b9ad0" width="230"><font color="#FFFFFF">補足</font></th>
	</tr>
	<tr>
		<td bgcolor="#b1d7e4" width="40" align="right">1</td>
		<td bgcolor="#7b9ad0" width="230">任意のタイミングでhtml2canvas関数を呼ぶ</td>
		<td bgcolor="#7b9ad0" width="230">※今回はオンロード処理</td>
	</tr>
	<tr>
		<td bgcolor="#b1d7e4" width="40" align="right">2</td>
		<td bgcolor="#7b9ad0" width="230">任意のタイミングでhtml2canvas関数を呼ぶ</td>
		<td bgcolor="#7b9ad0" width="230">※今回はオンロード処理</td>
	</tr>
	<tr>
		<td bgcolor="#b1d7e4" width="40" align="right">3</td>
		<td bgcolor="#7b9ad0" width="230">onrendered処理にて指定のElementに画像を追記</td>
		<td bgcolor="#7b9ad0" width="230">※[img]タグの[src]や、[a]タグの[href]など</td>
	</tr>
</table>
</div>
<br>
<hr>
<h3>↓↓ここから画像↓↓ (上の対象のDIVを画像化)</h3>
<img src="" id="result">
<h3>↑↑ここまで画像↑↑</h3>

<hr>

<a href="" id="ss" download="html_ss.png">スクリーンショット(document.body全体)をダウンロード</a>
<hr>
<h3>注意</h3>
<ul>
	<li>実際にはスクリーンショットを撮っているわけではない</li>
	<li>html2canvasは、HTML内のDOMやCCSを解釈してCanvas上に描画するライブラリ</li>
	<li>つまり、レンダリングエンジンに近い動作をする</li>
	<li>そのため、ブラウザと異なる表示がされる場合がある</li>
	<li>flashやapplet, iframe(別URL)はうまくキャプチャできない</li>
</ul>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script>
	window.onload = function(){

		html2canvas(document.getElementById("target"),{
			onrendered: function(canvas){
				var imgData = canvas.toDataURL();
				document.getElementById("result").src = imgData;
			}
		});

		html2canvas(document.body, {
			onrendered: function(canvas){
				var imgData = canvas.toDataURL();
				document.getElementById("ss").href = imgData;
			}
		});
	}
</script>
</body>
</html>

Canvasでiconを作る

<style>
	ul.icon{
		list-style:none;
	}
	ul.icon li {
		position: relative;
		margin-bottom: 0.5em;
	}
	ul.icon li canvas {
		position: absolute;
		top: 0.3em;
		left: -13px;
	}
</style>
<ul class="icon">
	<li>item01</li>
	<li>item02</li>
	<li>item03</li>
	<li>item04</li>
	<li>item05</li>
</ul>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	var list = $('ul.icon li');
	list.prepend('<canvas width="20" height="20" />');
	var ctx = null;

	list.each(function (i){
		var canvas = $('canvas', list).get(i);
		ctx = canvas.getContext('2d');
		drawIcon();
	});

	function drawIcon(){
		ctx.beginPath();
		ctx.arc(6, 10, 6, 0, Math.PI*2);
		ctx.fillStyle = 'rgb(50, 150, 255)';
		ctx.fill();

		ctx.beginPath();
		ctx.moveTo(5, 7);
		ctx.lineTo(8, 9);
		ctx.lineTo(5, 12);
		ctx.closePath();
		ctx.fillStyle = 'rgb(255, 255, 255)';
		ctx.fill();
	}
});
</script>

なるほどー

SAML

SAML is an abbreviation of Security Assertion Markup Language and is called “Samuru”.

SAML is a standard of authentication information developed by OASIS for authenticating users between different Internet domains. In other words, it refers to a rule protocol that exchanges user credentials.

Idp (= Identify Provider) is a system that provides authentication information. Without SAML, it is necessary to convert the format and format of information when the IdP and SP exchange information. You can save the trouble of that work.

Convenient improvement
With SSO, you can log in to different services with or user authentication. Because you do not need to authenticate each time, you can use the service comfortably.

Security improvements
Some users may be uneasy about the availability of many services with one authentication system. However, considering that most users use the same ID and password for all services and that only one login information needs to be managed securely, it can be said that there are security advantages as well.

apache execute user

To change the user running Apache, you need to change the user specification in httpd.conf. If nothing is specified, the daemon user is specified.

[vagrant@localhost ~]$ ps aux | grep http
root 2040 0.0 2.4 384472 12512 ? Ss 11:44 0: 02 /usr/sbin/httpd
jenkins 2083 0.5 56.8 2273640 285232 ? Ssl 11:45 2: 54 /etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonized -D java.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /u sr/lib/jenkins/jenkins.war –logfile=/var/log/jenkins/jenkins. log –webroot=/var/cache/jenkins/war –daemon –httpPort=8080 –debug=5 –handlerCountMax=100 –handlerCountMaxIdle=20
apache 2488 0.0 2.0 386112 10280 ? S 12:23 0: 00 /usr/sbin/httpd
apache 2489 0.0 2.0 386112 10280 ? S 12:23 0: 00 /usr/sbin/httpd
apache 2490 0.0 2.0 386112 10300 ? S 12:23 0: 00 /usr/sbin/httpd
apache 2491 0.0 2.0 386112 10280 ? S 12:23 0: 00 /usr/sbin/httpd
apache 2492 0.0 2.0 386112 10280 ? S 12:23 0: 00 /usr/sbin/httpd
apache 2493 0.0 2.0 386112 10280 ? S 12:23 0: 00 /usr/sbin/httpd
apache 2494 0.0 2.0 386112 10280 ? S 12:23 0: 00 /usr/sbin/httpd
apache 2495 0.0 2.0 386112 10280 ? S 12:23 0: 00 /usr/sbin/httpd
vagrant 4449 0.0 0.1 103320 872 pts/0 D+ 20:52 0: 00 grep http
うーん、apacheって書いてあるように見える。。

[vagrant@localhost ~]$ id apache
uid=48(apache) gid=48(apache) 所属グループ=48(apache)

migrationファイルによるカラム修正

<?php

use Illuminate\Support\Facades\Schema\;
use Illuminate\Database\Schema\Blueprint\;
use Innuminate\Database\Migrations\Migration;

class AddColumnSalesHogeTable extends Migration{

	public function up(){
		Schema::table('books', function(Blueprint $table){
			$table->integer('sales')->default(0)->index('index_sales')->after('price')->comment('販売数');
		});
	}

	public function down()
	{
		Schema::table('books', function(Blueprint $table){
			$table->dropColumn('sales');
		});
	}
}

CHARACTER_OCTET_LENGTH

CHARACTER_OCTET_LENGTH must be the same as CHARACTER_MAXIMUM_LENGTH except for multibyte character set.

mysql> select * from `information_schema`.`columns` where `table_schema` = “test”;
+—————+————–+————+————-+——————+—————-+————-+———–+————————–+————————+——————-+—————+——————–+——————–+—————–+————–+————+—————-+———————————+—————-+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE | CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH | NUMERIC_PRECISION | NUMERIC_SCALE | DATETIME_PRECISION | CHARACTER_SET_NAME | COLLATION_NAME | COLUMN_TYPE | COLUMN_KEY | EXTRA | PRIVILEGES | COLUMN_COMMENT |
+—————+————–+————+————-+——————+—————-+————-+———–+————————–+————————+——————-+—————+——————–+——————–+—————–+————–+————+—————-+———————————+—————-+
| def | test | items | item_id | 1 | NULL | NO | int | NULL | NULL | 10 | 0 | NULL | NULL | NULL | int(11) | PRI | auto_increment | select,insert,update,references | |
| def | test | items | name | 2 | NULL | YES | text | 65535 | 65535 | NULL | NULL | NULL | utf8 | utf8_general_ci | text | | | select,insert,update,references | |
| def | test | items | price | 3 | NULL | YES | int | NULL | NULL | 10 | 0 | NULL | NULL | NULL | int(11) | | | select,insert,update,references | |
| def | test | name | name | 1 | NULL | YES | varchar | 255 | 765 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(255) | | | select,insert,update,references | |
| def | test | name | password | 2 | NULL | YES | varchar | 255 | 765 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(255) | | | select,insert,update,references | |
| def | test | news | id | 1 | NULL | NO | int | NULL | NULL | 10 | 0 | NULL | NULL | NULL | int(11) | PRI | auto_increment | select,insert,update,references | |
| def | test | news | content | 2 | NULL | YES | varchar | 100 | 300 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(100) | | | select,insert,update,references | |
| def | test | user | id | 1 | NULL | NO | int | NULL | NULL | 10 | 0 | NULL | NULL | NULL | int(11) | MUL | auto_increment | select,insert,update,references | |
| def | test | user | name | 2 | NULL | YES | varchar | 20 | 60 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(20) | | | select,insert,update,references | |
+—————+————–+————+————-+——————+—————-+————-+———–+————————–+————————+——————-+—————+——————–+——————–+—————–+————–+————+—————-+———————————+—————-+
9 rows in set (0.15 sec)

なんじゃーこりゃーーー