Skip to content

Instantly share code, notes, and snippets.

View shin1x1's full-sized avatar
😀

Masashi Shinbara shin1x1

😀
View GitHub Profile
<?php
$string = str_repeat(' ', 200000) . 'a';
$start = microtime(true);
preg_replace('/\s+$/', '', $string);
if (preg_last_error() !== 0) {
var_dump(preg_last_error_msg());
}
<?php
const LOOP = 50;
$mesuare = function (string $title, callable $func): void {
printf("<h2>%s</h2>", htmlspecialchars($title));
for ($i = 1; $i <= LOOP; $i++) {
$start = microtime(true);
$time = $func() - $start;
<?php
enum Color: int {
case Red = 1;
case Blue = 2;
case Green = 3;
}
function foo(Color $color) {
var_dump($color);
<?php
declare(strict_types=1);
$i = random_int(1, 2);
var_dump($i);
// match expression
$ret = match ($i % 2 === 0) {
true => 'even',
false => 'odd',
<?php
declare(strict_types=1);
for ($i = 0 ; $i < 4 ; $i++) {
try {
$no = match ($i) {
0 => '0',
1 => throw new RuntimeException(),
// 2 => continue, Parse error: syntax error, unexpected token "continue"
@shin1x1
shin1x1 / Makefile
Last active September 29, 2020 02:31
hello-server
hello-server:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 docker run --rm -v `pwd`:/app -w /app golang:1.15-buster go build -o hello-server
clean:
-rm hello-server
<?php
namespace Acme;
use Attribute;
@@Attribute
final class Attr1 {}
@@Attr1
final class Foo {}
<?php
namespace Acme;
@@Attribute
final class Attr1 {}
@@Attr1
final class Foo {}
$reflectionClass = new \ReflectionClass(Foo::class);
<?php
declare(strict_types=1);
@@Attribute
final class Attr1 {
public function __construct(private string $value) {}
}
final class Attr2 {
public function __construct() {}