Skip to content

Instantly share code, notes, and snippets.

View caramelchocolate's full-sized avatar

caramelchocolate

View GitHub Profile
@caramelchocolate
caramelchocolate / main.sh
Created May 20, 2021 07:25
console clock
while;do sleep 3; printf "\r%s" $(date | awk '{print $1 $2 "_" $4 }'); done
<?php
date_default_timezone_set('Asia/Tokyo');
$date = new DateTimeImmutable();
var_dump($date->format('Y-m-d H:i:s.u'));
var_dump($date->format('Y-m-d H:i:s.v'));
$date = new DateTimeImmutable('2020-04-20 11:12:13');
var_dump($date->format('U'));
var_dump(mktime($hour=11, $minute=12, $second=13, $month=4, $day=20, $year=2020));
?>
@caramelchocolate
caramelchocolate / include.php
Created May 7, 2020 06:18
include vs ob_get_clean benchmark
<?php
$time = microtime(true);
register_shutdown_function(
function () use ($time) {
$time = microtime(true) - $time;
$format = <<<EOD
Memory: %s / %s MB
Time: %f ms
EOD;
--TEST--
mail test
--INI--
sendmail_path=./stdout.sh
mail.add_x_header=off
mail.log=./mail.log
--FILE--
<?php
# pear run-tests mailtest.phpt
$to = 'example@example.com';
@caramelchocolate
caramelchocolate / main.php
Created April 9, 2020 14:45
Round-off error example
<?php
$a = 0.1 + 0.1 + 0.1;
$b = 0.3;
if ($a != $b) {
echo "Round-off error" . PHP_EOL;
}
$a = (0.1 * 0.1) * 30;
$b = 0.3;
if ($a != $b) {
<?php
# php -d register_argc_argv=0 main.php
var_dump(ini_get("register_argc_argv"));
$argv = [
__FILE__,
'-f',
'123',
];
var_dump(getopt('f:'));
?>
@caramelchocolate
caramelchocolate / main.sh
Created April 4, 2020 12:52
Write log to file
#!/bin/sh
dir_path="/path/"
date_str=$(date "+%Y%m%d_%H%M%S")
log_name="${dir_path}/${date_str}.log"
touch "${log_name}"
command 2>&1 | tee -a ${log_name};
# or
command >> "${log_name}" 2>&1
@caramelchocolate
caramelchocolate / main.sh
Created April 4, 2020 12:50
Run on a specific day.
#!/bin/sh
if [ `date +"%Y%m%d"` == "20200401" ]; then
# do something
:
fi
@caramelchocolate
caramelchocolate / bootstrap.php
Last active March 31, 2020 06:46
phpunit uses it
<?php
require __DIR__.'/../vendor/autoload.php';
@caramelchocolate
caramelchocolate / phpunit.xml.dist
Created March 31, 2020 06:43
phpunit setting file for me
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"