サイズが合ってなくても気にしない著者
【PHP8】while – each を foreach に置きかえる
既存システムのPHP8対応の依頼を受けることが増えてきました。
PHP8ではeachが使用できなくなりましたので
1 2 |
while(list($key, $value) = each($data)) { } |
のような構文はforeachに置きかえます
1 2 |
foreach($data as $key => $value) { } |
Linuxでunzipしたら文字化けするときの対応
Windowsで作成されたzipファイルをLinuxでunzipすると
日本語のファイル名が文字化けすることがあります。
対策1:エンコード
unzipの-Oオプションを使ってエンコードを指定すれば解決する場合があります。
1 |
unzip -Ocp932 (zipファイル) |
対策2:unar
しかし、対策1でも解決しないケースや、元のエンコードが不明な場合は
unzipの代わりに、エンコードを自動判別してくれるunarを使いましょう。
1 |
unar (zipファイル) |
unarがインストールされていなければ
1 |
yum install unar |
(CentOS系)
【canvas】canvasで普通の矢印を描く(実線、破線)
canvasで普通の矢印を描きます。
ポイントは
・デザインに凝ってない単純な矢印。
・三角関数を使って任意の向きに。
・線の部分を破線にできる。
まずcanvasエリアを用意
1 |
<canvas id="canvas_view"></canvas> |
矢印描画関数を作る
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<script> function draw_arrow(ctx, x1, y1, x2, y2, color, dash) { var ar_l = 20; ctx.beginPath(); switch(dash) { case 'solid': ctx.setLineDash([]); break; case 'dashed': ctx.setLineDash([6, 4]); break; } ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.strokeStyle = color; ctx.lineWidth = 2; ctx.stroke(); var dx = x2 - x1; var ax = Math.sign(dx); var dy = y2 - y1; var ay = Math.sign(dy); var len = Math.sqrt(dx * dx + dy * dy); var cos = Math.acos(dx / len) / Math.PI * 180; var sin = Math.asin(dy / len) / Math.PI * 180; var x2_a1 = x2 + ar_l * Math.cos((cos + ax * 150) * Math.PI / 180); var y2_a1 = y2 + ar_l * Math.sin((sin + ay * 150) * Math.PI / 180); var x2_a2 = x2 + ar_l * Math.cos((cos - ax * 150) * Math.PI / 180); var y2_a2 = y2 + ar_l * Math.sin((sin - ay * 150) * Math.PI / 180); ctx.beginPath(); ctx.setLineDash([]); ctx.moveTo(x2, y2); ctx.lineTo(x2_a1, y2_a1); ctx.lineTo(x2_a2, y2_a2); ctx.lineTo(x2, y2); ctx.fillStyle = color; ctx.fill(); ctx.strokeStyle = color; ctx.lineWidth = 1; ctx.stroke(); } </script> |
関数を呼ぶ
1 2 3 4 5 6 7 8 9 10 11 |
<script> window.onload = function() { var canvas = document.getElementById('canvas_view'); canvas.width = 300; canvas.height = 300; var ctx = canvas.getContext('2d'); draw_arrow(ctx, 100, 100, 250, 200, 'red', 'solid'); draw_arrow(ctx, 50, 150, 200, 50, 'blue', 'dashed'); } </script> |
実行結果
【Linux】CentOS6からAlmaLinux9へパスワードなしssh接続
古いサーバーから新しいサーバーへパスなし接続がどうしても必要だったのでメモ。
もちろんセキュリティ的にオススメはしません。
接続元サーバーでECDSAでssh-keygen
1 |
ssh-keygen -t ecdsa -b 256 |
生成された公開鍵(id_ecdsa.pub)の内容を
接続先サーバーの authorized_keysにコピー
1 2 3 4 5 |
vi .ssh/authorized_keys (内容をコピーして保存) chmod 600 .ssh/authorized_keys chmod 700 .ssh |
接続元サーバーのECDSA対応
1 2 3 4 5 6 7 8 |
vi .ssh/config (以下を記載して保存) Host hogehoge.com(接続先) HostKeyAlgorithms ecdsa-sha2-nistp256 chmod 600 .ssh/config chmod 700 .ssh |
接続先サーバーのssh設定
1 2 3 4 5 |
vi /etc/ssh/sshd_config 以下を追記 PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys |
接続先サーバーのssh再起動で完了