This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class InfluxdbLine | |
{ | |
// https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/ | |
public function format(string $measurement, array $tags, array $fields, string $timestampNanoSeconds): string | |
{ | |
$measurementEscaped = $this->escapeMeasurement($measurement); | |
$tagsFlat = $this->flattenTags($tags); | |
$fieldsFlat = $this->flattenFields($fields); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Use this in ActiveRecord models to speed up creating objects 10x times | |
*/ | |
trait CachedSchemaTrait | |
{ | |
public static function getTableSchema() | |
{ | |
static $cache; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const got = require('got'); | |
const jsdom = require("jsdom"); | |
const { JSDOM } = jsdom; | |
const url = 'https://www.yiiframework.com/status/3.0'; | |
const isStableVersion = (version) => { | |
if (version === '') { | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
use App\Auth\AuthController; | |
use App\User\UserController; | |
use App\Middleware\ApiDataWrapper; | |
use App\Middleware\CorsHeaders; | |
use App\Middleware\RequestFormParser; | |
use App\RequestForm\SignupForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
YII_SERVER_PGID=$(ps x -o pgid,command | grep -v grep | grep "/vendor/bin/yii serve" | awk '{print $1;}') | |
if [[ -z "$YII_SERVER_PGID" ]]; then | |
echo "Yii server not running." | |
else | |
kill -TERM -- -$YII_SERVER_PGID | |
echo "Killed Yii server." | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Command\Shell; | |
use Psy\Configuration; | |
use Psy\Shell; | |
use Psy\VersionUpdater\Checker; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
* | |
* $breakSignalDetector = new BreakSignalDetector(); | |
* $breakSignalDetector->registerSignalHandler(); | |
* | |
* while (...) // Some long running cycle | |
* { | |
* ... | |
* if ($breakSignalDetector->isTerminated()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Covariance - narrowing type on return. Works from PHP 7.4.0 and above | |
// https://www.php.net/manual/ru/language.oop5.variance.php | |
class Animal | |
{ | |
public function getName(): string | |
{ | |
return 'Some animal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Now: | |
class Shop | |
{ | |
private Log $log; | |
public function __construct(Log $log) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Есть вот такой json: https://api.jsonbin.io/b/600e00febca934583e41307f | |
// На самом деле, на него надо смотреть как на какой-то json, в котором может быть есть массивы и/или объекты. Какие-то. Есть ли они вообще и сколько их достоверно не известно. Известно только то, что на вход подается валидный json. | |
// Задача: вывести все пути к массивам. Конкатенация пути через точку. Например в примере выше ключ bookkeeping указывает не на массив, а на другой объект. Путь bookkeeping.contacts указывает тоже не на массив, а на объект, а вот bookkeeping.contacts.emails указывает на массив и это первый найденный путь. Задача найти их всех. | |
// Правильный ответ для этого примера по ссылке | |
// |