question
dict | answers
list | id
stringlengths 2
5
| accepted_answer_id
stringlengths 2
5
⌀ | popular_answer_id
stringlengths 2
5
⌀ |
---|---|---|---|---|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "### やりたいこと\n\n 1. Aさん、Bさん、Cさんがそれぞれ以下の表へデータを入力します。\n 2. 事務員さんがデータを確認し、確認が終わったら✔をします。\n 3. チェックが付いた行のデータはAさん、Bさん、Cさんは編集できないようにしたいです。\n\n[](https://i.stack.imgur.com/MX6Hh.png)\n\n### 質問\n\n関数でもGASでもいいので上記のようなことは出来ますでしょうか。 \n「確認が終わった行のデータは編集できないようにしたい」というのが目的のため、 \n「チェックボックス」の形にもこだわってはおりません。 \n別のいい方法があればぜひそちらでも大丈夫です。\n\n### 調べたこと\n\n自分で調べてみたところ、シート全体の保護やブックの保護などは出てきたのですが、 \n任意の行のみの保護というのが調べても分からず悩んでおります。\n\n色々不足している点があるかと思いますが、是非お知恵をお借りしたいと思っております。 \n宜しくお願い致します。",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T01:11:58.760",
"favorite_count": 0,
"id": "86522",
"last_activity_date": "2022-02-23T05:30:30.420",
"last_edit_date": "2022-02-23T05:30:30.420",
"last_editor_user_id": "3060",
"owner_user_id": "51218",
"post_type": "question",
"score": 0,
"tags": [
"google-apps-script",
"google-spreadsheet"
],
"title": "確認が終わった行を保護したい",
"view_count": 325
} | [] | 86522 | null | null |
{
"accepted_answer_id": "86524",
"answer_count": 1,
"body": "お世話になります。\n\n公式サイトのフォーラムにも投稿しましたが、数日経っても投稿が反映されないため、こちらに改めて投稿をいたします。\n\nツール→メニューの変更→メインメニューで、「マイマクロ」というポップアップを作成し、 \nそこへ右に挿入で、マイマクロの一覧を登録しています。\n\nところが、いつのバージョンからか、メニューからマイマクロ→適当なマクロを選択しても、 \nそのマクロが実行されなくなりました。\n\nただ、表示されるマイマクロから適当なマクロを右クリック→編集などを選択すると、 \n編集モードで開きますので、どうやら選択による実行だけが動作していないようです。\n\nこのほか、キーボードの割り当てで、いくつかのマクロにショートカットキーを割り当てており、 \nこのショートカットを押すと、マクロは実行されます。\n\nまた、コンテキストメニューにも同じようにマイマクロの一覧を登録しているのですが、 \nこちらからは問題なく実行されます。\n\n気が付いたのは 21.4.1 で、21.5.1、21.5.2 に更新してみましたが、現象は変わりませんでした。 \n環境は、Windows 10 Home/21H1 Emeditorは64ビット版です。\n\nなお、別の端末(Windows 10 Home/21H2 、EmEditor 21.0.1)では問題ありませんでした。\n\n以上、よろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T03:17:11.967",
"favorite_count": 0,
"id": "86523",
"last_activity_date": "2022-03-04T15:38:40.077",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51569",
"post_type": "question",
"score": 1,
"tags": [
"emeditor"
],
"title": "メインメニューに登録したマイマクロからマクロが実行されない",
"view_count": 101
} | [
{
"body": "まず、[マクロ] メニューの [カスタマイズ] を選択し、[既定でマクロを非同期に実行する]\nオプションをクリアして、問題が再現するかどうか試してください。それで問題が解決するかどうかお知らせください。\n\n**更新** \nマクロに関連付けられたイベントを解除するか `EmEditor v21.5.904` 以上に更新してください。",
"comment_count": 10,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T03:26:14.967",
"id": "86524",
"last_activity_date": "2022-03-04T15:38:40.077",
"last_edit_date": "2022-03-04T15:38:40.077",
"last_editor_user_id": "40017",
"owner_user_id": "40017",
"parent_id": "86523",
"post_type": "answer",
"score": 0
}
] | 86523 | 86524 | 86524 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "# やりたいこと\n\n以下のコードのように、Pythonの`multiprocessing.Pool`を使って並列に処理したいです。\n\n```\n\n import multiprocessing\n \n def foo(i):\n if i%2==0:\n raise RuntimeError(\"偶数\")\n return i\n \n with multiprocessing.Pool(4) as p:\n result = p.map(foo, [1, 3, 5])\n print(result)\n # => [1, 3, 5]\n \n```\n\n# 質問\n\n以下のように`[1,2,3]`をmap関数に渡すと、`i=2`のときにRuntimeErrorがスローされます。\n\n```\n\n with multiprocessing.Pool(4) as p:\n result = p.map(foo, [1,2,3])\n \n```\n\n```\n\n RemoteTraceback: \n \"\"\"\n Traceback (most recent call last):\n File \"/home/vagrant/.pyenv/versions/3.9.7/lib/python3.9/multiprocessing/pool.py\", line 125, in worker\n result = (True, func(*args, **kwds))\n File \"/home/vagrant/.pyenv/versions/3.9.7/lib/python3.9/multiprocessing/pool.py\", line 48, in mapstar\n return list(map(*args))\n File \"<ipython-input-102-bbf59efb0d82>\", line 3, in foo\n raise RuntimeError(\"偶数\")\n RuntimeError: 偶数\n \"\"\"\n \n```\n\n`i=2`のときの例外をキャッチした上で、`i=1`, `i=3`のときの結果も取得したいです。どのようなコードを書けばよいでしょうか?\n\n以下のコードのように、`foo`関数の中でtry/exceptすれば、`i=1`, `i=3`のときの結果を取得できます。 \nしかし、本来try/exceptはfoo関数の呼び出し元で行うべきなので、できればこの方法は採用したくありません。\n\n```\n\n def foo(i):\n try:\n if i%2==0:\n raise RuntimeError(\"custom\")\n return i\n except Exception\n return None\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T06:12:22.247",
"favorite_count": 0,
"id": "86528",
"last_activity_date": "2022-02-23T11:25:36.113",
"last_edit_date": "2022-02-23T09:03:44.183",
"last_editor_user_id": "2238",
"owner_user_id": "19524",
"post_type": "question",
"score": 1,
"tags": [
"python"
],
"title": "マルチプロセスで処理する際、例外をキャッチした上で処理を継続したいです",
"view_count": 453
} | [
{
"body": "[ここ](https://stackoverflow.com/a/44819075/9105334)にあるように、[`imap`メソッド](https://docs.python.org/ja/3/library/multiprocessing.html#multiprocessing.pool.Pool.imap)を使ってイテレーターを取得し、例外を処理しながらイテレーターを進めていくのはいかがでしょうか。\n\n```\n\n import multiprocessing\n \n def foo(i):\n if i % 2 == 0:\n raise RuntimeError(f\"偶数: {i}\")\n return i\n \n if __name__ == '__main__':\n with multiprocessing.Pool(4) as p:\n result_iterator = p.imap(foo, [1, 2, 3])\n while True:\n try:\n result = next(result_iterator)\n print(result)\n except StopIteration:\n break\n except Exception as e:\n print(e)\n \n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T11:25:36.113",
"id": "86537",
"last_activity_date": "2022-02-23T11:25:36.113",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "36010",
"parent_id": "86528",
"post_type": "answer",
"score": 2
}
] | 86528 | null | 86537 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "以下のページの要件を元に、Javaでなんちゃって会員登録機能を作成しております。\n\n[作って覚えるプログラミング精選課題集(Java基礎編) - レベル4\n会員登録機能](https://qiita.com/s_hino/items/85ce20cb675484d300f0#%E3%83%AC%E3%83%99%E3%83%AB4-%E4%BC%9A%E5%93%A1%E7%99%BB%E9%8C%B2%E6%A9%9F%E8%83%BD)\n\nコードを記述し終わり動かしてみた所、エラーが発生してうまくデータが出力されません。\n\n```\n\n java.lang.IndexOutOfBoundsException: Index 333 out of bounds for length 1\n \n```\n\n[](https://i.stack.imgur.com/Ml3B1.png)\n\n記述しているコードには問題はないと思うのですが、直し方がわかりません。 \nお手数ですがご教授お願い致します。\n\n2/24追記 \nRegister.javaのコードを修正した所、 \nこのようなデータが表示されました。 \n[](https://i.stack.imgur.com/7vL3z.png)\n\n### ソースコード\n\nRegister.java\n\n```\n\n package rensyu;\n \n import java.util.Date;\n import java.util.*;\n \n public class Register {\n static ArrayList<Kaiin> kaiinAll = new ArrayList<Kaiin>();\n \n public static void main(String[] args) {\n Register r = new Register();\n Scanner scan = new Scanner(System.in);\n System.out.println(\"何人登録しますか?\");\n int i = scan.nextInt();\n int id = 0;\n String name = null;\n for (int j = 0; j < i; j++) {\n System.out.println(\"会員IDを入力してください\");\n id = scan.nextInt();\n System.out.println(\"名前を入力してください\");\n name = scan.next();\n kaiinAll.add(r.kaiinAdd(id, name));\n Kaiin lastElement = kaiinAll.get(kaiinAll.size() - 1);\n System.out.println(lastElement);\n \n }\n \n }\n \n private Kaiin kaiinAdd(int id, String name) {\n Kaiin k = new Kaiin();\n k.setId(id);\n k.setName(name);\n Date d = new Date();\n k.setAddDate(d);\n return k;\n \n }\n \n }\n \n```\n\nKaiin.java\n\n```\n\n package rensyu;\n import java.util.Date;\n public class Kaiin {\n int id;\n String name;\n Date addDate;\n public int getId() {\n return id;\n }\n public void setId(int id) {\n this.id = id;\n }\n public String getName() {\n return name;\n }\n public void setName(String name) {\n this.name = name;\n }\n public Date getAddDate() {\n return addDate;\n }\n public void setAddDate(Date addDate) {\n this.addDate = addDate;\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T06:56:23.057",
"favorite_count": 0,
"id": "86530",
"last_activity_date": "2022-02-24T07:55:07.090",
"last_edit_date": "2022-02-24T05:36:20.530",
"last_editor_user_id": "50555",
"owner_user_id": "50555",
"post_type": "question",
"score": 0,
"tags": [
"java"
],
"title": "ArrayList の操作・参照時にエラー java.lang.IndexOutOfBoundsException: Index 333 out of bounds for length 1",
"view_count": 515
} | [
{
"body": "`kaiinAll.get(id)`\nにて、idをキーとして可変長配列から要素を取得しているためです。これはHashMapや連想配列ではないので、挿入した順の配列です。(例えば、スクリーンショットの例外時の本来取得したい項目のインデックスは0です)\n\nたとえば`ArrayList<Kaiin>`から特定のIDを持つ要素を取得したい場合、for-eachループが使えます。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T11:11:31.407",
"id": "86536",
"last_activity_date": "2022-02-23T11:11:31.407",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2376",
"parent_id": "86530",
"post_type": "answer",
"score": 1
},
{
"body": "[`ArrayList#add()`](https://docs.oracle.com/javase/jp/17/docs/api/java.base/java/util/ArrayList.html#add\\(E\\))\nは、 **リストの最後** に、指定された要素を追加するメソッドです。\n\nですので、直前に追加した要素を取得するには、[`ArrayList#get()`](https://docs.oracle.com/javase/jp/17/docs/api/java.base/java/util/ArrayList.html#get\\(int\\))\nの引数に、 **リストの最後** の要素を示す **インデックス** を渡せば良いです。\n\nインデックスは0始まりなので、 **リストの最後** の要素を示す **インデックス** は `リストの要素数 - 1` になります。\n\nまとめると、\n\n```\n\n Kaiin lastElement = kaiinAll.get(kaiinAll.size() - 1);\n \n```\n\nで直前に登録した会員オブジェクトを取得できます。\n\n質問文の実装\n\n```\n\n kaiinAll.get(id)\n \n```\n\nは、インデックスとは無関係の値を引数にしています。\n\n(コメントを受けて追記)\n\n> 修正しましたが、うまく表示されませんでした。\n\n`System.out.println()` の引数にオブジェクトを渡すと\n[`toString()`](https://docs.oracle.com/javase/jp/17/docs/api/java.base/java/lang/Object.html#toString\\(\\))\nメソッドにより生成された文字列が出力されます。`Kaiin` クラスは `toString()` メソッドを実装していないので、デフォルト実装\n\n```\n\n getClass().getName() + '@' + Integer.toHexString(hashCode())\n \n```\n\nが用いられます。 \nこれはおそらく期待する出力とは異なるでしょう。\n\n解決策としては、`Kaiin`クラスで `toString()` をオーバライドして適切に実装を行う、ということが考えられます。\n\n```\n\n public class Kaiin {\n // ...\n \n @Override\n public String toString() {\n // ここで出力する文字列を組み立てる\n return \"TODO\";\n }\n }\n \n```\n\n(ただし、今回の課題は必ずしも `toString()` を利用すべし、というものでは無さそうにも見えます。)\n\n* * *\n\nなお、リンク先の課題は\n\n> 出力はプログラムの最後にまとめて行ってください。\n\nということなので、最終的には \"直前に登録した要素のインデックスは...\"\nというようなことは考えず、リストに登録されている全要素をループで一気に出力する、ということになるかと思います。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T23:47:35.770",
"id": "86542",
"last_activity_date": "2022-02-24T07:55:07.090",
"last_edit_date": "2022-02-24T07:55:07.090",
"last_editor_user_id": "2808",
"owner_user_id": "2808",
"parent_id": "86530",
"post_type": "answer",
"score": 0
}
] | 86530 | null | 86536 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "無料gmailアカウントで、GASのスクリプトを作っています。 \nメール送信上限が100であることが確認されたため、 \n「google workspace」では1500件にアップするとのことで、移行を決め、workspaceに有料化いたしました。 \nGASのメール送信上限を確認するには下記の質問で既出の通り確認できましたが、 \n[G\nsuite契約で適切なメール送信可能件数を取得したい](https://ja.stackoverflow.com/questions/37938/g-suite%e5%a5%91%e7%b4%84%e3%81%a7%e9%81%a9%e5%88%87%e3%81%aa%e3%83%a1%e3%83%bc%e3%83%ab%e9%80%81%e4%bf%a1%e5%8f%af%e8%83%bd%e4%bb%b6%e6%95%b0%e3%82%92%e5%8f%96%e5%be%97%e3%81%97%e3%81%9f%e3%81%84)\n\nworkspaceに移行したあとのスプレッドシートの権限譲渡および上限の増やし方はどのようにすればよろしいでしょうか。\n\n参考に下記回答をworkspaceチームよりいただいております。 \n1.まず、共有ドライブに新規でフォルダを作成します \n2.作成されたフォルダに入り、[メンバーを共有]ボタンをクリック \n3.外部ユーザー[Gmail アカウント]のメールアドレスを入力します \n4.与えたい権限を選択し、「送信」ボタンをクリック \n5.「組織外のメンバーと共有しますか?」という画面が表示され「このまま共有」をクリック\n\n上記の手順ができましたら、以下の手順に沿ってスプレットシートなどのドキュメントを移動してください。\n\n①まず、上記でフォルダを作成されたユーザーとスプレットシートを共有ください。\n\n②スプレットシートを移動する方法\n\n1.移動されたいスプレッドシートなどを開き \n2.スプレットシートのタイトルの隣で表示されているフォルダ→マークをクリック \n3.「マイドライブ」というのが表示されている左の方の矢印をクリックし、「共有ドライブ」を選択 \n4.作成されたフォルダを選択し、「移動」ボタンをクリック\n\n上記の手順でスプレットシートなどのドキュメントを移行することが可能となります。\n\n該当フォルダのメンバーであれば誰もが管理ができますので、オーナーという権限はなくなります。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T06:56:25.270",
"favorite_count": 0,
"id": "86531",
"last_activity_date": "2022-02-23T06:56:25.270",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "34545",
"post_type": "question",
"score": 0,
"tags": [
"google-apps-script",
"google-spreadsheet"
],
"title": "GASのオーナー権限譲渡についておよび メールリミット1500まで引き上げたい",
"view_count": 224
} | [] | 86531 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "gulp-rsync でファイルを同期しようとすると、以下のエラーが表示されました。\n\n```\n\n gulp-rsync: rsync error: error in rsync protocol data stream (code 12)\n \n```\n\n不安定なインターネット接続や間違っている接続先の様な簡単な理由でしたら、この質問を伺いするまでではなかったので、自分の努力を報告します。 \n尚、接続先 (VPS) は練習用なので、IPアドレス等の情報はそのまま載せています。\n\n```\n\n import Gulp from \"gulp\";\n import GulpRSync from \"gulp-rsync\";\n \n Gulp.task(\n \"Deploy\",\n (): NodeJS.ReadWriteStream => Gulp.src(\"03-ProductionBuild/BackEndEntryPoint.js\").\n pipe(GulpRSync({\n root: \"03-ProductionBuild/\",\n hostname: \"160.251.43.156\",\n port: \"22\",\n username: \"non_root_admin\",\n destination: \"/var/www/yamatodaiwa.com\"\n }))\n );\n \n```\n\n## 間違っている接続先原因除外\n\nこの原因の可能性があると言われたのは以下のページです。\n\n[バックアップログにエラーが記録される場合の対処方法は |\nバッファロー](https://www.buffalo.jp/support/faq/detail/2633.html)\n\nパスワードを聞かれたら、正しいパスワードを入力してみます。\n\n[](https://i.stack.imgur.com/nAz8I.png)\n\n上記のがエラーが発生します。\n\n```\n\n Message:\n Error: rsync exited with code 12\n at ChildProcess.<anonymous> (D:\\IntelliJ IDEA\\InHouseDevelopment\\yamatodaiwa.com\\node_modules\\gulp-rsync\\rsync.js:121:17) \n at ChildProcess.emit (node:events:390:28)\n at ChildProcess.emit (node:domain:537:15)\n at maybeClose (node:internal/child_process:1064:16)\n at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)\n at Process.callbackTrampoline (node:internal/async_hooks:130:17)\n \n```\n\n今回はパスワードをわざと間違って入力してみます。 \n違うエラーが発生します。\n\n```\n\n [email protected]'s password: [18:36:47] gulp-rsync: Permission denied, please try again. \n \n```\n\n従って、バックエンド側は認証まで正常に動いています。念の為一般のターミナルで接続してみます。\n\n[](https://i.stack.imgur.com/37sFd.png)\n\n成功でした。\n\n## サーバー側でrsyncが入っていない原因除外\n\nターミナルVPSと接続し`rsync -v`で除外完了です。\n\n[](https://i.stack.imgur.com/6bJp8.png)\n\n## サーバー側で容量が足りない原因除外\n\nコードで同期しようとしているファイルの **BackEndEntryPoint.js** はたった92.0\nKBです。VPS側のディスク使用量の情報は以下の通りです。\n\n[](https://i.stack.imgur.com/P68iD.png)\n\n* * *\n\n### 追記\n\n下記の実験の前にSSH接続の正常性を確認しました。\n\n#### 通常の rsync での実行結果\n\n```\n\n > rsync -a \"03-ProductionBuild/BackEndEntryPoint.js\" [email protected]:/var/www/yamatodaiwa.com \n [email protected]'s password: \n rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]\n rsync error: error in rsync protocol data stream (code 12) at io.c(235) [Receiver=3.1.3]\n rsync: connection unexpectedly closed (0 bytes received so far) [sender]\n rsync error: error in rsync protocol data stream (code 12) at io.c(228) [sender=3.2.3]\n \n```\n\n#### `-vvv` オプション付き\n\n```\n\n PS D:\\IntelliJ IDEA\\InHouseDevelopment\\yamatodaiwa.com> rsync -a \"03-ProductionBuild/BackEndEntryPoint.js\" [email protected]:/var/www/yamatodaiwa.com -vvv\n opening connection using: ssh -l non_root_admin 160.251.43.156 rsync --server -vvvlogDtpre.iLsfxCIvu . /var/www/yamatodaiwa.com (9 args)\n [email protected]'s password: \n rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]\n rsync error: error in rsync protocol data stream (code 12) at io.c(235) [Receiver=3.1.3]\n [Receiver] _exit_cleanup(code=12, file=io.c, line=235): about to call exit(12)\n rsync: connection unexpectedly closed (0 bytes received so far) [sender]\n rsync error: error in rsync protocol data stream (code 12) at io.c(228) [sender=3.2.3]\n [sender] _exit_cleanup(code=12, file=io.c, line=228): about to call exit(12)\n \n```",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T09:48:34.770",
"favorite_count": 0,
"id": "86533",
"last_activity_date": "2022-03-05T07:07:06.930",
"last_edit_date": "2022-02-27T06:00:54.543",
"last_editor_user_id": "3060",
"owner_user_id": "16876",
"post_type": "question",
"score": 1,
"tags": [
"linux",
"ubuntu",
"gulp",
"rsync"
],
"title": "gulp-rsync での同期時に error in rsync protocol data stream (code 12) が発生する",
"view_count": 1860
} | [
{
"body": "同期に伴うファイルやフォルダの作成にも適切な権限が必要です。\n\nコピー先に指定している `[email protected]:/var/www/yamatodaiwa.com` ですが、 \nそもそも `/var/www` は一般的に root 以外のユーザーで書き込みができないようになっています。\n\n**例:**\n\n```\n\n $ ls -ld /var/www\n drwxr-xr-x 4 root root 4096 1月 25 23:09 /var/www/\n \n```\n\n実行ユーザーの `non_root_admin` が非 root ユーザーなのであれば、以下いずれかの対応が考えられます。\n\n * `/var/www` に 対して non_root_admin でも書き込めるようにする\n * `/var/www/yamatodaiwa.com` を事前に作成して non_root_admin でも書き込めるようにする\n\nもしくは、non_root_admin で `sudo` コマンドが許可されているなら、ローカル側での `rsync` コマンドで \n`--rsync-path` オプションを使う方法が手っ取り早いかもしれません。\n\n[rsync でリモート側の実行権限が非 root\nユーザーの場合、ファイルの所有者情報がコピーされない](https://ja.stackoverflow.com/a/86551)\n\n>\n```\n\n> # rsync --rsync-path=\"sudo rsync\" -auvz /path/to/SOURCE\n> ec2-user@REMOTE:/path/to/TARGET\n> \n```",
"comment_count": 7,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T12:30:11.897",
"id": "86687",
"last_activity_date": "2022-03-05T07:07:06.930",
"last_edit_date": "2022-03-05T07:07:06.930",
"last_editor_user_id": "3060",
"owner_user_id": "3060",
"parent_id": "86533",
"post_type": "answer",
"score": 3
}
] | 86533 | null | 86687 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "adbコマンドでユーザビリティの設定変更をする方法がわかりません。\n\n特に、talkbackやSelect to Speakをなどの音声出力に関する設定をONに切り替える方法はないでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T11:54:59.797",
"favorite_count": 0,
"id": "86538",
"last_activity_date": "2022-02-23T14:31:14.427",
"last_edit_date": "2022-02-23T14:31:14.427",
"last_editor_user_id": "51577",
"owner_user_id": "51577",
"post_type": "question",
"score": 2,
"tags": [
"android",
"adb"
],
"title": "adbコマンドによるユーザビリティの設定変更",
"view_count": 65
} | [] | 86538 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "ワーカーが労働済みの仕事という意味の変数名を作りたい場合。 \njobs_worker_already_worked_for\n\njobs (which) the worker already worked\nforという関係代名詞で修飾された名詞を変数名にした形ですが、関係代名詞風の変数名ってあまり一般的ではないですかね? \n(もしかしたら正確には現在完了形じゃないとおかしいかもです=> jobs (which) the worker **has** already worked\nfor)\n\n結構複雑な意味をもたせたい場合どうしても関係代名詞風にしないとニュアンスが表せられない事があると思うんですが、かえってわかりにくいですかね?",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T12:14:32.083",
"favorite_count": 0,
"id": "86539",
"last_activity_date": "2022-02-24T00:39:59.033",
"last_edit_date": "2022-02-23T12:46:07.773",
"last_editor_user_id": "3060",
"owner_user_id": "40650",
"post_type": "question",
"score": 1,
"tags": [
"ruby-on-rails",
"英語"
],
"title": "関係代名詞みたいな変数名ってアリですか?",
"view_count": 265
} | [
{
"body": "正式に「これだ」というものはございません。また、[Rubyのコーディング規約](https://www.ruby.or.jp/ja/tech/development/ruby/050_coding_rule.html)においても正式なものは存在しないとされています。参考のために、当該ページのリンク先を参照するのが良いかと思われます。 \n他の言語で言えば[Pythonの規約(PEP8)](https://pep8-ja.readthedocs.io/ja/latest/#section-30)において、変数名は読みやすさのために必要に応じて単語区切りにすることが推奨されています。\n\nまた、質問に対する(主観的な)回答としては、関係代名詞風にするのは適切ではないと考えます。あくまで代名詞であるため、コードを読んだ人に解釈を委ねる形になります。そのような場合は変数の説明として用いるのが適切でしょう。 \n上記の「ワーカーが労働済みの仕事」であれば`tasks_already_done_by_the_worker`や`tasks_completed_by_worker`と短くするか、`jobs`及び`tasks`をオブジェクトとし、そのメンバーとして、bool値で`is_completed`を持たせた方が可読性の向上につながると考えられます。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T00:16:41.150",
"id": "86544",
"last_activity_date": "2022-02-24T00:39:59.033",
"last_edit_date": "2022-02-24T00:39:59.033",
"last_editor_user_id": "51317",
"owner_user_id": "51317",
"parent_id": "86539",
"post_type": "answer",
"score": 3
}
] | 86539 | null | 86544 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "現在、携帯アプリで作成したデータをPC側から取り込んで使用するシステムを作成しているのですが、android11以降の携帯では、セキュリティが強化されて、PC側からファイルを読み取れない状態になっています。 \nandroid11以降の携帯で、この動きを実現しようとした場合、GooglePlayに申請して承認をもらう必要があるようですが、1つの携帯でしか使用しないアプリに関しても、GooglePlayに申請して承認を受けないといけないのでしょうか。 \n別に世界に向けて売り出すようなアプリではなく、1つの携帯だけで稼働すればいい単純なアプリです。 \n何か他にやり方は無いのでしょうか。\n\n※携帯からデータを取り出すPCはインターネットに接続できない環境にあるPCです\n\n本来であれば、GoogleのPlayConsoleヘルプに問い合わせるべきなのでしょうが、一般的にアプリを売り出すつもりがないため、デベロッパーアカウントを作成しておらず、GooglePlayのコミュティでも、こう言った質問は受け付けていないとの事でした。\n\n申し訳ありませんが、何か情報をお持ちの方、教えていただければ幸いです。 \nよろしくお願いします。",
"comment_count": 6,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-23T23:49:56.843",
"favorite_count": 0,
"id": "86543",
"last_activity_date": "2023-09-03T01:19:07.857",
"last_edit_date": "2022-02-24T04:05:40.150",
"last_editor_user_id": "51584",
"owner_user_id": "51584",
"post_type": "question",
"score": 0,
"tags": [
"android",
"android-studio"
],
"title": "androidアプリ開発で、android11以降の携帯とPCとのデータのやり取りについて",
"view_count": 82
} | [
{
"body": "何かしらの外部ストレージを差し込んで、その中に保存をPC側からしておいて \nアプリ側からその外部ストレージを読みに行くとかできるんじゃないでしょうか…?\n\n後は、アプリのパーミッションでストレージ読み書きを許可してあげればいいかと思います。 \nやっぱり、アプリ内のストレージには外部から読み書きできないんですかね…。 \n昔はできたんですが。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2023-09-03T01:19:07.857",
"id": "96108",
"last_activity_date": "2023-09-03T01:19:07.857",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "59651",
"parent_id": "86543",
"post_type": "answer",
"score": 0
}
] | 86543 | null | 96108 |
{
"accepted_answer_id": "86566",
"answer_count": 3,
"body": "Windows の MSVC を初めて使用します。 ( macOS/Linux で GCC/Clang は使ったことがあります) \n簡単な次のファイルを cl.exe でコンパイルしようと思います。\n\nprog.c\n\n```\n\n #include <stdio.h>\n \n int main(int argc,char* argv[]) {\n \n printf(\"Hello world\\n\");\n return 0;\n \n }\n \n```\n\nコンパイルのコマンドは\n\n```\n\n cl.exe /EHsc /Feprog.exe prog.c\n \n```\n\nすると、 prog.obj と prog.exe が特に問題なく生成されたように思われます。 \nところが prog.exe は実行できません。 prog.exe の内容を Hex 表示すると 000000 (ヌル文字)\nがひたすら続くファイルになっています。 \nどうしたら適切に実行できるバイナリが生成できるか教えていただけませんでしょうか。\n\nインストールした開発環境\n\n * MSVC v143 x64/x86 ビルド\n * Visual Studio Community 2022\n * Windows 10 SDK (10.0.19041.0)\n * Windows 11 21H2\n\n## 追記\n\n情報が不足していて申し訳ありません。\n\n * 作業環境は Visual Studio Code で、統合ターミナルから次の batch ファイルを実行してコマンドプロンプトを開きました\n\n```\n\n @echo off\n %COMSPEC% /k \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat\"\n \n```\n\nこのコマンドプロンプト内で `cl.exe /EHsc /Feprog.exe prog.c` を実行しています。\n\n * Developer Command Prompt / Developer PowerShell でも試してみましたが同様の結果です。 `.\\prog.exe` に対して `指定されたプログラムは実行できません。` と返ってきます。\n\n * `cl.exe` の出力メッセージは次の通りです\n\n```\n\n Microsoft(R) C/C++ Optimizing Compiler Version 19.31.31104 for x86\n Copyright (C) Microsoft Corporation. All rights reserved.\n \n prog.c\n Microsoft (R) Incremental Linker Version 14.31.31104.0\n Copyright (C) Microsoft Corporation. All rights reserved.\n \n /out:prog.exe \n prog.obj\n \n \n```\n\n * prog.obj はヌル文字のみのファイルではなかったので、 `link.exe` に問題があるんじゃないかと思っています。 `link.exe prog.obj /out:prog.exe` も試してみたら、毎度ヌル文字の prog.exe が生成されます。 link.exe の出力は次の通り。\n\n```\n\n Microsoft (R) Incremental Linker Version 14.31.31104.0\n Copyright (C) Microsoft Corporation. All rights reserved.\n \n \n \n```\n\n * `dir` の出力でディレクトリ構成を説明します。\n\n```\n\n Directory of C:\\Users\\*\\prog\n \n 2022/02/24 12:18 <DIR> .\n 2022/02/24 12:17 <DIR> ..\n 2022/02/24 12:18 101,888 prog.exe\n 2022/02/24 12:18 94 prog.c\n 2022/02/24 12:18 1,433 prog.obj\n 3 File(s) 105,175 bytes\n \n```\n\n * 基本的に Visual Studio を使わずに CLI 上でコンパイルを行いたいので、 Visual Studio の動作確認をあまりしていないのですが、動作確認はした方がよいのでしょうか。\n\n## 追記2\n\n * ご指摘の通り、上記では間違って x86 の Developer Command Prompt を使っていました。確かに x64 だとこういう出力になります。\n\n```\n\n Microsoft(R) C/C++ Optimizing Compiler Version 19.31.31104 for x64\n Copyright (C) Microsoft Corporation. All rights reserved.\n \n prog.c\n Microsoft (R) Incremental Linker Version 14.31.31104.0\n Copyright (C) Microsoft Corporation. All rights reserved.\n \n /out:prog.exe\n prog.obj\n \n \n```\n\nどちらにしても壊れた実行ファイルが生成され続けます。 \nVisual Studio 2022 を一旦削除して、再びインストールしてみたのですが、やはり変わっていません。\n\n * Visual Studio のプロジェクト (コンソール アプリ) を作って、特に書き換えずそのまま「デバッグなしで開始」を押してみたのですが\n\n```\n\n プログラム `<実行ファイルの場所>` を開始できません。\n ファイルまたはディレクトリが壊れているため、読み取ることができません。\n \n```\n\nというダイアログが表示されて実行できませんでした。\n\n * あとセキュリティソフトはインストールしていない環境です。インストールしているアプリの中から疑わしいものを探してみます。\n\n * Mac の MinGW-w64 の GCC で作成した実行ファイルを当該 Windows 環境に転送しても問題なく実行できました。",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T00:22:01.867",
"favorite_count": 0,
"id": "86545",
"last_activity_date": "2022-02-25T00:33:36.173",
"last_edit_date": "2022-02-24T13:18:04.317",
"last_editor_user_id": "4236",
"owner_user_id": "47308",
"post_type": "question",
"score": 1,
"tags": [
"c",
"windows",
"visual-c++"
],
"title": "cl.exe が壊れたバイナリしか出力しない",
"view_count": 509
} | [
{
"body": "コメントの応答が返る前に取り敢えず回答します。 \nコンパイルする前段階の作業が書かれていないのですが、この記事のように「開発者コマンド プロンプト」を起動していますか? \n[Visual\nStudioを使いコマンドラインからC/C++のプログラムをコンパイルする](https://www.javadrive.jp/cstart/install/index5.html) \n記事はVisual Studio 2017のものですが、Visual Studio\n2022でも同様のものか、あるいはスタートメニューの表示は英語のまま(Developer Command Prompt for VS\n2022とか)のものがあるはずです。\n\nそして記事に質問と同等/類似のソースコードが提示されていますが、この程度ならばそのコンパイル時にオプション等無くても実行ファイルは出来ます。\n\n別に質問のオプション指定方法が間違っているとか問題があるとかでは無さそうですが、紹介記事のようにそのままソースコードだけ指定してみてはどうでしょう?\n\nそれが出来てから色々とオプションを試していくのが良いと思われます。 \n[アルファベット順のコンパイラ オプション](https://docs.microsoft.com/ja-\njp/cpp/build/reference/compiler-options-listed-alphabetically?view=msvc-170) \n[カテゴリ別のコンパイラ オプション](https://docs.microsoft.com/ja-\njp/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170)\n\n* * *\n\n作業環境を設定するバッチファイルが`vcvars64.bat`で、`cl.exe`の出力メッセージの最初の行に以下の`for\nx86`が表示されるのは、整合性が取れていない感じがします。\n\n```\n\n Microsoft(R) C/C++ Optimizing Compiler Version 19.31.31104 for x86\n \n```\n\nこの末尾が`for x86`になるのは、`Developer Command Prompt for VS 2022`の`VsDevCmd.bat`,\n`x64_x86 Cross Tools Command Prompt for VS 2022`の`vcvarsamd64_x86.bat`, `x86\nNative Tools Command Prompt for VS 2022`の`vcvars32.bat`あたりのはず。\n\nただ cl.exe の32bit/64bitが違っても、出来てくる .exe\nは動作するみたいなので、もしかしたらVS2022の環境が完全では無いか壊れているのかもしれません。\n\n以下のような方法を試してみて、それでも解決しないようでしたら、Visual Studio\nInstallerで修復インストールとかいったんアンインストール/再インストールを試してみた方が良いと思われます。\n\n * VSCodeからではなく、スタートメニューからVS2022の各コマンドプロンプトを起動して、コンパイルしてみる。(質問の追記では済んでいる?)\n * @radian さんのコメントのように、VSCodeやコマンドプロンプトではなく、Visual Studio のIDE上でプロジェクトを作成し、ビルドしてみる。\n\nそれから @774RR\nさんコメントのようにセキュリティソフトのチェックが影響しているなら、セキュリティソフトのログに何かしら記録が残りそうです。そちらとかあと加えてイベントログを調べてみるのも手かもしれません。\n\n* * *\n\n可能性は低い/あるいは既にチェック済みかもしれませんが、ユーザー名や作業フォルダまでの途中のパス名にShift-\nJISとかIBM拡張の全角文字とか半角文字でも何かの記号とか空白とかが含まれているということはありませんか?\n\nあとはまったく別に、Visual Studio Community\n2022をインストールする時に、`ワークロード`のタブでC++系のものを選んだだけでインストールしていませんか?\n\n`個別のコンポーネント`のタブにC++系でも様々な種類とその版数違いのコンポーネントが示されていて、`ワークロード`で選んだだけだと割と多くのものがインストールされません。 \nそれが影響する可能性は不明なのですが、もしかすると何かあるかもしれないので、C++系の(ゲーム系とか実験段階のものを除く)すべてのコンポーネントをインストールしてみてください。\n\n* * *\n\n上記あたりまでやっても駄目なら、いよいよデータのバックアップを取ってWindows11のクリーンインストールからやり直すパターンでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T01:11:05.527",
"id": "86546",
"last_activity_date": "2022-02-24T12:26:31.837",
"last_edit_date": "2022-02-24T12:26:31.837",
"last_editor_user_id": "26370",
"owner_user_id": "26370",
"parent_id": "86545",
"post_type": "answer",
"score": 0
},
{
"body": "既にコメントが付いていますし、私も実際に同じ手順でプログラムを作成・実行できることを確認しました。そこから言えることは、手順には問題はありません。\n\nあるとすれば、質問者さん固有の環境問題でしかありません。\n\n * セキュリティソフトはインストールしていない環境\n * Visual Studio 2022 を一旦削除して、再びインストールしてみた\n\nなどは考えられる問題の1つであり、どちらも原因ではなかったというのであれば、更に別問題なのでしょう。あらゆる可能性があり、特定できたとして、質問者さんにしか適用されないので、Q&Aの蓄積の観点では微妙だったりします…。\n\n例えば、別のディレクトリで全く同じ操作を行ったら改善しませんか?\n\n* * *\n\n> プログラム `<実行ファイルの場所>` を開始できません。 \n> ファイルまたはディレクトリが壊れているため、読み取ることができません。\n\nとのこと、イベントログにエラーが出ていませんか?\nこの実行に付随して発生するエラーや、もしくは日常的に何らかのエラーが。特にディスクの読み取りエラーなどが発生していないか気になります。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T13:16:02.060",
"id": "86560",
"last_activity_date": "2022-02-24T13:16:02.060",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "86545",
"post_type": "answer",
"score": 1
},
{
"body": "正体不明のエラーに付き合っていただきありがとうございました。 \n色々調べる中で原因がなんとなくわかった気がします。\n\nここまで説明しなかったのですが、当該 Windows 環境は VMWare Fusion の仮想マシンでした。 \nprog.c, prog.exe などが VMWare の共有ディレクトリ (vmware-host)\nに存在していたことが原因のようです。これらのディレクトリを仮想マシンのストレージ (C:) に移動させたところ、問題なくコンパイルできました。\n\nVMWare のコミュニティでも似た質問? をしている方がおられました: \n<https://communities.vmware.com/t5/VMware-Workstation-Pro/Visual-Studio-cl-\nexe-in-guest-OS-bad-performance/td-p/1913013>\n\n質問でディレクトリの場所を `C:/Users/*/prog` としていたのは、C: 中に vmware-host\nへのリンクを張り、そちらを介してアクセスしていたためです。混乱された方がいらっしゃったらすみません。",
"comment_count": 5,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-25T00:33:36.173",
"id": "86566",
"last_activity_date": "2022-02-25T00:33:36.173",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "47308",
"parent_id": "86545",
"post_type": "answer",
"score": 3
}
] | 86545 | 86566 | 86566 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "RestfulAPI を設計しております。 \nURIはリソース的な記述が良いとされていますが、以下のようなケースの場合、どちらの記述がよいでしょうか?\n\n対象:POSTメソッド\n\nAというリソースに対して、POSTメソッドで操作します。 \n操作には、以下のようなものがあるとします。 \nentry:新規追加 \nupdate:指定したAのIDに対して、パラメータを更新 \ncopy:指定したAのIDを新規IDとして複製する \nそれぞれの操作によって、リクエストボディに含めることができる必須パラメータ等が異なります。\n\n操作については、リソースではないので、URIに含めない案1のほうが良いと思いますが、opキーのパラメータにより、その後のパラメータを判断しなくてはなりません。 \n案2であると、操作によって、決められたパラメータがあるかをリクエストボディ内でチェックすればよく、また、URI毎の構文例として提示する際にもスッキリとドキュメント化できると考えています。\n\n直感的に理解しやすいのは案2のような気がします。\n\n案1:\n\n```\n\n URI:\n http://{host}/A/\n リクエストボディ:\n {\n \"op\":\"entry\",\n ...\n }\n \n```\n\n案2:\n\n```\n\n URI:\n http://{host}/A/entry\n リクエストボディ:\n {\n ...\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T02:05:03.783",
"favorite_count": 0,
"id": "86547",
"last_activity_date": "2022-02-24T02:05:03.783",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "32891",
"post_type": "question",
"score": 0,
"tags": [
"webapi"
],
"title": "RestfulAPI URI記述:どちらのほうが最適でしょうか?",
"view_count": 82
} | [] | 86547 | null | null |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "centosでのpythonの入れ直しのやり方が分かりません。 \ncentos上にpython3を入れたのですが、sqliteを先に入れるのを忘れていた為、 \npythonを入れ直しを行わないといけないそうなのですが、うまくアンインストールが出来ません。\n\nどうすればいいのでしょうか? \n \n[](https://i.stack.imgur.com/XTmyN.png)\n\n* * *\n\n追記 \npython3.9のインストールは、下記のサイトに従いインストールを行いました。 \n<https://mebee.info/2021/02/24/post-29350/>\n\n```\n\n which python3.9\n /usr/local/bin/python3.9\n \n```\n\n* * *\n\n追記 \npythonを入れ直しをしましたが、うまく行きませんでした。 \nsqliteがインストール出来ていないのかの確認を行いました。\n\n```\n\n [jirow04@jirow04 centos 初期インストール設定]$ jupyter notebook\n Traceback (most recent call last):\n File \"/home/jirow04/.local/lib/python3.9/site-packages/notebook/services/sessions/sessionmanager.py\", line 9, in <module>\n import sqlite3\n File \"/usr/local/lib/python3.9/sqlite3/__init__.py\", line 57, in <module>\n from sqlite3.dbapi2 import *\n File \"/usr/local/lib/python3.9/sqlite3/dbapi2.py\", line 27, in <module>\n from _sqlite3 import *\n ModuleNotFoundError: No module named '_sqlite3'\n \n During handling of the above exception, another exception occurred:\n \n Traceback (most recent call last):\n File \"/home/jirow04/.local/bin/jupyter-notebook\", line 5, in <module>\n from notebook.notebookapp import main\n File \"/home/jirow04/.local/lib/python3.9/site-packages/notebook/notebookapp.py\", line 83, in <module>\n from .services.sessions.sessionmanager import SessionManager\n File \"/home/jirow04/.local/lib/python3.9/site-packages/notebook/services/sessions/sessionmanager.py\", line 12, in <module>\n from pysqlite2 import dbapi2 as sqlite3\n ModuleNotFoundError: No module named 'pysqlite2'\n [jirow04@jirow04 centos 初期インストール設定]$ sqlite -V\n bash: sqlite: コマンドが見つかりませんでした...\n [jirow04@jirow04 centos 初期インストール設定]$ sqlite\n bash: sqlite: コマンドが見つかりませんでした...\n [jirow04@jirow04 centos 初期インストール設定]$ ^C\n [jirow04@jirow04 centos 初期インストール設定]$ sqlite3 --version\n 3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T05:08:06.960",
"favorite_count": 0,
"id": "86548",
"last_activity_date": "2022-02-25T08:18:03.223",
"last_edit_date": "2022-02-25T08:18:03.223",
"last_editor_user_id": "42741",
"owner_user_id": "42741",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3",
"centos"
],
"title": "centosでのpythonの入れ直しのやり方が分かりません。",
"view_count": 117
} | [] | 86548 | null | null |
{
"accepted_answer_id": "86593",
"answer_count": 1,
"body": "2点間の与えられた始点と終点の間に連続した点を置く為に、ブレゼンハムのアルゴリズムを使用したいのですが、座標(x,y)がCGFloat値で小数点以下の数値があります。 \nそこも含めて一旦、整数値Intにし計算する必要があると思うのですが、欲しいのは最終的に小数点を含むCGFloat値である為、どの様にSwiftで小数点→整数→小数点にするのが効率よく記述できますでしょうか。ブレゼンハムのコード自体は以下の様にしたいと考えています。宜しくお願い致します。\n\n```\n\n func getPoints(p0: CGPoint, p1: CGPoint) -> [CGPoint] {\n var points = [CGPoint]()\n var x0: Int = Int(p0.x)\n var y0: Int = Int(p0.y)\n let x1: Int = Int(p1.x)\n let y1: Int = Int(p1.y)\n let dx: Int = Int(abs(p1.x - p0.x)) // DeltaX\n let dy: Int = Int(abs(p1.y - p0.y)) // DeltaY\n let sx: Int = (p1.x>p0.x) ? 1 : -1 // StepX\n let sy: Int = (p1.y>p0.y) ? 1 : -1 // StepT\n var err = dx - dy\n while true {\n if x0 >= 0, y0 >= 0 { points.append(CGPoint(x: x0, y: y0)) }\n if x0 == x1, y0 == y1 { break }\n let e2 = 2*err\n if e2 > -dy {\n err -= dy\n x0 += sx\n }\n if e2 < dx {\n err += dx\n y0 += sy\n }\n }\n return points\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T05:53:20.250",
"favorite_count": 0,
"id": "86549",
"last_activity_date": "2022-02-27T03:15:54.780",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14780",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"ios"
],
"title": "CGFloat値の小数点以下を含む数値を整数にし、また小数点を含む数値に戻したい。",
"view_count": 250
} | [
{
"body": "浮動小数点数(`CGFloat`)と整数(`Int`)の変換ではなく、丸め処理(`rounded()`)で小数点以下を切り捨てたほうが、処理時間を短縮できるという結果になりました。\n\n```\n\n import Foundation\n \n // 質問で提示された、CGFloatとInt間の変換を伴う処理\n func getPointsA(p0: CGPoint, p1: CGPoint) -> [CGPoint] {\n var points = [CGPoint]()\n var x0: Int = Int(p0.x)\n var y0: Int = Int(p0.y)\n let x1: Int = Int(p1.x)\n let y1: Int = Int(p1.y)\n let dx: Int = Int(abs(p1.x - p0.x))\n let dy: Int = Int(abs(p1.y - p0.y))\n let sx: Int = (p1.x > p0.x) ? 1 : -1\n let sy: Int = (p1.y > p0.y) ? 1 : -1\n var err = dx - dy\n \n while true {\n if x0 >= 0, y0 >= 0 {\n points.append(CGPoint(x: x0, y: y0))\n }\n if x0 == x1, y0 == y1 {\n break\n }\n let e2 = err * 2\n if e2 > -dy {\n err -= dy\n x0 += sx\n }\n if e2 < dx {\n err += dx\n y0 += sy\n }\n }\n \n return points\n }\n \n // 丸め処理で、小数点以下を切り捨てる処理\n func getPointsB(p0: CGPoint, p1: CGPoint) -> [CGPoint] {\n var points = [CGPoint]()\n var x0 = p0.x.rounded(.down)\n var y0 = p0.y.rounded(.down)\n let x1 = p1.x.rounded(.down)\n let y1 = p1.y.rounded(.down)\n let dx = abs(p1.x - p0.x)\n let dy = abs(p1.y - p0.y)\n let sx = (p1.x > p0.x) ? 1.0 : -1.0\n let sy = (p1.y > p0.y) ? 1.0 : -1.0\n var err = dx - dy\n \n while true {\n if x0 >= 0, y0 >= 0 {\n points.append(CGPoint(x: x0, y: y0))\n }\n if x0 == x1, y0 == y1 {\n break\n }\n let e2 = err * 2\n if e2 > -dy {\n err -= dy\n x0 += sx\n }\n if e2 < dx {\n err += dx\n y0 += sy\n }\n }\n \n return points\n }\n \n // 処理時間の比較\n let startTime = Date()\n let points = getPointsA(p0: CGPoint(x: 0.0, y: 0.0), p1: CGPoint(x: 5000.3, y: 10000.7))\n let interval = -startTime.timeIntervalSinceNow\n print(interval)\n \n let startTime2 = Date()\n let points2 = getPointsB(p0: CGPoint(x: 0.0, y: 0.0), p1: CGPoint(x: 5000.3, y: 10000.7))\n let interval2 = -startTime2.timeIntervalSinceNow\n print(interval2)\n \n // 結果\n // 0.00038504600524902344\n // 0.00018894672393798828\n \n```\n\n型変換のコストがかからない分、時間が短いということだと思われます。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T03:15:54.780",
"id": "86593",
"last_activity_date": "2022-02-27T03:15:54.780",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "18540",
"parent_id": "86549",
"post_type": "answer",
"score": 0
}
] | 86549 | 86593 | 86593 |
{
"accepted_answer_id": "86551",
"answer_count": 1,
"body": "rsync を使ってサーバ間でファイルを同期しようとしています。\n\n実行ユーザーがローカルは root ですが、リモート側は Amazon EC2 の環境で ec2-user (一般ユーザー) となっており、rsync\nコマンドのオプションに `-a` (アーカイブモード) を指定しているにも関わらず、コピーしたファイルの所有者がすべて ec2-user\nになってしまいます。\n\n元の権限 (所有者情報) を維持したままコピーするにはどうすればよいでしょうか?\n\n**現状の実行例:**\n\n```\n\n # rsync -auvz /path/to/SOURCE ec2-user@REMOTE:/path/to/TARGET\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T08:22:57.487",
"favorite_count": 0,
"id": "86550",
"last_activity_date": "2022-02-24T08:22:57.487",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3060",
"post_type": "question",
"score": 0,
"tags": [
"linux",
"amazon-ec2",
"rsync"
],
"title": "rsync でリモート側の実行権限が非 root ユーザーの場合、ファイルの所有者情報がコピーされない",
"view_count": 1359
} | [
{
"body": "rsync のオプション `--rsync-path` で rsync コマンドを `sudo` 経由で呼び出すことで解決しました。\n\n**実行例:**\n\n```\n\n # rsync --rsync-path=\"sudo rsync\" -auvz /path/to/SOURCE ec2-user@REMOTE:/path/to/TARGET\n \n```\n\n**参考にしたページ:** \n[リモートでsudoしてrsyncしたい](https://mattintosh.hatenablog.com/entry/20200325/1585115330)",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T08:22:57.487",
"id": "86551",
"last_activity_date": "2022-02-24T08:22:57.487",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3060",
"parent_id": "86550",
"post_type": "answer",
"score": 0
}
] | 86550 | 86551 | 86551 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "USBメモリに入れたUbuntu LIVE USBでクラッシュしてしまったようです。 \n再起動できない状態です。 \n起動しようとすると、キャレットが左上に表示されたまま、止まってしまいます。 \n他のWindowsパソコンにUSBをさすと、「アクセスできません」とエラーが出ます。 \nUbuntu\nDesttopが入っているパソコンに差すと、ユーティリティのディスクアプリからは、/dev/sdbに認識されているようですが、「メディアなし」とオレンジになってしまいます。 \nコンソールからも試しました。 \n`fdisk`、`mount`、`dd`、`gparted`、`gddrescue`いずれもディスクを見つけられない状態です。 \n`lsusb`では\n\n```\n\n Bus 001 Device 013: ID 0930:6544 Toshiba Corp. TransMemory-Mini / Kingston DataTraveler 2.0 Stick\n \n```\n\nと出てきて、USBが認識されているような表示が出ました。USB2.0と、ずいぶん古いものを使っていたわけですね。 \n`/dev/disk/by-id/`とディレクトリ内を見てみると\n\n```\n\n /dev/disk/by-id/usb-GENERIC_USB_Mass_Storage_0014780DE1B7CEB1E7706517-0:0\n \n```\n\nといった感じで、USB自体は認識されているようです。 \nパーティションあるいはスーパーブロックが見つからない、状態とでもいいましょうか。\n\n定番の **Testdisk** も試しましたが、USBはリストに表示されませんでした。 \nknoppixやUBCDでもディスク系、パーティション系のアプリを使ってみたのですが、如何せんディスクを認識しない状態です。 \nEase UsやAOMEIなんかもWindowsから使ってみましたが、USB自体を捉えられません。\n\n`gdisk`と`/dev/disk/by-id`を使うと、\n\n```\n\n gdisk /dev/disk/by-id/usb-GENERIC_USB_Mass_Storage_0014780DE1B7CEB1E7706517-0\\:0\n GPT fdisk (gdisk) version 1.0.5\n \n Problem reading disk in BasicMBRData::ReadMBRData()!\n Warning! Read error 22; strange behavior now likely!\n Warning! Read error 22; strange behavior now likely!\n Partition table scan:\n MBR: MBR only\n BSD: not present\n APM: not present\n GPT: not present\n \n \n ***************************************************************\n Found invalid GPT and valid MBR; converting MBR to GPT format\n in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by\n typing 'q' if you don't want to convert your MBR partitions\n to GPT format!\n ***************************************************************\n \n```\n\nこんな感じになります。 \nもし`dd`でバックアップをとれていたら、`MBR`を`GPT`に変えてみるとかしてみたいところなのですが、バックアップしないで行うのはリスクなので避けています。\n\nまた、カバーを外して基盤も見てみましたが、ハンダがはがれているとか、ICに損傷があるとかは見受けられません。接点復活剤をかけてみましたが変わらず。\n\nこのような状態ではありますが、次の1手があるとしたらどのような方法がありますか? \n壊れたパーティションでもいいので見つかれば打つ手はありそうなんですが、、 \n詳しい方がおられましたらご教示いただけますと幸いです。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T10:40:19.943",
"favorite_count": 0,
"id": "86553",
"last_activity_date": "2022-02-24T10:40:19.943",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51589",
"post_type": "question",
"score": 0,
"tags": [
"linux",
"ubuntu",
"usb"
],
"title": "USBメモリに入れたUbuntu LIVE USBがクラッシュ。起動ができない上、パーティションも見りません。",
"view_count": 482
} | [] | 86553 | null | null |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "Excel VBAでOutlookのメールを作成するのですが、実行後にメールの画面がアクティブにならないことがあります。\nアクティブ(最前面)にする方法を教えてください。\n\nコードは以下のような感じです。\n\n```\n\n Dim objOutlook As Outlook.Application\n Dim objMail As Outlook.MailItem\n Set objOutlook = CreateObject(\"Outlook.Application\")\n Set objMail = objOutlook.CreateItem(olMailItem)\n With objMail\n .To = \"[email protected]\" \n .Subject =\"〇〇〇の件\" \n .BodyFormat = olFormatPlain \n .Body = \"メール本文\" \n .Display\n End With\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T12:32:17.700",
"favorite_count": 0,
"id": "86559",
"last_activity_date": "2022-09-06T11:22:26.283",
"last_edit_date": "2022-02-24T14:58:18.650",
"last_editor_user_id": "3060",
"owner_user_id": "48200",
"post_type": "question",
"score": 0,
"tags": [
"vba",
"excel",
"mail"
],
"title": "Excel VBA でOutlookのメールを作成するのですが、実行後にメールの画面がアクティブにならないことがあるので、 アクティブ(最前面)にする方法を教えてください。",
"view_count": 1918
} | [
{
"body": "私も同じことをやりたくてここにたどり着きました。\n\n.Display \nと \nEnd With \nの間に \n.GetInspector.Activate \nという1行を入れるとできました。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-07-06T09:52:37.890",
"id": "89791",
"last_activity_date": "2022-07-06T09:52:37.890",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "53398",
"parent_id": "86559",
"post_type": "answer",
"score": 1
},
{
"body": "私も上記の修正では前面に来ないことが出てきました。\n\nそこで、以下の通り書き換えて試しています。\n\n**修正前:**\n\n```\n\n .GetInspector.Activate\n \n```\n\n**修正後:**\n\n```\n\n .GetInspector.Display (False)\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-09-06T09:50:45.000",
"id": "90961",
"last_activity_date": "2022-09-06T11:22:26.283",
"last_edit_date": "2022-09-06T11:22:26.283",
"last_editor_user_id": "3060",
"owner_user_id": "53399",
"parent_id": "86559",
"post_type": "answer",
"score": 1
}
] | 86559 | null | 89791 |
{
"accepted_answer_id": "86564",
"answer_count": 1,
"body": "Macで収録した`.mov`をWindowsもしくはWSL2で長期保存用のなにかしらにエンコードするのが差し当たっての目標です.\n\n次のような引数の構成で`.mov`を`.mp4`に変換します:\n\n```\n\n ffmpeg -to 01:07:10 -i input.mov \\\n -vcodec hevc_nvenc -r 30 -vf crop=1116:1600:720:0 output.mp4\n \n```\n\n出力ファイルのサイズ:\n\n * `-vcodec hevc_nvenc`をつけると667.8 MB\n * `-vcodec h264_nvenc`をつけると604.1 MB\n * `-vcodec`をつけないと245.8 MB\n\nH.264を用いた方がH.265よりサイズが小さくなるのは異常に思えますし,NVEncに関連するパラメータを用いるとファイルサイズが大きくなるのは直感に反します. \nGPUを使うメリットってなんですか? \nGPUを使うと多少処理が速くなりますがこれではデメリットの方が大きく感じます. \nハードウェアエンコードってこういうものですか? \n根本から間違えている気がします.",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T20:32:24.113",
"favorite_count": 0,
"id": "86563",
"last_activity_date": "2022-02-25T00:08:56.517",
"last_edit_date": "2022-02-25T00:08:56.517",
"last_editor_user_id": "3060",
"owner_user_id": "50898",
"post_type": "question",
"score": 0,
"tags": [
"ffmpeg"
],
"title": "FFmpegのhevc_nvencの圧縮率について",
"view_count": 1797
} | [
{
"body": "[結局ハードウェアエンコードってどうなの?(H265篇)](https://qiita.com/yamakenjp/items/6a37afef25b1e4254669)という記事がありました。 \nこの記事では\n\n * X264(X265?)によるソフトウェアエンコード\n * Intel HD 630を使ったIntelQSV\n * NVIDIA T400をつかったNVENC\n\nを比較し、VMAFによる動画の品質を評価するツールで検証しています。まとめから引用しますと\n\n>\n> 改めてx265とQSV、NVEncを比較しましたが、単純にビットレートやqP指定でのエンコードの場合、HWエンコーダの特性を考えて最適な値にしないと、ただ早くて画質は悪いという状況になるため、パラメータの調整が必須というのがよくわかったのと、VMAFにて客観的な比較ができるため、VMAFの値を参考にチューニングをする必要がある。\n\nとのことです。詳細は記事を参照ください。\n\n長期保存目的であれば、x265などソフトウェアエンコードの方が適切かもしれません。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-24T21:23:38.597",
"id": "86564",
"last_activity_date": "2022-02-24T21:23:38.597",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "86563",
"post_type": "answer",
"score": 2
}
] | 86563 | 86564 | 86564 |
{
"accepted_answer_id": "86570",
"answer_count": 2,
"body": "Name | TEL1 | TEL2 | TEL3 \n---|---|---|--- \nTarou | 000-0000-0000 | 111-1111-1111 | 222-2222-2222 \nHanako | 333-3333-3333 | 444-4444-4444 | NULL \n \nという一つのテーブルに同じ項目を複数持っているようなものをばらして\n\nName | TEL \n---|--- \nTarou | 000-0000-0000 \nTarou | 111-1111-1111 \nTarou | 222-2222-2222 \nHanako | 333-3333-3333 \nHanako | 444-4444-4444 \n \nという感じのViewを作りたいです。 \nどのようなSQL文を書けばいいでしょうか。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-25T05:52:02.187",
"favorite_count": 0,
"id": "86569",
"last_activity_date": "2022-03-01T05:52:12.973",
"last_edit_date": "2022-02-25T09:48:47.980",
"last_editor_user_id": "18637",
"owner_user_id": "18637",
"post_type": "question",
"score": 1,
"tags": [
"sql"
],
"title": "SQLで複数列のデータを一つにまとめるViewを作りたい",
"view_count": 3704
} | [
{
"body": "Name, TEL1 と Name, TEL2 と Name, TEL3 との select 文をそれぞれ \nunion all して、 Name で order by すればいいのではなkでしょうか。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-25T07:20:14.547",
"id": "86570",
"last_activity_date": "2022-02-25T07:20:14.547",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "43029",
"parent_id": "86569",
"post_type": "answer",
"score": 1
},
{
"body": "既に正攻法で解決済みですが、別解としてOracle 11g R1以降ならば`Unpivot`構文で横行を縦列に変換できます。 \n参考資料: [Oracle 11g\nR1新機能のPivotとUnPivot](https://codezine.jp/article/detail/4985?p=4)\n\n```\n\n select NAME, TEL\n from TEST\n unpivot include nulls (TEL for COL_NAME IN (TEL1, TEL2, TEL3))\n \n```\n\nPostgreSQLなど`cross join`できる環境であれば交差結合で結合できます。 \n下記の`cross join unnest`と`cross join lateral`は同一の結果になります。 \n参考資料: [SQL で縦横変換まとめ(pivot と\nunpivot)](https://qiita.com/k24d/items/79bc4828c918dfeeac34)、[MySQL - How to\nunpivot columns to rows?](https://stackoverflow.com/a/64404865)\n\n```\n\n SELECT A.NAME,\n X.TEL\n FROM MY_ADDRS A\n cross join unnest (\n array[TEL1, TEL2, TEL3]\n ) as X(TEL)\n /*\n cross join lateral (\n select TEL1\n union all select TEL2\n union all select TEL3\n ) as X(TEL)\n */\n \n```\n\nなお、SQL Serverにも`Unpivot`構文が用意されていますが、`include nulls`に該当するオプションが見つかりませんでした。 \n代用として`cross apply`構文が利用できるようです。 \n参考資料: [Include NULL values in\nunpivot](https://stackoverflow.com/q/42642951)、[How to unpivot columns using\nCROSS APPLY in SQL Server 2012](https://stackoverflow.com/a/48654400)",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T05:52:12.973",
"id": "86630",
"last_activity_date": "2022-03-01T05:52:12.973",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9820",
"parent_id": "86569",
"post_type": "answer",
"score": 0
}
] | 86569 | 86570 | 86570 |
{
"accepted_answer_id": "86580",
"answer_count": 2,
"body": "以下のような感じでプロパティ名にワイルドカードをつけて型付けをする方法はあるのでしょうか。\n\n※以下のコードはエラーがでます\n\n```\n\n type Image = {\n url*: string;\n [key: string]: string;\n }\n \n const images: Image[] = [{\n url123: [\"path/to/a\", \"path/to/b\"], // 裏表のある画像へのパスになっている\n ...\n }, {\n url456: [\"path/to/a\", \"path/to/b\"],\n ...\n }, {\n url789: [\"path/to/a\", \"path/to/b\"],\n ...\n }]\n \n```\n\n## 追記 この質問をした経緯\n\n業務上で既存のjsファイルをtsに移行する作業を行っています。\n\nあるコード内で取得しに行っている、あるAPIが\n\n```\n\n // 実際のコードから質問用に改変しているので不備があるかもしれません\n // url + id\n [{\n url123: [\"path/to/a\", \"path/to/b\"], // 裏表のある画像へのパスになっています\n ...\n }, {\n url456: [\"path/to/a\", \"path/to/b\"],\n ...\n }, {\n url789: [\"path/to/a\", \"path/to/b\"],\n ...\n }]\n \n```\n\nのようなオブジェクトの配列を返しています。\n\nこの配列に対して\n\n```\n\n const images: Image[] = fetchImages();\n images[0][`url${id}`][0] .......\n \n```\n\nのような感じで、 `images[0][`url${id}`][0]`\nの部分のようにプロパティの中の要素に対してインデックスでアクセスしている箇所がありそこで、`型 '0' の式を使用して型 'Image'\nにインデックスを付けることはできないため、要素は暗黙的に 'any' 型になります。プロパティ '0' は型 'Image'\nに存在しません。ts(7053)`というtsエラーが出ました。 \nそのため、imagesオブジェクトをインデックスシグネチャのみで型付けすると出来なかったために上記のような質問をさせていただきました。",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-25T09:48:01.730",
"favorite_count": 0,
"id": "86572",
"last_activity_date": "2022-02-26T13:48:27.630",
"last_edit_date": "2022-02-26T13:48:27.630",
"last_editor_user_id": "50855",
"owner_user_id": "50855",
"post_type": "question",
"score": 2,
"tags": [
"typescript"
],
"title": "オブジェクトの型付けの際にプロパティ名にワイルドカードのようなものを使用できるか",
"view_count": 561
} | [
{
"body": "```\n\n type Image = {\n [key: `url${number}`]: string[];\n // ...\n };};\n \n```\n\nでどうでしょうか。 \n(参考: [Template Literal\nTypes](https://www.typescriptlang.org/docs/handbook/2/template-literal-\ntypes.html))\n\n```\n\n type Image = {\n [key: `url${number}`]: string[];\n hoge1: string;\n hoge2: string;\n // ...\n };\n \n const images: Image[] = [\n {\n url123: [\"path/to/a\", \"path/to/b\"], // 裏表のある画像へのパスになっています\n hoge1: \"hoge1\",\n hoge2: \"hoge2\",\n // ...\n },\n {\n url456: [\"path/to/a\", \"path/to/b\"],\n hoge1: \"hoge1\",\n hoge2: \"hoge2\",\n // ...\n },\n {\n url789: [\"path/to/a\", \"path/to/b\"],\n hoge1: \"hoge1\",\n hoge2: \"hoge2\",\n // ...\n },\n ];\n \n const id = 123;\n console.log(images[0][`url${id}`][0]); // \"path/to/a\"\n \n```\n\n([Playground](https://www.typescriptlang.org/play?#code/C4TwDgpgBAkgtgQwObQLxQN4CgpQNoDWEIAXFAAYCuATgDYAkGAdpXAEYTUC+5AumQGdg1AJZMkeXgG4cUABYB7FAEZBwsUhm5FKAExrR4rVAD0JqADorWLjKwBjBUyFQRiFALLxkESVHR4sti4uDS0yroAzGR4AERgCMByJsAKJgixADRQ8YnJqSZssbzZZlCA8xGAFhGAdgyAQgyA0QyA3K6A8wqAHgzVgIsMgJ0MgNYMgFYMgMYMgGYMgCIMgH4MgJoMstpKEKo5OnNZ0-Kz+gtryyGm5lYWslyZQSthACwArABsMblJKWkZ2bf5aUUlK4vzsZ9bIYvr302R22ZT2B2BmBOdAA7AAOACcNwSdwKjxyyJehWKEJmKjIgJUv1xEAB-\nyJO0s1lwhyw0iwDicLhEABN-\nFAIpEZI5nApaBALLQlAAKNw+AR4AAMvDwVDojBZPGlUoAlFIKc97ulYlggA))",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T00:57:14.080",
"id": "86577",
"last_activity_date": "2022-02-26T00:57:14.080",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2808",
"parent_id": "86572",
"post_type": "answer",
"score": 2
},
{
"body": "私の知る限り、TypeScript 4.5 までで、今回の問題に簡潔に対処できる方法はありません。可能なのであれば API\nが返すレスポンスのスキーマを変更する方が利便性はあるでしょう。その上で、部分的に解決できる方法を考えました。\n\n## コード量が少なく、おおよそ賄える方法\n\n[Template Literal\nTypes](https://www.typescriptlang.org/docs/handbook/2/template-literal-\ntypes.html) を用いると、今回の用法をおおよそ賄えます。Template Literal Types とは String Literal\nTypes において更にテンプレート文字列のような記法を用いることができるという機能です。\n\n具体的には、以下のように書けます。\n\n```\n\n type ImageURLKey = `url${number}`;\n \n type Image = {\n [key: ImageURLKey]: string[];\n }\n \n const data: Image[] = [\n {\n url123: [\"path/to/a\", \"path/to/b\"],\n },\n {\n url456: [\"path/to/a\", \"path/to/b\"],\n },\n {\n url789: [\"path/to/a\", \"path/to/b\"],\n },\n ];\n \n```\n\nここにデータとして `{ piyo123: [] }` などを足すと型検査が通らないことが確認できます。\n\nただし、この書き方には欠点があります。Template Literal Types の `${number}` は JavaScript が\n`number` としてパースできる文字列を大体通してしまいます。このため `url1e2` や `url0x1`、`url 123`\nなども型検査に通ってしまいます。特に、`url-123` が型検査を通ってしまうので、うっかり kebab-case\nだと勘違いしてしまっても気付けません。このことを許容できるのであれば、分かりやすい型の付け方と思います。\n\nTypeScript 側でも正整数のみを受け付ける型というのが検討はされているようなので、そこに貢献していくというのも手です。\n\n参考:\n\n * <https://github.com/microsoft/TypeScript/issues/46109>\n * <https://github.com/microsoft/TypeScript/issues/46674>\n * <https://stackoverflow.com/q/66294091/5989200>\n\n## 真面目に「数字の列」の型を作る方法\n\n上記の方法は、JavaScript の `number` を使っているために欠点が生まれるのでした。それでは `number`\nを作るのではなくて、単に「数字が並んでいる文字列」という型を作って解決できないでしょうか。\n\nもし ID の上限値が決まっているのであれば、Template Literal Types を使うことで以下のように書けます。\n\n```\n\n type NonZeroDigitString = `${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`;\n type DigitString = '0' | NonZeroDigitString;\n type MaybeDigitString = DigitString | '';\n type ImageIDLessThanThousand = '0' | `${NonZeroDigitString}${MaybeDigitString}${MaybeDigitString}`\n \n type Image = Partial<Record<`url${ImageIDLessThanThousand}`, string[]>>\n \n```\n\nただし ID がとても大きくなる場合には型の情報も大きくなってしまいますし、あまりオススメはできません。\n\n## なんとか上限を突破する\n\n上限を設定しない型も、[Recursive Conditional\nTypes](https://www.typescriptlang.org/docs/handbook/release-\nnotes/typescript-4-1.html#recursive-conditional-types)\nを使うと実装できる……はずです。具体的には以下のような型を考えました。\n\n```\n\n type NonZeroDigitString = `${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9}`;\n type DigitString = '0' | NonZeroDigitString;\n type ImageID<T extends string, V = T> = T extends DigitString ? V :\n T extends `${DigitString}${infer R}` ? ImageID<R, V> : never;\n type ImageURLKey<T extends string, V = T> = T extends `url${infer R}` ? ImageID<R, V> : never;\n type Image<T extends string> = Record<ImageURLKey<T>, string[]>\n \n```\n\nただしこの型は、計算に時間がかかるのか、手元で試すと時々期待通りに動いてくれないので、あんまり使いものにはならなさそうでした(おそらく……)。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T02:52:38.563",
"id": "86580",
"last_activity_date": "2022-02-26T02:52:38.563",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "86572",
"post_type": "answer",
"score": 2
}
] | 86572 | 86580 | 86577 |
{
"accepted_answer_id": "86589",
"answer_count": 2,
"body": "以下のような、マルチインデックスなデータフレーム(価格データ)と、 \n期間が含まれるデータフレーム(対象期間データ)から作成したスライスを利用して、 \n対象の期間の行を抽出したいです。 \nループを利用すれば何とか出来たのですが、 \n(パフォーマンス向上のために、)ループやapplyなしで、 \n記述することはできますでしょうか?\n\n```\n\n import io\n import pandas as pd\n \n text_price = '''\n area,date,price\n 東京,2022-02-01,100\n 東京,2022-02-03,200\n 東京,2022-02-05,300\n 埼玉,2022-02-11,400\n 埼玉,2022-02-13,500\n 埼玉,2022-02-15,600\n '''\n df_price = pd.read_csv(io.StringIO(text_price), index_col=['area', 'date'])\n df_price = df_price.sort_index()\n print('- 価格データ(入力)')\n display(df_price)\n \n text_history = '''\n area,start_date,end_date\n 東京,2022-02-02,2022-02-04\n 埼玉,2022-02-12,2022-02-16\n 沖縄,2022-02-01,2022-02-20\n '''\n df_history = pd.read_csv(io.StringIO(text_history))\n print('- 対象期間データ(入力)')\n display(df_history)\n \n print('- 期待する結果(出力)')\n list_out = []\n for row in df_history.itertuples():\n if row.area in df_price.index.get_level_values(0):\n series = df_price.loc[([row.area], slice(row.start_date, row.end_date)), :]\n list_out.append(series)\n \n df_out = pd.concat(list_out, axis='index')\n display(df_out)\n \n```\n\n[](https://i.stack.imgur.com/93VDd.png)",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-25T15:40:05.443",
"favorite_count": 0,
"id": "86575",
"last_activity_date": "2022-02-28T05:45:11.387",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "35267",
"post_type": "question",
"score": 1,
"tags": [
"python",
"pandas"
],
"title": "マルチインデックスなデータフレームから、ループなしで、行を抽出する方法",
"view_count": 157
} | [
{
"body": "> ループやapplyなしで、記述することはできますでしょうか?\n\n`df_history`\nにおいて、期間(`start_date`〜`end_date`)に重なりが無いのであれば可能です。ですが、今回のデータでは重複があるので、以下の方法では\n`apply` を使うしかありません。\n\n```\n\n # 日時を datetime として読み込む\n df_price = pd.read_csv(io.StringIO(text_price), index_col=['area', 'date'], parse_dates=['date'])\n df_history = pd.read_csv(io.StringIO(text_history), parse_dates=['start_date', 'end_date'])\n \n # IntervalIndex を作成\n idx = pd.IntervalIndex.from_arrays(df_history['start_date'], df_history['end_date'], closed='both')\n new_idx = pd.date_range(df_history['start_date'].min(), df_history['end_date'].max(), freq='D')\n \n # 期間の重複がある場合、reindex() で duplicate label エラーが発生する\n #idx = df_history.set_axis(idx).reindex(new_idx).dropna().index\n idx = df_history.set_axis(idx).groupby('area').apply(lambda x: x.reindex(new_idx)).dropna().index\n \n # Indexing\n result = df_price[df_price.index.isin(idx)].sort_index(level='date')\n print(result)\n \n #\n price\n area date \n 東京 2022-02-03 200\n 埼玉 2022-02-13 500\n 2022-02-15 600\n \n```\n\n##### 別解\n\nkirara0048 さんの回答を参考にしました。\n\n```\n\n result = (\n df_price.join(df_history.set_index('area'))\n .query('start_date <= date <= end_date')\n .sort_index(level='date')[['price']])\n \n print(result)\n \n #\n price\n area date \n 東京 2022-02-03 200\n 埼玉 2022-02-13 500\n 2022-02-15 600\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T13:46:08.150",
"id": "86589",
"last_activity_date": "2022-02-28T05:45:11.387",
"last_edit_date": "2022-02-28T05:45:11.387",
"last_editor_user_id": "47127",
"owner_user_id": "47127",
"parent_id": "86575",
"post_type": "answer",
"score": 0
},
{
"body": "以下でどうでしょうか。 \n単純にマージして、日付の比較を行っています。\n\n```\n\n df_price = pd.read_csv(io.StringIO(text_price), index_col=[\"area\", \"date\"], parse_dates=[\"date\"])\n df_history = pd.read_csv(io.StringIO(text_history), parse_dates=[\"start_date\", \"end_date\"])\n \n tmp_df = df_price.reset_index().merge(df_history, on=\"area\")\n out = df_price.loc[((tmp_df[\"start_date\"] <= tmp_df[\"date\"])\n & (tmp_df[\"date\"] < tmp_df[\"end_date\"])).tolist()]\n print(out)\n # price\n # area date \n # 東京 2022-02-03 200\n # 埼玉 2022-02-13 500\n # 2022-02-15 600\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T04:38:06.727",
"id": "86609",
"last_activity_date": "2022-02-28T04:38:06.727",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "37167",
"parent_id": "86575",
"post_type": "answer",
"score": 1
}
] | 86575 | 86589 | 86609 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "CentOS7でTCP Wrapperを使用し、hosts.allowに以下のような記述をしてドメイン名を限定したssh接続を許可していました。\n\n```\n\n sshd: .dion.ne.jp\n \n```\n\nAlmaLinux8を使うことになったのですが、同様に設定するための方法を調べたのですがわかりませんでした。IPアドレスが決まる場合はfirewall-\ncmdの--add-rich-ruleで設定出来ることは把握しているのですが・・・。\n\nどなたか識者の方、ご教示ください。よろしくお願いします。\n\n**追記**\n\npamを使えば良いことがわかりましたが、IPアドレスでの指定では動作してくれますが、ドメイン名を指定しても動いてくれません。 \naccess.confに以下のように記述しましたが接続できませんでした。\n\n```\n\n + : testuser : .vmobile.jp\n \n```\n\nドメイン名で指定するためには何か設定が必要でしょうか。",
"comment_count": 7,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-25T23:55:11.067",
"favorite_count": 0,
"id": "86576",
"last_activity_date": "2022-02-26T04:21:19.677",
"last_edit_date": "2022-02-26T04:21:19.677",
"last_editor_user_id": "3060",
"owner_user_id": "41925",
"post_type": "question",
"score": 0,
"tags": [
"linux"
],
"title": "AlmaLinux8でドメイン名を指定してssh接続を許可するには",
"view_count": 338
} | [
{
"body": "PAM でもできると思いますが、sshd 側で `AllowUsers` で制限する方法もあります。\n\n```\n\n (/etc/ssh/sshd_config)\n UseDNS yes\n AllowUsers testuser@*.vmobile.jp\n \n```\n\nただし、以下の条件があります。なりすましを防ぐためと思われます。\n\n**「接続元IPアドレスの逆引きで得られた FQDN (HOST.vmobile.jp) を正引きした結果(IPアドレス)」=「接続元IPアドレス」**",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T02:54:46.553",
"id": "86581",
"last_activity_date": "2022-02-26T02:54:46.553",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4603",
"parent_id": "86576",
"post_type": "answer",
"score": 0
}
] | 86576 | null | 86581 |
{
"accepted_answer_id": "86621",
"answer_count": 2,
"body": "## やりたいこと\n\nローカル環境で閲覧している状態を公開環境でも適用できるようにしたい。\n\n## 問題点\n\nローカル環境では期待通り正常に閲覧できています。 \nが、静的サイトジェネレータ(プラグイン)でビルドしたファイルを公開環境に格納してみると、各所にリンク切れやレイアウト崩れが発生しています。\n\n* * *\n\n## 現状\n\n### 設定情報\n\nwordpressの設定にある「WordPress アドレス (URL)」と「サイトアドレス (URL)」が異なる環境で運用しています。 \n前者はローカルで作業し、後者はビルドした静的ファイルを格納し、公開するURLです。 \nこれにより、内部リンクは問題なく運用できています。\n\n### 再現手順\n\n私の環境の話なのでお見せするのが難しいのですが、イメージをより具体的にしていただきやすいよう、再現手順を残します。\n\n 1. ローカル環境でサイトトップを開く: CSSやJSが読み込まれ実行される\n 2. ビルドする(WP2HTMLを使用): ※この時点でリンクがローカル環境になっている※\n 3. ビルドしたファイルを公開サーバーに格納: リンク切れ\n\n* * *\n\n## 解決アプローチを検討\n\n### テーマファイルを編集する\n\nCSSやJSの読み込みについては、それぞれのテーマに依存して?おり、各所で「サイトアドレス(公開先URL)」ではなく「WordPressアドレス(ローカル)」を適用しているようです。 \nローカルで編集する際には必要なので、これは妥当だと思います。\n\nが、ビルド時にもローカルアドレスになってしまっているため、これが原因で公開時にレイアウト崩れを起こしてしまっています。\n\nテーマファイルを書き換えて編集する方法が一番簡単な気がしていますが、テーマを変えるたびにファイルを書き換える必要がありそうなので、これは避けたいです。\n\n### サイトジェネレータを編集する\n\n本来であれば静的サイトジェネレータ側を編集するのが一番だと思いますが、どこをどういじれば良いか分かりません…。\n\n### 運用対処\n\n静的サイトジェネレータをいじらなくても、生成した後のすべてのファイルのローカル環境のパスを公開環境のパスに書き換えれば良いので、wordpressではなくshellなりで`find\n| xargs sedなりawkなり`すればよさそうです。 \nが、今回は一度設定すればwordpressで完結できる環境を作れることをゴールにしたいです。\n\n* * *\n\n## 所感\n\n検討には今、思いつく限りを書いていますが、実はwordpressの機能でもっと便利なものがあって、そちらを使えば全部解決とまで言わなくてもある程度作業はしやすくなるんじゃないかと考えています。 \nあるいは、運用対処している内容をプラグイン化できればwordpress上で完結することもできそうな気がしていますが、現実として可能かどうかが分かっていません…。\n\n### 参考情報\n\nshifterなどの便利なサービスを使えば解決できると思います。\n\n* * *\n\n## 期待する回答\n\n検討の方法はあくまで、私が今考えている方法に過ぎません。もっと良い方法があると思っています。 \nやりたいことは「ローカル環境で閲覧している状態を公開環境でも適用できるようにする」ことなので、まずはこれをゴールにして、\n**どのような解決アプローチが考えられるか** お力をお借りしたいです。\n\n### 要望\n\n * (※必須)公開環境は静的サイトジェネレータ(方法は不問)でビルドしたファイルを使いたいです。 \n * セキュリティ面を考えると、WP RESTAPIやWP-adminを外部公開した状態で使えません。\n * 開発環境は外からつなげられない場所に置きたいです。\n * (※必須)開発環境のGUIで編集したいので、開発環境でGUIが使えなくなるような改修はできません。 \n * 思い当たるのが設定画面の「WordPressアドレス」を公開先URLに変更する方法です。この場合、開発環境の管理画面にアクセスできなくなります。\n * 一度設定する場合にコアファイルを操作したりする事は許容できますが、基本的にはwordpressで完結したいです。 \n * テーマを変更した際に影響がないようにしたいです。\n\n(他、気付いた点があれば追記していきます)",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T01:37:39.730",
"favorite_count": 0,
"id": "86578",
"last_activity_date": "2022-02-28T17:20:32.220",
"last_edit_date": "2022-02-26T04:26:56.477",
"last_editor_user_id": "3060",
"owner_user_id": "27817",
"post_type": "question",
"score": 0,
"tags": [
"wordpress"
],
"title": "HTMLファイルのビルド時にJSやCSSの参照先がローカル環境のままになってしまっているので、公開環境に変更したい",
"view_count": 180
} | [
{
"body": "ローカルの開発環境がどのような形になっているのかわかりませんが、 \n/etc/hosts を書き換えてみてはいかがでしょうか?\n\n例えば \nhonban.com 127.0.0.1 \nとしてしまって、開発の時もサイトアドレスを利用してしまうのです。\n\n逆に言うとその開発環境で本番が参照できないですが、そんな時はコメントアウトしてしまえばいいと思います。\n\nローカルの環境が仮想のDockerやVBなどを利用している場合は仮想環境の/etc/hostsも書き換える必要があるかもしれません。\n\n/etc/hosts ファイルについては各OSに用意されていますのでご利用になられているOSに合わせて調べて書き換えてみてください。\n\nちなみに \nWPはCMS管理のプロダクトでHTMLを作る製品ではないです。 \nなので実際やろうとしていることはなかなか無理筋のような気もします。\n\nセキュリティ的にWPの管理画面を置けないとありますが、IP制限やVPNによるローカルエリアネットワーク制約や2段階認証など必要な対策を実施していれば十分セキュリティ担保になることもあります。 \nまたWPやその周りのプラグインは毎年脆弱性が報告されています。管理画面を閉じていればOKというものでもなく、WPそのものにたいする攻撃もこれまでいくつも見受けられました。管理画面すらおけないほどのセキュリティポリシーが厳しいものだとそもそもWP自体NGということもあり得ると思います。 \nセキュリティポリシーを見直して、WPをうまく使っていくか \nもしくは従来のポリシー通りにWP代替の製品を探したほうがいいと思います。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T07:06:45.377",
"id": "86611",
"last_activity_date": "2022-02-28T07:06:45.377",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "22665",
"parent_id": "86578",
"post_type": "answer",
"score": 1
},
{
"body": "自己解決しました。 \n他にも静的サイト化してくれるプラグインがあり、いくつか試したところ本件を解決できるプラグインもありました。 \n今回は単純にWP2HTMLだけでは対応できなかったようです。 \nハマったポイントとしては「WP2HTMLまたは他のプラグインで生成したディレクトリは都度削除する」という運用が必要なので、デバッグ時には要注意です。 \n(静的サイト化のプラグインをいくつか試したところ、うまく動いたり動かなかったりするプラグインがあるので過信は禁物のようです)\n\nまた、ご回答にもいただいている`/etc/hosts`を書き換える案も有用だと思います。 \n今後WordPressに限らず同様の問題があった時に意識しようと思いました。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T17:20:32.220",
"id": "86621",
"last_activity_date": "2022-02-28T17:20:32.220",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "27817",
"parent_id": "86578",
"post_type": "answer",
"score": 0
}
] | 86578 | 86621 | 86611 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "表題の通り、[Vue.js + Nuxt.js +\nTypeScript]でWEBアプリケーションを作成しているのですが、Layoutsから呼び出しているComponentに対し、Layoutsを適用しているPagesからComponentの変数に対して操作を行たのですが、完全に詰まってしまったため質問させてください。\n\nやりたいことの要点としては、 \n・`HogeMenu`にあるリストのclassをpagesから操作したい。 \n・`HogeMenu`は`HogeLayout`の中で読んでいる \n・実際に値を操作するのは`HogePage` \nといった感じです。\n\nMixinを使用してみましたがうまく動作しないため、どなたかご教授いただけないでしょうか。。。\n\nVueについては初学者のためツッコミどころ満載かと思いますが、暖かい目で見えていただけると幸いです。\n\n/layouts/HogeLayout.vue\n\n```\n\n <template>\n <HogeMenu />\n <main>\n <nuxt />\n </main>\n </template>\n \n <script lang=\"ts\">\n import { Vue, Component } from \"vue-property-decorator\";\n import HogeMenu from \"@/components/HogeMenu.vue\";\n @Component({\n components: {\n HogeMenu,\n },\n })\n export default class HogeLayout extends Vue {}\n </script>\n \n```\n\n/component/HogeMenu.vue\n\n```\n\n <template>\n <ul>\n <li v-bind:class=\"[isHoge1 ? 'active' : '']\">hoge1</li>\n <li v-bind:class=\"[isHoge2 ? 'active' : '']\">hoge2</li>\n <li v-bind:class=\"[isHoge3 ? 'active' : '']\">hoge3</li>\n </ul>\n </template>\n \n <script lang=\"ts\">\n import { Vue, Component } from \"vue-property-decorator\";\n import MenuMixin from \"@/assets/ts/MenuMixin\";\n @Component\n export default class HogeMenu extends Mixins(MenuMixin) {}\n </script>\n \n```\n\n/pages/index.vue\n\n```\n\n <template>\n <div>\n .....\n </div>\n </template>\n \n <script lang=\"ts\">\n import { Component, Mixins } from 'vue-property-decorator'\n import MenuMixin from \"@/assets/ts/MenuMixin\";\n import HogeLayout from '@/layouts/HogeLayout.vue';\n \n @Component({\n layout: \"HogeLayout\",\n components: {\n HogeLayout\n },\n })\n export default class HogePage extends Mixins(MenuMixin) {\n beforeMount() {\n this.activeHoge1();\n }\n }\n </script>\n \n```\n\nMenuMixin.ts\n\n```\n\n import Vue from 'vue';\n import { Component, Emit } from 'vue-property-decorator';\n \n @Component\n export class MenuMixin extends Vue {\n \n isHoge1 = false;\n isHoge2 = false;\n isHoge3 = false;\n \n @Emit()\n activeHoge1() {\n this.isHoge1 = true;\n this.isHoge2 = false;\n this.isHoge3 = false;\n }\n \n @Emit()\n activeHoge2() {\n this.isHoge1 = false;\n this.isHoge2 = true;\n this.isHoge3 = false;\n }\n \n @Emit()\n activeHoge3() {\n this.isHoge1 = false;\n this.isHoge2 = false;\n this.isHoge3 = true;\n }\n }\n \n```\n\nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T02:09:27.523",
"favorite_count": 0,
"id": "86579",
"last_activity_date": "2022-03-10T06:37:08.530",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "47269",
"post_type": "question",
"score": 0,
"tags": [
"vue.js",
"typescript",
"nuxt.js"
],
"title": "Vue.js + Nuxt.js + TypeScript アプリケーションでlayoutで呼び出しているコンポーネントの変数をpagesから操作したい",
"view_count": 313
} | [
{
"body": "直接の操作をするのは、おそらくちょっと辛いです。\n\nlayout の中の component は、 vuex を参照するようにして、 pages 側で asyncData などにて vuex の store\nを操作して、それによって表示が変わるようにするのが良いと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T06:37:08.530",
"id": "86780",
"last_activity_date": "2022-03-10T06:37:08.530",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"parent_id": "86579",
"post_type": "answer",
"score": 0
}
] | 86579 | null | 86780 |
{
"accepted_answer_id": "86587",
"answer_count": 2,
"body": "Pythonのsubprocessライブラリを使ってファイルをパスワード付きで圧縮したいです。\n\nコマンドでは問題なく実行できますが、subprocessを利用すると下記のエラーが表示されます。\n\nコマンドで実行した場合:\n\n```\n\n \"C:\\Program Files\\7-Zip\\7z.exe\" -pPassword data.zip \"C:\\Users\\user1\\testfolder\"\n \n```\n\n**Python プログラムを実行した場合のエラーメッセージ:**\n\n```\n\n 'C:\\Program' は、内部コマンドまたは外部コマンド、\n 操作可能なプログラムまたはバッチ ファイルとして認識されていません。\n \n```\n\nPythonのプログラム\n\n```\n\n from distutils import command\n import subprocess\n \n #ZIPファイルプログラム\n fileprogram=r\"C:\\Program Files\\7-Zip\\7z.exe\" \n \n #ZIPファイル保存先\n file=r\"C:\\Users\\user1\\testfolder\"\n \n #全体のコマンド\n allcommand=fileprogram+'a -pPassword data.zip'+file\n #print(exp_message)\n \n #コマンド実行\n result = subprocess.run(allcommand,encoding='shift jis',shell=True,stdout=subprocess.PIPE)\n \n #コマンド実行結果\n command_output = result.stdout\n print(command_output)\n \n```\n\n代わりにsubprocess.runから下記のように変更しましたが、 \n同じエラー内容が表示されます。\n\n```\n\n subprocess.call(allcommand,encoding='shift jis',shell=True,stdout=subprocess.PIPE)\n \n```\n\nもし分かる方がいましたら、教えていただけると幸いです。\n\nお手数ですが、よろしくお願い致します。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T03:25:24.967",
"favorite_count": 0,
"id": "86582",
"last_activity_date": "2022-02-27T08:00:32.477",
"last_edit_date": "2022-02-27T08:00:32.477",
"last_editor_user_id": "3060",
"owner_user_id": "18859",
"post_type": "question",
"score": 0,
"tags": [
"python",
"subprocess"
],
"title": "Python から外部コマンドを呼び出した際に認識されない",
"view_count": 2210
} | [
{
"body": "コマンドや引数の区切り文字は空白です。 \nコマンドや引数に空白が含まれている場合は区切り文字と解釈されないように、二重引用符で囲む必要があります。 \nPythonは引用符として`'`も使えます。 \n以下のようにすればエラーは解消すると思います。\n\n```\n\n # ZIPファイルプログラム\n fileprogram = r'\"C:\\Program Files\\7-Zip\\7z.exe\"'\n \n```\n\n* * *\n\n質問の「Pythonのプログラム」には他にも問題があります。 \n7zipのスイッチ`a`の前に空白が必要です。 \n`data.zip`の後にも空白が必要です。\n\n```\n\n #全体のコマンド\n allcommand = fileprogram + ' a -pPassword data.zip ' + file\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T07:09:30.033",
"id": "86587",
"last_activity_date": "2022-02-26T07:09:30.033",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "35558",
"parent_id": "86582",
"post_type": "answer",
"score": 1
},
{
"body": "`subprocess.run`に`shell=True`を指定して文字列形式でコマンドを与えるのは避けましょう。\n\n[リファレンス](https://docs.python.org/ja/3/library/subprocess.html#security-\nconsiderations)にも以下のように記載されています。\n\n> args\n> はすべての呼び出しに必要で、文字列あるいはプログラム引数のシーケンスでなければなりません。一般に、引数のシーケンスを渡す方が望ましいです。なぜなら、モジュールが必要な引数のエスケープやクオート\n> (例えばファイル名中のスペースを許すこと) の面倒を見ることができるためです。単一の文字列を渡す場合、shell は True でなければなりません\n> (以下を参照)。\n\n文字列形式でやると、質問のようにスペースにまつわる問題が起きます。さらに、文字列形式でコマンドを渡すには`shell=True`を指定する必要がありますが、これもワイルドカードなどにまつわる問題やセキュリティホールにつながります。そもそも、文字列組み立てはミスをしやすいという一般的な問題もあります。\n\nなので、「subprocess.runに文字列でコマンドを渡さない」というのは基本中の基本として覚えておいてください。外部プログラムを呼び出すモジュールには大抵同じ問題を引き起こす使い方があるので、subprocess.run(やpython)以外を使うときにも気をつけてください。\n\nリファレンスに記載の通り`subprocess.run`はシーケンスを受け取ることができます。\n\n```\n\n allcommand=[fileprogram, 'a', '-pPassword', 'data.zip', file]\n result = subprocess.run(allcommand,encoding='shiftjis',stdout=subprocess.PIPE)\n \n```\n\nコマンドやオプションにスペースが含まれていても意識する必要はありません。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T07:40:32.383",
"id": "86597",
"last_activity_date": "2022-02-27T07:40:32.383",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5793",
"parent_id": "86582",
"post_type": "answer",
"score": 6
}
] | 86582 | 86587 | 86597 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "こちらのコード(<https://github.com/MoonInTheRiver/DiffSinger>)をgit cloneしてGoogle\nColabで作ったノートブックで環境構築を行い、run.pyを実行したところ2行目の「import utils.hparams」で\n\n```\n\n File \"/content/DiffSinger/tasks/run.py\", line 2, in <module>\n from utils.hparams import set_hparams, hparams ModuleNotFoundError: No module named 'utils.hparams'\n \n```\n\nとエラーが出ました。 \n色々と調べてカレントディレクトリ関連のエラーかと思い%cdでディレクトリ移動などしてみましたが変わりませんでした。utils.hparamsというのが何のモジュールなのか分かっていないのですが、importする方法をお教えいただけませんか?",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-26T07:27:22.623",
"favorite_count": 0,
"id": "86588",
"last_activity_date": "2022-02-26T09:22:25.933",
"last_edit_date": "2022-02-26T09:22:25.933",
"last_editor_user_id": "3060",
"owner_user_id": "51592",
"post_type": "question",
"score": 0,
"tags": [
"python",
"google-colaboratory"
],
"title": "utils.hparamsをimportできない",
"view_count": 364
} | [] | 86588 | null | null |
{
"accepted_answer_id": "86594",
"answer_count": 1,
"body": "エクセル(Windows11)で株価情報の管理をしています。各シートが各企業の情報を持つようにしています。それらのシートをまとめるためにIndexシートを作成しブックの一枚目においています。Indexシートでは縦軸に企業名が各企業のシートタブから入力されその企業名から企業コード、決算月等の情報を同じく参照し反映させています。さらにKabutan、四季報そしてTradingview等のWeb情報サービスのその企業のページを別途開くようにハイパーリンクを入力しました。ハイパーリンクはうまく機能していますが、Web情報サービスは各企業ごとに企業コードを変えて入力しなければならないため一企業ごとに手作業となってしいます。そこのところを自動化できないかという相談です。\n\n例えば四季報のページへのリンクはこのようになるのですが、`=HYPERLINK(\"https://shikiho.jp/stocks/7373/\",\"四季報\")`\nこの中の7373の部分が企業コードとなっていてそこを変えることで他の企業のページへ変わります。Indexには50から100社がリストアップされていますので手作業となるとすべてのリンクを変更するわけですが、既に同じシートに企業コードのリストがあるのでそれを参照してリンクの中の企業コードの部分だけを変更する関数の使い方がありましたらご教授ください。\n\n[](https://i.stack.imgur.com/mFK1A.png)",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T00:18:31.243",
"favorite_count": 0,
"id": "86591",
"last_activity_date": "2022-02-27T06:09:01.450",
"last_edit_date": "2022-02-27T06:09:01.450",
"last_editor_user_id": "3060",
"owner_user_id": "51310",
"post_type": "question",
"score": -1,
"tags": [
"excel"
],
"title": "エクセルに張った株探と四季報へのリンクを企業コードごとに更新したい",
"view_count": 439
} | [
{
"body": "LibreOffice Calc で動作確認を行いました。\n\n一度にまとめるような記述はうまくいかなかったので少し冗長ですが、以下の手順で実現可能かと思います。\n\n証券コードが `A1` に入力されているとして、参照と文字列の結合を組み合わせて以下のように URL を生成できます。\n\nA1 | A2 (式) | A2 (結果) \n---|---|--- \n7373 | `=\"https://shikiho.jp/stocks/\" & A1` | <https://shikiho.jp/stocks/7373> \n \n次に、A2 の結果の URL を利用して `HYPERLINK` を設定します。\n\nA1 | A3 (式) | A3 (結果) \n---|---|--- \n7373 | `=HYPERLINK(A2, \"四季報\")` | 四季報",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T04:36:20.150",
"id": "86594",
"last_activity_date": "2022-02-27T04:36:20.150",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3060",
"parent_id": "86591",
"post_type": "answer",
"score": 0
}
] | 86591 | 86594 | 86594 |
{
"accepted_answer_id": null,
"answer_count": 3,
"body": "C言語初学者です。\n\n以下のように、`int` で変数を用意して、`double` の入力変換指定子で値を入力し、`double` の入力変換指定子で値を出力した場合、なぜ\n`0.000000` になるのか疑問に思っています。\n\n```\n\n #include <stdio.h>\n \n int main(void)\n {\n int data;\n scanf(\"%lf\", &data); // 実数入力\n printf(\"%f\\n\", data);\n return 0;\n }\n \n```\n\n上記が誤ったコード(`int` で `data` を定義しているのが悪い)であることは理解しているのですが、挙動の理解をしたいと思っています。\n\n`data` は `int` でメモリ確保されているので、そこに `double`\nで入力するとメモリが後ろにあふれてしまっているのかなと想像しているのですが、それだと `printf` の際になぜ `0.000000`\nとなるのか説明できないなと悩んでいます(それだと意味不明な数値の羅列になりそうな気がしていました)。\n\nコンパイラは `gcc (MinGW.org GCC Build-2) 9.2.0` です。 \nよろしくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T02:46:04.283",
"favorite_count": 0,
"id": "86592",
"last_activity_date": "2023-05-04T06:49:15.610",
"last_edit_date": "2023-05-04T06:24:31.277",
"last_editor_user_id": "4236",
"owner_user_id": "29953",
"post_type": "question",
"score": 4,
"tags": [
"windows",
"c",
"mingw"
],
"title": "int 型の変数に double でキーボード入力した際の挙動について",
"view_count": 380
} | [
{
"body": "キーボードの入力とかは関係なく、intの0を`%f`で指定したから`0.000000`と表示されています。 \n`printf(\"%f\\n\", 0);`と書いたのと同じです。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T04:50:55.233",
"id": "86595",
"last_activity_date": "2022-02-27T04:50:55.233",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "805",
"parent_id": "86592",
"post_type": "answer",
"score": -2
},
{
"body": "`gcc (MinGW.org GCC Build-2) 9.2.0`とのことで、32bit Windows(64bit\nWindowsだとしても32bit実行ファイルが作成・実行される)でしょうか。C言語では、データ型のサイズを具体的に定めていないため、環境によって異なります。そのため、質問のように意図的にデータ型を誤った場合、環境ごとのサイズに応じた挙動を示します。\n\nその上で、32bit Windowsにおいては想像されている通りです。意味不明な数値の羅列になり得ます。\n\n`printf()`を呼び出す際に`data`をスタックに格納します。`data`は32bit\nint型なのでスタックには32bitしか書き込まれていません。しかし呼び出された`printf()`は`%f`の指示により64bit倍精度浮動小数点数と解釈して読み取ります。このため、スタックに格納された`data`の隣32bit分を読み出そうとします。\n\n```\n\n 0 1 2 3 4 5 6\n 0123456789012345678901234567890123456789012345678901234567890123\n <-------------------- fraction --------------------><-exponent>S\n <---------- int data ----------><----------- 未初期化 ---------->\n ※ S = sign\n \n```\n\nこの図の状況で、`int\ndata`に何が格納されていようが、表示する精度を上げない限り表示には使われません。それよりも`printf`には渡していない未初期化部分が\n\n * 符号部 1ビット\n * 指数部 11ビット\n * 仮数部 上位20ビット\n\nに当たり表示内容を決定づけています。\n\n短いテストプログラムですし、スタックが汚れておらず未初期化部分が偶然`0`で埋められていたのだと思います。結果的に倍精度浮動小数点数として`0.000000`と解釈できるビット列になっただけです。\n\nちなみに、意図的に`data`の隣にも別の値を書き込むと表示が変化することを確認できるかと思います。\n\n```\n\n for (int i = 0; i < 32; i++)\n printf(\"i = %d, %f\\n\", i, data, 1 << i);\n \n```\n\nを手元のVisual C++で実行したところ、次のような出力が得られました。\n\n```\n\n i = 0, 0.000000\n i = 1, 0.000000\n i = 2, 0.000000\n i = 3, 0.000000\n i = 4, 0.000000\n i = 5, 0.000000\n i = 6, 0.000000\n i = 7, 0.000000\n i = 8, 0.000000\n i = 9, 0.000000\n i = 10, 0.000000\n i = 11, 0.000000\n i = 12, 0.000000\n i = 13, 0.000000\n i = 14, 0.000000\n i = 15, 0.000000\n i = 16, 0.000000\n i = 17, 0.000000\n i = 18, 0.000000\n i = 19, 0.000000\n i = 20, 0.000000\n i = 21, 0.000000\n i = 22, 0.000000\n i = 23, 0.000000\n i = 24, 0.000000\n i = 25, 0.000000\n i = 26, 0.000000\n i = 27, 0.000000\n i = 28, 0.000000\n i = 29, 0.000000\n i = 30, 2.000000\n i = 31, -0.000000\n \n```\n\n* * *\n\nなお、MinGW-w64など64bit Windows ~~やmetropolisさんが説明されている64bit Linux~~\nにおいてはまた異なる挙動になります。 \n64bit Windows ~~および64bit Linux~~ においては、32bit\nint型をスタックに格納する際、64bit領域を使います。この際の未使用の32bit部分はゼロクリアされます。 \n`printf()`はこの64bit領域を[倍精度浮動小数点数](https://ja.wikipedia.org/wiki/%E6%B5%AE%E5%8B%95%E5%B0%8F%E6%95%B0%E7%82%B9%E6%95%B0#IEEE%E6%96%B9%E5%BC%8F%EF%BC%88IEEE_754_%E5%BD%A2%E5%BC%8F%EF%BC%89)として読み取ろうとしますが、ゼロクリアされた未使用の32bit部分は\n\n * 符号部 1ビット = 0\n * 指数部 11ビット = 0\n * 仮数部 上位20ビット = 0\n * 仮数部 下位32ビット = dataの値\n\nに該当し、「指数部、仮数部ともに 0 のときは ±0 を表す」が適用されるため、常に`0.000000`が表示されます。\n\n前述のコードについても、64bitでは`data`の隣に`1 << i`を書き込んでいますが説明の通り参照されないため、\n\n```\n\n i = 0, 0.000000\n i = 1, 0.000000\n i = 2, 0.000000\n i = 3, 0.000000\n i = 4, 0.000000\n i = 5, 0.000000\n i = 6, 0.000000\n i = 7, 0.000000\n i = 8, 0.000000\n i = 9, 0.000000\n i = 10, 0.000000\n i = 11, 0.000000\n i = 12, 0.000000\n i = 13, 0.000000\n i = 14, 0.000000\n i = 15, 0.000000\n i = 16, 0.000000\n i = 17, 0.000000\n i = 18, 0.000000\n i = 19, 0.000000\n i = 20, 0.000000\n i = 21, 0.000000\n i = 22, 0.000000\n i = 23, 0.000000\n i = 24, 0.000000\n i = 25, 0.000000\n i = 26, 0.000000\n i = 27, 0.000000\n i = 28, 0.000000\n i = 29, 0.000000\n i = 30, 0.000000\n i = 31, 0.000000\n \n```\n\nとなります。\n\n* * *\n\nmetropolisさんが説明されている64bit Linuxの場合、`int data`が64bitになるので更に異なる挙動を示しますね。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T05:15:58.587",
"id": "86596",
"last_activity_date": "2023-05-04T06:49:15.610",
"last_edit_date": "2023-05-04T06:49:15.610",
"last_editor_user_id": "4236",
"owner_user_id": "4236",
"parent_id": "86592",
"post_type": "answer",
"score": 6
},
{
"body": "> data は int でメモリ確保されているので、そこに double で入力するとメモリが後ろにあふれてしまっているのかなと想像しているのですが、\n\nglibc scanf(3) の実装は以下の様になっています(`long double *` へ cast)。なので、その通りです。\n\n[glibc/stdio-common/vfscanf-\ninternal.c](https://code.woboq.org/userspace/glibc/stdio-common/vfscanf-\ninternal.c.html#2437)\n\n```\n\n if ((flags & LONGDBL) \\\n && __glibc_likely ((mode_flags & SCANF_LDBL_IS_DBL) == 0))\n {\n long double d = __strtold_internal\n (char_buffer_start (&charbuf), &tw, flags & GROUP);\n if (!(flags & SUPPRESS) && tw != char_buffer_start (&charbuf))\n *ARG (long double *) = d;\n }\n \n```\n\n> それだと printf の際になぜ 0.000000 となるのか説明できないなと悩んでいます\n\n`data` への pointer(`int *`型)を `long double *` に cast して dereference\nすれば入力した値(float の値)が表示されます(stack を踏み抜きますが)。\n\nではなぜ `%f` を指定すると `0.000000` が **表示される** のか、に関しては以下の warning message と\n`printf(3)` のソースコード([glibc/stdio-common/vfprintf-\ninternal.c](https://code.woboq.org/userspace/glibc/stdio-common/vfprintf-\ninternal.c.html#777))を眺めると判るかと思います。\n\n**サンプルコード**\n\n```\n\n #include <stdio.h>\n #include <limits.h>\n \n int main(void)\n {\n int data;\n scanf(\"%lf\", &data); // 実数入力\n \n printf(\"as is: %d\\n\", data);\n printf(\"as double: %f\\n\", data);\n printf(\"cast to double: %f\\n\", (double)data);\n printf(\"cast to double type pointer: %f\\n\", *(double * )&data);\n \n printf(\"woops!: %f\\n\", 0, data);\n \n return 0;\n }\n \n```\n\n**実行結果**\n\n```\n\n $ uname -isr\n Linux 5.15.0-18-generic x86_64\n $ gcc --version\n gcc (Ubuntu 11.2.0-16ubuntu1) 11.2.0\n $ /lib/x86_64-linux-gnu/libc.so.6\n GNU C Library (Ubuntu GLIBC 2.35-0ubuntu1) stable release version 2.35.\n \n $ gcc -Wall -Wextra x.c -o x\n x.c: In function ‘main’:\n x.c:7:12: warning: format ‘%lf’ expects argument of type ‘double *’, but argument 2 has type ‘int *’ [-Wformat=]\n 7 | scanf(\"%lf\", &data); // 実数入力\n | ~~^ ~~~~~\n | | |\n | | int *\n | double *\n | %d\n x.c:10:23: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=]\n 10 | printf(\"as double: %f\\n\", data);\n | ~^ ~~~~\n | | |\n | | int\n | double\n | %d\n x.c:14:20: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=]\n 14 | printf(\"woops!: %f\\n\", 0, data);\n | ~^ ~\n | | |\n | | int\n | double\n | %d\n x.c:14:10: warning: too many arguments for format [-Wformat-extra-args]\n 14 | printf(\"woops!: %f\\n\", 0, data);\n | ^~~~~~~~~~~~~~\n \n $ ./x\n 1.234\n as is: -927712936\n as double: 0.000000\n cast to double: -927712936.000000\n cast to double type pointer: 1.234000\n woops!: 1.234000\n *** stack smashing detected ***: terminated\n Aborted (core dumped)\n \n```\n\n※ stack protector が有効になっているので異常終了します。\n\nという訳で、Fushihara さんの回答はある意味で正しいと言えます(多少説明不足かな、とは思いますが……)。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T09:45:03.577",
"id": "86598",
"last_activity_date": "2022-02-27T10:10:04.267",
"last_edit_date": "2022-02-27T10:10:04.267",
"last_editor_user_id": "47127",
"owner_user_id": "47127",
"parent_id": "86592",
"post_type": "answer",
"score": 1
}
] | 86592 | null | 86596 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "タイトルの通り、SpresenseでのRGB565フォーマットによる高解像度画像の取得についてご教示頂きたく。\n\nCameraのサンプルを使用してRGB565フォーマットでVGAやFULL\nHD画質での画像取得を実施しようとしておりますが、エラーが出て取得することが出来ません。 \nRGB565でもQVGAでの取得や、JPGフォーマットでの高解像度画像の取得は問題なく出来ております。 \nRGB565 QVGAでの取得サイズが150KBなので、VGA程度なら600KBで取得出来そうですがそれも出来ません。\n\nSpresenseのメモリ領域が小さいことが起因していそうですが、対策等分かればご教示頂けませんでしょうか?\n\n### 試したこと\n\n * Spresenseのメモリサイズを1536KBに変更 ← 効果なし\n * Streaming関数の停止 ← 効果なし\n\n### エラー内容\n\n * RGB565 VGAサイズ \n`>>Error: Invalid parameter`\n\n * RGB565 FULL HDサイズ \n`>>Error: No memory`\n\n### 変更しているコード部分\n\n```\n\n theCamera.setStillPictureImageFormat(\n CAM_IMGSIZE_VGA_H,\n CAM_IMGSIZE_VGA_V,\n CAM_IMAGE_PIX_FMT_RGB565);\n \n```\n\n以上、宜しくお願いします。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T11:07:43.497",
"favorite_count": 0,
"id": "86599",
"last_activity_date": "2022-03-11T15:55:54.043",
"last_edit_date": "2022-02-28T01:21:34.800",
"last_editor_user_id": "3060",
"owner_user_id": "51626",
"post_type": "question",
"score": 0,
"tags": [
"spresense",
"arduino",
"camera"
],
"title": "SpresenseでのRGB565フォーマットによる高解像度画像の取得ができない",
"view_count": 325
} | [
{
"body": "自分も以前、気になってこの件調べてみました。\n\nspresense-nuttx/arch/arm/src/cxd56xx/cxd56_cisif.c\n\nの59行目の\n\n```\n\n #define YUV_VSIZE_MAX (360)\n #define YUV_HSIZE_MAX (480)\n \n```\n\nと、749行目の\n\n```\n\n static int cisif_chk_yuvfrmsize(int w, int h)\n {\n if ((w < YUV_HSIZE_MIN) || (w > YUV_HSIZE_MAX))\n {\n return -EINVAL;\n }\n \n if ((h < YUV_VSIZE_MIN) || (h > YUV_VSIZE_MAX))\n {\n return -EINVAL;\n }\n \n return OK;\n }\n \n \n```\n\nで、360x480 以下として、判定をしています。\n\nこのことから、360x480 以下という仕様なのだと思われます。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T17:10:39.307",
"id": "86620",
"last_activity_date": "2022-02-28T17:10:39.307",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "32281",
"parent_id": "86599",
"post_type": "answer",
"score": 1
},
{
"body": "トリッキーな技ですが JPEG で取り込んで、RGB に展開してファイルに出力するということができます。Arduino で行う場合は、Spresense\nArduino Board Package に **libjpeg** を取り込む必要があります。\n\nやり方を[ここ](https://ja.stackoverflow.com/questions/73301/spresense-\narduino-%e3%81%a7-libjpeg-%e3%82%92%e4%bd%bf%e3%81%84%e3%81%9f%e3%81%84)に紹介していますが、ボードパッケージを作るのは面倒だと思うので、独自パッケージを\nGithub リポジトリに公開しました。必要でしたら使ってみてください。README に従って、Arduino IDE に URL\nを設定すれば、ボードマネージャーからインストールできます。\n\n<https://github.com/YoshinoTaro/spresense-arduino-libjpeg>\n\nさて、肝心のやり方ですが、上記のリポジトリにもサンプルがありますが、簡略化したコードを掲載しておきます。JPEG を展開した\nRGBデータをファイルに保存できます。(メモリ展開も試してみたのですが、かなり大きな画像なのでメモリ不足で無理でした)\n\nこの技を拡張すれば、指定した ROI のみを部分デコードして RGB に展開することもできます。この場合、ROI\nが小さければメモリにも展開できます。上記リポジトリ内にサンプルがありますので、もしよろしければ参照してみてください。\n\n```\n\n /* [注意!]\n * このコードを試すには、libjpeg が有効になった Spresense Arduino\n * Board Package が必要です。次のURLで取得できます。(V2.4.0 base)\n * (Spresense libjpeg Boards: Spresense libjpeg)\n * https://github.com/YoshinoTaro/spresense-arduino-libjpeg\n */\n #include <Camera.h>\n #define HAVE_BOOLEAN\n \n #include <nuttx/config.h>\n #include <sys/stat.h>\n #include <unistd.h>\n #include <libjpeg/jpeglib.h>\n #include <string.h>\n extern \"C\" {\n #include <setjmp.h>\n }\n \n const int width = CAM_IMGSIZE_VGA_H;\n const int height = CAM_IMGSIZE_VGA_V;\n const char filename[10] = \"out.rgb\";\n \n extern \"C\" bool decode_jpeg_to_file(uint8_t* imgbuf, uint32_t imgsize\n , const char* filename);\n \n void setup() { \n Serial.begin(115200);\n theCamera.begin();\n theCamera.setStillPictureImageFormat(\n width, height, CAM_IMAGE_PIX_FMT_JPG);\n CamImage img = theCamera.takePicture();\n if (!img.isAvailable()) {\n Serial.println(\"Cannot take a picture\");\n return;\n }\n \n if (!decode_jpeg_to_file(img.getImgBuff(), img.getImgSize()\n , filename)) {\n Serial.println(\"decode error\");\n return;\n }\n \n Serial.println(\"the decoded image saved as out.rgb\");\n Serial.println(\"Please change the filename to out.data to visualize by GIMP\");\n \n // end the camera to reset the format and free the image buffer\n theCamera.end(); \n }\n \n void loop() {}\n \n bool decode_jpeg_to_file(uint8_t* imgbuf, uint32_t imgsize\n , const char* filename) {\n \n struct stat buf;\n for (;;) {\n sleep(1);\n int ret = stat(\"/mnt/sd0\", &buf);\n if (ret) printf(\"Please insert formateed SD Card.\\n\");\n else break;\n }\n \n char path[20] = \"/mnt/sd0/\";\n strcat(path, filename);\n printf(\"Filie path: %s\\n\", path);\n FILE* out = fopen(path, \"wb\");\n if (out == NULL) {\n fprintf(stderr, \"can't open %s\\n\", filename);\n return false;\n }\n printf(\"create %s\\n\", filename);\n \n static struct jpeg_decompress_struct cinfo;\n struct jpeg_error_mgr jerr; \n \n cinfo.err = jpeg_std_error(&jerr);\n jpeg_create_decompress(&cinfo);\n \n jpeg_mem_src(&cinfo, imgbuf, imgsize);\n \n jpeg_read_header(&cinfo, TRUE);\n \n cinfo.out_color_space = JCS_RGB;\n \n jpeg_start_decompress(&cinfo);\n printf(\"cinfo.output_width: %d\\n\", cinfo.output_width); \n printf(\"cinfo.output_height: %d\\n\", cinfo.output_height); \n \n JSAMPARRAY buffer; /* Output row buffer */\n int row_stride; /* physical row width in output buffer */\n row_stride = cinfo.output_width * 3; // in case of RGB\n buffer = (*cinfo.mem->alloc_sarray)\n ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);\n \n printf(\"Step6: read scanlines\\n\");\n int n = 0; /* for debug */\n while (cinfo.output_scanline < height) {\n jpeg_read_scanlines(&cinfo, buffer, 1);\n if (row_stride != fwrite(buffer[0], 1, row_stride, out)) {\n printf(\"fwrite error : %d\\n\", errno);\n }\n ++n;\n }\n printf(\"read lines: %d\\n\", n); /* for debug */\n fclose(out);\n \n jpeg_finish_decompress(&cinfo);\n jpeg_destroy_decompress(&cinfo);\n return true;\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-11T15:42:45.550",
"id": "86802",
"last_activity_date": "2022-03-11T15:55:54.043",
"last_edit_date": "2022-03-11T15:55:54.043",
"last_editor_user_id": "27334",
"owner_user_id": "27334",
"parent_id": "86599",
"post_type": "answer",
"score": 0
}
] | 86599 | null | 86620 |
{
"accepted_answer_id": "86601",
"answer_count": 2,
"body": "freq='D'のDateTimeIndexで、ニューヨーク時刻の2022/02/07を92日前にずらすとAmbiguousTimeErrorが発生します。\n\nfreq属性をNoneにすればエラーを回避できることが確認できましたが、現在の振る舞い/仕様が不可解で納得できずにいます。 \nタイムゾーンを変換するときに、夏時間によるあいまいさが発生するのは理解でできたのですが、freq属性の有無で振る舞いが変わることが理解できません。 \nこの振る舞いは仕様(期待どおりの振る舞い)なのでしょうか? \nもし仕様だとしたら、それを裏付ける背景/理由などがご存じでしょうか?\n\nWindows10, Python 3.9.1, Pandas 1.4.1 で100%再現しました。\n\n```\n\n import platform\n import pandas as pd\n print(f'- Python:[{platform.python_version()}], Pandas:[{pd.__version__}]')\n \n datetime_index = pd.DatetimeIndex([pd.Timestamp('2022-02-07',tz='America/New_York')], freq='D')\n # datetime_index.freq = None # <---この行を実行するとエラー回避できた\n print('入力:', datetime_index)\n \n datetime_index = datetime_index.shift(periods=-92, freq='D')\n print('出力:', datetime_index)\n \n```\n\n[](https://i.stack.imgur.com/J7lzv.png)",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T13:44:17.000",
"favorite_count": 0,
"id": "86600",
"last_activity_date": "2022-02-27T23:42:03.297",
"last_edit_date": "2022-02-27T16:16:38.883",
"last_editor_user_id": "3060",
"owner_user_id": "35267",
"post_type": "question",
"score": 1,
"tags": [
"python",
"python3",
"pandas"
],
"title": "awareなDataTimeIndexのshiftによる、不可解なAmbiguousTimeErrorについて",
"view_count": 84
} | [
{
"body": "> この振る舞いは仕様(期待どおりの振る舞い)なのでしょうか?\n\nソースコードの通りに動作しているので仕様と言えるのでしょう、おそらく。。。 \n※ 本来であれば `shift` メソッドに `ceil` や `floor` メソッドと同様に `ambiguous`\nキーワードが用意されているとよいのですけれども。\n\n最初に、`pandas.core.indexes.datetimelike.DatetimeIndexOpsMixin.shift`\nメソッドのソースコードは以下になります。\n\n[pandas/datetimelike.py at 1.4.x · pandas-\ndev/pandas](https://github.com/pandas-\ndev/pandas/blob/1.4.x/pandas/core/indexes/datetimelike.py#L356)\n\n```\n\n def shift(self: _T, periods: int = 1, freq=None) -> _T:\n :\n \n arr = self._data.view()\n arr._freq = self.freq\n result = arr._time_shift(periods, freq=freq)\n return type(self)._simple_new(result, name=self.name)\n \n```\n\nここで、`pandas.core.arrays.datetimelike.DatetimeLikeArrayMixin._time_shift`\nを呼び出しています。\n\n[pandas/datetimelike.py at 1.4.x · pandas-\ndev/pandas](https://github.com/pandas-\ndev/pandas/blob/1.4.x/pandas/core/arrays/datetimelike.py#L1230)\n\n```\n\n def _time_shift(\n self: DatetimeLikeArrayT, periods: int, freq=None\n ) -> DatetimeLikeArrayT:\n :\n \n if freq is not None and freq != self.freq:\n if isinstance(freq, str):\n freq = to_offset(freq)\n offset = periods * freq\n return self + offset\n :\n \n \n```\n\n今回の場合、`freq` は `shift` の parameter で `-92` です。そして、\n\n```\n\n datetime_index.freq = None\n \n```\n\nを実行した場合、`self.freq` は `None` になります。つまり、この `if` statement が成立して(`True`)、\n\n```\n\n >>> datetime_index + (-92) * pd._libs.tslibs.to_offset('D')\n DatetimeIndex(['2021-11-07 01:00:00-04:00'], dtype='datetime64[ns, America/New_York]', freq=None)\n \n```\n\nが戻される事になります(DST は考慮されません)。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T18:04:33.677",
"id": "86601",
"last_activity_date": "2022-02-27T18:04:33.677",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "47127",
"parent_id": "86600",
"post_type": "answer",
"score": 0
},
{
"body": "**freq属性の有無** よりも **freq属性が'D'である** ことと、 **時刻を指定していないので 00:00:00 を指定したと見做される**\nことの組み合わせが原因と思われます。\n\n[DateOffset objects - Time series / date\nfunctionality](https://pandas.pydata.org/pandas-\ndocs/stable/user_guide/timeseries.html#dateoffset-objects) \npandasの上記説明に書かれている`'D'`より細かい単位の`'H'`,`'T'`,`'S'`,`'L'`,`'U'`,`'N'`を`freq=`に指定するとエラーは発生しません。\n\nまた`freq='D'`のままで`pd.Timestamp('2022-02-07',tz='America/New_York')`の`'2022-02-07'`の部分に午前2時以後の時刻を指定して`'2022-02-07\n02:00'`や`'2022-02-07 23:59:59.999999999'`にするとエラーは発生しません。 \nしかし時刻部分に`00:00`から`01:59:59.999999999`までを指定していると同様のエラーになります。\n\nこちらの記事で、`'Europe/Berlin'`のタイムゾーンだと`02:00`から`02:59:59.999999999`までが同様に曖昧な時間として扱われるようです。 \n[Why do I get 'Cannot infer dst time from '2017-10-29 02:04:15', try using the\n'ambiguous' argument?](https://stackoverflow.com/q/51872791/9014308)\n\nこの辺のIssueが関連してそうで修正されているケースもあるようですね。 \n[Fix naive-datetime timezone conversion when marshaling dataframes\n#1061](https://github.com/streamlit/streamlit/issues/1061) \n[Fix datetime timezone handling in data frames\n#2784](https://github.com/streamlit/streamlit/pull/2784) \n[BUG: round() on tz-aware DateTimeIndex (spanning DST switch) throws\nAmbiguousTimeError as if tz-unaware #37485](https://github.com/pandas-\ndev/pandas/issues/37485) \n[BUG: Timestamp.floor() method not able to handle DST change in local time\n#44287](https://github.com/pandas-dev/pandas/issues/44287)\n\nだからまだ修正しきれていないバグの可能性もありそうです。 \nIssuesを検索して同様の物が無ければIssueを発行してみてはどうでしょう?",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-27T23:42:03.297",
"id": "86603",
"last_activity_date": "2022-02-27T23:42:03.297",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26370",
"parent_id": "86600",
"post_type": "answer",
"score": 0
}
] | 86600 | 86601 | 86601 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "Pythonでテキストにある内容をリスト化してCSVに出力したいのですが、やり方が分からなくて困っています。 \n調べたものでコードを作ってみたのですが、想像している動きではないので皆様のお力が欲しいです。\n\n**対象のテキストファイル**\n\n```\n\n 名前:A\n クラス:B\n 学年:C\n 成績:D\n \n 名前:AA\n クラス:BB\n 学年:CC\n 成績:DD\n \n```\n\n以上の `:` 以降の内容を、Pythonで次のようにリスト化し\n\n * `[A,B,C,D]`\n * `[AA,BB,CC,DD]`\n\nさらに最終的に `,` で区切ってCSVに出力したいです(下図の通り)。\n\n[](https://i.stack.imgur.com/uc4Mo.png)\n\n自分では以下のようなPythonコードが書けましたが、これをより短いコードで、期待通りの出力を得られるようにする方法をご教示いただけますと幸いです。\n\n**現状のコード:**\n\n```\n\n with open(r\"txtファイル\",encoding='utf-8') as f:\n lines = f.readlines()\n stat = 0\n for line in lines:\n if stat == 0:\n if(line.startswith(\"名前:\")):\n print(line.strip(\"名前:\"))\n stat = 1\n \n for line in lines:\n if stat == 1:\n if(line.startswith(\"クラス\")):\n print(line.strip(\"クラス:\"))\n stat = 2\n \n for line in lines:\n if stat == 2:\n if(line.startswith(\"学年:\")):\n print(line.strip(\"学年:\"))\n stat = 3\n \n for line in lines:\n if stat == 3:\n if(line.startswith(\"成績:\")):\n print(line.strip(\"成績:\"))\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T01:23:12.677",
"favorite_count": 0,
"id": "86604",
"last_activity_date": "2022-03-14T05:09:13.387",
"last_edit_date": "2022-03-07T12:05:47.497",
"last_editor_user_id": "3060",
"owner_user_id": "51630",
"post_type": "question",
"score": 0,
"tags": [
"python",
"csv"
],
"title": "Pythonでテキストファイルの内容をリスト化してCSVで出力する",
"view_count": 2556
} | [
{
"body": "pandas と openpyxl がインストールされている環境で \n成績:D\n\n名前:AA \nの「成績:D」と「名前:AA」の間が改行だけの空行の前提になります。\n\n```\n\n import pandas as pd\n \n df = pd.read_table(r\"txtファイル\", encoding='utf-8', header=None, engine='python', sep=':')\n item_num = len(set(df.values[:,0]))\n ary = df.values[:,1].reshape(-1, item_num)\n df2 = pd.DataFrame(ary, columns=df.values[0:item_num,0])\n df2.to_excel('data2.xlsx', header=True, index=False)\n \n```\n\n標準のリスト型のデータが欲しい場合は、上記 ary からリストにしてください。\n\n```\n\n lst = list(map(list, ary))\n print(lst)\n # [['A', 'B', 'C', 'D'], ['AA', 'BB', 'CC', 'DD']]\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T02:21:26.633",
"id": "86605",
"last_activity_date": "2022-03-14T04:38:24.333",
"last_edit_date": "2022-03-14T04:38:24.333",
"last_editor_user_id": "43025",
"owner_user_id": "41756",
"parent_id": "86604",
"post_type": "answer",
"score": 0
},
{
"body": "##### Pandas モジュールを使う場合\n\n```\n\n import pandas as pd\n \n with open(r'result_sheet.txt', encoding='utf-8') as f:\n records = [\n dict(j.split(':') for j in i.split('\\n') if j)\n for i in f.read().replace('\\r', '').split('\\n\\n') if i\n ]\n \n \n df = pd.DataFrame(records)\n df.to_excel('result_sheet.xlsx', index=False)\n \n```\n\n[](https://i.stack.imgur.com/ME7pf.png)\n\n##### CSV モジュールを使う場合\n\n```\n\n import csv\n \n with open(r'result_sheet.txt', encoding='utf-8') as f:\n records = [\n dict(j.split(':') for j in i.split('\\n') if j)\n for i in f.read().replace('\\r', '').split('\\n\\n') if i\n ]\n \n with open('result_sheet.csv', 'w') as f:\n writer = csv.DictWriter(f, fieldnames=records[0].keys())\n writer.writeheader()\n for r in records:\n writer.writerow(r)\n \n```\n\n**result_sheet.csv**\n\n```\n\n 名前,クラス,学年,成績\n A,B,C,D\n AA,BB,CC,DD\n \n```",
"comment_count": 5,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T02:30:00.637",
"id": "86606",
"last_activity_date": "2022-03-14T05:09:13.387",
"last_edit_date": "2022-03-14T05:09:13.387",
"last_editor_user_id": "3060",
"owner_user_id": "47127",
"parent_id": "86604",
"post_type": "answer",
"score": 1
}
] | 86604 | null | 86606 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Macbook pro mid2014に外付けGPU(egpu)をつけて外付けgpuから映像出力させるのがゴールです。\n\n現在、以下のURLを参考にpurge-wrangler.shを用いてegpuを認識させようとしてますが、うまくいかず。 \n<https://blog.goo.ne.jp/pinknoiz/e/7b347eadd8ac11e473b45e1b00911551>\n\n物理的なケーブルは以下のようになってます。 \nPC⇄TB2ケーブル⇄TB2,TB3変換ケーブル⇄egpu\n\nOSバージョン \nBig Sur \n11.6.4\n\nGPU \nRADEON RX 6500XT\n\n些細なことでも結構です。 \n情報をください。\n\nうまくいかない点: \nこのMacについてのグラフィックスのところがIntel Iris 1536 MBのままになっている \n参考URLにあるようなアイコンがメニューバーに追加されない",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T03:37:21.027",
"favorite_count": 0,
"id": "86607",
"last_activity_date": "2022-02-28T04:26:14.693",
"last_edit_date": "2022-02-28T04:26:14.693",
"last_editor_user_id": "39728",
"owner_user_id": "39728",
"post_type": "question",
"score": 0,
"tags": [
"macos",
"gpu"
],
"title": "purge-wranglerを用いたeGPUの認識がうまくいかない",
"view_count": 207
} | [] | 86607 | null | null |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "C#(Unity)でHoloLens2に映し出すコンテンツ制作に興味があり取り掛かり始めました。 \nそこで、自然光が多いと、HoloLens2のホログラム(CG)の色が薄くなることに不便を感じています。 \nホログラムを表示するときの輝度を調整したいので、せっかくですから、HoloLens2に内蔵されているハンドトラッキング用のカメラからHoloLens2が置かれている環境についての輝度などの値を得られたら、と思いました。 \nAPIでセンサー値が得られる、など情報をお持ちの方教えて頂けませんでしょうか。",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T04:32:34.403",
"favorite_count": 0,
"id": "86608",
"last_activity_date": "2022-02-28T04:32:34.403",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51631",
"post_type": "question",
"score": 2,
"tags": [
"c#",
"unity3d",
"api"
],
"title": "HoloLens2に付いているカメラから輝度の値を得たい。",
"view_count": 94
} | [] | 86608 | null | null |
{
"accepted_answer_id": "86629",
"answer_count": 1,
"body": "LaravelをPHPStormを利用して開発しています。\n\nPHPのインデントを4 \nBladeファイルのインデントを2(デフォルトは4) \nに設定しましたが、 \nReformat Codeしてもコードのリフォーマットは走りますが、インデントが4から2に変わりません。\n\n設定方法が悪いのでしょうか? \n同じような設定していてうまく行っている方、アドバイスをいただけると助かります。 \nよろしくおねがいします。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T08:52:50.960",
"favorite_count": 0,
"id": "86612",
"last_activity_date": "2022-03-01T05:19:02.337",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "50588",
"post_type": "question",
"score": 0,
"tags": [
"laravel",
"phpstorm"
],
"title": "PHPStormのBladeのインデント設定が反映されない",
"view_count": 339
} | [
{
"body": "自己解決しました。\n\nしくみがよくわかってないのですが、 \nCode Style -> Enable Editor Config support \nのチェックボックスにデフォルトでチェックが入ってたのですが、 \n試しに外してみたところリフォーマットが効くようになりました。\n\nチェックをはずすと別の所で副作用があるかもしれませんが、 \nとりあえずこの対応で行こうと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T05:19:02.337",
"id": "86629",
"last_activity_date": "2022-03-01T05:19:02.337",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "50588",
"parent_id": "86612",
"post_type": "answer",
"score": 0
}
] | 86612 | 86629 | 86629 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "「ゼロから作るディープラーニング」という本を読んで勉強しています。 \n読み進めていくとcommonというモジュールをインポートすることになるのですが、ここで以下のエラーが発生します。\n\n```\n\n ModuleNotFoundError: No module named 'common'\n \n```\n\ncommonモジュールというものをインストールしようとしたのですがそもそもこれ自体一般公開されているものではないらしく、インストールできませんでした。 \nまた、githubにはオライリー公式のcommonモジュールのファイルがあったのですが、このファイルはモジュールとして使うことはできるのでしょうか?できるのであればやり方を教えていただきたいです。\n\n【ゼロから作るディープラーニング ソースコード】 \n<https://github.com/oreilly-japan/deep-learning-from-scratch>",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T14:14:58.533",
"favorite_count": 0,
"id": "86617",
"last_activity_date": "2022-09-02T15:00:30.067",
"last_edit_date": "2022-02-28T16:25:07.447",
"last_editor_user_id": "3060",
"owner_user_id": "48078",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3",
"深層学習"
],
"title": "commonモジュールをimportしたい",
"view_count": 2656
} | [
{
"body": "参照先のリポジトリに`common`というフォルダがあって、それを`import`するようになっています。\n\n例えば`ch06/weight_init_compare.py`の2から5行目に以下の行があり、これが`common`を`import`出来るようにするための準備です。\n\n>\n```\n\n> import os\n> import sys\n> \n> sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定\n> \n```\n\n上記のコードは、リポジトリのフォルダ構成をそのまま展開して使用することを前提にしています。\n\n貴方が何か新しいことを行いたい場合、上記のリポジトリを展開したフォルダの`ch01`から`ch08`があるのと同じ階層に自分で何かのフォルダ(例えば`sample01`等)を作って、自分で作成したソースコードをそのフォルダ内に格納し、上記のコードを`common`を`import`する前に挿入すれば良いでしょう。\n\nそうしたフォルダ構成を同様に保つことはせずに済ませたい場合は、上記コードの`os.pardir`の部分を、展開した`common`の親フォルダを絶対パスで指定すれば同等の事が出来ます。\n\n仕様については以下を参照してください。 \n[6.1.2. モジュール検索パス](https://docs.python.org/ja/3/tutorial/modules.html#the-\nmodule-search-path) \n[6.2. 標準モジュール](https://docs.python.org/ja/3/tutorial/modules.html#standard-\nmodules)\n\n* * *\n\nJupyter-\nlab/notebook系の作業フォルダがスクリプト/ノートブックファイルの存在するフォルダと別になっていることもある開発環境の場合、上記方法だと上手くいかないこともあります。 \nそれは`os.pardir`が`'..'`という文字列定数なので、それは現在の作業フォルダの親フォルダを示すものだからです。 \n[os.pardir](https://docs.python.org/ja/3/library/os.html#os.pardir)\n\n> 親ディレクトリを参照するためにオペレーティングシステムで使われる文字列定数です。 POSIX と Windows では `'..'` になります。\n> os.path からも利用できます。\n\n参照先リポジトリのIssuesにこんな記事がありました。 \n[sys.path.append(os.pardir)がうまく行かず、os.pardirのところにフルパスを指定したところ動きました\n#25](https://github.com/oreilly-japan/deep-learning-from-scratch/issues/25) \n質問者の環境はmacosですがコンソールのようなので参考程度でしょうか。\n\n例えばスクリプトファイル自身のパスを取得出来ればそこから親フォルダを取得する方法があります。 \n[Pythonで実行中のスクリプトのパスを取得する: __file__, os.path.abspath, os.path.dirname,\nos.path.basename](https://yu-nix.com/blog/2021/7/20/python-path-get/) \n[Pythonで親ディレクトリの絶対パスを取得](https://qiita.com/Amayarielu/items/56d7f5e74ee25bb8d234)\n\nただしどうもJupyter-lab/notebook系でノートブックファイルのパスを取得する標準的な方法は無さそうな感じです。 \nでもこちらにそのためのパッケージを自分で作ったこんな記事が見つかったので、試してみてはどうでしょう? \n[[Jupyter]\n実行中のipynbファイルが自分のパスを取得できるパッケージを作った](https://qiita.com/kzm4269/items/7f79ac40cf8f30e4afa3)\n\nあるいはこんな記事もありますが、ノートブックを色んなフォルダに分けたい場合は向いて無いかもしれません。 \n[JupyterLabのホームディレクトリを変更する方法](https://sawalabo.com/210318-jupyterlab-home-\ndir/)",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T14:44:24.590",
"id": "86618",
"last_activity_date": "2022-03-01T02:21:12.260",
"last_edit_date": "2022-03-01T02:21:12.260",
"last_editor_user_id": "26370",
"owner_user_id": "26370",
"parent_id": "86617",
"post_type": "answer",
"score": 1
}
] | 86617 | null | 86618 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Laravelで作ったAPIをテストしようと \n外部APIテストツールで値を入れて叩いて見たのですが、 \nPOST/PUTメソッド csrf対策されているのか \n_tokenないと419error起きてしまいます。 \nどのようにテストしたら良いでしょうか。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-02-28T14:57:09.500",
"favorite_count": 0,
"id": "86619",
"last_activity_date": "2022-02-28T14:57:09.500",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "44839",
"post_type": "question",
"score": 0,
"tags": [
"php",
"laravel",
"api"
],
"title": "Laravelで作ったAPIのテスト方法 csrf対策で弾かれます",
"view_count": 440
} | [] | 86619 | null | null |
{
"accepted_answer_id": "86623",
"answer_count": 2,
"body": "`list(for x in range(10))`や,`''.join(for elem in\nelements)`などでは,`list`,`join`の引数は何として扱われているのでしょうか. \n`list([for x in range(10)])`と同義ですか,それとも`list((for x in range(10)))`でしょうか.",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T00:04:20.733",
"favorite_count": 0,
"id": "86622",
"last_activity_date": "2022-03-01T04:30:05.877",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51374",
"post_type": "question",
"score": 5,
"tags": [
"python",
"python3"
],
"title": "カッコのないジェネレーター表記?",
"view_count": 230
} | [
{
"body": "> `list(for x in range(10))`や,`''.join(for elem in\n> elements)`などでは,list,joinの引数は何として扱われているのでしょうか.\n\n仮に`list(x for x in range(10))`や`''.join(elem for elem in elements)`とした場合、 \nこれらlistやjoinの内部に記述されたものはご推察の通り、カッコのないジェネレーター表記です。\n\n> `list([for x in range(10)])`と同義ですか,それとも`list((for x in range(10)))`でしょうか.\n\n`list(x for x in range(10))`と同義なのは **後者** です。 \n以下にコードを示します。\n\n## コード\n\n```\n\n a = list(x for x in range(10))\n b = [x for x in range(10)]\n c = list([x for x in range(10)])\n d = (x for x in range(10))\n e = list(d)\n f = list((x for x in range(10)))\n \n # generatorをlistでキャスト\n print('aの型:{}, 値:{}'.format(type(a), a))\n \n # リスト内包表記\n print('bの型:{}, 値:{}'.format(type(b), b))\n \n # リスト内包表記をリストでキャスト\n print('cの型:{}, 値:{}'.format(type(c), c))\n \n # generator\n print('dの型:{}, 値:{}'.format(type(d), d))\n \n # generatorをlistでキャスト(aと同じ)\n print('eの型:{}, 値:{}'.format(type(e), e))\n \n # generatorをlistでキャスト(aと同じ)\n print('fの型:{}, 値:{}'.format(type(f), f))\n \n # generatorを直接確認\n print(type(x for x in range(10)))\n print(x for x in range(10))\n \n print(''.join(str(elem) for elem in a))\n \n```\n\n## 実行結果\n\n```\n\n aの型:<class 'list'>, 値:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n bの型:<class 'list'>, 値:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n cの型:<class 'list'>, 値:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n dの型:<class 'generator'>, 値:<generator object <genexpr> at 0x103667b30>\n eの型:<class 'list'>, 値:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n fの型:<class 'list'>, 値:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n <class 'generator'>\n <generator object <genexpr> at 0x103667a50>\n 0123456789\n \n```\n\nまた、一般的にジェネレーターの方が単なるリストよりも、メモリサイズや処理が高速となる場合が多いです。ご参考までに。 \n[Pythonでジェネレータを使用してメモリ効率の高いプログラムを作成する。](https://ichi.pro/python-de-jyenere-ta-\no-shiyoshite-memori-koritsu-no-takai-puroguramu-o-sakuseisuru-80836849663398)",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T00:30:09.603",
"id": "86623",
"last_activity_date": "2022-03-01T00:49:31.553",
"last_edit_date": "2022-03-01T00:49:31.553",
"last_editor_user_id": "51317",
"owner_user_id": "51317",
"parent_id": "86622",
"post_type": "answer",
"score": 2
},
{
"body": "公式ドキュメントだと\n\n<https://docs.python.org/ja/3/reference/expressions.html#generator-\nexpressions>\n\n> 関数の唯一の引数として渡す場合には、丸括弧を省略できます。\n\nのところですね。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T04:30:05.877",
"id": "86628",
"last_activity_date": "2022-03-01T04:30:05.877",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12274",
"parent_id": "86622",
"post_type": "answer",
"score": 2
}
] | 86622 | 86623 | 86623 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "私の理解は、下記のとおりなのですが、疑問があります。\n\n * マルチキャストは、複数のクライアントに配信することが目的。\n * ブロードキャストは、特定のセグメント内の全ポートに配信することが目的。\n\n**疑問1** \nL2ネットワーク(同一セグメント)の場合、マルチキャストもブロードキャストも同様に全ポートに配信される挙動に変わりはない?(IGMP\nsnoopingを使わない場合)\n\n**疑問2** \n調べる中で、”フラッディング”という言葉がでてきたのですが、フラッディングはMACアドレスが解決できなかった場合に、全ポートに投げるという意味と理解しました。 \nブロードキャストの場合、意図的な全ポート配信なので、フラッディングとは言わない? \n同様に、マルチキャストの場合は、フラッディングといってよい? \nブロードキャストもフラッディングといっている記事もあり混乱しています。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T01:26:02.047",
"favorite_count": 0,
"id": "86624",
"last_activity_date": "2022-03-03T06:57:19.190",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "42232",
"post_type": "question",
"score": 0,
"tags": [
"network"
],
"title": "マルチキャストとブロードキャストの違い",
"view_count": 397
} | [
{
"body": "前提からおさらいすると、 \n・マルチキャストは、特定の「アドレス」を指定して通信すること。 \n・ブロードキャストは、特定の「ネットワーク」を指定して通信すること。 \nです。\n\n特定のアドレスを指定して通信する都合上、マルチキャストは同一セグメント内の「全て」を \n対象としているわけではありません。\n\n例えていうならば、ブロードキャストは〇〇町全域に聞こえる防災放送。 \nマルチキャストは、〇〇町△△会の会員のみに伝えられる回覧板や会員放送といった感じです。\n\nそれを踏まえて、疑問にお答えすると\n\n■疑問1\n\n> (IGMP snoopingを使わない場合)\n\n「IGMP Snoopingを使わない場合」という前提は、やや不完全かと思います。 \n「マルチキャストグループのメンバーが適切に定義されていない場合」というのが正しいでしょう。\n\nマルチキャストグループのメンバーが適切に定義されていない場合、どのポートがメンバーかを正確に判断出来ない為、全ポートに配信されます。 \n定義が適切にされている場合は、マルチキャストグループに属するポートのみに配信されます。\n\n※IGMP\nSnoopingは、スイッチ側が自動的にマルチキャストグループの加入/離脱を判断し、適切な転送を行う為の機能ですが、この機能を用いずに手動でメンバー定義を行うことも可能です。\n\nブロードキャストは、同一ネットワーク内への一斉配信が前提にありますので、全ポートに配信されます。\n\n■疑問2\n\n>\n> 調べる中で、”フラッディング”という言葉がでてきたのですが、フラッディングはMACアドレスが解決できなかった場合に、全ポートに投げるという意味と理解しました。\n\nスイッチ自身のMACアドレステーブルに記載されていないフレームについては、受け取った誰かがしっかり処理してくれることを期待して全ポートに配信される為、フラッディングが発生します。\n\n> ブロードキャストの場合、意図的な全ポート配信なので、フラッディングとは言わない?\n\nブロードキャストは一斉配信するのが正しい動作の為、フラッディングではありません。 \nこの場合の全ポート転送は「ブロードキャスティング」と言います。\n\n> 同様に、マルチキャストの場合は、フラッディングといってよい?\n\nマルチキャストまたはユニキャストの場合、先に述べたように適切な定義がされていない場合、全ポートに転送するしかない為、「フラッディング」となります。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T06:57:19.190",
"id": "86667",
"last_activity_date": "2022-03-03T06:57:19.190",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "50521",
"parent_id": "86624",
"post_type": "answer",
"score": 0
}
] | 86624 | null | 86667 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Macでlaravel,vue.js,docker(ローカルではdockerにnginxを使用)を使用してローカルでWEBアプリを制作しています。.envの設定がおかしいからだとは思いますが、dbとして使用しているローカルのmysqlに繋がらず、そのために\n`php artisan migrate`\nがエラーとなって詰まってしまっています。どこの設定が間違っているためにmysqlに繋がらないのかを知りたいのですがよろしくお願いします。\n\n### 追記 \nマルチポストしていることを説明し忘れました。内容は全く同じですが追記しておきたいと思います。 \n<https://teratail.com/questions/dudp4gwhsdoz12>\n\n### エラー\n\n```\n\n root@8be8ddaa6767:/var/www/html# php artisan migrate \n \n Illuminate\\Database\\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = sample and table_name = migrations and table_type = 'BASE TABLE')\n \n at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669\n 665| // If an exception occurs when attempting to run a query, we'll format the error\n 666| // message to include the bindings with SQL, which will make this exception a\n 667| // lot more helpful to the developer instead of just the database's errors.\n 668| catch (Exception $e) {\n > 669| throw new QueryException(\n 670| $query, $this->prepareBindings($bindings), $e\n 671| );\n 672| }\n 673| \n \n Exception trace:\n \n 1 PDOException::(\"PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known\")\n /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70\n \n 2 PDO::__construct(\"mysql:host=db;port=3306;dbname=sample\", \"hoge\", \"777\", [])\n /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70\n \n Please use the argument -v to see more details.\n \n```\n\n### 追記\n\nコメントで助言されたのを試したところプロセスがうまく実行できていないことまでわかりました。\n\n```\n\n % docker-compose ps\n NAME COMMAND SERVICE STATUS PORTS\n portfolio-app-1 \"docker-php-entrypoi…\" app running 9000/tcp\n portfolio-db-1 \"docker-entrypoint.s…\" db exited (1) \n portfolio-web-1 \"/docker-entrypoint.…\" web running 0.0.0.0:80->80/tcp\n \n```\n\n### 追記2\n\n% docker-compose logs db の結果、'utf8mb4_0900_ai_ci'がおかしいとのことです。\n\n```\n\n % docker-compose logs db\n portfolio-db-1 | 2022-03-05 10:29:56+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.37-1debian10 started.\n portfolio-db-1 | 2022-03-05 10:29:57+09:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config\n portfolio-db-1 | command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.Ef2AJ4XEgw\n portfolio-db-1 | 2022-03-05T10:29:57.143207+09:00 0 [ERROR] Unknown collation: 'utf8mb4_0900_ai_ci'\n portfolio-db-1 | 2022-03-05T10:29:57.148263+09:00 0 [ERROR] Aborting\n masa@MasaakinoMacBook-Air portfolio % \n \n \n \n docker/mysql/my.cnfの部分にこの記述、 'utf8mb4_0900_ai_ci' があります\n \n portfolio/docker/mysql/my.cnf\n \n [mysqld]\n user=mysql\n character_set_server = utf8mb4\n //この部分\n collation_server = utf8mb4_0900_ai_ci\n \n # timezone\n default-time-zone = SYSTEM\n log_timestamps = SYSTEM\n \n # Error Log\n log-error = mysql-error.log\n \n # Slow Query Log\n slow_query_log = 1\n slow_query_log_file = mysql-slow.log\n long_query_time = 1.0\n log_queries_not_using_indexes = 0\n \n # General Log\n general_log = 1\n general_log_file = mysql-general.log\n \n [mysql]\n default-character-set = utf8mb4\n \n [client]\n default-character-set = utf8mb4\n \n```\n\nまたthinkerで環境変数を確認したところ一部反映されてないようでここにも原因がありそうです。\n\n```\n\n masa@MasaakinoMacBook-Air portfolio % docker-compose exec app bash \n root@7b0ccf8be086:/var/www/html# php artisan tinker\n Psy Shell v0.11.1 (PHP 7.4.1 — cli) by Justin Hileman\n >>> env('DB_HOST');\n => \"db\"\n >>> env('WEB_PORT');\n => null\n >>> env('DB_PORT');\n => \"3306\"\n >>> env('DB_HOSTURL');\n => null\n >>> env('DB_NAME');\n => null\n >>> env('DB_USER');\n => null\n >>> env('DB_PASSWORD');\n => \"777\"\n >>> env('DB_ROOT_PASSWORD');\n => null\n >>> \n \n```\n\nバージョン \nphp: 7.4.1 \nlaravel: 6.20. \nMySQL version: 8.0.28\n\ndocker, docker-compose.yml は以下のページを参考に利用。\n\n[絶対に失敗しないDockerでLaravel+Vueの実行環境(LEMP環境)を構築する方法〜前編〜](https://qiita.com/shimotaroo/items/29f7878b01ee4b99b951)\n\n```\n\n portfolio($docker-compose up -dをここで起動)\n ├─ docker\n │ ├─ php\n │ │ └─ Dockerfile\n │ │ └─ php.ini\n │ ├─ nginx\n │ │ └─ Dockerfile\n │ │ └─ default.conf\n │ └─ mysql\n │ └─ Dockerfile\n │ └─ my.cnf\n │\n ├─ src(laravelのapp、config,resousesや.env等が入っています)\n │ \n │ \n │─ .env(下)\n │─ .gitignore \n └─ docker-compose.yml(下)\n \n```\n\nportfolio/.env\n\n```\n\n WEB_PORT=80\n DB_PORT=3306\n //docker-compose.yml内のdb\n DB_HOSTURL=db\n DB_NAME=sample\n DB_USER=hoge\n DB_PASSWORD=777\n DB_ROOT_PASSWORD=secret\n \n```\n\nportfolio/src/.env\n\n```\n\n APP_NAME=docker-laravel-vue\n APP_ENV=local\n APP_KEY=省略\n APP_DEBUG=true\n APP_URL=127.0.0.1\n \n LOG_CHANNEL=stack\n \n DB_CONNECTION=mysql\n DB_HOST=db\n DB_PORT=3306\n DB_DATABASE=sample\n \n```\n\ndocker-compose.yml\n\n```\n\n # Composeファイルのバージョン\n version: '3.8'\n \n volumes:\n mysql-volume:\n \n services:\n app:\n build:\n context: .\n dockerfile: ./docker/php/Dockerfile\n volumes:\n - ./src/:/var/www/html\n environment:\n - DB_CONNECTION=mysql\n - DB_HOST=${DB_HOSTURL}\n - DB_PORT=3306\n - DB_DATABASE=${DB_NAME}\n - DB_USERNAME=${DB_USER}\n - DB_PASSWORD=${DB_PASSWORD}\n \n # web_serverでも可\n web:\n build:\n context: .\n dockerfile: ./docker/nginx/Dockerfile\n ports:\n - ${WEB_PORT}:80\n depends_on:\n - app\n volumes:\n - ./src/:/var/www/html\n \n db:\n build:\n context: .\n dockerfile: ./docker/mysql/Dockerfile\n ports:\n - ${DB_PORT}:3306\n environment:\n MYSQL_DATABASE: ${DB_NAME}\n MYSQL_USER: ${DB_USER}\n MYSQL_PASSWORD: ${DB_PASSWORD}\n MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}\n TZ: 'Asia/Tokyo'\n volumes:\n - mysql-volume:/var/lib/mysql \n \n```\n\n追記 \nsrc/config/database.php\n\n```\n\n 'mysql' => [\n 'driver' => 'mysql',\n 'url' => env('DATABASE_URL'),\n 'host' => env('DB_HOST', '127.0.0.1'),\n 'port' => env('DB_PORT', '3306'),\n 'database' => env('DB_DATABASE', 'forge'),\n 'username' => env('DB_USERNAME', 'forge'),\n 'password' => env('DB_PASSWORD', ''),\n 'unix_socket' => env('DB_SOCKET', ''),\n 'charset' => 'utf8mb4',\n 'collation' => 'utf8mb4_unicode_ci',\n 'prefix' => '',\n 'prefix_indexes' => true,\n 'strict' => true,\n 'engine' => null,\n 'options' => extension_loaded('pdo_mysql') ? array_filter([\n PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),\n ]) : [],\n ],\n \n \n```\n\nターミナルに打ち込んだ時に得られる情報\n\nlocalのmysql詳細\n\n```\n\n masa@MasaakinoMacBook-Air portfolio % pwd\n /Users/masa/Desktop/portfolio\n \n masa@MasaakinoMacBook-Air portfolio % mysql -u hoge -p sample;\n Enter password: \n //『777』を入力\n Welcome to the MySQL monitor. Commands end with ; or \\g.\n Your MySQL connection id is 27\n Server version: 8.0.28 Homebrew\n \n Copyright (c) 2000, 2022, Oracle and/or its affiliates.\n \n Oracle is a registered trademark of Oracle Corporation and/or its\n affiliates. Other names may be trademarks of their respective\n owners.\n \n \n mysql> select user( );\n +----------------+\n | user( ) |\n +----------------+\n | hoge@localhost |\n +----------------+\n 1 row in set (0.00 sec)\n \n mysql> show databases;\n +--------------------+\n | Database |\n +--------------------+\n | information_schema |\n | sample |\n +--------------------+\n 2 rows in set (0.01 sec)\n \n mysql> SELECT DATABASE();\n +------------+\n | DATABASE() |\n +------------+\n | sample |\n +------------+\n 1 row in set (0.00 sec)\n \n \n mysql> use sample;\n Database changed\n mysql> SELECT DATABASE();\n +------------+\n | DATABASE() |\n +------------+\n | sample |\n +------------+\n 1 row in set (0.00 sec)\n \n mysql> exit\n Bye\n \n masa@MasaakinoMacBook-Air portfolio % mysql -u root -p \n Enter password: \n //『secret』を入力\n Welcome to the MySQL monitor. Commands end with ; or \\g.\n Your MySQL connection id is 30\n Server version: 8.0.28 Homebrew\n \n Copyright (c) 2000, 2022, Oracle and/or its affiliates.\n \n Oracle is a registered trademark of Oracle Corporation and/or its\n affiliates. Other names may be trademarks of their respective\n owners.\n \n Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n \n mysql> \n \n```\n\n実際の `php artisan migrate` がうまく行かない部分の詳細\n\n```\n\n masa@MasaakinoMacBook-Air portfolio % mysql.server restart \n Shutting down MySQL\n . SUCCESS! \n Starting MySQL\n .. SUCCESS! \n masa@MasaakinoMacBook-Air portfolio % docker-compose down \n [+] Running 4/4\n ⠿ Container portfolio-db-1 Removed 0.1s\n ⠿ Container portfolio-web-1 Removed 0.3s\n ⠿ Container portfolio-app-1 Removed 0.3s\n ⠿ Network portfolio_default Removed 0.1s\n masa@MasaakinoMacBook-Air portfolio % docker builder prune & docker volume prune\n [1] 17257\n WARNING! This will remove all local volumes not used by at least one container.\n Are you sure you want to continue? [y/N] WARNING! This will remove all dangling build cache. Are you sure you want to continue? [y/N] \n Total reclaimed space: 0B\n masa@MasaakinoMacBook-Air portfolio % docker-compose up -d \n [+] Running 4/4\n ⠿ Network portfolio_default Created 0.1s\n ⠿ Container portfolio-app-1 Started 4.3s\n ⠿ Container portfolio-db-1 Started 1.4s\n ⠿ Container portfolio-web-1 Started 5.1s\n masa@MasaakinoMacBook-Air portfolio % docker-compose exec app bash \n root@8be8ddaa6767:/var/www/html# pwd\n /var/www/html\n root@8be8ddaa6767:/var/www/html# ls -a\n . .editorconfig .env.testing .gitignore .styleci.yml app bootstrap composer.lock database package-lock.json phpunit.xml resources server.php tests webpack.mix.js\n .. .env .gitattributes .phpunit.result.cache README.md artisan composer.json config node_modules package.json public routes storage vendor\n \n root@8be8ddaa6767:/var/www/html# php artisan config:cache \n Configuration cache cleared!\n Configuration cached successfully!\n root@8be8ddaa6767:/var/www/html# php artisan config:clear \n Configuration cache cleared!\n root@8be8ddaa6767:/var/www/html# php artisan cache:clear \n Application cache cleared!\n root@8be8ddaa6767:/var/www/html# php artisan migrate \n \n Illuminate\\Database\\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = sample and table_name = migrations and table_type = 'BASE TABLE')\n \n at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669\n 665| // If an exception occurs when attempting to run a query, we'll format the error\n 666| // message to include the bindings with SQL, which will make this exception a\n 667| // lot more helpful to the developer instead of just the database's errors.\n 668| catch (Exception $e) {\n > 669| throw new QueryException(\n 670| $query, $this->prepareBindings($bindings), $e\n 671| );\n 672| }\n 673| \n \n Exception trace:\n \n 1 PDOException::(\"PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known\")\n /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70\n \n 2 PDO::__construct(\"mysql:host=db;port=3306;dbname=sample\", \"hoge\", \"777\", [])\n /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70\n \n Please use the argument -v to see more details.\n \n```",
"comment_count": 11,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T01:42:04.537",
"favorite_count": 0,
"id": "86625",
"last_activity_date": "2022-03-05T04:17:32.930",
"last_edit_date": "2022-03-05T01:34:06.703",
"last_editor_user_id": "51643",
"owner_user_id": "51643",
"post_type": "question",
"score": 0,
"tags": [
"php",
"macos",
"docker",
"laravel",
"docker-compose"
],
"title": "Docker 環境で php artisan migrate がうまく行かない",
"view_count": 952
} | [
{
"body": "`docker-compose logs db` の実行結果\n\n```\n\n portfolio-db-1 | 2022-03-05 10:29:56+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.37-1debian10 started.\n portfolio-db-1 | 2022-03-05 10:29:57+09:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config\n portfolio-db-1 | command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.Ef2AJ4XEgw\n portfolio-db-1 | 2022-03-05T10:29:57.143207+09:00 0 [ERROR] Unknown collation: 'utf8mb4_0900_ai_ci'\n portfolio-db-1 | 2022-03-05T10:29:57.148263+09:00 0 [ERROR] Aborting\n \n```\n\nのように 'utf8mb4_0900_ai_ci' でエラーとなるので\n\n[(Resolved) Unknown collation:\nutf8mb4_0900_ai_ci](https://tecadmin.net/resolved-unknown-collation-\nutf8mb4_0900_ai_ci/)\n\nのサイトを参考にdocker内を \nCOLLATION を'utf8_general_ci' \nCHARACTER を'utf8' \nに変更したところ\n\n(docker/mysql/my.cnfの部分にこの記述、 'utf8mb4_0900_ai_ci' があるのでコードを載せておきたいと思います↓)\n\nportfolio/docker/mysql/my.cnf(元々)\n\n```\n\n [mysqld]\n user=mysql\n character_set_server = utf8mb4\n \n collation_server = utf8mb4_0900_ai_ci\n \n # timezone\n default-time-zone = SYSTEM\n log_timestamps = SYSTEM\n \n # Error Log\n log-error = mysql-error.log\n \n # Slow Query Log\n slow_query_log = 1\n slow_query_log_file = mysql-slow.log\n long_query_time = 1.0\n log_queries_not_using_indexes = 0\n \n # General Log\n general_log = 1\n general_log_file = mysql-general.log\n \n [mysql]\n default-character-set = utf8mb4\n \n [client]\n default-character-set = utf8mb4\n \n```\n\n改めて `docker-compose logs db` を実行した結果、以下のようにエラーメッセージが変わりました。\n\n```\n\n masa@MasaakinoMacBook-Air portfolio % \n portfolio-db-1 | 2022-03-05 10:58:18+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.37-1debian10 started.\n portfolio-db-1 | 2022-03-05 10:58:18+09:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config\n portfolio-db-1 | command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.u6hnMzU23j\n portfolio-db-1 | 2022-03-05T10:58:18.873878+09:00 0 [ERROR] COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'utf8mb4'\n portfolio-db-1 | 2022-03-05T10:58:18.876518+09:00 0 [ERROR] Aborting\n \n```\n\n'utf8_general_ci' は CHARACTER 'utf8mb4' に対して有効でないため \nlaravel内、およびdocker内の全てを \nCOLLATION を'utf8_general_ci' \nCHARACTER を'utf8' \nに統一すると `php artisan migrate` が通りました。解決できました。ありがとうございました!♂️",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T02:25:57.143",
"id": "86692",
"last_activity_date": "2022-03-05T04:17:32.930",
"last_edit_date": "2022-03-05T04:17:32.930",
"last_editor_user_id": "3060",
"owner_user_id": "51643",
"parent_id": "86625",
"post_type": "answer",
"score": 2
}
] | 86625 | null | 86692 |
{
"accepted_answer_id": "86627",
"answer_count": 1,
"body": "以下の記事にある、方法2 を中心に実験しています。\n\n[Python、Requestsを使ったダウンロード](https://blog.narito.ninja/detail/67/)\n\nこうすると、保存は出来るのですが、テキストでべたに書かれていて、見づらいファイルが出来上がってしまいます。\n\n例えば `print(json.dumps(data_jsn, indent=2))`\nというような感じで出てくるものをそのままファイルに保存するような方法ありますか?\n\nタブ位置などを合わせた書式で保存したい。また、可能であればソースコードのループ構造は避けたい。以下のようなイメージです。\n\n```\n\n with open(fullpath, 'wb') as f:\n f.write(str(json.dumps(data_jsn, indent=2)))\n f.close()\n \n```\n\nこれだと以下のエラーが表示されます。\n\n```\n\n TypeError: a bytes-like object is required, not 'str'\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T02:26:37.867",
"favorite_count": 0,
"id": "86626",
"last_activity_date": "2022-03-01T02:45:48.290",
"last_edit_date": "2022-03-01T02:45:48.290",
"last_editor_user_id": "3060",
"owner_user_id": "43160",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3",
"json"
],
"title": "Python で JSON ファイルの保存時にエラー TypeError: a bytes-like object is required",
"view_count": 809
} | [
{
"body": "`TypeError: a bytes-like object is required, not 'str'`が出てしまうのは \n**バイナリモード** で開いてしまっていることが原因かと思われます。 \n解決方法としては下記のように、open関数の引数を'wb'から'w'に書き換えればjson形式で出力されます。\n\n```\n\n # with open(fullpath, 'wb') as f:\n with open(fullpath, 'w') as f:\n f.write(str(json.dumps(data_jsn, indent=2)))\n f.close()\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T02:37:00.607",
"id": "86627",
"last_activity_date": "2022-03-01T02:37:00.607",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51317",
"parent_id": "86626",
"post_type": "answer",
"score": 1
}
] | 86626 | 86627 | 86627 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "# やりたいこと\n\nGoogleAppsScriptにて、スクリプト実行ユーザのToDoリスト内に存在するタスクのうち、 \n「日付」(due)の値がスクリプト実行日以前のものを取得するプログラムの作成\n\n# 問題点\n\nGASのサービス「Tasks API」を用いて、「GoogleCalendar」「Gmail」の画面から登録したタスクが取得できることを確認した。 \nしかし、GoogleChatのスペース内にある「タスク」機能を使用して登録したタスクについては、 \n割り当て先=スクリプト実行ユーザとして登録した場合でも取得できなかった。(タスクを登録したユーザも同一です)\n\n * 「タスク」機能を使用して、スクリプト実行ユーザに割り当て先を設定して登録 \n[](https://i.stack.imgur.com/WtMY4.png)\n\n * スクリプト実行時点での、スクリプト実行ユーザの「マイタスク」内に存在するタスク一覧 \n[](https://i.stack.imgur.com/kws5u.png)\n\n * スクリプト実行結果 \n[](https://i.stack.imgur.com/myIMG.png)\n\n# 質問内容\n\n * この方法で、GoogleChatの「タスク」機能を用いて割り当てたタスクが取得できなかった理由 \n(「タスク機能」を使用して登録したタスクは、割り当て先のユーザには紐付かない?)\n\n * GoogleChatの「タスク」機能を用いて割り当てたタスクの、Tasks APIでの正しい取得方法\n\n# 補足\n\n下記の公式ドキュメントには、目を通しております。 \n<https://developers.google.com/apps-script/advanced/tasks>\n\n以上、他にも情報にアップデートがあれば追記していきます。 \n何卒、宜しくお願い致します。",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T07:38:13.900",
"favorite_count": 0,
"id": "86631",
"last_activity_date": "2022-03-01T11:33:28.547",
"last_edit_date": "2022-03-01T11:33:28.547",
"last_editor_user_id": "3060",
"owner_user_id": "51646",
"post_type": "question",
"score": 0,
"tags": [
"google-apps-script",
"google-workspace"
],
"title": "Google Chat 経由で登録したタスクが、Tasks API で取得できない",
"view_count": 730
} | [] | 86631 | null | null |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "JSON-LDで値を返す RESTful API を使って、`r = requests.get( <API> )` で受け取った \n`r` の `type` は `<class 'requests.models.Response'>` です。\n\n[JSON を Pandas DataFrame に変換する](https://www.delftstack.com/ja/howto/python-\npandas/json-to-pandas-dataframe/) のページを見ながら真似してみたのですが、エラーとなってしまいます。 \n`json.loads(r.text)` の引数に何を入れたらよいのかがわかりません。\n\nよろしくお願いいたします。\n\n**コード:**\n\n```\n\n data_jsn = json.loads(r.text)\n df = pd.read_json(data_jsn, orient='index')\n \n```\n\n**エラーメッセージ:**\n\n```\n\n raise ValueError(msg)\n ValueError: Invalid file path or buffer object type: <class 'list'>\n \n```",
"comment_count": 5,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-01T07:49:25.910",
"favorite_count": 0,
"id": "86632",
"last_activity_date": "2022-03-01T23:59:32.767",
"last_edit_date": "2022-03-01T23:59:32.767",
"last_editor_user_id": "47127",
"owner_user_id": "43160",
"post_type": "question",
"score": 0,
"tags": [
"python",
"pandas",
"json"
],
"title": "JSON-LD を Pandas の DataFrame へ変換する方法",
"view_count": 282
} | [] | 86632 | null | null |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "不特定数の辞書をcsvに記載したいのですが、私の知識では方法をみつけることが出来ませんでした。 \nもし、何か方法ございましたらご教示頂けないでしょうか。\n\n[試したコード] \n以下コードは辞書が2つあった場合にやりたいことを実現出来たコードとなります。 \nただ、実際は辞書(d1,d2...)はユーザー入力のため、不特定で対応できるコートが必要となります。\n\n```\n\n import csv\n \n labels = ['FData_1', 'FData_2', 'FData_3']\n d1 = {'FData_1': 'test', 'FData_2': 2, 'FData_3': 3}\n d2 = {'FData_1': 10, 'FData_3': 30}\n \n with open('sample_dictwriter.csv', 'w') as f:\n writer = csv.DictWriter(f, fieldnames=labels)\n writer.writeheader()\n writer.writerow(d1)\n writer.writerow(d2)\n \n```\n\n#writer.writerow(dn)をfor文などで回す方法を探しております。\n\nどうぞよろしくお願い致します。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T04:25:12.277",
"favorite_count": 0,
"id": "86639",
"last_activity_date": "2022-03-02T04:37:10.810",
"last_edit_date": "2022-03-02T04:37:10.810",
"last_editor_user_id": "51317",
"owner_user_id": "51133",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3",
"csv"
],
"title": "複数の辞書に対してループで特定の処理を実行したい",
"view_count": 93
} | [] | 86639 | null | null |
{
"accepted_answer_id": "86649",
"answer_count": 1,
"body": "<https://pyorc.readthedocs.io/en/stable/tutorial.html#using-custom-converters> \npyorc というモジュールのカスタムクラス内で\n\n```\n\n class TestConverter(ORCConverter):\n @staticmethod\n def to_orc(obj, timezone):\n print(obj)\n print(type(obj))\n return (obj, 0)\n \n```\n\n```\n\n 1646092740\n <class 'int'>\n 2022-03-02 13:21:12,888 [ERROR] Unable to cast Python instance to C++ type (compile in debug mode for details)\n \n```\n\nというデバッグ出力とエラーになります\n\n```\n\n return (int(obj), 0)\n \n```\n\nとかくとエラーになりません\n\n> [ERROR] Unable to cast Python instance to C++ type (compile in debug mode\n> for details)\n\nこれはどういう意味のエラーなんでしょうか\n\n元々 <class 'int'> なのに int(obj) でキャストすると何が変化するんでしょうか\n\n* * *\n\n再現できるデータを見極めたいんですがなかなか再現しません\n\nエラーが再現するソースコード全体は後述のものになります\n\n他のプログラムがシリアライズ化した marshal ファイルをもう1度よみこんでそのまま 中身を orc writer\nに流し込むだけなのでデータに依存してるんだと思いますが、データの中身は業務情報が含まれていて公開できません\n\nただエラーになる直前のログは\n\n```\n\n (1646200394,)\n 1646200394\n <class 'int'>\n \n```\n\nとなるのでこの値を書き込んでエラーがでているのは間違い無いんですが \nコメントアウトしてる行を追加してこの値のみの1レコードを書き込んだファイルではエラーにならず成功します\n\n```\n\n import datetime\n import pyorc\n import marshal\n from pyorc.converters import ORCConverter\n \n class TestConverter(ORCConverter):\n @staticmethod\n def to_orc(obj, timezone):\n print(obj)\n print(type(obj))\n return (obj, 0)\n \n # with open('test.msl', 'wb') as f:\n # marshal.dump((1646200394,), f)\n \n with open('test.orc', 'wb') as orc_file:\n orc_writer = pyorc.Writer(\n orc_file,\n 'struct<time:timestamp>',\n converters={pyorc.TypeKind.TIMESTAMP: TestConverter},\n )\n with open('test.msl', 'rb') as f:\n try:\n while True:\n row = marshal.load(f)\n print(row)\n orc_writer.write(row)\n except EOFError:\n pass\n \n orc_writer.close()\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T04:48:25.087",
"favorite_count": 0,
"id": "86640",
"last_activity_date": "2022-03-02T11:00:11.087",
"last_edit_date": "2022-03-02T10:00:10.193",
"last_editor_user_id": null,
"owner_user_id": null,
"post_type": "question",
"score": 0,
"tags": [
"python"
],
"title": "int class なのに int() でキャストしないとエラーになる",
"view_count": 165
} | [
{
"body": "```\n\n if not isinstance(obj, int)\n print(obj)\n print(type(obj))\n \n```\n\nといれてみたところ float のデータが混ざっていました \nmarshal データを作る側で python のデフォルトで datetime 型から timestamp() をよぶと float\nになっちゃってたみたいです\n\nここからは想像ですが \npyorc は列単位である程度データが溜まってからファイル出力するので \nwrite をよんでもすぐにかきこまれずに変換時になってもっと前に書き込んだ float を int 出力しようとしてエラーになったみたいです\n\nお騒がせしました",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T11:00:11.087",
"id": "86649",
"last_activity_date": "2022-03-02T11:00:11.087",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "86640",
"post_type": "answer",
"score": 0
}
] | 86640 | 86649 | 86649 |
{
"accepted_answer_id": "86644",
"answer_count": 1,
"body": "Microsoft SOAP Toolkit 2.0をダウロードできるリンクを教えて下さい。 \niis5、VB6の環境でWebサービス(SOAP)を構築したいです。 \n実装例やiis5への設定方法が載ったページもあれば教えて下さい。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T06:27:38.140",
"favorite_count": 0,
"id": "86641",
"last_activity_date": "2022-03-02T09:01:27.813",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9183",
"post_type": "question",
"score": 0,
"tags": [
"webapi",
"soap",
"vb6"
],
"title": "Microsoft SOAP Toolkit 2.0のダウンロード",
"view_count": 236
} | [
{
"body": "以下のサイトの「サブスクライバーアクセス」からたどっていって入手できると思われます。 \n[Visual Studio:\nソフトウェア開発者とチーム向けのIDEおよびコードエディター](https://visualstudio.microsoft.com/ja/)\n\nただし、以下の条件が必要でしょう。\n\n * Visual StudioまたはMSDNのしかるべき製品またはライセンスを購入していること。 \nその種類によっては入手出来ないものもあるでしょう。\n\n * Microsoftアカウントを登録してサインインしていること。\n * 上記サイトのサブスクライバーとして登録していること。\n\nこのサイトとページから始まる一連の記事が提供しているサービスと使い方の説明になっています。 \n[Visual Studio サブスクリプションに関するドキュメント](https://docs.microsoft.com/ja-\njp/visualstudio/subscriptions/)\n\n[サブスクライバー ポータルの使用 - my.visualstudio.com](https://docs.microsoft.com/ja-\njp/visualstudio/subscriptions/using-the-subscriber-portal) \nサブスクリプション管理者のサポートを受ける \nVisual Studio サブスクリプションでのソフトウェア ダウンロードに対する製品の利用可能性 \nVisual Studio サブスクリプションでソフトウェア タイトルをダウンロードする \nダウンロードできるソフトウェア\n\n上記「ダウンロードできるソフトウェア」ページにリンクのあるこちらのExcelシートに **Soap Toolkit 2.0**\nが記載されており、どの製品やライセンスを持っていれば入手できるかチェックで示されています。(なおSoap Toolkit 3.0も記載されています) \n[ソフトウェア ダウンロードの一覧](https://docs.microsoft.com/ja-\njp/visualstudio/subscriptions/software-download-list)\n\n* * *\n\nSOAP Toolkit 2.0でのWebサービス構築方法やFAQと思われる記事がこちら。 \n[Building Secure Web Services with Microsoft SOAP Toolkit\n2.0](https://docs.microsoft.com/en-us/previous-versions/ms995772\\(v=msdn.10\\)) \n[Microsoft SOAP Toolkit Version 2.0 FAQ](https://docs.microsoft.com/en-\nus/previous-versions/ms995780\\(v=msdn.10\\))",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T09:01:27.813",
"id": "86644",
"last_activity_date": "2022-03-02T09:01:27.813",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26370",
"parent_id": "86641",
"post_type": "answer",
"score": 1
}
] | 86641 | 86644 | 86644 |
{
"accepted_answer_id": "86643",
"answer_count": 1,
"body": "事務所内のネットワークに2回線のインターネットが接続されています。 \n※ビジネス電話との関係でNTTとKDDIの2回線の契約があります。\n\n**NTT系** \nRT58i:192.168.1.5 \nVPN設定あり\n\n**KDDI系** (KDDI-HGWからDMZ接続)デフォルトGW \nNVR830:192.168.1.10 \nVPN設定あり\n\nクライアント端末のGWは基本的にKDDIへ接続されており、 \nリモートワークのためKDDI経由でVPN+RDP接続しています。\n\n先日KDDI回線が不調だったためNTT回線のRT58iへもVPN設定を行いVPNの疎通も確認できたのですが、RDP接続ができませんでした。\n\n色々とためしてみるとGWがNTTになっているときにはNTTからのRDP接続はできるが、KDDIのGW設定になっている場合はNTTからのRDP接続はNGになるようです。\n\nKDDIの回線が復活してから逆パターンも試してみましたが同じ状況で、VPN接続をしているルーター側にGWを設定していないとRDP接続ができませんでした。\n\nできれば保険として片方の回線がダメでももう片方の回線からRDP接続ができるとうれしいのですが、そういう事は難しいのでしょうか。\n\n事務所に居たらKDDIの回線の調子が悪い場合、手動でNTTのGWへ変更すれば問題無く使えるのはわかるのですが、事務所に行かずに生きている方のVPNからRDP接続(入れたらGWも手動で切り替え出来る)と言った運用ができると助かるのです。\n\nルート設定等で可能なのでしょうか。\n\n説明が分かりにくいかもしれませんが、どなたかお知恵をいただけると大変助かります。\n\n* * *\n\nhtb様\n\n詳しくありがとうございます\n\n1.KDDI側は触れるのですが、NTT側は業者がVoipの設定も含めて管理しているため入れ替えは難しいかもしれません \nただ、回線バックアップが使えるような機種だと一番安心できそうですね\n\n2.デフォルトゲートウェイを自動的に切り替えるのはbatとかですかね \n各端末で常時監視するのはちょっとハードルが高そうですので調査してみます\n\n3.VPN端末に払い出されるIPへのルート設定で良かったのですね \n言われたら確かにその通りなのですが接続元のグローバルIPへのルート設定をしないといけないのかと勘違いしました\n\nVPN払い出しIPはNTT(192.168.1.100-149)、KDDI(192.168.1.150-199)でそれぞれ違います\n\nIP範囲を変更して考えてみましたがこんな感じで良いのでしょうか \nNTT(192.168.1.96-127) \nKDDI(192.168.1.128-159)\n\nroute -p add 192.168.1.96 mask 255.255.255.224 192.168.1.5 \nroute -p add 192.168.1.128 mask 255.255.255.224 192.168.1.10",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T06:29:40.820",
"favorite_count": 0,
"id": "86642",
"last_activity_date": "2022-03-03T01:03:34.333",
"last_edit_date": "2022-03-03T01:03:34.333",
"last_editor_user_id": "51659",
"owner_user_id": "51659",
"post_type": "question",
"score": 0,
"tags": [
"vpn",
"rdp"
],
"title": "同一ネットワーク内の2つのゲートウェイとRDP接続について",
"view_count": 171
} | [
{
"body": "何個か手法はあると思います。\n\n 1. WANのポートを2個以上持つVPNルーターに置き換える \nRTX1220など。 \n<https://network.yamaha.com/products/routers/rtx1220/index> \nWAN回線のバックアップといった機能。 \n<https://network.yamaha.com/setting/router_firewall/internet/internet_redundancy/wan_backup/> \nお金とルーター導入の技術的なハードルはありますが、堅牢かと思います。\n\n 2. 端末のデフォルトゲートウェイを自動的に変更する \nping 8.8.8.8 など、インターネットへの疎通ができなくなったら、デフォルトゲートウェイを変更する。 \n既にデフォルトゲートウェイを変更すればOKであることは確認できているので、次善の策としてはアリだと思います。 \nデフォルトゲートウェイを自動的に変更するのは、別の問題を生みそうな気もします。\n\n 3. 事務所の端末にスタティックルートを書く \nVPN端末に払い出されるIPアドレス(ネットワーク)へのスタティックルートをGW宛に書く。 \nVPN端末とは事務所の外のVPN接続してくる手元のパソコンを指します。払い出されるIPアドレスは質問に書かれていないので具体的に答えることはできません。 \n<https://www.infraexpert.com/study/routing4.html>",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T07:23:42.370",
"id": "86643",
"last_activity_date": "2022-03-02T07:23:42.370",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2238",
"parent_id": "86642",
"post_type": "answer",
"score": 0
}
] | 86642 | 86643 | 86643 |
{
"accepted_answer_id": "86648",
"answer_count": 1,
"body": "<https://arrow.apache.org/docs/python/generated/pyarrow.orc.ORCWriter.html#pyarrow.orc.ORCWriter> \nこちらのモジュールを使って AWS Athena で読めるカラムナー形式のファイルを作りたいのですが使い方がわかりません\n\n```\n\n import pyarrow\n orc_writer = pyarrow.orc.ORCWriter('test.orc')\n \n```\n\nとかいただけでも \n`AttributeError: module 'pyarrow' has no attribute 'orc'` \nとなってそもそもモジュールのクラスすら見つけることができません\n\n* * *\n```\n\n pip list | grep pyarrow\n pyarrow 7.0.0\n \n```\n\nとなるので入ってるモジュールとみてるドキュメントバージョンは一致しているとおもうのですが...",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T09:30:28.950",
"favorite_count": 0,
"id": "86646",
"last_activity_date": "2022-03-02T14:34:24.777",
"last_edit_date": "2022-03-02T14:34:24.777",
"last_editor_user_id": null,
"owner_user_id": null,
"post_type": "question",
"score": 0,
"tags": [
"python"
],
"title": "pyarrow の orcwriter クラスの使い方",
"view_count": 54
} | [
{
"body": "以下の import 文を追加してみてください。\n\n```\n\n import pyarrow.orc\n \n```\n\n参考: \n<https://stackoverflow.com/a/68415793/2322778>",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T09:46:52.170",
"id": "86648",
"last_activity_date": "2022-03-02T09:46:52.170",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3060",
"parent_id": "86646",
"post_type": "answer",
"score": 1
}
] | 86646 | 86648 | 86648 |
{
"accepted_answer_id": "86656",
"answer_count": 1,
"body": "PowerShellのforeachステートメントでの挙動についてお聞きしたいです。 \n以下が通常のforeach文です。\n\n```\n\n $data = @('one','two','three')\n foreach ($a in $data) {\n \"$a\"\n }\n one\n two\n three\n \n```\n\n配列の要素1つ1つが$aに代入されて出力されている認識です。 \n以下がお聞きしたいforeach文です。\n\n```\n\n $data = @('one', 'two', 'three')\n foreach ($a in ,$data){\n \"$a\"\n }\n one two three\n \n```\n\n上記の文だと$aが配列になり、要素1つ1つが配列になった$aに代入されて出力されるイメージであってますでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T13:11:36.333",
"favorite_count": 0,
"id": "86650",
"last_activity_date": "2022-03-02T20:49:41.447",
"last_edit_date": "2022-03-02T13:24:39.440",
"last_editor_user_id": "51662",
"owner_user_id": "51662",
"post_type": "question",
"score": 0,
"tags": [
"powershell"
],
"title": "PowerShellのカンマ演算子の挙動について",
"view_count": 232
} | [
{
"body": "正しいです。`.GetType()`で型を調べることで確認できます。\n\n```\n\n PS> $data.GetType()\n \n IsPublic IsSerial Name BaseType\n -------- -------- ---- --------\n True True Object[] System.Array\n \n \n PS> $data[0].GetType()\n \n IsPublic IsSerial Name BaseType\n -------- -------- ---- --------\n True True String System.Object\n \n```\n\nと`$data`は`Object[]`であり、その先頭要素`$data[0]`は`String`です。\n\n`$data2 = ,$data`としたうえで\n\n```\n\n PS> $data2 = ,$data\n PS> $data2.GetType()\n \n IsPublic IsSerial Name BaseType\n -------- -------- ---- --------\n True True Object[] System.Array\n \n \n PS> $data2[0].GetType()\n \n IsPublic IsSerial Name BaseType\n -------- -------- ---- --------\n True True Object[] System.Array\n \n \n PS> $data2[0][0].GetType()\n \n IsPublic IsSerial Name BaseType\n -------- -------- ---- --------\n True True String System.Object\n \n```\n\nと`$data2`は`Object[]`ですが、その先頭要素`$data2[0]`は`Object[]`となります。更に先頭要素`$data2[0][0]`が`String`となります。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T20:49:41.447",
"id": "86656",
"last_activity_date": "2022-03-02T20:49:41.447",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "86650",
"post_type": "answer",
"score": 0
}
] | 86650 | 86656 | 86656 |
{
"accepted_answer_id": "86653",
"answer_count": 1,
"body": "```\n\n import pyarrow.orc\n orc_writer = pyarrow.orc.ORCWriter('test.orc')\n \n```\n\nとかいてみたところ \n`zsh: segmentation fault python test.py` \nとなってしまいます\n\n何かデータを書き込まないとダメなのかと思い \n以下のコードで1レコードだけいろいろな型のデータを書き込んでみたんですがかわらず segmentation fault になります\n\n```\n\n import pyarrow as pa\n import pyarrow.orc\n \n with pyarrow.orc.ORCWriter('test.orc') as orc_writer:\n data = [\n pa.array(['abc'], type=pa.string()),\n pa.array([10], type=pa.int32()),\n pa.array([1.5], type=pa.float64()),\n pa.array([1646200394], type=pa.timestamp('s')),\n pa.array([['x1', 'y1']], type=pa.list_(pa.string())),\n pa.array([b\"\\x00\\x00\\x00\\x00\\x01\\x01\\x00\\x00\\x00\" + struct.pack('d', 37) + struct.pack('d', 137)], type=pa.binary(length=25)),\n ]\n table = pa.table(data, names=[f'col{i}' for i in range(6)])\n orc_writer.write(table)\n \n```\n\ntest.orc 自体は中身空で作成されました(消して実行すると再作成されます)\n\n* * *\n\n書き込み方があってるのかも不明です \n<https://arrow.apache.org/docs/python/generated/pyarrow.orc.ORCWriter.html#pyarrow.orc.ORCWriter.write> \nこちらをみると引数が table みたいなので\n\n<https://arrow.apache.org/docs/python/getstarted.html> \nこちらの getstart を参考にして table を作ってみました\n\n最終的に作りたい Athena のカラム型が \nstring,double,int,timestamp,array,geom:binary \nの 6 つで \n<https://arrow.apache.org/docs/python/api/datatypes.html> \nこちらをみながらテストデータを書き込んだ次第です \n特に timestamp, string array, binary の与え方はあってるか自信ないですが \n`` \n`['x1', 'y1']` \n`b\"\\x00\\x00\\x00\\x00\\x01\\x01\\x00\\x00\\x00\" + struct.pack('d', 37) +\nstruct.pack('d', 137)` \nの値自体は pyorc という別のモジュールを使って生成した orc では Athena 上で読めていました",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T14:36:30.460",
"favorite_count": 0,
"id": "86652",
"last_activity_date": "2022-03-03T10:45:01.133",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"post_type": "question",
"score": 0,
"tags": [
"python"
],
"title": "pyarrow の orcwriter の使い方",
"view_count": 91
} | [
{
"body": "処理の目的が tableの書き込みであれば, 以下のようにできます\n\n```\n\n import pyarrow as pa\n import pyarrow.orc as orc # ⇐ 追加\n import pandas as pd\n import struct\n \n df = pd.DataFrame({\n 'col0': ['abc'],\n 'col1': [10],\n 'col2': [1.5],\n 'col3': [1646200394],\n 'col4': [['x1', 'y1']],\n 'col5': [b\"\\x00\\x00\\x00\\x00\\x01\\x01\\x00\\x00\\x00\"\n + struct.pack('d', 37) + struct.pack('d', 137)],\n }).astype(\n {'col1': 'int32', 'col3': 'datetime64[s]'})\n \n # table 準備とファイルへの書き込み\n table = pa.Table.from_pandas(df)\n display(table)\n orc.write_table(table, 'test.orc')\n \n # orc を pandasで読み取ってみる\n df = pd.read_orc('test.orc')\n display(df)\n \n```\n\n[](https://i.stack.imgur.com/Bsv3q.png)\n\n* * *\n\n#### 追記\n\nDataFrameを pyorc使って書き込む場合は, 以下の方法で可能なはず\n\n```\n\n with open('test.orc', 'wb') as orc_file:\n writer = pyorc.Writer(orc_file,\n 'struct<col0:string,col1:int,col2:double,col3:timestamp,col4:array<string>,col5:binary>',\n struct_repr=pyorc.StructRepr.DICT)\n writer.writerows(df.to_dict(orient=\"records\"))\n writer.close()\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T15:28:35.323",
"id": "86653",
"last_activity_date": "2022-03-03T10:45:01.133",
"last_edit_date": "2022-03-03T10:45:01.133",
"last_editor_user_id": "43025",
"owner_user_id": "43025",
"parent_id": "86652",
"post_type": "answer",
"score": 0
}
] | 86652 | 86653 | 86653 |
{
"accepted_answer_id": "86668",
"answer_count": 1,
"body": "unity初心者です。 \nTimelineでオブジェクトを移動する時、AnimationTrackからtransformの値を変更することで移動させることができますが、 \n凸凹した地形を移動する場合や、ジェットコースターで縦に一回転するような動きを作る場合、transformの値を細かく変えていく以外に方法はあるのでしょうか? \nTimelineのプレビューで再現できるようにしたいです。 \nご教授お願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T15:56:36.317",
"favorite_count": 0,
"id": "86654",
"last_activity_date": "2022-03-03T07:07:17.153",
"last_edit_date": "2022-03-02T16:18:43.877",
"last_editor_user_id": "3060",
"owner_user_id": "51664",
"post_type": "question",
"score": 0,
"tags": [
"unity3d"
],
"title": "Timelineでオブジェクトの位置を移動する方法",
"view_count": 228
} | [
{
"body": "> ジェットコースターで縦に一回転するような動きを作る場合、transformの値を細かく変えていく以外に方法はあるのでしょうか?\n\nCinemachine の Dolly Track with Cart\nという機能が使いやすいです。ベジェ曲線を引いて、その上を移動させて以下のような事が出来ます。\n\n[](https://i.stack.imgur.com/xYFMq.gif)\n\n上の Scene と Timeline を入れた unitypackage を置いておきます。\n\n * [unitypackage](https://www.dropbox.com/s/lc1egk0o2xtzm4x/DollyTrack.unitypackage?dl=1)\n\n> 凸凹した地形を移動する場合\n\nこちらも Dolly Track with Cart\nである程度できると思いますが、地形によってはやりにくいですね。例えば階段を降りるカットシーンだったら、早めに足下を画角からはずしてごまかし、足と地形を合わせなければならない手間を削るだろうと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T07:07:17.153",
"id": "86668",
"last_activity_date": "2022-03-03T07:07:17.153",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "48297",
"parent_id": "86654",
"post_type": "answer",
"score": 0
}
] | 86654 | 86668 | 86668 |
{
"accepted_answer_id": "86659",
"answer_count": 1,
"body": "```\n\n [scripts]\n test=\"python main.py < test.txt\"\n \n```\n\nをPipfile内に書き込み\n\n```\n\n pipenv run test\n \n```\n\nで実行してみると、実行したターミナル上で標準入力待ちに入ります。\n\n実際にコード自体に問題がないことは実行して確かめています。 \npipenvのスクリプトショートカットではリダイレクトができないのでしょうか。 \n可能だった例、疑いのある原因等教えていただけると幸いです。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T16:04:45.947",
"favorite_count": 0,
"id": "86655",
"last_activity_date": "2022-03-02T23:26:41.527",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "36057",
"post_type": "question",
"score": 0,
"tags": [
"python",
"shell",
"pipenv"
],
"title": "pipenvのスクリプトショートカットにてリダイレクトがうまくいかない。",
"view_count": 75
} | [
{
"body": "この Issue 記事が該当すると思われます。 \n[Pipe/redirection in scripts section\n#3277](https://github.com/pypa/pipenv/issues/3277)\n\n> Redirects and pipelines should always be wrapped in a call of `bash -c` to\n> get the expected behavior. Pipenv doesn't wrap it for you.\n\n> リダイレクトやパイプラインで期待される振る舞いを得るには常に`bash\n> -c`の呼び出しでラップする必要があります。pipenvは貴方のためにそれをラップしません。\n\nWindowsなら`cmd /c`でしょうか。\n\nということで、使用しているOSや環境に応じて以下のようにすれば良いでしょう。\n\nUnix系\n\n```\n\n test=\"bash -c \\\"python main.py < test.txt\\\"\"\n \n```\n\nWindows系\n\n```\n\n test=\"cmd /c \\\"python main.py < test.txt\\\"\"\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-02T23:26:41.527",
"id": "86659",
"last_activity_date": "2022-03-02T23:26:41.527",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26370",
"parent_id": "86655",
"post_type": "answer",
"score": 0
}
] | 86655 | 86659 | 86659 |
{
"accepted_answer_id": "86661",
"answer_count": 1,
"body": "やりたいこと: \nPythonでテキストを読み込み、 \nリストから特定文字が含まれていたらその文字を抽出したいです。 \nただリストをスライスする際に**TypeError: 'bool'**エラーが発生します。\n\n**エラー内容**\n\n```\n\n Traceback (most recent call last):\n File \"c:\\Users\\test\\Documents\\test\\textread.py\", line 35, in <module>\n s=New_list[20:35]\n TypeError: 'bool' object is not subscriptable\n \n```\n\nもし、このエラーの回避方法分かる方がいましたら、ご教授をお願い致します。 \nまた別の方法で抽出できるのであれば、教えていただけると幸いです。\n\nテキストファイル\n\n```\n\n フォロワー11\n コメント5件\n \n Enterキーで投稿します\n 2022年2月27日 ·\n \n おはよう!\n \n #元気\n \n 2022年2月28日 ·\n \n 本日良い天気\n \n #晴\n \n コメント2件\n \n Enterキーで投稿します\n \n 2022年3月1日 ·\n \n テスト 投稿\n \n TEST\n #python\n #code\n #programin\n プログラミング\n 簡単\n コーディング\n Python簡単\n pythonできること\n \n Enterキーで投稿します\n 2022年3月2日 ·\n \n こんにちわ!\n \n Enterキーで投稿します\n \n 2022年3月3日 ·\n \n おはようございます!\n \n Enterキーで投稿します\n \n```\n\n毎回テキストデータが変化しますので、 \n下記の文字が含んでいたら抽出したいです。\n\n```\n\n #特定文字がNew_listに含まれているかを調べる\n New_list = \"#python\" in New_list and \"Python簡単\" in New_list and \"#programin\" in New_list\n \n```\n\n**実現したいテキスト出力**\n\n```\n\n 2022年3月1日\n テスト 投稿\n TEST\n #python\n #code\n #programin\n プログラミング\n 簡単\n コーディング\n Python簡単\n pythonできること\n Enterキーで投稿します\n \n```\n\n下記のcodeで試してみましたが、 \n「#特定文字がNew_listに含まれているかを調べる」ところにand条件を入れたあとには \n**TypeError: 'bool'**エラーが発生します。\n\n手前にリストスライス情報を入れるとエラーが発生しません。\n\n```\n\n #スライスして投稿情報取得\n s=New_list[20:35]\n \n```\n\n全体コード\n\n```\n\n import locale\n \n #ファイルパステキスト\n path = r\"C:\\Users\\test\\Desktop\\test.txt\"\n \n #ファイル読み込む\n with open(path, \"r\", encoding=\"utf-8\") as f:\n mylist = f.readlines()\n print(mylist)\n \n #新しいリスト作成して特定の文字を置換\n New_list = []\n for x in mylist:\n New_list.append(x.replace(\"\\n\", \"\",).replace(' ', '').replace('·', '').replace('\\ufeff', ''))\n \n print(str(New_list))\n \n #リスト長さの結果\n # l=len(New_list)\n # print(l)\n # 39結果\n \n #特定文字がNew_listに含まれているかを調べる\n # str_match = [s for s in New_list if \"Enterキーで投稿します\" in s]\n # print(str_match)\n \n # #スライスして投稿情報取得\n # s=New_list[20:35]\n # print(s)\n \n #特定文字がNew_listに含まれているかを調べる\n New_list = \"#python\" in New_list and \"Python簡単\" in New_list and \"#programin\" in New_list\n print(New_list) \n \n if True == New_list :\n print(\"上記の#pythonなどの投稿情報取得\")\n \n #スライスして投稿情報取得\n s=New_list[20:35]\n print(s)\n \n else:\n print(\"何もしない\") \n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T01:26:54.097",
"favorite_count": 0,
"id": "86660",
"last_activity_date": "2022-03-03T01:50:16.470",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "18859",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "PythonテキストリストTypeError: 'bool'に関して",
"view_count": 777
} | [
{
"body": "下記の代入文でNew_listがlist型からbool型に書き変わってしまっています。 \nこれは右辺が条件式(評価結果がTrueまたはFalse)となっているからです。\n\n>\n```\n\n> #特定文字がNew_listに含まれているかを調べる\n> New_list = \"#python\" in New_list and \"Python簡単\" in New_list and\n> \"#programin\" in New_list\n> \n```\n\n解決策としてはNew_listとは別に`is_include`を用意すれば良いです。\n\n```\n\n is_include = \"#python\" in New_list and \"Python簡単\" in New_list and \"#programin\" in New_list\n \n if is_include:\n print(\"上記の#pythonなどの投稿情報取得\")\n \n #スライスして投稿情報取得\n s=New_list[20:35]\n print(s)\n \n else:\n print(\"何もしない\") \n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T01:50:16.470",
"id": "86661",
"last_activity_date": "2022-03-03T01:50:16.470",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51317",
"parent_id": "86660",
"post_type": "answer",
"score": 1
}
] | 86660 | 86661 | 86661 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "1つのタグや宣言の中で`'シングルクォーテーション'`と`\"ダブルクォーテーション\"`が混在するXMLは正しい構文でしょうか?\n\n例えば下のXMLは \n`<Ex am=\" 'シングルクォーテーション' と\" ple=' \"ダブルクォーテーション\" が'>タグの属性の中で混在するが</Ex>` \n[W3Cの定義](https://www.w3.org/TR/xml/)通りと理解して問題ないでしょうか?\n\n**質問の経緯**\n\n下記のような記述のXMLファイルを使用して読込プログラムの動作チェックを行ったところ、1行目のプロローグでエラーになりました。\n\n```\n\n <?xml version=\"1.0\" encoding='UTF-8'?>\n <body>以下略</body>\n \n```\n\nエラーの原因は`version=\"1.0\" encoding='UTF-8'`でクォーテーションの種類が混在していたことです。\n\nお行儀の悪いXML記述と承知しているのですが、W3Cの定義を読んでも **厳密な意味で**\n間違っているのはXMLなのかプログラムなのか確証が持てませんでした。 \nXML出力または読込プログラムのどちらかに改修依頼を出す際の判断基準を求めていることが質問の経緯です。\n\n**調べたこと**\n\n日本語翻訳版の[AttValue](http://w4ard.eplusx.net/translation/W3C/REC-\nxml-20081126/#NT-AttValue)、[2.8\nプロローグと文書型宣言](http://w4ard.eplusx.net/translation/W3C/REC-xml-20081126/#sec-\nprolog-dtd)、[4.3.3\n実体で使われる文字エンコーディング](http://w4ard.eplusx.net/translation/W3C/REC-\nxml-20081126/#charencoding)には、BN記法(バッカス・ナウア記法)?で下記の定義があります。\n\n```\n\n [10] AttValue ::= '\"' ( [^<&\"] | Reference )* '\"'\n | \"'\" ( [^<&'] | Reference )* \"'\" \n \n [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'\n [24] VersionInfo ::= S 'version' Eq ( \"'\" VersionNum \"'\" | '\"' VersionNum '\"' )\n \n [80] EncodingDecl ::= S 'encoding' Eq ( '\"' EncName '\"' | \"'\" EncName \"'\" )\n [81] EncName ::= [A-Za-z] ( [A-Za-z0-9._] | '-' )* /* ラテン文字しか含まないエンコーディング名 Encoding name contains only Latin characters */\n \n```\n\nBN記法を良く分かっていませんが、上記の内容から属性に`'`と`\"`のどちらも利用できると解釈しています。 \nただし混在に関する規定は見つかりませんでした。",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T03:53:27.693",
"favorite_count": 0,
"id": "86662",
"last_activity_date": "2022-03-03T04:07:44.167",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9820",
"post_type": "question",
"score": 2,
"tags": [
"xml"
],
"title": "XML属性の囲い文字として'と\"の混在は文法上許容されるか",
"view_count": 319
} | [] | 86662 | null | null |
{
"accepted_answer_id": "86666",
"answer_count": 1,
"body": "Windows11/Excel2019/Macro\n\nそれぞれのシートの”A1”の値が0.2以下であればそのシートタブを青色にし、0.1以上0.2未満であれば緑色にし、0.1未満0.01以上であればオレンジ色にし、最終的にそれ未満の場合には初期設定の色にするイベントを”ThisWorkbook”に”SheetChange”として下記の通り保存しました。\n\n```\n\n Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)\n If Sh.Range(\"A1\") >= 0.2 Then\n Sh.Tab.Color = RGB(0, 0, 255) 'BLUE\n ElseIf Sh.Range(\"A1\") < 0.2 And Sh.Range(\"A1\").Value >= 0.1 Then\n Sh.Tab.Color = RGB(0, 255, 0) 'GREEN\n ElseIf Sh.Range(\"A1\") < 0.1 And Sh.Range(\"A1\").Value >= 0.01 Then\n Sh.Tab.Color = RGB(255, 165, 0) 'ORANGE\n Else\n Sh.Tab.ColorIndex = xlColorIndexNone 'None\n End If\n End Sub\n \n```\n\n上記は作用しましたが、次にブックを開けたときに作用させたいと考えて全く同じイベントを\"Open\"で保存して見ましたが下記エラーが出てうまくいきませんでした。\n\n```\n\n Private Sub Workbook_Open()\n If Sh.Range(\"A1\") >= 0.2 Then\n Sh.Tab.Color = RGB(0, 0, 255) 'BLUE\n ElseIf Sh.Range(\"A1\") < 0.2 And Sh.Range(\"A1\").Value >= 0.1 Then\n Sh.Tab.Color = RGB(0, 255, 0) 'GREEN\n ElseIf Sh.Range(\"A1\") < 0.1 And Sh.Range(\"A1\").Value >= 0.01 Then\n Sh.Tab.Color = RGB(255, 165, 0) 'ORANGE\n Else\n Sh.Tab.ColorIndex = xlColorIndexNone 'None\n End If\n End Sub\n \n```\n\n**エラー \"Compile error: Variable not defined\"**\n\nなぜでしょうか?どこを直せば意図したような結果が得られるかご教授いただきたいです。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T05:39:48.863",
"favorite_count": 0,
"id": "86665",
"last_activity_date": "2022-03-03T06:17:11.203",
"last_edit_date": "2022-03-03T06:17:11.203",
"last_editor_user_id": "9820",
"owner_user_id": "51310",
"post_type": "question",
"score": 0,
"tags": [
"vba",
"excel"
],
"title": "同じイベントを\"SheetChange\"として保存したときと\"Open\"として保存したときに”Open”として保存した方にだけエラーが出る",
"view_count": 97
} | [
{
"body": "`Workbook_SheetChange`では、引数として`ByVal\nSh`が渡されていますが、`Workbook_Open`では`Sh`が渡されていないことが、「コンパイルエラー:\n変数が定義されていません」エラーが出る原因です。 \n`Sh`を宣言して、アクティブシートなどを代入してください。\n\n```\n\n Private Sub Workbook_Open()\n Dim Sh As Worksheet\n Set Sh = ActiveSheet\n \n If Sh.Range(\"A1\") >= 0.2 Then\n Sh.Tab.Color = RGB(0, 0, 255) 'BLUE\n ElseIf Sh.Range(\"A1\") < 0.2 And Sh.Range(\"A1\").Value >= 0.1 Then\n Sh.Tab.Color = RGB(0, 255, 0) 'GREEN\n ElseIf Sh.Range(\"A1\") < 0.1 And Sh.Range(\"A1\").Value >= 0.01 Then\n Sh.Tab.Color = RGB(255, 165, 0) 'ORANGE\n Else\n Sh.Tab.ColorIndex = xlColorIndexNone 'None\n End If\n End Sub\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T06:16:37.273",
"id": "86666",
"last_activity_date": "2022-03-03T06:16:37.273",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9820",
"parent_id": "86665",
"post_type": "answer",
"score": 0
}
] | 86665 | 86666 | 86666 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "pytorchで推論をしようと保存したモデルを読み込もうとするとエラーが出てきます。 \nGoogle colabの環境下で、gpuで学習を行い、CPUしかない環境下で以下のプログラムを実行するとエラーが出てきます。\n\n```\n\n model = Model\n model.load_state_dict(torch.load(\"185.pth\"))\n \n```\n\n`model.load_state_dict(torch.load(\"185.pth\"),map_location=torch.device('cpu'))`としてもエラーが出てきます。\n\n```\n\n /usr/local/lib/python3.7/dist-packages/torch/serialization.py in validate_cuda_device(location)\n 133 \n 134 if not torch.cuda.is_available():\n --> 135 raise RuntimeError('Attempting to deserialize object on a CUDA '\n 136 'device but torch.cuda.is_available() is False. '\n 137 'If you are running on a CPU-only machine, '\n \n RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.\n \n```\n\nどうすればいいのでしょうか? \nモデルの保存時は、`torch.save(net.state_dict(),'filename.pth')`で保存しています\n\n* * *\n\n追記\n\n```\n\n PATH =\"193.pth\"\n \n model = Model\n device = torch.device('cpu')\n model = Model\n model.load_state_dict(torch.load(PATH, map_location=device))\n \n```\n\nとコードを変更したところ、以下のエラーになりました。\n\n```\n\n TypeError: load_state_dict() missing 1 required positional argument: 'state_dict'\n \n```\n\nもしかしてなのですが、Optunaで学習時に使用していたモデルのままではだめなのでしょうか? \n[こちらのサイト](https://qiita.com/Yushi1958/items/cd22ade638f7e292e520)を参考にOptunaで学習させています。 \nダメとすると、各ハイパーパラメータの値、関数を自分で入力してモデルを一度作成して、読み込むしかないのでしょうか?プログラムである程度自動的に各ハイパーパラメータの値、関数を入れることはできないのでしょうか?",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T08:36:55.493",
"favorite_count": 0,
"id": "86669",
"last_activity_date": "2022-03-03T09:39:04.250",
"last_edit_date": "2022-03-03T09:39:04.250",
"last_editor_user_id": "42741",
"owner_user_id": "42741",
"post_type": "question",
"score": 0,
"tags": [
"python",
"機械学習",
"pytorch"
],
"title": "Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Falseが解消できない。",
"view_count": 961
} | [] | 86669 | null | null |
{
"accepted_answer_id": "86691",
"answer_count": 1,
"body": "最近htmlなどの学習に取り組み始めたばかりの初学者です。 \n元々Rubyの経験が少しあったため、Rubyでのメソッドの記述はできたのですが、htmlやJavaScriptの理解が難しく、うまくページに反映できず困っています。\n\nhtmlでファイルの読み込みを行った際、onchangeでメソッドを実行したいのですが、\n\n * そのままRubyのメソッドを呼び出したい\n * ページ遷移をしないまま実行したい\n\nと考えています。\n\n```\n\n <script type=\"text/javascript\">\n function analyze(file){\n 〜\n }\n </script>\n \n <input type=\"file\" id=\"file\" accept=\".html\" onchange=\"analyze(file)\">\n \n```\n\nのようなコードにおいて、「〜」部でRubyのメソッド(例:sample(file))を呼び出すためにはどうしたら良いでしょうか。\n\n(追記) \nform_withを用いてメソッドに渡す方法ではできたのですが、そうするとファイルの選択フォームが「ファイル未選択」状態になってしまうので困っています。(ファイル名を表示しておきたいため) \nJavaScriptに不慣れなことと、Rubyでのコードは完成しているため、それを活用して実行したいと考えています。\n\n○実行したいこと\n\n * htmlのチャットログを受け取り、発話者を抜粋したものを表示\n * 重要な発話者のみにチェックをつけ、その発話者のチャットのみを残したファイルを返す\n\nひとまずファイルの内容を一旦DBに保存することでこれは実現したのですが、セキュリティ的なことも考え、叶うならデータベースに入れることなく再編集や行いたいため、onchangeで出来ないかと検討しています。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T09:17:16.523",
"favorite_count": 0,
"id": "86670",
"last_activity_date": "2022-03-05T02:03:00.800",
"last_edit_date": "2022-03-03T16:18:42.233",
"last_editor_user_id": "3060",
"owner_user_id": "51668",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"ruby",
"html"
],
"title": "scriptタグ内でRubyのメソッドを実行したい",
"view_count": 867
} | [
{
"body": "**単純に実行することはできません。**\n\nWebアプリの作成は初めてですか?もし、そうなら、最初に学ぶべき重要なことがあります。それは、サーバーサイドとクライアントサイドの隔絶です。\n\nWebアプリではサーバーサイドとクライアントサイドという二つの環境が織り成すハーモニーです。この二つ環境は、実行する場所(実際のコンピューター)も違えば実行される言語も違います(言語は選択肢によっては同じ場合もあります)。この二つを混ぜて実行されることは原則できません。Webアプリを作る場合は、常に、サーバーサイドとクライアントサイドを意識し、それぞれの環境での制限は何か、そしてどちらで実行されるのかを意識する必要があります。\n\nでは、Railsを例にしながら実際に説明していきます。\n\n`<script>`タグの中で実行されるコードはクライアントサイドのJavaScriptです。その中でサーバーサイドのRubyのコードを書くことはできません。Rubyのクラスやメソッドを書いても、JavaScriptはそんなものは知らないので実行出来ません。逆も同じです。Rubyのコード内でJavaScriptのコードを呼び出すことはできません。\n**これは言語が異なるからと言う理由では無く、サーバーサイド側の言語をJavaScriptにしても、クライアントサイド側の言語をOpal(Rubyと互換性が高いAltJS)にしても、互いにそれぞれのコードを書くことはできません。**\nまずは、この原則を覚えてください。\n\nそれぞれは別々という話でしたが、そこから、データのやり取りはどうするのか考える必要があります。大きく分けて三つあります。例として、`sample(file)`\nでファイルを解析した結果を`<pre>`タグ内に出すというかたちで、説明していきます。\n\n## POSTで投げて実行結果が含まれたHTMLを生成する\n\nRailsが生成するHTMLはERBで書いているかとも思います。この中ではRubyを実行出来ます。もっと正確に言うと、Rubyが実行された結果のHTMLをクライアントサイドに渡しているのです。ですので、Rubyで必要なことはERBの中で実行して、出力するためのファイルに入れてしまいましょう。\n\nformは同じページに対してPOSTするものです。コントローラーでは@fileにアップロードされたファイルが読み込まれるとします。\n\n```\n\n <%= form_with(id: 'logform', ...) do |form| %>\n ...\n <input type=\"file\" id=\"file\" accept=\".html\" onchange=\"document.logform.submit()\"\n value=\"<%= @file&.original_filename%>\">\n ...\n <% end %>\n ...\n <pre><%= @file && sample(@file) %></pre>\n \n```\n\nERBを上のような感じにします。valueにファイルの名前を入れておくことでファイル名もそのまま表示されるようになります。\n\n`<% ...\n%>`の部分はサーバーサイドで実行されると言うことを常に意識してください。実行され、得られたHTMLがクライアントサイドに渡った後、サーバーサイドはその内容を変更することはできません。しかし、再度読み込まれるのであれば、また実行する事ができますので、Rubyの実行結果を反映したHTMLを渡すことができるというわけです。\n\n## Ajaxを使用する\n\n最初の方法は昔ながらの方法でした。今ほどJavaScriptが協力では無かった時代は(JavaAppletやFlash等の遺物を付かない限り)一般的な方法でした。しかし、各ブラウザがXMLHtttpRequestを実装したところで、Porotype.jsやjQueryの出現でAjaxという技術が急速に広まり、いまや一般的になっています。\n\nAjaxを使うためと技術はいくつかあります。古くはXMLHtttpRequestでしたが、余り使い勝手が良い物ではなかったため、jQuer.ajaxが広く使われていました。IEというレガシーなブラウザーはサポートしないモダンブラウザーのみをターゲットにした現代的なプログラムであれば[Fetch\nAPI](https://developer.mozilla.org/ja/docs/Web/API/Fetch_API)がいいでしょう。\n\nAjaxでのやり方は選択肢も多いですし、一から説明するには余りにも長くなるのでここでは書きません。本格的にWebアプリを作るには今や必須の技術なので、別途学ぶことをお勧めします。\n\n## フレームワークのAjax機能を使って可能な限りシームレスにする\n\nAjaxは色々あると言いましたが、フレームワークにAjaxを使ってなるべくシームレスに実行環境を交互に行き交うようにする物があります。\n\nRailsにも簡単にできる機能があります。それはrails-ujs.jsを使用したremoteです。form_withで`remote:\nture`を設定していることで使用できるようになります。\n\n```\n\n <%= form_with(action: '/sample_file', remote: true, ...) do |form| %>\n ...\n <input type=\"file\" id=\"file\" accept=\".html\" onchange=\"document.logform.submit()\">\n ...\n <% end %>\n ...\n <pre id=\"logpre></pre>\n \n```\n\n最初の例と似ているように見えますが、inputのvalueやpreの中身をRubyのコードで入れておこうとはしていません。代わりにpreにはidが付いています。このリモートで、呼び出される側のsample.js.erbを次のようにします。\n\n```\n\n document.getElementById('logpre').textContent = \"<%= @file && sample(@file) %>\"\n \n```\n\nformでのPOSTはAjaxとしてページ遷移せずに行われます。それは、最終的に上のERBで出力した結果のJavaScriptが返されるので、それを実行するという仕組みです。詳しくは[Railsガイド](https://railsguides.jp/working_with_javascript_in_rails.html)を参考にしてください。\n\n* * *\n\nいずれの場合でも、ちょっとコピペしたら動作するという物ではありません。どんな方法を取るにしても、RailsガイドやRailsチュートリアル、その他の入門書を読んで、基礎知識を身につけた上で、自分が実現したいことに対するベストな方法を選んで実装する必要があります。がんばってください。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T02:03:00.800",
"id": "86691",
"last_activity_date": "2022-03-05T02:03:00.800",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7347",
"parent_id": "86670",
"post_type": "answer",
"score": 2
}
] | 86670 | 86691 | 86691 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "掲題の通りです。 \n開発中のandroidアプリについて、電源供給が少なくなった時の挙動を観察したいのですが、端末をusb経由でPCに接続すると、必然的に電源供給がなされてしまい、目的が達成できません。 \n(アプリの概要:長時間、外部センサーのデータを取得し続けるアプリです。)\n\nネット上で「データ転送専用usb」と称するものを検索したのですが(二つほど実際に購入しました)、実際に「データ転送」だけを実現できるケーブルが見つかっていません。\n\n何か良い方法がありますでしょうか? \n例えば \n・実行中の特定のアプリlogcatに出てくるような情報を、オフラインで取得できるような別アプリ \n・オフラインでAndroid studioとつないで、logcatとおんなじようなことを行う方法\n\n良い方法がありましたら教えていただけると助かります。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T13:53:55.110",
"favorite_count": 0,
"id": "86672",
"last_activity_date": "2022-03-03T16:47:04.010",
"last_edit_date": "2022-03-03T16:16:35.577",
"last_editor_user_id": "3060",
"owner_user_id": "51672",
"post_type": "question",
"score": 2,
"tags": [
"android",
"android-studio",
"usb",
"debugging"
],
"title": "電源供給をせずに、端末をPCに繋いでlogcatでデバッグする方法はありますか?",
"view_count": 156
} | [
{
"body": "調べたら \"\"pairing devices using Wifi\" というものがありました。\n\nというか、何度も見ていたはずなのですが見逃していました。この機能、素晴らしいです感激しました。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T15:34:06.673",
"id": "86674",
"last_activity_date": "2022-03-03T16:47:04.010",
"last_edit_date": "2022-03-03T16:47:04.010",
"last_editor_user_id": "3060",
"owner_user_id": "51672",
"parent_id": "86672",
"post_type": "answer",
"score": 2
}
] | 86672 | null | 86674 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "pytorchで学習したモデルの推論を行いたいです。 \nモデルは、入力は2つ、出力は1つです。 \nそのため、入力を2つ入れて推論を行おうとしましたが、うまく動きません。 \nどうすればうまく動かせるのですか?\n\n```\n\n x_1 = np.arange(0.49, 1+2*10**-3, 2*10**-3) \n x_2 = [0.8 for i in range(len(x_1))]\n \n \n x_test1 = torch.from_numpy(x_1.astype(np.float32)).float().to(device) # xをテンソルに変換\n x_test2 = torch.from_numpy(np.array(x_2).astype(np.float32)).float().to(device) # xをテンソルに変換\n \n X_test = torch.stack([x_test1, x_test2], 1).to(device)\n \n net.eval()\n a = []\n for i in enumerate(X_test):\n outputs = net(i)\n a.append(outputs)\n \n```\n\nエラー\n\n```\n\n TypeError Traceback (most recent call last)\n <ipython-input-69-78f9e90abbc3> in <module>()\n 9 \n 10 for i in enumerate(X_test):\n ---> 11 outputs = net(i)\n 12 a.append(outputs)\n 13 \n \n 4 frames\n /usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in linear(input, weight, bias)\n 1846 if has_torch_function_variadic(input, weight, bias):\n 1847 return handle_torch_function(linear, (input, weight, bias), input, weight, bias=bias)\n -> 1848 return torch._C._nn.linear(input, weight, bias)\n 1849 \n 1850 \n \n TypeError: linear(): argument 'input' (position 1) must be Tensor, not tuple\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T14:18:42.820",
"favorite_count": 0,
"id": "86673",
"last_activity_date": "2023-06-29T13:04:50.670",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "42741",
"post_type": "question",
"score": 0,
"tags": [
"python",
"機械学習",
"pytorch"
],
"title": "TypeError: linear(): argument 'input' (position 1) must be Tensor, not tupleをうまく解消できない",
"view_count": 1373
} | [
{
"body": "forループにおける[enumerate関数の説明](https://docs.python.org/ja/3/library/functions.html#enumerate)では \nインデックスとオブジェクトのtupleを返すようになっています。\n\nおそらくnet関数の引数はTensorである必要があると思うので、 \n単にTensorが欲しいのであればX_TestがTensorを要素に持つリストであることを前提に以下のように書き換えてみてはいかがでしょうか。\n\n```\n\n for x in X_test:\n outputs = net(x)\n a.append(outputs) \n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T23:35:06.013",
"id": "86677",
"last_activity_date": "2022-03-03T23:35:06.013",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51317",
"parent_id": "86673",
"post_type": "answer",
"score": 0
}
] | 86673 | null | 86677 |
{
"accepted_answer_id": "86760",
"answer_count": 1,
"body": "[teratailでも同様の質問をしています](https://teratail.com/questions/kuq2z8wkb4lutk)が、こちらでも質問させて頂きます。 \nよろしくお願い致します。\n\n# 質問\n\nGCPのCloudSQLでDBを構築しています。 \nDBにパブリックIPを付与して外部から接続することは出来るのですが、 \nレイテンシを高めたいのとセキュリティの観点から、プライベートIPで接続するように変更したいと考えています。 \nしかし、プライベートIPを付与してCloudSQLを構築しても接続が出来ず、何の設定が足りていないのか分からず詰まっています。 \n他に何か設定が必要なのでしょうか。ご教示いただけると幸いです。\n\n# 試したこと\n\n・パブリックIPのCloudSQLを構築(承認済みネットワークには0.0.0.0/0を追加済み)し外部から接続できることを確認 \n・同じ設定でプライベートIPでCloudSQLを構築 \n・プライベートIPでCloudSQLが立ち上がった事を確認(10.系のIPが付与されている事を確認) \n・同じVPC内のGCEからCloudSQLのプライベートIPにmysqlコマンドで接続しようとしたり、pingコマンドを飛ばしても応答無し。\n\n# 補足情報(FW/ツールのバージョンなど)\n\nMySQL 8.0 \nシングルゾーン",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T16:34:06.877",
"favorite_count": 0,
"id": "86675",
"last_activity_date": "2022-03-08T15:05:43.063",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "41817",
"post_type": "question",
"score": 0,
"tags": [
"mysql",
"sql",
"network",
"database",
"google-cloud"
],
"title": "CloudSQLへプライベートIPで接続したいが出来ない",
"view_count": 288
} | [
{
"body": "GCEとCloudSQLを0から再作成してみたところ繋がるようになりました!",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T15:05:43.063",
"id": "86760",
"last_activity_date": "2022-03-08T15:05:43.063",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "41817",
"parent_id": "86675",
"post_type": "answer",
"score": 0
}
] | 86675 | 86760 | 86760 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "### 実現したいこと\n\n【jQuery・ハンバーガーメニュー】 閉じるボタン(X)を、元のハンバーガーボタン(三本線)に戻したいです\n\n### 状況の説明\n\njQueryでハンバーガーメニューを実装しています。 \nスマホナビが開いている状況で、リンクをクリックすると、\n\n * スマホナビが閉じて\n * リンク先のセクションにスムーススクロールされます\n\nここまでは良いのですが、閉じるボタン(X)が、元のハンバーガーボタン(三本線)に戻らない問題を解決できません。\n\nアドバイス頂けましたら幸いです。よろしくお願いいたします。\n\n```\n\n //◆ハンバーガーメニュー◆\n $('.js-hamburger').on('click',function() {\n if ($('.js-hamburger').hasClass('is-open')) {\n $('.js-drawer-menu').fadeOut();\n $(this).removeClass('is-open');\n } else {\n $('.js-drawer-menu').fadeIn();\n $(this).addClass('is-open');\n }\n });\n \n //spナビのリンクをクリックしたら\n $('.sp-nav__item').on('click',function() {\n $('.js-drawer-menu').fadeOut();\n $('js-hamburger').removeClass('is-open');\n });\n \n```\n\n```\n\n <header class=\"header\">\n <div class=\"header__inner\">\n <h1 class=\"header__logo\">\n <a href=\"index.html\" class=\"logo\">\n <img src=\"images/CodeUps.png\" alt=\"ロゴ画像\">\n </a>\n </h1>\n \n <!-- ハンバーガーボタン -->\n <button class=\"header__hamburger hamburger js-hamburger\">\n <span></span>\n <span></span>\n <span></span>\n </button>\n \n <!-- SPナビ -->\n <div class=\"header__sp-nav js-drawer-menu\">\n <ul class=\"sp-nav__items\">\n <li class=\"sp-nav__item\"><a href=\"index.html\">トップ</a></li>\n <li class=\"sp-nav__item\"><a href=\"#news\">お知らせ</a></li>\n <li class=\"sp-nav__item\"><a href=\"#content\">業務内容</a></li>\n <li class=\"sp-nav__item\"><a href=\"#works\">品質</a></li>\n <li class=\"sp-nav__item\"><a href=\"#overview\">制作者の想い</a></li>\n <li class=\"sp-nav__item\"><a href=\"#blog\">ブログ</a></li>\n <li class=\"sp-nav__item\"><a href=\"#contact\">お問い合わせ</a></li>\n </ul>\n </div>\n \n <!-- PCナビ -->\n <div class=\"header__pc-nav\">\n <ul class=\"pc-nav__items\">\n <li class=\"pc-nav__item\"><a href=\"#news\">お知らせ</a></li>\n <li class=\"pc-nav__item\"><a href=\"#content\">業務内容</a></li>\n <li class=\"pc-nav__item\"><a href=\"#works\">品質</a></li>\n <li class=\"pc-nav__item\"><a href=\"#overview\">制作者の想い</a></li>\n <li class=\"pc-nav__item\"><a href=\"#blog\">ブログ</a></li>\n <li class=\"pc-nav__item pc-nav__item--white\"><a href=\"#contact\">お問い合わせ</a></li>\n </ul>\n </div>\n \n </div><!-- /.header__inner -->\n </header>\n \n```\n\n```\n\n .hamburger {\n z-index: 9999;\n @include mq(md) {\n display: none;\n }\n }\n .hamburger span {\n position: relative;\n display: block;\n height: rem(2);\n width: rem(22);\n background: #fff;\n transition: ease .3s;\n }\n .hamburger span:nth-child(1) {\n top: 0;\n }\n .hamburger span:nth-child(2) {\n margin: 4px 0;\n }\n .hamburger span:nth-child(3) {\n top: 0;\n }\n //ハンバーガーメニューを開いたときにXボタンを表示\n .hamburger.is-open span:nth-child(1) {\n top: 5px;\n transform: rotate(45deg);\n }\n .hamburger.is-open span:nth-child(2) {\n transform: translateY(-50%);\n opacity: 0;\n }\n .hamburger.is-open span:nth-child(3) {\n top: -7px;\n transform: rotate(-45deg);\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-03T23:16:22.493",
"favorite_count": 0,
"id": "86676",
"last_activity_date": "2022-03-06T00:06:25.417",
"last_edit_date": "2022-03-04T00:19:18.053",
"last_editor_user_id": "3060",
"owner_user_id": "51677",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"jquery"
],
"title": "閉じるボタン(X)が、元のハンバーガーボタン(三本線)戻らない問題を解決したい",
"view_count": 509
} | [
{
"body": "```\n\n //spナビのリンクをクリックしたら\n $('.sp-nav__item').on('click',function() {\n $('.js-drawer-menu').fadeOut();\n $('js-hamburger').removeClass('is-open');\n });\n \n```\n\nドット抜けが原因でした!",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-06T00:06:25.417",
"id": "86708",
"last_activity_date": "2022-03-06T00:06:25.417",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51677",
"parent_id": "86676",
"post_type": "answer",
"score": 0
}
] | 86676 | null | 86708 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "sqlalchemy を使用\n\n親テーブル \nid name \n1 スズキ \n2 タナカ \n3 マイク \n4 ルイ \n5 ジャック\n\n子テーブル \nid user_id pname number \n1 1 リンゴ 2 \n2 1 バナナ 1 \n3 1 ブドウ 3 \n4 2 リンゴ 2 \n5 2 バナナ 2 \n6 2 ブドウ 1 \n7 3 イチゴ 5 \n8 3 バナナ 3 \n9 3 ブドウ 1\n\nリンゴを持っている親id且バナナのnumberで並べ替えしたいのですが、「リンゴを持っている親id」で検索するとフィルターされるのでバナナが消えてしまいます。実現方法を検索しても出てこきません。 \n宜しくお願い致します。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T02:28:35.877",
"favorite_count": 0,
"id": "86679",
"last_activity_date": "2022-03-04T02:28:35.877",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "48449",
"post_type": "question",
"score": 0,
"tags": [
"python",
"flask",
"sqlalchemy"
],
"title": "1対多結合で多を絞り込み条件とするSQLについて",
"view_count": 91
} | [] | 86679 | null | null |
{
"accepted_answer_id": "86682",
"answer_count": 1,
"body": "Excelで作成された請求書データ\"請求書フォーム_○○_FY21.xlsx\"(同book内にシートが複数)から一覧を作成したいと思い、まず1つの請求書データをVBAで取得したかったのですが、変数が定義されていません、とエラーになってしまいまいます。 \nどのようにすれば解決できますでしょうか。(参照先の\"請求書フォーム_○○_FY21.xlsx\"を何か変える必要はあるのでしょうか)\n\n```\n\n Dim ws As Worksheet\n Set ws = Workbooks(\"請求書フォーム_○○_FY21.xlsx\").Worksheets(1)\n \n \n wsData.Cells(2, 2).Value = ws.Range(\"H3\").Value '2 請求月\n wsData.Cells(2, 3).Value = ws.Range(\"H4\").Value '3 請求書番号\n wsData.Cells(2, 4).Value = ws.Range(\"B8\").Value '4 会社名\n wsData.Cells(2, 5).Value = ws.Range(\"C13\").Value '5 支払期限\n wsData.Cells(2, 6).Value = ws.Cells(18, 8).Value '6 金額\n wsData.Cells(2, 7).Value = ws.Cells(18, 9).Value '7 消費税\n wsData.Cells(2, 8).Value = ws.Range(\"A20\").Value '8 プロジェクト番号\n wsData.Cells(2, 9).Value = ws.Range(\"A18\").Value '9 内容\n \n \n End Sub\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T08:35:18.403",
"favorite_count": 0,
"id": "86680",
"last_activity_date": "2022-05-10T08:06:42.490",
"last_edit_date": "2022-03-04T09:05:49.947",
"last_editor_user_id": "3060",
"owner_user_id": "51683",
"post_type": "question",
"score": 0,
"tags": [
"vba"
],
"title": "VBA 実行時のエラー コンパイルエラー(変数が定義されていません)の解決方法",
"view_count": 490
} | [
{
"body": "`wsData`変数が宣言されていないのが原因ではないでしょうか。 \n手元の環境で下記のように書き換えたところ正常に実行できました。\n\n```\n\n Sub ボタン1_Click()\n Dim ws As Worksheet\n Set ws = Workbooks(\"test_list.xlsx\").Worksheets(1)\n \n Dim wsData As Worksheet\n Set wsData = ActiveSheet\n \n wsData.Cells(2, 2).Value = ws.Range(\"H3\").Value '2 請求月\n '(以下略)\n End Sub\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T09:10:13.293",
"id": "86682",
"last_activity_date": "2022-03-04T09:10:13.293",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9820",
"parent_id": "86680",
"post_type": "answer",
"score": 2
}
] | 86680 | 86682 | 86682 |
{
"accepted_answer_id": "86688",
"answer_count": 1,
"body": "Next.js + Tailwind + MathJax で数式を表示できるウェブサイトを作成しています。MathJax\nによる数式表示は問題なく行えるのですが、その延長線上で XyJax を利用して図式を描こうとすると文字と線の位置がずれてしまいます。tailwind.css\nの読み込みをやめれば正しく表示されるのですが、CSS\nを読み込むだけで副作用が起きる原因が分からず質問させていただきました。問題を再現できる最小限のコードを添付しています。Tailwind\nの使用を止めるのは最終手段にしたいと考えています。原因や解決策が分かる方がいればお願いいたします。\n\n```\n\n <body>\n \\begin{xy}\n \\xymatrix{G \\ar[d]_\\pi \\ar[r]^\\phi & H \\\\G/\\operatorname{Ker}\\,\\phi \\ar@{.>}[ur]_\\psi}\n \\end{xy}\n \n <script>\n MathJax = {\n loader: {load: ['[custom]/xypic.js'],\n paths: {custom:'https://cdn.jsdelivr.net/gh/sonoisa/[email protected]/build/'}},\n tex: {\n packages: { '[+]': ['xypic'] }\n }\n };\n </script>\n <script id=\"MathJax-script\"\n src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-chtml.min.js?config=TeX-AMS_HTML\">\n </script>\n <script src=\"https://cdn.tailwindcss.com\"></script> <!--この行を消すと正しく表示される-->\n </body>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T08:48:35.987",
"favorite_count": 0,
"id": "86681",
"last_activity_date": "2022-03-04T13:37:50.360",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51682",
"post_type": "question",
"score": 2,
"tags": [
"mathjax",
"tailwindcss"
],
"title": "tailwind.css を読み込むと XyJax の表示が崩れる",
"view_count": 109
} | [
{
"body": "Tailwind CSS はベーススタイルの中で、置換要素の `display` プロパティおよび `vertical-align`\nプロパティの値を、それぞれ `block` と `middle` に変更しています。この変更点が動的に生成された `svg`\n要素に影響し、文字のずれを生じさせています。このため、これらの値を初期値に戻すことで、問題の現象は解決します。\n\n```\n\n svg {\n display: inline !important;\n vertical-align: baseline !important;\n }\n```\n\n```\n\n <body>\n \\begin{xy}\n \\xymatrix{G \\ar[d]_\\pi \\ar[r]^\\phi & H \\\\G/\\operatorname{Ker}\\,\\phi \\ar@{.>}[ur]_\\psi}\n \\end{xy}\n \n <script>\n MathJax = {\n loader: {load: ['[custom]/xypic.js'],\n paths: {custom:'https://cdn.jsdelivr.net/gh/sonoisa/[email protected]/build/'}},\n tex: {\n packages: { '[+]': ['xypic'] }\n }\n };\n </script>\n <script id=\"MathJax-script\"\n src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-chtml.min.js?config=TeX-AMS_HTML\">\n </script>\n <script src=\"https://cdn.tailwindcss.com\"></script> <!--この行を消すと正しく表示される-->\n </body>\n```\n\n* * *\n\n蛇足ですが、これらのベーススタイルは以下のような理由から加えられました[[1]](https://tailwindcss.com/docs/preflight#images-\nare-block-level)。\n\n 1. `display: block`:ほとんどの置換要素はブロックレベルのほうが都合がよいため。たとえば、`img` 要素は行の中で使うことはほとんどないため、基本的にブロックレベルとして扱えるほうが理にかなっている。さらにブロックレベルでは、インラインレベルで生じる予期しない配置を防ぐことができる。`img` 要素を例にすると、インラインレベルではベースラインによる余白が生じるが、ブロックレベルであれば生じない。\n 2. `vertical-align: middle`:置換要素がインラインレベルに変更された場合でも、より好ましいと期待される配置にするため。前述のベースラインによる余白もこのスタイルによって生じなくなる。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T13:37:50.360",
"id": "86688",
"last_activity_date": "2022-03-04T13:37:50.360",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "32986",
"parent_id": "86681",
"post_type": "answer",
"score": 2
}
] | 86681 | 86688 | 86688 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "現在phpの学習のためにwebアプリケーション 『ブログ』を作っています。 \n二つほど質問させていただきたいと思います。\n\n質問の一つ目はエラーメッセージ判定、表示です。 \n投稿ボタンを押したときに \nタイトル のinput(title) \ntextarea(ここではmessageする) \n空で合った場合にエラーを表示させたいと思っています。 \nですが遷移先が同じページにしたいのでPOSTで送信された値が消えてしまう? \nそのためセッションでの判定である必要があると考えています。 \n該当しているコードはこちらになります \nなお初心者のためわからないことが多く \nエラー処理の記述の部分では正常に機能していないですが \nこういった感じで処理すれば良いのかなと思ったものを記述しているだけです。\n\n```\n\n if(isset($_SESSION['save'])){\n if($_SESSION['title'] == \"\") {\n $error['title'] = 'blank';\n }\n if($_SESSION['message'] == \"\") {\n $error['message'] = 'blank';\n }\n if(empty($error)){\n $_SESSION['save'] = $_POST;\n unset($_SESSION['save']);\n header('Location: ../blog5_file/blog5.php');\n exit();\n } \n }\n \n if(!empty($_POST)){\n if(isset($_POST['token']) && $_POST['token'] === $_SESSION['token']) {\n $message = $db->prepare('INSERT INTO blog_information SET created_by=?,title=?, message=?, created=NOW()');\n $message->execute(array($member['id'],$_POST['title'], $_POST['message']));\n $_SESSION['save'] = $_POST;\n header('Location:../blog5_file/confirm.php');\n exit();\n }else {\n header('Location:../blog4_file/blog4.php');\n exit();\n }\n }\n \n```\n\n質問の二つ目は、画像の「投稿」の下の部分が投稿されたブログの詳細ページに飛ぶためのページを表示しています。 \nこちら a タグで囲んでいるのですが、クリックするとdbに保存されているブログをmessage_idで判別し表示するように処理したいと考えております。 \nメインのページからの遷移先(ブログの詳細ページ)では\n\n```\n\n $posts=$db->query('SELECT p.title, p.message_id, p.message *FROM blog_information p WHERE p.message_id=$_GET[\"action\"]');\n \n```\n\ndbのblog_informationからそのブログのタイトル、メッセージID(ブログごとに振り与えられているID)、メッセージを引き出してくるようにし下記のように処理し投稿されたブログを見れるようにしたいと思っております。\n\n```\n\n <!-- <div class=\"content\">\n <p>タイトル\n <span class=\"content_title\"><?php echo htmlspecialchars($post['title'], ENT_QUOTES);?></span>\n </p><br />\n <p>メッセージ\n <span class=\"content_message\"><?php echo htmlspecialchars($post['message'], ENT_QUOTES);?></span>\n </p><br />\n <?php if($_SESSION['id'] == $post['created_by']): ?>\n <a href=\"../delete.php?id=<?php echo htmlspecialchars($post['message_id'], ENT_QUOTES); ?>\">削除</a>]<?php endif; ?></span></p>\n </div> -->\n \n $posts=$db->query('SELECT p.title, p.message_id, p.message *FROM blog_information p WHERE p.message_id=$_GET[\"action\"]');\n \n```\n\n質問の本題なのですが上記の部分なのですがdbのメッセージIDとブログ詳細ページを開くときに送られる `a\naction=$post['message_id']` が同じであるデータを持ってくるようにしたいです。 \n記述考え方として合っているか教えていただきたいと思います。\n\n初心者であるため、理解できていない部分が多くあるのですが \nアドバイスや、回答をご教授いただけたら幸いです。\n\n[](https://i.stack.imgur.com/uQou8.png)",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T10:28:42.540",
"favorite_count": 0,
"id": "86683",
"last_activity_date": "2022-03-04T11:34:27.783",
"last_edit_date": "2022-03-04T11:34:27.783",
"last_editor_user_id": "3060",
"owner_user_id": "51665",
"post_type": "question",
"score": 0,
"tags": [
"php",
"mysql"
],
"title": "SESSIONでエラーを判定し エラーがなければdbに保存 エラーがあれば処理を中止させたい etc",
"view_count": 205
} | [] | 86683 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "rails new を実行した際に、下記のエラーが表示されます\n\n```\n\n rails aborted!\n TZInfo::DataSourceNotFound: tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install\n C:/Users/usera/envrionment/sample_app/config/environment.rb:5:in `<main>'\n \n Caused by:\n TZInfo::DataSources::ZoneinfoDirectoryNotFound: None of the paths included in TZInfo::DataSources::ZoneinfoDataSource.search_path are valid zoneinfo directories.\n C:/Users/usera/envrionment/sample_app/config/environment.rb:5:in `<main>'\n Tasks: TOP => app:template => environment\n (See full trace by running task with --trace)\n rails turbo:install stimulus:install\n You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.\n You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.\n \n```\n\nGemfileに'gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw,\n:jruby]'を加えて、bundle installを実行したのですが、rails\nserverを実行した際に、下記のエラーが表示され原因が何なのかわかりません。\n\n```\n\n => Booting Puma\n => Rails 7.0.2.2 application starting in development\n => Run `bin/rails server --help` for more startup options\n Exiting\n C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:159:in `rescue in create_default_data_source': tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install (TZInfo::DataSourceNotFound)\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:156:in `create_default_data_source'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:55:in `block in get'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:54:in `synchronize'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:54:in `get'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.2/lib/active_support/railtie.rb:88:in `block in <class:Railtie>'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:32:in `instance_exec'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:32:in `run'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `each'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `call'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:60:in `run_initializers'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/application.rb:372:in `initialize!'\n from C:/Users/kazuk/envrionment/sample_app/config/environment.rb:5:in `<main>'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:42:in `require_relative'\n from config.ru:3:in `block in <main>'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:36:in `start'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:143:in `block in perform'\n from <internal:kernel>:90:in `tap'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:134:in `perform'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/command/base.rb:87:in `perform'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/command.rb:48:in `invoke'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands.rb:18:in `<main>'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n from bin/rails:4:in `<main>'\n C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_sources/zoneinfo_data_source.rb:232:in `initialize': None of the paths included in TZInfo::DataSources::ZoneinfoDataSource.search_path are valid zoneinfo directories. (TZInfo::DataSources::ZoneinfoDirectoryNotFound)\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:157:in `new'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:157:in `create_default_data_source'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:55:in `block in get'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:54:in `synchronize'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tzinfo-2.0.4/lib/tzinfo/data_source.rb:54:in `get'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/activesupport-7.0.2.2/lib/active_support/railtie.rb:88:in `block in <class:Railtie>'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:32:in `instance_exec'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:32:in `run'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `each'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `call'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'\n from C:/Ruby31-x64/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/initializable.rb:60:in `run_initializers'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/application.rb:372:in `initialize!'\n from C:/Users/kazuk/envrionment/sample_app/config/environment.rb:5:in `<main>'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:42:in `require_relative'\n from config.ru:3:in `block in <main>'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `eval'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:116:in `new_from_string'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:105:in `load_file'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/builder.rb:66:in `parse_file'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:349:in `build_app_and_options_from_config'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:249:in `app'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rack-2.2.3/lib/rack/server.rb:422:in `wrapped_app'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:36:in `start'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:143:in `block in perform'\n from <internal:kernel>:90:in `tap'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands/server/server_command.rb:134:in `perform'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/command/base.rb:87:in `perform'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/command.rb:48:in `invoke'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/railties-7.0.2.2/lib/rails/commands.rb:18:in `<main>'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n from C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/bootsnap-1.10.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n from bin/rails:4:in `<main>'\n \n```\n\nもし何かご存じであれば教えていただけないでしょうか?",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T10:37:45.427",
"favorite_count": 0,
"id": "86685",
"last_activity_date": "2023-02-23T12:07:01.050",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51687",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"ruby",
"gemfile"
],
"title": "rails new を実行した際に、rails aborted !というエラーが出て解決できません。",
"view_count": 2777
} | [
{
"body": "[Ruby Instnaller](https://rubyinstaller.org/)の64bit最新版 3.1.1-1 (x64)\nを使用しているという前提でお話しします。もし、違っている場合は、この回答は無視してください。\n\n* * *\n\nRuby\nInstallerはMSYS2の開発環境を用いてRubyをビルドします。以前は、MSYS2にmingw32とmingw64の二つの開発環境しか用意されていませんでしたが、現在はclang32、clang64、ucrt64の三つの開発環境が追加されました。clangはMingw-w64\nGCCの代わりにClangを用いる物ですが、ucrt64はmingw32やmingw64と同じくMingw-w64\nGCCを用います。そのような経緯もあって、Ruby\nIstallerの64bit版は、3.0系まではmingw64でしたが、3.1系からはucrt64に変更になりました。`ruby\n-v`と実行してプラットフォームがx64-mingw-ucrtになっている事が確認できるかと思います。\n\n問題はこのucrt64版(x64-mingw-\nucrt)です。Bundlerは`platform`でmingwやmswin等を指定できます。しかし、この機能はucrt64には対応していません。x64_mingwと指定しても、これはmingw64版の指定であって、同じくMingw-w64\nGCCを用いていると言っても、ucrt64版は対象では無いと判断されます。現在の所、Bundlerにucrt64版を指定する`platform`に渡すオプションは存在しません。\n\nここでRalisに関わる問題が発生します。Railsはタイムゾーン情報を時刻を扱うためにtzinfoというgemを使います。このtzinfoをWindowsで使用する場合、Linuxとは違ってOSにタイムゾーンの情報のファイルが存在しないため、tzinfo-\ndataという別のgemが必要になります。そのため、Railsで生成されるGemfileでは、`platform`でWindows環境になるプラットフォームを指定してtzinfo-\ndataが使用するようにしています。しかし、この`platform`の指定ではucrt64版は対象とはならないため、tzinfo-\ndataが読み込まれず、railsの実行に失敗する状況になっていました。\n\n根本的に修正されるにはBundler側がucrt64版に対応することとRails側がucrt64版でもtzinfo-\ndataを対象とするように初期のGemfileを用意するようにすることの二つが必要です。どちらにもissuesにすらあがっていないようですので、対応にはしばらくかかると思われます。\n\n* * *\n\nBundler側とRalis側で対応されるまでは時間がかかりますので、それ以外の解決方法を三つほど紹介します。\n\n### Gemfileでtzinfo-dataを読み込むようにする。\n\nucrt64版であっても、Gemfileでtzinfo-\ndataを読む込むようにすれば良いとなります。まずは、下記のようなtemplate.rbを用意します。\n\n```\n\n data = File.read('Gemfile')\n data.sub!(/^.*gem \"tzinfo-data\".*$/, 'install_if(-> { RUBY_PLATFORM =~ /mingw|mswin|java/ }) { gem \"tzinfo-data\" }')\n File.write('Gemfile', data)\n \n```\n\nそして`rais new アプリ名 -m template.rb`として作成すれば、エラー無く完了できるはずです。\n\nどうしてこれでうまくいくかは、エラーになるときとのGemfileと比べてみることでわかるはずです。\n\n### ucrt64版以外のRubyを使う。\n\n例えば、32bit版はmingw32であるためこの問題は起きません。また、MSYS2でもRubyのパッケージが存在し、mingw64版Rubyを使うという方法もあるでしょう。\n\n### 3.0系のRubyを使う。\n\n3.0系まではmingw64版ですので、問題は起きません。\n\n### Linux環境にする。\n\nLinux環境であればtzinfo-dataそのものが不要になり、問題になることはありません。Windowsの環境であればWSLを用いたり、Hyper-\nVやVirtualBox等の仮想環境でLinuxを用意すると良いでしょう。\n\n他にも、Ruby\n3.0系を使うという方法もあります。どうしても3.1系を使いたく、そして、なるべくこのようなエラーになるべく出くわしたくないという場合は、WSL上でアプリケーションを作成・開発すると良いでしょう。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-06T08:57:53.823",
"id": "86716",
"last_activity_date": "2022-03-06T11:48:21.470",
"last_edit_date": "2022-03-06T11:48:21.470",
"last_editor_user_id": "7347",
"owner_user_id": "7347",
"parent_id": "86685",
"post_type": "answer",
"score": 0
}
] | 86685 | null | 86716 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "画像のように `height: auto;` がすべての範囲に届きません。 \n今はタブレット用のデザインを作成しています。\n\n下記コードになります。\n\n```\n\n <section class=\"section-article\">\n <div class=\"article\">\n <div class=\"article-container\">\n <div class=\"article-wrapper\">\n <div>\n <h2 class=\"article-title\">TOEFL対策に特化した<br class=\"paragraph-eleventh\">Engress3つの強み</h2>\n </div>\n <div class=\"article-content\">\n <div class=\"article-inner-second article-inner\">\n <div class=\"article-area-fourth article-area-fourth-second\">\n <div class=\"article-section\">\n <p class=\"article-item\">特徴1</p></div>\n <div class=\"article-item-second\">\n <p class=\"article-area-txt\">TOEFLに最適化された<br>無駄のないカリキュラム</p>\n </div>\n <div class=\"article-item-third\">\n <p class=\"article-area-fifth\">\n TOEFLではビジネス英語には登場しない数多くの学術<br class=\"paragraph-fourth\">的内容が出題さ<br class=\"paragraph-fifth\">れます。そのため、ベースとなる知識<br class=\"paragraph-sixth\">も必要になります。Engressでは過去1000題を<br class=\"paragraph-seventh\">分析し、最適なカリキュラムを組んでいます。\n </p>\n </div>\n </div>\n <div class=\"article-group\">\n <img src=\"<?php echo get_template_directory_uri(); ?>/images/main_img_01.png\" class=\"main-logo\" alt=\"Engress\" /> \n </div>\n </div>\n <div class=\"article-inner-fourth article-inner\">\n <div class=\"article-group\">\n <img src=\"<?php echo get_template_directory_uri(); ?>/images/main_img_02.png\" class=\"main-logo\" alt=\"Engress\" />\n </div>\n <div class=\"article-area-fourth article-area-sixth\">\n <div class=\"article-section\">\n <p class=\"article-item\">特徴2</p>\n </div>\n <div class=\"article-item-second\">\n <p class=\"article-area-txt\">日本人指導歴10年以上の<br>経験豊富な講師陣</p>\n </div>\n <div class=\"article-item-third\">\n <p class=\"article-area-fifth\">\n Engressの講師陣は、もともと日本人向けにTOEFL<br class=\"paragraph-fourth\">を教えていた人が大多数です。また全メンバーが<br class=\"paragraph-sixth\">TOSOL(英語教授法)を取得しており、知識と経験を<br class=\"paragraph-seventh\">兼ね備えている教育のプロフェッショナルです。<br>\n </p> \n </div> \n </div>\n </div>\n <div class=\"article-inner-second article-inner\">\n <div class=\"article-area-fourth article-area-fourth-second\">\n <div class=\"article-section\">\n <p class=\"article-item\">特徴3</p>\n </div>\n <div class=\"article-item-second\">\n <p class=\"article-area-txt\">平均3ヶ月でTOEFLiBT20点<br class=\"paragraph-eighth\">アップ</p>\n </div>\n <div class=\"article-item-third\">\n <p class=\"article-area-fifth\">\n Engressは高校生からサラリーマンまで様々な年齢層<br class=\"paragraph-fourth\">の方々が通われていますが、完全オーダーメイドの<br class=\"paragraph-sixth\">カリキュラムで柔軟に対応しているため、平均3ヶ月で<br class=\"paragraph-seventh\">TOEFLスコアを20点アップさせています。\n </p>\n </div>\n </div>\n <div class=\"article-group \">\n <img src=\"<?php echo get_template_directory_uri(); ?>/images/main_img_03.png\" class=\"main-logo\" alt=\"Engress\" /> \n </div>\n </div>\n </div>\n </div>\n </div>\n <div class=\"article-caption\">\n <div class=\"article-caption-container\"> \n <div class=\"article-caption-title\">\n <h3 class=\"article-caption-nav\">Engressの料金プランはこちら</h3>\n </div>\n <div class=\"article-caption-inner\">\n <a class=\"article-caption-area\" href=\"#\" style=\"text-decoration: none;\">\n <p>料金を見てみる</p>\n </a>\n </div>\n </div>\n </div>\n </section>\n <section class=\"section-list-wrapper\">\n <div class=\"list-wrapper\">\n <div class=\"list-outer\">\n <h2 class=\"list-title\">TOEPL成功事例</h2>\n </div>\n <div class=\"list-outer-second\">\n <div class=\"list-content\">\n <div class=\"list-inner\">\n <div class=\"list-area\">\n <div class=\"list-area-title\">\n <p class=\"area-txt\">TOEFLiBT100点を突破してコロンビア大学大学院に進学できました!</p>\n </div>\n <div class=\"list-img\">\n <div class=\"person-img\">\n <?php if (get_field('participant-photo', 2)) : ?>\n <img class=\"test-image\" src=\"<?php the_field('participant-photo', 2); ?>\" />\n <?php endif; ?>\n </div>\n </div>\n <div class=\"list-area-txt\">\n <div class=\"txt-item\">\n <div class=\"txt-item-area-fourth\"><?php the_field('participant1', '2'); ?></div>\n </div>\n </div>\n </div>\n </div>\n <sectin/>\n \n \n```\n\n```\n\n section.section-article {\n section.section-article {\n height: auto;\n }\n \n \n .article {\n height: auto;\n width: 100%;\n }\n .article .article-container {\n max-width: 880px;\n height: auto;\n margin: 0 auto;\n }\n \n .article .article-container .article-wrapper {\n max-width: 745px;\n padding: 59px 0px 70px 0px;\n margin: 0 auto;\n }\n \n h2.article-title {\n font-size: 30px;\n }\n .article .article-container .article-wrapper div .article-inner-second {\n display: flex;\n flex-direction: column-reverse;\n padding-bottom: 60px;\n height: auto;\n max-width: 700px;\n margin: 0 auto;\n }\n \n .article-area-fourth {\n margin: 0px 123px;\n }\n \n .article-section {\n padding-top: 30px;\n }\n \n p.article-item {\n height: 30px;\n width: 90px;\n background-color: #F5A623;\n text-align: center;\n color: #fff;\n font-size: 12px;\n line-height: 30px;\n }\n \n p.article-area-txt {\n font-size: 21px;\n color: #1B224C;\n font-weight: bold;\n line-height: 1.3;\n padding-top: 16px;\n padding-bottom: 7px;\n height: 66px;\n }\n .article-item-third {\n width: auto;\n }\n \n p.article-area-fifth {\n color: #1B224C;\n font-size: 16px;\n line-height: 1.187;\n height: auto;\n }\n \n .paragraph-fourth {\n display: none;\n }\n \n .paragraph-fifth {\n display: none;\n }\n .paragraph-sixth {\n display: none;\n }\n .paragraph-seventh {\n display: none;\n }\n .article-group {\n max-width: 460px;\n margin: 0px 123px;\n }\n \n img.main-logo {\n width: 100%;\n margin: 0 auto;\n }\n .article .article-container .article-wrapper div .article-inner-fourth {\n display: flex;\n flex-direction: column;\n padding-bottom: 60px;\n height: auto;\n max-width: 700px;\n margin: 0 auto;\n }\n \n .article-group {\n max-width: 460px;\n margin: 0px 123px;\n }\n \n img.main-logo {\n width: 100%;\n margin: 0 auto;\n }\n .article-section {\n padding-top: 30px;\n }\n \n \n \n .article-item-third {\n width: auto;\n }\n p.article-area-fifth {\n color: #1B224C;\n font-size: 16px;\n line-height: 1.187;\n height: auto;\n }\n \n .article .article-container .article-wrapper div .article-inner-second {\n display: flex;\n flex-direction: column-reverse;\n padding-bottom: 60px;\n height: auto;\n max-width: 700px;\n margin: 0 auto;\n }\n \n .article-area-fourth {\n margin: 0px 123px;\n }\n \n p.article-item {\n height: 30px;\n width: 90px;\n background-color: #F5A623;\n text-align: center;\n color: #fff;\n font-size: 12px;\n line-height: 30px;\n }\n \n p.article-area-txt {\n font-size: 21px;\n color: #1B224C;\n font-weight: bold;\n line-height: 1.3;\n padding-top: 16px;\n padding-bottom: 7px;\n height: 66px;\n }\n \n \n .article-item-third {\n width: auto;\n }\n \n p.article-area-fifth {\n color: #1B224C;\n font-size: 16px;\n line-height: 1.187;\n height: auto;\n }\n \n body section .article-caption {\n max-width: 712px;\n height: 217px;\n }\n .article-caption .article-caption-container {\n padding-top: 61px;\n text-align: center;\n }\n article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {\n display: block;\n }\n body .list-wrapper {\n height: 592px;\n background-color: #1B224C;\n border: 1px solid #707070;\n }\n .list-wrapper .list-outer {\n padding-top: 70px;\n margin-bottom: 110px;\n }\n body .list-wrapper .list-outer .list-title {\n font-size: 30px;\n }\n .list-wrapper .list-outer {\n text-align: center;\n height: 34px;\n line-height: 1.388;\n }\n .list-wrapper .list-outer-second {\n display: flex;\n justify-content: space-between;\n background-color: #1B224C;\n margin: 0 auto;\n height: 317px;\n max-width: 901px;\n }\n body .list-wrapper .list-outer-second {\n width: 668px;\n }\n \n```\n\n[](https://i.stack.imgur.com/CAc8w.png)",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T11:37:36.043",
"favorite_count": 0,
"id": "86686",
"last_activity_date": "2022-03-06T05:58:15.330",
"last_edit_date": "2022-03-04T12:03:42.690",
"last_editor_user_id": "49042",
"owner_user_id": "49042",
"post_type": "question",
"score": 0,
"tags": [
"html",
"css"
],
"title": "height: auto;で設定した範囲が、中途半端なところで途切れます。",
"view_count": 77
} | [
{
"body": "以下の設定が `height auto` で打ち消されていなかったのが原因でした。\n\n```\n\n .article {\n max-height: 1341px;\n width: 100%;\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-06T01:08:09.347",
"id": "86709",
"last_activity_date": "2022-03-06T05:58:15.330",
"last_edit_date": "2022-03-06T05:58:15.330",
"last_editor_user_id": "3060",
"owner_user_id": "49042",
"parent_id": "86686",
"post_type": "answer",
"score": 0
}
] | 86686 | null | 86709 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "PySide6を使用しています。\n\nQTreeWidgetで2階層のTreeを作りました。 \n子供のQTreeWidgetItemを移動する時、トップレベルのQTreeWidgetItemの直下にしか移動しないようにしたいです。\n\n子供から子供の配下に移動しないようにするのは出来たのですが、トップレベルへの移動(この例で言えば、Data0とData1の間)を識別する手段が見つかりませんでした。\n\nSuper\nclassを呼び出した後であれば、トップレベルに移動してしまった事を知ることが出来るのですが、その後で、event.setDropAction(Qt.IgnoreAction)を呼び出す方法では、移動を禁止出来ませんでした。\n\n何か良い手立てはありませんでしょうか。\n\n```\n\n from PySide6.QtWidgets import (QTreeWidget, QTreeWidgetItem, QAbstractItemView)\n \n \n class MyTreeWidget(QTreeWidget):\n def __init__(self, parent=None):\n super(MyTreeWidget, self).__init__(parent)\n self.setDragDropMode(QAbstractItemView.InternalMove)\n \n def dropEvent(self, event):\n source = event.source()\n pos = event.pos()\n destination_parent = source.itemAt(pos)\n \n if destination_parent is None:\n print(\"no parent\")\n return\n \n if destination_parent.parent() is not None:\n print(\"destination is not top.\")\n return\n \n print(\"move item\")\n super(MyTreeWidget, self).dropEvent(event)\n \n \n if __name__ == \"__main__\":\n from SetupQt import setup_qt\n from PySide6.QtWidgets import QApplication\n \n setup_qt() # for venv\n \n app = QApplication()\n widget = MyTreeWidget()\n \n top_level_items = []\n for i in range(3):\n item_p = QTreeWidgetItem()\n item_p.setText(0, \"Data{0}\".format(i))\n for j in range(2):\n item_c = QTreeWidgetItem(item_p)\n item_c.setText(0, \"Data{0}{1}\".format(i, j))\n top_level_items.append(item_p)\n \n widget.insertTopLevelItems(0, top_level_items)\n \n widget.show()\n app.exec()\n \n \n```\n\n使用環境は \nPySide6 6.2.2.1 \nPython 3.10 \nです。\n\nsetup_qt()は仮想環境にQtへのパスを通す為に作った関数です",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-04T23:47:36.603",
"favorite_count": 0,
"id": "86690",
"last_activity_date": "2022-03-05T10:26:51.733",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51694",
"post_type": "question",
"score": 0,
"tags": [
"python",
"pyside"
],
"title": "QTreeWidgetのDrag & Dropでトップレベルには移動しないようにしたい",
"view_count": 177
} | [
{
"body": "知り合いが解決してくれました。 \nトップレベルにDragする時には、Itemの間には置けなくて、 \n子供の階層の時には、Itemの間にしか置けないようにしています。\n\n```\n\n def dropEvent(self, event):\n source = event.source()\n pos = event.pos()\n destination_item = source.itemAt(pos)\n dip = self.dropIndicatorPosition()\n \n if destination_item.parent() is None and dip != QAbstractItemView.DropIndicatorPosition.OnItem:\n print(\"no parent\")\n return\n \n if destination_item.parent() is not None and dip == QAbstractItemView.DropIndicatorPosition.OnItem:\n print(\"destination is not top.\")\n return\n \n print(\"move item\")\n super(MyTreeWidget, self).dropEvent(event)\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T10:26:51.733",
"id": "86704",
"last_activity_date": "2022-03-05T10:26:51.733",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51694",
"parent_id": "86690",
"post_type": "answer",
"score": 0
}
] | 86690 | null | 86704 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "AngularのHttpclientModuleを使ってExpressからデータを取得して表示する処理を実装しています。 \nGETで受け取り値を表示する際に以下のエラーが出ます。 \nこのエラーを解消するにはどうすればいいでしょうか?\n\n```\n\n Property 'id' does not exist on type 'number | Comment | (() => string) | (() => string) | (() => Comment | undefined) | ((...items: Comment[]) => number) | { (...items: ConcatArray<Comment>[]): Comment[]; (...items: (Comment | ConcatArray<...>)[]): Comment[]; } | ... 27 more ... | (() => { ...; })'.\n Property 'id' does not exist on type 'number'.\n \n 9 <h4 class=\"media-heading\">{{ comment.value.id | json }}</h4>\n \n```\n\n**・該当のコード** \n型定義\n\n```\n\n export interface Comment{\n \n comments: [\n {\n id: number,\n message: string,\n }\n ]\n }\n \n```\n\n**comment.service.ts**\n\n```\n\n import { Injectable } from '@angular/core';\n import { HttpClient, HttpRequest, HttpErrorResponse } from '@angular/common/http';\n import { catchError } from \"rxjs/operators\";\n import { Observable } from 'rxjs';\n import { Comment } from '../models/comment';\n import { of } from \"rxjs\";\n \n @Injectable({\n providedIn: 'root'\n })\n export class CommentService {\n private base_url: string = 'http://localhost:3000'\n comments!: Comment\n \n constructor(private http: HttpClient) { }\n \n getComments(): Observable<Comment>{\n return this.http.get<Comment>(`${this.base_url}/comments`) // get通信\n .pipe(\n catchError(this.handleError<Comment>('getComments'))\n );\n }\n \n private handleError<T>(operation = 'operation', result?: T) {\n return (error: any): Observable<T> => {\n // TODO: リモート上のロギング基盤にエラーを送信する\n console.error(error); // かわりにconsoleに出力\n // 空の結果を返して、アプリを持続可能にする\n return of(result as T);\n };\n }\n \n \n }\n \n```\n\n・ **app.commponet.ts** \nngOnInit()内の返す値の型がおかしいのかなと予想します\n\n```\n\n import { Component, OnInit } from '@angular/core';\n import { Observable } from 'rxjs';\n import { ApiService, Item} from './service/api.service';\n import { Comment } from './models/comment';\n import { CommentService } from './service/comment.service'\n // import { Comment } from './class/comment'\n import { NgForm } from '@angular/forms';\n \n @Component({\n selector: 'ac-root',\n templateUrl: './app.component.html',\n styleUrls: ['./app.component.css']\n })\n export class AppComponent implements OnInit {\n title = 'web-app';\n \n comes!: Comment[]\n // public comments$!: Observable<Comment>\n form!: NgForm\n \n \n constructor(private api:ApiService, private comment: CommentService){}\n \n ngOnInit(): any{\n this.comment.getComments().subscribe((res: any) => {\n this.comes = res.comments\n console.log(this.comes)\n })\n \n }\n }\n \n```\n\n・ **app.component.html**\n\n```\n\n <div *ngFor=\"let comment of comes | keyvalue\">\n \n <div class=\"media\">\n <div class=\"media-body\">\n <div class=\"d-flex w-100 justify-content-between\">\n <h4 class=\"media-heading\">{{ comment.value.message | json }}</h4>\n <small class=\"media-date\">{{ comment | json}}</small>\n </div>\n </div>\n </div>\n \n```\n\ncomment | jsonの中身\n\n```\n\n { \"id\": 1, \"message\": \"おはようございます\", \"createdAt\": \"2022-02-17T23:47:57.011Z\", \"updatedAt\": \"2022-02-22T03:45:49.555Z\" }\n \n```\n\n・追記 \nエラー全文\n\n```\n\n Property 'message' does not exist on type 'KeyValue<string, number | Comment | (() => string) | (() => string) | (() => Comment | undefined) | ((...items: Comment[]) => number) | { (...items: ConcatArray<Comment>[]): Comment[]; (...items: (Comment | ConcatArray<...>)[]): Comment[]; } | ... 27 more ... | (() => { ...; })>'.\n \n```\n\ncomment | jsonの中身が`{ \"key\": \"0\", \"value\": { \"id\": 1, \"message\": \"おはようございます\",\n\"createdAt\": \"2022-03-06T10:01:29.781Z\", \"updatedAt\":\n\"2022-03-06T10:01:29.790Z\" } }` \nなので、{{comment.value.message}}で表示しようとすると以下のエラー\n\n```\n\n Property 'message' does not exist on type 'number | Comment | (() => string) | (() => string) | (() => Comment | undefined)\n \n```\n\n・修正箇所\n\n```\n\n export class CommentService {\n private base_url: string = 'http://localhost:3000'\n comments!: ResponseComment\n \n constructor(private http: HttpClient) { }\n \n getComments(): Observable<ResponseComment>{\n return this.http.get<ResponseComment>(`${this.base_url}/comments`)\n .pipe(\n catchError(this.handleError<ResponseComment>('getComments'))\n );\n }\n \n```\n\n・型定義\n\n```\n\n export interface Comment { \n id: number\n message: string\n createdAt: number\n user_id: number\n }\n \n export interface ResponseComment { \n comments: Array<Comment>\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T03:44:10.093",
"favorite_count": 0,
"id": "86693",
"last_activity_date": "2022-03-08T02:43:56.717",
"last_edit_date": "2022-03-07T23:07:40.267",
"last_editor_user_id": "39431",
"owner_user_id": "39431",
"post_type": "question",
"score": 0,
"tags": [
"angularjs"
],
"title": "AngularでProperty 'message' does not exist on type 'Observable<any>.というエラーが表示される",
"view_count": 162
} | [
{
"body": "`app.commponet.ts` の `comes` は `Comment[]`\nの型だと宣言しているので以下のようなCommentの配列を期待するようになっています\n\n```\n\n comes = [\n {\n comments: [\n {\n id: number,\n message: string,\n }\n ]\n },\n {\n comments: [\n {\n id: number,\n message: string,\n }\n ]\n }\n ]\n \n```\n\n実際は `{ id: number, message: string }`\n配列を期待されているようなのでAPIレスポンスとモデルでインターフェイスを分けたほうが良いでしょう\n\n```\n\n export interface Comment { \n id: number\n value: {\n message: string\n }\n }\n \n export interface ResponseComment { \n comments: Array<Comment>\n }\n \n```\n\nインターフェイス変更後、CommentServiceの型を変更します。(他にも細かい修正が発生するかもしれません)\n\n```\n\n // comment.service.ts\n export class CommentService {\n // 省略\n getComments(): Observable<ResponseComment>{\n return this.http.get<ResponseComment>(`${this.base_url}/comments`)\n .pipe(\n catchError(this.handleError<ResponseComment>('getComments'))\n );\n }\n // 省略\n }\n \n```\n\n```\n\n <div *ngFor=\"let comment of comes | keyvalue\">\n \n <div class=\"media\">\n <div class=\"media-body\">\n <div class=\"d-flex w-100 justify-content-between\">\n <h4 class=\"media-heading\">{{ comment.value.message }}</h4>\n <small class=\"media-date\">{{ comment | json}}</small>\n </div>\n </div>\n </div>\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T06:52:32.077",
"id": "86728",
"last_activity_date": "2022-03-08T02:43:56.717",
"last_edit_date": "2022-03-08T02:43:56.717",
"last_editor_user_id": "298",
"owner_user_id": "298",
"parent_id": "86693",
"post_type": "answer",
"score": 0
}
] | 86693 | null | 86728 |
{
"accepted_answer_id": "86707",
"answer_count": 1,
"body": "数独を解くプログラムを作成しています。 \n9x9のentryへ問題を入力して、inputボタンを押すことで、entryからデータを読み取って \noutoutボタンを押すことで解答を表示するプログラムです。 \n入力した問題のデータはinput_dataのdataにはきちんと保存されているようです(9x9のリスト形式)。 \nだた、そのデータが数独を解くための関数には引き渡せていません。 \nどうしたら、きちんと渡せますか?\n\n* * *\n\ndataの入力部分は下記ですが、dataにはほしいデータは入っているようですが\n\n```\n\n Button = tk.Button(root, text='Input', command = input_data)\n \n```\n\nを実行しても下記にはうまく渡せていません。\n\n```\n\n input_grid = input_data() \n solve_sudoku(input_grid)\n \n```\n\n* * *\n```\n\n def input_data(): \n list0 = []\n data = []\n a = 0\n b = 9\n \n for x in range(n*n):\n list0.extend([item[x].get()])\n \n for x in range(n):\n list1 = list0[a:b]\n data.append(list1)\n a = a + n\n b = b + n\n \n for y in range(n):\n for x in range(n):\n if data[y][x] == '':\n data[y][x] = '0'\n \n for y in range(n): #もともとは9\n for x in range(n): #もともとは9\n data[y][x]=int(data[y][x])\n \n print(data) #意図したデータにはなっている(確認用)。\n return data \n \n```\n\n* * *\n\n試しに強制的に、dataにデータを入れ込んでやると正しく\n\n```\n\n input_grid = input_data() \n solve_sudoku(input_grid)\n \n```\n\nでちゃんと計算できています。\n\n```\n\n def input_data(): \n list0 = []\n data = []\n a = 0\n b = 9\n \n for x in range(n*n):\n list0.extend([item[x].get()])\n \n for x in range(n):\n list1 = list0[a:b]\n data.append(list1)\n a = a + n\n b = b + n\n \n for y in range(n):\n for x in range(n):\n if data[y][x] == '':\n data[y][x] = '0'\n \n for y in range(n): #もともとは9\n for x in range(n): #もともとは9\n data[y][x]=int(data[y][x])\n data = [[0, 1, 8, 0, 0, 0, 3, 2, 0],\n [2, 5, 0, 0, 0, 0, 0, 4, 6],\n [0, 0, 4, 6, 5, 2, 1, 0, 0],\n [0, 0, 6, 0, 7, 0, 2, 0, 0],\n [0, 2, 0, 0, 4, 0, 0, 5, 0],\n [0, 0, 3, 1, 0, 8, 7, 0, 0],\n [0, 0, 2, 5, 3, 9, 4, 0, 0],\n [4, 9, 0, 0, 0, 0, 0, 8, 3],\n [0, 7, 0, 0, 0, 0, 0, 9, 0]]\n print(data) #意図したデータにはなっている。\n return data \n \n```\n\n以下はコード全体です。\n\n```\n\n import tkinter as tk\n \n root = tk.Tk()\n root.geometry('300x600')\n root.title('test')\n \n n = 9\n i = -1\n backtracks = 0\n input_grid = list()\n item = [0]*n*n\n \n for y in range(n): \n for x in range(n): \n i = i + 1\n item[i] = tk.StringVar()\n entry0 = tk.Entry(root, width = 2, textvariable = item[i], justify ='center', font =('',14))\n entry0.grid(row = y, column = x, padx = 2, pady = 2, ipady = 3, sticky=(tk.N, tk.S, tk.E, tk.W))\n \n root.columnconfigure(x, weight = 1)\n # root.rowconfigure(y, weight = 1)\n \n def input_data():#直接データを書き込むとちゃんと動く, dataをsudoku-finalへ入れると動く, dataの出力をを直接入力したら動く \n list0 = []\n data = []\n a = 0\n b = 9\n \n for x in range(n*n):\n list0.extend([item[x].get()])\n \n for x in range(n):\n list1 = list0[a:b]\n data.append(list1)\n a = a + n\n b = b + n\n \n for y in range(n):\n for x in range(n):\n if data[y][x] == '':\n data[y][x] = '0'\n \n for y in range(n): #もともとは9\n for x in range(n): #もともとは9\n data[y][x]=int(data[y][x])\n \n print(data) #意図したデータにはなっている。\n return data \n \n def find_next_cell(grid):\n for y in range(n): #もともとは9\n for x in range(n): #もともとは9\n if grid[y][x] == 0:\n # 0の座標を返す\n return y, x\n # すべてのマスに数字が入っている状態\n return -1, -1\n \n def is_valid(grid, y, x, value):\n # 行のチェック\n is_row = value not in grid[y]\n # 列のチェック\n is_column = value not in [i[x] for i in grid]\n # ブロックを取り出す\n blk_x, blk_y = (x//3)*3 , (y//3)*3\n blk_grid = [i[blk_x:blk_x + 3]for i in grid[blk_y:blk_y +3]]\n # ブロックのチェック\n is_block = value not in sum(blk_grid,[])\n # 有効チェック\n return all([is_row, is_column, is_block])\n \n def solve_sudoku(grid, y=0, x=0):\n global backtracks\n y, x = find_next_cell(grid)\n # 終了判定\n if y == -1 or x == -1:\n return True\n # 入力\n for value in range(1, 10):\n if is_valid(grid, y, x, value):\n grid[y][x] = value\n # 次へ\n if solve_sudoku(grid, y, x):\n return True\n backtracks += 1\n grid[y][x] = 0\n return False\n \n # \n def output_data(): #data_set():\n i = -1\n item2 =[0]*n*n\n \n data = input_grid\n \n label0 = tk.Label(root, text = '計算結果', font = ('', 14), height = 1) \n label0.grid(row = 11, column = 0, columnspan = 4, rowspan = 1) \n root.columnconfigure(0, weight = 1)\n root.rowconfigure(12, weight = 1)\n \n for y in range(n):\n for x in range(n):\n i = i + 1 \n item2[i] = tk.StringVar()\n entry1 = tk.Entry(root, width = 2, textvariable = item2[i], justify ='center', font =('',14))\n entry1.grid(row = y + 13, column = x, padx = 2, pady = 2, ipady = 3, sticky=(tk.N, tk.S, tk.E, tk.W))\n item2[i] = data[y][x] \n entry1.insert(tk.END, item2[i]) \n \n root.columnconfigure(x, weight = 1)\n root.rowconfigure(y+13, weight = 1) \n \n #\n \n Button = tk.Button(root, text='Input', command = input_data)\n #Button = tk.Button(root, text='Input', command = lambda:input_data(data))\n Button.grid(row=0, column=10, padx=2)\n \n input_grid = input_data() #ここはちゃんと渡せている(直接データを書いたら)\n solve_sudoku(input_grid)\n \n Button = tk.Button(root, text='output', command = output_data)\n Button.grid(row=1, column=10, padx=2)\n \n root.mainloop()\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T04:52:39.963",
"favorite_count": 0,
"id": "86695",
"last_activity_date": "2022-03-05T16:07:19.487",
"last_edit_date": "2022-03-05T15:28:00.587",
"last_editor_user_id": "26370",
"owner_user_id": "51696",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "entryから取得したデータがきちんと使用できない",
"view_count": 100
} | [
{
"body": "以下のあたりがおかしいでしょう。\n\n * `def input_data():`関数は取得した入力値(`data`)を最後に戻り値として返していますが、ボタンから呼ばれた時にはそれをどこかに格納する処理が何処にもありません。 \n戻り値で返すのではなく、関数の中で必要とする変数(この場合は`input_grid`)に格納する必要があります。 \nそして`input_grid`に格納するなら、`def input_data():`関数の最初に`global`宣言をしておく必要があります。\n\n * `inputボタン処理`と`outputボタン処理`のどちらも`def solve_sudoku(grid, y=0, x=0):`を呼び出す部分がありません。 \n`inputボタン処理`の最後か、`outputボタン処理`の`input_grid`からデータをコピーする前に、`solve_sudoku(input_grid)`を呼び出しておく必要があります。\n\n * `outputボタン`作成や`root.mainloop()`を呼び出す前に行っている以下の処理は、これがあることでかえって問題の原因を判り難くしています。調査のために入れるなら、`output_data`処理の中で何かの変数を`print()`で出力するとかした方が良かったと思われます。\n\n```\n\n input_grid = input_data()\n solve_sudoku(input_grid)\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T16:00:04.593",
"id": "86707",
"last_activity_date": "2022-03-05T16:07:19.487",
"last_edit_date": "2022-03-05T16:07:19.487",
"last_editor_user_id": "26370",
"owner_user_id": "26370",
"parent_id": "86695",
"post_type": "answer",
"score": 1
}
] | 86695 | 86707 | 86707 |
{
"accepted_answer_id": "86700",
"answer_count": 1,
"body": "git add -A の-Aオプションはなぜ大文字なのでしょうか? \n-a オプションが他に使用されていたのですか? \n大文字・小文字の規則はあるのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T05:19:06.680",
"favorite_count": 0,
"id": "86696",
"last_activity_date": "2022-03-05T07:46:42.843",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51699",
"post_type": "question",
"score": 6,
"tags": [
"git"
],
"title": "gitオプションの大文字・小文字の違い",
"view_count": 241
} | [
{
"body": "たしかに git-add には `-a` オプションがないのに `--all` の短縮名は `-A` ですね.\n\nUnix\nコマンドの短縮名に大文字を採用することについて,私が知る限り明確なルールはないと思います.一般的には,以下のいずれかの理由で採用されている例が多いような気がします:\n\n 1. 小文字の短縮名が既に存在していて,それとの区別をするため\n 2. 挙動が特殊だったり危険だったりするため,使用時に注意してもらうため\n\nさて,git-add については,git-add に最初に `--all`\nオプションが追加された際のコミットメッセージに短縮名が大文字となった理由が書かれていました.\n\n> It will be too much of a change that is against the expectation of the \n> existing users to allow \"git commit -a\" to include untracked files, \n> and it would be inconsistent if we named this new option \"-a\", so the \n> short option is \"-A\". We _might_ want to later add \"git commit -A\" \n> but that is a separate topic. \n>\n> <https://github.com/git/git/commit/3ba1f114267b19a458df0f1d714dc4010ec9cc56>\n\n要するに,広義の 1. と 2. の複合みたいなパターンのようです.確かに git-add 自体には小文字の短縮名 `-a` は存在しませんが,それ以前から\ngit-commit に `-a` オプションが存在していて,git-commit の `-a` と git-add の `-A`\nでは挙動が異なることについて注意を促すために大文字になったということのようです.\n\nちなみに同コミットメッセージには「git-commit の方にも `-A` を追加するかも知れない」という主旨のことが書かれていますが,結局今日 (git\n2.35.1) まで追加されてはいないようです.",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T07:46:42.843",
"id": "86700",
"last_activity_date": "2022-03-05T07:46:42.843",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "27047",
"parent_id": "86696",
"post_type": "answer",
"score": 10
}
] | 86696 | 86700 | 86700 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "よろしくお願いいたします。\n\n以下のようなことを実現したいのですが、main.pyで定義されているfun()をmain.pyがimportしているsub.pyから呼び出したいのですが、やり方はあるのでしょうか?\n\n```\n\n # main.py\n from sub.py import *\n def fun():\n print('test')\n call_fun() # 'test'を表示したい\n \n```\n\n```\n\n # sub.py\n def call_fun():\n fun() # ここで自分をimportしているmain.pyのfun()を呼び出したい。うまい書き方はるのでしょうか?\n \n```\n\nfunをcall_fun()に渡せば(例、call_fun(fun))できそうですが、それはしたくないのです。\n\nまた、sub.pyをimportするファイル名は、好きなものにしたいので、例えば、main.pyをmain2.pyにしても動くようにしたいのです。sub.pyのcall_fun()はどのように書けば実現できるでしょうか?\n\nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T05:31:08.727",
"favorite_count": 0,
"id": "86697",
"last_activity_date": "2022-12-12T04:07:05.990",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51697",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "main.pyでimportしているモジュールからmain.pyで定義されている関数を呼び出す方法はあるのでしょうか?",
"view_count": 769
} | [
{
"body": "[Is there a way to access parent modules in\nPython](https://stackoverflow.com/q/5286210/9014308) \n上記記事の以下の回答を応用すれば出来るようです。 \nただし、多段階の`import`とかされると適用できないかもしれませんね。\n\n> [For posterity, I ran into this also and came up with the one\n> liner:](https://stackoverflow.com/a/45895490/9014308)\n```\n\n> import sys\n> parent_module = sys.modules['.'.join(__name__.split('.')[:-1]) or\n> '__main__']\n> \n```\n\n>\n> The `or '__main__'` part is just in case you load the file directly it will\n> return itself.\n\nソースコードは以下のようになるでしょう。\n\n * `main.py`は`sub.py`を`import`する行を以下に変える。(`.py`を削る)\n\n```\n\n from sub import *\n \n```\n\n * `sub.py`は上記記事を応用して親モジュールの情報を取得しておき、その関数を呼び出す。\n\n```\n\n # sub.py\n import sys\n parent_module = sys.modules['.'.join(__name__.split('.')[:-1]) or '__main__']\n \n def call_fun():\n parent_module.fun() # ここで自分をimportしている親モジュールのfun()を呼び出す。\n \n```",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T06:23:45.470",
"id": "86698",
"last_activity_date": "2022-03-05T06:23:45.470",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26370",
"parent_id": "86697",
"post_type": "answer",
"score": 1
}
] | 86697 | null | 86698 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "module内変数にアクセスするな、というお叱りの言葉を受けそうですが、main.pyでaを100にする方法はないのでしょうか?\n\n```\n\n # main.py\n from sub import *\n foo()\n print(a) # 0が表示される T-T)/\n \n```\n\n```\n\n # sub.py\n a = 0\n def foo():\n global a\n a = 100\n \n```\n\nまた、不思議なのは、以下のようにすると100が表示されることです。\n\n```\n\n # main.py\n from sub import *\n baa() # 100が表示される \n \n```\n\n```\n\n # sub.py\n a = 0\n def foo():\n global a\n a = 100\n def baa():\n print(a)\n \n```\n\nT^T)/ よろしくお願いいたします。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T08:16:37.773",
"favorite_count": 0,
"id": "86701",
"last_activity_date": "2022-03-05T10:00:03.900",
"last_edit_date": "2022-03-05T08:32:02.750",
"last_editor_user_id": "3060",
"owner_user_id": "51697",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "Python でモジュール内変数の謎な動き",
"view_count": 159
} | [
{
"body": "この記事の回答やPythonのドキュメントが参考になるでしょう。この記事自体の`import`とグローバル変数が何処に定義されているかは今の質問とは違いますが。 \nその回答の中で、3つのパターンの対処が説明されています。 \n[Visibility of global variables in imported\nmodules](https://stackoverflow.com/q/15959534/9014308)\n\n> Globals in Python are global to a module, not across all modules. (Many\n> people are confused by this, because in, say, C, a global is the same across\n> all implementation files unless you explicitly make it `static`.)\n\n> PythonのGlobalsは、すべてのモジュールにまたがるわけではなく、(個々の)モジュールに対してglobalです。\n> (たとえば、C(言語)では、明示的に`static`にしない限り、globalはすべての実装ファイルで同じであるため、多くの人がこれに混乱しています。)\n\nつまり`main.py`で`sub.py`を`import`してアクセス出来る`a`と、`sub.py`の中からアクセスできる`a`は違う物だということです。\n\n* * *\n\n同様のことは以下のPythonのドキュメントにも記述されています。\n\n[グローバル変数をモジュール間で共有するにはどうしたらいいですか?](https://docs.python.org/ja/3/faq/programming.html#how-\ndo-i-share-global-variables-across-modules)\n\n> 一つのプログラムのモジュール間で情報を共有する正準な方法は、特別なモジュール (しばしば config や cfg と呼ばれる)\n> を作ることです。単に設定モジュールをアプリケーションのすべてのモジュールにインポートしてください。\n\nそして両方の記事とも、`モジュール名.`を変数の頭に付けてアクセスするよう説明されています。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-05T09:52:58.103",
"id": "86703",
"last_activity_date": "2022-03-05T10:00:03.900",
"last_edit_date": "2022-03-05T10:00:03.900",
"last_editor_user_id": "26370",
"owner_user_id": "26370",
"parent_id": "86701",
"post_type": "answer",
"score": 1
}
] | 86701 | null | 86703 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "## 概要\n\niOSのキーボードの種類によってoninputの発火回数が異なる\n\n## Version\n\niOS: 15.3.1\n\n## コード例\n\n<https://codepen.io/Ryotokubo/pen/VwrErLj> \n上記コードのoninput内でalertを呼び出して検証しています。\n\n## 実際の挙動\n\n正常\n\n * キーボードタイプで数字を入力 \n<https://www.flickr.com/photos/195127769@N05/shares/30yv6r>\n\n異常\n\n * デフォルトキーボードで数字を入力 \n<https://www.flickr.com/photos/195127769@N05/shares/90Q9ek>\n\n## 検証したこと/調べたこと\n\n自身の調べ方が悪く、iOSのキーボードの仕様にあたる記事が見つかりませんでした。appleにfeedbackを求めても現在まで返答がありません。\n\n情報が少ないとは思うのですが、ご教授いただけると幸いです。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-06T05:36:08.420",
"favorite_count": 0,
"id": "86713",
"last_activity_date": "2022-03-06T05:36:08.420",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51708",
"post_type": "question",
"score": 0,
"tags": [
"ios"
],
"title": "iOSのキーボードの種類によってoninputの発火回数が異なる",
"view_count": 92
} | [] | 86713 | null | null |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "### 解決したいこと\n\ndockerのpermission deniedエラーを解決したいです。 \nプログラミング入門者です。ポートフォリオにdockerを使ってみようと思ったので2日ほど前からyoutubeの動画を参考にさせて頂き、学習しています。ですが、途中で\n\n```\n\n failed to solve: rpc error: code = Unknown desc = error from sender: open \n /home/senseiy/Documents/rails_docker/src/db/mysql_data/#innodb_temp: permission denied\n \n```\n\nのようなエラーが出てしまい、ここで詰まってしまいました。 \n環境 windows11のwsl2を使用しています。wsl2ではubuntu20.04を使用しています。\n\n### 発生している問題・エラー\n\n```\n\n senseiy@senseIY:~/Documents/rails_docker$ docker-compose run web rails new . --force --database=mysql\n [+] Running 13/13\n ⠿ db Pulled 66.9s\n ⠿ 15115158dd02 Pull complete 7.3s\n ⠿ d733f6778b18 Pull complete 7.4s\n ⠿ 1cc7a6c74a04 Pull complete 7.8s\n ⠿ c4364028a805 Pull complete 8.0s\n ⠿ 82887163f0f6 Pull complete 8.1s\n ⠿ 097bfae26e7a Pull complete 9.8s\n ⠿ e1b044d6a24f Pull complete 9.9s\n ⠿ cd2978bd4d12 Pull complete 10.0s\n ⠿ 28bce5cc1677 Pull complete 19.8s\n ⠿ 907b6d695760 Pull complete 19.8s\n ⠿ c5049403458b Pull complete 19.9s\n ⠿ f360718d6f4e Pull complete 20.0s\n [+] Running 2/2\n ⠿ Network rails_docker_default Created 0.8s\n ⠿ Container rails_docker-db-1 Created 0.5s\n [+] Running 1/1\n ⠿ Container rails_docker-db-1 Started 1.6s\n [+] Building 73.8s (6/9)\n => [internal] load build definition from Dockerfile 0.0s\n => => transferring dockerfile: 396B 0.0s\n => [internal] load .dockerignore 0.0s\n => => transferring context: 2B 0.0s\n => [internal] load metadata for docker.io/library/ruby:2.7 73.2s\n => CACHED [1/5] FROM docker.io/library/ruby:2.7@sha256:490f9343c654ce108a1bd34b4896e531135ffd47b9a25081948770ab9 0.0s\n => ERROR [internal] load build context 0.0s\n => => transferring context: 324B 0.0s\n => CANCELED [2/5] RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo \"deb https:/ 0.5s\n ------\n > [internal] load build context:\n ------\n failed to solve: rpc error: code = Unknown desc = error from sender: open /home/senseiy/Documents/rails_docker/src/db/mysql_data/#innodb_temp: permission denied\n \n```\n\n### 使用したファイル\n\n### Dockerfile\n\n```\n\n #Dockerfile\n \n FROM ruby:2.7\n RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \\\n && echo \"deb https://dl.yarnpkg.com/debian/ stable main\" | tee /etc/apt/sources.list.d/yarn.list \\\n && apt-get update -qq \\\n && apt-get install -y nodejs yarn\n WORKDIR /app\n COPY ./src /app\n RUN bundle config --local set path 'vendor/bundle' \\\n && bundle install\n \n \n```\n\n### Gemfile\n\n```\n\n source 'https://rubygems.org'\n \n gem 'rails', '~> 6.1.0'\n \n```\n\n### docker-compose.yml\n\n```\n\n version: '3'\n services:\n db: \n image: mysql:8.0\n command: --default-authentication-plugin=mysql_native_password\n volumes: \n - ./src/db/mysql_data:/var/lib/mysql\n environment:\n MYSQL_ROOT_PASSWORD: password\n web:\n build: .\n command: bundle exec rails s -p 3000 -b '0.0.0.0'\n volumes: \n - ./src:/app\n ports:\n - \"3000:3000\"\n depends_on:\n - db\n \n \n```\n\n### 試したことと考察など\n\n・スペルミスをチェックしたが問題はなさそうだった。 \n・https://teratail.com/questions/356474 \nこの方の記事を参考にDockerfileを ./build/web/Dockerfile に移動し、docker-compose.yml内のweb:を\n\n```\n\n web:\n build: ./build/web\n \n```\n\nへ変更して更にDockerfileのCOPY部分を削除してから実行すると\n\n```\n\n senseiy@senseIY:~/Documents/rails_docker$ docker-compose run web rails new . --force --database=mysql\n [+] Running 1/0\n ⠿ Container rails_docker-db-1 Running 0.0s\n [+] Building 43.3s (7/7) FINISHED\n => [internal] load build definition from Dockerfile 0.0s\n => => transferring dockerfile: 399B 0.0s\n => [internal] load .dockerignore 0.0s\n => => transferring context: 2B 0.0s\n => [internal] load metadata for docker.io/library/ruby:2.7 41.3s\n => [1/4] FROM docker.io/library/ruby:2.7@sha256:490f9343c654ce108a1bd34b4896e531135 0.0s\n => CACHED [2/4] RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add 0.0s\n => CACHED [3/4] WORKDIR /app 0.0s\n => ERROR [4/4] RUN bundle config --local set path 'vendor/bundle' && bundle ins 1.9s\n ------\n > [4/4] RUN bundle config --local set path 'vendor/bundle' && bundle install:\n #7 1.857 Could not locate Gemfile\n ------\n failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c bundle config --local set path 'vendor/bundle' && bundle install]: exit code: 10\n \n```\n\nのようなエラーが出てきてしまった。また、このエラーをググっても解決につながりそうな記事が見当たらなかった。Gemfileを見つけられないようだがどうすればいいかわからなくなったため、とりあえず別の方法を試すことにした。また、この方はERROR:\nService 'web' failed to build : Build\nfailedのエラーが出ていたが自分の場合はなぜか出ていない。恐らくだがファイルを見る限り私と同じ処理をしているはず。 \n・権限をつけてみることにしたので以下のコマンドを実行するも効果はなく、エラー文に変わりはなかった。\n\n```\n\n #もしかすると意味ないことしてしまっているかもしれません\n senseiy@senseIY:~/Documents/rails_docker$ pwd\n /home/senseiy/Documents/rails_docker\n senseiy@senseIY:~/Documents/rails_docker$ chmod 777 /home/senseiy/Documents/rails_docker\n \n```\n\n・プログラミング入門者のため認識が間違っている部分があると思います。何かしらアドバイスがあればよろしくお願いいたします。\n\n追記 \nローカルとコンテナ内でユーザー権限の不一致が起きている可能性があるとのご指摘を頂いたので調べていただきました。 \n<https://tech-blog.rakus.co.jp/entry/20200826/docker> \nこちらの記事を参考に進めさせていただきました。 \nまず、1つめのマウントしたボリュームの権限を書き換えるについてですが。\n\n```\n\n senseiy@senseIY:~/Documents/rails_docker$ chmod 777 src\n senseiy@senseIY:~/Documents/rails_docker$ docker-compose run web rails new . --force --database=mysql\n [+] Running 1/0\n ⠿ Container rails_docker-db-1 Running 0.0s\n [+] Building 41.4s (7/9)\n => [internal] load build definition from Dockerfile 0.0s\n => => transferring dockerfile: 397B 0.0s\n => [internal] load .dockerignore 0.0s\n => => transferring context: 2B 0.0s\n => [internal] load metadata for docker.io/library/ruby:2.7 41.3s\n => [1/5] FROM docker.io/library/ruby:2.7@sha256:490f9343c654ce108a1bd34b4896e531135 0.0s\n => ERROR [internal] load build context 0.0s\n => => transferring context: 324B 0.0s\n => CACHED [2/5] RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add 0.0s\n => CACHED [3/5] WORKDIR /app 0.0s\n ------\n > [internal] load build context:\n ------\n failed to solve: rpc error: code = Unknown desc = error from sender: open /home/senseiy/Documents/rails_docker/src/db/mysql_data/#innodb_temp: permission denied\n \n```\n\nのように特にエラーは変わりませんでした。 \n2つ目のもやろうとしたのですが、どうやらコンテナ内のidを調べる必要があるみたいです。私の場合初期設定でエラーが出ている(まだコンテナをつくっていないので、docker-\ncompose exec コンテナ名\nbashで中に入ってid確認できない。また、3つ目は途中でbuildする必要がある)ためどうすればいいかわからなくなり、また詰まってしまいました。何かしらアドバイスがあればよろしくお願いいたします。",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-06T06:35:30.763",
"favorite_count": 0,
"id": "86714",
"last_activity_date": "2022-07-14T03:04:45.470",
"last_edit_date": "2022-03-06T09:10:01.903",
"last_editor_user_id": "51193",
"owner_user_id": "51193",
"post_type": "question",
"score": 0,
"tags": [
"windows",
"docker",
"wsl-2"
],
"title": "dockerのpermission deniedエラーを解決したい",
"view_count": 9531
} | [
{
"body": "chmod -R 777 src \n上記のコマンドを実行(私の場合はなぜか-Rなし+すべてのファイル作りなおしで動きました) \nで解決できました。私のようなエラーで詰まっている方の参考になれば幸いです。アドバイスをして頂きありがとうございました。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-06T10:02:06.663",
"id": "86717",
"last_activity_date": "2022-03-06T10:02:06.663",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51193",
"parent_id": "86714",
"post_type": "answer",
"score": 1
},
{
"body": "`chmod -R 777 src` でうまくいかない場合は、頭に `sudo` を付けて管理者として実行してください。\n\n```\n\n $ sudo chmod -R 777 src\n \n```\n\n私の場合はこれでうまくいきました。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-05-04T06:26:48.817",
"id": "88646",
"last_activity_date": "2022-05-05T06:06:27.160",
"last_edit_date": "2022-05-05T06:06:27.160",
"last_editor_user_id": "3060",
"owner_user_id": "52479",
"parent_id": "86714",
"post_type": "answer",
"score": 1
}
] | 86714 | null | 86717 |
{
"accepted_answer_id": "86721",
"answer_count": 1,
"body": "フロントエンド、Spring初心者のため抽象的で拙い質問となることをお許しください! \n(teratailにも投稿しているのですがご回答がつかないため、すみませんがstackoverflowにも投稿させていただきます。)\n\n以下のコードのようにHTMLからContlollerの@RequestMappingに指定したパスを直接記述することで処理を呼び出して画像を表示するようなHTMLがあるとします。\n\n```\n\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <title>Insert title here</title>\n </head>\n <body>\n <p>画像表示</p>\n <img th:src=\"@{/getImg?name=IMGP12345}\" th:width=\"600\">\n </body>\n </html>\n \n```\n\n```\n\n package com.example.demo.app;\n \n import java.io.File;\n import java.io.IOException;\n import java.nio.file.Files;\n \n import org.springframework.http.HttpEntity;\n import org.springframework.http.HttpHeaders;\n import org.springframework.http.MediaType;\n import org.springframework.stereotype.Controller;\n import org.springframework.web.bind.annotation.GetMapping;\n import org.springframework.web.bind.annotation.RequestMapping;\n import org.springframework.web.bind.annotation.RequestParam;\n import org.springframework.web.bind.annotation.ResponseBody;\n \n @Controller\n public class ImgController {\n \n @GetMapping(\"/\")\n public String getIndex() {\n return \"ImgController\";\n }\n \n @RequestMapping(\"/getImg\")\n @ResponseBody\n public HttpEntity<byte[]> getImg(@RequestParam(\"name\") String fileName){\n File fileImg = new File(\"img/\"+ fileName +\".JPG\");\n \n byte[] byteImg = null;\n HttpHeaders headers = null;\n try {\n //バイト列に変換\n byteImg = Files.readAllBytes(fileImg.toPath());\n headers = new HttpHeaders();\n \n //Responseのヘッダーを作成\n headers.setContentType(MediaType.IMAGE_JPEG);\n headers.setContentLength(byteImg.length);\n }catch(IOException e) {\n return null;\n }\n return new HttpEntity<byte[]>(byteImg,headers);\n }\n \n @RequestMapping(\"/getText\")\n @ResponseBody\n public String text() {\n String text = \"test text\";\n return text;\n }\n \n }\n \n```\n\nこのようなニュアンスで非同期的?に画像以外の文字列だったりJsonだったりを例えばタグなどに指定して直接呼び出すようなことって可能でしょうか。例えば上記Javaで簡素に記述しておりますが、textメソッドのような文字列を返すメソッドの@RequestMappingのパスをHTML側(もしくはjsなど?)で指定して画面に表示したりパラメータとして使用したりしたいと思っております。 \nあくまでも画面に遷移するのではなく表示した画面の中の要素として呼び出すようなイメージです。\n\nググる力が足りず、こちらへ質問することに至りました。\n\nご確認・ご教授いただけると幸いです。よろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-06T12:00:35.210",
"favorite_count": 0,
"id": "86718",
"last_activity_date": "2022-03-07T08:57:28.050",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51714",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"java",
"html",
"spring-boot"
],
"title": "Spring Boot、Spring MVC の文字列やJsonを返すContlollerを直接タグから呼び出してHTML上に表示する方法はありますでしょうか",
"view_count": 344
} | [
{
"body": "```\n\n <!DOCTYPE html>\n <html xmlns:th=\"http://www.thymeleaf.org\">\n <head>\n <meta charset=\"UTF-8\" />\n <title>Insert title here</title>\n </head>\n <body>\n <p>画像表示</p>\n <img th:src=\"@{/getImg?name=IMGP12345}\" th:width=\"600\" />\n \n <script th:inline=\"javascript\">\n document.addEventListener(\"DOMContentLoaded\", (event) => {\n const url = /*[[@{/getText}]]*/ \"/dummy-url\";\n fetch(url)\n .then((resp) => resp.text())\n .then((text) => {\n const div = document.createElement(\"div\");\n div.textContent = text;\n const body = document.getElementsByTagName(\"body\")[0];\n body.insertAdjacentElement(\"afterbegin\", div);\n });\n });\n </script>\n </body>\n </html>\n \n```\n\n大枠としては、概ね一般的なJavaScript/HTMLの範囲に収まる話かなと考えます。 \nJavaScriptの [Fetch\nAPI](https://developer.mozilla.org/ja/docs/Web/API/Fetch_API/Using_Fetch)\nを利用して Spring MVC で用意したエンドポイントを非同期で呼ぶ、というのが処理の流れになるでしょう。\n\n細かい部分としては、Spring MVC(&\nThymeleaf)特有の話として、JavaScript部分も[テンプレート処理](https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf_ja.html#javascript%E3%82%A4%E3%83%B3%E3%83%A9%E3%82%A4%E3%83%B3%E5%87%A6%E7%90%86)できる、ということが挙げられれます。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T02:29:48.590",
"id": "86721",
"last_activity_date": "2022-03-07T08:57:28.050",
"last_edit_date": "2022-03-07T08:57:28.050",
"last_editor_user_id": "2808",
"owner_user_id": "2808",
"parent_id": "86718",
"post_type": "answer",
"score": 0
}
] | 86718 | 86721 | 86721 |
{
"accepted_answer_id": "86725",
"answer_count": 1,
"body": "ons-switchのsetCheckedについて詳しく教えてほしいです。 \nどんなに試してもエラーしか出ません。\n\nJavaScript\n\n```\n\n B = document.getElementById(\"sekasi\");\n B.setChecked(false);\n \n```\n\nHTML\n\n```\n\n <ons-switch id=\"sekasi\" onclick=\"sekasifunk()\"></ons-switch>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-06T18:24:15.617",
"favorite_count": 0,
"id": "86720",
"last_activity_date": "2022-03-08T03:02:32.143",
"last_edit_date": "2022-03-07T06:01:37.033",
"last_editor_user_id": "3060",
"owner_user_id": "51719",
"post_type": "question",
"score": 0,
"tags": [
"onsen-ui"
],
"title": "ons-switch の setChecked を使用するとエラーが発生する",
"view_count": 63
} | [
{
"body": "Onsen UI v2の前提で書きます\n\n<https://ja.onsen.io/v2/api/js/ons-switch.html>\n\n通常のDOM操作で良さそうなので以下をお試しください\n\n```\n\n const sekasi = document.getElementById(\"sekasi\");\n sekasi.checked = false\n \n```\n\n<https://codepen.io/sugumura/pen/rNYgaLK>",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T05:43:03.047",
"id": "86725",
"last_activity_date": "2022-03-08T03:02:32.143",
"last_edit_date": "2022-03-08T03:02:32.143",
"last_editor_user_id": "298",
"owner_user_id": "298",
"parent_id": "86720",
"post_type": "answer",
"score": 0
}
] | 86720 | 86725 | 86725 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "困りごとから先に書くと、下記コードの `return fn(...args);` の部分でエラーが発生し、それがどうやっても取れません。原因は何でしょうか?\n\n```\n\n const table = {\n add: (a: number, b: number) => a + b,\n square: (a: number) => a * a,\n } as const;\n \n type Table = typeof table;\n type Key = keyof Table;\n \n function calculate<T extends Key>(key: T, ...args: Parameters<Table[T]>): number {\n const fn: Table[T] = table[key];\n return fn(...args);\n }\n \n const x = calculate('add', 1, 2);\n const y = calculate('square', 3);\n \n```\n\n上のコードでやろうとしていることは、まずテーブルに関数を並べ、キーを使ってそのうちの一つを呼び出す、いわゆるヘルパー関数を実装することです。末尾2行が使用例で、このようにキーに応じて型推論がうまく効き、呼び出し側に正しい引数の型を強いることを狙いとしています。そして末尾2行にエラーが出ていないことから、この点では型推論はうまく行っているようです(`add`\nと `square` で引数の数が逆だとエラーが出ます)。\n\nところが、`calculate` 関数内の `return fn(...args);` の部分において、`fn` の型は `T`\nが決まるまで決まらないはずですが、エディタを見るとここが `(a: number, b: number) => number`\n型に決め打ちされているようで、それがエラーを呼び込んでいるように見えます。\n\n問題の細分化のために、試しに `calculate`\nの実装にジェネリックを使うのをやめて、下記のように特定のリテラル型限定で書くとエラーが消えました(そのため、自分にはコンパイラのバグに思えてなりません)。\n\n```\n\n function calculate(key: 'add', ...args: Parameters<Table['add']>): number {\n const fn: Table['add'] = table[key];\n return fn(...args);\n }\n \n```\n\n型推論に詳しい方、原因がお分かりでしたらご教示ください。よろしくお願いします。\n\n補足:\n\n * 今回についてはエラーメッセージは本質でないと思いますが、一応書くと `spread 引数には、組の種類を指定するか、rest パラメーターに渡す必要があります。ts(2556)` でした\n * 回りくどいコードに見えるかもしれませんが、これはエラーをあぶり出すために最小化したコードであり、このような形にしなければならない理由は省略しています",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T08:39:02.720",
"favorite_count": 0,
"id": "86732",
"last_activity_date": "2022-03-08T04:19:18.727",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51728",
"post_type": "question",
"score": 2,
"tags": [
"typescript"
],
"title": "ルックアップ型と可変長引数の組み合わせで型推論がうまく行かない",
"view_count": 378
} | [
{
"body": "自己解決しました。型制限 `<T extends Key>` は決して `Key` のうちの **一つであること** を要求しないんですね。\n\n上の例で `T` は `'add'` か `'square'` のどちらかに決まると思っていましたが、論理的には `'add' | 'square'`\nもあり得るわけで、そう考えると `fn` の型もこの時点で確定することはできませんね。\n\nユニオン型のうちの一つであることを要求する記述 `oneof` の提案について、この\n[issue](https://github.com/microsoft/TypeScript/issues/27808) で議論されているようです。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T04:19:18.727",
"id": "86746",
"last_activity_date": "2022-03-08T04:19:18.727",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51740",
"parent_id": "86732",
"post_type": "answer",
"score": 2
}
] | 86732 | null | 86746 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "scikit-learn公式ドキュメントには「Number of alphas along the regularization path, used\nfor each l1_ratio.」とありますが、Elasticnetの「n_alpha」という引数はどのようなものかご教授いただけますでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T08:44:13.610",
"favorite_count": 0,
"id": "86734",
"last_activity_date": "2022-03-29T23:26:32.750",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51729",
"post_type": "question",
"score": 0,
"tags": [
"python",
"機械学習",
"scikit-learn"
],
"title": "ElasticNetCVの引数n_alphasについて",
"view_count": 127
} | [
{
"body": "通常のElasticNetの場合は交差検証を内部的に行わないので単一のalphaを指定しますが、CVがつく場合は交差検証でパラメータをグリッドサーチするように処理するので、alphaを複数指定(alphas)できます。n_alphasを指定してalphas=Noneとすると、alphasはn_alphasの数だけ自動設定されます。ElasticNetCVはこのalphasそれぞれで訓練されたモデルでスコアを出し、bestとなるalphaを見つけ出します。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-29T13:48:27.533",
"id": "88089",
"last_activity_date": "2022-03-29T23:26:32.750",
"last_edit_date": "2022-03-29T23:26:32.750",
"last_editor_user_id": "52014",
"owner_user_id": "52014",
"parent_id": "86734",
"post_type": "answer",
"score": 0
}
] | 86734 | null | 88089 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "### 解決したいこと\n\n`rails s` でエラーが出てしまうので解決したいです。\n\nまず、`rails s` をすると以下のようなエラーが出てきました。\n\n```\n\n senseiy@senseIY:~/dictum/dictum$ rails s\n => Booting Puma\n => Rails 6.0.4.6 application starting in development\n => Run `rails server --help` for more startup options\n error Couldn't find an integrity file\n error Found 1 errors.\n \n \n ========================================\n Your Yarn packages are out of date!\n Please run `yarn install --check-files` to update.\n ========================================\n \n \n To disable this check, please change `check_yarn_integrity`\n to `false` in your webpacker config file (config/webpacker.yml).\n \n \n yarn check v1.22.17\n info Visit https://yarnpkg.com/en/docs/cli/check for documentation about this command.\n \n \n Exiting\n \n```\n\nどうやらyarnを新しくするといいみたいなので、指示通りコマンドを実行すると、以下のようなエラーになってしまいました。\n\n```\n\n senseiy@senseIY:~/dictum/dictum$ yarn install --check-files\n yarn install v1.22.17\n [1/4] Resolving packages...\n [2/4] Fetching packages...\n [3/4] Linking dependencies...\n warning \" > [email protected]\" has unmet peer dependency \"webpack@^4.37.0 || ^5.0.0\".\n warning \"webpack-dev-server > [email protected]\" has unmet peer dependency \"webpack@^4.0.0 || ^5.0.0\".\n [4/4] Building fresh packages...\n [-/2] ⠐ waiting...\n error /home/senseiy/dictum/dictum/node_modules/node-sass: Command failed.\n Exit code: 1\n Command: node scripts/build.js\n Arguments:\n Directory: /home/senseiy/dictum/dictum/node_modules/node-sass\n Output:\n Building: /usr/local/bin/node /home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=\n gyp info it worked if it ends with ok\n gyp verb cli [\n gyp verb cli '/usr/local/bin/node',\n gyp verb cli '/home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js',\n gyp verb cli 'rebuild',\n gyp verb cli '--verbose',\n gyp verb cli '--libsass_ext=',\n gyp verb cli '--libsass_cflags=',\n gyp verb cli '--libsass_ldflags=',\n gyp verb cli '--libsass_library='\n gyp verb cli ]\n gyp info using [email protected]\n gyp info using [email protected] | linux | x64\n gyp verb command rebuild []\n gyp verb command clean []\n gyp verb clean removing \"build\" directory\n gyp verb command configure []\n gyp verb check python checking for Python executable \"python2\" in the PATH\n gyp verb `which` failed Error: not found: python2\n gyp verb `which` failed at getNotFoundError (/home/senseiy/dictum/dictum/node_modules/which/which.js:13:12)\n gyp verb `which` failed at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:19)\n gyp verb `which` failed at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21)\n gyp verb `which` failed python2 Error: not found: python2\n gyp verb `which` failed at getNotFoundError (/home/senseiy/dictum/dictum/node_modules/which/which.js:13:12)\n gyp verb `which` failed at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:19)\n gyp verb `which` failed at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21) {\n gyp verb `which` failed code: 'ENOENT'\n gyp verb `which` failed }\n gyp verb check python checking for Python executable \"python\" in the PATH\n gyp verb `which` failed Error: not found: python\n gyp verb `which` failed at getNotFoundError (/home/senseiy/dictum/dictum/node_modules/which/which.js:13:12)\n gyp verb `which` failed at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:19)\n gyp verb `which` failed at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21)\n gyp verb `which` failed python Error: not found: python\n gyp verb `which` failed at getNotFoundError (/home/senseiy/dictum/dictum/node_modules/which/which.js:13:12)\n gyp verb `which` failed at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:19)\n gyp verb `which` failed at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21) {\n gyp verb `which` failed code: 'ENOENT'\n gyp verb `which` failed }\n gyp ERR! configure error\n gyp ERR! stack Error: Can't find Python executable \"python\", you can set the PYTHON env variable.\n gyp ERR! stack at PythonFinder.failNoPython (/home/senseiy/dictum/dictum/node_modules/node-gyp/lib/configure.js:484:19)\n gyp ERR! stack at PythonFinder.<anonymous> (/home/senseiy/dictum/dictum/node_modules/node-gyp/lib/configure.js:406:16)\n gyp ERR! stack at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:16)\n gyp ERR! stack at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp ERR! stack at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp ERR! stack at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp ERR! stack at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp ERR! stack at FSReqCallback.oncomplete (node:fs:198:21)\n gyp ERR! System Linux 5.10.16.3-microsoft-standard-WSL2\n gyp ERR! command \"/usr/local/bin/node\" \"/home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\" \"--verbose\" \"--libsass_ext=\" \"--libsass_cflags=\" \"--libsass_ldflags=\" \"--libsass_library=\"\n gyp ERR! cwd /home/senseiy/dictum/dictum/node_modules/node-sass\n gyp ERR! node -v v16.14.0\n gyp ERR! node-gyp -v v3.8.0\n gyp ERR! not ok\n Build failed with error code: 1\n \n```\n\n以下リンク先の方は `yarn upgrade` をしたら解決したようです。\n\n[rails コマンドの際のyarnエラー yarn.lockで不整合が起きてる場合に起こる -\nQiita](https://qiita.com/nakki/items/4fa58cb6ff4d6c24c2d2)\n\n実行してみましたが、以下のようなエラーが出てしまいました。\n\n```\n\n senseiy@senseIY:~/dictum/dictum$ yarn upgrade\n yarn upgrade v1.22.17\n [1/4] Resolving packages...\n warning @rails/webpacker > node-sass > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142\n warning @rails/webpacker > node-sass > node-gyp > [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142\n warning @rails/webpacker > node-sass > node-gyp > [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.\n warning @rails/webpacker > node-sass > request > [email protected]: this library is no longer supported\n warning @rails/webpacker > node-sass > request > [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.\n warning @rails/webpacker > webpack > watchpack > watchpack-chokidar2 > [email protected]: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies\n warning @rails/webpacker > postcss-preset-env > postcss-color-gray > postcss-values-parser > [email protected]: flatten is deprecated in favor of utility frameworks such as lodash.\n warning @rails/webpacker > webpack > micromatch > snapdragon > [email protected]: See https://github.com/lydell/source-map-resolve#deprecated\n warning @rails/webpacker > webpack > node-libs-browser > url > [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.\n warning @rails/webpacker > webpack > watchpack > watchpack-chokidar2 > chokidar > [email protected]: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.\n warning @rails/webpacker > optimize-css-assets-webpack-plugin > cssnano > cssnano-preset-default > postcss-svgo > [email protected]: This SVGO version is no longer supported. Upgrade to v2.x.x.\n warning @rails/webpacker > webpack > micromatch > snapdragon > source-map-resolve > [email protected]: See https://github.com/lydell/source-map-url#deprecated\n warning @rails/webpacker > webpack > micromatch > snapdragon > source-map-resolve > [email protected]: https://github.com/lydell/resolve-url#deprecated\n warning @rails/webpacker > webpack > micromatch > snapdragon > source-map-resolve > [email protected]: Please see https://github.com/lydell/urix#deprecated\n [2/4] Fetching packages...\n [3/4] Linking dependencies...\n warning \" > [email protected]\" has unmet peer dependency \"webpack@^4.37.0 || ^5.0.0\".\n warning \"webpack-dev-server > [email protected]\" has unmet peer dependency \"webpack@^4.0.0 || ^5.0.0\".\n [4/4] Rebuilding all packages...\n [-/2] ⢀ waiting...\n error /home/senseiy/dictum/dictum/node_modules/node-sass: Command failed.\n Exit code: 1\n Command: node scripts/build.js\n Arguments:\n Directory: /home/senseiy/dictum/dictum/node_modules/node-sass\n Output:\n Building: /usr/local/bin/node /home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=\n gyp info it worked if it ends with ok\n gyp verb cli [\n gyp verb cli '/usr/local/bin/node',\n gyp verb cli '/home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js',\n gyp verb cli 'rebuild',\n gyp verb cli '--verbose',\n gyp verb cli '--libsass_ext=',\n gyp verb cli '--libsass_cflags=',\n gyp verb cli '--libsass_ldflags=',\n gyp verb cli '--libsass_library='\n gyp verb cli ]\n gyp info using [email protected]\n gyp info using [email protected] | linux | x64\n gyp verb command rebuild []\n gyp verb command clean []\n gyp verb clean removing \"build\" directory\n gyp verb command configure []\n gyp verb check python checking for Python executable \"python2\" in the PATH\n gyp verb `which` failed Error: not found: python2\n gyp verb `which` failed at getNotFoundError (/home/senseiy/dictum/dictum/node_modules/which/which.js:13:12)\n gyp verb `which` failed at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:19)\n gyp verb `which` failed at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21)\n gyp verb `which` failed python2 Error: not found: python2\n gyp verb `which` failed at getNotFoundError (/home/senseiy/dictum/dictum/node_modules/which/which.js:13:12)\n gyp verb `which` failed at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:19)\n gyp verb `which` failed at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21) {\n gyp verb `which` failed code: 'ENOENT'\n gyp verb `which` failed }\n gyp verb check python checking for Python executable \"python\" in the PATH\n gyp verb `which` failed Error: not found: python\n gyp verb `which` failed at getNotFoundError (/home/senseiy/dictum/dictum/node_modules/which/which.js:13:12)\n gyp verb `which` failed at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:19)\n gyp verb `which` failed at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21)\n gyp verb `which` failed python Error: not found: python\n gyp verb `which` failed at getNotFoundError (/home/senseiy/dictum/dictum/node_modules/which/which.js:13:12)\n gyp verb `which` failed at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:19)\n gyp verb `which` failed at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp verb `which` failed at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21) {\n gyp verb `which` failed code: 'ENOENT'\n gyp verb `which` failed }\n gyp ERR! configure error\n gyp ERR! stack Error: Can't find Python executable \"python\", you can set the PYTHON env variable.\n gyp ERR! stack at PythonFinder.failNoPython (/home/senseiy/dictum/dictum/node_modules/node-gyp/lib/configure.js:484:19)\n gyp ERR! stack at PythonFinder.<anonymous> (/home/senseiy/dictum/dictum/node_modules/node-gyp/lib/configure.js:406:16)\n gyp ERR! stack at F (/home/senseiy/dictum/dictum/node_modules/which/which.js:68:16)\n gyp ERR! stack at E (/home/senseiy/dictum/dictum/node_modules/which/which.js:80:29)\n gyp ERR! stack at /home/senseiy/dictum/dictum/node_modules/which/which.js:89:16\n gyp ERR! stack at /home/senseiy/dictum/dictum/node_modules/isexe/index.js:42:5\n gyp ERR! stack at /home/senseiy/dictum/dictum/node_modules/isexe/mode.js:8:5\n gyp ERR! stack at FSReqCallback.oncomplete (node:fs:198:21)\n gyp ERR! System Linux 5.10.16.3-microsoft-standard-WSL2\n gyp ERR! command \"/usr/local/bin/node\" \"/home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\" \"--verbose\" \"--libsass_ext=\" \"--libsass_cflags=\" \"--libsass_ldflags=\" \"--libsass_library=\"\n gyp ERR! cwd /home/senseiy/dictum/dictum/node_modules/node-sass\n gyp ERR! node -v v16.14.0\n gyp ERR! node-gyp -v v3.8.0\n gyp ERR! not ok\n Build failed with error code: 1\n \n```\n\npython2とnodeが怪しいというエラーのようです。nodeのダウングレードを考えましたが、推奨版と同じだったためとりあえずそのままにしてpython2をインストールすることにしました。\n\n以下を実行\n\n```\n\n sudo apt update\n sudo apt install python2-minimal\n sudo apt-get install build-essential\n \n```\n\nもう一度 `yarn install --check-files` を実行\n\n```\n\n #エラーが長すぎるので気になった一部のみpython2のエラーは解消されたようだ \n #yarn upgrade と yarn install --check_yarn_integrity でも同じようなエラーに\n \n yarn install v1.22.17\n [1/4] Resolving packages...\n [2/4] Fetching packages...\n [3/4] Linking dependencies...\n warning \" > [email protected]\" has unmet peer dependency \"webpack@^4.37.0 || ^5.0.0\".\n warning \"webpack-dev-server > [email protected]\" has unmet peer dependency \"webpack@^4.0.0 || ^5.0.0\".\n [4/4] Building fresh packages...\n [-/2] ⡀ waiting...\n error /home/senseiy/dictum/dictum/node_modules/node-sass: Command failed.\n Exit code: 1\n Command: node scripts/build.js\n Arguments:\n Directory: /home/senseiy/dictum/dictum/node_modules/node-sass\n Output:\n Building: /usr/local/bin/node /home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=\n gyp info it worked if it ends with ok\n gyp verb cli [\n gyp verb cli '/usr/local/bin/node',\n gyp verb cli '/home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js',\n gyp verb cli 'rebuild',\n gyp verb cli '--verbose',\n gyp verb cli '--libsass_ext=',\n gyp verb cli '--libsass_cflags=',\n gyp verb cli '--libsass_ldflags=',\n gyp verb cli '--libsass_library='\n gyp verb cli ]\n gyp info using [email protected]\n gyp info using [email protected] | linux | x64\n gyp verb command rebuild []\n gyp verb command clean []\n gyp verb clean removing \"build\" directory\n gyp verb command configure []\n gyp verb check python checking for Python executable \"python2\" in the PATH\n gyp verb `which` succeeded python2 /usr/bin/python2\n ~\n 619e3b9799fa599ca81 == 0cb39adcabb513d2651fa25ea39c88cebd76200ea922e619e3b9799fa599ca81)\n gyp verb get node dir target node version installed: 16.14.0\n gyp verb build dir attempting to create \"build\" dir: /home/senseiy/dictum/dictum/node_modules/node-sass/build\n gyp verb build dir \"build\" dir needed to be created? /home/senseiy/dictum/dictum/node_modules/node-sass/build\n ~\n In file included from ../../nan/nan.h:58,\n from ../src/binding.cpp:1:\n ../src/binding.cpp: At global scope:\n /home/senseiy/.node-gyp/16.14.0/include/node/node.h:842:43: warning: cast between incompatible function types from ‘void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void (*)(v8::Local<v8::Object>)’} to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wcast-function-type]\n 842 | (node::addon_register_func) (regfunc), \\\n | ^\n /home/senseiy/.node-gyp/16.14.0/include/node/node.h:876:3: note: in expansion of macro ‘NODE_MODULE_X’\n 876 | NODE_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)\n | ^~~~~~~~~~~~~\n ../src/binding.cpp:358:1: note: in expansion of macro ‘NODE_MODULE’\n 358 | NODE_MODULE(binding, RegisterModule);\n | ^~~~~~~~~~~\n make: *** [binding.target.mk:133: Release/obj.target/binding/src/binding.o] Error 1\n make: Leaving directory '/home/senseiy/dictum/dictum/node_modules/node-sass/build'\n gyp ERR! build error\n gyp ERR! stack Error: `make` failed with exit code: 2\n gyp ERR! stack at ChildProcess.onExit (/home/senseiy/dictum/dictum/node_modules/node-gyp/lib/build.js:262:23)\n gyp ERR! stack at ChildProcess.emit (node:events:520:28)\n gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)\n gyp ERR! System Linux 5.10.16.3-microsoft-standard-WSL2\n gyp ERR! command \"/usr/local/bin/node\" \"/home/senseiy/dictum/dictum/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\" \"--verbose\" \"--libsass_ext=\" \"--libsass_cflags=\" \"--libsass_ldflags=\" \"--libsass_library=\"\n gyp ERR! cwd /home/senseiy/dictum/dictum/node_modules/node-sass\n gyp ERR! node -v v16.14.0\n gyp ERR! node-gyp -v v3.8.0\n \n```\n\nここで詰まってしまいました。何かしらアドバイスがあればよろしくお願いいたします。\n\n**実行環境:**\n\n * wsl2のubuntu20.04を使っています。\n * Ruby 3.0.0\n * Rails 6.0.4.6",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T10:10:49.923",
"favorite_count": 0,
"id": "86738",
"last_activity_date": "2022-03-07T12:11:14.790",
"last_edit_date": "2022-03-07T12:11:14.790",
"last_editor_user_id": "3060",
"owner_user_id": "51193",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"wsl",
"yarn"
],
"title": "rails sでエラーが出てしまう",
"view_count": 273
} | [
{
"body": "nodeをダウングレードしたところうまく動きました。どうやら現在の推奨は16のようですが、15系でないと動かない場合があるようです。困っている方の参考になれば幸いです。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T11:31:05.603",
"id": "86739",
"last_activity_date": "2022-03-07T11:31:05.603",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51193",
"parent_id": "86738",
"post_type": "answer",
"score": 0
}
] | 86738 | null | 86739 |
{
"accepted_answer_id": "86743",
"answer_count": 1,
"body": "AndroidのPreference項目を動的に非表示にしたいです。\n\n```\n\n <PreferenceScreen>\n ・・・\n <CheckBoxPreference\n android:key=\"test_key\"\n android:defaultValue=\"true\"\n android:title=\"@string/test_title\" />\n ・・・\n </PreferenceScreen>\n \n```\n\n上記の項目を \nコード上で非表示にしたいです。\n\n```\n\n CheckBoxPreference test = getCheckBoxPrefInstance(\"test_key\");\n if (test != null) {\n test.setSelectable(false);(1)\n // test.setEnabled(false);(2)\n }\n \n```\n\n(1)の場合は、活性のような表示ですが、タップができない状態 \n(2)の場合は、非活性のような表示となっています。\n\n<https://developer.android.com/guide/topics/ui/settings/customize-your-\nsettings?hl=ja>\n\n```\n\n EditTextPreference signaturePreference = findPreference(\"signature\");\n if (signaturePreference != null) {\n signaturePreference.setVisible(true);\n }\n \n```\n\n上記のような記載があり、EditTextPreferenceですが、上記を見ますと「setVisible」を使用すれば良さそうなのですが、\n\n```\n\n if (test != null) {\n // test.setSelectable(false);(1)\n // test.setEnabled(false);(2)\n test.setVisible(false);(3)\n }\n \n```\n\n(3)とすると、setVisibleはCheckBoxPreferenceに見つからないと怒られてしまいます。 \nチェックボックス項目を非表示にする方法はありますでしょうか?",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T12:20:37.223",
"favorite_count": 0,
"id": "86740",
"last_activity_date": "2022-03-07T15:38:19.080",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12842",
"post_type": "question",
"score": 0,
"tags": [
"android"
],
"title": "AndroidのCheckBoxPreference項目を動的に非表示にしたい",
"view_count": 195
} | [
{
"body": "公式リファレンス\n[CheckBoxPreference](https://developer.android.com/reference/androidx/preference/CheckBoxPreference#inherited-\nmethods) に `setVisible(boolean visible)` は明記されています。\n\n> setVisibleはCheckBoxPreferenceに見つからないと怒られてしまい\n\nというのは、CheckBoxPreference という代物が `setVisible` というメソッドが使えないわけではなく、原因は全く別のところにある、\n_使えるはずのものが使えなくなっている_ 、と考えた方がいいでしょう。\n\nおそらく、`import` が適切にできていないのではないでしょうか。\n\n`buile.gradle (:app)`\n\n```\n\n implementation 'androidx.preference:preference:1.2.0' // Java\n \n```\n\nまたは\n\n```\n\n implementation 'androidx.preference:preference-ktx:1.2.0' // Kotlin Java 兼用\n \n```\n\nそして import 文\n\n```\n\n import androidx.preference.CheckBoxPreference;\n \n```\n\nandroid **X** のものがちゃんと選択されているかどうか、確かめてください。\n\nFragment:\n\n```\n\n public class MySettingsFragment extends PreferenceFragmentCompat {\n @Override\n public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {\n setPreferencesFromResource(R.xml.preferences, rootKey);\n CheckBoxPreference check = findPreference(\"check\");\n check.setVisible(false);\n }\n }\n \n```\n\npreferences.xml\n\n```\n\n <PreferenceScreen xmlns:app=\"http://schemas.android.com/apk/res-auto\">\n <CheckBoxPreference app:key=\"check\" />\n </PreferenceScreen>\n \n```\n\nこんな感じで何の問題もなく `setVisible` できています。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-07T15:38:19.080",
"id": "86743",
"last_activity_date": "2022-03-07T15:38:19.080",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7290",
"parent_id": "86740",
"post_type": "answer",
"score": 2
}
] | 86740 | 86743 | 86743 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "### 解決したいこと\n\nrails db:createができないので解決したいです。\n\n### 状態\n\n・パソコンを買い替えたので、以前作業していたリポジトリをクローンしたばかりです。 \n・wsl2のubuntuを使用しています。 \n・rubyは 3.0.3 \n・railsは 6.0.4.6のバージョンを使っています。\n\n### これまでの操作\n\nまず、今の開発環境にデータベースがないため、mysqlインストール後にrails\ndb:createをしました。mysqlのインストールはマイクロソフトのサイトを参考にして行いました。 \n<https://docs.microsoft.com/ja-jp/windows/wsl/tutorials/wsl-database> \nその後rails db:createをした際以下のエラーが出てしまいました。\n\n###\n\n```\n\n senseiy@senseIY-wsl:~/dictum/dictum$ rails db:create\n Access denied for user 'root'@'localhost'\n Couldn't create 'dictation_app_development' database. Please check your configuration.\n rails aborted!\n Mysql2::Error: Access denied for user 'root'@'localhost'\n /home/senseiy/dictum/dictum/bin/rails:9:in `<top (required)>'\n <internal:/home/senseiy/.rbenv/versions/3.0.3/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'\n <internal:/home/senseiy/.rbenv/versions/3.0.3/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'\n /home/senseiy/dictum/dictum/bin/spring:15:in `<top (required)>'\n bin/rails:3:in `load'\n bin/rails:3:in `<main>'\n Tasks: TOP => db:create\n (See full trace by running task with --trace)\n \n```\n\nこのエラーで検索しましたが、どうやらAccess denied for user 'root'@'localhost' (using password:\nNO)のように表示されるようなのですが、私の場合、それが表示されません\n\n```\n\n # 私のエラー\n Access denied for user 'root'@'localhost'\n # ググって出てくるエラー\n Access denied for user 'root'@'localhost' (using password: NO) or YES\n \n```\n\nusing passwordがついていないものは現在この方の記事しか見つけられませんでした\n\n<https://stackoverflow.com/questions/64545975/rails-app-denied-access-to-\nmysql-for-user-root-localhost>\n\nこの方の場合、mysqlをアンインストールしてから再インストールしたら治ったようですが、自分の場合3回以上試したのですが直りません。 \nそこで以前のpc(windowsをつぶしてubuntuをいれたやつ)ではhomebrewを使ってインストールしていたためbrewコマンドでのインストールを試そうと考えたのですが、wsl2でmysqlをbrewコマンドでインストールしている記事が無かったため、一旦作業をストップしています。wsl2のubuntuでbrewコマンドでmysqlをインストールしても大丈夫でしょうか?また、そもそも別の部分がエラーの原因になっているのかもしれません。私のエラーの場合他にどのような原因が考えられるのでしょうか?\n\n### その他の原因として考えられることやこれまでに行った操作\n\n・Windows 10 or 11 (WSL2)のUbuntuでsystemctlを利用する方法(systemdをPID1で動作させる方法) \n<https://snowsystem.net/other/windows/wsl2-ubuntu-systemctl/> \nこちらの記事を参考にgenieをインストールしました。 \n・gem の mysql2がインストール出来なかったのでnodeを15系にダウングレードしています。(最終的にmysql2のgemはインストール出来ました)\n\n何かしらアドバイスがあればよろしくお願いいたします。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T00:38:33.263",
"favorite_count": 0,
"id": "86744",
"last_activity_date": "2022-03-08T00:38:33.263",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51193",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"mysql",
"wsl"
],
"title": "rails db:createができない",
"view_count": 335
} | [] | 86744 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "### 解決したいこと\n\nwsl2でmysqlがインストール出来ません。1つ前の質問のエラーがどうしても解消出来なかったので、brewコマンドを使い、wsl2でmysqlをインストールしてしまいました。参考にした記事はマックのものだったので、ちゃんと実行すべきかよく考えるべきでした(wsl2でbrewを使ってmysqlをインストールするという記事はなかった)。結局途中で出たエラーが解決出来なかったのでアンインストールして正式な方法でインストールし直すことにしました。ですが、ここでエラーが発生してしまいました。\n\n```\n\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt install mysql-server\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n The following NEW packages will be installed:\n mysql-server\n 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.\n 1 not fully installed or removed.\n Need to get 0 B/9544 B of archives.\n After this operation, 113 kB of additional disk space will be used.\n Selecting previously unselected package mysql-server.\n (Reading database ... 43180 files and directories currently installed.)\n Preparing to unpack .../mysql-server_8.0.28-0ubuntu0.20.04.3_all.deb ...\n Unpacking mysql-server (8.0.28-0ubuntu0.20.04.3) ...\n Setting up mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist\n dpkg: error processing package mysql-server-8.0 (--configure):\n installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2\n No apport report written because the error message indicates its a followup error from a previous failure.\n dpkg: dependency problems prevent configuration of mysql-server:\n mysql-server depends on mysql-server-8.0; however:\n Package mysql-server-8.0 is not configured yet.\n \n dpkg: error processing package mysql-server (--configure):\n dependency problems - leaving unconfigured\n Errors were encountered while processing:\n mysql-server-8.0\n mysql-server\n \n```\n\n間違って以前のログを消してしまったので、正確にはこのエラー画面ではない(このエラーは現在出ているエラー)のですが、内容は同じで依存関係に関するものでした。このエラーを解決するために、\n\n<https://stackoverflow.com/questions/67564215/problems-installing-mysql-on-\nubuntu-20-04>\n\nこの方の記事を参考にしてコマンドを実行しました。この時はコマンドが成功し、一見直ったかのように思い、再度mysqlのインストールを試みるも同じエラーが出てしまいました。参考にしたのはこのサイトです \n<https://docs.microsoft.com/ja-jp/windows/wsl/tutorials/wsl-database>\n\nこの時私は恐らくbrewを使ってインストールしたことが原因で依存関係がおかしくなってしまったのだと思い、homebrewをアンインストールしました。その後もう一度インストールを試そうと思ったらまた同じエラーが出てしまい、詰まってしまいました。更に困った事に、先ほどまで使えたコマンドが使えなくなってしまいました。このサイト \n<https://stackoverflow.com/questions/67564215/problems-installing-mysql-on-\nubuntu-20-04> \nのコマンドを実行しても\n\n```\n\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt autoremove\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n The following packages will be REMOVED:\n libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl\n libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl\n libio-html-perl liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8\n mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0\n 0 upgraded, 0 newly installed, 24 to remove and 0 not upgraded.\n 1 not fully installed or removed.\n After this operation, 262 MB disk space will be freed.\n Do you want to continue? [Y/n] Y\n (Reading database ... 43180 files and directories currently installed.)\n Removing mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n Removing libcgi-fast-perl (1:2.15-1) ...\n Removing libhtml-template-perl (2.97-1) ...\n Removing libcgi-pm-perl (4.46-1) ...\n Removing libhttp-message-perl (6.22-1) ...\n Removing libencode-locale-perl (1.05-1) ...\n Removing mysql-server-core-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n Removing libevent-pthreads-2.1-7:amd64 (2.1.11-stable-1) ...\n Removing libevent-core-2.1-7:amd64 (2.1.11-stable-1) ...\n Removing libfcgi-perl (0.79-1) ...\n Removing libhtml-parser-perl (3.72-5) ...\n Removing libhtml-tagset-perl (3.20-4) ...\n Removing libhttp-date-perl (6.05-1) ...\n Removing libio-html-perl (1.001-1) ...\n Removing liblwp-mediatypes-perl (6.04-1) ...\n Removing mecab-ipadic-utf8 (2.7.0-20070801+main-2.1) ...\n update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode\n Removing mecab-ipadic (2.7.0-20070801+main-2.1) ...\n Removing mecab-utils (0.996-10build1) ...\n Removing libmecab2:amd64 (0.996-10build1) ...\n Removing libtimedate-perl (2.3200-1) ...\n Removing liburi-perl (1.76-2) ...\n Removing mysql-client-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n Removing mysql-client-core-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n Removing mysql-common (5.8+1.0.5ubuntu2) ...\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n Package 'mysql-server' is not installed, so not removed\n 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt purge mysql-server\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n Package 'mysql-server' is not installed, so not removed\n 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt autoclean\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt remove dbconfig-mysql\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n Package 'dbconfig-mysql' is not installed, so not removed\n 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo systemctl stop mysql\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n Note, selecting 'mysql-server-core-5.5' for glob 'mysql-server-core-*'\n Note, selecting 'mysql-server-core-5.6' for glob 'mysql-server-core-*'\n Note, selecting 'mysql-server-core-5.7' for glob 'mysql-server-core-*'\n Note, selecting 'mysql-server-core-8.0' for glob 'mysql-server-core-*'\n Package 'mysql-server-core-5.7' is not installed, so not removed\n Package 'mysql-server-core-5.5' is not installed, so not removed\n Package 'mysql-server-core-5.6' is not installed, so not removed\n Note, selecting 'mysql-client-core-5.5' for glob 'mysql-client-core-*'\n Note, selecting 'mysql-client-core-5.6' for glob 'mysql-client-core-*'\n Note, selecting 'mysql-client-core-5.7' for glob 'mysql-client-core-*'\n Note, selecting 'mysql-client-core-8.0' for glob 'mysql-client-core-*'\n Package 'mysql-client-core-5.7' is not installed, so not removed\n Package 'mysql-client-core-5.5' is not installed, so not removed\n Package 'mysql-client-core-5.6' is not installed, so not removed\n Package 'mysql-client' is not installed, so not removed\n Package 'mysql-client-core-8.0' is not installed, so not removed\n reading /usr/share/mecab/dic/ipadic/Noun.name.csv ... 34202\n reading /usr/share/mecab/dic/ipadic/Postp-col.csv ... 91\n reading /usr/share/mecab/dic/ipadic/Noun.number.csv ... 42\n reading /usr/share/mecab/dic/ipadic/Auxil.csv ... 199\n reading /usr/share/mecab/dic/ipadic/Noun.place.csv ... 72999\n reading /usr/share/mecab/dic/ipadic/Filler.csv ... 19\n reading /usr/share/mecab/dic/ipadic/Noun.proper.csv ... 27328\n reading /usr/share/mecab/dic/ipadic/matrix.def ... 1316x1316\n emitting matrix : 100% |###########################################|\n \n done!\n update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode\n Setting up libhtml-parser-perl (3.72-5) ...\n Setting up libhttp-message-perl (6.22-1) ...\n Setting up mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist\n dpkg: error processing package mysql-server-8.0 (--configure):\n installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2\n Setting up libcgi-pm-perl (4.46-1) ...\n Setting up libhtml-template-perl (2.97-1) ...\n dpkg: dependency problems prevent configuration of mysql-server:\n mysql-server depends on mysql-server-8.0; however:\n Processing triggers for libc-bin (2.31-0ubuntu9.7) ...\n Errors were encountered while processing:\n mysql-server-8.0\n mysql-server\n E: Sub-process /usr/bin/dpkg returned an error code (1)\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt autoremove\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n 2 not fully installed or removed.\n After this operation, 0 B of additional disk space will be used.\n Setting up mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist\n \n dpkg: error processing package mysql-server (--configure):\n dependency problems - leaving unconfigured\n Errors were encountered while processing:\n mysql-server-8.0\n mysql-server\n E: Sub-process /usr/bin/dpkg returned an error code (1)\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt remove --purge mysql-server\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n The following packages were automatically installed and are no longer required:\n libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl\n libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl\n libio-html-perl liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8\n mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0\n Use 'sudo apt autoremove' to remove them.\n The following packages will be REMOVED:\n Setting up mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist\n dpkg: error processing package mysql-server-8.0 (--configure):\n installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2\n Errors were encountered while processing:\n mysql-server-8.0\n E: Sub-process /usr/bin/dpkg returned an error code (1)\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt purge mysql-server\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n Package 'mysql-server' is not installed, so not removed\n The following packages were automatically installed and are no longer required:\n libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl\n Setting up mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist\n dpkg: error processing package mysql-server-8.0 (--configure):\n installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2\n Errors were encountered while processing:\n mysql-server-8.0\n E: Sub-process /usr/bin/dpkg returned an error code (1)\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt autoclean\n Reading package lists... Done\n Building dependency tree\n mysql-server-8.0\n E: Sub-process /usr/bin/dpkg returned an error code (1)\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt remove --purge mysql-server\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n Package 'mysql-server' is not installed, so not removed\n The following packages were automatically installed and are no longer required:\n libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl\n libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl\n libio-html-perl liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8\n mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0\n Use 'sudo apt autoremove' to remove them.\n 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n 1 not fully installed or removed.\n After this operation, 0 B of additional disk space will be used.\n Setting up mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist\n dpkg: error processing package mysql-server-8.0 (--configure):\n installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2\n Errors were encountered while processing:\n mysql-server-8.0\n E: Sub-process /usr/bin/dpkg returned an error code (1)\n senseiy@senseIY-wsl:~/dictum/dictum$ sudo apt install mysql-server\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n The following NEW packages will be installed:\n mysql-server\n 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.\n 1 not fully installed or removed.\n Need to get 0 B/9544 B of archives.\n After this operation, 113 kB of additional disk space will be used.\n Selecting previously unselected package mysql-server.\n (Reading database ... 43180 files and directories currently installed.)\n Preparing to unpack .../mysql-server_8.0.28-0ubuntu0.20.04.3_all.deb ...\n Unpacking mysql-server (8.0.28-0ubuntu0.20.04.3) ...\n Setting up mysql-server-8.0 (8.0.28-0ubuntu0.20.04.3) ...\n update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist\n dpkg: error processing package mysql-server-8.0 (--configure):\n installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2\n No apport report written because the error message indicates its a followup error from a previous failure.\n dpkg: dependency problems prevent configuration of mysql-server:\n mysql-server depends on mysql-server-8.0; however:\n Package mysql-server-8.0 is not configured yet.\n \n dpkg: error processing package mysql-server (--configure):\n dependency problems - leaving unconfigured\n Errors were encountered while processing:\n mysql-server-8.0\n mysql-server\n \n```\n\nこのようにすべてのコマンドでエラーが出てしまうようになってしまいました。どうすればいいのか分かりません。何かしらアドバイスがあればよろしくお願いいたします。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T04:05:41.377",
"favorite_count": 0,
"id": "86745",
"last_activity_date": "2022-03-08T05:10:21.023",
"last_edit_date": "2022-03-08T04:52:19.220",
"last_editor_user_id": "51193",
"owner_user_id": "51193",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"mysql",
"wsl",
"homebrew"
],
"title": "wsl2でmysqlがインストール出来ない",
"view_count": 334
} | [
{
"body": "どうしても解決出来ないので、wsl2を初期化することにしました。ご協力ありがとうございました。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T05:10:21.023",
"id": "86749",
"last_activity_date": "2022-03-08T05:10:21.023",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51193",
"parent_id": "86745",
"post_type": "answer",
"score": 0
}
] | 86745 | null | 86749 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "### 聞きたいことの一行まとめ\n\nCSVデータの取得した内容が正しいかテストをしたい\n\n```\n\n <img title='entries_controller_spec_rb_—_Hairbook.png' alt='entries_controller_spec_rb_—_Hairbook' src='/attachments/02b2bf7f-c207-49b1-aa8d-fcd6a32b81eb' width=\"1280\" data-meta='{\"width\":1280,\"height\":254}'>\n \n```\n\n### 起きている問題(起きている現象の詳細/エラーメッセージ/スクリーンショット)\n\nキャンペーンに参加しているユーザーのCSVデータを取得し、内容が正しいかのテストを実行しようとしてます。 \n上記スクリーンショットの青枠を配列として取得したいがうまくできない。\n\n### ソースコード(関連するソースコード/全ソースコード)\n\n```\n\n describe 'GET /index_csv2' do\n subject { get(admin_campaign_entries_path(campaign, format: :csv)) }\n \n let(:campaign) { create(:campaign) }\n \n before do\n create_list(:campaign_entry, 2, campaign: campaign)\n create(:campaign_entry)\n end\n \n context 'CSVファイルをダウンロードしたとき' do\n it 'CSVデータが正しいこと' do\n subject\n \n expect(CSV.parse(response.body)).to include \"campaign_id_#{campaign.id}_entry_users.csv\"\n end\n end\n end\n \n```\n\n * expectの部分は記述している最中です。\n * expect箇所であるcsv.parse(response.body)でcreateしたキャンペーンユーザーの情報が取得できてますが配列がうまく取得できない。\n\n### 問題について自分なりに考えたこと(検索結果/自分なりの原因予想/切り分けた内容)\n\n * <https://qiita.com/san_you/items/1fea28b0ebb9c607889b> こちらの記事を参考にしようとしたが、配列をうまくとれない。\n\nruby初心者なのでうまくできず困っています。 \n何かしらアドバイスを頂ければ幸いです。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T04:46:57.467",
"favorite_count": 0,
"id": "86748",
"last_activity_date": "2022-03-08T05:33:24.973",
"last_edit_date": "2022-03-08T05:33:24.973",
"last_editor_user_id": "3060",
"owner_user_id": "51464",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"ruby"
],
"title": "CSVデータの内容が一致しているかをテスト",
"view_count": 184
} | [] | 86748 | null | null |
{
"accepted_answer_id": "86767",
"answer_count": 2,
"body": "なりすましメール対策について調べています。 \n自分で調べた結果、SPFがエンベロープFromの偽装の対策になることまでは理解できたのですが、 \nなりすましメール送信者の立場で考えた時に、エンベロープFromを偽装する必要性がよくわかりませんでした。\n\nようはエンベロープFromは偽装せずにヘッダFromを偽装すれば攻撃者としては充分目的を達成できるのでは?と感じてしまうのです。 \nSPFの仕組みだと、ヘッダFromだけを偽装している場合には全く機能しないと解釈しています。\n\n * 自前でドメインとメールサーバーを管理する、ということがそもそも難しいことなのでしょうか?\n * エンベロープFromを偽装するメリットは何かあるのでしょうか?\n * ヘッダFromだけを偽装しているケースへの対処方法はあるのでしょうか?\n\nメールやドメインについては疎いため、とんちんかんな質問かもしれませんがよろしくお願いいたします。 \nプログラミングではないのでそもそもスタック・オーバーフローでする質問ではないかもしれませんが・・・",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T05:38:42.783",
"favorite_count": 0,
"id": "86750",
"last_activity_date": "2022-03-09T03:16:13.720",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "17238",
"post_type": "question",
"score": 1,
"tags": [
"mail"
],
"title": "SPFとなりすましメール対策について",
"view_count": 327
} | [
{
"body": "> エンベロープFromを偽装するメリットは何かあるのでしょうか?\n\n一例として、「バックスキャッター」というスパムメール送信に利用されます。 \nenvelope from=<スパムメールを送りたいメールアドレス>, envelope to=<存在しないメールアドレス>\nにして、あるメールサーバーに送りつけます。 \nこのメールサーバーが User unknown で即時拒否すればいいのですが、一旦受け取ったあとに User unknown\nとなる構成の場合、バウンスメールが envelope from 宛に送られます。\n\nこのバウンスメールの送信元IPアドレスは、利用されたメールサーバーのもの、あるいは、その組織の別のメールサーバーのものになるので、ブラックリストに入ったとしてもスパム送信者には被害がないことになります。\n\n> ヘッダFromだけを偽装しているケースへの対処方法はあるのでしょうか?\n\nSender-ID (spf2.0) や DKIM があります。 \nSPF でも実装によってはヘッダ From も見るものもあるようです。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T08:55:14.233",
"id": "86754",
"last_activity_date": "2022-03-08T08:55:14.233",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4603",
"parent_id": "86750",
"post_type": "answer",
"score": 3
},
{
"body": "現在では、ヘッダーFromとエンベロープFromが一致しないと \n大体のメールソフトやセキュリティソフトは迷惑メール判定や警告されることが多いです。\n\nただしそれだと、正規のドメインの管理者が別のサーバからメール配信したいときなどに困ってしまうので、我々のメールはこのIPから送りますよというリストを公開するという手法をとっています。これがSPFになります。\n\nエンベロープが偽装していようが偽装していないが関係なく、 \n許可されていないIPからの送信は迷惑メール判定してもらって構わないという手法になります。\n\nただいまのクラウド時代に特定のIPだけに絞ったやり方はわりに合わない、IPも偽装されるような高度な攻撃の対応としてDKIMという電子署名を利用したIPを利用しないドメイン認証方式を採用したりします。 \nまたそれらを組み合わせてより強固なDMARCというセキュリティ対策を導入することもできます。\n\n> 自前でドメインとメールサーバーを管理する、ということがそもそも難しいことなのでしょうか?\n\nこの回答については難しいです。 \n運用者のスキルや環境また要件(メールを使ってどういったことをやりたいのか)によるところが大きいです。ただし、よくわからないなら外注するかPaasをおとなしく利用したほうが良いでしょう。\n\n> エンベロープFromを偽装するメリットは何かあるのでしょうか?\n\n他の方の回答でもありますが「バックスキャッター」という方式がありますので偽装すると成立する攻撃があります。ただメールサービスによってはエンベロープFROMのドメインとIPが正引き逆引きが正しく行えるかチェックしているサービスもあります。\n\n> ヘッダFromだけを偽装しているケースへの対処方法はあるのでしょうか?\n\nヘッダーだけ偽装しているケースに関してはそもそもヘッダーFROMとエンベロープFROMが一致していないと警告されるべきかなと思います。SPFを設定していればそもそも不許可のIPからの場合は弾かれます。 \n例えばGmailですと「経由」の文字が出てきます。 \n[Gmail\n送信者の横に表示される詳細情報](https://support.google.com/mail/answer/1311182?hl=ja#zippy=%2C%E9%80%81%E4%BF%A1%E8%80%85%E5%90%8D%E3%81%AE%E6%A8%AA%E3%81%AB%E7%B5%8C%E7%94%B1%E3%81%A8%E3%83%89%E3%83%A1%E3%82%A4%E3%83%B3%E5%90%8D%E3%81%8C%E8%A1%A8%E7%A4%BA%E3%81%95%E3%82%8C%E3%82%8B)\n\nあとはDKIM等の利用を考えてみるとよいでしょう。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T03:16:13.720",
"id": "86767",
"last_activity_date": "2022-03-09T03:16:13.720",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "22665",
"parent_id": "86750",
"post_type": "answer",
"score": 3
}
] | 86750 | 86767 | 86754 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "こんにちは。 \nGoogleAppsScriptのYoutubeDataApiのエラーについてお聞きしたいことがあります。 \n私はGASでスプレッドシートにある動画のリンクをYoutubeの再生リストに追加するプログラムを書いていて、 \nそのプログラムを走らせたときにこのようなエラーが出ました。\n\n```\n\n GoogleJsonResponseException: API call to youtube.playlistItems.list failed with error: Access Forbidden. The authenticated user cannot access this service.\n \n```\n\nこのエラーが出る前までは正常に追加処理が出来ていたのですが、 \nある日突然実行時にこのようエラーが出るようになってしまいました。\n\n```\n\n GoogleJsonResponseException:youtube.playlistItems.listへのAPI呼び出しが次のエラーで失敗しました:アクセスが禁止されています。 認証されたユーザーはこのサービスにアクセスできません。\n \n```\n\n直訳するとこのような内容になりますが、認証は初回実行時にやったつもりでいて、 \n一度Youtube Data Apiのサービスを消してから入れ直したのですがそれでも上のようなエラーが出てしまい、 \n正常にプログラムの実行をすることが出来ませんでした。\n\n# お聞きしたいこと\n\n * このエラーが出てしまう理由\n * このエラーの解決方法\n\n# 唯一思い当たること\n\n * 学校から配られたGoogle Workspaceアカウントを利用していること\n\n以上です。 \n詳しい方がいらっしゃいましたら、ご教示いただけると幸いです。 \nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T08:24:26.750",
"favorite_count": 0,
"id": "86751",
"last_activity_date": "2022-03-08T08:52:26.417",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51744",
"post_type": "question",
"score": 0,
"tags": [
"google-apps-script",
"youtube-data-api",
"youtube"
],
"title": "GAS Youtube Data Api アクセスの禁止",
"view_count": 203
} | [
{
"body": "Google Workspace では YouTube へのアクセスを管理者が制限できるようなので、こちらが影響している可能性があります。\n\n<https://support.google.com/a/answer/6212415?hl=ja>",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T08:52:26.417",
"id": "86753",
"last_activity_date": "2022-03-08T08:52:26.417",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3060",
"parent_id": "86751",
"post_type": "answer",
"score": 0
}
] | 86751 | null | 86753 |
{
"accepted_answer_id": "86757",
"answer_count": 1,
"body": "昨日までは `rails new` ができていたのですが、本日できなくなりました。\n\nエラーメッセージを読んでみましたが解決できていません。\n\n**環境**\n\nM1 Mac \nVScode\n\n**実行したこと**\n\n * `bundle init`\n * gem fileを編集\n * `rails new .`\n\n`rails new` の段階でエラーで進めません。\n\n**エラーメッセージ**\n\n_文字数制限の関係で後半部分のみ_\n\n```\n\n /Users/tee/Desktop/esf/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n /Users/tee/Desktop/esf/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.11.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'\n Tasks: TOP => app:template => environment\n (See full trace by running task with --trace)\n rails turbo:install stimulus:install\n You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.\n You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.\n \n```\n\n**Gemfile**\n\n```\n\n source \"https://rubygems.org\"\n git_source(:github) { |repo| \"https://github.com/#{repo}.git\" }\n \n ruby \"3.0.3\"\n gem \"rails\", \"~> 7.0.0\"\n gem \"sprockets-rails\"\n gem \"sqlite3\", \"~> 1.4\"\n gem \"puma\", \"~> 5.0\"\n gem \"importmap-rails\"\n gem \"turbo-rails\"\n gem \"stimulus-rails\"\n gem \"jbuilder\"\n gem \"tzinfo-data\", platforms: %i[ mingw mswin x64_mingw jruby ]\n gem \"bootsnap\", require: false\n \n \n \n group :development, :test do\n gem \"debug\", platforms: %i[ mri mingw x64_mingw ]\n end\n \n group :development do\n gem \"web-console\"\n end\n \n group :test do\n gem \"capybara\"\n gem \"selenium-webdriver\"\n gem \"webdrivers\"\n end\n \n```\n\nまた、この状態で `rails s` すると下記のメッセージが表示されます。\n\n何かわかるかたいらっしゃいましたら教えてください。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T10:00:16.197",
"favorite_count": 0,
"id": "86755",
"last_activity_date": "2022-03-08T11:27:32.960",
"last_edit_date": "2022-03-08T11:12:36.660",
"last_editor_user_id": "3060",
"owner_user_id": "51745",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"ruby"
],
"title": "rails new ができなくなった",
"view_count": 422
} | [
{
"body": "gemとrailsのversionをあげたら解決しました。。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T11:27:32.960",
"id": "86757",
"last_activity_date": "2022-03-08T11:27:32.960",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51745",
"parent_id": "86755",
"post_type": "answer",
"score": 0
}
] | 86755 | 86757 | 86757 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "html、cssがすこし触れる程度でjavascriptは主にコピペで使用している初心者です。\n\nスマホでハンバーガーメニューを作成した際、 \nメニューを全画面で開いた時に隠れているbody全体はスクロールしないようjQueryで設定していましたが、 \nメニューの中身がドロップダウンで開くようになるとbodyのスクロールが復活してしまいました。\n\nメニュー内のドロップダウンが開いたときはメニュー内部のみスクロールさせ、 \n背景のbodyは依然としてスクロールさせないようにしたいです。\n\n現在以下のようなコードになっています。 \n修正点ご指摘いただけますと幸いです。\n\n▼HTML\n\n```\n\n <div class=\"sp-only\">\n <div class=\"cp_fullscreenmenu\">\n <input class=\"toggle\" type=\"checkbox\" />\n <div class=\"hamburger\"><span></span></div>\n <!--ハンバーガーメニューを押したら開くメニューここから-->\n <div class=\"menu\">\n <div>\n <ul class=\"menu_ul\">\n <li class=\"drop click_down_1\">\n <a href=\"#\">あいうえお</a><span class=\"plus\"></span>\n <div class=\"sub_list_1\">\n <ul class=\"menu_close\">\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n </ul>\n </div>\n </li>\n <li class=\"drop click_down_2\">\n <a href=\"brand/index.html\">かきくけこ</a><span class=\"plus\"></span>\n <div class=\"sub_list_2\">\n <ul class=\"menu_close\">\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n </ul>\n </div>\n </li>\n <li class=\"drop click_down_3\">\n <a href=\"theme/index.html\">さしすせそ</a><span class=\"plus\"></span>\n <div class=\"sub_list_3\">\n <ul class=\"menu_close\">\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n <li><a href=\"#\">テキスト</a></li>\n </ul>\n </div>\n </li>\n <li class=\"nodrop\"><a href=\"about/index.html\">たちつてと</a><span></span></li>\n <li class=\"nodrop\"><a href=\"sustainability/index.html\">なにぬねの</a><span></span></li>\n <li class=\"nodrop\"><a href=\"https://www.rakuten.co.jp/\" target=\"_blank\">はひふへほ</a><span></span></li>\n </ul>\n </div>\n </div>\n <!--ハンバーガーメニューを押したら開くメニューここまで-->\n <div class=\"logo\"><a href=\"index.html\"><img src=\"images/logo.svg\" alt=\"ほげ\"></a></div>\n <div class=\"nav_icon\">\n <a href=\"javascript:void(0)\" class=\"open-btn\"><img src=\"images/search.svg\" width=\"17px\" alt=\"検索\"></a>\n <a href=\"\"><img src=\"images/cart.svg\" width=\"17px\" alt=\"ほげ\"></a>\n </div>\n </div>\n </div>\n \n```\n\n▼CSS\n\n```\n\n /*menuコンテンツ*/\n .cp_fullscreenmenu .menu {\n position: fixed;\n top: 0;\n left: 0;\n display: flex;\n visibility: hidden;\n overflow: hidden;\n width: 100%;\n height: 100%;\n pointer-events: none;\n outline: 1px solid transparent;\n \n -webkit-backface-visibility: hidden;\n backface-visibility: hidden;\n align-items: center;\n justify-content: center;\n }\n .cp_fullscreenmenu .menu > div {\n display: flex;\n overflow-y: scroll;\n width: 100%;\n height: 100%;\n \n text-align: left;\n color: #000000;\n background: rgba(245, 240, 233, 1);\n \n flex: none;\n -webkit-backface-visibility: hidden;\n backface-visibility: hidden;\n justify-content: center;\n padding-top: 20%;\n }\n .cp_fullscreenmenu .menu > div > ul {\n display: block;\n max-height: 100vh;\n margin: 0;\n padding: 0 1em;\n list-style: none;\n transition: opacity 0.4s ease;\n opacity: 0;\n }\n .cp_fullscreenmenu .menu > div > ul > li {\n font-size: 14px;\n font-family: 'Josefin Sans',\"游ゴシック\";\n display: block;\n margin: 1em;\n padding: 0;\n border-bottom: 1px solid #E6E1D9;\n padding-bottom: 14px;\n width: 84vw;\n }\n .cp_fullscreenmenu .menu > div > ul > li > a {\n position: relative;\n display: inline;\n cursor: pointer;\n transition: color 0.4s ease;\n \n }\n .cp_fullscreenmenu .menu > div > ul > li > a:hover {\n color: #e5e5e5;\n }\n .cp_fullscreenmenu .menu > div > ul > li > a:hover:after {\n width: 100%;\n }\n \n```\n\n▼JS\n\n```\n\n //メニュークリックでサブメニューを開く_あいうえお\n $(function(){\n $('.click_down_1').click(function () {\n $('.sub_list_1').slideToggle(0);\n });\n });\n \n //メニュークリックでサブメニューを開く_かきくけこ\n $(function(){\n $('.click_down_2').click(function () {\n $('.sub_list_2').slideToggle(0);\n });\n });\n \n //メニュークリックでサブメニューを開く_さしすせそ\n $(function(){\n $('.click_down_3').click(function () {\n $('.sub_list_3').slideToggle(0);\n });\n });\n \n \n //メニュークリックで+をーにする\n $(function(){\n $(function(){\n $(\".plus\").on(\"click\", function () {\n $(this).toggleClass(\"minus\");\n });\n });\n });\n \n \n \n //ハンバーガーメニュー開いた時にbodyを固定\n var state = false;\n var pos;\n $(\".cp_fullscreenmenu\").click(function() {\n if (state == false) {\n pos = $(window).scrollTop();\n $(\"body\").addClass(\"fixed\").css({\n \"top\": -pos});\n state = true;\n } else {\n $(\"body\").removeClass(\"fixed\").css({\n \"top\": 0});\n window.scrollTo(0, pos);\n state = false;\n }\n });\n \n });\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T10:03:09.633",
"favorite_count": 0,
"id": "86756",
"last_activity_date": "2022-03-08T10:03:09.633",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51214",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"html",
"css",
"jquery"
],
"title": "ハンバーガーメニューを開いている最中bodyはスクロールしない設定にしていたが、メニュー内のドロップダウンを開いた時メニュー内だけでなくbodyもスクロールしてしまいます",
"view_count": 990
} | [] | 86756 | null | null |
{
"accepted_answer_id": "86763",
"answer_count": 2,
"body": "### 実現したいこと\n\n`bundle exec`を省略したい\n\n### 発生している問題\n\n`--binstubs=vendor/bin`が非推奨になっているので、 \n今後推奨される`bundle binstubs --path=vendor/bin`のコマンドを打つとエラーメッセージが表示される\n\n### 表示されるエラー\n\n```\n\n `bundle binstubs` needs at least one gem to run.\n \n```\n\n### 使っているツールのバージョン等\n\nMac OS M1 \nVScode \nruby 3.1.0 \nrails \"~> 7.0.2\", \">= 7.0.2.2\"\n\n### rails new . に至るまでのコマンドの流れ\n\n 1. プロジェクトファイルを作成する \n`mkdir sample`\n\n 2. ファイル内でbundleを初期化 \n`bundle init`\n\n 3. Gemfileを編集する\n 4. gemのインストール先をローカルに設定 \n`bundle config set path 'vendor/bundle'`\n\n 5. bundle execを省略する設定 \n`bundle binstubs --path=vendor/bin`\n\n 6. gemをインストール \n`bundle install`\n\n 7. 新規Railsアプリケーションの作成 \n`rails new . -d postgresql`\n\n### 下記の設定もしています\n\nrails 環境構築部の`bundle exec`を省略する設定を有効にするために`.rbenv`に設定を加える必要がある\n\n```\n\n $ mkdir -p ~/.rbenv/plugins\n $ cd ~/.rbenv/plugins\n $ git clone https://github.com/ianheggie/rbenv-binstubs.git\n \n```\n\n### さいごに\n\n`bundle exec`をつければこのまま開発は続けられるが、 \n`rails g`コマンド等でも毎度`bundle exec`を打つのは非効率なので、できれば解決したいです。 \n何かわかる方教えてくださると嬉しいです。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T15:48:08.533",
"favorite_count": 0,
"id": "86762",
"last_activity_date": "2022-03-09T00:30:19.023",
"last_edit_date": "2022-03-08T16:07:03.357",
"last_editor_user_id": "3060",
"owner_user_id": "51745",
"post_type": "question",
"score": 2,
"tags": [
"ruby-on-rails",
"ruby",
"rubygems"
],
"title": "bundle execを省略したい",
"view_count": 362
} | [
{
"body": "`bundle binstubs`は実行可能なファイルを「引数で与えられたgemに対して」生成するコマンドです。 \n<https://bundler.io/man/bundle-binstubs.1.html> \nもし全てのgemに対してbinstubsを生成したい場合は、`--all`オプションを付ける必要があります。\n\n基本的には、`bundle\ninstall`コマンドを先に実行しておくとよいでしょう。そうすれば、Bundlerはインストールされたgemに対して処理を行うことができます。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-08T17:30:56.823",
"id": "86763",
"last_activity_date": "2022-03-08T17:30:56.823",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "442",
"parent_id": "86762",
"post_type": "answer",
"score": 1
},
{
"body": "`bundle exec` の文字数が多いのが問題なのであれば、`alias be='bundle exec'` などと alias\nを貼るのはよく見ます。プロジェクトごとに設定を確認するのが面倒なので、個人的には毎回 `bundle exec` が意識できる書き方にする方を好んでいます。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T00:30:19.023",
"id": "86764",
"last_activity_date": "2022-03-09T00:30:19.023",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "86762",
"post_type": "answer",
"score": 0
}
] | 86762 | 86763 | 86763 |
{
"accepted_answer_id": "86769",
"answer_count": 1,
"body": "※[他質問サイト](https://teratail.com/questions/jk5yzgfjbmj4aj)でも同様の質問をしています。解決した場合はそちらも更新します。よろしくお願いします。\n\n### 前提・実現したいこと\n\nrails、bootstrapでメニューバーを作成しています。 \n現在表示しているページのリンクを自動でアクティブな状態にしたいです。\n\n### 発生している問題・エラーメッセージ\n\nアクティブな状態が実装できません。 \n以下記事を参考に作成しました。 \n[サイドメニューのアクティブ・非アクティブ化](https://study-\ndiary.hatenadiary.jp/entry/2020/09/05/190836)\n\n\n\n### 該当のソースコード\n\n```\n\n app/helpers/application_helper.rb\n \n module ApplicationHelper\n (省略)\n def active_if(path)\n path == controller_path ? 'active' : ''\n end\n end\n \n```\n\n```\n\n app/views/users/_sidebar.html.erb\n \n <div class=\"col-auto col-md-3 col-xl-2 px-sm-2 px-0 bg-light\">\n <div class=\"d-flex flex-column align-items-center align-items-sm-start px-3 pt-2 text-white min-vh-100\">\n <ul class=\"nav nav-pills nav-fill flex-column mb-sm-auto mb-0 align-items-center align-items-sm-start\" id=\"menu\">\n <li class=\"nav-item\">\n \n <!-- 該当のコード -->\n <%= link_to mypage_path, class: \"nav-link align-middle px-0 #{active_if('mypage')}\" do %>\n <i class=\"fa-solid fa-house\"></i><span class=\"ms-1 d-none d-sm-inline\">マイページ</span>\n <% end %>\n </li>\n <li class=\"nav-item\">\n <%= link_to profile_path, class: \"nav-link align-middle px-0 #{active_if('profile')}\" do %>\n <i class=\"fa-solid fa-user\"></i><span class=\"ms-1 d-none d-sm-inline\">プロフィール</span>\n <% end %>\n </li>\n </ul>\n </div>\n </div>\n \n```\n\n```\n\n routes.rb\n \n Rails.application.routes.draw do\n get 'mypage', to: 'users#mypage'\n (省略)\n resource :profile\n (省略)\n end\n \n \n```\n\n### 試したこと\n\nclassに手動でactiveを付与するとアクティブな状態になるため、 \nヘルパーに問題があると思いますが、 \n参考記事と同じコードを使用しているのに実装できない原因がわかりません。 \n恐れ入りますがよろしくお願いいたします。\n\n### 補足情報(FW/ツールのバージョンなど)\n\nruby: 3.0.2 \nrails: 6.0.4 \nBootstrap: 5.0",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T02:34:00.950",
"favorite_count": 0,
"id": "86765",
"last_activity_date": "2022-03-09T05:27:45.703",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51475",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"ruby",
"bootstrap"
],
"title": "メニューバーのリンクが自動でアクティブ化しない",
"view_count": 135
} | [
{
"body": "`get 'mypage', to:\n'users#mypage'`というroutesの場合`/mypage`の時`controller_path`は`users`を返すので`class:\n\"nav-link align-middle px-0 #{active_if('users')}\"`だと`active`が付与されると思います。\n\nこう言った時は`binding.pry`で覗いてみるとすぐ問題点がわかります。\n\n```\n\n def active_if(path)\n binding.pry\n path == controller_path ? 'active' : ''\n end\n \n```\n\n本題とはそれますがコントローラーだけで判断するのは余計な時にも`active`がついちゃいそうなので、私は以前、こんな感じのヘルパーを作ったことがあります。\n\n```\n\n def current_page?(arg)\n arg.keys.all? {|key| params[key] == arg[key] }\n end\n \n```\n\n使う時はこんな感じ\n\n```\n\n current_page?(controller: 'users', action: 'mypage')\n \n```\n\n(このコード動かしてないのでダメだったら適当に修正お願いします)\n\nあと、手前味噌ですがHTMLのclassを動的に付与する場合[classnames-rails-\nview](https://github.com/gomo/classnames-rails-\nview)を使うと便利ですよ。jsで有名な[classnames](https://github.com/JedWatson/classnames)のマネですけど。\n\nこれを使えばこんな感じになります。\n\n```\n\n <%= link_to mypage_path, class: class_names('nav-link align-middle px-0', 'active': current_page?(controller: 'users', action: 'mypage')) do %>\n <i class=\"fa-solid fa-house\"></i><span class=\"ms-1 d-none d-sm-inline\">マイページ</span>\n <% end %>\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T05:27:45.703",
"id": "86769",
"last_activity_date": "2022-03-09T05:27:45.703",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "15048",
"parent_id": "86765",
"post_type": "answer",
"score": 0
}
] | 86765 | 86769 | 86769 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "typescriptで書いています。あるアプリケーションでサポートする言語(locale)が限定されていて、システムがそれ以外のlocaleを返したらデフォルトのlocaleにフォールバックするための関数を書きたいです。\n\n`/* currentLocaleがSupportedLocaleだったら */`はどう書けばいいのでしょうか?\n\n```\n\n type SupportedLocale = 'ja' | 'en';\n \n export function currentLocale() : SupportedLocale{\n // システムからlocaleを取る。\n const currentLocale = Localization.locale.split('-')[0];\n \n if(/* currentLocaleがSupportedLocaleだったら */){\n return currentLocale\n }\n \n return 'ja'; \n }\n \n```\n\n型ガードあたりで検索すると、以下の様な記述というのは出てきますが、これだとサポートするlocaleが増えた時、二箇所に変更を加えるのが嫌です。\n\n```\n\n export function currentLocale() : SupportedLocale{\n const currentLocale = Localization.locale.split('-')[0];\n \n if(currentLocale == 'ja' || currentLocale == 'en'){\n return currentLocale;\n }\n \n return 'ja'; \n }\n \n```\n\ntypeofはと思ったけど、これはそもそも`typeof currentLocale`が`string`だろうし、`'SupportedLocale'\nonly refers to a type, but is being used as a value\nhere.ts(2693)`と言われ左辺には置けないようですね。\n\n```\n\n if(typeof currentLocale === SupportedLocale){\n return currentLocale;\n }\n \n```\n\nユーザー定義型ガードというのを見つけて使ってみたけど、結局のところ二箇所にサポートlocaleの情報が散らばってしまいます。\n\n```\n\n export type SupportedLocale = 'ja' | 'en';\n \n const isSupportedLocale = (test: unknown): test is SupportedLocale => {\n if(test == 'ja' || test == 'en'){\n return true;\n }\n \n return false;\n };\n \n export function currentLocale() : SupportedLocale{\n const currentLocale = Localization.locale.split('-')[0];\n \n if(isSupportedLocale(currentLocale)){\n return currentLocale;\n }\n \n return 'ja'; \n }\n \n```\n\nまあ、やってることはIF文でやった型ガードを関数に切り出しただけですよね。サポートするlocaleのリストを一箇所だけに書いて、判定するにはどう書けばいいのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T04:41:19.297",
"favorite_count": 0,
"id": "86768",
"last_activity_date": "2022-03-10T03:47:02.260",
"last_edit_date": "2022-03-10T03:47:02.260",
"last_editor_user_id": "3060",
"owner_user_id": "15048",
"post_type": "question",
"score": 4,
"tags": [
"javascript",
"typescript"
],
"title": "typescriptで指定した文字列のどれかを返す関数を定義したい",
"view_count": 214
} | [
{
"body": "許容される値の配列から Union 型を生成することで、今回の問題を簡潔に解決できます。この手法は一般的に利用できるでしょう。\n\n```\n\n // refer https://stackoverflow.com/a/45257357\n const _SupportedLocale = [\n 'ja',\n 'en'\n ] as const\n type SupportedLocale = typeof _SupportedLocale[number]\n \n // refer https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates\n const _SupportedLocaleValues: readonly string[] = _SupportedLocale\n \n function isSupportedLocale(str: string): str is SupportedLocale {\n return _SupportedLocaleValues.includes(str)\n }\n \n /* apply it to your code...\n const DEFAULT_LOCALE: SupportedLocale = 'ja'\n \n export function currentLocale(): SupportedLocale {\n const currentLocale = Localization.locale.split('-')[0]\n if (isSupportedLocale(currentLocale)) {\n return currentLocale\n }\n return DEFAULT_LOCALE\n }\n */\n \n // for example...\n console.log('ja', isSupportedLocale('ja'))\n // true\n console.log('en', isSupportedLocale('en'))\n // true\n console.log('zh', isSupportedLocale('zh'))\n // false\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T05:31:42.963",
"id": "86770",
"last_activity_date": "2022-03-09T05:31:42.963",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "86768",
"post_type": "answer",
"score": 6
}
] | 86768 | null | 86770 |
{
"accepted_answer_id": "86773",
"answer_count": 1,
"body": "### 目標\n\nMicrosoft\nAzureのクラウド環境でつまづいた点を共有して、他の人にアドバイスをもらうために状態の共有や問題点の再現が出来るようにしたいと考えています。 \n手段として期待出来るものは、Azureの設定値をJSONエクスポートやGitHubでの共有を考えています。\n\n### これまで試したこと\n\nしかし、Azureの設定のExportの仕方などのドキュメントはありません。 \nまた、Microsoft公認の人は自分のやり方をよくGitHubにドキュメント化しています。 \nguestアカウントに希望する人を招待するやり方は必要な権限の付与があるため、あまり好ましくないと考えています。\n\n### 期待\n\nもっと簡単に、設定値をAzureCLIなどで設定するだけで開発者プログラム環境などへ反映が出来ないでしょうか?そうすれば、他の人のエラーの再現が出来ることや対処までの工数が減ると思います。",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T08:02:33.337",
"favorite_count": 0,
"id": "86771",
"last_activity_date": "2022-03-09T13:27:43.780",
"last_edit_date": "2022-03-09T10:57:12.167",
"last_editor_user_id": "3060",
"owner_user_id": "51724",
"post_type": "question",
"score": 0,
"tags": [
"azure"
],
"title": "Azure の環境設定を JSON 等でエクスポートすることは可能?",
"view_count": 435
} | [
{
"body": "リソースをテンプレートとしてエクスポートする機能があります。こちらを使うのはいかがでしょうか。\n\n<https://docs.microsoft.com/ja-jp/azure/azure-resource-\nmanager/templates/export-template-portal#export-template-from-a-resource-\ngroup>",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T13:27:43.780",
"id": "86773",
"last_activity_date": "2022-03-09T13:27:43.780",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "32948",
"parent_id": "86771",
"post_type": "answer",
"score": 0
}
] | 86771 | 86773 | 86773 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Linuxにおける、 \n多段ページングを学習しております。\n\nリニアアドレスが48ビット制限の場合、 \n1プロセスがフルフルに \n512×512×512×512×8バイトの512GBのテーブルを使い切ったとすると、 \nそのプロセスの物理メモリを食うサイズはいくつになりますでしょうか?\n\n計算式などを知りたいと思います。 \nよろしくお願いいたします。",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-09T10:35:25.420",
"favorite_count": 0,
"id": "86772",
"last_activity_date": "2022-03-09T10:35:25.420",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "45466",
"post_type": "question",
"score": 2,
"tags": [
"linux"
],
"title": "Linux 64ビット 1プロセス最大サイズ",
"view_count": 133
} | [] | 86772 | null | null |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "マルチポストしているのですがよろしくお願いします。 \n<https://teratail.com/questions/c842khs7083hca>\n\n以下の環境でlaravelとvue.jsでアプリ制作をしています。\n\n * MacOS\n * PHP 7.4.1\n * Laravel 6.20.26\n * PHPUnit 9.5.16\n\nPHPunitでテストをした際に RegisterApiTest.php が通らない原因がわからないでいます。\n\nRegisterApiTest.php\n\n```\n\n <?php\n \n namespace Tests\\Feature;\n \n use App\\User;\n use Tests\\TestCase;\n use Illuminate\\Foundation\\Testing\\WithFaker;\n use Illuminate\\Foundation\\Testing\\RefreshDatabase;\n \n class RegisterApiTest extends TestCase\n {\n use RefreshDatabase;\n \n /**\n * @test\n */\n public function should_新しいユーザーを作成して返却する()\n {\n $data = [\n 'name' => 'user',\n 'email' => '[email protected]',\n 'password' => 'test1234',\n 'password_confirmation' => 'test1234',\n ];\n (追記2でコメント機能解除)\n // dd($data);\n // 会員登録をroutes/api.php にルート定義\n // Route::post('/register', 'Auth\\RegisterController@register')->name('register');\n // コントローラーの影響でここで @register → RegistersUsers トレイトの register メソッド\n // → @registeredが必要→registeredを書き込む。これによって$dataが登録用データとして送られる\n // RegisterController で registered メソッドの中身をオーバーライド\n // $dataを送る\n (追記2でコメント機能解除)\n // dd($response);\n $response = $this->json('POST', route('register'), $data);\n \n \n $user = User::first();\n (1回目のテスト,ここがエディターの37行目に当たります)\n $this->assertEquals($data['name'], $user->name);\n (2回目のテストで上を省略)\n //$this->assertEquals($data['name'], $user->name);\n \n $response\n (ここが2回目のテストにおけるエディターの40行目に当たります)\n ->assertStatus(201)\n ->assertJson(['name' => $user->name]);\n }\n }\n \n```\n\nこれでテストを試したところ、ターミナルでは\n\n**1回目のテスト**\n\n```\n\n root@bf0269c31cae:/var/www/html# ./vendor/bin/phpunit tests/Feature/RegisterApiTest.php \n PHPUnit 9.5.16 by Sebastian Bergmann and contributors.\n \n E 1 / 1 (100%)\n \n Time: 00:01.960, Memory: 22.00 MB\n \n There was 1 error:\n \n 1) Tests\\Feature\\RegisterApiTest::should_新しいユーザーを作成して返却する\n ErrorException: Trying to get property 'name' of non-object\n \n /var/www/html/tests/Feature/RegisterApiTest.php:37\n \n ERRORS!\n Tests: 1, Assertions: 0, Errors: 1.\n \n```\n\nここからRegisterApiTest.phpの37行目でnameプロパティが、から(null?)なのだろうとまず考えました。\n\n次に問題の37行目をコメント機能で消したところ\n\n**2回目のテスト**\n\n```\n\n :/var/www/html# ./vendor/bin/phpunit tests/Feature/RegisterApiTest.php \n PHPUnit 9.5.16 by Sebastian Bergmann and contributors.\n \n F 1 / 1 (100%)\n \n Time: 00:03.398, Memory: 22.00 MB\n \n There was 1 failure:\n \n 1) Tests\\Feature\\RegisterApiTest::should_新しいユーザーを作成して返却する\n Expected status code 201 but received 405.\n Failed asserting that false is true.\n \n /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:186\n /var/www/html/tests/Feature/RegisterApiTest.php:40\n \n FAILURES!\n Tests: 1, Assertions: 1, Failures: 1.\n \n```\n\nこのことからresponseが上手く行っていないことからエラーが出るのでは?と判断して、ルーティングとメソッドを見に行きました。\n\nAPIのためにルーティングを少し変更しています。\n\napp/Providers/RouteServiceProvider.php を以下のようにしました。\n\n```\n\n protected function mapApiRoutes()\n {\n Route::prefix('api')\n // 'api' → 'web' に変更\n ->middleware('web') \n ->namespace($this->namespace)\n ->group(base_path('routes/api.php'));\n }\n \n```\n\napiに関するルーティングはroutes/api.php(routes/web.phpではありません)に書き込んで\n\nroutes/api.php\n\n```\n\n <?php\n \n use Illuminate\\Http\\Request;\n \n // 会員登録\n Route::post('/register', 'Auth\\RegisterController@register')->name('register');\n \n```\n\nメソッドはsrc/app/Http/Contorollers/auth/RegisterController.phpに以下を記述しています。\n\n```\n\n コード\n protected function registered(Request $request, $user)\n {\n return $user;\n }\n \n```\n\nどこで見落としているのかがわからないでいます。よろしくお願いします♂️\n\n### 追記\n\nlaravel6.0での \n$response = $this->json('POST', route('register'), $data); \nの書き方がおかしいのかな?と考えたのですが、6系のドキュメントにおいて\n\n<https://readouble.com/laravel/6.x/ja/http-tests.html>\n\n以下のようにあったので、ここは問題ないと思います。\n\n```\n\n public function testBasicExample()\n {\n $response = $this->json('POST', '/user', ['name' => 'Sally']);\n \n $response\n ->assertStatus(201)\n ->assertExactJson([\n 'created' => true,\n ]);\n }\n \n```\n\nPHPUnit.xml\n\n```\n\n <php>\n <env name=\"APP_ENV\" value=\"testing\"/>\n <env name=\"DB_CONNECTION\" value=\"sqlite_testing\"/>\n <server name=\"BCRYPT_ROUNDS\" value=\"4\"/>\n <server name=\"CACHE_DRIVER\" value=\"array\"/>\n <server name=\"DB_CONNECTION\" value=\"sqlite\"/>\n <server name=\"DB_DATABASE\" value=\":memory:\"/>\n <server name=\"MAIL_DRIVER\" value=\"array\"/>\n <server name=\"QUEUE_CONNECTION\" value=\"sync\"/>\n <server name=\"SESSION_DRIVER\" value=\"array\"/>\n </php>\n \n```\n\nconfig/database.php\n\n```\n\n 'connections' => [\n //追加\n 'sqlite_testing' => [\n 'driver' => 'sqlite',\n 'database' => ':memory:',\n 'prefix' => '',\n ],\n \n```\n\n追記2 \ndd()を利用して調べてみたのですがコメントが長すぎることもあるので重要そうな部分を抜粋して載せて行きたいと思います♂️dd()の場所とその内容は上記のテストコードにわかりやすいように記述しておきたいと思います。\n\n```\n\n dd($data);の場合\n \n root@bf0269c31cae:/var/www/html# ./vendor/bin/phpunit tests/Feature/RegisterApiTest.php\n PHPUnit 9.5.16 by Sebastian Bergmann and contributors.\n \n array:4 [\n \"name\" => \"user\"\n \"email\" => \"[email protected]\"\n \"password\" => \"test1234\"\n \"password_confirmation\" => \"test1234\"\n ]\n root@bf0269c31cae:/var/www/html#\n \n \n dd($response);の場合\n \n lluminate\\Foundation\\Testing\\TestResponse^ {#1169\n +baseResponse: Illuminate\\Http\\JsonResponse^ {#1209\n #data: \"\"\"\n {\\n\n \"message\": \"The POST method is not supported for this route. Supported methods: GET, HEAD.\",\\n\n \"exception\": \"Symfony\\\\Component\\\\HttpKernel\\\\Exception\\\\MethodNotAllowedHttpException\",\\n\n \"file\": \"/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php\",\\n\n \"line\": 256,\\n\n \"trace\": [\\n\n {\\n\n \n \n \n \"\"\"\n #version: \"1.0\"\n #statusCode: 405\n #statusText: \"Method Not Allowed\"\n #charset: null\n +original: array:5 [\n \"message\" => \"The POST method is not supported for this route. Supported methods: GET, HEAD.\"\n \"exception\" => \"Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException\"\n \"file\" => \"/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php\"\n \"line\" => 256\n \"trace\" => array:32 [\n \n \n \n +exception: Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException^ {#1185\n -statusCode: 405\n -headers: array:1 [\n \"Allow\" => \"GET, HEAD\"\n ]\n #message: \"The POST method is not supported for this route. Supported methods: GET, HEAD.\"\n #code: 0\n #file: \"./vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php\"\n #line: 256\n trace: {\n \n \n ./vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:442 { …}\n ./tests/Feature/RegisterApiTest.php:34 {\n Tests\\Feature\\RegisterApiTest->should_新しいユーザーを作成して返却する()^\n › // dd($data);\n › $response = $this->json('POST', route('register'), $data);\n › \n arguments: {\n $method: \"POST\"\n $uri: \"http://localhost/127.0.0.1/api/register\"\n $data: array:4 [ …4]\n }\n }\n \n \n }\n }\n #streamedContent: null\n }\n root@bf0269c31cae:/var/www/html# \n \n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T01:08:54.383",
"favorite_count": 0,
"id": "86774",
"last_activity_date": "2022-03-10T12:13:37.717",
"last_edit_date": "2022-03-10T11:07:04.587",
"last_editor_user_id": "51643",
"owner_user_id": "51643",
"post_type": "question",
"score": 0,
"tags": [
"php",
"laravel",
"vue.js",
"phpunit"
],
"title": "PHPUnitでのテストにおいて登録を確認するテストのresponseが上手くいかず、エラーが出てしまう",
"view_count": 525
} | [
{
"body": "ヘルパ関数 `route()` はURL を生成します。 \n<https://readouble.com/laravel/6.x/ja/helpers.html#method-route>\n\n```\n\n $response = $this->json('POST', route('register'), $data);\n \n```\n\n`json` メソッドの二番目の引数を `'api/register'` に改めるといかがでしょうか?",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T07:21:18.263",
"id": "86782",
"last_activity_date": "2022-03-10T07:21:18.263",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51722",
"parent_id": "86774",
"post_type": "answer",
"score": 0
},
{
"body": "自己解決しました。\n\n追記2内の `$uri: \"http://localhost/127.0.0.1/api/register\"` が明らかにおかしいことに気づき、元々\n`127.0.0.1` が記述されていた箇所を以下の通り変更したらとりあえず通りました。\n\n**変更前:**\n\n```\n\n REDIS_HOST=127.0.0.1\n APP_URL=127.0.0.1\n \n```\n\n**変更後:**\n\n```\n\n REDIS_HOST=db (dockerのmysqlに接続)\n APP_URL=\n \n```\n\nなのでどちらかの `127.0.0.1` が原因となってurlでおかしくなって通らなかったのだと思われます。ありがとうございました♂️",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T11:20:31.003",
"id": "86786",
"last_activity_date": "2022-03-10T12:13:37.717",
"last_edit_date": "2022-03-10T12:13:37.717",
"last_editor_user_id": "3060",
"owner_user_id": "51643",
"parent_id": "86774",
"post_type": "answer",
"score": 0
}
] | 86774 | null | 86782 |
{
"accepted_answer_id": "86796",
"answer_count": 1,
"body": "こんにちは、Dartで以下のような実装が可能か教えて下さい。\n\nDartで型判定を行う際には「is」を使用する方法がありますが、 \nこの「is」の右辺を動的な変数として置くことは可能でしょうか。\n\n例えば以下のような場合です。\n\n```\n\n void main() {\n final parameter = FormatException();\n final exceptions = [Exception];\n \n // これはできる\n print(parameter is Exception);\n \n for (final exception in exceptions) {\n // 構文エラー\n print(parameter is exception);\n }\n }\n \n```\n\n私の実装に必要なのはまさに構文エラーが出る「print(parameter is exception);」の部分で、 \n代替案があれば教えていただきたく思います。\n\nよろしくお願いします。\n\n== 以下追記 ==\n\nこの処理を必要とする理由を聞かれましたので、 \n以下のように回答します。\n\n現在とあるフレームワークを作成していまして、 \n上記の例にあるような形式でユーザーが指定した複数の例外の型を基にして、 \n実際に処理中で例外が発生した場合に指定された例外であれば処理をスキップする処理を追加しようとしています。\n\nそうなりますと先に挙げた構文エラーになる例のように \nユーザーが指定した例外の型と処理中で発生した例外と比較する必要があります。\n\n現状はどうしてもDart言語の仕様上「is」では構文エラーになるので文字列に直して比較していますが、 \nこの比較方法では例えばFormatExceptionがExceptionの子供だということがわかりません。\n\nそのため、今回の問題を解決する手段がDartにあるか質問させていただきました。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T06:19:46.783",
"favorite_count": 0,
"id": "86779",
"last_activity_date": "2022-03-11T05:11:28.487",
"last_edit_date": "2022-03-10T08:26:22.657",
"last_editor_user_id": "51316",
"owner_user_id": "51316",
"post_type": "question",
"score": 2,
"tags": [
"flutter",
"dart"
],
"title": "動的に型判定を行いたい",
"view_count": 245
} | [
{
"body": "## エラーが出ている理由\n\nDart 2.15 の時点で、`e is T` 形式の演算子では `T`\nの部分に具体的な型が要求されており、かつ、ここに値レベルの式を書いても評価されません。`parameter is exception` と書いたときに\n`The name 'exception' isn't defined, so it can't be used in an 'is'\nexpression.` というエラーになるのはこのためで、`exception` という名前の型を探しにいって見つからないのでエラーになっています。\n\nこの仕様は仕様書の \"Type Test\" のところに書かれています <https://dart.dev/guides/language/spec>\n\n## 部分的な解決案\n\nワークアラウンドとして、`runtimeType` と値として比較する方法はあります。\n\n```\n\n parameter.runtimeType == exception\n \n```\n\nただしこの方法でも部分型関係は表現できません。また Dart Tour では `runtimeType` の利用は非推奨になっています\n\n> In production environments, the test `object is Type` is more stable than\n> the test `object.runtimeType == Type`.\n\n<https://dart.dev/guides/language/language-tour#getting-an-objects-type>\n\nもし比較対象の型が関数引数か何かに渡されてくる想定なのであれば、少なくとも type test を使った検査は現状できないはずです。\n\n悩みますが、可能なのであれば、例外の方を渡してもらうのではなくて、例外側は固定して、例外を投げるべき場面でその例外を投げるようにしてもらう方が簡単かもしれません(ここについてはちょっと自信がありません)。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-11T05:11:28.487",
"id": "86796",
"last_activity_date": "2022-03-11T05:11:28.487",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "86779",
"post_type": "answer",
"score": 1
}
] | 86779 | 86796 | 86796 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "スプレッドシートのシートを複数作成したいのですが、応答なしで固まるためご教示ください。 \n待機を何度か押下すれば、問題なくシートの作成はできます。\n\nシート作成の処理が重くなるみたいですが改善策がわかりません。 \nどうぞよろしくお願いいたします。\n\n```\n\n let mySheet = SpreadsheetApp.getActiveSpreadsheet();\n var templateSheet = mySheet.getSheetByName('マスタ'); \n \n for(i=0;i<50,i++){\n mySheet.insertSheet(日報+i, 2+i, {template: templateSheet}); \n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T07:46:33.710",
"favorite_count": 0,
"id": "86783",
"last_activity_date": "2022-03-10T08:03:15.350",
"last_edit_date": "2022-03-10T08:03:15.350",
"last_editor_user_id": "3060",
"owner_user_id": "51773",
"post_type": "question",
"score": 0,
"tags": [
"google-apps-script"
],
"title": "スプレッドシートのシートを複数作成したいのですが、応答なしで固まる",
"view_count": 133
} | [] | 86783 | null | null |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Cent OS 7をクリーンインストール後にWeblogic 12.2.1.4をセットアップしようとしています。 \nOracleサイトから \n・jdk-8u311-linux-x64.rpm \n・fmw_12.2.1.4.0_wls_lite_Disk1_1of1.zip \nをダウンロードしてJDKのインストールに成功したのでWeblogic Serverをインストールしようとしましたが \n添付画像の通り、真っ白な画面が出てしまい継続できません。 \nWebも調べたのですが該当情報がなく、回避策をご存じの方はいらっしゃいませんか。 \n(Windows 10のPCで同じ手順をした場合は正常なインストーラが表示されました)\n\n```\n\n [xxxxx@xxxxxxx Downloads]$ java -jar ./fmw_12.2.1.4.0_wls_lite_generic.jar \n Launcher log file is /tmp/OraInstall2022-03-10_05-32-07PM/launcher2022-03-10_05-32-07PM.log.\n Extracting the installer . . . . Done\n Checking if CPU speed is above 300 MHz. Actual 3499.896 MHz Passed\n Checking monitor: must be configured to display at least 256 colors. Actual 4294967296 Passed\n Checking swap space: must be greater than 512 MB. Actual 3967 MB Passed\n Checking if this platform requires a 64-bit JVM. Actual 64 Passed (64-bit not required)\n Checking temp space: must be greater than 300 MB. Actual 38876 MB Passed\n Preparing to launch the Oracle Universal Installer from /tmp/OraInstall2022-03-10_05-32-07PM\n \n```\n\n[](https://i.stack.imgur.com/5tPLL.png)",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T08:38:55.313",
"favorite_count": 0,
"id": "86785",
"last_activity_date": "2022-03-10T09:19:46.877",
"last_edit_date": "2022-03-10T09:19:46.877",
"last_editor_user_id": "3060",
"owner_user_id": "51774",
"post_type": "question",
"score": 0,
"tags": [
"java",
"centos",
"oracle",
"weblogic"
],
"title": "CentOS7へのWeblogic 12インストーラで真っ白なインストーラ画面しか表示されない",
"view_count": 205
} | [] | 86785 | null | null |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "loginした日時を保存したいので、login_timeという名前のカラムを「DATETIME型、デフォルト値NULL」で追加しました。\n\n練習中ですので追加したテーブルには情報がいくつか入っています。 \n追加したlogin_timeだけNULLの状態です。\n\n```\n\n if (isset($_SESSION['customer'])) {\n date_default_timezone_set('Asia/Tokyo');\n \n $day = date('Y-m-d H:i:s');\n $id = $_SESSION['customer']['kaiin_id'];\n \n $sql = $pdo->prepare(\"update customer set login_time = '.$day.' where kaiin_id = '.$id.' \");\n $sql->execute();\n \n```\n\nエラーはでませんがphpmyadminを更新してもNULLのままで更新されません。\n\nなぜなのか教えて頂きたいです。\n\n初心者の頭で今考えているのは \n・DATETIMEのNULLには、updateは効かない?でもinsertではやりたい事(ログイン毎に時間を更新)はできない…と思う \n・途中から追加されたDATETIMEは更新できない?一度すべてのカラムを消去し、作成しなおす?\n\nよくわかりません。よろしくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T14:36:28.377",
"favorite_count": 0,
"id": "86787",
"last_activity_date": "2022-03-10T16:05:00.797",
"last_edit_date": "2022-03-10T16:05:00.797",
"last_editor_user_id": "3060",
"owner_user_id": "51781",
"post_type": "question",
"score": 0,
"tags": [
"php",
"mysql"
],
"title": "PHP でログイン日時を MySQL に保存したいができない",
"view_count": 89
} | [] | 86787 | null | null |
{
"accepted_answer_id": "86789",
"answer_count": 1,
"body": "以下のBクラスのメインメソッドを実行したいです。\n\n```\n\n package package_35;\n \n public class A {\n \n private void print() {\n System.out.println(\"A\");\n }\n \n public void a() {\n print();\n }\n }\n \n \n```\n\n```\n\n package package_35;\n \n public class B extends A {\n \n private void print() {\n System.out.println(\"B\");\n }\n \n public void b() {\n print();\n }\n \n public static void main(String[] args) {\n B b = new B();\n b.a();\n b.b();\n }\n }\n \n```\n\nコマンドプロンプトにて、以下の順でコンパイル、実行を試しましたが、例外出力されます。\n\n```\n\n javac A.java B.java\n java B.class\n \n```\n\n```\n\n エラー: メイン・クラスB.classを検出およびロードできませんでした\n 原因: java.lang.ClassNotFoundException: B.class\n \n```\n\n回答への返信と結果:DEWA Kazuyuki - 出羽和之 様の回答にて意図通りの動作を確認しました。ありがとうございます。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T17:02:21.830",
"favorite_count": 0,
"id": "86788",
"last_activity_date": "2022-03-12T05:30:08.877",
"last_edit_date": "2022-03-12T05:30:08.877",
"last_editor_user_id": "51783",
"owner_user_id": "51783",
"post_type": "question",
"score": 0,
"tags": [
"java"
],
"title": "継承クラスの実行時、java.lang.ClassNotFoundExceptionとなる",
"view_count": 750
} | [
{
"body": "* (大抵の場合)class ファイルは package に従ってファイルシステム上に配置されている必要がある\n * `java` コマンドは、 package 名も含めたクラス名を渡す \n * 質問文中で渡している `B.class` というのはファイル名なので誤り\n\nという点を満たす必要があります。\n\n具体的には、次のようにすれば良いです:\n\n```\n\n javac -d . A.java B.java\n java package_35.B\n \n```\n\n次の回答にもう少し詳細に説明を記述していますのでこちらも参照してみてください:\n\n * [Javaプログラムがターミナルから実行できない](https://ja.stackoverflow.com/a/54441/2808)\n\n(注: この回答はJava11のころに行ったもので、[Java17の\n`javac`](https://docs.oracle.com/javase/jp/17/docs/specs/man/javac.html)は仕様が追加されているようですが、今回の質問の範囲においては影響ありません)",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T23:15:59.310",
"id": "86789",
"last_activity_date": "2022-03-10T23:28:04.823",
"last_edit_date": "2022-03-10T23:28:04.823",
"last_editor_user_id": "2808",
"owner_user_id": "2808",
"parent_id": "86788",
"post_type": "answer",
"score": 0
}
] | 86788 | 86789 | 86789 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "超シンプルに言います。\n\n * 求人サービスだとします\n * ユーザーは法律の関係で週に40時間未満しか働けないので、応募採用時に40時間未満かチェックしないといけない\n\n以下採用時の処理です。\n\n```\n\n ActiveRecord::Base.transaction do\n check(user) # ユーザーの勤務時間が40時間未満かチェック、超えていた場合raiseする\n \n # 中略しますが、いろんな処理をする\n \n employ(user) # ユーザーを雇用する、具体的にはuserに紐づくapplication(応募)というレコードのstatusカラムを:employedにする等の処理が行われる\n end\n \n```\n\nしかし上記だと問題があります。 \nもし同時に別の会社から同ユーザーが採用ボタンを押された場合、両プロセスで、check(user)を通過してしまう可能性があります。\n\n排他ロックをすればいいのかなーと思って調べたのですが、 \nよく銀行の例えが用いられますが、ネットを調べてるとあくまで一つのレコードの更新時に、複数のプロセスから更新されないようにロックする話しか出てこないんですんね。 \n(例: [銀行の特定の人の口座レコード](https://reona.dev/posts/20210616))\n\n今回のケース、複数の会社から採用される場合というのは、応募のレコードはあくまでそれぞれ別のレコードなんですよね。\n\nそこで以下のように排他ロックを追加すればよいのかなと思いました。\n\n```\n\n ActiveRecord::Base.transaction do\n # ユーザーの全application(応募)をロックします。\n Application.lock.where(user_id: user_id ).lock('FOR UPDATE NOWAIT')\n \n check(user) \n \n # 中略しますが、いろんな処理をする\n \n employ(user) # ユーザーを雇用する、具体的にはuserに紐づくapplication(応募)というレコードのstatusカラムを:employedにする等の処理が行われる\n end\n \n```\n\nユーザーの全ての応募をロックしてしまいます。 \nそうすることで、他の会社が同ユーザーを採用しようとしても、同ユーザーの全ての応募はロックされていて読み取れないので、弾くことができるのではと思いました。\n\nこのような排他ロックの使い方は正しいでしょうか?",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-10T23:38:49.593",
"favorite_count": 0,
"id": "86790",
"last_activity_date": "2022-03-11T05:39:00.520",
"last_edit_date": "2022-03-11T05:39:00.520",
"last_editor_user_id": "40650",
"owner_user_id": "40650",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"rails-activerecord"
],
"title": "railsの排他ロックについて",
"view_count": 285
} | [] | 86790 | null | null |
{
"accepted_answer_id": "86795",
"answer_count": 1,
"body": "Python 3.9.10を使っています。\n\n```\n\n class cls_Common(object):\n \n def __init__(略)\n 以下略\n \n def Process_A():・・・①\n 以下略\n \n def Process_B():\n 前略\n \n self.Process_A():\n \n 以下略\n \n```\n\n* * *\n```\n\n class cls_main(cls_Common):\n \n def __init__(略)\n super().__init__(略)\n 以下略\n \n def Process_Z():\n super().Process_B():\n 以下略\n \n def Process_A():・・・②\n 以下略\n \n```\n\n* * *\n\nというクラス定義をした上で、\n\n```\n\n if __name__ == '__main__':\n print_hi('PyCharm')\n \n CLS = cls_main(略)\n CLS.Process_Z() ・・・③\n \n```\n\nとした場合、Process_Aは、最終的に②が呼ばれるのではないかと思います。 \n③のような場所から呼び出す前提で、Process_B内(またはcls_Common内)に何らかの処理(条件分岐など)を埋め込むことで、Process_Aの①、②を呼び分けることは可能ですか?\n\nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-11T01:48:38.503",
"favorite_count": 0,
"id": "86793",
"last_activity_date": "2022-03-11T04:12:15.890",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "43160",
"post_type": "question",
"score": 0,
"tags": [
"python3"
],
"title": "オーバーライドされた関数を基底クラスからの呼び分ける方法",
"view_count": 85
} | [
{
"body": "やりたい事と合っているか分かりませんが、以下のように単純に`cls_Common`側に変数/パラメータ/メソッドを定義して、それを元に呼び出し先を変更出来ると思われます。 \n変数はクラス/グローバル変数などでも出来るでしょうから、お好みで。\n\n```\n\n class cls_Common(object):\n def __init__(self):\n self.rootmode = False #### インスタンスにモード変数(例えばbool型)を定義して初期化\n print('Common.Init')\n \n def Process_A(self):\n print('Common.ProcessA')\n \n def Process_B(self):\n print('Common.ProcessB')\n if self.rootmode: #### インスタンスのモード変数に応じて呼び先変更\n cls_Common.Process_A(self)\n else:\n self.Process_A()\n \n def Process_C(self, root): #### モードを指定するパラメータを定義\n print('Common.ProcessC')\n if root: #### 指定されたパラメータに応じて呼び先変更\n cls_Common.Process_A(self)\n else:\n self.Process_A()\n \n def Process_M(self, mode): #### インスタンスのモード変数を変更するメソッド\n self.rootmode = mode\n print('Common.ProcessM')\n \n class cls_main(cls_Common):\n def __init__(self):\n super().__init__()\n print('Main.Init')\n \n def Process_Z(self):\n print('Main.ProcessZ')\n super().Process_B()\n \n def Process_A(self):\n print('Main.ProcessA')\n \n def Process_Y(self, root): #### パラメータを指定して呼び出すメソッド追加\n print('Main.ProcessY')\n super().Process_C(root)\n \n if __name__ == '__main__':\n CLS = cls_main()\n print('-----------0')\n CLS.Process_Z()\n print('-----------1')\n CLS.Process_M(True) #### cls_main側に対応するメソッドを追加しても良いがここでは直接呼出し\n print('-----------2')\n CLS.Process_Z()\n print('-----------3')\n CLS.Process_Y(False)\n print('-----------4')\n CLS.Process_Y(True)\n print('-----------5')\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-11T04:12:15.890",
"id": "86795",
"last_activity_date": "2022-03-11T04:12:15.890",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26370",
"parent_id": "86793",
"post_type": "answer",
"score": 0
}
] | 86793 | 86795 | 86795 |
{
"accepted_answer_id": "88242",
"answer_count": 1,
"body": "**実現したいこと** \nRealmのオブジェクトをiCloudにアップロード、ダウンロードすることにより、スマホを紛失してもデータを復元ができるアプリデータの永続化対応\n\n**発生している問題** \niCloudからダウンロードしたRealmのデータをアプリで見ようとするとエラーが発生します。\n\n**詳細なOK処理、NG処理**\n\n① iCloudにアップロード、アプリそのままで、iCloudからデータをダウンロード、データをアプリで見る → OK \n② iCloudにアップロード、アプリをBuildでインストール、iCloudからデータをダウンロード、データをアプリで見る → OK \n③ iCloudにアップロード、アプリを手で削除してBuildでインストール、iCloudからデータをダウンロード、データをアプリで見る → NG\n\n③が機種変をイメージしています。\n\n今回の件はiCloudは関係なく、外部から取り込んだRealmデータを反映する箇所に問題があると思って、色々調査しましたが、わかりませんでした。 \nお忙しいところ恐れ入りますが、どなたか、ご教示いただけると幸いです。\n\n**エラーメッセージ**\n\n```\n\n Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=2 \"Unable to open a realm at path '/var/mobile/Containers/Data/Application/BA8E4840-F570-4AE0-BBA0-EF3D9B8936B0/Documents/default.realm': Realm file has bad size (181) Path:Exception backtrace:\n 0 Realm 0x00000001064c7e10 _ZN5realm15InvalidDatabaseC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ + 60\n 1 Realm 0x0000000106491c74 _ZN5realm9SlabAlloc15validate_headerEPKcmRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE + 864\n 2 Realm 0x0000000106490f28 _ZN5realm9SlabAlloc11attach_fileERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERNS0_6ConfigE + 708\n \n```\n\n**ソースコード**\n\nClass1\n\n```\n\n private var _realm:Realm? = nil\n private var realm:Realm {\n get {\n if let realm2 = _realm {\n return realm2\n } else {\n let realm2 = try! Realm() // ※※※ エラー発生位置 ※※※\n _realm = realm2\n return realm2\n }\n }\n }\n \n```\n\nClass2\n\n```\n\n private let _fileManager = FileManager.default\n /// バックアップフォルダURL\n private var backupFolderUrl: URL{\n get {\n return _fileManager.url(forUbiquityContainerIdentifier: nil)!\n .appendingPathComponent(\"BackUp\")\n }}\n /// バックアップファイル名(前部)\n private let mBackupFileNamePre = \"default.realm_bk_\"\n \n /// Realmのデータを復元\n func restoreRealm() {\n guard let realmURL = Realm.Configuration.defaultConfiguration.fileURL else {\n print(\"Realmのファイルパスが取得できませんでした。\")\n return\n }\n // バックアップファイルの有無チェック\n let (exists, files) = isBackupFileExists()\n if exists {\n do {\n let config = Realm.Configuration()\n // 既存Realmファイル削除\n let realmURLs = [\n realmURL,\n realmURL.appendingPathExtension(\"lock\"),\n realmURL.appendingPathExtension(\"note\"),\n realmURL.appendingPathExtension(\"management\")\n ]\n for URL in realmURLs {\n do {\n try FileManager.default.removeItem(at: URL)\n } catch {\n print(error.localizedDescription)\n }\n }\n // バックアップファイルをRealmの位置にコピー\n try _fileManager.copyItem(at: backupFolderUrl.appendingPathComponent(files[files.count - 1]),\n to: realmURL)\n Realm.Configuration.defaultConfiguration = config\n abort() // 既存のRealmを開放させるため\n } catch {\n print(error.localizedDescription)\n }\n }\n }\n \n /// バックアップデータ作成処理\n /// RealmのデータをiCloudにコピー\n func backup() {\n do {\n /// iCloudにフォルダ作成\n if _fileManager.fileExists(atPath: backupFolderUrl.path) {\n } else {\n try _fileManager.createDirectory(atPath: backupFolderUrl.path, withIntermediateDirectories: false)\n }\n \n // 既存バックアップファイル(iCloud)の削除\n deleteBackup()\n // バックアップ作成先(iCloud)\n let fileName = mBackupFileNamePre + \"\" // 日付\n let fileUrl = backupFolderUrl.appendingPathComponent(fileName)\n // バックアップ作成\n try backupRealm(backupFileUrl: fileUrl)\n } catch {\n print(error.localizedDescription)\n }\n }\n \n /// Realmのデータファイルを指定ファイル名(フルパス)にコピー\n /// - Parameter backupFileUrl: 指定ファイル名(フルパス)URL\n private func backupRealm(backupFileUrl: URL) throws {\n do {\n let realm = try Realm()\n realm.beginWrite()\n try realm.writeCopy(toFile: backupFileUrl)\n realm.cancelWrite()\n } catch {\n throw error\n }\n }\n \n /// バックアップファイル削除\n func deleteBackup() {\n let (exists, files) = isBackupFileExists()\n if exists {\n do {\n for file in files {\n try _fileManager.removeItem(at: backupFolderUrl.appendingPathComponent(file))\n }\n } catch {\n print(error.localizedDescription)\n }\n }\n }\n \n /// バックアップフォルダにバックアップファイルがあるか、ある場合、そのファイル名を取得\n /// - Returns: バックアップファイルの有無、そのファイル名\n private func isBackupFileExists() -> (Bool, [String]) {\n var exists = false\n var files: [String] = []\n var allFiles: [String] = []\n // バックアップフォルダのファイル取得\n do {\n allFiles = try _fileManager.contentsOfDirectory(atPath: backupFolderUrl.path)\n } catch {\n return (exists, files)\n }\n // バックアップファイル名を選別\n for file in allFiles {\n if file.contains(mBackupFileNamePre) {\n exists = true\n files.append(file)\n }\n }\n return (exists, files)\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-03-11T01:49:24.650",
"favorite_count": 0,
"id": "86794",
"last_activity_date": "2022-04-09T12:17:34.680",
"last_edit_date": "2022-04-09T12:10:22.073",
"last_editor_user_id": "51780",
"owner_user_id": "51780",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"realm"
],
"title": "iCloudからダウンロードしたRealmのバックアップを用いてデータの復元",
"view_count": 361
} | [
{
"body": "自己解決しました。 \n事前に、 \nFileManager.default.startDownloadingUbiquitousItem(at:) \nにて、対象ファイルと同期をとることで、正常にRealmのデータを復元できました。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2022-04-09T12:17:34.680",
"id": "88242",
"last_activity_date": "2022-04-09T12:17:34.680",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "51780",
"parent_id": "86794",
"post_type": "answer",
"score": 2
}
] | 86794 | 88242 | 88242 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.