Spring Boot と Spring Framework バージョン 対応表まとめ(SpringBoot v2,v3)

SpringBoot と Spring Framework のバージョン対応表をまとめました。
今使われているシステムのSpringBootはSpring4shell の脆弱性があるバージョンでないか照らし合わせにもお使いください。

Spring Boot v2, v3 のバージョンのみ。(2023/11/18現在)
GitHub Releases – Dependency Upgrades に記載がないものは、gradle.propertiesなどソースコードを参照しています。(GitHub列に※記載)

「続きを読む」

Powershellで既に開いているウィンドウを半透明にする

ウィンドウを透明化したいが、それだけのためにフリーソフトは入れたくない。
Powershellで”メモ帳”を含むウィンドウタイトルを対象に透明化する。

透明化後

コード

Add-Type -TypeDefinition @"
    using System;
    using System.Runtime.InteropServices;
    using System.Text;

    public class User32 {
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);

        public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

        [DllImport("user32.dll")]
        public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

        [DllImport("user32.dll")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        public const int GWL_EXSTYLE = -20;
        public const int WS_EX_LAYERED = 0x80000;
        public const int LWA_ALPHA = 0x2;
    }
"@ -Language CSharp

$windowsWithMemoPad = New-Object System.Collections.ArrayList

$enumWindowsCallback = [User32+EnumWindowsProc] {
    param ([System.IntPtr]$hWnd, [System.IntPtr]$lParam)

    $title = New-Object System.Text.StringBuilder 1024
    [User32]::GetWindowText($hWnd, $title, $title.Capacity)
    
    if ($title.ToString().Contains("メモ帳")) {
        $null = $windowsWithMemoPad.Add($hWnd)
    }

    return $true
}

[User32]::EnumWindows($enumWindowsCallback, [System.IntPtr]::Zero)

foreach ($hwnd in $windowsWithMemoPad) {
    $style = [User32]::GetWindowLong($hwnd, [User32]::GWL_EXSTYLE)
    [User32]::SetWindowLong($hwnd, [User32]::GWL_EXSTYLE, ($style -bor [User32]::WS_EX_LAYERED))
    [User32]::SetLayeredWindowAttributes($hwnd, 0, 150, [User32]::LWA_ALPHA) #透明度を指定する(0-255) 
}

if ($windowsWithMemoPad.Count -eq 0) {
    Write-Host "タイトルにメモ帳を含むウィンドウが見つかりませんでした。"
}

透明度やウィンドウ名を調整すればカスタム可能。

Excelデータのスクロールバーが短い現象を保存を使わずに直す

行数が多いデータをマクロなどで処理した後に、スクロールバーが短いままの状態になることがある。

対処法を検索しても、日本語のサイトではデータやオブジェクトが残ってるなら削除する。その後に保存が必要。しかし保存はしたくない。マクロのExcelに上書き保存はしたくない。

そのようなケースに海外のサイトで解決策を発見。

https://exceloffthegrid.com/resetting-the-scroll-bar-in-excel/

1. Excelを開き、修正したいシートを選択する。


2. マクロの実行が可能な状態にして、VBAエディタを開きます。(Alt + F11で開けます。)


3. VBAエディタのイミディエイトウィンドウを開く。


4. 以下のコードを入力し、Enterを押す

ActiveSheet.UsedRange

5. スクロールバーが長くなっている事を確認する。

もちろんマクロの中に埋め込むことも可能です。
(セル範囲を出力するだけのコマンドでなぜ直るのか…)

iOS Safari の日付型のフォーム input type=”date”でtext-align が反映されない

iOSのSafariにおいて、input type="date"要素を使用する際、text-alignプロパティを指定しても、テキストの位置が左寄せにならず、中央寄せのまま表示されてしまうという現象が報告されていました。これはデフォルトの挙動であり、通常のCSSスタイリングがうまく適用されない状況。

解決策

input::-webkit-date-and-time-value {
    text-align: left;
}

Stack Overflowで検索したらヒット。
-webkit-date-and-time-value 疑似要素を使用することで、解決できる。

参考

https://stackoverflow.com/questions/70111522/how-can-i-align-the-text-of-a-date-input-to-the-left-on-ios-15

エックスサーバーにLaravelプロジェクトをデプロイ

GitHubにプッシュする

特に言うことなし。
初めての人は「user.email」,「user.name」を忘れずに設定を。


エックスサーバーにclone(Privateリポジトリの場合)

エックスサーバー SSH

ghコマンドは入ってないので、手動で公開鍵生成

ssh-keygen -t rsa -C 'メールアドレス'

Generating public/private rsa key pair.
Enter file in which to save the key (/home/.ssh/id_rsa):

Enter passphrase (empty for no passphrase): <Password>
Enter same passphrase again: <Password>

cat ~/.ssh/id_rsa.pub
ssh-rsa *********************** メールアドレス

Githubで公開鍵を設定

https://github.com/settings/keys

上記の公開鍵「id_rsa.pub」をペースト

クローン

git clone git@github.com***

.envを書く

vi .env

APP_ENV=production
APP_DEBUG=false
APP_URL=https://***
DB_HOST=127.0.0.1
...

セットアップ

composer install
php artisan key:generate
php artisan migrate:fresh

完了!


Viteがインストールされていない場合

npm run build

> build
> vite build

/tmp/build-9bbcca7e.sh: 行 1: vite: コマンドが見つかりません

なぜかインストールされていなかったのでインストール。

npm install vite --save-dev

完了!

Laravel10でx-input-errorを使うとUndefined variable $messagesになる

※x-input-errorを使わずに別の方法で解決させています。

Laravel フレームワークあまり触ったことなく、ハマったのでメモ

環境

PHP 8.2.5, Laravel: 10.15.0

コード

view

<x-input-error :message="$errors->get('title')" class="mt-2"/>

実行結果

  input-error.blade.php でエラーが起きているのは分かる。

ErrorException
Undefined variable $messages

エラーこれだけだと分からないよ…


やったこと

https://biz.addisteria.com/error_message_error/

<x-input-error class="mb-4" :messages="$errors->all()"/>

↓
ErrorException
Undefined variable $messages

変わらない…


とりあえず解決策

https://laravel.com/docs/10.x/validation#the-at-error-directive

公式ドキュメント通りだと動いた。x-input-errorについての記述はなかった。
GitHub Copilot でもこっちが出てくる。

@error('title')
    <div class="alert alert-danger">{{ $message }}</div>
@enderror

katteneをPHP8.0以上に対応させる

2023/07/21 追記
https://webfood.info/make-kattene/
https://plugins.trac.wordpress.org/browser/kattene/tags/1.6/plugin.php

WordPressがサブディレクトリにインストールされている場合も使えるようにした。
mainフラグ周りの「Warning: Undefined array key」や「Notice: Undefined index」が出ないようにした。
mainフラグが1つも設定されていない場合、1番上のURLをメインとして使うようにした。複数にmainフラグが設定されてしまった場合は、そのうちの1番上のものをメインとするようにした。

kattene 1.6で修正されました。


別ブログでkatteneプラグインを使っていて、PHP8.0以上にアップグレードすると、下記エラーが発生。

Warning: Undefind array key "main" in /home/xxxx/wp-content/plugins/kattene/plugin.php on line 44

PHP7まではNoticeのみで出力されていなかった。PHP8以降はWarningに格上げ。
上の表示でもそんな感じ。

プラグイン自体2年ほどアップデートされていないので、pochippに乗り換える人がちらほら。

今更全てのリンクを変更するのは面倒だったので、plugin.phpを編集。


編集前

plugin.php
$main_tmp = array_filter($sites,
  function($site){
    return $site["main"];
  }
);

$main = array_pop($main_tmp);

編集後

plugin.php
  $main_tmp = array_filter($sites,
    function($site){
      return isset($site["main"]) && $site["main"];
    }
  );

  if (!empty($main_tmp)) {
    $main = array_pop($main_tmp);
  }

$sites 配列の要素に "main" キーが存在するかどうかを事前に確認。

$main = array_pop($main_tmp); も一応エラーハンドリングを追加しておく。


PHP8.2.5で動作確認済。

エックスサーバーに最新バージョンのComposerをインストールする

参考する記事によってはPATHの反映がされなかったりだったので、メモ程度に。
サーバーへSSH接続までは省略します。

各バージョン確認

$composer -V
Composer version 1.10.26 2022-04-13 16:39:56

$php -v
PHP 5.4.16 (cli) (built: Apr  1 2020 04:07:17) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.5, Copyright (c) 1999-2015, by Zend Technologies

初期状態のPATHだと古いPHP・Composerのバージョンが使用されていると思うので、別のバージョンにPATHを通します。

今回は運用中のサイトで使用中のバージョンを使います。
Xserverサーバーパネルから現バージョンを確認します。

今回はPHP7.4 を使います。

1. PHP PATHを通す

既に存在するXserverのPHPにシンボリックリンクを作成します。
バージョンは各自調整してください。

$ cd
$ mkdir bin
$ ln -s /usr/bin/php7.4 $HOME/bin/php
$ ls -la $HOME/bin/

2. Composerをインストール

公式サイトのコマンド通りインストールします。
https://getcomposer.org/download/

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

pharファイルを移動してPATHを通します。

mkdir -p .config/composer/vendor/bin/
mv composer.phar .config/composer/vendor/bin/composer
$vi .bash_profile

PATH=$HOME/.config/composer/vendor/bin:$HOME/bin:$PATH

3. .bash_profileを編集

PHPへのシンボリックリンク・ComposerへPATHを追加するため、1行追加します。

$vi .bash_profile

...
# 1行追加して保存
PATH=$HOME/.config/composer/vendor/bin:$HOME/bin:$PATH
...compose

# .bash_profileを反映
$ source .bash_profile

4. バージョン確認

$ composer -V
Composer version 2.2.21 2023-02-15 13:07:40

$ php -v
PHP 7.4.33 (cli) (built: Nov  1 2022 16:31:23) ( NTS )
Copyright (c) The PHP Group

バージョンアップ完了!