まだらもよう

Qiitaに投稿できないメモ書きなど

Laravelのコーディング規約で忘れがちなところ

php-cs-fixerは効かないやつとか

??で改行したいとき

        return $this->textView
                ?? $markdown->renderText($this->markdown, $data);

if文で改行したいとき

        if (is_a($value->class, Pivot::class, true) ||
            in_array(AsPivot::class, class_uses($value->class))) {
            return $collection;
        }

もしくは

        if ($value instanceof UploadedFile && ! $value->isValid() &&
            $this->hasRule($attribute, array_merge($this->fileRules, $this->implicitRules))
        ) {
            return $this->addFailure($attribute, 'uploaded', []);
        }

is_callable()

is_callable ( mixed $var ) : bool

関数としてコール可能かを返す。アクセス修飾子も考慮してくれる(protectedなどで実行できないならfalse)。

ex: LaravelのExceptionHandler

    public function report(Exception $e)
    {
        if ($this->shouldntReport($e)) {
            return;
        }

        if (is_callable($reportCallable = [$e, 'report'])) {
            return $this->container->call($reportCallable);
        }

        try {
            $logger = $this->container->make(LoggerInterface::class);
        } catch (Exception $ex) {
            throw $e;
        }

        $logger->error(
            $e->getMessage(),
            array_merge($this->context(), ['exception' => $e]
        ));
    }

似た関数にmethod_exists ( mixed $object , string $method_name ) : boolがある。
こちらはメソッドが定義されているかを返すだけで、コールできるかどうかは考慮しない。

curlコマンド

様々なプロトコルでデータ通信を行うコマンド。

$ curl <url>

オプション

-X <method> HTTPメソッド

-H <header> リクエストヘッダー

-d <data> POSTするデータ

-u <user:pass> Basic認証情報

curl -X POST -u user:pass -H 'Content-Type: application/json' -d '{"foo":"xxx", "bar":1}' https://example.com

771. Jewels and Stones

https://leetcode.com/problems/jewels-and-stones/

宝石である石の種類を表す文字列Jと、お持ちの石を表す文字列Sが与えられます。Sの各文字はあなたが持っている石の種類です。あなたが持っている石のうちいくつが宝石でもあるか知りたいですね。

Jの文字は区別できることが保証されており、JとSの文字はすべて文字です。文字は大文字と小文字が区別されるため、「a」は「A」とは別の種類の石と見なされます。

Example 1:

Input: J = "aA", S = "aAAbbbb"
Output: 3

Example 2:

Input: J = "z", S = "ZZ"
Output: 0
Note:

Answer:

  • for〜ofは文字列でも使える
  • str.includes()
/**
 * @param {string} J
 * @param {string} S
 * @return {number}
 */
var numJewelsInStones = function(J, S) {
    let count = 0;
    for (s of S) {
        if (J.includes(s)) {
            count++;
        }
    }
    return count;
};

GraphQL 参考になりそうなサイトまとめ

リファレンス
Introduction to GraphQL | GraphQL

よくまとまってるQiita
GraphQL入門 - 使いたくなるGraphQL - Qiita

チュートリアルサイト
Getting Started With GraphQL.js | GraphQL.js Tutorial
https://www.howtographql.com/
GraphQL Server Basics: GraphQL Schemas, TypeDefs & Resolvers Explained | Prisma

Strapi + Nuxt.js + GraphQL
🍝 Cooking a Deliveroo clone with Nuxt (Vue.js), GraphQL, Strapi and Stripe - 🏗️ Setup (part 1/7)