PHP配列の添え字が連番になっていないと json_encode() でJSONオブジェクトに変換される。
$x = [0 => 'a', 1 => 'b'];
echo json_encode($x);
# => ["a","b"]
$x = [0 => 'a', 2 => 'b'];
echo json_encode($x);
# => {"0":"a","2":"b"}PHP配列の添え字が連番になっていないと json_encode() でJSONオブジェクトに変換される。
$x = [0 => 'a', 1 => 'b'];
echo json_encode($x);
# => ["a","b"]
$x = [0 => 'a', 2 => 'b'];
echo json_encode($x);
# => {"0":"a","2":"b"}| <?php | |
| /** | |
| * 配列とオブジェクトのそれぞれに対して | |
| * 比較演算子 `==` と一致演算子 `===` の挙動を確認する | |
| */ | |
| // 配列 | |
| $a = ["value" => 1]; | |
| $b = ["value" => 1]; |
| """PythonでGoogleの認証についての状態を検証する | |
| """ | |
| import os | |
| import google.auth | |
| import google.auth.transport.requests | |
| from google.auth.exceptions import DefaultCredentialsError | |
| def get_tokeninfo(): |
| #' --- | |
| #' title: "scales::comma() のデフォルト accuracy の挙動確認" | |
| #' author: terashim | |
| #' output: | |
| #' html_document: | |
| #' keep_md: true | |
| #' --- | |
| #' ### accuracy を明示的に指定 | |
| scales::comma(c(0L, 1L), accuracy = 1) |
| def ifnone(x, y): | |
| return y if x is None else x |
| # Sys.setenv の副作用を検証 | |
| local({ | |
| x <- 1 | |
| Sys.setenv(MYENVVAR = x) | |
| }) | |
| x | |
| #> error | |
| # 変数はローカル |
| x = {"a": 1} | |
| {**x, "b": 10} | |
| # {'a': 1, 'b': 10} | |
| lst = [{"a": 1}, {"a": 2}] | |
| list(map(lambda x: {**x, "b": 10}, lst)) | |
| # [{'a': 1, 'b': 10}, {'a': 2, 'b': 10}] |
| --- | |
| title: "Target Markdown の検証" | |
| author: "@terashim_" | |
| date: "2021-06-08" | |
| output: html_document | |
| --- | |
| ```{r setup, include = FALSE} | |
| knitr::opts_chunk$set(collapse = TRUE, comment = "#>", | |
| tar_interactive = FALSE) |
| # check Laravel cache files permission | |
| cd /path/to/laravel/root/directory | |
| find storage/framework/cache -printf "%y %4m %8u %8g %p\n" | |
| # output example | |
| #> d 2775 apache laravel storage/framework/cache | |
| #> d 2775 apache laravel storage/framework/cache/data | |
| #> f 664 apache laravel storage/framework/cache/data/.gitignore | |
| #> d 2755 ec2-user laravel storage/framework/cache/data/47 | |
| #> d 2755 ec2-user laravel storage/framework/cache/data/47/13 |
| #!/usr/bin/env bash | |
| # | |
| # Down all running Docker Compose projects | |
| # | |
| docker ps --filter "label=com.docker.compose.project" -q |\ | |
| xargs docker inspect |\ | |
| jq -r 'map( .Config.Labels ) | | |
| map({" | |
| project": ."com.docker.compose.project", |