Skip to content

Instantly share code, notes, and snippets.

View macocci7's full-sized avatar
😊
good

macocci7 macocci7

😊
good
View GitHub Profile
@macocci7
macocci7 / Dir.php
Created May 26, 2024 09:15
[Laravel Prompts] File Selector (ファイル選択)
<?php
namespace MyLib;
class Dir
{
/**
* Returns all entries in the directory as RecursiveDirectoryIterator
* ディレクトリ内の全エントリーをRecursiveDirectoryIteratorで返す
*
@macocci7
macocci7 / takeScreenshotAndHtmlOfSelectedNode.php
Last active May 14, 2024 02:47
chrome-php/chrome 指定要素のみのスクリーンショット&HTML取得 (Taking Screenshot and Html of Selected Node)
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use HeadlessChromium\BrowserFactory;
use HeadlessChromium\Clip;
use HeadlessChromium\Dom\Dom;
use HeadlessChromium\Dom\Selector\CssSelector;
use HeadlessChromium\Page;
use headlessChromium\Utils;
@macocci7
macocci7 / LaravelPromptsTextValidateMbStringsFn.php
Last active March 31, 2024 06:20
Laravel Promptsの textプロンプトのマルチバイトバリデーション例(アロー関数と無名関数)
<?php
use function Laravel\Prompts\text;
$name = text(
label: 'あなたの名前を入力してください。',
placeholder: 'ななし はらぺこ',
default: '',
hint: 'ここで入力した名前はプロフィールに表示されます。',
required: "名前の入力は必須です。",
@macocci7
macocci7 / benchmarkAddArrayEelements.php
Last active December 17, 2023 12:10
Script to benchmark the performance of adding array elements (配列要素追加処理のベンチマークスクリプト)
<?php
function benchmark(string $name, Closure $callback)
{
$start = microtime(true);
$callback();
$time = microtime(true) - $start;
echo sprintf(
"%24s =>\tTime: %.6f sec.\n",
$name,
@macocci7
macocci7 / verifyLimitOfArrayElements.php
Created December 10, 2023 01:28
PHP code for verification of limit on number of array elements. (PHPの配列要素数の上限を検証するコード)
<?php
/**
* Code for verification of limit on number of array elements
*/
// initialization
$a = [];
// lower limit of array index
@macocci7
macocci7 / pairs.php
Last active December 17, 2023 00:55
A function to get all pairs of array elements (配列要素の全てのペアを取得する関数)
<?php
/**
* returns all pairs
* @param array $items
* @return array
*/
function pairs(array $items)
{
if (count($items) < 2) {
@macocci7
macocci7 / getAllCombinations.php
Last active December 17, 2023 00:48
2進数を使って全ての組み合わせを取得する関数。A function to get all combinations using binary numbers.
<?php
/**
* Code to get all combinations of array elements
*/
namespace Macocci7;
class Combination
{