Skip to content

Instantly share code, notes, and snippets.

View caramelchocolate's full-sized avatar

caramelchocolate

View GitHub Profile
@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) {
--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 = '[email protected]';
@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;
<?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 / main.sh
Created May 20, 2021 07:25
console clock
while;do sleep 3; printf "\r%s" $(date | awk '{print $1 $2 "_" $4 }'); done