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": 1, "body": "楽天レシピAPI取得後、 \n「try JSONSerialization.jsonObject」でJSONに変換しようとしたのですが、 \nprint文で中身を確認したところ、下記のように表示され、変換されませんでした。 \nキャスト部分に問題があるのでしょうか。API自体に問題があるのでしょうか。 \nご教示いただけますと幸いです。よろしくお願いいたします。\n\n```\n\n [\"result\": {\n large = (\n {\n categoryId = 30;\n categoryName = \"\\U4eba\\U6c17\\U30e1\\U30cb\\U30e5\\U30fc\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/30/\";\n },\n {\n categoryId = 31;\n categoryName = \"\\U5b9a\\U756a\\U306e\\U8089\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/31/\";\n },\n {\n categoryId = 32;\n categoryName = \"\\U5b9a\\U756a\\U306e\\U9b5a\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/32/\";\n },\n {\n categoryId = 33;\n categoryName = \"\\U5375\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/33/\";\n },\n {\n categoryId = 14;\n categoryName = \"\\U3054\\U98ef\\U3082\\U306e\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/14/\";\n },\n {\n categoryId = 15;\n categoryName = \"\\U30d1\\U30b9\\U30bf\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/15/\";\n },\n {\n categoryId = 16;\n categoryName = \"\\U9eba\\U30fb\\U7c89\\U7269\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/16/\";\n },\n {\n categoryId = 17;\n categoryName = \"\\U6c41\\U7269\\U30fb\\U30b9\\U30fc\\U30d7\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/17/\";\n },\n {\n categoryId = 23;\n categoryName = \"\\U934b\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/23/\";\n },\n {\n categoryId = 18;\n categoryName = \"\\U30b5\\U30e9\\U30c0\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/18/\";\n },\n {\n categoryId = 22;\n categoryName = \"\\U30d1\\U30f3\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/22/\";\n },\n {\n categoryId = 21;\n categoryName = \"\\U304a\\U83d3\\U5b50\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/21/\";\n },\n {\n categoryId = 10;\n categoryName = \"\\U8089\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/10/\";\n },\n {\n categoryId = 11;\n categoryName = \"\\U9b5a\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/11/\";\n },\n {\n categoryId = 12;\n categoryName = \"\\U91ce\\U83dc\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/12/\";\n },\n {\n categoryId = 34;\n categoryName = \"\\U679c\\U7269\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/34/\";\n },\n {\n categoryId = 19;\n categoryName = \"\\U30bd\\U30fc\\U30b9\\U30fb\\U8abf\\U5473\\U6599\\U30fb\\U30c9\\U30ec\\U30c3\\U30b7\\U30f3\\U30b0\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/19/\";\n },\n {\n categoryId = 27;\n categoryName = \"\\U98f2\\U307f\\U3082\\U306e\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/27/\";\n },\n {\n categoryId = 35;\n categoryName = \"\\U5927\\U8c46\\U30fb\\U8c46\\U8150\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/35/\";\n },\n {\n categoryId = 13;\n categoryName = \"\\U305d\\U306e\\U4ed6\\U306e\\U98df\\U6750\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/13/\";\n },\n {\n categoryId = 20;\n categoryName = \"\\U304a\\U5f01\\U5f53\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/20/\";\n },\n {\n categoryId = 36;\n categoryName = \"\\U7c21\\U5358\\U6599\\U7406\\U30fb\\U6642\\U77ed\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/36/\";\n },\n {\n categoryId = 37;\n categoryName = \"\\U7bc0\\U7d04\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/37/\";\n },\n {\n categoryId = 38;\n categoryName = \"\\U4eca\\U65e5\\U306e\\U732e\\U7acb\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/38/\";\n },\n {\n categoryId = 39;\n categoryName = \"\\U5065\\U5eb7\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/39/\";\n },\n {\n categoryId = 40;\n categoryName = \"\\U8abf\\U7406\\U5668\\U5177\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/40/\";\n },\n {\n categoryId = 26;\n categoryName = \"\\U305d\\U306e\\U4ed6\\U306e\\U76ee\\U7684\\U30fb\\U30b7\\U30fc\\U30f3\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/26/\";\n },\n {\n categoryId = 41;\n categoryName = \"\\U4e2d\\U83ef\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/41/\";\n },\n {\n categoryId = 42;\n categoryName = \"\\U97d3\\U56fd\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/42/\";\n },\n {\n categoryId = 43;\n categoryName = \"\\U30a4\\U30bf\\U30ea\\U30a2\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/43/\";\n },\n {\n categoryId = 44;\n categoryName = \"\\U30d5\\U30e9\\U30f3\\U30b9\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/44/\";\n },\n {\n categoryId = 25;\n categoryName = \"\\U897f\\U6d0b\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/25/\";\n },\n {\n categoryId = 46;\n categoryName = \"\\U30a8\\U30b9\\U30cb\\U30c3\\U30af\\U6599\\U7406\\U30fb\\U4e2d\\U5357\\U7c73\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/46/\";\n },\n {\n categoryId = 47;\n categoryName = \"\\U6c96\\U7e04\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/47/\";\n },\n {\n categoryId = 48;\n categoryName = \"\\U65e5\\U672c\\U5404\\U5730\\U306e\\U90f7\\U571f\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/48/\";\n },\n {\n categoryId = 24;\n categoryName = \"\\U884c\\U4e8b\\U30fb\\U30a4\\U30d9\\U30f3\\U30c8\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/24/\";\n },\n {\n categoryId = 49;\n categoryName = \"\\U304a\\U305b\\U3061\\U6599\\U7406\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/49/\";\n },\n {\n categoryId = 50;\n categoryName = \"\\U30af\\U30ea\\U30b9\\U30de\\U30b9\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/50/\";\n },\n {\n categoryId = 51;\n categoryName = \"\\U3072\\U306a\\U796d\\U308a\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/51/\";\n },\n {\n categoryId = 52;\n categoryName = \"\\U6625\\Uff083\\U6708\\Uff5e5\\U6708\\Uff09\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/52/\";\n },\n {\n categoryId = 53;\n categoryName = \"\\U590f\\Uff086\\U6708\\Uff5e8\\U6708\\Uff09\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/53/\";\n },\n {\n categoryId = 54;\n categoryName = \"\\U79cb\\Uff089\\U6708\\Uff5e11\\U6708\\Uff09\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/54/\";\n },\n {\n categoryId = 55;\n categoryName = \"\\U51ac\\Uff0812\\U6708\\Uff5e2\\U6708\\Uff09\";\n categoryUrl = \"https://recipe.rakuten.co.jp/category/55/\";\n }\n );\n medium = (\n );\n small = (\n );\n }]\n \n```\n\n```\n\n //リクエスト\n let task : URLSessionTask = URLSession.shared.dataTask(with: url, completionHandler: {data, response, error in\n \n do {\n let recipeData = try JSONSerialization.jsonObject(with: data!,    options:JSONSerialization.ReadingOptions.allowFragments) as! [String : Any]\n \n print(recipeData)\n \n }\n catch{\n \n print(error)\n }\n }) \n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-22T08:50:57.453", "favorite_count": 0, "id": "67900", "last_activity_date": "2020-06-22T10:33:15.080", "last_edit_date": "2020-06-22T10:33:15.080", "last_editor_user_id": "3060", "owner_user_id": "40671", "post_type": "question", "score": 0, "tags": [ "swift", "json", "api" ], "title": "楽天レシピAPI取得後、JSONに変換したい", "view_count": 403 }
[ { "body": "JSON形式のAPIについて少し勘違いをしておられるようです。\n\nまず、 \n_**「楽天レシピAPI」は元々結果をJSON形式で返しています。それを「JSONに変換」する必要はありません**_\n\nAPIの返したJSON text形式のデータを見たければ、`try JSONSerialization.jsonObject`の **前**\nに次の一行を入れてみて下さい。\n\n```\n\n print(String(data: data!, encoding: .utf8)!)\n \n```\n\n* * *\n\nまた、 \n_**`JSONSerialization.jsonObject`はJSON形式のデータからiOS/Objective-C/(Swift)で扱えるデータ型に変換するもの**_\nです。\n\n「JSONに変換」するためのメソッドではありません。\n\n変換後の結果は以下のようなデータ型になります。\n\n```\n\n JSON object → NSDictionary\n JSON array → NSArray\n JSON string → NSString\n JSON number → NSNumber\n true/false → NSNumber\n \n```\n\nあなたのコードでは、変換後に一番外側の`NSDictionary`をSwiftの`Dictionary<String,\nAny>`型にさらに変換しているので、「Swiftの`Dictionary`形式」「`NSDictionary`形式」「`NSArray`形式」などが入り混じった形式で`print(recipeData)`の結果が表示されています。\n\n`print(error)`ではなく`print(recipeData)`が実行されていると言うことは、\n\n_**元のデータは正しいJSON形式であり、`JSONSerialization.jsonObject`での変換は成功した**_\n\nと言うことになります。\n\n* * *\n\n`print(recipeData)`の結果がJSON形式になっていないのは当たり前なので、そんなことは気にせずに **取得したデータをどう使うか**\n、を気にして下さい。\n\n例えば、以下のようなコードを実行すると、\n\n```\n\n do {\n \n if\n let jsonData = data,\n let recipeData = try JSONSerialization.jsonObject(with: jsonData) as? [String : Any],\n let result = recipeData[\"result\"] as? [String: Any],\n let large = result[\"large\"] as? [[String: Any]]\n {\n for category in large {\n print(category[\"categoryName\"] as? String ?? \"\")\n print(category[\"categoryUrl\"] as? String ?? \"\")\n }\n } else {\n print(\"Bad data\", data)\n }\n } catch{\n print(error)\n }\n \n```\n\n(このAPIの場合、`JSONSerialization.ReadingOptions.allowFragments`は意味を持たないと思われるので、`options:`の指定は省略してあります。)\n\nこんな出力が得られます。\n\n```\n\n 人気メニュー\n https://recipe.rakuten.co.jp/category/30/\n 定番の肉料理\n https://recipe.rakuten.co.jp/category/31/\n 定番の魚料理\n https://recipe.rakuten.co.jp/category/32/\n 卵料理\n https://recipe.rakuten.co.jp/category/33/\n ご飯もの\n https://recipe.rakuten.co.jp/category/14/\n パスタ\n https://recipe.rakuten.co.jp/category/15/\n 麺・粉物料理\n https://recipe.rakuten.co.jp/category/16/\n 汁物・スープ\n https://recipe.rakuten.co.jp/category/17/\n ...(以下略)\n \n```\n\n* * *\n\n何か疑問点などありましたら、この回答へコメントしてお知らせください。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-22T10:30:25.680", "id": "67902", "last_activity_date": "2020-06-22T10:30:25.680", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "67900", "post_type": "answer", "score": 0 } ]
67900
null
67902
{ "accepted_answer_id": "67911", "answer_count": 1, "body": "現在Java8の勉強をしています。 \nstreamでcarListの中に該当のcarIdがある場合、isExistをtrueにする処理を書きました。 \nforEachではとくにbooleanでもエラーにならなかったのですが、streamではAtomicBooleanにしろと言われました。\n\n**なぜなのでしょうか?またAtomicBooleanにするしかないのでしょうか?あまり見慣れないので進んで使っていいのかわかりません。**\n\nアドバイスいただけると幸いです。\n\n```\n\n // boolean isExist = false; //エラーになる\n AtomicBoolean isExist = new AtomicBoolean(false);\n for (car c:carList) {\n if(c.carId() == this.carId){\n isExist.set(true);\n }\n }\n \n carList.stream()\n .filter(c -> c.getCarId() == this.carId)\n .forEach(i -> isExist.set(true));\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-22T14:58:40.873", "favorite_count": 0, "id": "67905", "last_activity_date": "2020-06-23T04:42:25.167", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40231", "post_type": "question", "score": 3, "tags": [ "java", "java8", "stream" ], "title": "stream処理のラムダ式の中でbooleanの設定がエラーになるのがなぜか知りたい", "view_count": 563 }
[ { "body": "> streamではAtomicBooleanにしろと言われました。\n\n(コンパイルエラーとしては \"ラムダ式から参照されるローカル変数は、finalまたは事実上のfinalである必要があります\"\nなので、ここから`AtomicBoolean`に至るまでには少し飛躍があるように思われますが、疑問の関心には含まれていないようなので端折ります)\n\n* * *\n\n簡単に言うと、ストリーム操作はマルチスレッドで実行される可能性を考慮して実装する必要があるからです。\n\n[`Stream#forEach()`の説明](https://docs.oracle.com/javase/jp/11/docs/api/java.base/java/util/stream/Stream.html#forEach\\(java.util.function.Consumer\\))で次のように表現されています:\n\n> 与えられた任意の要素に対し、ライブラリが選択した任意のタイミングで任意のスレッド内でアクションが実行される可能性があります。\n> アクションが共有状態にアクセスする場合、必要な同期を提供する責任はアクションにあります。\n\n今回のコードでは、`AtomicBoolean`を使うことが「必要な同期を提供する」ことに当たります。\n\nまた、[`java.util.stream`のリファレンス](https://docs.oracle.com/javase/jp/11/docs/api/java.base/java/util/stream/package-\nsummary.html)にも説明があります。 \n特に、次の2つのセクションが今回の疑問の説明に関わってきます:\n\n * Parallelism\n * Side-effects\n\n* * *\n\n> またAtomicBooleanにするしかないのでしょうか?\n\n前述の[Side-\neffectsセクション](https://docs.oracle.com/javase/jp/11/docs/api/java.base/java/util/stream/package-\nsummary.html#package-summary.38qnK)で例として挙げられているコードの解説\n\n>\n> 並列実行時には、`ArrayList`がスレッドセーフでないために不正な結果が生成されますし、必要な同期を追加すれば競合が発生し、並列性のメリットが薄れます。\n> さらに言えば、ここで副作用を使用する必要はまったくありません。`forEach()`は単純に、より効率的で安全な、並列化により適したリダクション操作で置き換えることができます。\n\nが今回のコードにもそのまま当てはまります(対象が`ArrayList`ではない点を除いて)。\n\n今回のコードの場合、Stream APIを利用するのであれば\n\n```\n\n boolean isExist = carList.stream()\n .anyMatch(c -> c.getCarId() == this.carId);\n \n```\n\nとするのが妥当かと考えます。\n\nここで`anyMatch()`は[リファレンス](https://docs.oracle.com/javase/jp/11/docs/api/java.base/java/util/stream/Stream.html#anyMatch\\(java.util.function.Predicate\\))にある通り短絡操作であり、for-\nloopだと次のような操作に相当します。\n\n```\n\n boolean isExist = false;\n for (car c : carList) {\n if (c.carId() == this.carId) {\n isExist = true;\n break;\n }\n }\n \n```\n\nそうではなく、質問文の通りの、途中で`break`しないものに相当するコードにしたいのであれば、\n\n```\n\n boolean isExist = carList.stream()\n .map(c -> c.getCarId() == this.carId)\n .reduce(false, (res, cur) -> res | cur);\n \n```\n\nとなります([リダクション操作](https://docs.oracle.com/javase/jp/11/docs/api/java.base/java/util/stream/package-\nsummary.html#Reduction)参照)。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T03:51:34.707", "id": "67911", "last_activity_date": "2020-06-23T04:42:25.167", "last_edit_date": "2020-06-23T04:42:25.167", "last_editor_user_id": "2808", "owner_user_id": "2808", "parent_id": "67905", "post_type": "answer", "score": 2 } ]
67905
67911
67911
{ "accepted_answer_id": "67929", "answer_count": 2, "body": "GradleをインストールしたくHomebrewを利用しbrew install gradleをすると下記のようになりインストール出来ません。\n\n```\n\n ~ $ brew install gradle\n Updating Homebrew...\n ==> Auto-updated Homebrew!\n Updated 2 taps (homebrew/core and homebrew/cask).\n ==> New Formulae\n kde-kdoctools\n ==> Updated Formulae\n balena-cli epubcheck gatsby-cli jc pdftk-java\n citus erlang@22 graphene neon pnpm\n cpr fpc guile nest tnftpd\n diamond freerdp harfbuzz okteto tokei\n ==> Deleted Formulae\n marathon-swift\n ==> Updated Casks\n balenaetcher gpodder powerpanel ticktick\n boxcryptor mmex stellarium ximalaya\n google-chrome mps stremio\n \n ==> Downloading https://services.gradle.org/distributions/gradle-6.5-all.zip\n ==> Downloading from https://downloads.gradle-dn.com/distributions/gradle-6.5-al\n 0.6%\n curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54\n Error: Failed to download resource \"gradle\"\n Download failed: https://services.gradle.org/distributions/gradle-6.5-all.zip\n ~ $ \n \n \n```\n\n調べたところ「curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno\n54」というのがバッファの容量の問題と考えられ、「brew cleanup」をしキャッシュの削除をしましたが上記内容は変わりませんでした。 \nその他、考えられる原因がわからず手詰まりです。ご教授お願い致します。\n\n```\n\n ~ $ openssl version -a\n LibreSSL 2.8.3\n built on: date not available\n platform: information not available\n options: bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx) \n compiler: information not available\n OPENSSLDIR: \"/private/etc/ssl\"\n ~ $ brew -v\n Homebrew 2.4.1\n Homebrew/homebrew-core (git revision 0204; last commit 2020-06-22)\n Homebrew/homebrew-cask (git revision 575fd; last commit 2020-06-23)\n ~ $ sw_vers\n ProductName: Mac OS X\n ProductVersion: 10.15.5\n BuildVersion: 19F101\n ~ $ \n \n \n```", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-22T23:56:02.563", "favorite_count": 0, "id": "67907", "last_activity_date": "2020-06-24T02:31:16.993", "last_edit_date": "2020-06-23T03:11:28.397", "last_editor_user_id": "40666", "owner_user_id": "40666", "post_type": "question", "score": 1, "tags": [ "gradle", "homebrew" ], "title": "brew install gradle をするもcurl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54となりインストール出来ない", "view_count": 2062 }
[ { "body": "WiFiの2.4GHz→5GHzに変更したらダウンロード 出来ました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T14:21:40.267", "id": "67929", "last_activity_date": "2020-06-23T14:21:40.267", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40666", "parent_id": "67907", "post_type": "answer", "score": 1 }, { "body": "ネットの接続性が悪い場合になります(私の経験でも、公衆 Wi-Fi\nで混雑しているような場面でなったことがあります)。おそらく応答速度が遅いと、正常なデータを得られなかったと判断され、SSL\nのエラーとして報告されますが、実際は SSL の処理自体に問題があるわけではありません。\n\nたとえ Wi-Fi が 2.4GHz であったとしても、通信が安定している限り、問題はないはずです。2.4GHz か 5GHz\nかどうかは、本質的に問題の原因としては関係がないでしょう。@tk32 さんの通信環境では、5GHz の方が 2.4GHz\nのように帯域が混雑しておらず、接続が安定していた、というだけのことのはずです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T02:31:16.993", "id": "67936", "last_activity_date": "2020-06-24T02:31:16.993", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7290", "parent_id": "67907", "post_type": "answer", "score": 3 } ]
67907
67929
67936
{ "accepted_answer_id": "67919", "answer_count": 1, "body": "皆様はじめまして。 \nPythonを始めたばかりで今回質問させていただきました。\n\n指定のCSVファイル「input.csv」から内容を取り込み、書き出す際は「input.csv」の元ヘッダーは使わず、用意したヘッダーに差し替え、カンマ区切り、認識コードの列は除外して「output.csv」に出力しようとしています。\n\nしかし、ヘッダーは指定したものが書き出されていますが、整形された「input.csv」の内容が出力されません。\n\n**output.csv (出力されたCSV)**\n\n```\n\n 差出名称,内部印字区分,外部仕分区分\n \n \n \n```\n\n**実行時のエラーメッセージ**\n\n```\n\n Traceback (most recent call last):\n File \"csv_convert.py\", line 21, in <module>\n outptfile.write(row)\n TypeError: write() argument must be str, not list\n \n```\n\nエラーがTypeErrorということで正しい型の書き方にしないといけないのは理解できますが、恥ずかしながら思い通りな書き方が思いつかず、全体のコード自体も間違いだらけだと思いますが今回質問させていただきました。\n\nご教示頂ければ幸いです。どうぞよろしくお願い致します。\n\n**開発・実行環境** \nWindows 10 Home OSビルド19041.329 \nPython 3.7.7\n\n* * *\n\n**input.csv (読み込むCSV)**\n\n```\n\n 名称,印字区分,仕分区分,認識コード\n あいうえお,1,10,123456789012\n かきくけこ,3,6,987654321012\n \n```\n\n**csv_convert.py (実行コード)**\n\n```\n\n # coding: utf-8\n import csv\n \n inptfile = open(\"input.csv\",\"r\" , newline=\"\")\n outptfile = open(\"output.csv\",\"w\" , newline=\"\")\n \n outptfile.write(\"差出名称,内部印字区分,外部仕分区分\\n\")\n \n inptfile.readline()\n lines = inptfile.readlines()\n \n for line in lines:\n line = line.replace(\"\\n\",\"\")\n line = line.split(\",\")\n \n row = [\"{},{},{}\\n\".format(\n line[0],\n line[1],\n line[2]\n )]\n outptfile.write(row)\n \n inptfile.close()\n outptfile.close()\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T03:49:44.823", "favorite_count": 0, "id": "67910", "last_activity_date": "2020-06-24T15:51:57.133", "last_edit_date": "2020-06-24T15:51:57.133", "last_editor_user_id": "3060", "owner_user_id": "40769", "post_type": "question", "score": 1, "tags": [ "python", "csv" ], "title": "CSV を出力しようとすると TypeError: write() argument must be str エラーが発生する", "view_count": 7617 }
[ { "body": "ご明察の通り、エラーは「writeメソッドの引数は文字列型のみ受け付けています。リスト型はダメです」という内容です。 \nなので例えば[`str.join`](https://docs.python.org/ja/3/library/stdtypes.html#str.join)を使って、リスト型`row`に入っている要素を連結することで解決できます。\n\n変更前: `outptfile.write(row)` \n変更後: `outptfile.write(\"\".join(row))`\n\nこれだけでご所望の結果は取り出せると思います。\n\nこの他に[csvモジュール](https://docs.python.org/ja/3/library/csv.html)を使って頑張る方法もあります。\n\n```\n\n # coding: utf-8\n import csv\n \n with open(\"input.csv\", \"r\", newline=\"\") as inptfile, open(\"output.csv\",\"w\" , newline=\"\") as outptfile:\n reader = csv.DictReader(inptfile)\n \n write_fields = [\"差出名称\", \"内部印字区分\", \"外部仕分区分\"]\n writer = csv.DictWriter(outptfile, fieldnames=write_fields)\n writer.writeheader()\n for row in reader:\n writer.writerow({\"差出名称\": row[\"名称\"] ,\"内部印字区分\": row[\"印字区分\"], \"外部仕分区分\": row[\"仕分区分\"]})\n \n```\n\nもしPandasとDataframeをインストールして使うことができるならばさらに簡略化できます。 \n(インストール方法は別途検索してください)\n\n```\n\n # coding: utf-8\n import pandas as pd\n \n df = pd.read_csv(\"input.csv\", encoding = \"shift-jis\")\n df = df.drop(\"認識コード\", axis=1)\n df = df.rename(columns={\"名称\": \"差出名称\", \"印字区分\": \"内部印字区分\", \"仕分区分\": \"外部仕分区分\"})\n df.to_csv(\"output.csv\", index=False, encoding = \"shift-jis\")\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T06:43:24.683", "id": "67919", "last_activity_date": "2020-06-23T06:43:24.683", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "67910", "post_type": "answer", "score": 0 } ]
67910
67919
67919
{ "accepted_answer_id": "68188", "answer_count": 1, "body": "Windows10Pro64bitにunityhubをインストールし、適当なバージョンのunityをインストールしました \nライセンスはpersonalです \nプロジェクトを作成、保存、unityを終了した後、再度プロジェクトを開こうとしても、添付のエラーメッセージが一瞬表示されるのみで、unityhubのプロジェクト一覧画面に戻ってしまいます\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/Ml9id.png)](https://i.stack.imgur.com/Ml9id.png)\n\nunityは最新のバージョン以外にもいくつか試しましたが、いずれも同じ結果でした\n\nネットで検索し対応してみましたがだめでした \n・パスに全角文字を含めないこと \nユーザーは全角でしたが、インストールパス・プロジェクトパスは半角であることを確認しました \n・プロジェクトを起動する時にネットワークを無効にしておく \nサーバが見つからないというエラーになりました \n・マルウェア対策アプリを止めること \n止めましたが変わりありませんでした\n\nユーザー名が全角でしたので、新たにwindowsのローカルユーザーを作成し、unityhubのインストールから試してみましたが、結果は変わりませんでした \n対応方法ありましたら、教えていただけると助かります", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T04:36:10.920", "favorite_count": 0, "id": "67912", "last_activity_date": "2020-07-01T16:42:55.597", "last_edit_date": "2020-07-01T16:42:55.597", "last_editor_user_id": "3060", "owner_user_id": "27721", "post_type": "question", "score": 0, "tags": [ "unity3d" ], "title": "unityのプロジェクトが2度と開けなくなる", "view_count": 543 }
[ { "body": "自己解決しました \n私のPCにはネットワークアダプタがオンボード×1、WiFi×1がついています \nWiFiは使用しないので、Windowsのネットワーク接続を無効にしていました\n\nそれ(WiFi)を有効にします \n有線はそのまま使用します \nするとUnityのライセンス認証がエラーになるので、再度手動認証します \nそうすると、プロジェクトが開けるようになりました\n\n実はオンボードは2ついているのですが、有効にするとWindowsがハングアップするのでUEFIで無効にしています \nプロジェクトが開けるようになっても、WiFiを無効にするとまた開けなくなりました \nなのでWiFiもUEFIで無効にしてもよいかもしれませんが、試していません \nUnityのライセンス認証はネットワークアダプタが関係しているということが分かったので、色々ためした結果です", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-01T13:02:27.593", "id": "68188", "last_activity_date": "2020-07-01T13:02:27.593", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "27721", "parent_id": "67912", "post_type": "answer", "score": 2 } ]
67912
68188
68188
{ "accepted_answer_id": null, "answer_count": 0, "body": "### 質問内容\n\nWindows10Proで、LanmanServerを起動させる方法を知りたいです。\n\n### 背景\n\nある日PCを立ち上げた後、Docker Desktop for\nWindowsが立ち上がらなくなり、アンインストールして再インストールしようとしたところ、以下の画面が出ました。\n\n```\n\n Docker Desktop requires the Server service to be enabled.\n \n```\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/eGSDw.png)](https://i.stack.imgur.com/eGSDw.png)\n\n文言を読むに、LanmanServerが立ち上がってないことが原因だと思い、サービスを確認したところ、 \n想定通り起動していませんでした。\n\nこれを立ち上げようと思い、管理者権限で実行したコマンドプロンプトでLanmanServerを立ち上げようとしたところ、 \n下記のアクセス拒否が発生しました。 \n[![画像の説明をここに入力](https://i.stack.imgur.com/CpmGs.png)](https://i.stack.imgur.com/CpmGs.png)\n\nしかし、Administrator権限のユーザで操作しており、 \n拒否される要因がわかりません。 \nまた、Windowsを触った経験も少ないため、 \n他にどのような要因が影響しているか掴めない状況です。\n\n誠に恐縮ですが、 \nご教授をいただきたく存じます、", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T05:30:50.273", "favorite_count": 0, "id": "67913", "last_activity_date": "2020-06-23T05:30:50.273", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32566", "post_type": "question", "score": 0, "tags": [ "docker", "windows-10" ], "title": "LanmanServerが起動しない(Dockerインストールエラー)", "view_count": 684 }
[]
67913
null
null
{ "accepted_answer_id": "67915", "answer_count": 1, "body": "enumの重複したメンバーを文字列化すると定義の順番に関わらずどちらかの文字列に変換されるのですが、この法則がわかりません。 \nどのようなルールで文字列が決定されるのでしょうか?\n\n```\n\n using System;\n \n namespace EnumTest\n {\n class Program\n {\n // 例:System.Windows.Input.Key の一部\n public enum Key\n {\n Oem4 = 149,\n OemOpenBrackets = 149,\n Oem5 = 150,\n OemPipe = 150,\n }\n \n static void Main(string[] args)\n {\n Console.WriteLine(Key.Oem4);\n Console.WriteLine(Key.OemOpenBrackets);\n Console.WriteLine(Key.Oem5);\n Console.WriteLine(Key.OemPipe);\n \n // 出力結果:\n // OemOpenBrackets\n // OemOpenBrackets\n // Oem5\n // Oem5\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T05:34:34.003", "favorite_count": 0, "id": "67914", "last_activity_date": "2020-06-23T06:00:40.050", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "14817", "post_type": "question", "score": 3, "tags": [ "c#" ], "title": "C#のenumの重複したメンバーが文字列化されるときの法則は?", "view_count": 787 }
[ { "body": "法則は明示されていません。 \n現在の出力結果から法則性を見出しても、今後の実装で同一の結果が返ってくるとは限りません。\n\n[本家SOの関連質問](https://stackoverflow.com/q/26321509)\n\n[MSDN](https://docs.microsoft.com/en-\nus/dotnet/api/system.enum.tostring?view=netcore-3.1#System_Enum_ToString_System_String_)から\n_Notes to Callers_ を引用します。\n\n> If multiple enumeration members have the same underlying value and you\n> attempt to retrieve the string representation of an enumeration member's\n> name based on its underlying value, your code should not make any\n> assumptions about which name the method will return. For example, the\n> following enumeration defines two members, Shade.Gray and Shade.Grey, that\n> have the same underlying value.\n\n**雰囲気訳:**\n複数の列挙型の値が同一の基本値を持ち、基本値から列挙型メンバーの名前を文字列化しようとする場合、コードで(ToString)メソッドが返す名前を仮定しないでください。 \nたとえば、次の列挙は、同じ基本値を持つ2つのメンバー`Shade.Gray`と`Shade.Grey`を定義します。\n\n```\n\n enum Shade\n {\n White = 0, Gray = 1, Grey = 1, Black = 2\n }\n \n```\n\n> The following method call attempts to retrieve the name of a member of the\n> Shade enumeration whose underlying value is 1. The method can return either\n> \"Gray\" or \"Grey\", and your code should not make any assumptions about which\n> string will be returned.\n\n**雰囲気訳:** 次の(ToString)メソッドは、基本値が1であるShade列挙体のメンバーの名前を取得しようとします。 \nメソッドは \"Gray\"または \"Grey\"のどちらでも返すことができます。このコードを使用してどちらの文字列が返されるかについて想定しないでください。\n\n```\n\n string shadeName = ((Shade) 1).ToString(\"F\");\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T06:00:40.050", "id": "67915", "last_activity_date": "2020-06-23T06:00:40.050", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "67914", "post_type": "answer", "score": 3 } ]
67914
67915
67915
{ "accepted_answer_id": null, "answer_count": 1, "body": "RaisのomniauthでGoogleログインの実装を行っており、ローカル環境では正常に動作しています。 \nサーバー環境(CentOS, Nginx)ではGoogleの認証後に以下のようなURLにコールバックされた時、403エラーが表示されてしまいます。\n\n`https://dummy.com/auth/google_oauth2/callback?xxxxxxx&scope=email+https%3A%2F%2Fwww.googleapis.com&xxxxx`\n\n**403 Forbiddenの状況**\n\n[![403\nForbiddenの状況](https://i.stack.imgur.com/kp4bk.png)](https://i.stack.imgur.com/kp4bk.png)\n\n調査を進める中で、omniauthやGoogleログインに関わらず、以下のように「://」を含むURLにアクセスすると、同様のエラーが発生することが分かりました。\n\n(非エンコード) \n`https://dummy.com/?a=https://` \n(エンコード) \n`https://dummy.com/?a=https%3A%2F%2F`\n\nクエリパラメーターに `://`\nを含むアクセスを禁止するようなサーバーのセキュリティー関係の設定があるのかなと思っているのですが、思い当たる設定がある方がいたら、教えて頂けませんか。\n\nなお、この問題に関するRailsやNginxのエラーログやアクセスログへの出力はありません。\n\n### 環境\n\nCentOS7 \nNginx \nRails", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T06:04:52.483", "favorite_count": 0, "id": "67916", "last_activity_date": "2020-07-24T06:14:08.557", "last_edit_date": "2020-06-24T04:26:39.520", "last_editor_user_id": "3060", "owner_user_id": "12509", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "centos", "nginx", "security", "url" ], "title": "RaisのomniauthでGoogleログインのコールバック時に403エラーとなる", "view_count": 126 }
[ { "body": "調査の結果、AWSのWAFの設定で `://` を含むURLをブロックしていたのが問題でした。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T04:23:21.900", "id": "67942", "last_activity_date": "2020-07-24T06:14:08.557", "last_edit_date": "2020-07-24T06:14:08.557", "last_editor_user_id": "3060", "owner_user_id": "12509", "parent_id": "67916", "post_type": "answer", "score": 1 } ]
67916
null
67942
{ "accepted_answer_id": null, "answer_count": 1, "body": "# 概要\n\nkotlinを使用してAndroidアプリを開発しています。 \n開発しているアプリはニュースアプリのようなもので、クリップというお気に入り保存機能があります。 \nアプリ起動時にDBに保存されているクリップ一覧を取得し、lateinitのグローバル変数に保持していますが、一部のユーザーでlateinitがイニシャライズされていないというクラッシュが発生しています。\n\n```\n\n Unable to start activity ComponentInfo{xxx.xxx.xxx/xxx.xxx.xxx.activity.XXXActivity}: kotlin.UninitializedPropertyAccessException: lateinit property clipList has not been initialized\n \n```\n\n`clipList`はアプリ起動時に取得し、確実に取得しないとアプリを使用できないようにしてあるので、初期化漏れということはないはずです。 \nメモリ超過によりグローバル変数を保持しているシングルトンクラスが破棄されてしまっているのだと考えています。\n\n具体的な実装は下記に記しますが、applicationクラスを継承しているので破棄されないものと思っていましたが、こういったグローバル変数はどのように保持するのが正解なのでしょうか。\n\nご教示よろしくお願いいたします。\n\n# 実装\n\n**グローバル変数保持クラス**\n\n```\n\n class MyApp: Application() {\n \n // クリップ記事リスト(ClipAdviceは自作モデル)\n lateinit var clipList: ArrayList<ClipAdvice>\n \n override fun onCreate() {\n super.onCreate()\n }\n \n companion object {\n val sharedInstance: MyApp by lazy {\n MyApp()\n }\n }\n }\n \n```\n\n**グローバル変数にアクセスしているコード**\n\n```\n\n MyApp.sharedInstance.clipList.add(0, clip)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T06:30:35.430", "favorite_count": 0, "id": "67918", "last_activity_date": "2020-07-09T15:50:35.340", "last_edit_date": "2020-06-23T08:10:11.997", "last_editor_user_id": "3060", "owner_user_id": "15313", "post_type": "question", "score": 1, "tags": [ "android", "kotlin" ], "title": "androidアプリにおけるlateinitのグローバル変数を保持する方法", "view_count": 858 }
[ { "body": "androidにおいて、Applicationクラスに保持したデータは消えることがあります。 \n詳細は以下解説している記事をご確認ください。 \n<http://www.developerphil.com/dont-store-data-in-the-application-object/>\n\n記事中でもある様に、Activity間でデータを保持する場合、いくつか方法があります。\n\n * Activity間でIntentを用いてデータをやり取りする \n * これは環境にも依存しますが上限サイズが1MB程度が限度と言われています。\n * local database等を使用して永続化し、Activity毎に復元する\n * lateinitの代わりにnullで初期化しておき、常にnull checkを行う\n\n古い記事なので言及されておりませんが、以下の様なInterfaceを使用することも出来ます。\n\n * Allicationスコープで ViewModelStoreOwnerを使用する", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-09T15:50:35.340", "id": "68451", "last_activity_date": "2020-07-09T15:50:35.340", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39410", "parent_id": "67918", "post_type": "answer", "score": 1 } ]
67918
null
68451
{ "accepted_answer_id": "67923", "answer_count": 1, "body": ".NET Framework 4.7.2 \nMicrosoft Visual Studio Community 2019 \nVersion 16.6.2\n\n上記環境でシリアル通信を行うWPFアプリを作成しています。 \nSerialPortクラスのOpen(), Close()を下記のように連続で投げた場合にフリーズが発生します。\n\n```\n\n private bool CheckPortState()\n {\n var able = true;\n var mes = string.Empty;\n try\n {\n SelectedPort.Open();\n SelectedPort.Close();\n }\n catch(Exception e)\n {\n mes = e.Message;\n able = false;\n }\n \n var str = able ? \"Available.\" : \"Disable.\";\n Main.Instance.EventLogger.WriteLine($\"{SelectedPort.PortName} ... {str}\");\n if (!able)\n {\n Main.Instance.EventLogger.WriteLine(mes);\n }\n return able;\n }\n \n```\n\nここでOpen(), Close()を連続で投げているのは、 \n他のアプリケーションでポートが使用中の場合を検知するのに \nSerialPortクラスのIsOpenプロパティでは不十分なためです。\n\nこれを調査中、Open(), Close()の前後にそれぞれConsole出力を入れたところ \n現象が発生しなくなりました。 \nそこで、連続で投げていることが原因ではと考え、Open(), Close()間に \nThread.Sleep(1)を入れてみると、問題の症状はやはり発生しなくなりました。\n\n環境によって差があるのか、わかりませんが \n今後の参考にしたいので、この現象が一般的に発生するものなのか教えていただきたいです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T06:50:52.350", "favorite_count": 0, "id": "67921", "last_activity_date": "2020-06-23T07:21:32.810", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "38100", "post_type": "question", "score": 0, "tags": [ "c#", "wpf" ], "title": "SerialPortのOpen(), Close()を連続で投げるとフリーズする", "view_count": 3233 }
[ { "body": "ご質問の現象を指しているかは不明ですが、注意事項として書くくらいには一般的なようです。 \n日本語ページの文章はちょっとおかしいですが、英語ページをGoogle翻訳すると意味が通りそうです。\n\n[Remarks - SerialPort.Open\nMethod(System.IO.Ports)](https://docs.microsoft.com/en-\nus/dotnet/api/system.io.ports.serialport.open?view=dotnet-plat-\next-3.1#remarks)\n\n> **Remarks** \n> Only one open connection can exist per SerialPort object. \n> The best practice for any application is to wait for some amount of time\n> after calling the Close method before attempting to call the Open method, as\n> the port may not be closed instantly.\n\n> **備考** \n> SerialPortオブジェクトごとに存在できる接続は1つだけです。 \n>\n> すべてのアプリケーションのベストプラクティスは、ポートがすぐに閉じられない可能性があるため、Closeメソッドを呼び出した後、Openメソッドを呼び出す前にしばらく待機することです。\n\n* * *\n\nちなみに日本語ページの内容はこちら。 \n1つ目の文の方は逆に日本語ページの方が良さそうですが。\n\n[注釈](https://docs.microsoft.com/ja-\njp/dotnet/api/system.io.ports.serialport.open?view=dotnet-plat-\next-3.1#moniker-applies-to) リンクが壊れているのでその下の適用対象のアドレス\n\n> **注釈** \n> SerialPort オブジェクトごとに存在できる開いている接続は1つだけです。 \n> すべてのアプリケーションのベストプラクティスは、ポートが即座に閉じられない可能性があるため、Close メソッドを呼び出した後、Open\n> メソッドを呼び出した後にしばらく待つことです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T07:10:12.810", "id": "67923", "last_activity_date": "2020-06-23T07:21:32.810", "last_edit_date": "2020-06-23T07:21:32.810", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "67921", "post_type": "answer", "score": 1 } ]
67921
67923
67923
{ "accepted_answer_id": null, "answer_count": 1, "body": "pythonで(5, 5)の以下のような配列Xがあります。(数値は適当です。)\n\n```\n\n array([[59, 65, 57, 57, 62],\n [96, 81, 83, 83, 96],\n [53, 29, 30, 30, 53],\n [26, 0, 0, 0, 27],\n [20, 1, 5, 0, 19]], dtype=uint8)\n \n X.shape >>>(5, 5)\n \n```\n\nこのような配列を4つ合わせてshape(5, 5, 4)の以下のような配列X2作成したいのですが方法が良くわかりません。\n\n```\n\n array([[[59, 35, 26, 54],\n [65, 17, 22, 1],\n [12, 27, 47, 21],\n [14, 17, 37, 41],\n [11, 36, 42, 11]],\n         ・\n         ・\n         ・\n [[20, 25, 10, 3],\n [ 1, 15, 21, 42],\n [ 5, 25, 11, 3],\n [ 0, 4, 10, 23],\n [12, 14, 11, 32]]], dtype=uint8)\n \n X2.shape >>>(5, 5, 4)\n \n```\n\nどうしたらこのような処理ができるのか、どなたかご教授お願いします。\n\n以上.\n\n**追記** \nすみません。 \n元の2次元配列をそのまま3次元配列に並べる処理で、shapeは(4,5,5)になる形の処理でも大丈夫です。shapeの順番は問いません。 \nX2.shape >>>(4, 5, 5)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T06:59:16.433", "favorite_count": 0, "id": "67922", "last_activity_date": "2020-06-24T08:41:43.910", "last_edit_date": "2020-06-24T03:58:53.507", "last_editor_user_id": "36620", "owner_user_id": "36620", "post_type": "question", "score": 1, "tags": [ "python", "numpy", "array" ], "title": "python numpy配列でshape(5, 5)の配列から、(5, 5, 4)配列を作る方法", "view_count": 274 }
[ { "body": "出来るshapeが(4,5,5)で良いのなら、このページの記事が参考になるでしょう。 \n[NumPy配列ndarrayを結合(concatenate, stack, blockなど)](https://note.nkmk.me/python-\nnumpy-concatenate-stack-block/)\n\n`numpy`の`stack()`で一気に出来ます。 \n`Xa`,`Xb`,`Xc`,`Xd`という4つの2次元配列があったとすると:\n\n```\n\n X2 = np.stack([Xa, Xb, Xc, Xd], 0)\n \n```\n\n1つづつあるいは複数同士を結合するなら`concatenate()`でしょうね。 \n1つづつ増やす:\n\n```\n\n X3 = np.stack([Xa, Xb], 0)\n X3 = np.concatenate([X3, [Xc]])\n X3 = np.concatenate([X3, [Xd]])\n \n```\n\n2つの3次元配列を結合\n\n```\n\n X4 = np.stack([Xa, Xb], 0)\n X5 = np.stack([Xc, Xd], 0)\n X4 = np.concatenate([X4, X5])\n \n```\n\n続けるとこんな感じに\n\n```\n\n import numpy as np\n \n Xa = np.array([\n [1,2,3,4,5],\n [6,7,8,9,10],\n [11,12,13,14,15],\n [16,17,18,19,20],\n [21,22,23,24,25]\n ], dtype=np.uint8)\n \n Xb = np.array([\n [51,52,53,54,55],\n [56,57,58,59,60],\n [61,62,63,64,65],\n [66,67,68,69,60],\n [71,72,73,74,75]\n ], dtype=np.uint8)\n \n Xc = np.array([\n [101,102,103,104,105],\n [106,107,108,109,110],\n [111,112,113,114,115],\n [116,117,118,119,120],\n [121,122,123,124,125]\n ], dtype=np.uint8)\n \n Xd = np.array([\n [151,152,153,154,155],\n [156,157,158,159,160],\n [161,162,163,164,165],\n [166,167,168,169,160],\n [171,172,173,174,175]\n ], dtype=np.uint8)\n \n X2 = np.stack([Xa, Xb, Xc, Xd], 0)\n X2.shape\n \n X3 = np.stack([Xa, Xb], 0)\n X3 = np.concatenate([X3, [Xc]])\n X3 = np.concatenate([X3, [Xd]])\n X3.shape\n \n X4 = np.stack([Xa, Xb], 0)\n X5 = np.stack([Xc, Xd], 0)\n X4 = np.concatenate([X4, X5])\n X4.shape\n \n```\n\n* * *\n\nちなみに uint8\nのデータ型とか4つをひとまとめにすることとかからすると、R,G,B,Aの4つのプレーン毎のデータを合わせてフルカラーデータを求める感じでしょうか。\n\nそうすると当てはまるか(英語版はRGBの3つだけ)どうか不明ですが、こんな記事が参考になるかもしれません。 \n[Combine 3 separate numpy arrays to an RGB image in\nPython](https://stackoverflow.com/q/10443295/9014308) \n[Python, NumPyで画像処理(読み込み、演算、保存)](https://note.nkmk.me/python-numpy-image-\nprocessing/) \n[NumPyでRGB画像の色チャンネルを分離して単色化、白黒化、色交換](https://note.nkmk.me/python-numpy-rgb-\nimage-split-color/) : 分離する逆の操作ですが \n[How to extract R,G,B values with numpy into seperate\narrays](https://stackoverflow.com/q/41500637/9014308) : こちらも逆方向かつRGB\n\nOpenCVやPILにはそうした機能のメソッドがあるのかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T04:25:08.417", "id": "67943", "last_activity_date": "2020-06-24T08:41:43.910", "last_edit_date": "2020-06-24T08:41:43.910", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "67922", "post_type": "answer", "score": 1 } ]
67922
null
67943
{ "accepted_answer_id": null, "answer_count": 0, "body": "ffmpeg で h265エンコードを行いたいと考えています。 \nその際、特許のライセンスは各自で解決する必要があります。\n\n具体的にどこと契約をする必要があるのでしょうか", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T07:46:13.493", "favorite_count": 0, "id": "67925", "last_activity_date": "2020-06-23T12:03:59.990", "last_edit_date": "2020-06-23T12:03:59.990", "last_editor_user_id": "3060", "owner_user_id": "7978", "post_type": "question", "score": 1, "tags": [ "ffmpeg", "ライセンス" ], "title": "H.265 の利用にあたって、特許ライセンス問題を解決するにはどこと契約すればよいでしょうか?", "view_count": 1212 }
[]
67925
null
null
{ "accepted_answer_id": "67946", "answer_count": 1, "body": "ffmpeg-\npythonでvp9の動画をH.264にエンコードしたいのですが上手く行きません。vp9の動画ファイルとaacの音声ファイルを結合させるプログラムを書いたのですが、`vcodec`の値をlibx264かh264に変更すれば上手くできると思ったのですが途中に下記のエラーが出ます。\n\n**エラー**\n\n```\n\n ffmpeg version 4.2.3-static https://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2020 the FFmpeg developers\n built with gcc 8 (Debian 8.3.0-6)\n configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg\n libavutil 56. 31.100 / 56. 31.100\n libavcodec 58. 54.100 / 58. 54.100\n libavformat 58. 29.100 / 58. 29.100\n libavdevice 58. 8.100 / 58. 8.100\n libavfilter 7. 57.100 / 7. 57.100\n libswscale 5. 5.100 / 5. 5.100\n libswresample 3. 5.100 / 3. 5.100\n libpostproc 55. 5.100 / 55. 5.100\n Stream mapping:\n Stream #0:0 -> #0:0 (vp9 (native) -> h264 (libx264))\n Stream #1:0 -> #0:1 (copy)\n Press [q] to stop, [?] for help\n [libx264 @ 0x73895c0] using SAR=1/1\n [libx264 @ 0x73895c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX\n [libx264 @ 0x73895c0] profile High, level 5.1, 4:2:0, 8-bit\n [libx264 @ 0x73895c0] 264 - core 160 r3000 33f9e14 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00\n Output #0, mp4, to 'video/joined/scarlxrd - NEW LEVEL.mp4':\n Metadata:\n encoder : Lavf58.29.100\n Stream #0:0(eng): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 3840x2160 [SAR 1:1 DAR 16:9], q=-1--1, 25 fps, 12800 tbn, 25 tbc (default)\n Metadata:\n encoder : Lavc58.54.100 libx264\n Side data:\n cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1\n Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)\n Metadata:\n handler_name : SoundHandler\n Traceback (most recent call last): 0kB time=00:00:00.00 bitrate=N/A speed= 0x \n File \"test.py\", line 129, in <module>\n Downloader.join_audio_video()\n File \"test.py\", line 121, in join_audio_video\n ffmpeg.run(stream)\n File \"/home/vagrant/anaconda3/envs/test/lib/python3.7/site-packages/ffmpeg/_run.py\", line 325, in run\n raise Error('ffmpeg', out, err)\n ffmpeg._run.Error: ffmpeg error (see stderr output for detail)\n \n```\n\n途中まではしっかり動作しているような気がします。 \n**コード**\n\n```\n\n instream_v = ffmpeg.input(videopath)\n instream_a = ffmpeg.input(title_aac)\n stream = ffmpeg.output(instream_v, instream_a, title_join, vcodec=\"h264\", acodec=\"copy\") #ここのvscodecでエラー\n ffmpeg.run(stream)\n \n```\n\n下記のリンク先で似たような質問があったので`ffmpeg -formats`と`ffmpeg\n-codecs`を実行しましたがいずれにもh264、H.264の記述がありました。\n\n**ffmpeg -h 2 >&1 | grep 'enable-libx264'実行結果**\n\n```\n\n configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg\n \n```\n\nどなたか詳しい方教えて頂けると助かります。 \nよろしくお願いします。\n\n追記\n\n```\n\n ffmpeg.run(capture_stdout=True, capture_stderr=True)\n \n```\n\nこのコードを記述することでstderrの中身が確認可能ということで実行しましたが、下記のエラーが出力されました。\n\n```\n\n TypeError: run() missing 1 required positional argument: 'stream_spec'\n \n```\n\n`ffmpeg.run(stream_spec, capture_stdout=True,\ncapture_stderr=True)`これで実行してみたのですが、同じエラーが出力されます。\n\n[ffmpegのlibx264について質問です。](https://ja.stackoverflow.com/questions/17180/ffmpeg%E3%81%AElibx264%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E8%B3%AA%E5%95%8F%E3%81%A7%E3%81%99)", "comment_count": 10, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-23T09:31:38.910", "favorite_count": 0, "id": "67928", "last_activity_date": "2020-06-25T02:00:20.320", "last_edit_date": "2020-06-24T06:33:33.307", "last_editor_user_id": "22565", "owner_user_id": "22565", "post_type": "question", "score": 0, "tags": [ "python", "python3", "ffmpeg", "mp4" ], "title": "ffmpegでvp9の動画をH.264にエンコードしたい。", "view_count": 2050 }
[ { "body": "Vagrant の仮装環境内で実行していましたが、メモリ不足によるものでした。 \nメモリの割り当て量を 1GB → 4GB に増量することで正常に動作しました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T06:33:49.290", "id": "67946", "last_activity_date": "2020-06-25T02:00:20.320", "last_edit_date": "2020-06-25T02:00:20.320", "last_editor_user_id": "3060", "owner_user_id": "22565", "parent_id": "67928", "post_type": "answer", "score": 1 } ]
67928
67946
67946
{ "accepted_answer_id": null, "answer_count": 0, "body": "お世話になります。※1 データベース初学者です。\n\nExcelファイルをMySQLに読み込む方法についてお聞きしたいと思っております。\n\n[ExcelファイルをMySQLデータベースにインポートする方法](https://www.it-\nswarm.dev/ja/mysql/excel%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92mysql%E3%83%87%E3%83%BC%E3%82%BF%E3%83%99%E3%83%BC%E3%82%B9%E3%81%AB%E3%82%A4%E3%83%B3%E3%83%9D%E3%83%BC%E3%83%88%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/966948694/)\n\n上記のサイトを読みながら下記のようなExcelの表をMySQLに読み込んで操作したいと考えております。\n\n[![MySQLに読み込みたいExcelの表](https://i.stack.imgur.com/fIVDg.png)](https://i.stack.imgur.com/fIVDg.png)\n\nまずは、MySQLのコマンドプロンプトに `SHOW DATABASES;` を入力したら、下記のような出力がされたら幸いです。\n\n外部から特定のファイルを読み込むコマンドがMySQLにあると思うのですが、Googleで検索をかけても分からなかったのでこちらで質問させていただきました。\n\n```\n\n Country | Amount | Qty\n ----------------------------------\n America | 93 | 0.60\n Greece | 9377 | 0.80\n Australia | 9375 | 0.80\n \n```\n\n※2 手順通りにやれば、解決致しました。ご回答ありがとうございます。\n\n編集点 \n※1 自分が初心者であることを追加したこと。 \n※2 自己解決したこと。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T00:45:49.140", "favorite_count": 0, "id": "67933", "last_activity_date": "2020-06-24T01:24:37.463", "last_edit_date": "2020-06-24T01:24:37.463", "last_editor_user_id": "39846", "owner_user_id": "39846", "post_type": "question", "score": 0, "tags": [ "mysql", "excel" ], "title": "ExcelファイルをMySQLデータベースにインポートする方法について教えて下さい。", "view_count": 2476 }
[]
67933
null
null
{ "accepted_answer_id": "67941", "answer_count": 1, "body": "# 実現したいこと\n\nRailsアプリをHerokuへデプロイし、問題なくアプリを見れるようにすること\n\n# 環境\n\nRails:5.2.4 \nDB:PostgreSQL \nRubyのbuildpackはインストール済 \n(heroku create --buildpack <https://github.com/heroku/heroku-buildpack-\nruby.git>)\n\n# 今起こっている問題\n\n`git push heroku\nmaster`する際に、2つのエラーが発生しており、デプロイできないでいます。別々に対処していますが、全く解決の糸口が見えず、解決方法がございましたら、ご教示頂けますと幸いです。\n\n```\n\n remote: !\n remote: ! Precompiling assets failed.\n remote: !\n remote: ! Push rejected, failed to compile Ruby app.\n remote: \n remote: ! Push failed\n remote: Verifying deploy...\n remote: \n remote: ! Push rejected to [アプリ名]\n remote: \n To https://git.heroku.com/[アプリ名].git\n ! [remote rejected] master -> master (pre-receive hook declined)\n error: failed to push some refs to '[アプリ名].git'\n \n```\n\n# 試したこと\n\n### ①Precompiling assets failed.について\n\n下記コードで確認するも、`rake aborted`の表示により確認できず。\n\n`RAILS_ENV=production bundle exec rake assets:precompile`\n\nもう一度ログを辿ると、\n\n```\n\n remote: rake aborted!\n remote: LoadError: cannot load such file -- uglifier\n \n```\n\nを確認。そこで、[Heroku build fails on uglifier \n](https://stackoverrun.com/ja/q/7592880)の回答を参考に、下記を、`config/application.rb`に追記\n\n```\n\n config.assets.js_compressor = :uglifier\n \n \n```\n\nもう一度pushするが、結果は変わらず。\n\n### ②error: failed to push some refs to〜.gitについて\n\n[【Heroku】error: failed to push some refs toエラーの解決策 \n](https://algorithm.joho.info/heroku/error-failed-to-push-some-refs-\nto/)を参考に、下記を実行\n\n```\n\n $ git fetch\n $ git rebase heroku/master \n \n```\n\nしかし、これでpushしてもエラーが変わらず。そこで、強制的だが、gitの時と同じくこちらのコマンドで対応\n\n```\n\n $ git push -f heroku master \n \n```\n\nこちらも結果は変わりませんでした。\n\n# その他\n\nエラー全文と、Herokuのログを追記しました。\n\n### エラー全文\n\n```\n\n USER:tt.manager user$ git push heroku master\n Enumerating objects: 209, done.\n Counting objects: 100% (209/209), done.\n Delta compression using up to 8 threads\n Compressing objects: 100% (178/178), done.\n Writing objects: 100% (209/209), 181.92 KiB | 7.28 MiB/s, done.\n Total 209 (delta 29), reused 105 (delta 11)\n remote: Compressing source files... done.\n remote: Building source:\n remote: \n remote: -----> Ruby app detected\n remote: -----> Installing bundler 2.0.2\n remote: -----> Removing BUNDLED WITH version in the Gemfile.lock\n remote: -----> Compiling Ruby/Rails\n remote: -----> Using Ruby version: ruby-2.6.5\n remote: -----> Installing dependencies using bundler 2.0.2\n remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment\n remote: Your Gemfile lists the gem pg (>= 0.18, < 2.0) more than once.\n remote: You should probably keep only one of them.\n remote: Remove any duplicate entries and specify the gem only once (per group).\n remote: While it's not a problem now, it could cause errors if you change the version of one of them later.\n remote: The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.\n remote: Fetching gem metadata from https://rubygems.org/.........\n remote: Fetching rake 13.0.1\n remote: Installing rake 13.0.1\n remote: Fetching concurrent-ruby 1.1.6\n remote: Fetching minitest 5.14.1\n remote: Fetching thread_safe 0.3.6\n remote: Installing thread_safe 0.3.6\n remote: Installing concurrent-ruby 1.1.6\n remote: Installing minitest 5.14.1\n remote: Fetching builder 3.2.4\n remote: Fetching erubi 1.9.0\n remote: Installing builder 3.2.4\n remote: Installing erubi 1.9.0\n remote: Fetching mini_portile2 2.4.0\n remote: Installing mini_portile2 2.4.0\n remote: Fetching crass 1.0.6\n remote: Installing crass 1.0.6\n remote: Fetching rack 2.2.2\n remote: Fetching nio4r 2.5.2\n remote: Installing rack 2.2.2\n remote: Installing nio4r 2.5.2 with native extensions\n remote: Fetching websocket-extensions 0.1.5\n remote: Installing websocket-extensions 0.1.5\n remote: Fetching mini_mime 1.0.2\n remote: Installing mini_mime 1.0.2\n remote: Fetching arel 9.0.0\n remote: Installing arel 9.0.0\n remote: Fetching mimemagic 0.3.5\n remote: Installing mimemagic 0.3.5\n remote: Fetching execjs 2.7.0\n remote: Installing execjs 2.7.0\n remote: Fetching bcrypt 3.1.13\n remote: Fetching msgpack 1.3.3\n remote: Installing bcrypt 3.1.13 with native extensions\n remote: Installing msgpack 1.3.3 with native extensions\n remote: Fetching popper_js 1.16.0\n remote: Installing popper_js 1.16.0\n remote: Fetching method_source 1.0.0\n remote: Installing method_source 1.0.0\n remote: Fetching thor 1.0.1\n remote: Installing thor 1.0.1\n remote: Fetching ffi 1.13.0\n remote: Installing ffi 1.13.0 with native extensions\n remote: Fetching tilt 2.0.10\n remote: Installing tilt 2.0.10\n remote: Using bundler 2.0.2\n remote: Fetching cocoon 1.2.14\n remote: Installing cocoon 1.2.14\n remote: Fetching coderay 1.1.3\n remote: Installing coderay 1.1.3\n remote: Fetching orm_adapter 0.5.0\n remote: Installing orm_adapter 0.5.0\n remote: Fetching devise-bootstrap-views 1.1.0\n remote: Installing devise-bootstrap-views 1.1.0\n remote: Fetching devise-i18n-views 0.3.7\n remote: Installing devise-i18n-views 0.3.7\n remote: Fetching multi_json 1.14.1\n remote: Installing multi_json 1.14.1\n remote: Fetching hpricot 0.8.6\n remote: Installing hpricot 0.8.6 with native extensions\n remote: Fetching kaminari-core 1.2.1\n remote: Installing kaminari-core 1.2.1\n remote: Fetching pg 1.2.3\n remote: Installing pg 1.2.3 with native extensions\n remote: Fetching temple 0.8.2\n remote: Installing temple 0.8.2\n remote: Fetching turbolinks-source 5.2.0\n remote: Installing turbolinks-source 5.2.0\n remote: Fetching tzinfo 1.2.7\n remote: Installing tzinfo 1.2.7\n remote: Fetching nokogiri 1.10.9\n remote: Installing nokogiri 1.10.9 with native extensions\n remote: Fetching i18n 1.8.2\n remote: Installing i18n 1.8.2\n remote: Fetching websocket-driver 0.7.2\n remote: Installing websocket-driver 0.7.2 with native extensions\n remote: Fetching mail 2.7.1\n remote: Installing mail 2.7.1\n remote: Fetching rack-test 1.1.0\n remote: Installing rack-test 1.1.0\n remote: Fetching sprockets 4.0.0\n remote: Installing sprockets 4.0.0\n remote: Fetching warden 1.2.8\n remote: Installing warden 1.2.8\n remote: Fetching request_store 1.5.0\n remote: Installing request_store 1.5.0\n remote: Fetching rack-proxy 0.6.5\n remote: Installing rack-proxy 0.6.5\n remote: Fetching marcel 0.3.3\n remote: Installing marcel 0.3.3\n remote: Fetching autoprefixer-rails 9.7.6\n remote: Installing autoprefixer-rails 9.7.6\n remote: Fetching puma 4.3.5\n remote: Installing puma 4.3.5 with native extensions\n remote: Fetching pry 0.13.1\n remote: Installing pry 0.13.1\n remote: Fetching bootsnap 1.4.6\n remote: Installing bootsnap 1.4.6 with native extensions\n remote: Fetching sassc 2.3.0\n remote: Installing sassc 2.3.0 with native extensions\n remote: Fetching slim 4.1.0\n remote: Installing slim 4.1.0\n remote: Fetching turbolinks 5.2.1\n remote: Installing turbolinks 5.2.1\n remote: Fetching activesupport 5.2.4.3\n remote: Installing activesupport 5.2.4.3\n remote: Fetching html2slim 0.2.0\n remote: Fetching loofah 2.5.0\n remote: Installing loofah 2.5.0\n remote: Installing html2slim 0.2.0\n remote: Fetching pry-rails 0.3.9\n remote: Installing pry-rails 0.3.9\n remote: Fetching rails-dom-testing 2.0.3\n remote: Installing rails-dom-testing 2.0.3\n remote: Fetching globalid 0.4.2\n remote: Installing globalid 0.4.2\n remote: Fetching activemodel 5.2.4.3\n remote: Installing activemodel 5.2.4.3\n remote: Fetching jbuilder 2.10.0\n remote: Installing jbuilder 2.10.0\n remote: Fetching rails-html-sanitizer 1.3.0\n remote: Fetching activejob 5.2.4.3\n remote: Installing rails-html-sanitizer 1.3.0\n remote: Installing activejob 5.2.4.3\n remote: Fetching activerecord 5.2.4.3\n remote: Installing activerecord 5.2.4.3\n remote: Fetching actionview 5.2.4.3\n remote: Installing actionview 5.2.4.3\n remote: Fetching actionpack 5.2.4.3\n remote: Installing actionpack 5.2.4.3\n remote: Fetching kaminari-actionview 1.2.1\n remote: Installing kaminari-actionview 1.2.1\n remote: Fetching kaminari-activerecord 1.2.1\n remote: Installing kaminari-activerecord 1.2.1\n remote: Fetching polyamorous 2.3.2\n remote: Installing polyamorous 2.3.2\n remote: Fetching kaminari 1.2.1\n remote: Installing kaminari 1.2.1\n remote: Fetching ransack 2.3.2\n remote: Installing ransack 2.3.2\n remote: Fetching actioncable 5.2.4.3\n remote: Installing actioncable 5.2.4.3\n remote: Fetching actionmailer 5.2.4.3\n remote: Installing actionmailer 5.2.4.3\n remote: Fetching activestorage 5.2.4.3\n remote: Fetching railties 5.2.4.3\n remote: Installing activestorage 5.2.4.3\n remote: Installing railties 5.2.4.3\n remote: Fetching sprockets-rails 3.2.1\n remote: Installing sprockets-rails 3.2.1\n remote: Fetching gon 6.3.2\n remote: Installing gon 6.3.2\n remote: Fetching chart-js-rails 0.1.7\n remote: Fetching responders 3.0.1\n remote: Installing responders 3.0.1\n remote: Installing chart-js-rails 0.1.7\n remote: Fetching jquery-rails 4.4.0\n remote: Fetching rails 5.2.4.3\n remote: Installing rails 5.2.4.3\n remote: Fetching momentjs-rails 2.20.1\n remote: Installing jquery-rails 4.4.0\n remote: Installing momentjs-rails 2.20.1\n remote: Fetching rails-i18n 5.1.3\n remote: Installing rails-i18n 5.1.3\n remote: Fetching slim-rails 3.2.0\n remote: Installing slim-rails 3.2.0\n remote: Fetching webpacker 4.2.2\n remote: Installing webpacker 4.2.2\n remote: Fetching devise 4.7.1\n remote: Installing devise 4.7.1\n remote: Fetching kaminari-bootstrap 3.0.1\n remote: Installing kaminari-bootstrap 3.0.1\n remote: Fetching devise-i18n 1.9.1\n remote: Installing devise-i18n 1.9.1\n remote: Fetching sassc-rails 2.1.2\n remote: Installing sassc-rails 2.1.2\n remote: Fetching bootstrap 4.5.0\n remote: Fetching sass-rails 6.0.0\n remote: Installing sass-rails 6.0.0\n remote: Installing bootstrap 4.5.0\n remote: Bundle complete! 38 Gemfile dependencies, 90 gems now installed.\n remote: Gems in the groups development and test were not installed.\n remote: Bundled gems are installed into `./vendor/bundle`\n remote: Post-install message from i18n:\n remote: \n remote: HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.\n remote: But that may break your application.\n remote: \n remote: If you are upgrading your Rails application from an older version of Rails:\n remote: \n remote: Please check your Rails app for 'config.i18n.fallbacks = true'.\n remote: If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be\n remote: 'config.i18n.fallbacks = [I18n.default_locale]'.\n remote: If not, fallbacks will be broken in your app by I18n 1.1.x.\n remote: \n remote: If you are starting a NEW Rails application, you can ignore this notice.\n remote: \n remote: For more info see:\n remote: https://github.com/svenfuchs/i18n/releases/tag/v1.1.0\n remote: \n remote: Bundle completed (234.22s)\n remote: Cleaning up the bundler cache.\n remote: -----> Installing node-v10.15.3-linux-x64\n remote: -----> Installing yarn-v1.16.0\n remote: -----> Detecting rake tasks\n remote: -----> Preparing app for Rails asset pipeline\n remote: Running: rake assets:precompile\n remote: yarn install v1.16.0\n remote: [1/4] Resolving packages...\n remote: [2/4] Fetching packages...\n remote: info [email protected]: The platform \"linux\" is incompatible with this module.\n remote: info \"[email protected]\" is an optional dependency and failed compatibility check. Excluding it from installation.\n remote: info [email protected]: The platform \"linux\" is incompatible with this module.\n remote: info \"[email protected]\" is an optional dependency and failed compatibility check. Excluding it from installation.\n remote: [3/4] Linking dependencies...\n remote: warning \" > [email protected]\" has unmet peer dependency \"webpack@^4.0.0 || ^5.0.0\".\n remote: warning \"webpack-dev-server > [email protected]\" has unmet peer dependency \"webpack@^4.0.0\".\n remote: [4/4] Building fresh packages...\n remote: Done in 27.11s.\n remote: yarn install v1.16.0\n remote: [1/4] Resolving packages...\n remote: [2/4] Fetching packages...\n remote: info [email protected]: The platform \"linux\" is incompatible with this module.\n remote: info \"[email protected]\" is an optional dependency and failed compatibility check. Excluding it from installation.\n remote: info [email protected]: The platform \"linux\" is incompatible with this module.\n remote: info \"[email protected]\" is an optional dependency and failed compatibility check. Excluding it from installation.\n remote: [3/4] Linking dependencies...\n remote: warning \" > [email protected]\" has unmet peer dependency \"webpack@^4.0.0 || ^5.0.0\".\n remote: warning \"webpack-dev-server > [email protected]\" has unmet peer dependency \"webpack@^4.0.0\".\n remote: [4/4] Building fresh packages...\n remote: Done in 5.73s.\n remote: rake aborted!\n remote: LoadError: cannot load such file -- uglifier\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:34:in `require'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `block in require'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:257:in `load_dependency'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/autoload/uglifier.rb:2:in `<main>'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `block in require'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:257:in `load_dependency'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/uglifier_compressor.rb:43:in `initialize\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/uglifier_compressor.rb:26:in `new'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/uglifier_compressor.rb:26:in `instance'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/uglifier_compressor.rb:30:in `call'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/processor_utils.rb:84:in `call_processor\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/processor_utils.rb:66:in `block in call_processors'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/processor_utils.rb:65:in `reverse_each'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/processor_utils.rb:65:in `call_processors'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/loader.rb:182:in `load_from_unloaded'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/loader.rb:59:in `block in load'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/loader.rb:335:in `fetch_asset_from_dependency_cache'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/loader.rb:43:in `load'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/cached_environment.rb:44:in `load'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/bundle.rb:32:in `block in call'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/bundle.rb:31:in `call'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/processor_utils.rb:84:in `call_processor\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/processor_utils.rb:66:in `block in call_processors'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/processor_utils.rb:65:in `reverse_each'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/processor_utils.rb:65:in `call_processors'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/loader.rb:182:in `load_from_unloaded'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/loader.rb:59:in `block in load'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/loader.rb:335:in `fetch_asset_from_dependency_cache'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/loader.rb:43:in `load'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/cached_environment.rb:44:in `load'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/base.rb:81:in `find_asset'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/base.rb:88:in `find_all_linked_assets'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.0/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `block in synchronize'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:19:in `execute'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/promise.rb:563:in `block in realize'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:353:in `run_task'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:342:in `block (3 levels) in create_worker'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:325:in `loop'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:325:in `block (2 levels) in create_worker'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:324:in `catch'\n remote: /tmp/build_766ffab2466e42f825b9e77071bc1f96/vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.6/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:324:in `block in create_worker'\n remote: Tasks: TOP => assets:precompile\n remote: (See full trace by running task with --trace)\n remote: \n remote: !\n remote: ! Precompiling assets failed.\n remote: !\n remote: ! Push rejected, failed to compile Ruby app.\n remote: \n remote: ! Push failed\n remote: Verifying deploy...\n remote: \n remote: ! Push rejected to quiet-escarpment-59252.\n remote: \n To https://git.heroku.com/quiet-escarpment-59252.git\n ! [remote rejected] master -> master (pre-receive hook declined)\n error: failed to push some refs to 'https://git.heroku.com/quiet-escarpment-59252.git'\n \n \n```\n\n### Herokuのログ\n\n```\n\n USER:tt.manager user$ heroku logs\n 2020-06-23T23:13:40.437814+00:00 app[api]: Initial release by [email protected]\n 2020-06-23T23:13:40.437814+00:00 app[api]: Release v1 created by user [email protected]\n 2020-06-23T23:13:40.555521+00:00 app[api]: Release v2 created by user [email protected]\n 2020-06-23T23:13:40.555521+00:00 app[api]: Enable Logplex by user [email protected]\n 2020-06-23T23:27:34.000000+00:00 app[api]: Build started by user [email protected]\n 2020-06-23T23:31:47.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/9d484bc3-b7b6-4de9-8aaf-292aac539a19/activity/builds/c6cc724f-8cc0-451d-ae62-9ec869d0904b\n 2020-06-24T00:13:41.000000+00:00 app[api]: Build started by user [email protected]\n 2020-06-24T00:18:19.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/9d484bc3-b7b6-4de9-8aaf-292aac539a19/activity/builds/ee7ffc0b-8b43-4312-bc2b-f3d1ce1787cb\n 2020-06-24T00:43:21.000000+00:00 app[api]: Build started by user [email protected]\n 2020-06-24T00:47:45.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/9d484bc3-b7b6-4de9-8aaf-292aac539a19/activity/builds/d431367b-c625-475f-bebf-5f7203d9e507\n 2020-06-24T00:49:20.000000+00:00 app[api]: Build started by user [email protected]\n 2020-06-24T00:53:36.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/9d484bc3-b7b6-4de9-8aaf-292aac539a19/activity/builds/a7742a76-b35d-4e31-ba0f-77d2ef59c9d9\n 2020-06-24T01:10:36.000000+00:00 app[api]: Build started by user [email protected]\n 2020-06-24T01:14:57.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/9d484bc3-b7b6-4de9-8aaf-292aac539a19/activity/builds/3176a4df-330f-4b1c-9fbe-986ab31b7a17\n 2020-06-24T01:20:19.520837+00:00 heroku[router]: at=info code=H81 desc=\"Blank app\" method=GET path=\"/\" host=quiet-escarpment-59252.herokuapp.com request_id=280d8635-db41-4da4-ad23-fbfb94aaea92 fwd=\"103.5.140.141\" dyno= connect= service= status=502 bytes= protocol=https\n 2020-06-24T01:20:19.885714+00:00 heroku[router]: at=info code=H81 desc=\"Blank app\" method=GET path=\"/favicon.ico\" host=quiet-escarpment-59252.herokuapp.com request_id=b7340efc-ad58-4f0a-88dd-d48dc8d56113 fwd=\"103.5.140.141\" dyno= connect= service= status=502 bytes= protocol=https\n 2020-06-24T01:29:38.000000+00:00 app[api]: Build started by user [email protected]\n 2020-06-24T01:33:54.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/9d484bc3-b7b6-4de9-8aaf-292aac539a19/activity/builds/da5457d1-1199-44ed-9952-244b79412b0a\n 2020-06-24T01:34:11.000000+00:00 app[api]: Build started by user [email protected]\n 2020-06-24T01:38:49.000000+00:00 app[api]: Build failed -- check your build output: https://dashboard.heroku.com/apps/9d484bc3-b7b6-4de9-8aaf-292aac539a19/activity/builds/009aabba-40e3-48cb-a430-e93f8bb99711\n 2020-06-24T01:41:52.652821+00:00 heroku[router]: at=info code=H81 desc=\"Blank app\" method=GET path=\"/\" host=quiet-escarpment-59252.herokuapp.com request_id=891db6c9-af82-4a18-a44c-a5d0e1a548a7 fwd=\"103.5.140.141\" dyno= connect= service= status=502 bytes= protocol=https\n 2020-06-24T01:41:52.985462+00:00 heroku[router]: at=info code=H81 desc=\"Blank app\" method=GET path=\"/favicon.ico\" host=quiet-escarpment-59252.herokuapp.com request_id=e7b9a64b-1360-4fd7-a645-9c6cf6053502 fwd=\"103.5.140.141\" dyno= connect= service= status=502 bytes= protocol=https\n \n```\n\nリモートリポジトリ\n\n```\n\n $ git remote -v\n heroku https://git.heroku.com/quiet-escarpment-59252.git (fetch)\n heroku https://git.heroku.com/quiet-escarpment-59252.git (push)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T01:47:43.323", "favorite_count": 0, "id": "67934", "last_activity_date": "2020-06-24T16:55:22.647", "last_edit_date": "2020-06-24T16:55:22.647", "last_editor_user_id": "39475", "owner_user_id": "39475", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "git", "heroku", "デプロイ" ], "title": "git push heroku masterで発生するエラー( Precompiling assets failed., error: failed to push some refs to)について", "view_count": 2827 }
[ { "body": "Gemfile に `uglifier` の gem は追加されていますか? それを追加したあと実行すれば、この事象は解決すると思います。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T04:02:20.277", "id": "67941", "last_activity_date": "2020-06-24T04:02:20.277", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "754", "parent_id": "67934", "post_type": "answer", "score": 1 } ]
67934
67941
67941
{ "accepted_answer_id": null, "answer_count": 0, "body": "表題の件について質問させていただきたいのですが、そもそも私の基礎知識自体が稚拙すぎるためあっちこっちに飛ぶような文章になってしまうであろうことを、どうかご容赦ください。\n\nWindows\nServerに関する質問なのですが、企業のクライアントPCにはシマンテックやウイルスバスターといった様々なウイルス対策ソフトがインストールされていると思います(個人PCにおいてもですが)。\n\nそこで、例えば各クライアントPCに対し、\n\n 1. 特定のソフトの一括インストールをサーバ側で統括して行うなどということは可能でしょうか。\n\n 2. また、1の質問での答えが仮にNOである場合、では定期的にセキュリティソフトの更新作業等をサーバ側でコントロールすることは可能なのでしょうか。\n\n 3. 「公開サーバ」という言葉の意味がまず私にはわかっていないのですが、例えばWSUSのように、複数のクライアントPCが本来であれば個別に行うような一連の作業を、一手に引き受けるものという認識で合っていますか。\n\n 4. 「ウイルス対策/セキュリティ対策ソフトの公開サーバ構築」このキーワードから、だいたいどういったことを行うサーバを立てるのか、詳細は除いて少しだけ具体的なイメージをお持ちになられる有識者の方がいらっしゃいましたら、そのイメージだけでも何となくご教授くださいますと幸いです。\n\n現在の私は、とりあえず1台にサーバにウイルス対策ソフトを入れました…そしてここから「公開サーバ」というゴールに向かうための道筋が右も左もわかっていない状態でございます。\n\n何卒、よろしくお願いいたします。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T02:28:54.753", "favorite_count": 0, "id": "67935", "last_activity_date": "2020-06-24T02:32:47.083", "last_edit_date": "2020-06-24T02:32:47.083", "last_editor_user_id": "7290", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "windows", "サーバー管理" ], "title": "ウイルス対策ソフトの公開サーバ構築について", "view_count": 112 }
[]
67935
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "もし質問の内容がサイトの色と異なる場合は然るべきサイトを教えて頂ける事を期待しています。\n\nホームスピーカーやスマホで、音声アシスタントを使用する際に「OK\nGoogle!」などのWakeupキーワードを発声するまでの間、どの様に待機しているのかが知りたいです。\n\nもし常に音声を監視しているのであれば電気消費はとても大きくなるでしょう。 \nしかしその様な事にならず待機しています。 \nまた違ったワードの選別などはどの様に行われているのでしょうか?\n\n自分は音声認識の仕組みの部分がとても知りたいのですが検索が下手で上手く探すことができません。 \n何卒よろしくお願いいたします", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T02:32:32.287", "favorite_count": 0, "id": "67937", "last_activity_date": "2020-06-24T08:11:12.660", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40795", "post_type": "question", "score": 1, "tags": [ "apple", "amazon" ], "title": "Googleなどの音声アシスタントでWakeupキーワードを受取り→判断までの仕組み", "view_count": 80 }
[ { "body": "こんにちは、はじめまして。\n\nご質問の件ですが音声は常に監視しています。ですのでオフにすることで、端末によってはバッテリー消費をおさえられます。低電力でそうしたことをする専門のハードウェアが存在するものと考えてください。(キーワード:Low\nPower Audio,SOC)\n\nウェイクアップワードは単にマッチしているかを端末で判別しています(インターネット接続を切ったスマホでもウェイクアップワードに応答するはずです)。大雑把に言えば音の波形を解析して、サンプルと類似してるか比較すればことたります。(キーワード:音声認識)\n\n任意に入力された発話の解析やそれに対する応答の仕組みはより大がかりで、大抵の場合はインターネット上にあるコンピューターで行っています。音声入力に関しては古くからあり、ネットワーク無しで処理するものも多いですが、現在の様に実用化したのはディープラーニング以後となり、オンラインの計算リソースを活用したものに触れることが多いと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T08:11:12.660", "id": "67950", "last_activity_date": "2020-06-24T08:11:12.660", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37777", "parent_id": "67937", "post_type": "answer", "score": 1 } ]
67937
null
67950
{ "accepted_answer_id": "67964", "answer_count": 1, "body": "rails で Active Record すなわちデータベースを取り扱うと、 MigrationFile\nの作成・適用を行うことになります。これは、なんとなく、「新しい(未適用)の Migration File があれば、それを file name の\nalphabetical order 順 (そして、 file name は先頭が datetime 的 prefix\nである必要があるので、ほぼほぼ作成順)」で適用してくれるツールだと理解しています。\n\nここで疑問になるのが、このふるまいはどうやって実現されているのか、ということです。\n\n 1. 一度適用した MigrationFile を削除した(してしまった場合)\n 2. db:setup の際に schema.rb の元になったデータベースの構築に使われていない MigrationFile が db/migrations にまぎれこんでいた場合\n\nなどのエッジケースにおいて、 rails の migration がどうふるまうのかが、ふと、自分は良く理解していないな、と思うにいたりました。\n\n# 質問\n\n * 疑似コードぐらいの粒度では、rails の `db:migrate`, `db:reset`, `db:setup`, `db:migrate:reset` は、それぞれどのようにふるまっていますか?\n * その挙動がまとまっている資料はありますか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T03:44:46.600", "favorite_count": 0, "id": "67940", "last_activity_date": "2020-06-24T17:37:39.283", "last_edit_date": "2020-06-24T06:28:12.400", "last_editor_user_id": "3060", "owner_user_id": "754", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails" ], "title": "rails の migration の仕様について", "view_count": 156 }
[ { "body": "データベースに schema_migration というテーブルが造られて \n成功したマイグレーションファイルの数字の部分(YYYYMMDDHHMMSS)が記憶されていて \ndb/migrate ディレクトリと比較して未実行のマイグレーションを検出してます\n\nなので\n\n 1. 一度適用した MigrationFile を削除した(してしまった場合) \n何も起きません \nDB側にのみ履歴が存在しますが特にエラーにもなりません\n\n 2. データベースの構築に使われていない MigrationFile が db/migrations にまぎれこんでいた場合 \n履歴にないので当然実行されます\n\n> db:migrate, db:reset, db:setup, db:migrate:reset は、それぞれどのようにふるまっていますか?\n\nその前に schema.rb というのがあってはマイグレーションが成功したときに更新されます \n最後に成功したスキーマダンプファイルのようなものですね\n\n**db:migrate** \nDB の状態を正として未実行のマイグレーションファイルだけを適用します \nすでに適用済みのマイグレーションファイルを変更していても反映されません\n\n**db:migrate:reset** \nマイグレーションを正として \nすべてのテーブルをドロップしてマイグレーションをすべて再実行します\n\nこの2つはマイグレーションファイルのみを見ていて schema.rb はみません(更新はします)\n\n**db:reset** \nschema.rb を正として \nすべてのテーブルをドロップして schema.rb の状態にテーブルを再作成します\n\n**db:setup** \n最初にしか使ったことがなくて自信がないんですが \nデータベース作成スキーマ変更シードデータ投入だけ行うんだと思います \n既にDBが作成されてる場合エラーで止まるのかスキーマ更新をやるのかわからないですが\n\nこの2つはマイグレーションは見ずに schema.rb だけを参照します\n\n基本的にどこか1つの環境にでも実行したマイグレーションファイルは変更してはいけない \nスキーマを変更したいときは修正マイグレーションを作る \nという運用さえ守ってれば初回 setup とあと db:migrate だけでおかしなことはおきないはずです\n\n* * *\n\n<https://qiita.com/kenkentarou/items/9d2dd0d032f530311d2a> \nこちらによると \ndb:migrate:reset = db:drop + db:migrate \ndb:reset = db:drop + db:setup \ndb:setup = db:create + db:schema:load + db:seed \nということみたいです\n\n<https://qiita.com/katsuyan/items/59afccf9d0def886e8b3> \ndb:schema:load は force:true をつけると drop and create \nつけなければ create だけですでに存在する場合は already exist エラーになるようです\n\nなのでやはり db:migrate 以外でスキーマ変更をすると \nテーブル再作成になってレコードも消えるので注意", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T17:08:25.940", "id": "67964", "last_activity_date": "2020-06-24T17:37:39.283", "last_edit_date": "2020-06-24T17:37:39.283", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "67940", "post_type": "answer", "score": 0 } ]
67940
67964
67964
{ "accepted_answer_id": null, "answer_count": 1, "body": "Spresense SDK スタートガイド (CLI 版)の環境構築手順説明にはブートローダーのインストールについて下記の説明があります。\n\n> 適切なバージョンのブートローダーがインストールされていない場合、spresense/sdk ディレクトリの下で、 後述する \n> tools/config.py 及び tools/flash.sh ツールを実行したときに次のような WARNING が表示されます。 \n> Install command: に書かれた内容に従ってインストールを行います。\n>\n> WARNING: New loader vX.Y.Z is required, please download and install. \n> Download URL : **<https://developer.sony.com/file/download/spresense-\n> binaries-vX.Y.Z.zip>** \n> Install command: \n> 1\\. Extract loader archive into host PC. \n> ./tools/flash.sh -e \n> 2\\. Flash loader into Board. \n> ./tools/flash.sh -l /home/user/spresense/firmware/spresense -c\n\nDownload URLの部分については、Spresense\nSDKバージョンは2.0.0更新される前のものであり、2.0.0更新後、該当リンクがアクセスできなくなり、実際のWarningは下記のようなものになります。 \n[![画像の説明をここに入力](https://i.stack.imgur.com/XCCoZ.png)](https://i.stack.imgur.com/XCCoZ.png) \nつまり、 \n**<https://developer.sony.com/file/download/download-spresense-\nfirmware-v2-0-000>** \nのほうは正しいということなので、 \nv2-0-000と従来の命名規則vX.Y.Zが一致していないことについて \nご確認お願いいたします。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T04:51:35.533", "favorite_count": 0, "id": "67944", "last_activity_date": "2020-07-17T01:25:39.147", "last_edit_date": "2020-06-24T05:37:25.687", "last_editor_user_id": "40797", "owner_user_id": "40797", "post_type": "question", "score": 0, "tags": [ "spresense" ], "title": "Spresense SDKブートローダーのインストールについて", "view_count": 363 }
[ { "body": "ソニーのSPRESENSEサポート担当です。\n\nご指摘ありがとうございます。 \nWebドキュメントに記載されているダウンロードURLと実際のダウンロードURLとでフォーマットが異なっておりました。 \nこちら、誤解を生じさせない形での表現に変更いたしました。\n\nダウンロードURLはお使いの環境で表示された WARNING に記載されているものをお使いください。\n\n今後ともSPRESENSEをどうぞよろしくお願いいたします。\n\nSPRESENSEサポートチーム", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-17T01:25:39.147", "id": "68659", "last_activity_date": "2020-07-17T01:25:39.147", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29520", "parent_id": "67944", "post_type": "answer", "score": 1 } ]
67944
null
68659
{ "accepted_answer_id": "67949", "answer_count": 1, "body": "以下2つのTrimとTrim$や、MidとMid$等「$」のあるメソッドと「$」がないメソッドがありますが、動作は異なるのでしょうか。 \n私としては、それぞれのメソッドにカーソルを当てると、どちらも「Function Trim(str As String) As\nString」と表示されるので、実は同じメソッドが呼ばれているのではないかと思っています。\n\n```\n\n Sub Main()\n Microsoft.VisualBasic.Strings.Trim(\" abc \")\n Microsoft.VisualBasic.Strings.Trim$(\" abc \")\n End Sub\n \n```\n\n※VB(6.0)やVBAではなく、Visual Basic(.NET)の場合です。 \n※ターゲットフレームワークは4.7.2。OSはWindows 10です。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T06:01:12.927", "favorite_count": 0, "id": "67945", "last_activity_date": "2020-06-24T07:57:40.437", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19705", "post_type": "question", "score": 1, "tags": [ ".net", "vb.net" ], "title": "Strings.TrimとStrings.Trim$その他「$」ありなしで動作は異なりますか", "view_count": 258 }
[ { "body": "以下の記事が該当すると思われます。 \n最後の **非$関数は、$関数とまったく同じように機能します。これは、古いコードとの下位互換性のためにのみ保持されています。** が当てはまるのでしょう。\n\n[what is the meaning of the dollar sign after a method name in\nvb.net](https://stackoverflow.com/q/8341524/9014308) \n問:\n\n> what is the meaning of the dollar sign after a method name in vb.net \n> vb.netのメソッド名の後のドル記号の意味は何ですか。 \n> like this:\n```\n\n> Replace$(\"EG000000\", \"0\", \"\")\n> \n```\n\n短い答え:\n\n> Old type notifier - [see this](http://www.aivosto.com/vbtips/stringopt.html) \n> 古い型文字です \n> Some other old ones:\n```\n\n> & -> Long\n> % -> Integer\n> # -> Double\n> ! -> Single\n> @ -> Decimal\n> $ -> String\n> \n```\n\n>\n> Still exist in VB.Net for the sake of backward compatibility... \n> 下位互換性のためにVB.Netにはまだ存在しています。\n>\n> COMMENT: For the sake of completeness, the [MSDN\n> Link](http://msdn.microsoft.com/en-us/library/s9cz43ek%28v=VS.100%29.aspx). \n> 完全を期すために\n\n長い答え:\n\n> In \"classic\" VB, there were two versions of the built in-string functions.\n> Let me use Left as an example: \n> 「クラシック」VBには、組み込みの文字列関数の2つのバージョンがありました。 例としてLeftを使用してみましょう:\n>\n> * Left(s, length) takes a variant as the first parameter and returns a\n> variant.\n> * Left$(s, length) takes a string as the first parameter and returns a\n> string.\n>\n\n>\n> This distinction still exists in modern-day VBA. \n> この違いは、現在のVBAにも存在しています。\n>\n> I suspect that the reason behind this is that strings in VBA cannot be\n> `Null` (note that `Null <> \"\"`). Thus, when dealing with nullable database\n> fields, you had to use variant variables. Variant variables can take any\n> value, including all of the integral values (strings, integers, ...) as well\n> as some special values such as `Null`, `Empty` or `Missing`. The non-$\n> functions allowed you to use variants as input and get variants as output.\n> For example, `Left(Null, ...)` returns `Null`. \n> これの背後にある理由は、VBA内の文字列を`Null`にすることはできないためだと思います(`Null <> \"\"\n> `に注意してください)。したがって、null許容データベースフィールドを処理するときは、バリアント変数を使用する必要がありました。バリアント変数は、すべての整数値(文字列、整数など)や、\n> `Null`、` Empty`、\n> `Missing`などの特別な値を含む任意の値を取ることができます。非$関数を使用すると、バリアントを入力として使用し、バリアントを出力として取得できます。\n> たとえば、 `Left(Null、...)`は `Null`を返します。\n>\n> In VB.NET, this distinction is no longer necessary: The non-$ functions do\n> exactly the same as the $ functions, which are kept only for backwards\n> compatibility with old code. \n>\n> VB.NETでは、この区別は不要になりました。非$関数は、$関数とまったく同じように機能します。これは、古いコードとの下位互換性のためにのみ保持されています。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T07:57:40.437", "id": "67949", "last_activity_date": "2020-06-24T07:57:40.437", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "67945", "post_type": "answer", "score": 3 } ]
67945
67949
67949
{ "accepted_answer_id": null, "answer_count": 1, "body": "画像検出のプログラムで輪郭を抽出したく、参考書をもとにかいているのですが\n\n```\n\n ValueError: not enough values to unpack (expected 3, got 2)\n \n```\n\nというエラーが出てしまいわかりません。変数と要素の数が一致しないというものらしいのですが、いろいろ試してみたものの解決できませんでした。教えてくださる方がいらっしゃいましたら教えてください。\n\n```\n\n # 輪郭を抽出\n import cv2\n import matplotlib.pyplot as plt\n \n img_bgr=cv2.imread('earth15_02.jpg')\n img_gray=cv2.cvtColor(img_bgr,cv2.COLOR_BGR2GRAY)\n retval,thresh=cv2.threshold(img_gray,88,255,0)\n img,contours,hierarchy=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)\n \n result_img=cv2.drawContours(img,contours,-1,(0,0,255),3)\n \n #\n plt.imshow(result_img);\n plt.show()\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T08:18:24.603", "favorite_count": 0, "id": "67951", "last_activity_date": "2020-06-24T09:12:57.920", "last_edit_date": "2020-06-24T08:28:14.257", "last_editor_user_id": "3060", "owner_user_id": "40799", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "pythonで ValueError: not enough values to unpack というエラーが出てしまう", "view_count": 6993 }
[ { "body": "これらの記事が当てはまるでしょう。 \n[pythonで発生したValueError: not enough values to\nunpackの解決](https://teratail.com/questions/194500) \n[[OpenCV] ValueError: not enough values to unpack (expected 3, got\n2)](https://qiita.com/rareshana/items/6a2f5e7396f28f6eee49)\n\n2つ目の記事に沿って`img,contours,hierarchy=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)`の先頭の`img`を削除すればその行は動作しますが、質問記事のソースでは直後に`img`をパラメータとして使っているので、またそこでエラーになります。\n\nPython, OpenCV, matplotlib\nの各版数を参考書で使っているものに合わせるか、新しい版数の仕様に合わせて参考書のソースを書き換える必要があるでしょう。\n\nちなみにこの記事あたりが新しい版数に対応していそうです。 \n参考書の内容と細かく対比できるとも限りませんが、何かの足しに。 \n[OpenCVで画像から輪郭検出の基本(findContours関数あたり)](https://kitakantech.com/opencv-\nfindcontours/)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T09:04:07.990", "id": "67954", "last_activity_date": "2020-06-24T09:12:57.920", "last_edit_date": "2020-06-24T09:12:57.920", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "67951", "post_type": "answer", "score": 1 } ]
67951
null
67954
{ "accepted_answer_id": null, "answer_count": 1, "body": "質問です。 \nカレンダー入力で選択した日付をデータベースに登録したいのですが、うまく行きません。 \n[![画像の説明をここに入力](https://i.stack.imgur.com/KKcqA.png)](https://i.stack.imgur.com/KKcqA.png) \nparams内にあるdue_onというキーです。\n\nデータベース上のreportsテーブルにdue_onというカラムに入れたいのですが、型はdateで合っているのでしょうか?[![画像の説明をここに入力](https://i.stack.imgur.com/nE0tM.png)](https://i.stack.imgur.com/nE0tM.png)\n\nstring型かなとも思ったのですが、どなたか分かる方教えていただきますか?\n\nviewのコード (haml)\n\n```\n\n = form_with model: @report, html: {class: \"Report\"}, local: true do |f|\n %ul.Report__contents\n %li= date_field_tag :due_on, Date.today, use_month_numbers: true\n %li= f.collection_select :job_id, Job.all, :id, :job, include_blank: \"内容を選択して下さい\"\n %li= f.collection_select :hour_id, Hour.all, :id, :hour, include_blank: \"時間を選択して下さい\"\n %p 時間\n %li= f.text_field :impression, class: 'Report__imp', placeholder: '改善点'\n = f.submit '保存する', class: 'Report__submit'\n \n \n```\n\nコントローラーのコード\n\n```\n\n params.require(:report).permit(:due_on, :job_id, :hour_id, :impression).merge(user_id: current_user.id)\n \n```\n\nよろしくお願いいたします。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T08:40:06.160", "favorite_count": 0, "id": "67952", "last_activity_date": "2022-09-27T13:08:00.733", "last_edit_date": "2020-06-24T23:28:26.763", "last_editor_user_id": "2238", "owner_user_id": "40800", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails" ], "title": "カレンダーから入力した日付をMySQLのデータベースに保存する方法", "view_count": 514 }
[ { "body": "おそらく \ndate_field_tag を f.date_field \nにかえればいいのではないかと思いますが \nそれでだめならコントローラ全文を表示してください", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T17:58:47.373", "id": "67965", "last_activity_date": "2020-06-24T17:58:47.373", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "67952", "post_type": "answer", "score": 1 } ]
67952
null
67965
{ "accepted_answer_id": null, "answer_count": 1, "body": "RubyのRedisクライアントのソースコード(redis4.0.1)を読んでいると、 \n`lib/redis/client.rb` \nというファイルに\n\n```\n\n def call(command)\n reply = process([command]) { read }\n raise reply if reply.is_a?(CommandError)\n ......\n \n```\n\nという記述がありました。\n\n```\n\n process([command]) { read }\n \n```\n\nこの`[]`閉じと、`{ }`\nの文法の名前をググりたいのですがどういうワードでググればいいのか見当がつかないので、知っている方がいれば教えていただきたいです\n\n追記 2020/6/27 \nこちらが参考になりました。 \n<http://rubylearning.com/satishtalim/ruby_blocks.html>", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T09:07:37.703", "favorite_count": 0, "id": "67955", "last_activity_date": "2020-06-27T10:10:17.570", "last_edit_date": "2020-06-27T10:10:17.570", "last_editor_user_id": "39416", "owner_user_id": "39416", "post_type": "question", "score": 1, "tags": [ "ruby", "redis" ], "title": "process([command]) { read } のような文法の名前を知りたい", "view_count": 84 }
[ { "body": "記号をググるのは難しいので、Rubyの場合はリファレンスマニュアルの「Rubyで使われる記号の意味」のページを参照すると意味がつかめると思います。 \n<https://docs.ruby-lang.org/ja/latest/doc/symref.html>\n\n英単語としてググるなら、brackets, braces, curly braces, parenthesesなどの単語が適切でしょうか。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T09:40:18.967", "id": "67956", "last_activity_date": "2020-06-24T09:40:18.967", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "21283", "parent_id": "67955", "post_type": "answer", "score": 3 } ]
67955
null
67956
{ "accepted_answer_id": null, "answer_count": 1, "body": "下記の様なZONE設定ファイルをtest.local、test.local.revとして作成してDNSサーバを構築しました。\n\nしかしながらこれらのファイルを正常に読み込めていない、とjournalctlで見ると出てきます。 \n具体的にZONE設定の何が間違っているのか教えていただけませんでしょうか。\n\n* * *\n\n**test.local**\n\n```\n\n $TTL 86400\n \n @ IN SOA cent01.test.local. (\n 2020020501 ; serial\n 28800 ; refresh\n 14400 ; retry\n 3600000 ; expire\n 86400) ; minimum\n IN NS cent01.test.local.\n cent01.test.local. IN A 1.4.7.31\n cent02.test.local. IN A 1.4.7.32\n \n```\n\n**test.local.rev**\n\n```\n\n $TTL 86400\n @ IN SOA cent01.test.local. (\n 2020020501 ; serial\n 28800 ; refresh\n 14400 ; retry\n 3600000 ; expire\n 86400) ; minimum\n IN NS cent01.test.local.\n 1.4.7.31 IN PTR cent01.test.local\n 1.4.7.32 IN PTR cent02.test.local\n \n```\n\n追加 \n下記の設定に変更をした場合、うまくDNSサーバは動いているように見えます。named-\ncheckzoneで確認をするとOKと出ます。root.test.local.を入れました。 しかしながら、別のPCからDNSサーバに対してnslookup\n1.4.7.31を試すと ** server can't find 31.4.7.1.in-addr.arpa.: NXDOMAIN\nと表示されてしまいます。実際に存在するIPは1.4.7.31です。 逆にnslookup\ncent01.test.localを試すと名前解決は正しく出来ます。 尚、nslookup cent01を試すと下記のエラーが返ってきます。 **\nserver can't find cent01:NXDOMAIN これは期待通りの動作だと思います。\nどうして逆引きがうまく出来ないのか、教えていただけませんでしょうか?\n\n* * *\n\n**test.local**\n\n```\n\n $TTL 86400\n \n @ IN SOA cent01.test.local. root.test.local.(\n 2020020501 ; serial\n 28800 ; refresh\n 14400 ; retry\n 3600000 ; expire\n 86400) ; minimum\n IN NS cent01.test.local.\n cent01.test.local. IN A 1.4.7.31\n cent02.test.local. IN A 1.4.7.32\n \n```\n\n**test.local.rev**\n\n```\n\n $TTL 86400\n @ IN SOA cent01.test.local. root.test.local.(\n 2020020501 ; serial\n 28800 ; refresh\n 14400 ; retry\n 3600000 ; expire\n 86400) ; minimum\n IN NS cent01.test.local.\n 1.4.7.31 IN PTR cent01.test.local\n 1.4.7.32 IN PTR cent02.test.local\n \n```\n\nnamed.confは下記の通りです。\n\n```\n\n options {\n listen-on port 53 { 1.4.7.34; };\n #listen-on-v6 port 53 { ::1; };\n directory \"/var/named\";\n dump-file \"/var/named/data/cache_dump.db\";\n statistics-file \"/var/named/data/named_stats.txt\";\n memstatistics-file \"/var/named/data/named_mem_stats.txt\";\n recursing-file \"/var/named/data/named.recursing\";\n secroots-file \"/var/named/data/named.secroots\";\n allow-query { 1.4.7.0/24; };\n \n /* \n - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.\n - If you are building a RECURSIVE (caching) DNS server, you need to enable \n recursion. \n - If your recursive DNS server has a public IP address, you MUST enable access \n control to limit queries to your legitimate users. Failing to do so will\n cause your server to become part of large scale DNS amplification \n attacks. Implementing BCP38 within your network would greatly\n reduce such attack surface \n */\n recursion yes;\n \n dnssec-enable yes;\n dnssec-validation yes;\n \n /* Path to ISC DLV key */\n bindkeys-file \"/etc/named.root.key\";\n \n managed-keys-directory \"/var/named/dynamic\";\n \n pid-file \"/run/named/named.pid\";\n session-keyfile \"/run/named/session.key\";\n };\n \n logging {\n channel default_debug {\n file \"data/named.run\";\n severity dynamic;\n };\n };\n \n zone \"test.local\" IN {\n type master;\n file \"test.local\";\n };\n \n zone \"zone.rev\" {\n type master;\n file \"test.local.rev\";\n };\n \n include \"/etc/named.rfc1912.zones\";\n include \"/etc/named.root.key\";\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T10:01:39.913", "favorite_count": 0, "id": "67957", "last_activity_date": "2020-07-03T14:12:47.700", "last_edit_date": "2020-07-03T12:15:07.053", "last_editor_user_id": "3060", "owner_user_id": "31472", "post_type": "question", "score": -1, "tags": [ "centos", "dns" ], "title": "BINDのzone設定が正常に読み込まれない", "view_count": 1980 }
[ { "body": "`named-checkzone` で確認するとエラーになります。 \n`SOA` に不足があります。 \n「SOA DNSサーバー メールアドレス(@を.に置き換えたもの)」とする必要があります。\n\n```\n\n (例)\n @ IN SOA cent01.test.local. root.test.local. (\n \n```\n\n* * *\n\n(2020/07/03 23:12) 追記\n\n逆引きは `in-addr.arpa.` という特別なドメインを付けます。 \nIPv4アドレス **A.B.C.D** は **D.C.B.A.in-addr.arpa.** と逆順に対応します。 \nネットワークアドレス 1.4.7.0/24 の zone は以下のように記述します。\n\n```\n\n (named.conf)\n zone \"7.4.1.in-addr.arpa\" {\n type master;\n file \"test.local.rev\";\n };\n \n```\n\nまた、test.local.rev は第4オクテットのみとするか、in-addr.arpa. まですべて記述します。\n\n```\n\n (test.local.rev)\n 31 IN PTR cent01.test.local.\n 32 IN PTR cent02.test.local.\n \n または\n 31.7.4.1.in-addr.arpa. IN PTR cent01.test.local.\n 32.7.4.1.in-addr.arpa. IN PTR cent02.test.local.\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T01:33:45.277", "id": "67974", "last_activity_date": "2020-07-03T14:12:47.700", "last_edit_date": "2020-07-03T14:12:47.700", "last_editor_user_id": "4603", "owner_user_id": "4603", "parent_id": "67957", "post_type": "answer", "score": 0 } ]
67957
null
67974
{ "accepted_answer_id": "67998", "answer_count": 2, "body": "これまで INNER JOIN を一度も使用したことはないのですが、 INNER JOIN は、どういう時に使用するのですか? \nINNER JOIN を使用しないと、出来ない処理はありますか?\n\n* * *\n\nINNER JOIN の説明を読むと、両テーブルのカラム値が一致するデータだけ取得する、と書いてあるのですが、 \nOUTER JOIN で、両テーブルのカラム値が一致するという条件を書けば良いだけだと思うのですが、そういう問題ではない??\n\n例えばですが、OUTER JOIN 後に、条件追記することで INNER JOIN と同じ結果を取得できますか? \n実際に実行するかどうかは別として、基本的な考え方としては下記認識で合っていますか? \n・INNER JOIN 取得結果から、OUTER JOIN 取得結果を 得ることは不可 \n・OUTER JOIN 取得結果から、(条件追記することで)INNER JOIN 取得結果を 得ることは可", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T10:57:33.680", "favorite_count": 0, "id": "67958", "last_activity_date": "2020-06-25T15:47:16.593", "last_edit_date": "2020-06-25T14:20:40.803", "last_editor_user_id": "19110", "owner_user_id": "7886", "post_type": "question", "score": 1, "tags": [ "mysql", "sql" ], "title": "INNER JOIN は、どういう時に使用するのですか? INNER JOIN でしか出来ないことはありますか?", "view_count": 1177 }
[ { "body": "> ・INNER JOIN 取得結果から、OUTER JOIN 取得結果を 得ることは不可\n\nはい、不可能です。\n\n> ・OUTER JOIN 取得結果から、(条件追記することで)INNER JOIN 取得結果を 得ることは可\n\nはい、可能です。\n\n* * *\n\n# 詳細\n\n`OUTER JOIN` は3つの種類があります。\n\n * `LEFT OUTER JOIN` (左外部結合)\n * `RIGHT OUTER JOIN` (右外部結合)\n * `FULL OUTER JOIN` (完全外部結合)\n\n`LEFT JOIN` のように、`OUTER` を省略して書いても構いません。 \n逆に、`LEFT/RIGHT/FULL` を省略して `OUTER JOIN` と書くことはできません。 \n(ちなみに、`FROM A, B` のように書いた場合、`FROM A CROSS JOIN B` 相当になります)\n\n質問者の `OUTER JOIN` がどれを指すか不明ですが、質問内容から `FULL OUTER JOIN` と仮定します。\n\n以下のテーブルを使って、例を挙げます。\n\n```\n\n Aテーブル Bテーブル\n +------+ +------+\n | ID | | ID |\n +------+ +------+\n | 1 | | 1 |\n | 2 | | 3 |\n +------+ +------+\n \n```\n\n## 例1: `FROM A INNER JOIN B ON A.ID = B.ID`\n\nAテーブルとBテーブルの両方に同じIDがある行のみ取得できます。\n\n```\n\n +------+------+\n | A.ID | B.ID |\n +------+------+\n | 1 | 1 |\n +------+------+\n \n```\n\n## 例2: `FROM A FULL OUTER JOIN B ON A.ID = B.ID`\n\nAテーブルまたはBテーブルにある行が取得できます。\n\n```\n\n +------+------+\n | A.ID | B.ID |\n +------+------+\n | 1 | 1 |\n | 2 | null |\n | null | 3 |\n +------+------+\n \n```\n\n## 例3: `FROM A FULL OUTER JOIN B ON A.ID = B.ID WHERE A.ID = B.ID`\n\n例2のテーブルができあがった後に、`A.ID = B.ID` となる行を抽出しています。\n\n```\n\n +------+------+\n | A.ID | B.ID |\n +------+------+\n | 1 | 1 |\n +------+------+\n \n```\n\nつまり、`INNER JOIN` と同じ結果になります。 \n(データベース内部では、大体の場合 `INNER JOIN` と同じ処理に変換されます)\n\n## 使い分け\n\n適切に JOIN を使い分けることで、 **`ON` 句に結合条件、`WHERE` 句に抽出条件** を書けます。\n\n例えば、`A.ID = B.ID` は抽出条件ではなく結合条件です。 \nこの場合、`INNER JOIN` を使って結合条件を `ON` 句に書いた方が、 **二つのテーブルをIDで結合している**\nということが一目でわかります。\n\n逆に、`FULL OUTER JOIN` を使って `WHERE`\n句に結合条件を書くと、抽出条件の中に結合条件が埋もれてしまうため、二つのテーブルの関係がぱっと見でわからなくなります。\n\n## 参考\n\n[7.2. テーブル式 - 第7章 問い合わせ - PostgreSQL\n12.0文書](https://www.postgresql.jp/document/12/html/queries-table-\nexpressions.html#QUERIES-JOIN)", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T15:20:35.687", "id": "67998", "last_activity_date": "2020-06-25T15:41:08.850", "last_edit_date": "2020-06-25T15:41:08.850", "last_editor_user_id": "14334", "owner_user_id": "14334", "parent_id": "67958", "post_type": "answer", "score": 2 }, { "body": "INNER JOIN と OUTER JOIN は状況に応じて使い分けるべき、別の演算です。MySQL では何も装飾のない `JOIN` は INNER\nJOIN になるので、使ったことはあるのではないかと思います。\n\nそもそも、関係データベースの JOIN 演算には次の 4 つの種類が知られています。\n\n * INNER JOIN\n * LEFT OUTER JOIN\n * RIGHT OUTER JOIN\n * FULL OUTER JOIN\n\nこれらはそれぞれ、対応する値が相手のテーブルに存在しなかったときにどうするか、が異なります。\n\n例として『リレーショナルデータベース入門』(増永良文)に載っていたものを引用します。最初に次のようにふたつのテーブル「供給」と「需要」があったとします。\n\n[![](https://i.stack.imgur.com/HzcSl.png)](https://i.stack.imgur.com/HzcSl.png)\n\nこのふたつのテーブルを、`供給.部品 = 需要.部品` という条件のもとでそれぞれ JOIN 演算すると次のようになります。\n\n[![](https://i.stack.imgur.com/4ZbTU.png)](https://i.stack.imgur.com/4ZbTU.png)\n\nそれぞれの演算において相手のテーブルに対応する `部品`\nがあるかないかによって演算結果に特定の行ができるかできないかが変わってくるのがお分かりかと思います。この違いは、この後どのような演算をしたいのかによって\n\nこれらを理解していただいた上で質問文の質問に答えます。\n\n> (INNER JOIN を使わずに)OUTER JOIN\n> で、両テーブルのカラム値が一致するという条件を書けば良いだけだと思うのですが、そういう問題ではない??\n\nNULL のある行が生まれるか生まれないかの差異があるので、その条件だと代替はできません。\n\n> OUTER JOIN 後に、条件追記することで INNER JOIN と同じ結果を取得できますか?\n\nはい、無駄を許せば、一度 OUTER JOIN した後、その結果のテーブルに対して `供給.部品 = 需要.部品` な行だけ残るように WHERE\n節を書けば実現できます。ただそんなことをするくらいなら最初から INNER JOIN を書けば良いでしょう(もっとも、MySQL\nだとこのような条件は[最適化されて](https://dev.mysql.com/doc/refman/8.0/en/outer-join-\noptimization.html) INNER JOIN 相当のクエリになることが多そうですが)。\n\n* * *\n\n補足:MySQL には FULL OUTER JOIN 構文は存在しないのでお気をつけください。参考: [Why does MySQL report a\nsyntax error on FULL OUTER JOIN?](https://stackoverflow.com/q/2384298/5989200)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T15:39:22.737", "id": "67999", "last_activity_date": "2020-06-25T15:47:16.593", "last_edit_date": "2020-06-25T15:47:16.593", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "67958", "post_type": "answer", "score": 1 } ]
67958
67998
67998
{ "accepted_answer_id": "67979", "answer_count": 3, "body": "* 以下のコードはすべてWindows10のwsl1のUbuntu上で試しています。\n\n私は以下のコードを試しました。(10秒ごとに手動でエンターキー押しています。)\n\n```\n\n $cat /dev/random | pv >a.txt\n 615MiB 0:00:10 [59.4MiB/s]\n 1.20GiB 0:00:20 [59.3MiB/s]\n 1.80GiB 0:00:30 [61.7MiB/s]\n $cat /dev/random | pv >>a.txt\n 618MiB 0:00:10 [61.7MiB/s]\n 1.23GiB 0:00:20 [65.1MiB/s]\n 1.81GiB 0:00:30 [61.4MiB/s]\n \n```\n\n若干追記のほうが早いですがあまり変わりません。 \nまた以下のコードを試しました。\n\n```\n\n $cat /dev/random | pv > /dev/null\n 740MiB 0:00:10 [70.7MiB/s]\n 1.41GiB 0:00:20 [70.8MiB/s]\n 2.11GiB 0:00:30 [70.6MiB/s]\n \n $cat /dev/random | pv >> /dev/null\n 631MiB 0:00:10 [63.3MiB/s]\n 1.22GiB 0:00:20 [61.1MiB/s]\n 1.83GiB 0:00:30 [64.2MiB/s]\n \n```\n\nこちらは明らかに追記のほうが遅いです。 \n勝手な想像ですが、/dev/nullに書き込んでいるので実際のファイルに書き込んだり追記したりするよりも速度差はなくなるのかなと思っていました。\n\nQ.この違いはどこからきているのでしょうか。 \n(具体的に何がしたいとかではなく単純に疑問に思って質問しました。)", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T15:05:32.133", "favorite_count": 0, "id": "67962", "last_activity_date": "2020-06-26T15:05:48.627", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "17106", "post_type": "question", "score": 5, "tags": [ "linux", "ubuntu", "shell" ], "title": "> /dev/nullと >>/dev/nullの速度の違いについての疑問", "view_count": 366 }
[ { "body": "pvは`> /dev/null`のときにnullデバイスにwriteしていません。\n\n`> /dev/null`と`>> /dev/null`の差はこれが理由です。\n\n調査に使用したpvのバージョンは以下です。 \npv 1.6.6 - Copyright 2015 Andrew Wood [email protected]\n\n* * *\n\nこの現象の差は`> /dev/null`と`>> /dev/null`の性能差ではなさそうです。 \npvの代わりにcatにを使ってtimeとstraceを実行してみましたが、有意な差は見受けられませんでした。 \n`> /dev/null`と`>> /dev/null`のわずかな差がpvで拡大しているように見えます。\n\n> Q.この違いはどこからきているのでしょうか。\n\n謎の解決にはなっていませんが`pv`が主因のようです。\n\n【追記】\n\n理由がわかりました。 \n`pv`は `> /dev/null`のときにwriteしていません。 \n`>> /dev/null`のときはwriteしています。 \npvはパイプの性能を計測するのが主たる機能のようですので気を利かせているのかもしれません。\n\n`strace -r -T -ff`を実行しwrieの回数を数えたところ、以下の結果となりました。 \n`> /dev/null`は15回 \n`>> /dev/null`は13916回\n\n```\n\n openat(AT_FDCWD, \"/dev/null\", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3\n dup2(3, 1) = 1\n \n```\n\nのあと、`write(1`のトレースはありませんでした。 \n`pv`の代わりに`cat`を使ったときは当然ですがwriteしています。\n\n* * *\n\n以下は最初に計測したときの結果です。\n\nシステムコールの呼び出し回数は`cat > /dev/null`と`cat >> /dev/null`で差異はありませんでした。 \n`pv > /dev/null`と`pv >> /dev/null`では大きな差があります。 \n`>>\n/dev/null`では`read/write/rt_sigaction/select/gettimeofday/time`の呼び出し回数が増えています。 \n`splice`は`>> /dev/null`の方が少ないです。 \n`alarm`は `>> /dev/null`の方だけに現れます。\n\n【追記】 \nよくみるとwriteの回数に大きな差異があります。\n\n```\n\n ==> a.sh <==\n #!/bin/sh\n cat in.data | pv > /dev/null\n \n ==> b.sh <==\n #!/bin/sh\n cat in.data | pv >> /dev/null\n \n ==> aa.sh <==\n #!/bin/sh\n cat in.data | cat > /dev/null\n \n ==> bb.sh <==\n #!/bin/sh\n cat in.data | cat >> /dev/null\n \n```\n\nin.dataは1,000,000,000バイトのファイルです。\n\n```\n\n ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n time ./a.sh\n ./a.sh の内容 ==> cat in.data | pv > /dev/null\n ____________________________________________\n 953MiB 0:00:00 [1.37GiB/s] [ <=> ]\n 0.09user 0.76system 0:00.69elapsed 123%CPU (0avgtext+0avgdata 1008maxresident)k\n 0inputs+0outputs (0major+726minor)pagefaults 0swaps\n ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n time ./b.sh\n ./b.sh の内容 ==> cat in.data | pv >> /dev/null\n ____________________________________________\n 953MiB 0:00:00 [1.27GiB/s] [ <=> ]\n 0.10user 0.90system 0:00.75elapsed 133%CPU (0avgtext+0avgdata 1016maxresident)k\n 0inputs+0outputs (0major+728minor)pagefaults 0swaps\n ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n time ./aa.sh\n ./aa.sh の内容 ==> cat in.data | cat > /dev/null\n ____________________________________________\n 0.03user 0.84system 0:00.61elapsed 141%CPU (0avgtext+0avgdata 796maxresident)k\n 0inputs+0outputs (0major+683minor)pagefaults 0swaps\n ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n time ./bb.sh\n ./bb.sh の内容 ==> cat in.data | cat >> /dev/null\n ____________________________________________\n 0.01user 0.73system 0:00.63elapsed 117%CPU (0avgtext+0avgdata 800maxresident)k\n 0inputs+0outputs (0major+683minor)pagefaults 0swaps\n ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n strace -c -f ./a.sh\n ./a.sh の内容 ==> cat in.data | pv > /dev/null\n ____________________________________________\n strace: Process 3997 attached\n strace: Process 3998 attached\n 953MiB 0:00:04 [ 237MiB/s] [ <=> ]\n % time seconds usecs/call calls errors syscall\n ------ ----------- ----------- --------- --------- ----------------\n 100.00 0.782999 391500 2 wait4\n 0.00 0.000000 0 7639 read\n 0.00 0.000000 0 7641 write\n 0.00 0.000000 0 24 1 close\n 0.00 0.000000 0 15 10 stat\n 0.00 0.000000 0 16 fstat\n 0.00 0.000000 0 19 mmap\n 0.00 0.000000 0 12 mprotect\n 0.00 0.000000 0 5 munmap\n 0.00 0.000000 0 9 brk\n 0.00 0.000000 0 24 rt_sigaction\n 0.00 0.000000 0 2 rt_sigreturn\n 0.00 0.000000 0 11 1 ioctl\n 0.00 0.000000 0 9 9 access\n 0.00 0.000000 0 1 pipe\n 0.00 0.000000 0 15260 select\n 0.00 0.000000 0 3 dup2\n 0.00 0.000000 0 1 getpid\n 0.00 0.000000 0 2 clone\n 0.00 0.000000 0 3 execve\n 0.00 0.000000 0 1 1 msgget\n 0.00 0.000000 0 4 fcntl\n 0.00 0.000000 0 15263 gettimeofday\n 0.00 0.000000 0 1 getuid\n 0.00 0.000000 0 1 getgid\n 0.00 0.000000 0 3 geteuid\n 0.00 0.000000 0 1 getegid\n 0.00 0.000000 0 1 getppid\n 0.00 0.000000 0 3 arch_prctl\n 0.00 0.000000 0 9 time\n 0.00 0.000000 0 1 fadvise64\n 0.00 0.000000 0 24 12 openat\n 0.00 0.000000 0 15260 splice\n ------ ----------- ----------- --------- --------- ----------------\n 100.00 0.782999 61270 34 total\n ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n strace -c -f ./b.sh\n ./b.sh の内容 ==> cat in.data | pv >> /dev/null\n ____________________________________________\n strace: Process 4005 attached\n strace: Process 4006 attached\n 953MiB 0:00:08 [ 116MiB/s] [ <=> ]\n % time seconds usecs/call calls errors syscall\n ------ ----------- ----------- --------- --------- ----------------\n 100.00 0.721400 360700 2 wait4\n 0.00 0.000000 0 22899 read\n 0.00 0.000000 0 15279 write\n 0.00 0.000000 0 24 1 close\n 0.00 0.000000 0 15 10 stat\n 0.00 0.000000 0 16 fstat\n 0.00 0.000000 0 19 mmap\n 0.00 0.000000 0 12 mprotect\n 0.00 0.000000 0 5 munmap\n 0.00 0.000000 0 9 brk\n 0.00 0.000000 0 7654 rt_sigaction\n 0.00 0.000000 0 2 rt_sigreturn\n 0.00 0.000000 0 11 1 ioctl\n 0.00 0.000000 0 9 9 access\n 0.00 0.000000 0 1 pipe\n 0.00 0.000000 0 22890 select\n 0.00 0.000000 0 3 dup2\n 0.00 0.000000 0 15260 alarm\n 0.00 0.000000 0 1 getpid\n 0.00 0.000000 0 2 clone\n 0.00 0.000000 0 3 execve\n 0.00 0.000000 0 1 1 msgget\n 0.00 0.000000 0 4 fcntl\n 0.00 0.000000 0 53412 gettimeofday\n 0.00 0.000000 0 1 getuid\n 0.00 0.000000 0 1 getgid\n 0.00 0.000000 0 3 geteuid\n 0.00 0.000000 0 1 getegid\n 0.00 0.000000 0 1 getppid\n 0.00 0.000000 0 3 arch_prctl\n 0.00 0.000000 0 17 time\n 0.00 0.000000 0 1 fadvise64\n 0.00 0.000000 0 24 12 openat\n 0.00 0.000000 0 1 1 splice\n ------ ----------- ----------- --------- --------- ----------------\n 100.00 0.721400 137586 35 total\n ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n strace -c -f ./aa.sh\n ./aa.sh の内容 ==> cat in.data | cat > /dev/null\n ____________________________________________\n strace: Process 4013 attached\n strace: Process 4014 attached\n % time seconds usecs/call calls errors syscall\n ------ ----------- ----------- --------- --------- ----------------\n 100.00 0.687791 343896 2 wait4\n 0.00 0.000000 0 22896 read\n 0.00 0.000000 0 22889 write\n 0.00 0.000000 0 25 1 close\n 0.00 0.000000 0 9 6 stat\n 0.00 0.000000 0 12 fstat\n 0.00 0.000000 0 19 mmap\n 0.00 0.000000 0 12 mprotect\n 0.00 0.000000 0 5 munmap\n 0.00 0.000000 0 9 brk\n 0.00 0.000000 0 7 rt_sigaction\n 0.00 0.000000 0 2 rt_sigreturn\n 0.00 0.000000 0 9 9 access\n 0.00 0.000000 0 1 pipe\n 0.00 0.000000 0 3 dup2\n 0.00 0.000000 0 1 getpid\n 0.00 0.000000 0 2 clone\n 0.00 0.000000 0 3 execve\n 0.00 0.000000 0 4 fcntl\n 0.00 0.000000 0 1 getuid\n 0.00 0.000000 0 1 getgid\n 0.00 0.000000 0 2 geteuid\n 0.00 0.000000 0 1 getegid\n 0.00 0.000000 0 1 getppid\n 0.00 0.000000 0 3 arch_prctl\n 0.00 0.000000 0 2 fadvise64\n 0.00 0.000000 0 11 openat\n ------ ----------- ----------- --------- --------- ----------------\n 100.00 0.687791 45932 16 total\n ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■\n strace -c -f ./bb.sh\n ./bb.sh の内容 ==> cat in.data | cat >> /dev/null\n ____________________________________________\n strace: Process 4021 attached\n strace: Process 4022 attached\n % time seconds usecs/call calls errors syscall\n ------ ----------- ----------- --------- --------- ----------------\n 100.00 0.656595 328298 2 wait4\n 0.00 0.000000 0 22896 read\n 0.00 0.000000 0 22889 write\n 0.00 0.000000 0 25 1 close\n 0.00 0.000000 0 9 6 stat\n 0.00 0.000000 0 12 fstat\n 0.00 0.000000 0 19 mmap\n 0.00 0.000000 0 12 mprotect\n 0.00 0.000000 0 5 munmap\n 0.00 0.000000 0 9 brk\n 0.00 0.000000 0 7 rt_sigaction\n 0.00 0.000000 0 2 rt_sigreturn\n 0.00 0.000000 0 9 9 access\n 0.00 0.000000 0 1 pipe\n 0.00 0.000000 0 3 dup2\n 0.00 0.000000 0 1 getpid\n 0.00 0.000000 0 2 clone\n 0.00 0.000000 0 3 execve\n 0.00 0.000000 0 4 fcntl\n 0.00 0.000000 0 1 getuid\n 0.00 0.000000 0 1 getgid\n 0.00 0.000000 0 2 geteuid\n 0.00 0.000000 0 1 getegid\n 0.00 0.000000 0 1 getppid\n 0.00 0.000000 0 3 arch_prctl\n 0.00 0.000000 0 2 fadvise64\n 0.00 0.000000 0 11 openat\n ------ ----------- ----------- --------- --------- ----------------\n 100.00 0.656595 45932 16 total\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T04:00:20.807", "id": "67979", "last_activity_date": "2020-06-26T06:40:56.990", "last_edit_date": "2020-06-26T06:40:56.990", "last_editor_user_id": "35558", "owner_user_id": "35558", "parent_id": "67962", "post_type": "answer", "score": 7 }, { "body": "\">\" と \">>\" でシステムコールに違いがあるのは不可解です。 \n\"cat hoge | pv > /dev/null\" は、シェルが /dev/null を open する時に \nO_APPEND を付けるかどうかの違いしかなく、pv の処理には影響しないはずです。 \n実際手元の CentOS6.9 で試してみた限りでは、その違いしか見られませんでした。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T11:46:27.173", "id": "67990", "last_activity_date": "2020-06-25T11:46:27.173", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40823", "parent_id": "67962", "post_type": "answer", "score": 1 }, { "body": "pv プロセスの stdin と stdout に対して、`read(2)` も `write(2)` も呼び出されていません。\n\n```\n\n $ lsb_release -ir\n Distributor ID: Ubuntu\n Release: 20.04\n $ uname -srm\n Linux 5.4.0-37-generic x86_64\n $ pv --version\n pv 1.6.6 - Copyright 2015 Andrew Wood <[email protected]>\n \n $ cat /dev/urandom | pv -rf -t -i 2 >/dev/null 2>output & strace -p $! -e read,write\n :\n write(2, \"0:00:02 [31.7MiB/s]\", 19) = 19\n write(2, \"\\r\", 1) = 1\n write(2, \"0:00:04 [33.0MiB/s]\", 19) = 19\n write(2, \"\\r\", 1) = 1\n :\n \n```\n\n`read(2)` や `write(2)` に変わる何か(system call)が使われているだろうと推測して、以下を実行してみた所、\n\n```\n\n $ cat /dev/urandom | pv -rf -t -i 2 >/dev/null 2>output & strace -p $! | grep -E '\\([01],'\n :\n select(1, [0], [], NULL, {tv_sec=0, tv_usec=90000}) = 1 (in [0], left {tv_sec=0, tv_usec=86340})\n splice(0, NULL, 1, NULL, 131072, SPLICE_F_MORE) = 131072\n :\n \n```\n\n`splice(2)` が使われている事が判りました。\n\n**man splice(2)**\n\n> splice() moves data between two file descriptors **without copying** between\n> kernel address space and user address space.\n\npv には `splice(2)` を利用しないオプションスイッチがあります。\n\n**man pv(1)**\n\n> -C, --no-splice \n> Never use splice(2), even if it would normally be possible. **The splice(2)\n> system call is a more efficient way of transferring data from or to a pipe\n> than regular read(2) and write(2)** , but means that the transfer buffer may\n> not be used. This prevents -A and -T from working, so if you want to use -A\n> or -T then you will need to use -C, at the cost of a small loss in transfer\n> efficiency. (This option has no effect on systems where splice(2) is\n> unavailable).\n```\n\n $ cat /dev/urandom | pv -C -rf -t -i 2 >/dev/null 2>output & strace -p $! -e read,write\n :\n read(0, ...\n write(1, ...\n read(0, ...\n write(1, ...\n :\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T14:54:02.927", "id": "68038", "last_activity_date": "2020-06-26T15:05:48.627", "last_edit_date": "2020-06-26T15:05:48.627", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "67962", "post_type": "answer", "score": 1 } ]
67962
67979
67979
{ "accepted_answer_id": null, "answer_count": 0, "body": "初めて利用させていただきます、宜しくお願い致します。\n\nWordpressのテーマにてカスタム投稿タイプを使用していますが、 \n複数のカスタム投稿タイプへ繋がるページャーは設定できるのでしょうか。\n\n例えば「A」と「B」の2つのカスタム投稿タイプがあったとして、 \nAの投稿ページ(仮に single-a.php とします)にページャーを設置したとき、AとBを合体させて、\n\n```\n\n Aの1月の投稿\n \n ↓「<前の記事」をクリック\n \n Bの2月の投稿\n \n ↓「<前の記事」をクリック\n \n Aの3月の投稿\n \n```\n\nのようにページを遷移させたいです。\n\nWPはほぼ素人なので、ググってもなかなかヒットせず…。 \nどのような仕組みでできるか教えていただけると幸いです。 \n出来るか出来ないか、簡単か難しいかだけでも構いません。\n\n宜しくお願い致します。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T15:16:54.953", "favorite_count": 0, "id": "67963", "last_activity_date": "2020-06-24T15:16:54.953", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40808", "post_type": "question", "score": 0, "tags": [ "php", "wordpress" ], "title": "複数のカスタム投稿タイプへ繋がるページャーを出力", "view_count": 91 }
[]
67963
null
null
{ "accepted_answer_id": "67970", "answer_count": 1, "body": "以下のようなデータがあります。\n\nsample code:\n\n```\n\n import pandas as pd\n \n arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']),\n np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'])]\n \n s = pd.Series(np.random.randn(8), index=arrays)\n \n print(s)\n \n```\n\noutput:\n\n```\n\n bar one -0.431204\n two -0.476479\n baz one -0.758383\n two -0.263379\n foo one -0.353537\n two -0.202995\n qux one -0.774872\n two -0.011614\n dtype: float64\n \n```\n\nこのデータを\n\n```\n\n one two\n bar -0.43 -047\n baz -0.75 -0.26\n foo ... ...\n qux ... ...\n \n```\n\nのような形式にするためにはどうすればよいでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T22:24:47.537", "favorite_count": 0, "id": "67968", "last_activity_date": "2020-06-25T00:28:14.870", "last_edit_date": "2020-06-25T00:28:14.870", "last_editor_user_id": "3060", "owner_user_id": "28294", "post_type": "question", "score": 0, "tags": [ "python", "pandas" ], "title": "MultiindexなSeriesを表形式に変換する方法", "view_count": 160 }
[ { "body": "`unstack(level=-1)`を使えば出来るでしょう。 \nちょうど類似の説明がドキュメントに書いてあります。 \n[pandas.Series.unstack](https://pandas.pydata.org/pandas-\ndocs/stable/reference/api/pandas.Series.unstack.html)\n\n質問内容に適用すれば以下のようになるでしょう。\n\n```\n\n s = s.unstack(level=-1)\n \n```\n\n結果\n\n```\n\n one two\n bar -0.431204 -0.476479\n baz -0.758383 -0.263379\n foo -0.353537 -0.202995\n qux -0.774872 -0.011614\n \n```\n\nちなみに何故かマイナスではない`(level=1)`でも同様の結果になるようです。 \nそして`0`と`-2`が同じ結果で以下のようになり、`-3`と`2`はエラーになりました。\n\n```\n\n bar baz foo qux\n one -0.431204 -0.758383 -0.353537 -0.774872\n two -0.476479 -0.263379 -0.202995 -0.011614\n \n```\n\n* * *\n\n小数点以下の桁数を変更する場合、表示する値そのものの変更は`round()`等で、値は変えずに表示形式だけ変更するなら`display.float_format`で変えられるようです。 \n[pandasで数値を丸める(四捨五入、偶数への丸め)](https://note.nkmk.me/python-pandas-round-\ndecimal/) \n[Pythonで小数・整数を四捨五入するroundとDecimal.quantize](https://note.nkmk.me/python-round-\ndecimal-quantize/)\n\n[pandasの表示設定変更(小数点以下桁数、有効数字、最大行数・列数など)](https://note.nkmk.me/python-pandas-\noption-display/)\n\nただし変更後の数値がどのようになるかは、それぞれの処理方法や指定によるでしょう。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T23:10:17.290", "id": "67970", "last_activity_date": "2020-06-24T23:36:00.383", "last_edit_date": "2020-06-24T23:36:00.383", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "67968", "post_type": "answer", "score": 1 } ]
67968
67970
67970
{ "accepted_answer_id": "67978", "answer_count": 3, "body": "私は、複数のスレッドから以下のArrayの要素にアクセスすることを考えました。 \n加えて、インデックスをatomicに管理することで、複数のスレッドから同時に同じ要素には触らないという条件を設けました。\n\n```\n\n std::array<uint8_t, SIZE> ar;\n std::array<Struct_70bit, SIZE> ar; //あるいはsizeof(size_t)の幅で区切ることが出来ない型\n \n```\n\nこの場合、隣り合った要素はスレッドセーフに読み書きできますか?\n\nもしスレッドセーフでない場合の対策として、私は以下のようにすることを考えましたが、これは正しいですか?\n\n```\n\n alignas(size_t) std::array<uint8_t, SIZE> ar;\n alignas(size_t) std::array<Struct_70bit, SIZE> ar;\n \n```\n\nP.S. \nスレッドセーフの定義が曖昧だとご指摘いただきました。 \n私自身がスレッドセーフという言葉を取り違えていました。お詫びします。 \nここではさらに具体的に、「特別な管理によって配列の同じインデックスにアクセスすることはないが、小さな型のとき隣り合った要素アクセスにはデータ競合が生じるか(アクセスした要素の周囲の要素が、意図しない値になるか)」という点についての質問でした。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-24T22:36:15.000", "favorite_count": 0, "id": "67969", "last_activity_date": "2020-06-27T00:36:11.120", "last_edit_date": "2020-06-26T07:44:02.743", "last_editor_user_id": "37013", "owner_user_id": "37013", "post_type": "question", "score": 0, "tags": [ "c++" ], "title": "sizeof(size_t)未満の幅の型の、メモリ上隣り合った変数に関して、マルチスレッドプログラムはデータ競合なく読み書きできますか?", "view_count": 378 }
[ { "body": "スレッドセーフ / atomic という用語の解釈次第なところがありますが、この手の話が問題になるのはメインメモリのほかにキャッシュを持つマルチコア CPU\n(ないしは SMP 構成) の場合に限定できるでしょう。\n\nアトミックという用語は「その変数の1回の読み書きが他者に阻害されない」という意味でしかありません。よって、マルチコア/SMP 構成で、複数のコア / CPU\nが複数の変数を連続的に読み書きする場合に「順番が入れ替わったように観測される」ことによるスレッド安全性までは担保されません。\n\n[メモリバリア](https://ja.wikipedia.org/wiki/%E3%83%A1%E3%83%A2%E3%83%AA%E3%83%90%E3%83%AA%E3%82%A2)\nで説明されている、最近の高性能 CPU が持つ「アウトオブオーダー」な実行に対して、\n\n * それでもよい\n\nならばおそらく提示されたソースで十分です (x86 / x64 はこちらの状況にはならないと推測でき、検証するなら他の CPU で試す必要がある)\n\n * それはスレッドセーフでない\n\nなら真にメモリバリアが必要で、その場合 `alignas` ではおそらくダメで `std::atomic` な指定が必要になると思われます。\n\n検証例1\n\n```\n\n std::array<uint8_t, SIZE> a1;\n alignas(size_t) std::array<uint8_t, SIZE> a2;\n \n```\n\nに対して\n\n * cygwin64 の gcc-8.2.0 / 9.3.0 は `movb` を生成\n * s2019 の cl.exe version 19.26.28806 for x64 は `mov byte ptr` を生成\n\nメモリバリアな命令を生成していない (高速)\n\n検証例2\n\n```\n\n std::array<std::atomic<uint8_t>, SIZE> ar3;\n \n```\n\n * cygwin64 の gcc-8.2.0 / gcc-9.3.0 は `movb` のほかに `mfence` 命令を追加生成\n * vs2019 の cl.exe version 19.26.28806 for x64 は `mov` の代わりに `xchg` 命令を生成\n\nメモリバリアな命令が生成されている (超絶遅い)\n\nということで `std::atomic`\nにすると安全かもしれませんが超絶遅くなります。なので「スレッドセーフ」の意味をきっちり定義してから始めたほうがよさそうです。\n\n* * *\n\nこの話は純粋にハードウエアレベルのことなので、コンパイラが [c](/questions/tagged/c \"'c' のタグが付いた質問を表示\") だろうと\n[c++](/questions/tagged/c%2b%2b \"'c++' のタグが付いた質問を表示\") だろうと\n[golang](/questions/tagged/golang \"'golang' のタグが付いた質問を表示\")\nだろうとあまり違いは無くてどの言語を使っても問題は発生します。\n\n* * *\n\n32bit CPU で同一データバス 32bit 内の違う 8bit に異なるスレッドから「単純 write\n」を行ってもハードウエア上データは壊れません(そのように CPU は作ってあります)\n安心してください。ただし「アトミックである型」でアクセスしたとき限定です。\n\n```\n\n struct test_type {\n unsigned char a;\n unsigned int x:4;\n unsigned int y:8;\n unsigned int z:4;\n };\n \n```\n\nのようなものを作ったとしたら、おそらくは `a` はアトミックですが `y` はアトミックであることを期待してはいけません\n(アトミックになるかもしれないしならないかもしれない)\n\nまた原理的に read-modify-write になるアクションはアトミック操作になりえませんので注意。 `ar[i]++;` のような書き換えは\n`ar[i]` が `char` 型であってもアトミック操作ではありません。時と場合によっては処理系が `InterlockedIncrement`\nみたいな API を用意していますので、これを使うしかないです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T03:25:28.583", "id": "67978", "last_activity_date": "2020-06-26T03:59:52.073", "last_edit_date": "2020-06-26T03:59:52.073", "last_editor_user_id": "8589", "owner_user_id": "8589", "parent_id": "67969", "post_type": "answer", "score": 3 }, { "body": "> sizeof(size_t)未満の幅の型の、メモリ上隣り合った変数に関して、マルチスレッドプログラムはデータ競合なく読み書きできますか?\n\nはい、できます。C++言語仕様は、異なるスレッドから **異なる変数** に対してそれぞれ同時アクセスしても安全であることを保障します。\n\n>\n> 特別な管理によって配列の同じインデックスにアクセスすることはないが、小さな型のとき隣り合った要素アクセスにはデータ競合が生じるか(アクセスした要素の周囲の要素が、意図しない値になるか)\n\n前述の通り、データ競合は発生しません。最もサイズが小さい`char`型の配列であっても、下記コードは安全に実行されます。\n\n```\n\n char arr[2] = {1, 2};\n \n // スレッド1\n arr[0] = 100;\n \n // スレッド2\n int r = arr[1];\n \n```\n\n* * *\n\nC++言語としてはプログラムが安全に動作することを保障しますが、現実的にはプログラムは正常動作するものの速度ペナルティを受けることがあります。現代のプロセッサはメモリキャッシュ(Memory\ncache)機構を備えており、この速度ペナルティはキャッシュ管理単位「キャッシュライン(Cache line)」に起因します。\n\n例えば`char`型配列の隣接要素はC++言語としては異なる変数ですが、プロセッサはこれらを同一キャッシュラインとして扱います。この状況を「False\nSharing(偽共有)」と呼びます。\n\nFalse Sharing\nが起きている状況で、異なるスレッドから書込(`arr[0]=100`)と読込(`r=arr[1]`)を行うと同一キャッシュラインに対する読み書き競合が発生し、プログラム実行速度が低下するという事象が発生します。あくまでも処理が遅くなるだけで、プログラムは正しく動作します。\n\nC++17からは False Sharing を回避する、つまり隣接する変数のメモリアドレスを意図的に離す仕組みを提供します。\n\n```\n\n // 通常は同一構造体内の2個のatomic<int>変数は隣接メモリアドレスに配置される。\n // alignas(~)により2個の変数アドレスがキャッシュラインサイズの倍数に整列、\n // つまり必ず異なるキャッシュラインに載るようメモリ位置を離すよう指示する。\n struct keep_apart {\n alignas(std::hardware_destructive_interference_size) std::atomic<int> cat;\n alignas(std::hardware_destructive_interference_size) std::atomic<int> dog;\n };\n \n```\n\n * <https://en.cppreference.com/w/cpp/thread/hardware_destructive_interference_size>\n * <https://cpprefjp.github.io/reference/new/hardware_destructive_interference_size.html>", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T08:56:08.710", "id": "68028", "last_activity_date": "2020-06-26T09:16:33.443", "last_edit_date": "2020-06-26T09:16:33.443", "last_editor_user_id": "49", "owner_user_id": "49", "parent_id": "67969", "post_type": "answer", "score": 3 }, { "body": "参考までに、[バイト単位のロード・ストア命令を持たないプロセッサアーキテクチャ](https://ja.wikipedia.org/wiki/DEC_Alpha#%E8%A8%AD%E8%A8%88%E5%8E%9F%E5%89%87)も存在します。この場合、1バイト書き込みを実現するためには\n\n 1. 4バイト読み込みし\n 2. 希望する位置のバイトを書き換え\n 3. 4バイト書き込み\n\nという手順を踏むため、隣り合った要素はスレッドセーフに書き込みできません(たぶん)。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T00:36:11.120", "id": "68047", "last_activity_date": "2020-06-27T00:36:11.120", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "67969", "post_type": "answer", "score": 1 } ]
67969
67978
67978
{ "accepted_answer_id": null, "answer_count": 0, "body": "チャットルームのなかにBotを追加して社内の共有ドライブやマイドライブ内のファイルを掲示できるようにしたいのですが可能でしょうか?もしあればやり方やgasのコード等のご教示いただけないでしょうか? \nよろしくお願いいたします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T00:32:13.513", "favorite_count": 0, "id": "67971", "last_activity_date": "2020-06-25T00:32:13.513", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37984", "post_type": "question", "score": 0, "tags": [ "google-apps-script" ], "title": "ハングアウトチャットを利用したBot作成", "view_count": 68 }
[]
67971
null
null
{ "accepted_answer_id": null, "answer_count": 2, "body": "ある測定器からの信号を Spresense で処理しようとしています。\n\nピンの一つを GPIO として使って、測定器の値が用意できたことを示すトリガー信号による割り込みを受け付けるようにしています。\n\n * その際、トリガー信号を直にピンに接続すると発振してしまいます\n * トリガー信号からインバーター (NOT) を 2 段経由してピンに接続すると安定して割り込みを受けることができます\n\n測定器の回路に依存する話なのかもしれませんが、インバーターを使わずに安定して信号を受ける方法はないものでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T02:31:21.137", "favorite_count": 0, "id": "67975", "last_activity_date": "2020-06-25T17:42:20.233", "last_edit_date": "2020-06-25T04:22:18.333", "last_editor_user_id": "3060", "owner_user_id": "40811", "post_type": "question", "score": 4, "tags": [ "spresense" ], "title": "測定器からの信号を Spresense に直接繋ぐと発振してしまう", "view_count": 215 }
[ { "body": "ケーブルを何 cm 延長していますか? \nマイコンというか CMOS-IC の入力ピンに直結している信号を基板から引き出して使うと 10cm\nくらいしか延ばせません。それ以上に引き出すと指摘のある通り動作が不安定になります(経験的に 15cm がギリギリで 20cm\n以上にすると必ず失敗します)。ノイズが乗って発振してしまうのはそのうちの一例に過ぎないです。\n\nUSB だの SATA だの、あるいは RS232(EIA574) 今は無き IEEE1394\nだの、シリアル通信バスに専用回路が入っているのは伊達ではないのです。\n\n> インバーターを使わずに安定して信号を受ける方法\n\nCMOS 信号出力の機器1と CMOS 信号入力の機器2を 10cm を超えて直結している限り絶対に安定しません。\n\n * 中距離・長距離伝送に適した信号に変換する (RS232 とか RS485 とか LVDS とか)\n * 最短距離で接続し総延長を1桁 cm 以下にする\n * ノイズ対策用の C/R/D を挿入する\n\nあたりが取れる対策でしょう。具体的にどんな回路にするかは伝送距離、通信速度、周囲ノイズレベルなどなど、用途とコスト次第で違います。\n\nC/R/D だけでも(短距離なら)そこそこ効果ありますしやってみますか?具体的回路が知りたいなら検索してみてください(オイラでも答えられますが SO\n向き話題とも思えない)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T04:21:08.367", "id": "67980", "last_activity_date": "2020-06-25T04:21:08.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "67975", "post_type": "answer", "score": 1 }, { "body": "公式サイトにこのような記述があります。\n\n[https://developer.sony.com/develop/spresense/docs/hw_docs_ja.html#_拡張基板でのデジタル信号uartspipwmgpio使用上の注意](https://developer.sony.com/develop/spresense/docs/hw_docs_ja.html#_%E6%8B%A1%E5%BC%B5%E5%9F%BA%E6%9D%BF%E3%81%A7%E3%81%AE%E3%83%87%E3%82%B8%E3%82%BF%E3%83%AB%E4%BF%A1%E5%8F%B7uartspipwmgpio%E4%BD%BF%E7%94%A8%E4%B8%8A%E3%81%AE%E6%B3%A8%E6%84%8F)\n\n入力の信号のインピーダンスが低い場合は。バッファが必要なようですね。 \nもし該当であった場合、バッファを入れてみてはどうでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T17:42:20.233", "id": "68003", "last_activity_date": "2020-06-25T17:42:20.233", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32281", "parent_id": "67975", "post_type": "answer", "score": 1 } ]
67975
null
67980
{ "accepted_answer_id": null, "answer_count": 0, "body": "こんにちは。Pepperを使って地域施設の館内説明を自動化しようとしています。 \n開発担当を今年引き継いだのですがこれまではChoregrapheで開発していた環境が \n今年からはAndroid Studioに変更になってしまったので一からは作り直しています。\n\nAndroid\nStudioの基本は大体理解したのですがローカライズという機能は外部の影響で途中で停止してしまうという事でその他の手法を試そうという事になりました。 \nそこでChoregraphe時の記事でラズベリーパイとpepperを通信してデータに応じてpepperが発話するというものがありました。\n\n参考: \n[今回は温度センサとPepperを連動させたラズパイハンズオン!](https://pepper-atelier-\nakihabara.jp/archives/2213)\n\nこのような事は現在のAndroid Studioでも可能でしょうか? \n理想の形としてはpepperとラズベリーパイを通信して、ラズベリーパイにライントレースを搭載してラズベリーパイのデータをもとにpepperが自律移動して一定の場所で停止し館内説明を行うというものです。\n\nそして可能ならどのようにラズベリーパイと通信を行うのか、その他の情報に関しては全くの無知ですので分かりやすく教えていただけたらと思います。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T02:45:59.233", "favorite_count": 0, "id": "67976", "last_activity_date": "2020-06-25T04:44:09.690", "last_edit_date": "2020-06-25T04:44:09.690", "last_editor_user_id": "3060", "owner_user_id": "40815", "post_type": "question", "score": 0, "tags": [ "android-studio", "raspberry-pi" ], "title": "Pepperを自律移動させる場合に外部(ラズベリーパイ等)からのデータを取得して制御する方法を知りたい", "view_count": 68 }
[]
67976
null
null
{ "accepted_answer_id": null, "answer_count": 3, "body": "# エラーの詳細\n\nアプリをsnapでインストールしようとすると下記のエラーが出る。\n\n```\n\n $ sudo apt install snapd\n $ sudo snap install mini-diary\n \n error: cannot communicate with server: Post http://localhost/v2/snaps/mini-diary: dial unix /run/snapd.socket: connect: no such file or directory\n \n```\n\n# バージョン\n\n```\n\n $ snap --version\n snap 2.37.4-1+b1\n snapd unavailable\n series -\n \n```\n\n# OS\n\nMX Linux\n\n```\n\n $ cat /etc/debian_version\n 10.4\n \n $ cat /etc/lsb-release\n PRETTY_NAME=\"MX 19.2 patito feo\"\n DISTRIB_ID=MX\n DISTRIB_RELEASE=19.2 \n DISTRIB_CODENAME=\"patito feo\"\n DISTRIB_DESCRIPTION=\"MX 19.2 patito feo\"\n \n```\n\n## インストールした際の画面\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/y3Jmg.png)](https://i.stack.imgur.com/y3Jmg.png)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T03:18:48.940", "favorite_count": 0, "id": "67977", "last_activity_date": "2023-01-30T02:08:46.087", "last_edit_date": "2020-06-29T04:19:01.927", "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": 1, "tags": [ "linux" ], "title": "Snapdのエラーを解決したい: cannot communicate with server", "view_count": 8752 }
[ { "body": "snapd が起動していないように見えます。MX Linux の環境が手元に無いので試していませんが、`systemctl start\nsnapd.service` (systemd の場合) や `service snapd start` (sysVinit の場合)\nなどの方法でデーモンを起動させれば動かないでしょうか。", "comment_count": 7, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T11:29:16.377", "id": "67989", "last_activity_date": "2020-06-28T15:58:35.403", "last_edit_date": "2020-06-28T15:58:35.403", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "67977", "post_type": "answer", "score": 0 }, { "body": "自分も同じ現象に悩まされてきました。UBUNTU-20.04です。 \n[こちらのサイト](https://qiita.com/matarillo/items/f036a9561a4839275e5f)を参考に、以下の方法で、snap\nを使えるようになりました。\n\n但し事前に、 \nsudo apt update \nsudo apt upgrade -y \nsudo apt install daemonize をする必要が有りました。\n\n[Running Snaps on WSL2 (Insiders only for\nnow)](https://forum.snapcraft.io/t/running-snaps-on-wsl2-insiders-only-for-\nnow/13033)", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2021-03-27T17:41:27.207", "id": "74933", "last_activity_date": "2021-03-29T04:19:08.893", "last_edit_date": "2021-03-29T04:19:08.893", "last_editor_user_id": "44532", "owner_user_id": "44532", "parent_id": "67977", "post_type": "answer", "score": 0 }, { "body": "snaps には, systemdが必要そうです。もう一度 環境を確認してみるのも良いかも\n\n```\n\n $ systemctl status snapd.service\n snapd.service - Snap Daemon\n Loaded: loaded (/lib/systemd/system/snapd.service; enabled; vendor preset: enabled)\n Active: active (running) since Thu 2021-03-25 05:36:01 JST; 4 days ago\n TriggeredBy: snapd.socket\n Main PID: 1254 (snapd)\n Tasks: 19 (limit: 18118)\n \n $ snap version\n snap 2.49.1\n snapd 2.49.1\n series 16\n ubuntu 20.10\n kernel 5.8.0-48-generic\n \n```\n\nUbuntuでは, 上記のメッセージ(とログ)が出ました\n\n参考:\n\n * [SOLVED - Cannot install snaps on Linux MX19 patito feo](https://forum.snapcraft.io/t/solved-cannot-install-snaps-on-linux-mx19-patito-feo/14976)\n * [MX Linux(Debian)でSnapdが動かない?](https://nyakki-yossi.hatenablog.com/entry/2019/03/18/021440)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2021-03-29T04:51:16.657", "id": "74960", "last_activity_date": "2021-03-29T04:51:16.657", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "43025", "parent_id": "67977", "post_type": "answer", "score": 0 } ]
67977
null
67989
{ "accepted_answer_id": null, "answer_count": 0, "body": "sql文を使って、table1からtable2にflagの情報を追加したいときに、 \ntable1の中の \nflag = '1'の場合、'1'を設定 \nflag = '0'の場合、nullを設定 \nがしたいですが\n\n```\n\n insert into table2 select pk1,pk2,pk3,(case when flag='1' then '1' else null end) as col1 from table1\n \n```\n\nを実行するときに、aはPRIMARY KEYではありませんが、一意制約違反のエラーが出ます。 \nどうにもうまくできませんでした。\n\ntable1とtable2の構成について\n\n```\n\n CREATE TABLE table1\n pk1 CHAR(13) NOT NULL,\n pk2 NUMBER(3,0) NOT NULL,\n pk3 CHAR(13) NOT NULL,\n flag CHAR(1),\n etc...\n CONSTRAINT PK_table1 PRIMARY KEY (CUST_NUM, CUST_SEQ, REC_NUM) USING INDEX\n \n```\n\ntable1とtable2の構成が一緒で、table2に前期のデータと今期(table1)のデータを入れたいです。\n\n初めて質問するので不足しているところが多々あると思いますが、 \nどなたがご教授いただければ幸いです。よろしくお願いいたします。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T04:36:37.913", "favorite_count": 0, "id": "67981", "last_activity_date": "2020-06-25T11:18:22.733", "last_edit_date": "2020-06-25T11:18:22.733", "last_editor_user_id": "19110", "owner_user_id": "40817", "post_type": "question", "score": 0, "tags": [ "sql" ], "title": "INSERT INTO したときに一意制約違反のエラーが出る", "view_count": 1530 }
[]
67981
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "下のようなプログラムを作りたいのですがうまくいきません。どうしてもわからないのでどなたか解答を教えてくれませんか。 \nよろしくお願いしますm(__)m\n\n```\n\n /*\n * Ex07\n * 球体を表すクラス Ball を作成せよ。\n * 具体的には、以下のコンストラクタとメソッドを作成せよ。\n * Ball(int radius) ------------ 半径radiusの球体を生成する\n * Ball(Ball ball) ------------- 球体ballのクローンを生成する\n * int getRadius() ------------- 半径を取得する\n * void setRadius(int radius) -- 半径を設定する\n * double computeVolume() ------ 体積を計算する\n * boolean equalTo(Ball ball) -- 球体ballと同じ大きさか判定する\n * String toString() ----------- 文字列表現「Ball(radius)」を得る\n *\n * ただし、フィールドとして int radius を使用すること。\n */\n import java.util.Scanner;\n class Ball {\n \n // フィールド(変更禁止)\n private int radius; // 半径\n \n // コンストラクタ(変更禁止)\n public Ball() {\n }\n \n // コンストラクタ(要作成)\n public Ball(int radius) {\n \n }\n \n // コンストラクタ(要作成)\n public Ball(Ball ball) {\n \n }\n \n // 半径を取得するメソッド(要作成)\n public int getRadius() {\n \n return -1; // 不要ならば削除すること\n }\n \n // 半径を設定するメソッド(要作成)\n public void setRadius(int radius) {\n double r; // 半径\n Scanner scanner = new Scanner(System.in);\n \n System.out.print( \"半径:\" );\n r = scanner.nextDouble();\n \n }\n \n // 体積を計算するメソッド(要作成)\n public double computeVolume() {\n \n return(4.0 / 3.0 * 3.14 * radius * radius * radius);\n \n }\n \n // 球体ballと同じ大きさか判定する(要作成)\n public boolean equalTo(Ball ball) {\n \n return false; // 不要ならば削除すること\n }\n \n // 文字列表現を得る(要作成)\n public String toString() {\n \n return \"\"; // 不要ならば削除すること\n }\n }\n \n```", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T05:48:04.143", "favorite_count": 0, "id": "67982", "last_activity_date": "2020-07-24T06:49:31.263", "last_edit_date": "2020-06-25T15:08:51.110", "last_editor_user_id": "40820", "owner_user_id": "40820", "post_type": "question", "score": 0, "tags": [ "java" ], "title": "java 球体を表すBallクラス", "view_count": 371 }
[ { "body": "クラスのフィールドとメソッドの使い方が分かればその応用で解決できます。\n\n * Ball(int radius) ------------ 半径radiusの球体を生成する \n * radiusを書き換えるので、コンストラクタの中でsetRadiusメソッドを呼び出せば解決です。\n * Ball(Ball ball) ------------- 球体ballのクローンを生成する \n * こちらは別のインスタンスから半径を取ってきてradiusを書き換えるので、`ball.getRadius();`で取得したradiusを上のコンストラクタと同様にsetRadiusで書き換えます。\n * int getRadius() ------------- 半径を取得する \n * この演習までの教材に`return`の使い方が載っていたと思いますので、それを参考にしてみましょう。 \nこのサイトの類似QA: [戻り値についてとvoidについて](https://ja.stackoverflow.com/a/11560/9820)\n\n * void setRadius(int radius) -- 半径を設定する \n * `this`キーワードをうまく使いましょう。 \n少し発展的な類似QA: [継承したクラスのメンバ変数を差し替えたい](https://ja.stackoverflow.com/q/4642/9820)\n\n * double computeVolume() ------ 体積を計算する \n * 類似の[演習問題](http://www.aoni.waseda.jp/ichiji/2012/java-01/java-05-1.html)サイトのどこかに解答が載っています。\n * boolean equalTo(Ball ball) -- 球体ballと同じ大きさか判定する \n * このインスタンスのradiusとball.getRadius()を比較演算子で比較した結果をreturnしましょう。\n * String toString() ----------- 文字列表現「Ball(radius)」を得る \n * 文字列のフォーマットが分かりませんが、例えば下記のサンプルコードで半径と体積を表現できます。\n\n```\n\n public String toString() {\n return String.format(\"ボールの半径は%d, 体積は%fです。\", radius, computeVolume());\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-24T06:49:31.263", "id": "68894", "last_activity_date": "2020-07-24T06:49:31.263", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "67982", "post_type": "answer", "score": 1 } ]
67982
null
68894
{ "accepted_answer_id": "68002", "answer_count": 1, "body": "# 実現したいこと\n\ngit push heroku master した時のNoMethodError: undefined method `to_sym' for\nnil:NilClassを解消して、デプロイに成功させたい\n\n# 背景\n\nAction_mailerとHeroku shcedulerを使って定期的にメールを1通ユーザーに送る実装をしようと考えていました。そこで、gem\nfigaroを使って実装進めていました。\n\n# 環境\n\nRails:5.2.4 \nDB:PostgreSQL \nRubyのbuildpackはインストール済 \n(heroku create --buildpack <https://github.com/heroku/heroku-buildpack-\nruby.git>) \nheroku addons:add scheduler:standard\n\n# 今起こっている問題\n\ngit push heroku\nmasterする際に、3つのエラーが発生しており、そのうち2つは[自分の昨日の記事](https://ja.stackoverflow.com/questions/67934/git-\npush-heroku-\nmaster%e3%81%a7%e7%99%ba%e7%94%9f%e3%81%99%e3%82%8b%e3%82%a8%e3%83%a9%e3%83%bc-\nprecompiling-assets-failed-error-failed-to-\npu)と同じものなのですが、もう1つ、下記のようなエラーに初めて出くわしました。\n\n```\n\n remote: rake aborted!\n remote: NoMethodError: undefined method `to_sym' for nil:NilClass\n \n```\n\n出てきたエラーに対しログを辿っても、意味が理解できず、解決に苦しんでおります。何か、アドバイス頂ければ幸いです。\n\nto_sym:シンボルを返すrubyのメソッドで、`production.rb`内の\n\n```\n\n config.action_mailer.delivery_method = ENV['delivery_method'].to_sym\n \n```\n\nこれが悪さしている?気がします。\n\n# 試したこと\n\n①`gem figaro`をインストール\n\n②`bundle exec figaro install`\n\n③生成された`application.yml`で、以下のように編集\n\n**application.yml**\n\n```\n\n # Add configuration values here, as shown below.\n #\n # pusher_app_id: \"2954\"\n # pusher_key: 7381a978f7dd7f9a1117\n # pusher_secret: abdc3b896a0ffb85d373\n # stripe_api_key: sk_test_2J0l093xOyW72XUYJHE4Dv2r\n # stripe_publishable_key: pk_test_ro9jV5SNwGb1yYlQfzG17LHK\n # メール送信サーバの設定(gmail)\n delivery_method: smtp\n smtp_enable_starttls_auto: true\n smtp_address: smtp.gmail.com\n smtp_port: 587\n smtp_domain: gmail.com\n smtp_authentication: plain\n smtp_user_name: (送信元アドレス)@gmail.com\n smtp_password: (2段階認証で設定したアプリパスワード)\n \n # production:\n # stripe_api_key: sk_live_EeHnL644i6zo4Iyq4v1KdV9H\n # stripe_publishable_key: pk_live_9lcthxpSIHbGwmdO941O1XVU\n \n```\n\n④`production.rb`には、下記の通り編集\n\n```\n\n Rails.application.configure do\n # Settings specified here will take precedence over those in config/application.rb.\n config.action_mailer.raise_delivery_errors = true\n config.action_mailer.delivery_method = ENV['delivery_method'].to_sym\n config.action_mailer.default_url_options = { host: 'quiet-escarpment-59252.herokuapp.com'}\n config.action_mailer.smtp_settings = {\n enable_starttls_auto: ENV['smtp_enable_starttls_auto'],\n address: ENV['smtp_address'],\n port: ENV['smtp_port'],\n domain: ENV['smtp_domain'],\n authentication: ENV['smtp_authentication'],\n user_name: ENV['smtp_user_name'],\n password: ENV['smtp_password']\n }\n \n \n```\n\nその後、全ての変更は、 git add -A, git commit -m \"Message\"で行い,git push heroku\nmasterでデプロイに挑戦しましたが、すべてデプロイできませんでした、、、お力貸して頂けますと幸いです。\n\n# エラー全文\n\n**ログ**\n\n```\n\n -----> Ruby app detected\n -----> Installing bundler 2.0.2\n -----> Removing BUNDLED WITH version in the Gemfile.lock\n -----> Compiling Ruby/Rails\n -----> Using Ruby version: ruby-2.6.5\n -----> Installing dependencies using bundler 2.0.2\n Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment\n The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.\n Fetching gem metadata from https://rubygems.org/.........\n Using rake 13.0.1\n Using concurrent-ruby 1.1.6\n Using minitest 5.14.1\n Using thread_safe 0.3.6\n Using builder 3.2.4\n Using mini_portile2 2.4.0\n Using erubi 1.9.0\n Using crass 1.0.6\n Fetching rack 2.2.3\n Using nio4r 2.5.2\n Using websocket-extensions 0.1.5\n Using mini_mime 1.0.2\n Using arel 9.0.0\n Using mimemagic 0.3.5\n Using execjs 2.7.0\n Using bcrypt 3.1.13\n Using msgpack 1.3.3\n Using popper_js 1.16.0\n Using method_source 1.0.0\n Using thor 1.0.1\n Using ffi 1.13.0\n Using tilt 2.0.10\n Using bundler 2.0.2\n Using cocoon 1.2.14\n Using coderay 1.1.3\n Using orm_adapter 0.5.0\n Using devise-bootstrap-views 1.1.0\n Using devise-i18n-views 0.3.7\n Using multi_json 1.14.1\n Using hpricot 0.8.6\n Using kaminari-core 1.2.1\n Using pg 1.2.3\n Using temple 0.8.2\n Using turbolinks-source 5.2.0\n Installing rack 2.2.3\n Using i18n 1.8.2\n Using tzinfo 1.2.7\n Using nokogiri 1.10.9\n Using websocket-driver 0.7.2\n Using puma 4.3.5\n Using mail 2.7.1\n Using marcel 0.3.3\n Using bootsnap 1.4.6\n Using sassc 2.3.0\n Fetching figaro 1.2.0\n Using pry 0.13.1\n Using autoprefixer-rails 9.7.6\n Using uglifier 4.2.0\n Using html2slim 0.2.0\n Using slim 4.1.0\n Installing figaro 1.2.0\n Using turbolinks 5.2.1\n Using activesupport 5.2.4.3\n Using loofah 2.5.0\n Using pry-rails 0.3.9\n Using rails-dom-testing 2.0.3\n Using globalid 0.4.2\n Using activemodel 5.2.4.3\n Using jbuilder 2.10.0\n Using rails-html-sanitizer 1.3.0\n Using activejob 5.2.4.3\n Using activerecord 5.2.4.3\n Using actionview 5.2.4.3\n Using kaminari-activerecord 1.2.1\n Using polyamorous 2.3.2\n Using kaminari-actionview 1.2.1\n Using ransack 2.3.2\n Using kaminari 1.2.1\n Using rack-test 1.1.0\n Using warden 1.2.8\n Using request_store 1.5.0\n Using rack-proxy 0.6.5\n Using actionpack 5.2.4.3\n Using sprockets 4.0.0\n Using actioncable 5.2.4.3\n Using actionmailer 5.2.4.3\n Using activestorage 5.2.4.3\n Using railties 5.2.4.3\n Using gon 6.3.2\n Using chart-js-rails 0.1.7\n Using sprockets-rails 3.2.1\n Using responders 3.0.1\n Using jquery-rails 4.4.0\n Using momentjs-rails 2.20.1\n Using rails-i18n 5.1.3\n Using slim-rails 3.2.0\n Using webpacker 4.2.2\n Using sassc-rails 2.1.2\n Using rails 5.2.4.3\n Using bootstrap 4.5.0\n Using devise 4.7.1\n Using sass-rails 6.0.0\n Using devise-i18n 1.9.1\n Using kaminari-bootstrap 3.0.1\n Bundle complete! 39 Gemfile dependencies, 92 gems now installed.\n Gems in the groups development and test were not installed.\n Bundled gems are installed into `./vendor/bundle`\n Removing rack (2.2.2)\n Bundle completed (3.42s)\n Cleaning up the bundler cache.\n -----> Installing node-v10.15.3-linux-x64\n -----> Installing yarn-v1.16.0\n -----> Detecting rake tasks\n -----> Preparing app for Rails asset pipeline\n Running: rake assets:precompile\n done.\n rake aborted!\n NoMethodError: undefined method `to_sym' for nil:NilClass\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/config/environments/production.rb:4:in `block in <main>'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/railtie.rb:216:in `instance_eval'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/railtie.rb:216:in `configure'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/config/environments/production.rb:1:in `<main>'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `block in require'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:257:in `load_dependency'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/engine.rb:608:in `block (2 levels) in <class:Engine>'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/engine.rb:607:in `each'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/engine.rb:607:in `block in <class:Engine>'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/initializable.rb:32:in `instance_exec'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/initializable.rb:32:in `run'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/initializable.rb:61:in `block in run_initializers'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/initializable.rb:50:in `each'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/initializable.rb:50:in `tsort_each_child'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/initializable.rb:60:in `run_initializers'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/application.rb:361:in `initialize!'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/config/environment.rb:5:in `<main>'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `block in require'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:257:in `load_dependency'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.3/lib/active_support/dependencies.rb:291:in `require'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/application.rb:337:in `require_environment!'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/railties-5.2.4.3/lib/rails/application.rb:520:in `block in run_tasks_blocks'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'\n /tmp/build_f385a0a2521e560c2ede3dcc72c22ed8/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'\n Tasks: TOP => environment\n (See full trace by running task with --trace)\n !\n ! Precompiling assets failed.\n !\n ! Push rejected, failed to compile Ruby app.\n ! Push failed\n remote: Verifying deploy...\n remote: \n remote: ! Push rejected to quiet-escarpment-59252.\n remote: \n To https://git.heroku.com/quiet-escarpment-59252.git\n ! [remote rejected] master -> master (pre-receive hook declined)\n error: failed to push some refs to 'https://git.heroku.com/quiet-escarpment-59252.git'\n \n```\n\n**application.yml全文**\n\n```\n\n Rails.application.configure do\n # Settings specified here will take precedence over those in config/application.rb.\n config.action_mailer.raise_delivery_errors = true\n config.action_mailer.delivery_method = ENV['delivery_method'].to_sym\n config.action_mailer.default_url_options = { host: 'quiet-escarpment-59252.herokuapp.com'}\n config.action_mailer.smtp_settings = {\n enable_starttls_auto: ENV['smtp_enable_starttls_auto'],\n address: ENV['smtp_address'],\n port: ENV['smtp_port'],\n domain: ENV['smtp_domain'],\n authentication: ENV['smtp_authentication'],\n user_name: ENV['smtp_user_name'],\n password: ENV['smtp_password']\n }\n \n # user_name: ENV['smtp_user_name'],\n # password: ENV['smtp_password']\n # user_name: ENV['SENDGRID_USERNAME'],\n # password: ENV['SENDGRID_PASSWORD']\n # Code is not reloaded between requests.\n config.cache_classes = true\n \n # Eager load code on boot. This eager loads most of Rails and\n # your application in memory, allowing both threaded web servers\n # and those relying on copy on write to perform better.\n # Rake tasks automatically ignore this option for performance.\n config.eager_load = true\n \n # Full error reports are disabled and caching is turned on.\n config.consider_all_requests_local = false\n config.action_controller.perform_caching = true\n \n # Ensures that a master key has been made available in either ENV[\"RAILS_MASTER_KEY\"]\n # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).\n # config.require_master_key = true\n \n # Disable serving static files from the `/public` folder by default since\n # Apache or NGINX already handles this.\n config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?\n \n # Compress JavaScripts and CSS.\n config.assets.js_compressor = :uglifier\n # config.assets.css_compressor = :sass\n \n # Do not fallback to assets pipeline if a precompiled asset is missed.\n config.assets.compile = true\n \n # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb\n \n # Enable serving of images, stylesheets, and JavaScripts from an asset server.\n # config.action_controller.asset_host = 'http://assets.example.com'\n \n # Specifies the header that your server uses for sending files.\n # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache\n # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX\n \n # Store uploaded files on the local file system (see config/storage.yml for options)\n config.active_storage.service = :local\n \n # Mount Action Cable outside main process or domain\n # config.action_cable.mount_path = nil\n # config.action_cable.url = 'wss://example.com/cable'\n # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\\/\\/example.*/ ]\n \n # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.\n # config.force_ssl = true\n \n # Use the lowest log level to ensure availability of diagnostic information\n # when problems arise.\n config.log_level = :debug\n \n # Prepend all log lines with the following tags.\n config.log_tags = [ :request_id ]\n \n # Use a different cache store in production.\n # config.cache_store = :mem_cache_store\n \n # Use a real queuing backend for Active Job (and separate queues per environment)\n # config.active_job.queue_adapter = :resque\n # config.active_job.queue_name_prefix = \"tt_manager_#{Rails.env}\"\n \n config.action_mailer.perform_caching = false\n \n # Ignore bad email addresses and do not raise email delivery errors.\n # Set this to true and configure the email server for immediate delivery to raise delivery errors.\n # config.action_mailer.raise_delivery_errors = false\n \n # Enable locale fallbacks for I18n (makes lookups for any locale fall back to\n # the I18n.default_locale when a translation cannot be found).\n config.i18n.fallbacks = true\n \n # Send deprecation notices to registered listeners.\n config.active_support.deprecation = :notify\n \n # Use default logging formatter so that PID and timestamp are not suppressed.\n config.log_formatter = ::Logger::Formatter.new\n \n # Use a different logger for distributed setups.\n # require 'syslog/logger'\n # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')\n \n if ENV[\"RAILS_LOG_TO_STDOUT\"].present?\n logger = ActiveSupport::Logger.new(STDOUT)\n logger.formatter = config.log_formatter\n config.logger = ActiveSupport::TaggedLogging.new(logger)\n end\n \n # Do not dump schema after migrations.\n config.active_record.dump_schema_after_migration = false\n end\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T06:26:32.997", "favorite_count": 0, "id": "67983", "last_activity_date": "2020-06-25T17:23:03.617", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39475", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "heroku", "gmail", "rbenv", "sendmail" ], "title": "git push heroku master した時のNoMethodError: undefined method `to_sym' for nil:NilClassを解消したい", "view_count": 696 }
[ { "body": "確かに、\n\n```\n\n config.action_mailer.delivery_method = ENV['delivery_method'].to_sym\n \n```\n\nの行でエラーになっていそうです。環境変数 `delivery_method` を設定しておらず `ENV['delivery_method']` が\n`nil` になったため、`nil.to_sym` をしようとしてエラーになっているように見えます。\n\n本来ならば application.yml に書いてある設定を figaro gem\nが読み込んで環境変数に出してくれるはずなので、この一連の流れのどこかが上手くいってなさそうですね。\n\nで、figaro gem の初期設定では application.yml は .gitignore されるので Heroku の環境側に\napplication.yml が存在していないのではないでしょうか。このファイルには秘匿値も入りうる想定なので、単に git push\nするのでは公開されないようになっています。この仮説のもと質問者さんの操作手順を見ると、Heroku の環境に application.yml\nを送り込むコマンドである、\n\n```\n\n figaro heroku:set -e production\n \n```\n\nを実行していなさそうです。README の <https://github.com/laserlemon/figaro#deployment>\nあたりに書かれているので、こちらを試してみてください。", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T17:23:03.617", "id": "68002", "last_activity_date": "2020-06-25T17:23:03.617", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "67983", "post_type": "answer", "score": 2 } ]
67983
68002
68002
{ "accepted_answer_id": "68008", "answer_count": 1, "body": "Three.jsで、3Dキャラクターをインタラクティブに動作させてみたいのですが、 \nThree.jsで動作させることが可能な3Dキャラクターは、どうやって作成するのですか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T08:38:12.853", "favorite_count": 0, "id": "67984", "last_activity_date": "2020-06-26T02:24:59.513", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 1, "tags": [ "three.js" ], "title": "Three.jsで動作させることが可能な3Dキャラクターは、どうやって作成するのですか?", "view_count": 416 }
[ { "body": "3Dキャラクターは3DCG作成ソフトウェアを使って作成します。\n\nあくまで一例ですが、個人用途では例えば[Blender](https://ja.wikipedia.org/wiki/Blender)というオープンソースソフトウェアを利用します。 \nBlenderでは3Dモデルを変形や結合していわゆる『3Dキャラクター』を作成し、それをキーフレームという手法で時間単位のアニメーションを定義して動かすことができます。 \nBlenderを使って作成したモデルとアニメーションは[glTF\n2.0](https://ja.wikipedia.org/wiki/GlTF)というフォーマット(拡張子は`*.glb`など)で出力可能です。 \n※Wikipediaには「glTF (GL Transmission Format)\nはJSONによって3Dモデルやシーンを表現するフォーマットである。」と書かれていますが、Blenderから出力したファイルを開くと中身はバイナリです。 \n[Blenderから出力し、モデルを単純に読み込む例](https://www.pentacreation.com/blog/2019/09/190916.html)\n\nこのglTFフォーマットのファイルをThree.jsから読み取ってJavaScriptからアニメーション操作を呼び出すことでWeb上で動作させることができます。 \n[コード例](https://www.pentacreation.com/blog/2019/10/191016.html)\n\nインタラクティブに動作させる仕組みは別のご質問[glbファイルについて](https://ja.stackoverflow.com/q/67985)もご参照ください。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T02:24:59.513", "id": "68008", "last_activity_date": "2020-06-26T02:24:59.513", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "67984", "post_type": "answer", "score": 2 } ]
67984
68008
68008
{ "accepted_answer_id": "68009", "answer_count": 1, "body": "Three.jsで「glbファイル」を読み込んで3Dキャラクターを動作させているコードがあるのですが、「glbファイル」とはどういうファイルですか?\nどうやって作成するのですか?\n\nテキストエディタで「glbファイル」ソースコードを確認しようとしたのですが、ファイルサイズが大きくて無理でした。\n\nそこで、Windowsの3Dビューアー(今回初めて使いました)で「glbファイル」を開いたら、3Dが表示され、プルダウンで複数アニメーション切り替えが出来ました。 \nこれは、1つの「glbファイル」に、3Dデータと複数アニメーションの動作が格納されている、ということですか?", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T08:49:19.210", "favorite_count": 0, "id": "67985", "last_activity_date": "2020-06-27T00:15:47.367", "last_edit_date": "2020-06-25T08:58:01.107", "last_editor_user_id": "7886", "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "three.js" ], "title": "glbファイルについて", "view_count": 1187 }
[ { "body": "[Three.jsで動作させることが可能な3Dキャラクターは、どうやって作成するのですか?](https://ja.stackoverflow.com/q/67984)\nの[回答](https://ja.stackoverflow.com/a/68008/9820)に記述した通り、glbファイルは[glTF](https://ja.wikipedia.org/wiki/GlTF)というフォーマットで3Dモデルやシーン(そしてアニメーション)を記述するファイルです。\n\n3Dモデルは大量にポリゴンの座標などの情報を含んでいるため、これを記述するには非常に大きなデータが必要です。 \nこのためglbファイルの中身は通常で数MBを超えるバイナリベースの形式になっており、テキストエディタで人間が視認することは想定されておりません。 \n※glTFのWikipediaには「glTF (GL Transmission Format)\nはJSONによって3Dモデルやシーンを表現するフォーマット」と書かれていますが、JSONの中にバイナリデータが詰め込まれています。\n\nちなみに3DモデルのエディタであるBlenderのソースコード(*.blendファイル)もバイナリベースなのでエディタで書き換えることが前提となっています。テキストエディタで書き換えることは実質不可能です。\n\nglTFには複数のアニメーションを格納することができ、[animationsという配列](https://qiita.com/syoyo/items/236f2a4713aa381c6735#animations)を選択して切り替えることができます。 \n切り替えのためにThree.jsでは[AnimationMixer#clipAction](https://threejs.org/docs/#api/en/animation/AnimationMixer.clipAction)というメソッドが用意されています。 \nおそらくご質問の3Dビューアーも同様の仕組みでプルダウンの項目を読み取って表示しているはずです。\n\n参考資料: [Three.jsを用いたモデルのアニメーション切り替え](https://qiita.com/sawa-\nzen/items/05ff33a3531f469b29ef)", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T02:27:08.733", "id": "68009", "last_activity_date": "2020-06-27T00:15:47.367", "last_edit_date": "2020-06-27T00:15:47.367", "last_editor_user_id": "9820", "owner_user_id": "9820", "parent_id": "67985", "post_type": "answer", "score": 2 } ]
67985
68009
68009
{ "accepted_answer_id": null, "answer_count": 1, "body": "sample.txt \nの中身が\n\n```\n\n apple=150\n orange=300\n grape=200\n \n```\n\nのときに\n\n 1. sample.txtを読み込んで(全読み込み)\n 2. \"\\n\"で1行ずつsplit\n 3. \"=\"でsplitしてパラメータ名が正しければcorrectを表示\n\nしたいのですが、下記コードだと、grapeがある場合でもgrapeがない場合でも `else if(key != \"grape\")`\nに引っかかってしまいます。\n\ngrapeがある場合、 `else if(key != \"grape\")` に引っかからないようにするにはどのように修正すべきなのでしょうか。\n\ngrapeがない場合やgrapeの綴りが間違っている(例glape)時だけ `else if(key != \"grape\")`の処理に入りたいです。\n\n```\n\n #include \"MainWindow.h\" \n #include <QApplication>\n #include <QDebug>\n #include <QFile>\n #include <QTextCodec>\n \n int main(int argc, char *argv[])\n {\n //QApplication a(argc, argv);\n //MainWindow w;\n //w.show();\n QFile file(\"C:\\\\Users\\\\Desktop\\\\sample.txt\");\n if (!file.open(QIODevice::ReadOnly))\n {\n qDebug() << \"can not open file.\" ;\n return 0;\n }\n QString str;\n QTextStream in(&file);\n str = in.readAll();\n qDebug() << str ;\n QStringList list1 = str.split(\"\\n\");\n for (int i=0; i < list1.count(); i++) {\n QString txt = list1[i];\n QStringList list2 = txt.split(\"=\");\n QString key = list2[0];\n QString value = list2[1];\n if(key == \"apple\"){\n qDebug() << \"correct\";\n }\n if(key == \"grape\"){\n qDebug() << \"correct\";\n }\n else if (key != \"grape\"){\n qDebug() << \"incorrect\";\n //break;\n }\n if(key == \"orange\"){\n qDebug() << \"correct\";\n }\n }\n \n file.close();\n //return a.exec();\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T10:24:45.743", "favorite_count": 0, "id": "67986", "last_activity_date": "2020-06-26T01:30:12.243", "last_edit_date": "2020-06-26T01:30:12.243", "last_editor_user_id": "3060", "owner_user_id": "40822", "post_type": "question", "score": 0, "tags": [ "c++", "qt", "qt-creator" ], "title": "Qtのsplitについてです", "view_count": 173 }
[ { "body": "これはタイトルのような「Qtのsplitについて」ではなく、一般的なC++のプログラミング上の問題ですね。\n\n`for`ループ内の3つの`if`文は`break`や`continue`でスキップしたり、`else\nif`,`else`でまとめたりしていないため、その回の処理対象に対して全て適用されます。\n\n例えば`apple`や`orange`に対しても、`apple`か, `grape`か`grape`で無いか, `orange`か\nのチェックがすべて行われます。 \nそのため、「`grape`で無い」ことになり`qDebug() << \"incorrect\";`が実行されます。\n\n**何をどうチェック・処理したいのか? を厳密に整理しましょう**\n\n例えば「`grape`で無い」という条件は、別に`glape`,`grepe`,`grapu`等に限らず`apple`や`orange`でも(あるいは`lemon`でも)成立します。 \nそういう意味で、「`grape`で無いか?」という条件による判定は適切とは言えないでしょう。\n\nどんなデータがあった時にどのように処理を行うか(処理対象あるいは対象外のデータとは何か、対象外データがあった時にどう判定してどう処理するか)といったことを細かく厳密に整理して、それに沿ったプログラミングを行ってください。\n\n**変更の少ないやり方としては?** \n以下のようにすれば良いでしょう。 \n(上記整理で条件が増減したり変わったりしたら、それに合わせて変更します)\n\n * `apple`, `grape` , `orange`, **`それ以外`** の4つの場合に分ける(`grape`では無いという判定はやめる)\n * それぞれの判定を`if`,`else if`,`else`で接続して、どれかが成立したら他の判定は行われないようにする\n * `grape`が有ったかどうかのフラグ変数を用意して、`for`ループの前にfalseで初期化、`for`ループ内で見つかればtrue設定、`for`ループ終了後にフラグ変数で`grape`有無のチェックを行う", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T15:40:56.993", "id": "68000", "last_activity_date": "2020-06-25T15:49:17.580", "last_edit_date": "2020-06-25T15:49:17.580", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "67986", "post_type": "answer", "score": 1 } ]
67986
null
68000
{ "accepted_answer_id": "68053", "answer_count": 2, "body": "PostersSQLを勉強しています。MySQLでは下記のようにすると外部キー制約等リレーションがうまくいくのですが、PostersSQLの場合、少し構文が変わると思い変えてみてはいますがうまくいきません。\n\nMySQL\n\n```\n\n CREATE TABLE `users` (\n `username` varchar(80) NOT NULL,\n `password` varchar(80) NOT NULL,\n `enabled` tinyint(1) NOT NULL\n );\n \n CREATE TABLE `authorities` (\n `username` varchar(80) NOT NULL,\n `authority` varchar(80) NOT NULL\n );\n \n ALTER TABLE `users`\n ADD PRIMARY KEY (`username`);\n \n ALTER TABLE `authorities`\n ADD UNIQUE KEY `username` (`username`,`authority`);\n \n ALTER TABLE `authorities`\n ADD CONSTRAINT `authorities_ibfk_1` FOREIGN KEY (`username`) REFERENCES `users` (`username`);\n \n```\n\nPostgreSQL\n\n```\n\n \n CREATE TABLE users ( \n  username varchar(80) NOT NULL, \n  password varchar(80) NOT NULL,\n        ↓tinyintはないのでsmallintに変更 \n  enabled smallint(1) NOT NULL);\n \n CREATE TABLE authorities ( \n  username varchar(80) NOT NULL, \n  authority varchar(80) NOT NULL);\n \n \n ALTER TABLE users \n  ADD PRIMARY KEY (username);\n \n ALTER TABLE authorities \n     ↓UNIQUE KEY(PostgreSQLの場合はUNIQUE?\n  ADD UNIQUE username (username,authority);\n \n ALTER TABLE authorities \n  ADD CONSTRAINT authorities_ibfk_1 FOREIGN KEY (username) REFERENCES users (username);\n \n```\n\n上記のやり方によるエラー\n\n```\n\n ERROR: \"(\"またはその近辺で構文エラー\n 行 1: ... password varchar(80) NOT NULL, enabled smallint(1) NOT NU...\n ^\n ERROR: リレーション\"authorities\"はすでに存在します\n ERROR: リレーション\"users\"は存在しません\n ERROR: \"username\"またはその近辺で構文エラー\n 行 1: ALTER TABLE authorities ADD UNIQUE username (username,autho...\n ^\n ERROR: リレーション\"users\"は存在しません\n \n```\n\n・smallint(1)でエラーになっているので、smallintのみにする。 \n・ALTER TABLE authorities ADD UNIQUE username (username,autho...部分の修正方法がわかりません。 \n・その他修正が必要か?\n\nご教授いただけたら幸いです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T10:40:14.297", "favorite_count": 0, "id": "67987", "last_activity_date": "2020-06-28T10:28:32.063", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40666", "post_type": "question", "score": 0, "tags": [ "mysql", "postgresql" ], "title": "MySQL から PostgreSQLへの変換", "view_count": 714 }
[ { "body": "> smallint(1)でエラーになっているので、smallintのみにする。\n\nはい。 \nもしくは桁数をユーザ指定精度にするならば`numeric`型をご検討ください。 \n[数値データ型](https://www.postgresql.jp/document/8.2/html/datatype-numeric.html)\n\nちなみに`enabled numeric(1, 0) NOT NULL`のように1桁精度を指定した場合、小数点以下は丸められます。\n\n```\n\n insert into users values('piyo', 'foo', 0.1); -- enabledが0に丸められる\n insert into users values('bar', 'buz', 10); -- エラー\n \n```\n\n> ALTER TABLE authorities ADD UNIQUE username\n\n[CREATE INDEX](https://www.postgresql.jp/document/9.3/html/sql-\ncreateindex.html)に書き換え可能です。\n\n```\n\n CREATE UNIQUE INDEX username ON authorities (username,authority);\n \n```\n\n[ALTER TABLE](https://www.postgresql.jp/document/9.4/html/sql-\naltertable.html)でユニークキーを追加したことがないので自信はないのですが、リンク先の ADD\n`table_constraint_using_index` の通り既存のインデックスを使用する構文ではないでしょうか。(下記の太字は筆者)\n\n> この構文は、 **既存の一意性インデックス** に基づき、テーブルにPRIMARY KEYまたはUNIQUE制約を新たに追加します。\n\n> その他修正が必要か?\n\nSQL文に全角スペースが含まれているので半角スペースに変更した方が良いのではないでしょうか。\n\n[SQL Fiddle](http://sqlfiddle.com/#!17/27d7a/1)でビルド可能なSQL:\n\n```\n\n CREATE TABLE users (\n username varchar(80) NOT NULL,\n password varchar(80) NOT NULL,\n -- enabled smallint NOT NULL\n enabled numeric(1, 0) NOT NULL);\n \n CREATE TABLE authorities (\n username varchar(80) NOT NULL,\n authority varchar(80) NOT NULL);\n \n ALTER TABLE users \n ADD PRIMARY KEY (username);\n \n CREATE UNIQUE INDEX username\n ON authorities (username,authority);\n \n ALTER TABLE authorities \n ADD CONSTRAINT authorities_ibfk_1 FOREIGN KEY (username) REFERENCES users (username);\n \n insert into users values('hoge', 'fuga', 9); -- 正常\n insert into users values('piyo', 'foo', 0.1); -- enabledが0に丸められる\n -- insert into users values('bar', 'buz', 10); -- エラー\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T06:50:27.363", "id": "68053", "last_activity_date": "2020-06-27T06:50:27.363", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "67987", "post_type": "answer", "score": 1 }, { "body": "PostgreSQL には boolean 型がありますが、MySQL には無いので 代わりに tinyint(1) が使われることがよくあります。\n\nこの enabled が true, false を保持するためのカラムなのであれば、boolean を使うのがいいと思います。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T10:28:32.063", "id": "68080", "last_activity_date": "2020-06-28T10:28:32.063", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3249", "parent_id": "67987", "post_type": "answer", "score": 1 } ]
67987
68053
68053
{ "accepted_answer_id": null, "answer_count": 1, "body": "Laravelとvueを使ってTODOアプリを作っているのですが、アイコンをクリックした時にDBのdoneというカラムの真偽値を反転させたいのですがどのように実装すればいいのかさっぱりです。(axiosを使って非同期でDBの値をクリックするたびに反転させたい)、またはDBにdoneカラムに真偽値を持たせないでも、doneの真偽値だけvue側で持たせてクリックでイベント発火させる方法でもいいです。 \n画像の5行目がクリックイベントを仕込んであります。クリックイベントのメソッドはまだ書いてません。 \n1枚目のTODOのタスクのように左側のサークルをクリックしたらチェックのついたサークルになりその要素の色が変わる、またクリックしたら元に戻るという風にしたいです。画像のものはvueのみで作ったTODOですがこれをLaravelを含めてやるとタスクのタイトルやIDはDBに登録してVueで表示してるのですが、完了のステータスをVue側で管理するのかDBで管理するのか、そしてそれの実装の仕方がわかりませんので、どなたかご教授いただきたいです。 \n[![タスク表示のVueコンポーネント](https://i.stack.imgur.com/hKxfW.png)](https://i.stack.imgur.com/hKxfW.png) \n[![vueで作ったTODO](https://i.stack.imgur.com/Zxuvn.png)](https://i.stack.imgur.com/Zxuvn.png)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T13:00:04.017", "favorite_count": 0, "id": "67991", "last_activity_date": "2021-04-04T00:52:07.377", "last_edit_date": "2021-04-04T00:52:07.377", "last_editor_user_id": "32986", "owner_user_id": "40824", "post_type": "question", "score": 0, "tags": [ "vue.js", "laravel-5", "非同期", "axios" ], "title": "axiosを使って非同期でDBの値をクリックするたびに反転させたい", "view_count": 212 }
[ { "body": "最初に言いたいのは、SSではなく、コードを書いた方がいいと思います。そして、SSにはtemplateの中身しかみられません。例えば`toggleDone()`\nmethodの中で何が起こっているか確認したいのですが、これでもやりたいことを想像して、サンプルとして、何か書きましょうか。\n\nチェックバックス使いたくないようですので、v-modelなしの方法を考えましょう。\n\n**template**\n\n```\n\n @click=\"toggleDone(todo.id, todo.done)\">\n \n```\n\nクリックする時にparamとしてIDも送りましょう。\n\n**script**\n\n```\n\n methods: {\n toggleDone(id, done){\n let new_done = done == true ? false : true\n let payload = {\n \"id\": id,\n \"done\": new_done,\n }\n axios.post(\"your/endpoint\", payload).then(response => {\n console.log(response.data)\n })\n }\n },\n \n```\n\nPS: axiosをインポートするの忘れないでください。\n\n上記はフロントエンドです。今からバックエンドについてです。\n\n**routes/api**\n\n```\n\n Route::post(\"your/endpoint\", \"TodoController@update\");\n \n```\n\n**controller**\n\n```\n\n public function update(Request $request)\n {\n \n // done は DBテーブルにある列の名\n $payload = [\n \"done\" => $request->get(\"done\"),\n ];\n \n // TodoはDBテーブルの名\n Todo::where(\"id\", $request->get(\"id\"))->update($payload);\n \n $todos = Todo::all() \n \n return response()->json($todos)\n \n }\n \n```\n\nここで気を付けないといけないところはModelです。もしモデルはに $fillable の箇所を決めてないなら、updateができません。\n\n**Todo Model**\n\n```\n\n namespace App;\n \n use Illuminate\\Database\\Eloquent\\Model;\n \n class Todo extends Model\n {\n protected $guarded = [];\n protected $table = \"todo\";\n \n }\n \n```\n\n修正したい箇所を $fillable として一つ一つ決めるより 私は $guardedを使いました。この方が早いです。\n\n`update`, `create` などの eloquent ORM\nmethodsを調べる為に[ララベルのDOCS](https://laravel.com/docs/7.x/eloquent#inserting-and-\nupdating-models)を確認してください。\n\n私は外国人だし、もし日本語が間違えていたらすみません。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T14:23:11.423", "id": "67993", "last_activity_date": "2020-06-25T14:28:44.050", "last_edit_date": "2020-06-25T14:28:44.050", "last_editor_user_id": "30379", "owner_user_id": "30379", "parent_id": "67991", "post_type": "answer", "score": 2 } ]
67991
null
67993
{ "accepted_answer_id": null, "answer_count": 1, "body": "以下の DataFrame があります。\n\n```\n\n     install_t\n 0 NaT\n 1 2020-03-28 19:31:22.159174+09:00\n 2 NaT\n 3 2019-12-31 10:38:38.165566+09:00\n 4 2020-06-14 15:29:41.511317+09:00\n Name: install_t, dtype: datetime64[ns, pytz.FixedOffset(540)]\n \n```\n\n上記の install_t 列を `2019-12-31` という日付のみにしたいので、以下のコードを書いたのですが、エラーも出ず、結果に変化もありません。 \nなぜでしょうか。宜しくお願いします。\n\n```\n\n df['install_t'] = pd.to_datetime(df['install_t']) \n df['install_t'] = df['install_t'].dt.round(\"D\")\n df['install_t']\n \n```\n\nまたタイムゾーンを削除できないかと以下も試みましたが、エラーがでました。 \n助けてください。\n\n```\n\n df6['install_t'] = df6['install_t'].replace(tzinfo=None)\n \n```\n\n```\n\n ---------------------------------------------------------------------------\n TypeError Traceback (most recent call last)\n <ipython-input-29-e26e2db5d810> in <module>\n ----> 1 df6['install_t'] = df6['install_t'].replace(tzinfo=None)\n \n TypeError: replace() got an unexpected keyword argument 'tzinfo'\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T13:51:08.137", "favorite_count": 0, "id": "67992", "last_activity_date": "2021-07-09T12:02:20.303", "last_edit_date": "2020-06-26T01:02:04.010", "last_editor_user_id": "3060", "owner_user_id": "38096", "post_type": "question", "score": 0, "tags": [ "python", "python3", "pandas" ], "title": "DataFrame からタイムゾーンを削除したいがうまくいかない", "view_count": 2661 }
[ { "body": "この記事が適用できると思われます。 \n[How to remove timezone from a Timestamp column in a pandas\ndataframe](https://stackoverflow.com/q/49198068/9014308)\n\n> You can use `tz_localize` to change the time zone, a naive timestamp\n> corresponds to time zone `None`: \n> `tz_localize`を使用してタイムゾーンを変更できます。単純なタイムスタンプはタイムゾーン`None`に対応します:\n\n>\n```\n\n> testdata['time'].dt.tz_localize(None)\n> \n```\n\n> Unless the column is an index you have to call method `dt` to access pandas\n> datetime functions. \n> 列がインデックスでない限り、pandasの日時関数にアクセスするには、メソッド `dt`を呼び出す必要があります。\n\n* * *\n\n質問内容に適用すれば、以下になるでしょう。\n\n```\n\n df['install_t'] = df['install_t'].dt.tz_localize(None)\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T14:44:24.420", "id": "67995", "last_activity_date": "2020-06-25T14:44:24.420", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "67992", "post_type": "answer", "score": 1 } ]
67992
null
67995
{ "accepted_answer_id": "68031", "answer_count": 2, "body": "下記リンク先で、マウスを使ってcanvasに線を引いた後、変換ボタンを押すと、その線に沿う形で、予め指定した小さな形状の集まりに単純化されるのですが、こういった(単純化する)動きをする実装を何と呼びますか?\n(このようなことが出来る)ライブラリを探しているのですが、何のキーワードで検索したら良いか分からないので質問しました。 \n<https://www.logoshi.com/draw-a-logo>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T14:53:12.813", "favorite_count": 0, "id": "67996", "last_activity_date": "2020-06-26T11:12:20.817", "last_edit_date": "2020-06-26T08:14:19.073", "last_editor_user_id": "3475", "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "画像処理" ], "title": "canvasに描画した内容を、予め指定した小さな形状の集まりに単純化することを何と呼ぶ?", "view_count": 83 }
[ { "body": "単純化するステップは「量子化 (quantization)」でしょうか。\n\n指定した形状の集まりにするステップに名前があるかどうかは存じません。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T08:21:30.630", "id": "68026", "last_activity_date": "2020-06-26T08:21:30.630", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3475", "parent_id": "67996", "post_type": "answer", "score": 1 }, { "body": "ご質問の「小さな形状の集まりに単純化」とか、参照先ツールの機能とは少し違いますが、Illustratorのブレンドツールやブラシツールのパスに沿って配置(Align\nto Path)が近いと思われます。\n\n[パス(線)上にオブジェクト(図形)を等間隔に並べる方法【Illustrator】](https://www.yslife-b.com/archives/1696)\n\n> 1. ブレンドを使う\n>\n\n> * オープンパス(パスが開いた線)の場合\n> * クローズパス(パスが閉じた線)の場合\n>\n\n> 2. ブラシを使う\n>\n\n> * ブラシを使った簡単な方法\n> * もっと均等にしたい場合\n>\n\nこの動画が近い感じですね。 \n[How to Repeat a Shape Along Any Path in Adobe\nIllustrator](https://www.youtube.com/watch?v=d-0aSsuFGCY)\n\n英語サイトの関連しそうな記事 \n[Distribute objects along a path in\nIllustrator](https://graphicdesign.stackexchange.com/q/5044)\n\nIllustratorの解説ページ \n[ブレンドオブジェクトについて](https://helpx.adobe.com/jp/illustrator/using/blending-\nobjects.html) \n[ブラシについて](https://helpx.adobe.com/jp/illustrator/using/brushes.html)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T11:12:20.817", "id": "68031", "last_activity_date": "2020-06-26T11:12:20.817", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "67996", "post_type": "answer", "score": 1 } ]
67996
68031
68026
{ "accepted_answer_id": "68001", "answer_count": 2, "body": "C#を使ってwindowsアプリを制作しています。 \n以下のコードは別のコントローラーのループメソッドを呼び出し、そこで並列に動かしているのですが、これを停止させようとする際に、停止したことを証明するようなものを受け取りたいと思っています。\n\n```\n\n private void StartCheck()\n {\n this.TokenSource = new CancellationTokenSource();\n var token = TokenSource.Token;\n token.Register(() => AsyncCallback());\n Task.Run(() => CheckController.Execute(token, this));\n }\n \n```\n\nいまはこのようなメソッドで止めているのですが、これだと止まったかどうかが判定できず、その後の動作によってはエラーが発生してしまいます。 \n`StartCheck()` を呼ぶ際にコールバック関数を設定したり、`StopCheck()`\nを実行した後にコントローラーから返答があればいいのですが、何かいい案があれば教えていただきたいです。\n\n```\n\n private void StopCheck()\n {\n this.TokenSource.Cancel();\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T14:54:59.703", "favorite_count": 0, "id": "67997", "last_activity_date": "2020-06-27T02:54:13.797", "last_edit_date": "2020-06-26T01:05:18.910", "last_editor_user_id": "3060", "owner_user_id": "37744", "post_type": "question", "score": 0, "tags": [ "c#", "windows", ".net" ], "title": "c#のwindowsアプリでスレッドの停止信号を受け取りたい", "view_count": 1461 }
[ { "body": "「別のコントローラー(のループメソッド)」を変更して良いのなら、コールバック関数を指定するパラメータを増やして、ループメソッドの最終処理でコールバック関数を呼び出すようにすれば、終了タイミングを知ることが出来ると思われます。\n\n以下の記事の後半「メモ」の部分ですね。抜粋しておきます。 \n[C#のawait/async非同期処理およびラムダ式](https://www.usagi1975.com/071920182101/)\n\n> 以下の場合、connectAsyncを実行すると内部で非同期処理が実行されて、その処理が終了するとcallbackが実行される。 \n>\n> callbackは同期関数なので、内部で非同期処理をawaitできない。非同期処理をそのまま非同期でコールするか、Wait()で待つしかない。もしawaitを使いたいなら、callbackの型をFunc<int,\n> Task>にする。(そうしないといけないケースがあるのか?)\n```\n\n> private void Button_Click(object sender, RoutedEventArgs e) {\n> Debug.WriteLine( \"--- start ---\" );\n> Task t = connectAsync( \"abc\", (int stat) => {\n> Debug.WriteLine( \"start lambda\" );\n> Debug.WriteLine( \"stat={0}\", stat );\n> Task.Delay(1000).Wait(); // 終了までこのまま処理を待つ\n> //Task.Delay(1000); // 非同期で実行されるので、即材に終了する\n> Debug.WriteLine( \"end lambda\" );\n> return 2;\n> } );\n> Debug.WriteLine( \"--- end ---\" );\n> }\n> \n> private async Task connectAsync(string url, Func<int, int> callback) {\n> Debug.WriteLine( \"start connectAsync\" );\n> int stat = 1;\n> await Task.Delay( 2000 );\n> int ret = callback(stat);\n> Debug.WriteLine( \"ret={0}\", ret );\n> Debug.WriteLine( \"end connectAsy\n> \n```\n\n古い形式らしい同様の内容はこちら。 \n[コールバック:\n非同期処理の終了通知](https://ufcpp.net/study/csharp/misc_delegate.html#callback)\n\n* * *\n\n「別のコントローラー(のループメソッド)」が変更出来ないのなら以下になるでしょうか。\n\n**基本的には`Task.Run(() => CheckController.Execute(token,\nthis));`で作成・起動された`Task`のインスタンスが作りっぱなしであってアプリケーションクラスの中に保持されていないことが問題でしょう。**\n\nアプリケーションのどこかに`Task t;`と定義しておいて、`t = Task.Run(() =>\nCheckController...`として作成・起動時に代入しておけば、`t.Status`とか`t.IsCompleted`とかで状態を知ることが出来ます。(eventを受け取るのは無理のようですが) \nただし、CancelされてもCanceledではなくRanToCompletionの場合が多いようですね。\n\n[Task.Status プロパティ](https://docs.microsoft.com/ja-\njp/dotnet/api/system.threading.tasks.task.status?view=netcore-3.1) \n[TaskStatus 列挙型](https://docs.microsoft.com/ja-\njp/dotnet/api/system.threading.tasks.taskstatus?view=netcore-3.1)\n\n>\n```\n\n> Canceled 6 タスクの CancellationToken\n> がシグナル状態であるときに、タスクがこのトークンを使用して OperationCanceledException\n> をスローすることによって取り消しを受領したか、タスクの実行開始前にタスクの CancellationToken が既にシグナル状態でした。\n> 詳細については、「タスクのキャンセル」をご覧ください。\n> Created 0 タスクは初期化されていますが、まだスケジュールされていません。\n> Faulted 7 タスクはハンドルされない例外が発生したために終了しました。\n> RanToCompletion 5 タスクの実行は正常に完了しました。\n> Running 3 タスクは実行中で、まだ完了していません。\n> WaitingForActivation 1 タスクはアクティブ化されるのを待機中で、.NET Framework\n> インフラストラクチャによって内部的にスケジュールされています。\n> WaitingForChildrenToComplete 4\n> タスクは実行を終了し、アタッチされている子タスクの完了を暗黙的に待機しています。\n> WaitingToRun 2 タスクの実行はスケジュールされていますが、まだ開始されていません。\n> \n```\n\n[Task.IsCompleted プロパティ](https://docs.microsoft.com/ja-\njp/dotnet/api/system.threading.tasks.task.iscompleted?view=netcore-3.1)\n\n> タスクが完了した (つまり、RanToCompletion、Faulted、Canceled)\n> のいずれかの最終状態であることを`true`します。それ以外の場合は、`false`ます。\n\nなお、[Task.Wait メソッド](https://docs.microsoft.com/ja-\njp/dotnet/api/system.threading.tasks.task.wait?view=netcore-3.1) や\n[Task.ContinueWith メソッド](https://docs.microsoft.com/ja-\njp/dotnet/api/system.threading.tasks.task.continuewith?view=netcore-3.1)\nあたりが使えそうな記事も見かけましたが、単純なCancel後のWaitは上手くいきませんでした。使い方に工夫が必要なのかもしれません。\n\n* * *\n\n上記も含めてこの辺の記事とその関連ページがそれらの話題を扱っていて参考になると思われます。 \n色々な方法があるようなので、現在行っていることおよびやりたいことと整合性のある方法を選択して試してみてください。\n\n[タスク ベースの非同期プログラミング](https://docs.microsoft.com/ja-\njp/dotnet/standard/parallel-programming/task-based-asynchronous-programming)\n\n* * *\n\n[タスクのキャンセル](https://docs.microsoft.com/ja-jp/dotnet/standard/parallel-\nprogramming/task-cancellation)\n\n> キャンセル処理が正常に実行されるためには、要求コードが CancellationTokenSource.Cancel メソッドを呼び出し、ユーザー\n> デリゲートが操作を適時に終了する必要があります。 次のオプションのいずれかを使用して操作を終了できます。\n>\n> * デリゲートから戻ります。 多くの場合、この処理で十分ですが、この方法で取り消されたタスク インスタンスは、\n> TaskStatus.RanToCompletion 状態ではなく、 TaskStatus.Canceled 状態に遷移します。\n> * OperationCanceledException をスローし、これをキャンセルが要求されたトークンに渡します。 これを行うには、\n> ThrowIfCancellationRequested メソッドを使用する方法をお勧めします。 この方法で取り消されたタスクは Canceled\n> 状態に遷移し、タスクがキャンセル要求に応答したことを確認するために呼び出し元のコードによって使用されます。\n>\n\n* * *\n\n[方法: タスクとその子を取り消す](https://docs.microsoft.com/ja-jp/dotnet/standard/parallel-\nprogramming/how-to-cancel-a-task-and-its-children)\n\n> 以下の例では、次のタスクを実行する方法を説明します。\n>\n> 1. 取り消すことができるタスクを作成し、開始します。\n> 2. キャンセル トークンをユーザー デリゲートに渡し、必要に応じてタスク インスタンスにも渡します。\n> 3. ユーザー デリゲート内のキャンセル要求を確認し、これに応答します。\n> 4. 必要に応じて、タスクが取り消された呼び出し元のスレッドを確認します。\n>\n\n>\n> 呼び出し元のスレッドは、タスクを強制終了せず、キャンセルが要求されたことを通知するだけです。 タスクが既に実行中である場合、ユーザー\n> デリゲートが要求を確認して適切に応答します。 タスクを実行する前にキャンセルが要求された場合、ユーザー デリゲートは実行されず、タスク オブジェクトは\n> Canceled 状態に遷移します。\n\n* * *\n\n[マネージド スレッドのキャンセル](https://docs.microsoft.com/ja-\njp/dotnet/standard/threading/cancellation-in-managed-threads#operation-\ncancellation-versus-object-cancellation)\n\n> 連携によるキャンセル処理モデルを実装するための一般的なパターンは次のとおりです。\n>\n> * CancellationTokenSource オブジェクトのインスタンスを作成します。このオブジェクトでは、個々のキャンセル\n> トークンへのキャンセル通知を管理し、送信します。\n> * CancellationTokenSource.Token\n> プロパティによって返されるトークンを、キャンセルをリッスンしているそれぞれのタスクまたはスレッドに渡します。\n> * それぞれのタスクまたはスレッドに対し、キャンセルに応答するメカニズムを提供します。\n> * キャンセルの通知を提供する CancellationTokenSource.Cancel メソッドを呼び出します。\n>\n\n[操作のキャンセルとオブジェクトのキャンセル](https://docs.microsoft.com/ja-\njp/dotnet/standard/threading/cancellation-in-managed-threads#operation-\ncancellation-versus-object-cancellation)\n\n[キャンセル要求のリッスンと応答](https://docs.microsoft.com/ja-\njp/dotnet/standard/threading/cancellation-in-managed-threads#listening-and-\nresponding-to-cancellation-requests)\n\n[ポーリングによるリッスン](https://docs.microsoft.com/ja-\njp/dotnet/standard/threading/cancellation-in-managed-threads#listening-by-\npolling)\n\n> ループや再帰を伴う長時間にわたる計算では、CancellationToken.IsCancellationRequested\n> プロパティの値を定期的にポーリングすることによってキャンセル要求をリッスンできます。\n\n[コールバックの登録によるリッスン](https://docs.microsoft.com/ja-\njp/dotnet/standard/threading/cancellation-in-managed-threads#listening-by-\nregistering-a-callback)\n\n> 操作によっては、キャンセル トークンの値を定期的に確認できないことによりブロックされる場合があります。\n> そのような場合は、キャンセル要求を受け取ったときにメソッドのブロックを解除するコールバック メソッドを登録できます。\n\n[待機ハンドルを使用したリッスン](https://docs.microsoft.com/ja-\njp/dotnet/standard/threading/cancellation-in-managed-threads#listening-by-\nusing-a-wait-handle)\n\n> System.Threading.ManualResetEvent や System.Threading.Semaphore\n> などの同期プリミティブを待機している間、キャンセル可能な操作をブロックできる場合は、CancellationToken.WaitHandle\n> プロパティを使用してその操作がイベントとキャンセル要求の両方を待機するようにできます。\n\n* * *\n\n[方法: キャンセル要求のコールバックを登録する](https://docs.microsoft.com/ja-\njp/dotnet/standard/threading/how-to-register-callbacks-for-cancellation-\nrequests)\n\n> 次の例では、トークンを作成したオブジェクトに対する Cancel の呼び出しにより IsCancellationRequested プロパティが\n> true になったときに呼び出されるデリゲートを登録する方法を示します。\n\n> 次の例では、CancelAsync メソッドを、キャンセル トークンを通じてキャンセルが要求されたときに呼び出されるメソッドとして登録します。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-25T16:30:46.603", "id": "68001", "last_activity_date": "2020-06-27T02:54:13.797", "last_edit_date": "2020-06-27T02:54:13.797", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "67997", "post_type": "answer", "score": -1 }, { "body": "> 止まったかどうかが判定できず、その後の動作によってはエラーが発生してしまいます。 \n> 何かいい案があれば教えていただきたいです。\n\n`CheckController` に 終了状態を保持する `ManualResetEventSlim` 等の同期オブジェクトを持たせ\n\n`IsCancellationRequested` の 要求結果 処理が済んだ後で 同期オブジェクトの値を変更する \nというのはどうでしょう。\n\nCheckController 側のコードの例\n\n```\n\n private static ManualResetEventSlim stopEvent = new ManualResetEventSlim(false);\n \n // 別スレッドのループ処理\n private void ExecuteLoop(CancellationToken token) {\n // 処理開始\n stopEvent.Reset();\n \n for (;;)\n {\n Thread.Sleep(1000); // ダミーの処理\n \n if (token.IsCancellationRequested)\n {\n break;\n }\n }\n \n // 処理終了\n stopEvent.Set();\n }\n \n // 停止するまで待つ\n public static bool WaitStopped(int maxTimeout = 0)\n {\n if (stopEvent.Wait(maxTimeout))\n {\n return true;\n }\n else\n {\n return false;\n }\n }\n \n```\n\n呼び出し側の処理\n\n```\n\n StopCheck();\n \n if (! CheckController.WaitStopped(60*1000)) {\n // 60秒待ったけど終了しなかった場合の処理\n }\n \n \n```\n\nマルチスレッドで 並列実行して、相手の答えを待つ場合の \n普通の実装パターンだと思います。\n\n何を待つか、連続して実行する場合があるか、実行中に何度も呼び出される事があるか \n等のいろいろな条件によって実装が少しづつ異なりますが、基本は同じようなものだと思います。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T17:09:04.367", "id": "68040", "last_activity_date": "2020-06-26T17:09:04.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18851", "parent_id": "67997", "post_type": "answer", "score": 0 } ]
67997
68001
68040
{ "accepted_answer_id": null, "answer_count": 1, "body": "数理最適化に関するアルゴリズムに関して学習しています。\n\n0-1整数2次計画に関して分岐限定法で厳密解などを解くらしいのですが、 \n調べても連続変数の2次計画の問題に関する内容が多く、私の検索能力が低くて見つけられません。\n\n0-1整数2次計画問題に関して \n<https://www.letsopt.com/entry/2019/08/18/131125>\n\ngroubiOptimizerのような有料のものではなく、 \npythonで解くフリーのライブラリーなどありますか? \nまた、サンプルコードでもあればそれを理解して学習したいです。 \n(Atcoderとか得意な人はすぐに書けるものなのでしょうか?)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T01:17:26.247", "favorite_count": 0, "id": "68005", "last_activity_date": "2022-09-21T23:00:38.287", "last_edit_date": "2020-06-26T04:00:48.280", "last_editor_user_id": "19110", "owner_user_id": "37042", "post_type": "question", "score": 4, "tags": [ "python", "アルゴリズム" ], "title": "0-1整数2次計画問題に関する数理最適化のアルゴリズムについて", "view_count": 336 }
[ { "body": "## Fixstars.Amplifyソルバ\n\nFixstarsが提供しているAmplifyソルバを用いて問題を解くことができます。元々はイジングモデル求解ソルバですが、バイナリ(0-1整数)変数でのモデリングも可能です。制約もつけられます。\n\n<https://amplify.fixstars.com/ja/>\n\n利用規約の範囲で、無償ライセンスでも問題を解くことができます。 \nただ、アニーリングによるヒューリスティックな解法なので、厳密解を得られる保証はありません。\n\n## 変数積を解消して線形計画ソルバを実行する\n\n[http://web.tuat.ac.jp/~miya/fujie_ORSJ.pdf](http://web.tuat.ac.jp/%7Emiya/fujie_ORSJ.pdf)\nの3.4非線形関数\n2を見ると1つのバイナリ変数と3つの制約を問題に足すことによってバイナリ変数の積を解消する方法が記載してあります。このテクニックを用いて問題を線形化し、線形計画ソルバを実行することでオリジナルの問題の解を求めることができます。 \nこちらの方法であれば厳密解の取得が可能です。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2022-09-21T13:30:32.940", "id": "91217", "last_activity_date": "2022-09-21T23:00:38.287", "last_edit_date": "2022-09-21T23:00:38.287", "last_editor_user_id": "54208", "owner_user_id": "54208", "parent_id": "68005", "post_type": "answer", "score": 3 } ]
68005
null
91217
{ "accepted_answer_id": "68027", "answer_count": 3, "body": "以下のようなテーブルで、pkeyとIDが両方とも合致する条件として抽出したいです。 \nIDやNameは重複する可能性があります。 \n合致する条件はリストで任意に複数が与えられます。\n\n```\n\n CREATE TABLE \"Tbl_Dev\" (\n \"pkey\" INTEGER NOT NULL UNIQUE,\n \"ID\" TEXT NOT NULL DEFAULT 0,\n \"Name\" TEXT NOT NULL DEFAULT 'Unkown',\n PRIMARY KEY(\"pkey\" AUTOINCREMENT)\n );\n \n```\n\n仮のデータとして以下のようにしました。\n\n```\n\n pkey|ID|Name\n 1|0|Unkown1\n 2|0|Unkown2\n 3|0|Unkown3\n 4|0|Unkown4\n \n```\n\n試したSELECT文\n\n```\n\n SELECT pkey,ID \n FROM Tbl_Dev \n WHERE (pkey, ID)\n IN (('1','0'),('2','0'))\n \n```\n\nエラーメッセージ\n\n```\n\n Execution finished with errors\n Result: row value misused\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T01:42:59.887", "favorite_count": 0, "id": "68006", "last_activity_date": "2021-12-17T17:54:19.703", "last_edit_date": "2020-06-26T04:08:25.760", "last_editor_user_id": "3060", "owner_user_id": "32891", "post_type": "question", "score": 1, "tags": [ "sqlite" ], "title": "SQLite で複数のカラムを条件として抽出する方法", "view_count": 2369 }
[ { "body": "質問内容にあるSELECT文は、MySQLなどでは機能するそうですがSQLiteでは未サポートのようです。 \n参考URLに解決策がありました。 \nこのようにIN句に使用する一次リストを作成します。\n\n```\n\n ID_list = [0,0]\n Key_list = [1,2]\n W_list = [f'{k}_{id}' for k,id in zip(Key_list,ID_list)]\n \n```\n\nSELECT文は以下のようになります。\n\n```\n\n SELECT ID, name\n FROM Tbl_Dev AS t\n WHERE t.pkey || '_' || t.ID\n IN ('1_0','2_0')\n \n```\n\n参考 \n[SQL Search Query with multiple columns needs to\nedited](https://stackoverflow.com/questions/14387585/sql-search-query-with-\nmultiple-columns-needs-to-edited/14388639#14388639)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T02:36:24.010", "id": "68011", "last_activity_date": "2020-06-26T02:36:24.010", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32891", "parent_id": "68006", "post_type": "answer", "score": 0 }, { "body": "自己解決された方法ではインデックスが効かず、pkeyやIDがINTEGER型の場合は暗黙の型変換が発生します。 \nインデックスを有効にしたい場合は副問い合わせでダミー表を作成して結合する方法もあります。 \n正直なところ可読性は下がりますので、インデックスの有無やレコード数、要求速度に合わせて対応方法を選択するのが良いと思います。\n\n[SO本家の類似回答](https://stackoverflow.com/a/18365048)\n\n```\n\n -- 疑似テーブル作成\n with Tbl_Dev as (\n select 1 pkey, 0 ID, 'Unkown1' Name union all\n select 2 pkey, 0 ID, 'Unkown2' Name union all\n select 3 pkey, 0 ID, 'Unkown3' Name union all\n select 4 pkey, 0 ID, 'Unkown4' Name)\n -- サンプルSQL\n select t.*\n from Tbl_Dev as t\n -- (pkey, ID) in (('1','0'),('2','0')) の代用テーブル結合\n join (select 1 pkey, 0 ID union all\n select 2 pkey, 0 ID) as lookup\n on t.pkey = lookup.pkey\n and t.ID = lookup.ID\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T08:30:27.700", "id": "68027", "last_activity_date": "2020-06-26T08:30:27.700", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "68006", "post_type": "answer", "score": 1 }, { "body": "適切かどうかわからないけど、 \n一度andを使ってwhere分を分けてやったら、 \nエラーは発生しません。\n\n```\n\n SELECT pkey,ID \n FROM Tbl_Dev \n WHERE pkey\n IN (('1'))\n and pkey\n IN (('2'))\n and ID\n IN (('2'))\n and ID\n IN (('0'))\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2021-12-17T08:31:17.880", "id": "85197", "last_activity_date": "2021-12-17T17:54:19.703", "last_edit_date": "2021-12-17T17:54:19.703", "last_editor_user_id": "32986", "owner_user_id": "50549", "parent_id": "68006", "post_type": "answer", "score": 0 } ]
68006
68027
68027
{ "accepted_answer_id": null, "answer_count": 3, "body": "お世話になります。 \n私は、インストーラーなどの知識が乏しい状態ですので、 \nトライした事項はなく、質問しかできない状態です。 \nご了承ください。\n\n参考にできるウェブサイトなどご紹介いただけるだけでも大変ありがたいです。 \n業務におきまして、引継ぎが行われなかったところがあり、大変困っている状態です。 \n前任者はすでに退職、さらにソフトウェア開発が主の会社ではありません。\n\nご質問したいのは、 開発元から、実行ファイル(exe)が配布されてくるのですが、 \nそこから前任者は(.msi)ファイルと(.exe)ファイルを作成し配布しておりました。 \n前任者が作成していたexeファイルと開発元から送られているexeは名前も違い、容量も違います。\n\nmsiファイルとexeファイルの意味は調べて分かっている状態ですが、\n\nmsiファイルとexeファイルの作成方法が分からない状態です。 \ninno setupしか持ち合わせていないのでinno setupで教えていただきたいのですが、 \n他のフリーソフトで簡単に作成できるのであれば、それでも大丈夫ですので教えていただきたいです。\n\nおそらく大変初歩的な質問なのだと思います。 \nご返答いただけば幸いです。\n\nこの操作が出来れば、一通り問題なく引き継げるようになります。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T02:16:13.907", "favorite_count": 0, "id": "68007", "last_activity_date": "2023-05-01T09:00:10.070", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40828", "post_type": "question", "score": 1, "tags": [ "inno-setup" ], "title": "InnoSetupを用いてexeファイルから msiファイル、exeファイルを作成したい。", "view_count": 717 }
[ { "body": "要するに\n\n * 1つの製品において実行形式ファイルは1つとは限らず `.exe` のほかに `.dll` や `.exe.config` などなど、複数のファイルが必要なことがほとんど\n * ヘルプファイルとかサンプルデータファイルとかが別途必要かもしれない\n * ハードウエア製品ならデバイスドライバとかも追加が必要\n * 今回作成している実行形式だけでなくて `vcredist.exe` とか `.NET Framework 3.5` とか別プロジェクトを事前・事後にインストールする必要があることもある\n * たいていのお客はスタートメニューやデスクトップにショートカットを追加したいだろう\n * データファイルの拡張子と実行形式ファイルを関連付けしたいだろう\n * そしてアプリを安全に削除するための補助情報も残しておきたいだろう\n\nというわけでこれらの処理一式をするのがインストーラです。そして「インストーラ」 `*.msi` を作るソフトが `InnoSetup` であるとか\n`Visual Studio Installer Projects` です。\n\nこれらの使い方ならそこら中に解説があるわけでそちらを読んでいただくと幸い(いやオイラがここで解説してもいいですけど)\n\nですがその前に先ほど挙げた「インストーラで何をするの?」案件分析が必要です。それはプロジェクトによってみな違うはずなので、それはあなたが自分で整理するしかないです。そしてその機能を実現するには\n`InnoSetup` ならこういう操作をするとか `VSInstallerProjects`\nではこういう操作をするとか、そういう話になります。前提となる案件の理解なしに解説だけ読んでもわけわからんが多いっす(オイラがそうだったので)\n\nなので実のところ初歩的な質問などでは全くありません。\n\nとりあえずここ jSO\nで「1つの製品の詳細な使いかた」の説明は困難なのでまずは自分でいろいろ記事を探して実践してみてください。「こういう機能を実現したいんだけど」みたいに質問が小さくなれば、回答してくれる人も増えるでしょう。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T03:02:00.320", "id": "68014", "last_activity_date": "2020-06-26T03:02:00.320", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "68007", "post_type": "answer", "score": 1 }, { "body": "InnoSetup6.0.4と仮定しますと、 \nInnoSetupCompilerというものが、インストールされていると思います。 \nそれを起動して、File->Newを選択して、Wizardに沿って進めてみてください。 \n途中でEXEを選択する項目があるので、それをお手持ちのEXEファイルにすれば出来上がりです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T03:12:25.343", "id": "68016", "last_activity_date": "2020-06-26T03:12:25.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32891", "parent_id": "68007", "post_type": "answer", "score": 0 }, { "body": "使い方で分からないことがあったら、まずは **マニュアルに頼る** (マニュアルを探す) 癖を付けることをお勧めします。\n\n今回のケースであれば英語になりますが [Inno Setup Help](https://jrsoftware.org/ishelp/)\nにオンラインマニュアルがありますし、 \n「Inno Setup」でgoogle 検索すると [Inno Setup 日本語 デベロッパーズガイド](http://inno-\nsetup.sidefeed.com/) というサイトもヒットします (後者は情報の鮮度が分かりませんが…)。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T05:47:19.060", "id": "68022", "last_activity_date": "2020-06-26T05:47:19.060", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "68007", "post_type": "answer", "score": 1 } ]
68007
null
68014
{ "accepted_answer_id": "68013", "answer_count": 1, "body": "複数のサーバのソースをアップデート(データの入れ替え)をするため、以下のようなシェルスクリプトを作りました。\n\n```\n\n #リモート先へシェル転送\n cat /var/tmp/remote.sh | ssh ユーザ@ホスト 'cat > /var/tmp/remote.sh'\n #転送したシェルを実行\n ssh ユーザ@ホスト chmod u+x ./remote.sh | ./remote.sh\n \n```\n\nこれでリモート先で動作はするのですが、エラーログは誤情報を吐きます。 \nローカル入っていないが、リモート先で入っているnode.jsのコマンドが見つからないとログでは言われていながら、実行されていたり、データのコピーも出来ないと言われながらされていたりします。\n\n以下のようなコマンドで直接sshログインしてからシェルを実行すると正常なログが出ます。\n\n```\n\n ssh ユーザ@ホスト\n ./remote.sh\n \n```\n\nリモート先のシェルスクリプト実行でログを正常に出すにはどうすればよいのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T02:28:13.430", "favorite_count": 0, "id": "68010", "last_activity_date": "2020-06-26T04:07:11.040", "last_edit_date": "2020-06-26T04:07:11.040", "last_editor_user_id": "3060", "owner_user_id": "36855", "post_type": "question", "score": 0, "tags": [ "shellscript", "ssh" ], "title": "リモート先シェルスクリプト起動してもログが誤情報を吐き出す。", "view_count": 69 }
[ { "body": "> ssh ユーザ@ホスト chmod u+x ./remote.sh | ./remote.sh\n\nだと「./remote.sh」がローカル側で実行されてしまっていると思います。\n\n> ssh ユーザ@ホスト 'chmod u+x ./remote.sh | ./remote.sh'\n\nとすべきではないでしょうか? \nあと、途中のパイプも不要な気がするので\n\n> ssh ユーザ@ホスト 'chmod u+x ./remote.sh && ./remote.sh'\n\nのような感じになるのではないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T02:50:40.417", "id": "68013", "last_activity_date": "2020-06-26T02:50:40.417", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30745", "parent_id": "68010", "post_type": "answer", "score": 1 } ]
68010
68013
68013
{ "accepted_answer_id": "68318", "answer_count": 1, "body": "[[Python] Django ロケールファイルを追加して日本語メッセージを変更する -\nQiita](https://qiita.com/okoppe8/items/e1c8d4b6ba24af788504) \nなどを参考に、英語を元文にして日本語ユーザーには日本語で表示するように開発したはずなのですが、英語で表示されてしまいます。もちろんブラウザの言語設定は日本語にしています。\n\n試しにsettings.pyのLANGUAGE_CODEを'en-\nus'から'ja'にしたらちゃんと日本語が表示されるようになったのでソースなどは間違ってないはずです。しかしこれだと海外ユーザーにも日本語で表示されてしまうと思うので、LANGUAGE_CODEを'en-\nUS'のままローカライズしたいと思います。 \nどのすれば解決するでしょう?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T04:02:24.807", "favorite_count": 0, "id": "68018", "last_activity_date": "2020-07-05T21:43:08.537", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "816", "post_type": "question", "score": 0, "tags": [ "django" ], "title": "Djangoでローカライズが反映されない", "view_count": 229 }
[ { "body": "ミドルウェアを追加してないことが原因でした。失礼しました。 \n'django.contrib.sessions.middleware.SessionMiddleware', \n'django.middleware.locale.LocaleMiddleware',#これ \n'django.middleware.common.CommonMiddleware', \n参考リンク:[Django、多言語対応 - Narito Blog](https://narito.ninja/blog/detail/86/)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-05T21:43:08.537", "id": "68318", "last_activity_date": "2020-07-05T21:43:08.537", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "816", "parent_id": "68018", "post_type": "answer", "score": 0 } ]
68018
68318
68318
{ "accepted_answer_id": "68046", "answer_count": 1, "body": "こちらの記事を参考にdynamodbインポートを試みているのですがうまくいきません。\n\nAmazon DynamoDB への CSV 一括取り込みの実装 \n<https://aws.amazon.com/jp/blogs/news/implementing-bulk-csv-ingestion-to-\namazon-dynamodb/>\n\nDynamoDB、Amazon S3、Lambda、および AWS CloudFormation にアクセスできる IAM ユーザー。\n\n記事の内容はs3にcsvが入ったら、それをトリガーとしてcsvをdynamodbにインポートさせるlambdaを動かす \ncloudfomationスタックを作るものと記憶しています。\n\n### dynamoDBの構成\n\nテーブル名 test \nプライマリパーティションキー tag (文字列) \nプライマリソートキー keyword (文字列)\n\n### 挿入csvの構成\n\n```\n\n hoge1,fuga1\n hoge2,fuga2\n hoge3,fuga3\n hoge4,fuga4\n hoge5,fuga5\n hoge6,fuga6\n hoge7,fuga7\n hoge8,fuga8\n hoge9,fuga9\n hoge10,fuga10\n \n```\n\n手順としてfloudfomationに入り\n\n1.スタックの作成をクリック\n\n前提条件 - テンプレートの準備: \nテンプレートの準備完了を選択\n\nテンプレートの指定: \nテンプレートファイルのアップロードを選択、 \nテンプレートには記事から入れるgithubにあるテンプレートを選択\n\n2.スタックの詳細を指定\n\nスタックの名前:csv-to-dynamodb\n\nパラメータ \nbucketname「dynamo-imp-0101」\n\ndynamodbtablename[test] \n↑サンプルに合うフォーマットで作成したテーブル\n\nfilename[test.csv] \n↑サンプルファイルの上から2行のみ使用\n\n3.スタックオプションの設定\n\nアクセス許可: \n以下のロールを使用\n\n使用付与ロール: \ns3fullaccess \nDynamoDBfullaccess \nLambdafullaccess \nCloudFormationfullaccess\n\nこの設定でスタックを作成しても、すぐにcloudfomationに \n×マークがついてしまいます。\n\n考えられるエラーでIAMの設定が適してない為、処理が継続しないことが \n考えられます、ただし、十分にロールの権限を付与しているため \nどのような権限を付与すればよいかわかりません。\n\n「csvファイル名やテーブル名、バケット名が間違ってないか」 \n「csvとテーブルのフォーマット間違ってないか」 \nについては調べてつぶしています。\n\nイベントログはこちらになります。\n\n```\n\n 2020-06-26 12:14:59 UTC+0900 testfile ROLLBACK_COMPLETE -\n 2020-06-26 12:14:58 UTC+0900 LambdaRole DELETE_COMPLETE -\n 2020-06-26 12:14:56 UTC+0900 DynamoDBTable DELETE_COMPLETE -\n 2020-06-26 12:14:56 UTC+0900 LambdaRole DELETE_IN_PROGRESS -\n 2020-06-26 12:14:49 UTC+0900 testfile ROLLBACK_IN_PROGRESS The following resource(s) failed to create: [DynamoDBTable, LambdaRole]. . Rollback requested by user.\n 2020-06-26 12:14:48 UTC+0900 LambdaRole CREATE_FAILED Resource creation cancelled\n 2020-06-26 12:14:47 UTC+0900 LambdaRole CREATE_IN_PROGRESS -\n 2020-06-26 12:14:47 UTC+0900 DynamoDBTable CREATE_FAILED testfile already exists in stack arn:aws:cloudformation:ap-northeast-1:671527041604:stack/xxx/b4e28760-b52a-11ea-9d7b-06c1e14cac70\n \n \n```\n\n```\n\n {\n \"AWSTemplateFormatVersion\": \"2010-09-09\",\n \"Metadata\": {\n \n },\n \"Parameters\" : {\n \"BucketName\": {\n \"Description\": \"Name of the S3 bucket you will deploy the CSV file to\",\n \"Type\": \"String\",\n \"ConstraintDescription\": \"must be a valid bucket name.\"\n },\n \"FileName\": {\n \"Description\": \"Name of the S3 file (including suffix)\",\n \"Type\": \"String\",\n \"ConstraintDescription\": \"Valid S3 file name.\"\n },\n \"DynamoDBTableName\": {\n \"Description\": \"Name of the dynamoDB table you will use\",\n \"Type\": \"String\",\n \"ConstraintDescription\": \"must be a valid dynamoDB name.\"\n }\n },\n \"Resources\": {\n \"DynamoDBTable\":{\n \"Type\": \"AWS::DynamoDB::Table\",\n \"Properties\":{\n \"TableName\": {\"Ref\" : \"test\"},\n \"BillingMode\": \"PAY_PER_REQUEST\",\n \"AttributeDefinitions\":[\n {\n \"AttributeName\": \"uuid\",\n \"AttributeType\": \"S\"\n }\n ],\n \"KeySchema\":[\n {\n \"AttributeName\": \"uuid\",\n \"KeyType\": \"HASH\"\n }\n ],\n \"Tags\":[\n {\n \"Key\": \"Name\",\n \"Value\": {\"Ref\" : \"test\"}\n }\n ]\n }\n },\n \"LambdaRole\" : {\n \"Type\" : \"AWS::IAM::Role\",\n \"Properties\" : {\n \"AssumeRolePolicyDocument\": {\n \"Version\" : \"2012-10-17\",\n \"Statement\" : [\n {\n \"Effect\" : \"Allow\",\n \"Principal\" : {\n \"Service\" : [\"lambda.amazonaws.com\",\"s3.amazonaws.com\"]\n },\n \"Action\" : [\n \"sts:AssumeRole\"\n ]\n }\n ]\n },\n \"Path\" : \"/\",\n \"ManagedPolicyArns\":[\"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole\",\"arn:aws:iam::aws:policy/AWSLambdaInvocation-DynamoDB\",\"arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess\"],\n \"Policies\": [{\n \"PolicyName\": \"policyname\",\n \"PolicyDocument\": {\n \"Version\": \"2012-10-17\",\n \"Statement\": [{\n \"Effect\": \"Allow\",\n \"Resource\": \"*\",\n \"Action\": [\n \"dynamodb:PutItem\",\n \"dynamodb:BatchWriteItem\"\n ]\n }]\n }\n }]\n }\n },\n \"CsvToDDBLambdaFunction\": {\n \"Type\": \"AWS::Lambda::Function\",\n \"Properties\": {\n \"Handler\": \"index.lambda_handler\",\n \"Role\": {\n \"Fn::GetAtt\": [\n \"LambdaRole\",\n \"Arn\"\n ]\n },\n \"Code\": {\n \"ZipFile\": {\n \"Fn::Join\": [\n \"\\n\",\n [\n \"import json\",\n \"import boto3\",\n \"import os\",\n \"import csv\",\n \"import codecs\",\n \"import sys\",\n \"\",\n \"s3 = boto3.resource('s3')\",\n \"dynamodb = boto3.resource('dynamodb')\",\n \"\",\n \"bucket = os.environ['bucket']\",\n \"key = os.environ['key']\",\n \"tableName = os.environ['table']\",\n \"\",\n \"def lambda_handler(event, context):\",\n \"\", \n \"\",\n \" #get() does not store in memory\",\n \" try:\",\n \" obj = s3.Object(bucket, key).get()['Body']\",\n \" except:\",\n \" print(\\\"S3 Object could not be opened. Check environment variable. \\\")\",\n \" try:\",\n \" table = dynamodb.Table(tableName)\",\n \" except:\",\n \" print(\\\"Error loading DynamoDB table. Check if table was created correctly and environment variable.\\\")\",\n \"\",\n \" batch_size = 100\",\n \" batch = []\",\n \"\",\n \" #DictReader is a generator; not stored in memory\",\n \" for row in csv.DictReader(codecs.getreader('utf-8')(obj)):\",\n \" if len(batch) >= batch_size:\",\n \" write_to_dynamo(batch)\",\n \" batch.clear()\",\n \"\",\n \" batch.append(row)\",\n \"\",\n \" if batch:\",\n \" write_to_dynamo(batch)\",\n \"\",\n \" return {\",\n \" 'statusCode': 200,\",\n \" 'body': json.dumps('Uploaded to DynamoDB Table')\",\n \" }\",\n \"\",\n \"\", \n \"def write_to_dynamo(rows):\",\n \" try:\",\n \" table = dynamodb.Table(tableName)\",\n \" except:\",\n \" print(\\\"Error loading DynamoDB table. Check if table was created correctly and environment variable.\\\")\",\n \"\",\n \" try:\",\n \" with table.batch_writer() as batch:\",\n \" for i in range(len(rows)):\",\n \" batch.put_item(\",\n \" Item=rows[i]\",\n \" )\",\n \" except:\",\n \" print(\\\"Error executing batch_writer\\\")\"\n ]\n ]\n }\n },\n \"Runtime\": \"python3.7\",\n \"Timeout\": 900,\n \"MemorySize\": 3008,\n \"Environment\" : {\n \"Variables\" : {\"bucket\" : { \"Ref\" : \"BucketName\" }, \"key\" : { \"Ref\" : \"FileName\" },\"table\" : { \"Ref\" : \"DynamoDBTableName\" }}\n }\n }\n },\n \n \"S3Bucket\": {\n \"DependsOn\" : [\"CsvToDDBLambdaFunction\",\"BucketPermission\"],\n \"Type\": \"AWS::S3::Bucket\",\n \"Properties\": {\n \n \"BucketName\": {\"Ref\" : \"BucketName\"},\n \"AccessControl\": \"BucketOwnerFullControl\",\n \"NotificationConfiguration\":{\n \"LambdaConfigurations\":[\n {\n \"Event\":\"s3:ObjectCreated:*\",\n \"Function\":{\n \"Fn::GetAtt\": [\n \"CsvToDDBLambdaFunction\",\n \"Arn\"\n ]\n }\n }\n ]\n }\n }\n },\n \"BucketPermission\":{\n \"Type\": \"AWS::Lambda::Permission\",\n \"Properties\":{\n \"Action\": \"lambda:InvokeFunction\",\n \"FunctionName\":{\"Ref\" : \"CsvToDDBLambdaFunction\"},\n \"Principal\": \"s3.amazonaws.com\",\n \"SourceAccount\": {\"Ref\":\"AWS::AccountId\"}\n }\n }\n },\n \"Outputs\" : {\n \n }\n }\n \n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T04:27:30.280", "favorite_count": 0, "id": "68019", "last_activity_date": "2020-07-09T17:05:19.300", "last_edit_date": "2020-07-09T17:05:19.300", "last_editor_user_id": "3060", "owner_user_id": "39754", "post_type": "question", "score": 0, "tags": [ "aws", "amazon-dynamodb" ], "title": "こちらの記事を参考にdynamodbインポートを試みているのですがうまくいきません。", "view_count": 595 }
[ { "body": "エラーメッセージの通り\n\n> DynamoDBTable CREATE_FAILED testfile already exists in stack\n> arn:aws:cloudformation:ap-\n> northeast-1:671527041604:stack/xxx/b4e28760-b52a-11ea-9d7b-06c1e14cac70\n\nDynamoDB上に同名のテーブルが既に存在することが原因で、それを削除するかテーブル名を変更する必要があります。\n\n> dynamodbtablename[test] \n> ↑サンプルに合うフォーマットで作成したテーブル\n\nCloudFormationはテーブルを作成するコードを含んでいるので、事前に作成しておくことは邪魔にしかならないということでしょう。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T00:17:02.797", "id": "68046", "last_activity_date": "2020-06-27T00:17:02.797", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "68019", "post_type": "answer", "score": 0 } ]
68019
68046
68046
{ "accepted_answer_id": null, "answer_count": 1, "body": "MT4を使って取得したデータを自作クラスに格納しております。\n\n下記のコードでリストに設定後、リスト内のpositionProfitLossカラムでソートを行いたいのですが compare, sort\nの方法をご教示いただけないでしょうか。\n\n```\n\n class HogeClass:public CObject{\n public:\n string hogeId, hogeTime\n int amount, positionProfitLoss\n public:\n void\n 以下省略\n }\n \n CList hogeList;\n \n void setToList(){\n HogeClass *hoge = new HogeClass(\n \"posId1234\"\n , \"20201010\"\n , 1000\n , -49\n );\n hogeList.Add(hoge);\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T06:04:01.557", "favorite_count": 0, "id": "68023", "last_activity_date": "2020-08-08T23:58:50.217", "last_edit_date": "2020-08-08T23:58:50.217", "last_editor_user_id": "15413", "owner_user_id": "40831", "post_type": "question", "score": -1, "tags": [ "c++" ], "title": "MT4の自作クラス(CList)をソートする方法", "view_count": 350 }
[ { "body": "質問するときは環境に関する情報を詳しく記述しましょう。\n\n * [技術系メーリングリストで質問するときのパターン・ランゲージ](https://www.hyuki.com/writing/techask.html)\n\n「MT4」というのが何なのかよく分かりませんが、おそらく「MetaTrader 4」のことだと仮定します。\n\nMetaTrader\n5のリファレンスを見る限り、[`CObject::Compare()`](https://www.mql5.com/en/docs/standardlibrary/cobject/cobjectcompare)をオーバーライドして、所望のメンバー変数を基に比較すれば、[`CList::Sort()`](https://www.mql5.com/en/docs/standardlibrary/datastructures/clist/clistsort)が使えるようになるのではないでしょうか。\n\n```\n\n class Xxx : public CObject {\n ...\n public:\n virtual int Compare(const CObject* node, const int mode = 0) const override {\n // 引数 node から Xxx へのポインタを得る場合は、\n // static_cast または dynamic_cast でダウンキャストする。\n // this オブジェクトが node オブジェクトと等しい場合は 0 を返す。\n // this オブジェクトが node オブジェクトよりも小さい場合は -1 を返す。\n // this オブジェクトが node オブジェクトよりも大きい場合は 1 を返す。\n // 引数 mode が何なのかは不明。\n }\n };\n \n```\n\n質問する前に、まずはリファレンスを読むようにしてください。大手ベンダー/零細ベンダー問わず、日本語版リファレンスは翻訳がおかしかったり、情報が古かったりするので、原文の英語版リファレンスを読んだほうが正確な情報を得られます。技術系の英文は高校レベルの知識があれば十分読めます。\n\nちなみにこのライブラリは一見古いMFC (Microsoft Foundation Classes)\nに酷似していますが、それなりに経験を積んだC++プログラマーの立場から言わせてもらうと、全体的にかなりおかしな設計になっています。よほどの理由がない限り使わないほうがいいと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-25T16:26:26.717", "id": "68963", "last_activity_date": "2020-07-25T16:39:21.117", "last_edit_date": "2020-07-25T16:39:21.117", "last_editor_user_id": "15413", "owner_user_id": "15413", "parent_id": "68023", "post_type": "answer", "score": 1 } ]
68023
null
68963
{ "accepted_answer_id": null, "answer_count": 0, "body": "**環境** \nApache: 2.4.6 \nPHP: 5.6 CGI/FastCGI \nOS: CentOS 7.5.1804\n\n**説明**\n\n<https://www.php.net/manual/ja/function.flock.php>\n\n上記PHPのマニュアルを読むと、以下記述がありました。\n\n> いくつかのオーペレーティングシステムでflock() はプロセスレベルで実装されています。ISAPIのようなマルチスレッド \n> 型のサーバーAPIを使用している場合、同じサーバーインスタンスの並 列スレッドで実行されている他のPHPスクリプトに対してファイルを保護する際に\n> flock()を使用することはできません!\n\nflock()はFATのような 旧式のファイルシステムではサポートされていないため、 これらの環境の場合は常にFALSEを返すことになります。\n\nevent MPMでは1つのプロセスから複数のスレッドが起動し、各スレッドでPHPが実行されると理解しています。 \nその場合、上記の制限事項に引っかかると思うのですが、情報をお持ちの方はいらっしゃいませんか? \nこの制限内容だと、実質的にpreforkで動作するPHPでしかflockが使用できないように思うのですが、Web上ではそのような情報は見つけられませんでした。\n\nまた、マルチスレッド環境でも動作するロック機構が存在するのであれば、それについても情報があるとありがたいです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T06:53:59.030", "favorite_count": 0, "id": "68024", "last_activity_date": "2020-06-29T07:17:31.177", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "17238", "post_type": "question", "score": 2, "tags": [ "php", "apache" ], "title": "Apacheのevent MPMで動作するPHPでflockは使用可能ですか?", "view_count": 132 }
[]
68024
null
null
{ "accepted_answer_id": "68032", "answer_count": 1, "body": "エンドポイントの認証には既に成功しています。\n\nこれ以降は音声コマンドをaiboが認識すると、エンドポイントのプログラムがキックされると思います。 \nこの際に検証に使った①「eventIdやchallenge」ではなく、②「deviceId、data、eventId、timestamp」がエンドポイントに飛びますよね?\n\n【質問】 \n②の場合、エンドポイントのプログラムから、毎回aiboクラウドに対して何らかのリターン(など)は必要ですか? \nそれとも一度認証してしまえば、以降は特にリターン不要(認証で使った①challengeなどの受け取り・リターン部分のコードは除去可能)でしょうか? \n※エンドポイント側では、aibo Web APIの行動制御を行おうとは思っていません。エンドポイントにあるサーバ側の処理を実行させようとしているだけです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T07:12:48.067", "favorite_count": 0, "id": "68025", "last_activity_date": "2020-06-26T12:04:35.197", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "36635", "post_type": "question", "score": 1, "tags": [ "aibo-developer", "aibo-visual-programming" ], "title": "エンドポイント認証成功後も、毎回aiboクラウドへのリターンは必要か?", "view_count": 127 }
[ { "body": "aibo デベロッパーサポート担当です。\n\naibo クラウドからデベロッパーのエンドポイントに対して送られる HTTP リクエストは、次の 2 つに分類できます。\n\n * A. eventId が endpoint_verification の場合\n * B. eventId が endpoint_verification 以外の場合\n\nそれぞれのリクエストに対しては、以下のように応答してください。\n\n**A. eventId が endpoint_verification の場合**\n\nエンドポイントの検証が行われる際に送られるリクエストです。 \nサーバーが正常にリクエストを処理できた場合には下記で応答してください。\n\n> statusCode: 200 \n> body: challenge が含まれたJSON オブジェクト\n\n現行仕様では、エンドポイントの検証リクエストがエンドポイントの登録時以外に送られることはありません。\n\n詳しくは以下を参照してください\n\n<https://developer.aibo.com/jp/docs#%E3%82%A8%E3%83%B3%E3%83%89%E3%83%9D%E3%82%A4%E3%83%B3%E3%83%88%E3%81%AE%E6%A4%9C%E8%A8%BC>\n\n```\n\n エンドポイントから aibo クラウドへ送る検証用 HTTP リクエスト\n レスポンスとして statusCode に 200 を、challege に送られて来た値を設定した body を作成し、返してください。\n \n```\n\n**B. eventId が endpoint_verification 以外の場合**\n\naibo からのイベントが通知される際に送られるリクエストです。 \nサーバーが正常にリクエストを処理できた場合には下記で応答してください。\n\n> statusCode: 200\n\n上記はいずれも現時点での仕様ですので、aibo Events API が更新された際はご確認ください。\n\n今後とも aibo デベロッパープログラムをどうぞよろしくお願いいたします。 \naibo デベロッパーサポートチーム", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T12:04:35.197", "id": "68032", "last_activity_date": "2020-06-26T12:04:35.197", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "36494", "parent_id": "68025", "post_type": "answer", "score": 3 } ]
68025
68032
68032
{ "accepted_answer_id": null, "answer_count": 1, "body": "Spresense Reference Board v2.0.1(Spresense Arduino Library\nv2.0.1)のスケッチ例`Signal\nProcessing/LowPassSound`を実行し、シリアルモニタを開くと以下のようなログが表示され、スピーカーからノイズが再生されました。正常に動作されるためにはどのような処理が必要なのでしょうか?つい先日触り始めた機器のため右も左も分からず、困り果てています…もう一つの開発環境であるIDEバージョンで解決な場合は、ご案内をいただけると助かります。\n\n以下の調査を通してメモリ不足を疑っておりますが、対処の方法が思いつきません。 \nよろしくお願いいたします。\n\n* * *\n\n## 環境\n\nwindows10 Pro \nArduino IDE 1.8.13 \nSpresense Reference Board v2.0.1 \n**ボード設定** \n[![画像の説明をここに入力](https://i.stack.imgur.com/4p5Zq.png)](https://i.stack.imgur.com/4p5Zq.png)\n\n## 1.サンプルコードをそのまま実行した場合\n\n[公式ドキュメント](https://developer.sony.com/develop/spresense/docs/arduino_tutorials_ja.html#_highpasssound_lowpasssound)を参考にDSPライブラリをSDカードにインストールした後、サンプルコードを実行した。 \n以下のログが表示された。Insufficient buffer areaとあるので、メモリ不足を疑い、2を実行した。\n\n```\n\n initialization MediaRecorder, MediaPlayer and OutputMixer\n recorder init\n player init\n recorder start\n player start\n WARNING: Insufficient buffer area.\n Error! 8 ,d04d8b0 , 1536\n WARNING: Insufficient buffer area.\n .\n .\n .同様の表示\n .\n Error! 8 ,d04d8b0 , 1536\n WARNING: Insufficient buffer area.\n \n```\n\n## 2.サンプリングレートを落とした場合\n\n再生/録音のサンプリングレートを48kHz->16kHzにし、さらにメモリの使用容量を調べるコードをmaincore,subcore1に挿入し実行した。しかしスピーカーから音すら出なかった。 \nsubcore1とmaincoreが起動した時点で`Free: 128 [KB]`となり、ヒープ領域がほとんど存在していない上に、\n\n```\n\n mptask_exec() failure. -12\n Attention: module[11][0] attention id[2]/code[18] (components/decoder/decoder_component.cpp L593)\n \n```\n\nとあり、おそらくDSPモジュールを読み込めなかったことが想定できる。とにかくメモリ不足が原因に見えたが、対処の方法が思いつかなかった。\n\n以下はコードとログである。 \n**ログ**\n\n```\n\n [Sub1] Used:1024 [KB] / Free: 512 [KB] (Largest: 512 [KB])\n nitialization MediaRecorder, MediaPlayer and OutputMixer\n recorder init\n player init\n mptask_exec() failure. -12\n Attention: module[11][0] attention id[2]/code[18] (components/decoder/decoder_component.cpp L593)\n \n [Main] Used:1408 [KB] / Free: 128 [KB] (Largest: 128 [KB])\n recorder start\n Attention: module[4][0] attention id[1]/code[6] (objects/media_recorder/audio_recorder_sink.cpp L84)\n \n error! -116Attention!! Level 0x1 Code 0x6\n \n```\n\n**maincore.ino**\n\n```\n\n #include <MP.h>\n #include <MediaRecorder.h>\n #include <MediaPlayer.h>\n #include <OutputMixer.h>\n #include <MemoryUtil.h>\n \n MediaRecorder *theRecorder;\n MediaPlayer *thePlayer;\n OutputMixer *theMixer;\n \n /* Now suppot only mono channel*/\n \n /* Select mic channel number */\n const int mic_channel_num = 1;\n //const int mic_channel_num = 2;\n \n const int32_t s_buffer_size = 768 * mic_channel_num * sizeof(uint16_t);\n uint8_t s_buffer[s_buffer_size];\n bool ErrEnd = false;\n \n const int subcore = 1;\n \n struct Request {\n void *buffer;\n int sample;\n };\n \n struct Result {\n void *buffer;\n int sample;\n };\n \n /**\n @brief Audio attention callback\n \n When audio internal error occurc, this function will be called back.\n */\n \n static void attention_callback(const ErrorAttentionParam *atprm)\n {\n puts(\"Attention!\");\n \n if (atprm->error_code >= AS_ATTENTION_CODE_WARNING)\n {\n ErrEnd = true;\n }\n }\n \n /**\n @brief Recorder done callback procedure\n \n @param [in] event AsRecorderEvent type indicator\n @param [in] result Result\n @param [in] sub_result Sub result\n \n @return true on success, false otherwise\n */\n \n static bool mediarecorder_event_callback(AsRecorderEvent event, uint32_t result, uint32_t sub_result)\n {\n return true;\n }\n \n /**\n @brief Mixer done callback procedure\n \n @param [in] requester_dtq MsgQueId type\n @param [in] reply_of MsgType type\n @param [in,out] done_param AsOutputMixDoneParam type pointer\n */\n static void outputmixer_event_callback(MsgQueId requester_dtq,\n MsgType reply_of,\n AsOutputMixDoneParam *done_param)\n {\n return;\n }\n \n /**\n @brief Mixer data send callback procedure\n \n @param [in] identifier Device identifier\n @param [in] is_end For normal request give false, for stop request give true\n */\n static void outmixer_rendering_callback(int32_t identifier, bool is_end)\n {\n AsRequestNextParam next;\n \n next.type = (!is_end) ? AsNextNormalRequest : AsNextStopResRequest;\n \n AS_RequestNextPlayerProcess(AS_PLAYER_ID_0, &next);\n \n return;\n }\n \n /**\n @brief Player done callback procedure\n \n @param [in] event AsPlayerEvent type indicator\n @param [in] result Result\n @param [in] sub_result Sub result\n \n @return true on success, false otherwise\n */\n static bool mediaplayer_event_callback(AsPlayerEvent event, uint32_t result, uint32_t sub_result)\n {\n /* If result of \"Play\", restart recording (It should been stopped when \"Play\" requested) */\n return true;\n }\n \n /**\n @brief Player decode callback procedure\n \n @param [in] pcm_param AsPcmDataParam type\n */\n void mediaplayer_decode_callback(AsPcmDataParam pcm_param)\n {\n /* You can imprement any audio signal process */\n \n /* Output and sound audio data */\n theMixer->sendData(OutputMixer0,\n outmixer_rendering_callback,\n pcm_param);\n }\n \n void setup()\n {\n \n \n /* Launch SubCore */\n int ret = MP.begin(subcore);\n if (ret < 0) {\n printf(\"MP.begin error = %d\\n\", ret);\n }\n /* receive with non-blocking */\n MP.RecvTimeout(20);\n \n /* Initialize memory pools and message libs */\n Serial.println(\"Init memory Library\");\n \n initMemoryPools();\n createStaticPools(MEM_LAYOUT_RECORDINGPLAYER);\n \n /* start audio system */\n Serial.println(\"Init Audio Library\");\n \n theRecorder = MediaRecorder::getInstance();\n thePlayer = MediaPlayer::getInstance();\n theMixer = OutputMixer::getInstance();\n \n theRecorder->begin();\n thePlayer->begin();\n \n puts(\"initialization MediaRecorder, MediaPlayer and OutputMixer\");\n \n theMixer->activateBaseband();\n \n /* Create Objects */\n \n thePlayer->create(MediaPlayer::Player0, attention_callback);\n theMixer->create(attention_callback);\n \n /* Activate Objects. Set output device to Speakers/Headphones */\n \n theRecorder->activate(AS_SETRECDR_STS_INPUTDEVICE_MIC, mediarecorder_event_callback);\n thePlayer->activate(MediaPlayer::Player0, AS_SETPLAYER_OUTPUTDEVICE_SPHP, mediaplayer_event_callback);\n theMixer->activate(OutputMixer0, outputmixer_event_callback);\n \n usleep(100 * 1000);\n \n /*\n Initialize recorder to decode stereo wav stream with 48kHz sample rate\n Search for SRC filter in \"/mnt/sd0/BIN\" directory\n */\n uint8_t channel;\n switch (mic_channel_num) {\n case 1: channel = AS_CHANNEL_MONO; break;\n case 2: channel = AS_CHANNEL_STEREO; break;\n case 4: channel = AS_CHANNEL_4CH; break;\n }\n \n //const auto codec_path = \"/mnt/spif/BIN\";\n \n theRecorder->init(AS_CODECTYPE_LPCM, channel, AS_SAMPLINGRATE_16000, AS_BITLENGTH_16, 0);//サンプリングレートを変更したらどうにかなる?\n theRecorder->setMicGain(180);\n puts(\"recorder init\");\n thePlayer->init(MediaPlayer::Player0, AS_CODECTYPE_WAV,AS_SAMPLINGRATE_16000, channel);\n puts(\"player init\");\n \n /* Start Recorder */\n \n theMixer->setVolume(0, 0, 0);\n \n #if 1\n //memcheck\n int usedMem, freeMem, largestFreeMem;\n \n MP.GetMemoryInfo(usedMem, freeMem, largestFreeMem);\n \n MPLog(\"Used:%4d [KB] / Free:%4d [KB] (Largest:%4d [KB])\\n\",\n usedMem / 1024, freeMem / 1024, largestFreeMem / 1024);\n #endif \n }\n \n typedef enum e_appState {\n StateReady = 0,\n StatePrepare,\n StateRun\n } appState_t;\n \n void loop()\n {\n static appState_t state = StateReady;\n \n int8_t sndid = 100; /* user-defined msgid */\n int8_t rcvid = 0;\n int read_size;\n int ret;\n \n static Request request;\n static Result* result;\n \n switch (state) {\n case StateReady:\n {\n /* Start recording */\n theRecorder->start();\n puts(\"recorder start\");\n state = StatePrepare;\n break;\n }\n case StatePrepare:\n {\n static int pre_cnt = 0;\n err_t err = theRecorder->readFrames(s_buffer, s_buffer_size, &read_size);\n \n if (err != 0) { printf(\"Error! %x ,%x , %d\\n\",err,request.buffer,request.sample); }\n \n if (read_size > 0)\n {\n request.buffer = s_buffer;\n request.sample = read_size/ sizeof(uint16_t) / mic_channel_num;\n MP.Send(sndid, &request, subcore);\n \n if (pre_cnt < 2) {\n pre_cnt++;\n break;\n }\n \n /* Receive sound from SubCore */\n int ret = MP.Recv(&rcvid, &result, subcore);\n if (ret >= 0) {\n if (result->sample != 768) { break;}\n thePlayer->writeFrames(MediaPlayer::Player0, result->buffer, result->sample*2);\n pre_cnt++;\n } else {\n printf(\"error! %d\", ret);\n exit(1);\n }\n } else {\n break;\n }\n \n if (pre_cnt > 10) {\n puts(\"player start\");\n thePlayer->start(MediaPlayer::Player0, mediaplayer_decode_callback);\n pre_cnt = 0;\n state = StateRun;\n }\n break;\n }\n \n case StateRun:\n {\n err_t err = theRecorder->readFrames(s_buffer, s_buffer_size, &read_size);\n \n if (err != 0) {printf(\"Error! %x ,%x , %d\\n\",err,request.buffer,read_size);}\n if (read_size > 0)\n {\n request.buffer = s_buffer;\n request.sample = read_size / sizeof(uint16_t) / mic_channel_num;\n MP.Send(sndid, &request, subcore);\n \n /* Receive sound from SubCore */\n ret = MP.Recv(&rcvid, &result, subcore);\n if (ret >= 0) {\n if (result->sample != 768) {break;}\n thePlayer->writeFrames(MediaPlayer::Player0,result->buffer, result->sample*2);\n } else {\n printf(\"error! %d\", ret);\n exit(1);\n }\n } else {\n break;\n }\n break;\n }\n default:\n {\n puts(\"error!\");\n exit(1);\n }\n }\n }\n \n```\n\n**subcore.ino**\n\n```\n\n #include <MP.h>\n \n #include \"IIR.h\"\n \n /* Use CMSIS library */\n #define ARM_MATH_CM4\n #define __FPU_PRESENT 1U\n #include <cmsis/arm_math.h>\n \n /* channel number */\n const int g_channel = 1;\n \n IIRClass LPF;\n \n /* Allocate the larger heap size than default */\n \n USER_HEAP_SIZE(64 * 1024);\n \n /* MultiCore definitions */\n \n struct Request {\n void *buffer;\n int sample;\n };\n \n struct Result {\n void *buffer;\n int sample;\n };\n \n void setup()\n {\n int ret = 0;\n \n /* Initialize MP library */\n ret = MP.begin();\n if (ret < 0) {\n errorLoop(2);\n }\n /* receive with non-blocking */\n // MP.RecvTimeout(MP_RECV_POLLING);\n MP.RecvTimeout(100000);\n LPF.begin(TYPE_LPF,g_channel,1000,sqrt(0.5));\n #if 1\n //memcheck\n int usedMem, freeMem, largestFreeMem;\n \n MP.GetMemoryInfo(usedMem, freeMem, largestFreeMem);\n \n MPLog(\"Used:%4d [KB] / Free:%4d [KB] (Largest:%4d [KB])\\n\",\n usedMem / 1024, freeMem / 1024, largestFreeMem / 1024);\n #endif \n }\n \n #define RESULT_SIZE 4\n void loop()\n {\n int ret;\n int8_t sndid = 10; /* user-defined msgid */\n int8_t rcvid;\n Request *request;\n static Result result[RESULT_SIZE];\n \n static q15_t pDst[FRAMSIZE];\n static q15_t out_buffer[RESULT_SIZE][FRAMSIZE*g_channel];\n static int pos=0;\n \n /* Receive PCM captured buffer from MainCore */\n ret = MP.Recv(&rcvid, &request);\n if (ret >= 0) {\n LPF.put((q15_t*)request->buffer,request->sample);\n }else{\n puts(\"error!\");\n return;\n }\n \n int cnt = 0;\n while (!LPF.empty(0)) {\n for (int i = 0; i < g_channel; i++) {\n cnt = LPF.get(pDst,i);\n /* support only mono channel */\n memcpy(&out_buffer[pos][0],pDst,cnt*2);\n }\n \n result[pos].buffer = MP.Virt2Phys(&out_buffer[pos][0]);\n result[pos].sample = cnt;\n \n ret = MP.Send(sndid, &result[pos],0);\n pos = (pos+1)%RESULT_SIZE;\n if (ret < 0) {\n errorLoop(1);\n }\n }\n }\n \n void errorLoop(int num)\n {\n int i;\n \n while (1) {\n for (i = 0; i < num; i++) {\n ledOn(LED0);\n delay(300);\n ledOff(LED0);\n delay(300);\n }\n delay(1000);\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T09:11:12.940", "favorite_count": 0, "id": "68029", "last_activity_date": "2020-08-14T02:08:45.927", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40834", "post_type": "question", "score": 1, "tags": [ "spresense", "arduino" ], "title": "Spresenseのサンプルコード \"Signal Processing/LowPassSound\"を実行しても正常に動作せず、mptask_exec() failure. -12と表示される。", "view_count": 425 }
[ { "body": "自分が実行したところ、特にノイズにはなりませんでした。\n\nただ、このエラーは、確かに出ますね。\n\nWARNING: Insufficient buffer area. \nError! 8 ,d04d8b0 , 1536\n\nでも、このエラー出ても動作するようです。 \nWARNING なので、警告程度なのでしょうか。", "comment_count": 6, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T12:22:18.823", "id": "68034", "last_activity_date": "2020-06-26T12:22:18.823", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32281", "parent_id": "68029", "post_type": "answer", "score": 0 } ]
68029
null
68034
{ "accepted_answer_id": "68190", "answer_count": 1, "body": "現在Java8のcompletablefutureを勉強しています。\n\n表題にある通りなのですが、 \n**completablefutureにおいてthencomposeのメソッドチェーンを途中で抜ける方法はありますでしょうか?**\n\n例えば以下のようなコードにおいて以下のような方法はありますでしょうか? \n後者に関しては意図的にExceptionを投げる方法だけでしょうか? \nExceptionを投げるにしても意図的に投げるとしたらどのようなExceptionを投げるべきでしょうか? \n・①のthenComposeで処理を終える方法 \n・①のthenComposeから②のexceptionallyに飛ぶ方法\n\n```\n\n public class CompletableFutureTest {\n \n public static void main(String[] args) throws InterruptedException, ExecutionException {\n CompletableFuture<String> future = CompletableFuture.completedFuture(\"aaaaa\");\n future = future.thenCompose(s -> CompletableFuture.completedFuture(\"bbb\"))\n .thenCompose(f -> CompletableFuture.completedFuture(\"ccc\")) //①\n .thenCompose(f -> CompletableFuture.completedFuture(1111))\n .thenCompose(f -> CompletableFuture.completedFuture(\"ffff\"))\n .thenApply(s -> CompletableFuture.completedFuture(\"ffff\"))\n .thenCompose(f -> CompletableFuture.completedFuture(\"ffff\"))\n .exceptionally(s -> \"ffff\"); //②\n \n System.out.println(future.get());\n }\n }\n \n```\n\nもしわかる方がいればお願い致します。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T10:31:20.640", "favorite_count": 0, "id": "68030", "last_activity_date": "2020-07-01T13:50:29.970", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40231", "post_type": "question", "score": 1, "tags": [ "java", "java8" ], "title": "completablefutureにおいてthencomposeのメソッドチェーンを途中で抜ける方法があるか知りたい", "view_count": 170 }
[ { "body": "```\n\n boolean isThrowException = true;\n CompletableFuture<String> future = CompletableFuture.completedFuture(\"aaaaa\");\n future = future.thenCompose(s -> CompletableFuture.completedFuture(\"bbb\"))\n .thenCompose(f -> {\n if(isThrowException) {\n throw new RuntimeException(\"Its a Exception\");\n }\n return CompletableFuture.completedFuture(\"ccc\");\n }) //①\n .thenCompose(f -> CompletableFuture.completedFuture(1111))\n .thenCompose(f -> CompletableFuture.completedFuture(\"ffff\"))\n .thenApply(s -> CompletableFuture.completedFuture(\"ffff\"))\n .thenCompose(f -> CompletableFuture.completedFuture(\"ffff\"))\n .exceptionally(s -> s.getMessage()); //②\n \n System.out.println(future.get());\n \n```\n\nこれはどうでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-01T13:50:29.970", "id": "68190", "last_activity_date": "2020-07-01T13:50:29.970", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40887", "parent_id": "68030", "post_type": "answer", "score": 1 } ]
68030
68190
68190
{ "accepted_answer_id": null, "answer_count": 0, "body": "python tensorflow Keras-rl使用して、DQNをCNNモデルを使用して学習させています。 \nそこで、自身のMacBook Proを使用して学習させたときと、GoogleColabのGPUを使用して学習させたときに、 \n結果に天と地ほどの差が生まれてました。\n\n学習時間が大きく変わることは承知していますが、MacBookではあまりいい結果が出ないのに対し、Colabではいい結果が出ました。 \n何回繰り返しても、同様の結果が出てしまいます。\n\nまた、いい結果の出ているモデルを使用して、MacBookとColabにおいて動かした結果、 \nMacBookでは下手でしたが、Colabではちゃんと上手なプレイをしていました。\n\nこれは、マシンの性能に差があるために、ニューラルネットワークがうまく機能していないなど、 \nそういったことが起きているのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T15:23:49.350", "favorite_count": 0, "id": "68039", "last_activity_date": "2020-06-26T15:23:49.350", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "36620", "post_type": "question", "score": 1, "tags": [ "python", "tensorflow", "gpu", "ニューラルネットワーク" ], "title": "DQNにおいて、MacBook ProとGoogle ColabのGPUを使用したときの学習に差が生じる問題について", "view_count": 126 }
[]
68039
null
null
{ "accepted_answer_id": "68042", "answer_count": 1, "body": "JST の 「年 月 日 時 分 秒 ミリ秒」 からDateをインスタンス化したいです。 \nそれは↓のコードで完璧に動作します。\n\n```\n\n SimpleDateFormat format = new SimpleDateFormat(\"yyyy MM dd HH mm ss SSS z\");\n format.parse(new StringBuilder()\n .append(year).append(' ')\n .append(month).append(' ')\n .append(day).append(' ')\n .append(hour).append(' ')\n .append(minute).append(' ')\n .append(second).append(' ')\n .append(milli).append(\" JST\").toString());\n \n```\n\nですが、このコードは非効率だと思います。 \nなぜなら、日付情報などはフォーマットで保持しておらず、最初から整数として持っているからです。 \nこのコードだと \n年月日などの整数 → フォーマット → フォーマット解析 → Date \nという処理になってしまいます。\n\nもっと効率よくDateをインスタンス化する方法を探しています。\n\n```\n\n Calendar cl = new GregorianCalendar(TimeZone.getTimeZone(\"JST\"));\n cl.set(uear, month-1, day, hour, minute, second);\n cl.getTime();\n \n```\n\nこのCalendarを使用するコードは動作する端末のディフォルトタイムゾーンにより思うように動作しません。 \n私は事前にJSTをCalendarにセットすれば`set`メソッドで指定する数値はJSTのものでいいと思っていましたがそうではないみたいで\n\n例えば\n\n_**2020/06/27 00:54:01 557**_\n\nという日付をCalendarでDateに変換したとき、 \n_**【UTC端末で実行したら】**_ \nFri Jun 26 15:54:01 UTC 2020 \n1593186841557 \nこのタイムスタンプを日本時間に変換すると「2020/06/27 00:54:01」なので正常\n\n_**【JST端末で実行したら】**_ \nSat Jun 27 09:54:01 GMT+09:00 2020 \n1593219241766 \nこのタイムスタンプを日本時間に変換すると「2020/06/27 09:54:01」となりタイムゾーン関連で期待通りの数値になりませんでした。\n\nどのような方法がありますでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T18:19:21.210", "favorite_count": 0, "id": "68041", "last_activity_date": "2020-06-26T21:09:27.200", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10346", "post_type": "question", "score": 0, "tags": [ "java", "kotlin" ], "title": "Java で 年月日 などから Date をインスタンス化する", "view_count": 187 }
[ { "body": "`OffsetDateTime.of()`で`OffsetDateTime`オブジェクトを生成した後、`Date`へ変換することができます。\n\n```\n\n // 2020/06/27 00:54:01 557 (JST)\n // 注: 第7引数はミリ秒でなくナノ秒\n final OffsetDateTime datetime = OffsetDateTime.of(2020, 6, 27, 0, 54, 1, 557_000_000, ZoneOffset.ofHours(9));\n // final ZonedDateTime datetime = ZonedDateTime.of(2020, 6, 27, 0, 54, 1, 557_000_000, ZoneId.of(\"JST\", ZoneId.SHORT_IDS));\n final Date date = Date.from(datetime.toInstant());\n System.out.println(date);\n System.out.println(date.getTime());\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T20:55:53.480", "id": "68042", "last_activity_date": "2020-06-26T21:09:27.200", "last_edit_date": "2020-06-26T21:09:27.200", "last_editor_user_id": "2808", "owner_user_id": "2808", "parent_id": "68041", "post_type": "answer", "score": 1 } ]
68041
68042
68042
{ "accepted_answer_id": "68135", "answer_count": 1, "body": "[sizeof(size_t)未満の幅の型の、メモリ上隣り合った変数に関して、マルチスレッドプログラムはデータ競合なく読み書きできますか?](https://ja.stackoverflow.com/questions/67969/)\n\n上記の投稿においては `size_t` 型はハードウエア的に特殊な意味を持つ(バス幅ないしはキャッシュバウンダリー)\nように書かれています。ですが、オイラの認識では C99 6.5.3.4 ならびに C++03 5.3.3 で「 `sizeof` の結果は `size_t`\n型の定数である」とだけあってハードウエアの機能に関係する型ではありません。\n\n最近の C/C++ 規格改定で `size_t` の機能にハードウエアに関係する文言が追加されているでしょうか? \n(すんません最近の規格書がフォローできていないっす)", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-26T22:30:00.627", "favorite_count": 0, "id": "68043", "last_activity_date": "2020-06-30T05:05:06.083", "last_edit_date": "2020-06-27T06:28:30.487", "last_editor_user_id": "3060", "owner_user_id": "8589", "post_type": "question", "score": 2, "tags": [ "c++", "c" ], "title": "最近の規格書改定で size_t に新しい(ハードウエア的)意味が増えましたか?", "view_count": 260 }
[ { "body": "> 最近の C/C++ 規格改定で `size_t` の機能にハードウエアに関係する文言が追加されているでしょうか?\n\nそのような改定は行われてないはずです。(少なくともC++2aドラフト、C2xドラフトでは。)\n\n* * *\n\nC++2a [support.types.layout]/p3\n\n> The type `size_­t` is an implementation-defined unsigned integer type that\n> is large enough to contain the size in bytes of any object ([expr.sizeof]).\n\nC2x §7.19 Common definitions <stddef.h>/p1\n\n> `size_t` \n> which is the unsigned integer type of the result of the sizeof operator;", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T05:05:06.083", "id": "68135", "last_activity_date": "2020-06-30T05:05:06.083", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "49", "parent_id": "68043", "post_type": "answer", "score": 2 } ]
68043
68135
68135
{ "accepted_answer_id": "68048", "answer_count": 1, "body": "Reactのドキュメントを読み始めました。\n\n[Getting Started – React](https://ja.reactjs.org/docs/getting-\nstarted.html#try-react) に\n\n> 自前のテキストエディタを使いたい場合は、この HTML\n> ファイルをダウンロード・編集して、ブラウザを使ってからローカルファイルシステムから開くことができます。ランタイムでの遅いコード変換が行われる為、簡単なデモに留めておくことをおすすめします。\n\nとあるので、「このHTMLファイル」を開いてみると下記のようになっていました。\n\n```\n\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <title>Hello World</title>\n <script src=\"https://unpkg.com/react@16/umd/react.development.js\"></script>\n <script src=\"https://unpkg.com/react-dom@16/umd/react-dom.development.js\"></script>\n \n <!-- Don't use this in production: -->\n <script src=\"https://unpkg.com/@babel/standalone/babel.min.js\"></script>\n </head>\n <body>\n <div id=\"root\"></div>\n <script type=\"text/babel\">\n \n ReactDOM.render(\n <h1>Hello, world!</h1>,\n document.getElementById('root')\n );\n \n </script>\n <!--\n Note: this page is a great way to try React but it's not suitable for production.\n It slowly compiles JSX with Babel in the browser and uses a large development build of React.\n \n Read this section for a production-ready setup with JSX:\n https://reactjs.org/docs/add-react-to-a-website.html#add-jsx-to-a-project\n \n In a larger project, you can use an integrated toolchain that includes JSX instead:\n https://reactjs.org/docs/create-a-new-react-app.html\n \n You can also use React without JSX, in which case you can remove Babel:\n https://reactjs.org/docs/react-without-jsx.html\n -->\n </body>\n </html>\n \n```\n\nここでJSXについて知りたいと思い下記を読みました。\n\n * [JSX の導入 – React](https://ja.reactjs.org/docs/introducing-jsx.html)\n * [Add React to a Website – React](https://reactjs.org/docs/add-react-to-a-website.html#quickly-try-jsx)\n\n構文についての引用:\n\n> 以下の変数宣言を考えてみましょう:\n>\n> `const element = <h1>Hello, world!</h1>;` \n> このおかしなタグ構文は文字列でも HTML でもありません。\n>\n> これは JSX と呼ばれる JavaScript の構文の拡張です。\n\nJSXについての引用:\n\n> The quickest way to try JSX in your project is to add this tag to your page:\n>\n> `<script src=\"https://unpkg.com/babel-standalone@6/babel.min.js\"></script>` \n> Now you can use JSX in any tag by adding type=\"text/babel\" attribute to it.\n> Here is an example HTML file with JSX that you can download and play with.\n>\n> This approach is fine for learning and creating simple demos. However, it\n> makes your website slow and isn’t suitable for production. When you’re ready\n> to move forward, remove this new tag and the type=\"text/babel\" attributes\n> you’ve added. Instead, in the next section you will set up a JSX\n> preprocessor to convert all your tags automatically.\n\nなるほど、「`babel.min.js` と `text/babel`\nを使うことでいい感じに動くんだな(ただし本番では使わない)」と理解したのですが....\n\n下記のように `babel.min.js` を剥がして、JSXだけ書いてもエラーになりません。\n\n```\n\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <title>Hello World</title>\n \n </head>\n <body>\n <div id=\"root\"></div>\n <script type=\"text/babel\">\n <h1>aaaa</h1>\n </script>\n </body>\n </html>\n \n```\n\n加えて、下記のように\n\n```\n\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\" />\n <title>Hello World</title>\n \n </head>\n <body>\n <div id=\"root\"></div>\n <script type=\"text/babel\">\n console.log(\"AA\n </script>\n </body>\n </html>\n \n```\n\nと明らかに console.log の構文をミスってみてもエラーになりませんでした。\n\n`text/babel` を剥がすとどちらのパターンもエラーになりました。\n\n`text/babel` とはいったい何でしょうか?\n\n(babelはローカル環境でコンパイルして使ったことしかなかったのでこれは不思議です)\n\nChromeで試しています。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T00:06:50.597", "favorite_count": 0, "id": "68045", "last_activity_date": "2020-06-27T01:28:55.260", "last_edit_date": "2020-06-27T01:04:18.907", "last_editor_user_id": "9008", "owner_user_id": "9008", "post_type": "question", "score": 5, "tags": [ "javascript", "reactjs", "babeljs", "react-jsx" ], "title": "text/babel とはなんですか?", "view_count": 1639 }
[ { "body": "MDNの[`<script>`要素](https://developer.mozilla.org/ja/docs/Web/HTML/Element/Script#:%7E:text=type)のドキュメントを読むと\n\n> `type` \n> スクリプトを表すタイプを指定します。この属性の値は、以下の種類のいずれかにします。\n>\n> * **省略または JavaScript の MIME タイプ** : これはスクリプトが JavaScript であることを示します。 HTML5\n> 仕様書では、冗長な MIME タイプを指定せずに属性を省略するよう主張しています。過去のブラウザーでは埋め込まれている、あるいは (`src` 属性で)\n> インポートされたコードのスクリプト言語を指定していました。JavaScript の MIME タイプは仕様書に掲載されています。\n> * **`module`** : コードを JavaScript モジュールとして扱います。スクリプトの処理は、charset および defer\n> 属性の影響を受けません。 `module` の利用についての情報は、 _JavaScript モジュール_\n> をご覧ください。クラシックスクリプトとは異なり、モジュールスクリプトはオリジン間のフェッチに CORS プロトコルの使用を必要とします。\n> * **その他の値** :\n> このタグで埋め込んだコンテンツを、ブラウザーによって処理されないデータブロックとして扱います。開発者はデータブロックを記述するために、\n> JavaScript の MIME タイプではない有効な MIME タイプを使用しなければなりません。 src 属性は無視されます。\n>\n\nとあり、`text/babel`は「 _その他の値_\n」に該当します。つまり、ブラウザはこれをただのデータフラグメントとして扱い、記述されたコードは無視します。babelのランタイムトランスパイラはこれ([`text/babel`を指定したscriptタグ](https://github.com/babel/babel/blob/eea156b2cb8deecfcf82d52aa1b71ba4995c7d68/packages/babel-\nstandalone/src/transformScriptTags.js#L192)など)をテキストとして読み込み、パース、トランスパイル、実行をしてくれます。これによってscriptタグ内にJSコードを書くのと同様に実行できるわけです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T01:21:45.633", "id": "68048", "last_activity_date": "2020-06-27T01:28:55.260", "last_edit_date": "2020-06-27T01:28:55.260", "last_editor_user_id": "2376", "owner_user_id": "2376", "parent_id": "68045", "post_type": "answer", "score": 6 } ]
68045
68048
68048
{ "accepted_answer_id": "68076", "answer_count": 1, "body": "VBA から (Strawberry Perlに入っている) GCC で作る関数 (DLL) を呼び出したいのですが、何から調べれば良いですか? \nご指導よろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T04:10:27.500", "favorite_count": 0, "id": "68049", "last_activity_date": "2020-06-28T11:35:10.343", "last_edit_date": "2020-06-28T11:35:10.343", "last_editor_user_id": "3060", "owner_user_id": "40839", "post_type": "question", "score": 0, "tags": [ "vba", "gcc", "dll" ], "title": "VBA から (Strawberry Perlに入っている) GCC で作る関数 (DLL) を呼び出したい", "view_count": 332 }
[ { "body": "Strawberry Perlに同梱されているgccはMinGW-w64のようなので、その辺のキーワードで検索した記事が参考になるでしょう。\n\n[mingw-w64 GCC for Windows 64 & 32 bits](http://mingw-w64.org/doku.php)\n\n> Some Projects using Mingw-w64\n>\n> * [Strawberry Perl (bundles C toolchains)](http://strawberryperl.com/)\n>\n\n単に最小限のソースからDLLを作って呼べるように試したプロジェクト例 \n[rdinse/MSAccessSQL_DLL.md](https://gist.github.com/rdinse/0696f2cd3509a01237e5c3385dc54869)\n\n少し古いかもな記事 \n[VB6, VBA の文字列 String を返す\nDLLを作成する](https://happynow.hateblo.jp/entry/20130825/1377404951)\n\n32bit版での記事 \n[DLL compiled from C source code. Not able to use in excel VBA. File not found\nerror](https://stackoverflow.com/q/30265036/9014308)\n\n実は解決していない記事 \n[Using MinGW gcc to create DLLs for VBA 64\nbit](https://stackoverflow.com/q/59110111/9014308) \n[Unable to run C coded DLL in Excel\nVBA](https://stackoverflow.com/q/61309881/9014308)\n\nこちらはVBAではなくVisual Basic向けですが。 \n[Visual Basic DLL | MinGW](http://www.mingw.org/wiki/Visual_Basic_DLL) \n[Compile a DLL in C/C++, then call it from another\nprogram](https://stackoverflow.com/q/847396/9014308)\n\n上記でExcelから呼べた記事 \n[Excel won't load function from C++\nDLL](https://stackoverflow.com/q/11403981/9014308)\n\n参考:VisualStudio系での記事 \n[DLLを作成してみる(その1)](http://dorapanda.asablo.jp/blog/2013/02/24/6729220) \n[1章:DLLの作成方法とVBAから呼び出し方法](http://skomo.o.oo7.jp/f46/hp46_1.htm) \n[ExcelのVBAで使えるDLLを、C++(Visual Studio\n2017)で作る。・・・その1](https://z1000s.hatenablog.com/entry/2018/04/15/213852)\n\n* * *\n\n他には上記記事にも一部書かれていますが、VBA側の知識も必要でしょう。\n\nDLLの関数をどう定義してどう呼び出すか、パラメータや戻り値は、といったことが説明されています。 \n[Excel で DLL にアクセスする](https://docs.microsoft.com/ja-jp/office/client-\ndeveloper/excel/how-to-access-dlls-in-excel)\n\n上記を含む開発キット(VisualStudio用?)の先頭ページ \n[Excel ソフトウェア開発キットへようこそ](https://docs.microsoft.com/ja-jp/office/client-\ndeveloper/excel/welcome-to-the-excel-software-development-kit)\n\nDLL経由でなくてもAPIを呼べたりしますが、方法とか(64bit時の)注意事項とか。 \n[VBAでWinAPI32を使うためのリンク集](https://qiita.com/Q11Q/items/16862ef1797e25cbadfd)", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T07:52:50.463", "id": "68076", "last_activity_date": "2020-06-28T07:52:50.463", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "68049", "post_type": "answer", "score": -1 } ]
68049
68076
68076
{ "accepted_answer_id": "68054", "answer_count": 1, "body": "canvasへ描画した内容をSVGのパスデータへ変換して、SVGのパターンを適用させてみたいのですが、そもそも、canvasへ描画した内容をSVGのパスデータへ変換することは出来ますか?\n\n検索してみたら下記ページが見つかったのですが、ここで記載されている内容は、canvasへ描画した内容をSVGへ取り込んでいるだけでSVGのパスデータへ変換しているわけではないのですか?\n\n[CanvasをSVGで利用する方法](http://nmi.jp/archives/216)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T04:19:24.613", "favorite_count": 0, "id": "68050", "last_activity_date": "2020-06-27T10:21:56.600", "last_edit_date": "2020-06-27T07:59:29.107", "last_editor_user_id": "3060", "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "svg", "html5-canvas" ], "title": "canvasへ描画した内容をSVGのパスデータへ変換して、パターン適用させることは出来ますか?", "view_count": 1137 }
[ { "body": "「canvasへ描画した内容をSVGのパスデータへ変換」に関しては、「パス」に変換されるかは不明ですが、この(古い)記事によると以下のようなライブラリがあるようです。\n\n[Method to convert HTML5 canvas to\nSVG?](https://stackoverflow.com/q/8571294/9014308)\n\n[Fabric.js](http://fabricjs.com/)というのが、そういう機能(canvasとSVG間の相互変換)を持っているようです。\n\n> Fabric.js is a powerful and simpleJavascript HTML5 canvas library \n> Fabric provides interactive object model on top of canvas elementFabric\n> also has SVG-to-canvas (and canvas-to-SVG) parser\n>\n> Fabric.jsは、強力でシンプルなJavascript HTML5キャンバスライブラリです。 \n> Fabricは、canvas elementFabricの上にインタラクティブなオブジェクトモデルを提供します。Fabricには、SVG-to-\n> canvas(およびcanvas-to-SVG)パーサーもあります。\n\nまた[gliffy/canvas2svg](https://github.com/gliffy/canvas2svg)というのもあるようです。\n\n> This library turns your Canvas into SVG using javascript. In other words,\n> this library lets you build an SVG document using the canvas api. \n> We create a mock 2d canvas context. Use the canvas context like you would\n> on a normal canvas. As you call methods, we build up a scene graph in SVG.\n>\n> このライブラリは、JavaScriptを使用してCanvasをSVGに変換します。 つまり、このライブラリーでは、canvas\n> APIを使用してSVGドキュメントを構築できます。 \n> 模擬2Dキャンバスコンテキストを作成します。 通常のキャンバスと同じように、キャンバスコンテキストを使用します。\n> メソッドを呼び出すと、SVGでシーングラフが作成されます。\n\nあと古いようですが、[canvas-svg](https://code.google.com/archive/p/canvas-\nsvg/)と逆の[canvg/canvg](https://github.com/canvg/canvg)というのもあるようですね。 \ncanvas-svg\n\n> This is a set of related components that make canvas and SVG play together\n> more. Notably, it allows you to save a canvas 2D context as SVG, and to have\n> an SVG mirror of a canvas context. \n> これは、canvasとSVGをより連携させる関連コンポーネントのセットです。\n> 特に、キャンバスの2DコンテキストをSVGとして保存し、キャンバスコンテキストのSVGミラーを持つことができます。\n\ncanvg\n\n> JavaScript SVG parser and renderer on Canvas. It takes the URL to the SVG\n> file or the text of the SVG file, parses it in JavaScript and renders the\n> result on Canvas. \n> Canvas上のJavaScript SVGパーサーおよびレンダラー。\n> SVGファイルのURLまたはSVGファイルのテキストを取得し、JavaScriptで解析して、結果をCanvasにレンダリングします。\n\n* * *\n\nちなみにMDNにSVG教本があり、[基本的な図形](https://developer.mozilla.org/ja/docs/Web/SVG/Tutorial/Basic_Shapes)とか[パス](https://developer.mozilla.org/ja/docs/Web/SVG/Tutorial/Paths)とか説明されています。 \n他に基本的な図形からパスへの変換は、以下の記事でIllustratorで出来るとか、そういうサービスのWebサイトがあるとかなので、頑張れば出来るか上記ライブラリの中に機能があるかするのでしょう。\n\n[How to convert a circle to a\npath?](https://graphicdesign.stackexchange.com/q/82491)\n\n> For example, when I save an SVG from illustrator and view the code, I see a\n> <circle> element, for example, but I'd like for it to be a <path> element,\n> not a <circle> element. \n> How can I change it to be a path element? \n>\n> たとえば、IllustratorからSVGを保存してコードを表示すると、たとえば<circle>要素が表示されますが、それを<circle>要素ではなく<path>要素にしたいと考えています。 \n> どうすればパス要素に変更できますか?\n\n> **One solution** : In Illustrator, select your circle and choose Object >\n> Compound Path > Make. \n> **1つの解決策** : Illustratorで円を選択し、[オブジェクト]> [複合パス]> [作成]を選択します。\n\n以下はどこかに英語版の元記事がありそうですが。 \n[svgのpolygon,\npolylineをpathに変換する方法](https://www.creamu.co.jp/blog/technology/2019/12/svg_polygon_polyline_path.html)\n\n> svgの線/塗り(stroke /\n> fill)のアニメーションをしたい場合、パスにする必要があり、ポリゴン/ポリラインだとうまくいきません。polygon,\n> polylineをpathに変換するには、以下サイトから行います。\n>\n> [Convert SVG Polygon to Path](https://codepen.io/michaelschofield/pen/gKpef)\n>\n> HTMLにsvgタグをペーストして、下の空白の部分をクリックし、Chromeデベロッパーツールでsvgタグをコピーして使用します。\n\nこれらの記事とかも何か出来そうです。 \n[Convert SVG polygon to path](https://stackoverflow.com/q/10717190/9014308) \n[svgのpolygonのpointsをpathのdとして扱う](https://qiita.com/yoshiiiiie/items/abe30977e86779999c2f)\n\n* * *\n\nそれからPathの簡略化のような機能が必要では? と思ったので探してみたら、使えるかどうか不明ですがズバリの名前の物とか有りました。\n\n[mourner/simplify-js](https://mourner.github.io/simplify-js/)\n\n> Simplify.js is a high-performance JavaScript polyline simplification library\n> by Vladimir Agafonkin, extracted from Leaflet.\n>\n> Simplify.jsは、リーフレットから抽出された、Vladimir\n> Agafonkinによる高性能JavaScriptポリライン簡略化ライブラリです。\n\n類似なのかどうなのか、Paper.jsというのもあるようです。 \n[Simplifying SVG path in\njavascript](https://stackoverflow.com/q/39218265/9014308)\n\n> Does anybody know a js library/algorithm for optimizing SVG path? I need to\n> optimize paths only (reduce number of nodes). My path is autogenerated and\n> is full of beziers, so simplify.js mentioned in a similar question won't\n> fit. I'm also required to use browser, so node-backed modules won't fit too.\n>\n> SVGパスを最適化するためのjsライブラリ/アルゴリズムを知っている人はいますか? パスのみを最適化する必要があります(ノードの数を減らします)。\n> 私のパスは自動生成され、ベジェでいっぱいなので、同様の質問で言及されたsimplify.jsは適合しません。\n> また、ブラウザーを使用する必要があるので、ノード・ベースのモジュールも適合しません。\n\n> Finally used paperjs. Unfortunately they don't support modular builds yet. \n> 最後にpaperjsを使用しました。 残念ながら、それらはまだモジュール式ビルドをサポートしていません。\n\n[Paper.js](http://paperjs.org/)\n\n* * *\n\nなお「パターン適用」は逆に簡単かもしれません。 \n以下のような記事があり、適用したいパスで`.getPointAtLength(n)`するとポジションを取得出来るようです。\n\n[Implement Div objects on SVG\npath](https://stackoverflow.com/q/26850265/9014308) \n[Placing and rotating svg elements along a path with\nSnap.svg](https://stackoverflow.com/q/27132114/9014308)\n\n* * *\n\nついでに日本語のまとめ記事もあるようです。 \n[SVGを使うときに知っておくといいことをまとめました](https://qiita.com/manabuyasuda/items/01a76204f97cd73ffc4e)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T07:43:27.020", "id": "68054", "last_activity_date": "2020-06-27T10:21:56.600", "last_edit_date": "2020-06-27T10:21:56.600", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "68050", "post_type": "answer", "score": 2 } ]
68050
68054
68054
{ "accepted_answer_id": "68055", "answer_count": 1, "body": "お世話になります。 \nVBAで、文の表現に揺れがあるののや、漢字が平仮名になっているだけ、「。」が無いだけで、文の意味が一致するものを、同じ一つのキーする方法ありませんか? \nご指導よろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T04:51:01.873", "favorite_count": 0, "id": "68051", "last_activity_date": "2020-06-27T09:43:25.353", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40839", "post_type": "question", "score": 0, "tags": [ "vba" ], "title": "VBA で、文の意味が一致するものを1つのキーに辞書に登録できますか?", "view_count": 166 }
[ { "body": "質問に書いてあるような多機能さは無いでしょう。 \nサポートしている範囲では、 **検索時** のキーで大文字/小文字、ひらがな/カタカナ、全角/半角を区別しないモードがあるようです。 \n一応MS-\nAccessだけは検索時にデータベース内の情報に基づいて比較を実行する機能があると書いてあります。が詳細は不明で、それほど特別な機能があるようには見えません。単にモードの初期設定情報があるだけかもしれません。 \n**そしてこの機能は検索時だけであり登録時には影響しない(あいまいに出来たり多重に登録出来たりはしない)ようです。**\n\n[CompareMode プロパティ](https://docs.microsoft.com/ja-\njp/office/vba/language/reference/user-interface-help/comparemode-property)\n\n> Dictionary オブジェクト内の文字列キーを比較するための比較モードを設定および取得します。 \n> 構文 \n> オブジェクト。Comparemode[= compare ] \n> 設定 \n> compare 引数には、次の値を指定できます。\n```\n\n> 定数 値 説明\n> vbUseCompareOption -1 Option Compare ステートメントの設定を使用して比較を実行します。\n> vbBinaryCompare 0 バイナリ比較を実行します。\n> vbTextCompare 1 テキスト比較を実行します。\n> vbDatabaseCompare 2 Microsoft Access のみ。 データベース内の情報に基づいて比較を実行します。\n> \n```\n\n>\n> 注釈 \n> データが既に含まれる Dictionary オブジェクトの比較モードの変更を試みた場合、エラーが発生します。\n\n* * *\n\n[VBAのDictionaryの使い方(全メソッドとプロパティ網羅)](https://vbabeginner.net/vba%E3%81%AEdictionary%E3%82%AF%E3%83%A9%E3%82%B9%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%EF%BC%88%E5%85%A8%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%81%A8%E3%83%97%E3%83%AD%E3%83%91%E3%83%86%E3%82%A3/) \n[プロパティ](https://vbabeginner.net/vba%E3%81%AEdictionary%E3%82%AF%E3%83%A9%E3%82%B9%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%EF%BC%88%E5%85%A8%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89%E3%81%A8%E3%83%97%E3%83%AD%E3%83%91%E3%83%86%E3%82%A3/#keni-\ntoc6)\n\n>\n```\n\n> Property CompareMode キーのあいまい検索を許可するかどうかをCompareMethod列挙型の定数で指定します。\n> As CompareMethod\n>\n> Itemプロパティなどで使うキーがDictionaryオブジェクトに格納されているキーと厳密に同じでなければならない場合はBinaryCompareを指定し、大文字・小文字、ひらがな・カタカナ、全角・半角の区別せずに行う場合はTextCompareを指定します。\n>\n> あくまでも検索する際のキーの条件のため、テキスト比較を設定してもキーの重複が許されるわけではありません。\n> Dictionaryオブジェクトにデータがセットされている状態ではエラーになります。\n> CompareMethod列挙型\n> 定数 値 内容\n> BinaryCompare 0\n> バイナリ比較(大文字・小文字、ひらがな・カタカナ、全角・半角を区別します)\n> TextCompare 1\n> テキスト比較(大文字・小文字、ひらがな・カタカナ、全角・半角を区別しません)\n> \n```\n\n* * *\n\n質問のような機能が欲しいならば、自分で前処理としてあいまいな文字列を実際に辞書に存在するキーに変換する機能を用意する必要があるでしょう。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T09:43:25.353", "id": "68055", "last_activity_date": "2020-06-27T09:43:25.353", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "68051", "post_type": "answer", "score": 1 } ]
68051
68055
68055
{ "accepted_answer_id": null, "answer_count": 0, "body": "Unityで開発を行っております。\n\nScene読み込みを「SceneManager.LoadSceneAsync」を使用して非同期読み込みを行っています。\n\nしかし、「SceneManager.LoadSceneAsync」開始と読み込み終了からシーンを遷移させる際に \n数秒メインスレッドが停止してしまい、ローディングアニメーションが止まってしまいます。\n\n読み込み先のObject数が多いSceneほど停止時間が長くなります。\n\nローディングアニメーションはImageを一定で回転させているだけでして、 \n「StartCoroutine」、「Task」、「Animator」と処理方法を変えて対応してみたのですが、 \n解決には至りませんでした。\n\nScene遷移時にもアニメーションが止まらないような非同期処理は在りますでしょうか\n\n開発環境 \nUnity 2018.4.22f1", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T04:54:18.813", "favorite_count": 0, "id": "68052", "last_activity_date": "2020-06-27T04:54:18.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29606", "post_type": "question", "score": 1, "tags": [ "ios", "android", "unity3d" ], "title": "Scene遷移の際に非同期で動くローディングアニメーションの実装", "view_count": 286 }
[]
68052
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "環境 \nvagrantにてubuntu18.04を動かしており、git init、git addを行った際に`git add .`で下記のエラーが表示された。 \nVirtualBox:バージョン 6.0.6 r130049\n\n```\n\n error: insufficient permission for adding an object to repository database .git/objects\n error: READ.md: failed to insert into database\n error: unable to index file READ.md\n fatal: adding files failed\n \n```\n\nネットの記事を読むと権限の問題ということで `ls -l .git/objects`で権限を調べてみました。\n\n```\n\n drwxr-xr-x 1 vagrant vagrant 96 Jun 27 08:46 b6\n drwxr-xr-x 1 vagrant vagrant 160 Jun 27 08:54 e4\n drwxr-xr-x 1 vagrant vagrant 96 Jun 27 08:43 ff\n drwxr-xr-x 1 vagrant vagrant 64 Jun 27 08:42 info\n drwxr-xr-x 1 vagrant vagrant 64 Jun 27 08:42 pack\n \n```\n\n出力結果:`ls -l .git`\n\n```\n\n total 12\n -rw-rw-r-- 1 vagrant vagrant 23 Jun 27 08:42 HEAD\n drwxr-xr-x 1 vagrant vagrant 64 Jun 27 08:42 branches\n -rw-rw-r-- 1 vagrant vagrant 111 Jun 27 08:42 config\n -rw-rw-r-- 1 vagrant vagrant 73 Jun 27 08:42 description\n drwxr-xr-x 1 vagrant vagrant 416 Jun 27 08:42 hooks\n drwxr-xr-x 1 vagrant vagrant 96 Jun 27 08:42 info\n drwxr-xr-x 1 vagrant vagrant 224 Jun 27 08:49 objects\n drwxr-xr-x 1 vagrant vagrant 128 Jun 27 08:42 refs\n \n```\n\nここの方と同じエラーだと思うんですけど、なぜsudoを付けて上手く行くのか分かりません。 \n<https://github.com/hashicorp/vagrant/issues/10913>\n\n実際`sudo git add .`で上手く行きました。しかし毎回sudo付けるの嫌なので何か解決方法があると助かります。 \nこれを見るとオーナーは読み書き検索可能なので権限に問題はなさそうなのですが、何が原因でしょうか? \nご存知の方がいらしたらご教授頂けると幸いです。 \nよろしくお願いします。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T10:02:40.523", "favorite_count": 0, "id": "68056", "last_activity_date": "2021-10-30T22:04:40.200", "last_edit_date": "2020-06-28T01:02:45.307", "last_editor_user_id": "22565", "owner_user_id": "22565", "post_type": "question", "score": 1, "tags": [ "linux", "git", "vagrant", "virtualbox" ], "title": "git addでエラーが出る: insufficient permission for adding an object to repository database", "view_count": 7511 }
[ { "body": "`.git/`\nディレクトリ以下には細かなサブディレクトリがあるので、個別の原因となるファイルを特定するよりは一括で権限を変更してしまう方が手っ取り早いかもしれません。\n\n**所有者とグループを変更**\n\n```\n\n $ chown -R vagrant.vagrant .git\n \n```\n\n**読み取り + 書き込み権限を追加**\n\n```\n\n $ chmod -R ug+rw .git\n \n```\n\n参考: \n[can't add file to git repository but can change / commit - Stack\nOverflow](https://stackoverflow.com/q/7864872)", "comment_count": 6, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T11:50:27.733", "id": "68059", "last_activity_date": "2020-06-27T12:06:03.023", "last_edit_date": "2020-06-27T12:06:03.023", "last_editor_user_id": "3060", "owner_user_id": "3060", "parent_id": "68056", "post_type": "answer", "score": 1 } ]
68056
null
68059
{ "accepted_answer_id": null, "answer_count": 0, "body": "実現したいことは、ジェットコースターの垂直ループのようなコースをキャラクターに走らせることです。\n\n**参考動画(GIF)**\n\n```\n\n <img src=\"https://img.gifmagazine.net/gifmagazine/images/1386312/original.gif\" width=\"320\" />\n```\n\n**試したこと**\n\n壁の法線ベクトルを取得してその逆方向に重力をかけてあげればできるかなと思いましたが、キャラクターが落ちてしまいます。\n\nアプローチの仕方が悪いのでしょうか?解決策を探しています。よろしくお願いいたします。\n\n```\n\n Ray ray = new Ray(playerObj.transform.position, Vector3.down);\n \n int layerMask = 1 << LayerMask.NameToLayer(\"Wall\");\n \n RaycastHit raycastHit;\n if (Physics.Raycast(ray, out raycastHit, Mathf.Infinity, layerMask))\n {\n \n playerObj.transform.eulerAngles =\n Quaternion.FromToRotation(raycastHit.transform.up, raycastHit.normal).eulerAngles;\n GravityVector = playerObj.transform.rotation * Vector3.down;\n \n PlyaerRB = GameObject.Find(\"Player\").GetComponent<Rigidbody>();\n PlyaerRB.useGravity = false;\n }\n \n void update(){\n PlyaerRB.AddForce(GravityVector * 9.81f, ForceMode.Acceleration);\n }\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T11:47:53.673", "favorite_count": 0, "id": "68057", "last_activity_date": "2020-06-27T21:14:42.333", "last_edit_date": "2020-06-27T21:14:42.333", "last_editor_user_id": "3068", "owner_user_id": "40807", "post_type": "question", "score": 0, "tags": [ "unity3d", "game-development" ], "title": "キャラクターに壁を走らせたい", "view_count": 101 }
[]
68057
null
null
{ "accepted_answer_id": "68061", "answer_count": 1, "body": "有向グラフG=(V,E)の時、V = {1, 3, 4, 5, 6, 12} and E = {⟨u, v⟩ | u|v,⟨u, v⟩ ∈ V × V\nand u ̸= v}\nといった表現がされていた場合のEの右辺の表現が理解できません。この場合はどのようなグラフが期待されるのでしょうか?ご教示いただけると幸いです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T11:49:00.107", "favorite_count": 0, "id": "68058", "last_activity_date": "2020-06-27T14:07:22.880", "last_edit_date": "2020-06-27T14:03:59.990", "last_editor_user_id": "19110", "owner_user_id": "38330", "post_type": "question", "score": 0, "tags": [ "アルゴリズム", "データ構造" ], "title": "有向グラフの表現で、E = {⟨u, v⟩ | u|v,⟨u, v⟩ ∈ V × V and u ̸= v} の表すものが分からない", "view_count": 89 }
[ { "body": "おそらく u|v の部分が分からないのだと思いますが、今回頂点は自然数なので u や v も自然数で、自然数に対する u|v\nという書き方だと約数を表す記号として使われているのだと思います。Wikipedia\nの[約数](http://%E7%B4%84%E6%95%B0)のページなどを参考にしてください。\n\nただしもちろん、プログラミングで関数を自由に定義できるように、数学でも定義さえすれば記号の意味は変わりうるので、何かしらの教科書などに書いてあったのだとすればその教科書での定義を確認してください。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T14:07:22.880", "id": "68061", "last_activity_date": "2020-06-27T14:07:22.880", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "68058", "post_type": "answer", "score": 2 } ]
68058
68061
68061
{ "accepted_answer_id": null, "answer_count": 1, "body": "[Tutorial: Using Thymeleaf\n(ja)](https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf_ja.html)\n\n下記引用にHTMLが(ブラウザが?)無視してくれるという記述があります。\n\n引用:\n\n>\n> スタンダードダイアレクトの大半のプロセッサは「属性プロセッサ」です。属性プロセッサを使用すると、XHTML/HTML5テンプレートファイルは処理前であってもブラウザで正しく表示することができます。単純にその属性が無視されるからです。例えば、タグライブラリを使用したJSPだとブラウザで直接表示できない場合がありますが: \n> `<form:inputText name=\"userName\" value=\"${user.name}\" />` \n> Thymeleafスタンダードダイアレクトでは同様の機能をこのように実現します: \n> `<input type=\"text\" name=\"userName\" value=\"James Carrot\"\n> th:value=\"${user.name}\" />` \n> ブラウザで正しく表示できるだけでなく、(任意ですが)value属性を指定することもできます(この場合の “James Carrot”\n> の部分です)。プロトタイプを静的にブラウザで開いた場合にはこの値が表示され、Thymeleafでテンプレートを処理した場合には ${user.name}\n> の評価結果値で置き換えられます。\n\n属性にコロンを使った `th:value` の書き方は見慣れないのですが、HTMLのどういった仕様がこれを無視してくれるのでしょうか?", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T13:56:33.000", "favorite_count": 0, "id": "68060", "last_activity_date": "2020-06-28T05:20:53.187", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9008", "post_type": "question", "score": 0, "tags": [ "html", "thymeleaf" ], "title": "Thymeleafのth属性はなぜHTMLが無視できるようになっているのでしょうか?HTMLのどの仕様でしょうか?", "view_count": 396 }
[ { "body": "Spring BootとThymeleafの組み合わせで実現されているもので、HTMLの仕様によるものではありません。\n\n[4.1. テンプレートエンジン(Thymeleaf)](https://macchinetta.github.io/server-guideline-\nthymeleaf/current/ja/ArchitectureInDetail/WebApplicationDetail/Thymeleaf.html#id7)\nの記事をじっくりと読まれることをお勧めします。\n\n記事の4.1.1.3節で図示されているように、リクエストを受けてから、レスポンスを返すまでに、様々な処理が行われるのです。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T05:20:53.187", "id": "68073", "last_activity_date": "2020-06-28T05:20:53.187", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "68060", "post_type": "answer", "score": -1 } ]
68060
null
68073
{ "accepted_answer_id": "68093", "answer_count": 3, "body": "[javascript - HTMLで独自タグを使うのは仕様上問題ないのか -\nスタック・オーバーフロー](https://ja.stackoverflow.com/questions/31216/html%e3%81%a7%e7%8b%ac%e8%87%aa%e3%82%bf%e3%82%b0%e3%82%92%e4%bd%bf%e3%81%86%e3%81%ae%e3%81%af%e4%bb%95%e6%a7%98%e4%b8%8a%e5%95%8f%e9%a1%8c%e3%81%aa%e3%81%84%e3%81%ae%e3%81%8b)\n\n一部引用:\n\n> DOM の仕様では HTMLUnknownElement という要素が定められていて、不明な要素を扱うことができます。 \n> そのため、現時点では不明な要素を利用しても問題なく動作すると思います。\n>\n> しかしながら、将来的に新しい要素が追加される可能性があります。この時に名前がかぶってしまうと意図しない動作になる可能性があります。\n\nで、HTMLで独自のタグを使うのは問題ないことがわかりました。\n\nその後、 [Is it OK to use unknown HTML tags? - Stack\nOverflow](https://stackoverflow.com/questions/10830682/is-it-ok-to-use-\nunknown-html-tags) や [Custom Elements: HTML に新しい要素を定義する - HTML5\nRocks](https://www.html5rocks.com/ja/tutorials/webcomponents/customelements/) \nを見てみましたが、よくわかりません。\n\n私の現状の「問題ない」の理解は「文法的にOK」と言い換えることができると考えています。文法的にOKという意味が正しいとして、`HTMLUnknownElement`を使うと結局、ブラウザはどのように振る舞うのでしょうか?仕様はあるのでしょうか?\nそれとも未定義なのでしょうか?\n\n蛇足ですが、仕様に言及していると思われる\n\n[HTMLUnknownElement - Web APIs | MDN](https://developer.mozilla.org/en-\nUS/docs/Web/API/HTMLUnknownElement)\n\n> The HTMLUnknownElement interface represents an invalid HTML element and\n> derives from the HTMLElement interface, but without implementing any\n> additional properties or methods.\n\nや\n\n[HTML Standard](https://html.spec.whatwg.org/multipage/dom.html#elements-in-\nthe-dom)\n\n> The HTMLElement interface holds methods and attributes related to a number\n> of disparate features, and the members of this interface are therefore\n> described in various different sections of this specification.\n\nは私には、結局、どういうこと?(文法的にOKと言っている??)という感じで理解できませんでした...\n\nたとえば `<hoge>aaa</hoge>`\nと存在しないタグを書いてみて試してみたところ、`aaa`がブラウザの画面に表示されたのですが、これはタグで囲まれた部分を表示する仕様なのでしょうか?\nそれともこれはたまたま表示されただけなのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T14:29:40.203", "favorite_count": 0, "id": "68062", "last_activity_date": "2020-06-29T02:10:10.050", "last_edit_date": "2020-06-27T14:42:14.023", "last_editor_user_id": "9008", "owner_user_id": "9008", "post_type": "question", "score": 0, "tags": [ "html", "html5" ], "title": "HTMLUnknownElementの仕様は定義されているのでしょうか?されていないのでしょうか?", "view_count": 346 }
[ { "body": "参照先のWHATWG,MDNのページには、以下のように定義されていると考えられます。\n\n * `HTMLElement`を継承した派生インータフェース\n * `HTMLElement`に対して何もプロパティやメソッドを追加していない\n * 注意事項として、意図的に`[HTMLConstructor]`を持っていない\n * 名前が applet, bgsound, blink, isindex, keygen, multicol, nextid, spacer か、他の文書化/定義済みの要素/インターフェース等に分類されない要素である\n\nMDNのページからたどったW3Cのページには、WHATWGのページでは抜けている以下の文があります。\n\n> The HTMLUnknownElement interface must be used for HTML elements that are not\n> defined by this specification (or other applicable specifications).\n\n>\n> この仕様(またはその他の適用可能な仕様)で定義されていないHTML要素には、HTMLUnknownElementインターフェースを使用する必要があります。\n\n* * *\n\n**上記定義によれば「`HTMLUnknownElement`は`HTMLElement`とインターフェース名が違うことおよびカスタム要素機能をサポートしていないこと以外は同じに扱われる(同じ動作をする)」ように見えます。**\n\n「カスタム要素機能をサポートしていない」については注意事項の「意図的に`[HTMLConstructor]`を持っていない」ことと、そのページの次に記述されている「3.2.3\nHTML element constructors」の先頭の内容を元に推測しています。\n\n> To support the custom elements feature, all HTML elements have special\n> constructor behavior. This is indicated via the [HTMLConstructor] IDL\n> extended attribute. It indicates that the interface object for the given\n> interface will have a specific behavior when called, as defined in detail\n> below.\n\n> カスタム要素機能をサポートするために、すべてのHTML要素には特別なコンストラクター動作があります。これは、[HTMLConstructor]\n> IDL拡張属性によって示されます。\n> これは、特定のインターフェースのインターフェースオブジェクトが、以下で詳細に定義されているように、呼び出されたときに特定の動作を持つことを示します。\n\n対応する知識を持っていない単なる推測なのでトンチンカンで間違っているかもしれませんが。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T00:05:48.497", "id": "68065", "last_activity_date": "2020-06-28T00:36:48.363", "last_edit_date": "2020-06-28T00:36:48.363", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "68062", "post_type": "answer", "score": 0 }, { "body": "[Thymeleafのth属性はなぜHTMLが無視できるようになっているのでしょうか?HTMLのどの仕様でしょうか?](https://ja.stackoverflow.com/questions/68060/thymeleaf%e3%81%aeth%e5%b1%9e%e6%80%a7%e3%81%af%e3%81%aa%e3%81%9chtml%e3%81%8c%e7%84%a1%e8%a6%96%e3%81%a7%e3%81%8d%e3%82%8b%e3%82%88%e3%81%86%e3%81%ab%e3%81%aa%e3%81%a3%e3%81%a6%e3%81%84%e3%82%8b%e3%81%ae%e3%81%a7%e3%81%97%e3%82%87%e3%81%86%e3%81%8b-html%e3%81%ae%e3%81%a9%e3%81%ae%e4%bb%95%e6%a7%98%e3%81%a7%e3%81%97%e3%82%87%e3%81%86%e3%81%8b#comment74679_68060)\n\n別の質問についてコメントいただいたものからHTML4.01の仕様へのリンクがありました。\n\n[Performance, Implementation, and Design Notes](https://www.w3.org/TR/REC-\nhtml40/appendix/notes.html#notes-invalid-docs)\n\n> B.1 Notes on invalid documents \n> This specification does not define how conforming user agents handle\n> general error conditions, including how user agents behave when they\n> encounter elements, attributes, attribute values, or entities not specified\n> in this document.\n>\n> However, to facilitate experimentation and interoperability between\n> implementations of various versions of HTML, we recommend the following\n> behavior:\n>\n> If a user agent encounters an element it does not recognize, it should try\n> to render the element's content. \n> If a user agent encounters an attribute it does not recognize, it should\n> ignore the entire attribute specification (i.e., the attribute and its\n> value). \n> If a user agent encounters an attribute value it doesn't recognize, it\n> should use the default attribute value. \n> If it encounters an undeclared entity, the entity should be treated as\n> character data. \n> We also recommend that user agents provide support for notifying the user\n> of such errors.\n\n質問に関するところだけ翻訳すると\n\nユーザーエージェントが、定義されていないelements、attributes、attribute\nvalues、そしてentitiesに遭遇したとき一般的にどのようにエラーを扱うか定義していない。\n\nしかし、次のような動作を推奨する。\n\n認識できないelementに遭遇したとき、そのelementの内容をレンダリングすることが望ましい。\n\nということで、内容をレンダリングするのが望ましいとされているようです。望ましいだけで、すべてのブラウザがレンダリングするとは限らないはずです。またこれはHTML4.01の動きなので、HTML5ではどうなっているのかは見つけられていません。\n\n(つまり未定義だけど、こうした方がいいですよという提案が仕様にあるという感じだと思います)", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T07:00:18.690", "id": "68075", "last_activity_date": "2020-06-28T07:00:18.690", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9008", "parent_id": "68062", "post_type": "answer", "score": 0 }, { "body": "もとの質問「[HTMLで独自タグを使うのは仕様上問題ないのか](https://ja.stackoverflow.com/questions/31216/html%E3%81%A7%E7%8B%AC%E8%87%AA%E3%82%BF%E3%82%B0%E3%82%92%E4%BD%BF%E3%81%86%E3%81%AE%E3%81%AF%E4%BB%95%E6%A7%98%E4%B8%8A%E5%95%8F%E9%A1%8C%E3%81%AA%E3%81%84%E3%81%AE%E3%81%8B)」と同じような回答になるのではないかと思います。\n\n> たとえば `<hoge>aaa</hoge>`\n> と存在しないタグを書いてみて試してみたところ、`aaa`がブラウザの画面に表示されたのですが、これはタグで囲まれた部分を表示する仕様なのでしょうか?\n> それともこれはたまたま表示されただけなのでしょうか?\n\n表示されるのが現在の仕様です。 \nが、`<hoge>`という独自タグを使用すべきではありません。将来の仕様で`<hoge>`という要素が定義され、ブラウザの挙動が変わるかもしれないからです。\n\n独自タグを使いたいのなら、`-` が入った名前にすべきです。例: `<my-hoge>` \n`-`が入った名前は custom element 用に開放されているので、将来の規格が`-`が入ったタグ名を定義することはありません。\n\n* * *\n\n`HTMLUnknownElement`はもちろん規格で定義されています。[この手順](https://html.spec.whatwg.org/C/#elements-\nin-the-dom:element-\ninterface)で`HTMLUnknownElement`になるかどうかが決まります。ただし、`HTMLUnknownElement` は DOM\nAPI でどう見えるかだけを定義しているだけなので、パージングや表示には関係ありません。\n\nパージングに関しては、不明なタグ名でも開始タグと終了タグの対応が取れていればDOMが構築できるように定義されています。規格の一部をピンポイントで指すのは難しいですが、[The\nrules for pasing tokens in HTML\ncontent](https://html.spec.whatwg.org/C/#parsing-main-inhtml) 内で \"Any other\nstart tag\" \"Any other end tag\" のあたりで処理されます。\n\n表示に関して、CSS規格は要素名が規格で定義されているかどうかなど感知しないで、単純にセレクタとタグ名のマッチングを行います。何もスタイルが用意されていなければ\n[display: inline がデフォルト](https://drafts.csswg.org/css-display/#the-display-\nproperties)なので、`<span>` と同じように表示されます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T02:10:10.050", "id": "68093", "last_activity_date": "2020-06-29T02:10:10.050", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3475", "parent_id": "68062", "post_type": "answer", "score": 0 } ]
68062
68093
68065
{ "accepted_answer_id": null, "answer_count": 0, "body": "フリーハンド描画実装に関して、 canvas と svg の違いはありますか? \nそれぞれ長所と短所があれば知りたいです。\n\n**質問経緯** \nWebブラウザで動作するフリーハンド描画ツールを作成しようと思い、色々調べています。 \n当初はcanvasでしか作成できないと思っていたのですが、 svg で作成している人もいることに気が付きました。\n\n両者を比較した上で何れかを選択したいのですが、その指針となるような情報があれば知りたいと思い質問しました。 \nフリーハンド描画という機能に関して、canvas でなければできない、あるいは svg でなければできない、ことはありますか?", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-27T23:57:49.497", "favorite_count": 0, "id": "68064", "last_activity_date": "2020-06-28T07:46:39.003", "last_edit_date": "2020-06-28T07:46:39.003", "last_editor_user_id": "3060", "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "svg", "html5-canvas" ], "title": "フリーハンド描画実装に関する canvas と svg の違いは?", "view_count": 180 }
[]
68064
null
null
{ "accepted_answer_id": "68071", "answer_count": 1, "body": "githubの[insights][Traffic]で \nUnique visitors:3 \nUnique cloners:18 \nとなっています。 \nvisitしてcloneする理解ですが、Unique visitors >= Unique clonersとならないのは何故ですか?\n\nあと皆さんの経験則で構わないのですが、visitorsもclonersも公開後数日だけあって1週間もたつとcloneもvisitも0になってしまいました。そんなものですか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T02:25:37.537", "favorite_count": 0, "id": "68066", "last_activity_date": "2020-06-28T03:59:02.057", "last_edit_date": "2020-06-28T02:35:10.023", "last_editor_user_id": "37284", "owner_user_id": "37284", "post_type": "question", "score": 0, "tags": [ "github" ], "title": "githubの[insights][Traffic]でvisitorsがclonersより少ないのはなぜ?", "view_count": 1396 }
[ { "body": "この記事が該当するでしょう。\n\n誰かがリポジトリの訪問者にカウントされずにgithubリポジトリを複製できますか? \n[Can someone clone your github repository without being counted in the\nvisitors of the repository?](https://stackoverflow.com/q/55515001/9014308) \n問:\n\n> My GitHub repository shows that it's been cloned 7 times by 4 different\n> users, but it shows that there's only 1 unique visitor to the same\n> repository. How come that's possible?\n>\n>\n> 私のGitHubリポジトリは、4人の異なるユーザーによって7回クローンされていることを示していますが、同じリポジトリへの一意の訪問者が1人だけであることを示しています。\n> なぜそれが可能になるのですか?\n\n答:\n\n> Visitors are people who visit your github page. Clones are when people do\n> `git clone`, which doesn't involve visiting the site at all.\n>\n> 訪問者とは、githubページにアクセスする人です。 クローンは、人々が`git\n> clone`を行う場合で、サイトにアクセスする必要はまったくありません。\n\n* * *\n\nTrafficの推移は、まあそんなものではないでしょうか?\n\n旬な話題に沿っているとか、緊急の要件とか、メンバーの多い何某かのグループで宣伝されたり、内容に突っ込みどころが多かったりなどの事情があるかどうかでしょうね。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T03:41:19.810", "id": "68071", "last_activity_date": "2020-06-28T03:59:02.057", "last_edit_date": "2020-06-28T03:59:02.057", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "68066", "post_type": "answer", "score": 1 } ]
68066
68071
68071
{ "accepted_answer_id": "68069", "answer_count": 2, "body": "初歩的な質問で失礼します。 \n現在ホームページを作成中で、リンクの付け方で躓いております。\n\nホームページの階層は以下の通りです。`index.html` から `activitysummary.html` にリンクしたいです。\n\n```\n\n Lectureフォルダ\n ∟index.html\n ∟activitysummary.html\n ∟cssフォルダ\n ∟imagesフォルダ\n \n```\n\nHTML リンク部分抜粋\n\n```\n\n <nav>\n <ul>\n <li><a href=\"./activitysummary.html\"></a>活動概要</li>\n </ul>\n </nav>\n \n```\n\n一見合ってるように見えますが、何がおかしいのでしょうか。ドメインを取らないと画面遷移できないとかありますでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T02:30:04.473", "favorite_count": 0, "id": "68068", "last_activity_date": "2020-06-28T07:45:36.420", "last_edit_date": "2020-06-28T07:45:36.420", "last_editor_user_id": "3060", "owner_user_id": "39728", "post_type": "question", "score": 1, "tags": [ "html" ], "title": "アンカーリンクで別のページに移動できない", "view_count": 211 }
[ { "body": "```\n\n <nav>\n <ul>\n <li><a href=\"activitysummary.html\">活動概要</a></li>\n </ul>\n </nav>\n \n```\n\nとしてみてください。\n\n質問に書かれたHTMLでは、タグとタグに挟まれた部分が無いので、リンクが表示されません(無いものは表示できないですから)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T03:20:15.570", "id": "68069", "last_activity_date": "2020-06-28T03:20:15.570", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "68068", "post_type": "answer", "score": 3 }, { "body": "```\n\n <nav>\n <ul>\n <li><a href=\"activitysummary.html\"></a>活動概要</li>\n </ul>\n </nav>\n \n```\n\nでダメですか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T03:20:55.803", "id": "68070", "last_activity_date": "2020-06-28T03:20:55.803", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13152", "parent_id": "68068", "post_type": "answer", "score": -1 } ]
68068
68069
68069
{ "accepted_answer_id": "68086", "answer_count": 2, "body": "BeautifulSoup4でホームページから情報取得をする勉強をしているのですが空白を含んだclassを指定して取得する方法がわかりません。 \n具体例だと \n[https://race.netkeiba.com/race/result.html?race_id=202006010810&rf=race_submenu](https://race.netkeiba.com/race/result.html?race_id=202006010810&rf=race_submenu) \nの【後3F】の部分で、背景に色がついているものは'Time BgYellow'のようになっているので\n\n```\n\n soup.find(class_ = 'Time ')\n \n```\n\nや\n\n```\n\n soup.find(class_ = 'Time.')\n \n```\n\nで取得できるのですが背景に色がついていないものは'Time 'となっており↑の方法では取得できません。 \n何か解決策はありますでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T08:26:41.593", "favorite_count": 0, "id": "68078", "last_activity_date": "2020-06-28T17:14:00.190", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "27760", "post_type": "question", "score": 0, "tags": [ "python", "beautifulsoup" ], "title": "BeautifulSoup4で空白文字を含んだclassの中身を取得したい", "view_count": 1630 }
[ { "body": "本家SOの[類似質問の回答](https://stackoverflow.com/a/46719313)で、[CSS\nselectors](https://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-\nby-css-class)を使う方法が例示されています。\n\nスペース区切りで`Time`を含むクラスが全て取得できます。\n\n**サンプルコード:**\n\n```\n\n from bs4 import BeautifulSoup\n \n html = \"\"\"\n <!DOCTYPE html>\n <html>\n <body>\n <table>\n <tr>\n <td class=\"Time \">35.5</td>\n <td class=\"Time BgOrange\">35.2</td>\n <td class=\"Time\"><span class=\"RaceTime\">1:36.7</span></td>\n <td class=\"NotTime\">36.7</td>\n <td class=\"It is Time\">36.7</td>\n </tr>\n </table>\n </body>\n </html>\n \"\"\"\n \n soup = BeautifulSoup(html, 'html.parser')\n print(soup.select(\"td.Time\"))\n \n```\n\n**出力結果:**\n\n```\n\n [<td class=\"Time\">35.5</td>, <td class=\"Time BgOrange\">35.2</td>, <td class=\"Time\"><span class=\"RaceTime\">1:36.7</span></td>, <td class=\"It is Time\">36.7</td>]\n \n```\n\n`It is Time`クラスがヒットし、`NotTime`クラスはヒットしません。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T10:33:42.307", "id": "68081", "last_activity_date": "2020-06-28T10:33:42.307", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "68078", "post_type": "answer", "score": 0 }, { "body": "@payaneco さんの回答にもありますが、`soup = BeautifulSoup(html,\n'html.parser')`の処理を通した時点でクラス名文字列の後ろに付いた空白は削られています。(おそらく文字列の前に空白が付いていても削られると思われます)\n\nそのため、`BeautifulSoup()`処理後のデータを使った場合は、クラス名など属性文字列の前後に空白が有るか無いかの差で何かを判定することは出来ないでしょう。\n\n質問で紹介されたページの場合、`class=\"Time\"`が指定されたフィールドは他にも多数あるので、クラス名を元に取得したデータが何処のデータかを判定することは困難だと考えられます。\n\n抽出したデータの場所や内容にかかわらず`class=\"Time\"`のデータを集めているならば、@payaneco さん回答の方法で大丈夫でしょう。\n\nそうでなくて、「後3F」の列のデータを取得したい場合は、他の方法を探すことになります。 \nその1つがテーブルデータをひと固まりで取り出して、その中から「後3F」の列のデータを取り出す方法です。\n\n以下の記事を参考にしています。 \n[How to extract table column and rows using beatifulsoup\npython](https://stackoverflow.com/q/43603122/9014308)\n\n紹介ページの該当表のidが`All_Result_Table`で、「後3F」の列が0オリジンで11番目となっており、それを基に上記記事を参考に以下のようにプログラムを組んでみます。\n\n```\n\n import requests\n import bs4\n \n url = 'https://race.netkeiba.com/race/result.html?race_id=202006010810&rf=race_submenu'\n res = requests.get(url)\n res.raise_for_status()\n soup = bs4.BeautifulSoup(res.text, \"html.parser\")\n tbody = soup.find_all(id='All_Result_Table')[0].tbody\n \n aft3f = []\n for tr in tbody.find_all('tr'):\n td = tr.find_all('td')[11]\n aft3f.extend([td])\n \n for td in aft3f:\n print(td)\n \n```\n\n結果は以下のようになります。\n\n```\n\n <td class=\"Time BgYellow\">\n 34.4\n </td>\n <td class=\"Time BgBlue02\">\n 34.9\n </td>\n <td class=\"Time\">\n 35.5\n </td>\n <td class=\"Time\">\n 35.3\n </td>\n <td class=\"Time\">\n 35.6\n </td>\n <td class=\"Time BgOrange\">\n 35.2\n </td>\n <td class=\"Time\">\n 35.9\n </td>\n <td class=\"Time\">\n 35.8\n </td>\n <td class=\"Time\">\n 35.8\n </td>\n <td class=\"Time\">\n 35.6\n </td>\n <td class=\"Time\">\n 35.8\n </td>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T17:14:00.190", "id": "68086", "last_activity_date": "2020-06-28T17:14:00.190", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "68078", "post_type": "answer", "score": 1 } ]
68078
68086
68086
{ "accepted_answer_id": null, "answer_count": 1, "body": "表題の件について質問になります。\n\n期間限定のページを運用で回していきたいと思っていて、 \nURL末尾に`?enddate=200731` のようなパラメータをセットして、このパラメータを判別してページの表示期間を \n制御させる方法(記述)をご教示頂けますと幸いです。\n\nこの例で言うと20年8月1日になった時点でページが見れなくなる想定です。\n\nそれか、パラメータに有効期間をセットして、その有効期間を判別してページを出し分ける方法のどちらかの方法が知りたいです。。。\n\n何卒よろしくお願いいたします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T10:20:06.950", "favorite_count": 0, "id": "68079", "last_activity_date": "2022-11-28T07:51:01.067", "last_edit_date": "2020-06-28T11:20:23.290", "last_editor_user_id": "2376", "owner_user_id": "40848", "post_type": "question", "score": 0, "tags": [ "javascript" ], "title": "URLのパラメータを判別して期間限定のページを出し分ける方法", "view_count": 139 }
[ { "body": "とりあえずパラメータを探し出してYYYYMMDDの形式に直してみましょう。以下がそのコードです。\n\n```\n\n if (0 != document.location.search) { //パラメータの存在の確認\n var parameter = document.location.search.substring(1).split('&');//パラメータを取得した後?を取り除いて&で区切ったリスト\n for (var i = 0; i < parameter.length; i++) { //リストの要素の数(=パラメータの数)を取得しその回数分繰り返す\n var parameta_sub = parameter[i].split('='); //それぞれのパラメータを名前と値で分離\n if (parameta_sub[0] == 'enddate') { //パラメータの名前がenddateだった場合のみ実行\n console.log('20'+parameta_sub[1]); //YYMMDD形式なので20を追加しYYYYMMDD形式にし出力(このコードだと2000年~2099年しか使えませんが実用十分かと思います。)\n }\n }\n }else {\n console.log(null); //パラメータが存在しなかった際にnullを出力\n }\n \n```\n\nこの後は詳細が記されていないのでよくわかりませんがif文で分岐を入れてあげればいいと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2022-11-28T07:51:01.067", "id": "92475", "last_activity_date": "2022-11-28T07:51:01.067", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "54864", "parent_id": "68079", "post_type": "answer", "score": 0 } ]
68079
null
92475
{ "accepted_answer_id": "68092", "answer_count": 1, "body": "Pythonで制作したプログラムをelectronでパッケージ化して配布できるようにしたいです。\n\nただネットの記事を見ると配布先のPCにPythonやモジュールがインストールされていないと使用できないと書いてあります。\n\n一般の方でも簡単にインストールできるような感じにしたいのですが、electronアプリ内にPythonも最初から入っている状態で配布する事は可能なのでしょうか? \nもしくは展開時にPythonを自動的にインストールできる形にできたりする事は可能ですか? \nできるだけ、配布先の環境を汚さない形にしたいです。\n\neel pyinstallerを組み合わせてPythonコードをバイナリファイルにする方法もあるみたいですが、そんなことが可能なのか気になります。 \n<https://qiita.com/inoory/items/f431c581332c8d500a3b>", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-28T10:57:12.087", "favorite_count": 0, "id": "68082", "last_activity_date": "2020-06-29T03:18:41.500", "last_edit_date": "2020-06-29T03:18:41.500", "last_editor_user_id": "22565", "owner_user_id": "22565", "post_type": "question", "score": 0, "tags": [ "python", "python3", "flask", "electron" ], "title": "Python のインストールされていない環境向けに Python プログラムを配布するには?", "view_count": 1873 }
[ { "body": "コメントで紹介した記事3つで出来ているようです。だいたい2種類の方法になるでしょう。\n\n**virtualenvで分離独立したPython環境を作成し、そのフォルダ全体を配布する** \n[How can I bundle Python 3.x to my Electron App that uses\nReactJs?](https://stackoverflow.com/q/57924218/9014308)\n\n> You can bundle everthing using.\n> [Innosetup](http://www.jrsoftware.org/isinfo.php). \n> You can use [Standalone - Portable\n> Winpython](https://winpython.github.io/).\n\n回答が承認済みになっているので、上記で解決したものと思われます。 \n`Portable\nWinpython`のリンク先を読むと、おそらく`virtualenv`で1つのフォルダ配下に分離独立したPython環境を作成しているものと思われます。 \n色々と使い勝手が良くなるようにサポートするプログラムも同梱されているようですが。 \nそしてそれ全体とElectron Applicationを`Innosetup`でまとめてインストーラにしているのでしょう。\n\n* * *\n\n**PythonプログラムをPyInstallerでコマンド化してElectron Applicationに含める** \n[fyears/electron-python-example](https://github.com/fyears/electron-python-\nexample) \n[Electron +\nPythonでクロスプラットフォーム開発](https://evekatsu.github.io/news/Electron%20+%20Python%E3%81%A7%E3%82%AF%E3%83%AD%E3%82%B9%E3%83%97%E3%83%A9%E3%83%83%E3%83%88%E3%83%95%E3%82%A9%E3%83%BC%E3%83%A0%E9%96%8B%E7%99%BA.html)\n\n偶々なのかどちらかが相手を参考にしたのか、`ZeroMQ(zerorpc)`という仕組みでElectron\nApplicationとPythonプログラムが通信・連携しているようです。 \nただしそれは今回の質問とは直接は関係無くて、肝となるのはPythonプログラムをPyInstallerでコマンド化している部分でしょう。 \nどうも結局こちらも`virtualenv`を使っているようですが、それは`ZeroMQ`がPython\n2.7で動作し、Pythonアプリは3.xで作りたいからのようです。 \nこちらはElectronでPython部分もあわせてパッケージ化していますね。\n\n* * *\n\n探せばもっと別の方法や上記の中でも組み合わせを変えるとかあるでしょうが、類似の内容のバリエーションになりそうです。\n\n出来上がるPythonプログラムや配布するファイルのサイズや数の多寡と、使えるPythonの版数の問題といったもののトレードオフになるでしょう。 \n(PyInstallerは今のところ3.8では使えない(公式には3.6,実績で3.7?):cx_Freezeの最新版は3.8が使えるよう)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T01:49:33.383", "id": "68092", "last_activity_date": "2020-06-29T01:49:33.383", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "68082", "post_type": "answer", "score": 1 } ]
68082
68092
68092
{ "accepted_answer_id": null, "answer_count": 0, "body": "lambdaで使っているbatchwriterのエラーの原因が解りません。\n\n前回の質問で使った以下のテンプレート \n<https://raw.githubusercontent.com/aws-samples/csv-to-\ndynamodb/master/CloudFormation/CSVToDynamo.template>\n\nこのテンプレートで作られたs3バケットにcsvをアップすると \ndynamodbに内容がインポートされるはずなのですが\n\nどうも、s3へのアップをトリガーにしてdynamodbインポートする役割を果たす \nlambdaがうまく機能していないようです。\n\nlambdaからはエラーは見えず、cloudwatchを辿ると以下のようなエラーが出ています。 \n[![画像の説明をここに入力](https://i.stack.imgur.com/66z7X.jpg)](https://i.stack.imgur.com/66z7X.jpg)\n\nこれはプログラムで用意したprint文なので \nエラーが出る具体的な原因が解りません。 \n具体的なエラー原因を知るにはどうすればよいのでしょうか?\n\n仮説として以下が上げられます \n・フォーマット表記が合わない \n・ロール権限が正しく付与されていない\n\nできればテンプレートをこのようにしたいです \n・どんなファイル名でもcsv・jsonなら読めるようにする \n・既存のテーブルバケットを使う", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T00:16:01.817", "favorite_count": 0, "id": "68090", "last_activity_date": "2020-06-29T00:16:01.817", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "39754", "post_type": "question", "score": 1, "tags": [ "aws", "amazon-s3", "aws-lambda", "aws-iam", "aws-cloudformation" ], "title": "lambdaで使っているbatchwriterのエラーの原因が解りません。", "view_count": 69 }
[]
68090
null
null
{ "accepted_answer_id": "68104", "answer_count": 2, "body": "最大公約数を返す関数を下記のように書いたのですが、テストデータに通したところ \n\"Wrong Answer\" となってしまいます。 \n書き方に欠陥があると考えていますがどこが悪いのか見当たりません。 \nどなたか教えていただけると幸いです。\n\n制約は 1 ≤ x, y ≤ 10^9 で、具体的にどのケースで誤判定したかは競技プログラミングの判定サイトを用いたため不明です。\n\n**現状のソースコード:**\n\n```\n\n def GCD(x, y):\n if x > y:\n x, y = y, x\n if x == 0 or y == 0:\n return 0\n else:\n rem = y % x\n if rem == 0:\n return x\n else:\n return GCD(rem, x)\n \n x,y = map(int,input().split())\n GCD(x, y)\n \n```", "comment_count": 6, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T02:29:37.763", "favorite_count": 0, "id": "68094", "last_activity_date": "2020-06-29T16:52:02.870", "last_edit_date": "2020-06-29T16:52:02.870", "last_editor_user_id": "3060", "owner_user_id": "36869", "post_type": "question", "score": 0, "tags": [ "python", "python3" ], "title": "2つのintの入力の最大公約数を返す関数を作成したところ、きちんと機能していない(WA)原因が分からない", "view_count": 216 }
[ { "body": "一応思いついたのが、引数に0を与えたときに0割が発生している、とかでしょうか。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T05:18:42.710", "id": "68100", "last_activity_date": "2020-06-29T05:18:42.710", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18637", "parent_id": "68094", "post_type": "answer", "score": 1 }, { "body": "もしそのコードをそのまま提出してるのでしたら、単純に最大公約数を出力し忘れてるだけです", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T06:32:22.967", "id": "68104", "last_activity_date": "2020-06-29T06:32:22.967", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "33033", "parent_id": "68094", "post_type": "answer", "score": 4 } ]
68094
68104
68104
{ "accepted_answer_id": null, "answer_count": 0, "body": "使用OS: Windows 10\n\n<https://dev.classmethod.jp/articles/first-login-to-ec2-linux/> \n<https://dev.classmethod.jp/articles/aws-beginner-ec2-ssh/>\n\n上記の2リンクを参考にして、EC2へのSSH接続を試みましたが、失敗してしまいます。\n\nエラーメッセージ(TeraTermの)は「認証に失敗しました。」なので、1つ目のリンク先の末尾にある「認証に失敗している」の内容が該当しそうです。 \n(ちなみに「ネットワーク的に通信できない」にある、「EC2のパブリックIP/パブリックDNS名が間違っている」や「セキュリティグループで通信が許可されていない」などは、EC2のインスタンスとセキュリティグループ設定を確認しましたが該当しなさそうです。\n\n一体何が原因なのでしょうか。\n\n(Amazon\nLinuxのため初期ユーザ名はec2-userです。秘密鍵についてはインスタンス作成時の.pemファイルを適用しており、自分のPC上に1つしかないため間違ってることは考えにくいです。)", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T03:58:05.847", "favorite_count": 0, "id": "68096", "last_activity_date": "2020-06-29T04:25:03.010", "last_edit_date": "2020-06-29T04:25:03.010", "last_editor_user_id": "3060", "owner_user_id": "39812", "post_type": "question", "score": 0, "tags": [ "aws", "ssh" ], "title": "AWS EC2のSSH接続に失敗する", "view_count": 2207 }
[]
68096
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "SJISで書かれたものをxmlファイルへ書き出すというバッチファイルを作っています。\n\nSJISに取り込みをしてXMLファイルで確認すると日本語表記が文字化けしたり、文字がないというエラーが発生します。\n\n例 \nSJIS(例AAA.TXT)\n\n```\n\n 1,パンダ\n 2,羊\n ・・・\n \n```\n\nXML(AAAXML)\n\n```\n\n <?xml version=\"1.0\" encoding=\"UTF-8\"?> \n <Code Code=\"1\" content=\" \n \n```\n\nとなります。\n\nおそらくファイル中にutf-8が入っているのにもかかわらず \nSJISを使っているのでIE等でみると文字がなくなってしまうのかと思われますが \nSJISを取り込みはSJISでも保存するときに、UTF-8に変換して保存できないでしょうか? \nよろしくお願いいたします。\n\n簡単な取り込み文は \nfor /f %%a in (AAA.TXT) do ( ECHO %%a>>AAA.XML ) です。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T04:48:56.093", "favorite_count": 0, "id": "68097", "last_activity_date": "2021-10-04T20:07:15.707", "last_edit_date": "2020-06-29T05:34:32.580", "last_editor_user_id": "31311", "owner_user_id": "31311", "post_type": "question", "score": 0, "tags": [ "batch-file" ], "title": "バッチファイル読み込み時、出力ファイルが文字化けする", "view_count": 3370 }
[ { "body": "バッチファイルの実行環境(CMD.EXEとその関連のWindows標準コマンド)では、1行のコマンド/スクリプトの中で入力ファイル文字コード、作業変数、出力ファイル文字コードを別々に指定して、しかもそれをUTF-8にすることはまず出来ないでしょう。\n\n以下のいずれか、あるいはそのバリエーションで対処するのが良いと思われます。\n\n * XMLファイルにするまでの処理は、いったんすべてシフトJISで行い、その後 nkf, iconv, その他何かのスクリプトやコマンドでUTF-8に変換する\n * PowerShellやPython等の、入力文字コード/出力文字コードを別々に指定できるスクリプトツールやコマンドで処理を構築する", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T11:09:51.817", "id": "68112", "last_activity_date": "2020-06-29T11:09:51.817", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "68097", "post_type": "answer", "score": 1 } ]
68097
null
68112
{ "accepted_answer_id": "68120", "answer_count": 4, "body": "以下のSwiftコードのネストを浅くしたいのですが、いい案はないでしょうか?\n\n```\n\n task = URLSession.shared.dataTask(with: URL(string: url)!) { (data, res, err) in\n if let obj = try! JSONSerialization.jsonObject(with: data!) as? [String: Any] {\n if let items = obj[\"items\"] as? [[String: Any]] {\n self.repo = items\n DispatchQueue.main.async {\n self.tableView.reloadData()\n }\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T05:02:21.613", "favorite_count": 0, "id": "68098", "last_activity_date": "2020-06-30T08:21:50.267", "last_edit_date": "2020-06-29T08:17:35.087", "last_editor_user_id": "3060", "owner_user_id": "40856", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "Swiftのネストを浅くしたい", "view_count": 347 }
[ { "body": "一つネストを減らせました。\n\n参考:[Swift 1.2のif\nlet複数宣言と例外処理](https://qiita.com/boohbah/items/84e9d76a8ceaf9f56077)\n\n```\n\n task = URLSession.shared.dataTask(with: URL(string: url)!) { (data, res, err) in\n if let obj = try! JSONSerialization.jsonObject(with: data!) as? [String: Any],\n let items = obj[\"items\"] as? [[String: Any]] {\n self.repo = items\n DispatchQueue.main.async {\n self.tableView.reloadData()\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T05:12:11.327", "id": "68099", "last_activity_date": "2020-06-29T05:12:11.327", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40856", "parent_id": "68098", "post_type": "answer", "score": 0 }, { "body": "ネストを減らすと言う意味では、guard文の採用も検討された方が良いでしょう。\n\n```\n\n task = URLSession.shared.dataTask(with: URL(string: url)!) { (data, res, err) in\n guard let obj = try! JSONSerialization.jsonObject(with: data!) as? [String: Any],\n let items = obj[\"items\"] as? [[String: Any]]\n else {\n print(\"bad data\")\n return\n }\n self.repo = items\n DispatchQueue.main.async {\n self.tableView.reloadData()\n }\n }\n \n```\n\n* * *\n\nなお、コード例の中で`try!`を使用していますが、`JSONSerialization.jsonObject(with:)`は、入力となるデータに1バイトでもおかしな点があれば簡単に失敗するので、`try!`を使用するとそこでアプリがクラッシュしてしまいます。「強制tryは確実に安全と分かっている場合以外は使ってはいけない」と覚えておいた方が良いと思います。\n\n別質問とも関わりますが、その他の危険な強制アンラップも全部避け、エラーチェックもきちんとやるとこんな感じになります。「ネストを減らす」と言うご質問の趣旨からは外れることになりますが、`URLSession`は様々な理由でエラー終了しますので、(今は練習用のコードなのかもしれませんが、例えそうだとしても)必要なエラー処理を省略すべきではありません。\n\n```\n\n guard let theUrl = URL(string: url) else {\n print(\"bad URL string\")\n return\n }\n task = URLSession.shared.dataTask(with: theUrl) { (data, res, err) in\n do {\n if let error = err {\n throw error\n }\n guard let data = data else {\n print(\"data is nil\")\n throw MyError.dataNil\n }\n guard let obj = try JSONSerialization.jsonObject(with: data) as? [String: Any],\n let items = obj[\"items\"] as? [[String: Any]]\n else {\n throw MyError.badData\n }\n self.repo = items\n DispatchQueue.main.async {\n self.tableView.reloadData()\n }\n } catch {\n print(error)\n //必要であればエラー時の処理を追加\n }\n }\n \n```\n\n(どこかにこんなものを定義してある前提のコードです。)\n\n```\n\n enum MyError: Error {\n case dataNil\n case badData\n }\n \n```", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T07:40:55.010", "id": "68107", "last_activity_date": "2020-06-29T16:50:08.917", "last_edit_date": "2020-06-29T16:50:08.917", "last_editor_user_id": "3060", "owner_user_id": "13972", "parent_id": "68098", "post_type": "answer", "score": 1 }, { "body": "はじめまして、`URLSession`で非同期なので、タイミングによっては`self`が解放されている可能性まで考えてのコードです。 \n`guard`文の多用になってあまりすっきりはしていないかも知れませんが、あえて `guard let a = b, let c =\nd`の様な一つのguard文で複数のチェックを行う事は今回は避けています。 \nエラー処理の構文まで含めると1ネスト減らすことが出来ていて、 \nロジック自体は2ネスト減らすことができそうです。\n\n```\n\n guard let url: URL = URL(string: url) else {\n print(\"URL not constructed\")\n return\n }\n task = URLSession.shared.dataTask(with: url) { [weak self] (data, res, err) in\n guard let weakSelf = self else {\n print(\"self already deallocated\")\n return\n }\n guard let jsonData: Data = data else {\n print(\"received data not exist\"\n return\n }\n guard let obj = try? JSONSerialization.jsonObject(with: data!) as? [String: Any] {\n print(\"JSON Serialization failed\")\n return\n }\n guard let items = obj[\"items\"] as? [[String: Any]] else {\n print(\"items is not much type\")\n return\n }\n weakSelf.repo = items\n DispatchQueue.main.async { [weak self] in\n guard let weakSelf = self else {\n print(\"self is already deallocated\")\n return\n }\n weakSelf.tableView.reloadData()\n }\n }\n \n```\n\n`try!`は続くメソッドや関数が例外を発生させた時にエラーでアプリケーションそのものが終了してしまうため、`try?`というエラーが起きた時は`nil`を返す`try`に書き替えてあります。 \nこれにより、`obj`というローカル変数はそれ以降必ずあることが保証されるので、`guard`文によるアンラップチェックを多用してデーターが十全であることをアンラップが必要な度にしつこいほど確認・保証する作りになっています。これによりなにをアンラップした時にエラーになったか?、が続く処理ですぐにかけるので、エラーの発生箇所と対処箇所がすぐ近くに書けるのもメリットの一つだと思います\n\nまた、`URLSession`にデーターをリクエストしているので、指定したURLからデーターが帰ってきた時には、呼び出したクラスが解放しようとした後かも知れない場合も考慮し、クロージャーの先頭に \n`[weak self] (引数があればここに書く) in`という「このブロックの中では`self`を弱参照してメモリーリークを防ぐ」と共に、 \n`guard let weakSelf = self else { return }` \nという一文で弱参照している`self`が解放されていない(nilでない)ことも確認しています。\n\nコード全体のネストは一段しか減らせていないですが、オプショナル型のアンラップ時の`nil`によるアプリのクラッシュを可能な限り防ぐ方向に振っています。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T17:37:02.593", "id": "68120", "last_activity_date": "2020-06-29T17:37:02.593", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "14745", "parent_id": "68098", "post_type": "answer", "score": 1 }, { "body": "回答してくださったのを統合した感じでコーディングしてみました。\n\nそしてErrorに関するMyError.swiftのファイルを別に作りました。\n\n## わかったこと\n\n * try?文は基本「guard else」とセットで使うこと\n * Error処理をちゃんとすること\n * \n\n```\n\n guard let url: URL = URL(string: url) else {\n print(\"URL not constructed\")\n return\n }\n \n task = URLSession.shared.dataTask(with: url) { [weak self] (data, res, err) in\n do {\n if let error = err {\n throw error\n }\n \n guard let weakSelf = self else {\n print(\"self already deallocated\")\n return\n }\n \n guard let jsonData = data else {\n print(\"data is nil\")\n throw MyError.dataNil\n }\n guard let obj = try? JSONSerialization.jsonObject(with: jsonData) as? [String: Any] else {\n print(\"JSON Serialization failed\")\n throw MyError.badData\n }\n \n guard let items = obj[\"items\"] as? [[String: Any]] else {\n print(\"items is not much type\")\n        throw MyError.badData\n }\n weakSelf.repo = items\n DispatchQueue.main.async { [weak self] in\n guard let weakSelf = self else {\n print(\"self is already deallocated\")\n return\n }\n weakSelf.tableView.reloadData()\n }\n }catch {\n print(error)\n }\n }\n \n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T08:13:49.103", "id": "68139", "last_activity_date": "2020-06-30T08:21:50.267", "last_edit_date": "2020-06-30T08:21:50.267", "last_editor_user_id": "40856", "owner_user_id": "40856", "parent_id": "68098", "post_type": "answer", "score": 0 } ]
68098
68120
68107
{ "accepted_answer_id": "68106", "answer_count": 1, "body": "コードの危険な部分をなくという問題で、Swiftの強制アンラップを解消したいのですが、どのように解消すれば良いのでしょうか? \n例をあげれなくてすいません。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T06:09:27.313", "favorite_count": 0, "id": "68102", "last_activity_date": "2020-06-29T07:11:14.910", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40856", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "Swiftの強制アンラップの解消方法", "view_count": 125 }
[ { "body": "ざっくり、次の3つを使い分けるのが、基本です。\n\n 1. Optional Chaining\n 2. Optional Binding\n 3. Nil-coalescing operator\n\n* * *\n\n_質問者さんの反応に応じて、それぞれの項目について、解説を書き加えていく用意があります。随時、コメント欄にリクエストをください。_", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T07:11:14.910", "id": "68106", "last_activity_date": "2020-06-29T07:11:14.910", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18540", "parent_id": "68102", "post_type": "answer", "score": 1 } ]
68102
68106
68106
{ "accepted_answer_id": "68113", "answer_count": 2, "body": "C#のJsonデータのデシリアライズについての質問となります。 \n連番された項目名のオブジェクトをListにしてデシリアライズする良い方法がないか、調査中です。 \n良い方法があれば、ご教授して頂ければと思います。\n\n**前提** \n例えば、これまでは下記のような一部が配列となるjsonを処理する必要があり、\n\n```\n\n {\n \"textData\": \"textVal\",\n \"numData\" : 123,\n \"objData\": [\n {\n \"hogeText\": \"hogeTextVal1\",\n \"hogeNum\" : 1,\n \"hogeobj\": {\n \"hoge\": \"hogeVal1\",\n \"hage\": \"hageVal1\"\n }\n },\n {\n \"hogeText\": \"hogeTextVal2\",\n \"hogeNum\" : 2,\n \"hogeobj\": {\n \"hoge\": \"hogeVal2\",\n \"hage\": \"hageVal2\"\n }\n },\n {\n \"hogeText\": \"hogeTextVal3\",\n \"hogeNum\" : 3,\n \"hogeobj\": {\n \"hoge\": \"hogeVal3\",\n \"hage\": \"hageVal3\"\n }\n }\n ]\n }\n \n```\n\n下記Entityクラスを準備して、「JsonSerializer.Deserialize(json);」(namespace:\nSystem.Text.Json)でデシリアライズを行っていました。 \n※課題が解決できれば、デシリアライズの方法にこだわりはありません。\n\n```\n\n public class entity\n {\n public class Root\n {\n public string textData { get; set; }\n \n public long numData { get; set; }\n \n public ObjDatum[] objData { get; set; }\n }\n \n public class ObjDatum\n {\n public string hogeText { get; set; }\n \n public long hogeNum { get; set; }\n \n public Hogeobj hogeobj { get; set; }\n }\n \n public class Hogeobj\n {\n public string hoge { get; set; }\n \n public string hage { get; set; }\n }\n }\n \n```\n\n**質問** \n前提のような一部配列のjsonではなく、下記のようにオブジェクト名が連番で変動するデータの場合、前提と同様にデシリアライズ時にListにする方法はありますか。 \n(前提の配列objData部が、objData1、objData2、objData3...ようになる)\n\n```\n\n {\n \"textData\": \"textVal\",\n \"numData\" : 123,\n \"objData1\": {\n \"hogeText\": \"hogeTextVal1\",\n \"hogeNum\" : 1,\n \"hogeobj1\": {\n \"hoge\": \"hogeVal1\",\n \"hage\": \"hageVal1\"\n }\n },\n \"objData2\": {\n \"hogeText\": \"hogeTextVal2\",\n \"hogeNum\" : 2,\n \"hogeobj2\": {\n \"hoge\": \"hogeVal2\",\n \"hage\": \"hageVal2\"\n }\n },\n \"objData3\": {\n \"hogeText\": \"hogeTextVal3\",\n \"hogeNum\" : 3,\n \"hogeobj3\": {\n \"hoge\": \"hogeVal3\",\n \"hage\": \"hageVal3\"\n }\n }\n }\n \n```\n\n実際には3つだけではなく、数10、数100というobjDataがあるため、1つずつクラスを作成する方法は避けたいと思っています。 \nまた、ネストされたhogeobjも連番で項目名が変動いたします。デシリアライズされた後にListをさらに処理・加工するため、プロパティ名は揃っていて欲しいです。\n\n以上、よろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T06:31:46.940", "favorite_count": 0, "id": "68103", "last_activity_date": "2020-06-29T23:41:41.773", "last_edit_date": "2020-06-29T11:27:34.217", "last_editor_user_id": "3060", "owner_user_id": "40858", "post_type": "question", "score": 1, "tags": [ "c#", ".net", "json" ], "title": "C#(.net)のjsonデータのデシリアライズについて", "view_count": 3019 }
[ { "body": "構成が複雑なので、ある程度ゴリ押しのコードで達成することになると予想しています。 \n私が思いついた方法は以下の2つです。\n\n 1. [JsonDocument](https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsondocument?view=netcore-3.0)でネストを深掘りする方法\n\n * サンプルコードの`ParseElephant`メソッドです\n\n 2. [JsonExtensionDataAttribute](https://docs.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonextensiondataattribute?view=netcore-3.0)である程度動的に値を取得する方法\n\n * サンプルコードの`ParseClass`メソッドです\n\nJson内部で入れ子になっているJsonを[JsonConverter](https://docs.microsoft.com/en-\nus/dotnet/api/system.text.json.serialization.jsonconverter?view=netcore-3.0)でカスタム変換できれば良かったのですが、動的な名称の項目に適用する方法が見つかりませんでした。\n\n**サンプルコード**\n\n```\n\n using System;\n using System.Collections.Generic;\n using System.Linq;\n using System.Text.Json;\n using System.Text.Json.Serialization;\n \n namespace ConsoleApp1\n {\n class Program\n {\n static void Main(string[] args)\n {\n ParseElephant();\n ParseClass();\n }\n \n /// <summary>\n /// JsonDocumentを使いながらJsonを深掘りしてプロパティを補完する手法\n /// </summary>\n private static void ParseElephant()\n {\n // objData 以外をざっくり作成\n Root root = JsonSerializer.Deserialize<Root>(JSON_TEXT);\n var doc = JsonDocument.Parse(JSON_TEXT);\n root.objData = doc.RootElement.EnumerateObject()\n .Where(x => x.Name.StartsWith(\"objData\")) // Jsonキーが \"objData\" から始まるもの\n .Select(elm =>\n {\n // Rootと同様に hogeobj 以外をざっくり作成\n ObjDatum objDatum = JsonSerializer.Deserialize<ObjDatum>(elm.Value.GetRawText());\n // 上のLinqと同様の深掘り手法\n using var hogeDoc = JsonDocument.Parse(elm.Value.GetRawText());\n var prop = hogeDoc.RootElement.EnumerateObject()\n .First(x => x.Name.StartsWith(\"hogeobj\")); // Jsonキーが \"hogeobj\" から始まるもの\n objDatum.hogeobj = JsonSerializer.Deserialize<Hogeobj>(prop.Value.GetRawText());\n return objDatum;\n })\n .ToList();\n Console.WriteLine(JsonSerializer.Serialize<Root>(root));\n }\n \n /// <summary>\n /// クラスメソッドからJsonSerializerを呼び出してプロパティを補完する手法\n /// </summary>\n private static void ParseClass()\n {\n using var doc = JsonDocument.Parse(JSON_TEXT);\n var root = JsonSerializer.Deserialize<Root2>(JSON_TEXT);\n //プロパティは正しく取れる\n Console.WriteLine(root.ObjData[0].hogeobj.hoge);\n //シリアライズすると求めるフォーマットから離れる\n Console.WriteLine(JsonSerializer.Serialize<Root2>(root));\n }\n \n const string JSON_TEXT = @\"{\n \"\"textData\"\": \"\"textVal\"\",\n \"\"numData\"\" : 123,\n \"\"objData1\"\": {\n \"\"hogeText\"\": \"\"hogeTextVal1\"\",\n \"\"hogeNum\"\" : 1,\n \"\"hogeobj1\"\": {\n \"\"hoge\"\": \"\"hogeVal1\"\",\n \"\"hage\"\": \"\"hageVal1\"\" \n }\n },\n \"\"objData2\"\": {\n \"\"hogeText\"\": \"\"hogeTextVal2\"\",\n \"\"hogeNum\"\" : 2,\n \"\"hogeobj2\"\": {\n \"\"hoge\"\": \"\"hogeVal2\"\",\n \"\"hage\"\": \"\"hageVal2\"\" \n }\n },\n \"\"objData3\"\": {\n \"\"hogeText\"\": \"\"hogeTextVal3\"\",\n \"\"hogeNum\"\" : 3,\n \"\"hogeobj3\"\": {\n \"\"hoge\"\": \"\"hogeVal3\"\",\n \"\"hage\"\": \"\"hageVal3\"\" \n }\n }\n }\";\n }\n \n public class Root\n {\n public string textData { get; set; }\n \n public long numData { get; set; }\n \n public List<ObjDatum> objData { get; set; }\n }\n \n public class ObjDatum\n {\n public string hogeText { get; set; }\n \n public long hogeNum { get; set; }\n \n public Hogeobj hogeobj { get; set; }\n }\n \n public class Hogeobj\n {\n public string hoge { get; set; }\n \n public string hage { get; set; }\n }\n \n public class Root2\n {\n [JsonPropertyName(\"textData\")]\n public string TextData { get; set; }\n \n [JsonPropertyName(\"numData\")]\n public long NumData { get; set; }\n \n [JsonIgnoreAttribute]\n public List<ObjDatum2> ObjData\n {\n get\n {\n return ExtensionData.Values\n .Select(v => JsonSerializer.Deserialize<ObjDatum2>(v.GetRawText())).ToList();\n }\n }\n \n [JsonExtensionDataAttribute]\n public IDictionary<string, JsonElement> ExtensionData { get; set; }\n }\n \n public class ObjDatum2\n {\n public string hogeText { get; set; }\n \n public long hogeNum { get; set; }\n \n [JsonIgnoreAttribute]\n public Hogeobj hogeobj\n {\n get\n {\n return JsonSerializer.Deserialize<Hogeobj>(ExtensionData.Values.First().GetRawText());\n }\n }\n \n [JsonExtensionDataAttribute]\n public IDictionary<string, JsonElement> ExtensionData { get; set; }\n }\n }\n \n```\n\n**出力結果**\n\n```\n\n {\"textData\":\"textVal\",\"numData\":123,\"objData\":[{\"hogeText\":\"hogeTextVal1\",\"hogeNum\":1,\"hogeobj\":{\"hoge\":\"hogeVal1\",\"hage\":\"hageVal1\"}},{\"hogeText\":\"hogeTextVal2\",\"hogeNum\":2,\"hogeobj\":{\"hoge\":\"hogeVal2\",\"hage\":\"hageVal2\"}},{\"hogeText\":\"hogeTextVal3\",\"hogeNum\":3,\"hogeobj\":{\"hoge\":\"hogeVal3\",\"hage\":\"hageVal3\"}}]}\n hogeVal1\n {\"textData\":\"textVal\",\"numData\":123,\"objData1\":{\"hogeText\":\"hogeTextVal1\",\"hogeNum\":1,\"hogeobj1\":{\"hoge\":\"hogeVal1\",\"hage\":\"hageVal1\"}},\"objData2\":{\"hogeText\":\"hogeTextVal2\",\"hogeNum\":2,\"hogeobj2\":{\"hoge\":\"hogeVal2\",\"hage\":\"hageVal2\"}},\"objData3\":{\"hogeText\":\"hogeTextVal3\",\"hogeNum\":3,\"hogeobj3\":{\"hoge\":\"hogeVal3\",\"hage\":\"hageVal3\"}}}\n \n```\n\n前者の`ParseElephant`は冗長ですが、再度Jsonにシリアライズした時にobjDataはきれいな配列になります。 \n後者の`ParseClass`の方が一見コードはきれいに見えますし、プロパティの値は問題なく取得できますが、Jsonにシリアライズすると動的なキー名称はそのままです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T11:23:47.240", "id": "68113", "last_activity_date": "2020-06-29T23:41:41.773", "last_edit_date": "2020-06-29T23:41:41.773", "last_editor_user_id": "9820", "owner_user_id": "9820", "parent_id": "68103", "post_type": "answer", "score": 0 }, { "body": "payanecoさんもおっしゃっている通りスッキリした書き方はできませんね。\n\n[オーバーフロー JSON の処理](https://docs.microsoft.com/ja-\njp/dotnet/standard/serialization/system-text-json-how-to#handle-overflow-\njson)という機能を使うと対応するプロパティのない要素を`Dictionary`として取得することができます。これを利用して、次のようにクラス定義します。\n\n```\n\n public class Root{\n public string textData { get; set; }\n public long numData { get; set; }\n \n [JsonExtensionData]\n public Dictionary<string, JsonElement> ExtensionData { private get; set; }\n \n public Dictionary<string, ObjDatum> objData\n => ExtensionData.ToDictionary(p => p.Key, p => JsonSerializer.Deserialize<ObjDatum>(p.Value.GetRawText()));\n }\n \n public class ObjDatum {\n public string hogeText { get; set; }\n public long hogeNum { get; set; }\n public Hogeobj hogeobj { get; set; }\n }\n \n public class Hogeobj {\n public string hoge { get; set; }\n public string hage { get; set; }\n }\n \n```\n\n`ExtensionData` という不要なプロパティが見えてしまいますが、 `objData` プロパティを参照すると再度デシリアライズして\n`Dictionary<string, ObjDatum>` を得ることができます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T23:12:21.127", "id": "68122", "last_activity_date": "2020-06-29T23:12:21.127", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "68103", "post_type": "answer", "score": 1 } ]
68103
68113
68122
{ "accepted_answer_id": "68108", "answer_count": 1, "body": "Qt(C++)で本体の時刻を変更するというのを試しているのですが \n以下のコードで試したところ、本体の時刻が変更されませんでした \nWindowsで時刻の自動設定や、タイムゾーンの自動設定は外しています \nLinuxでも同様のことをしたいのですが \n本体の時刻の変更は何か別の関数を利用するのでしょうか\n\n```\n\n void MainWindow::on_pushButton_clicked()\n {\n QDate *date = new QDate(2020,6,30); //日付設定\n QTime *tim = new QTime(19,10,50); //時刻設定\n \n qDebug() << \"日:\" << date->toString();\n \n QDateTime *qd = new QDateTime(*date,*tim); //日時を設定//★★★★日時を本体に設定する・・・はずだが反映されない\n qDebug() << \"日時:\" << qd->toString();\n \n QDateTimeEdit *dateTime = new QDateTimeEdit;\n dateTime->setDateTime(*qd); \n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T06:48:46.187", "favorite_count": 0, "id": "68105", "last_activity_date": "2020-06-29T08:04:21.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "15047", "post_type": "question", "score": 0, "tags": [ "c++", "qt" ], "title": "Qtで時刻を設定したい", "view_count": 1167 }
[ { "body": "これらの記事が該当するでしょう。つまり時刻を設定する権限が必要ということですね。\n\n* * *\n\n**Windows:** \n[How to change windows system time in\nQt?](https://stackoverflow.com/q/34249054/9014308) \n問:\n\n> I want to change my system time ,How can I change the Windows system time in\n> Qt? I used this way,but failed! \n> システム時間を変更したいのですが、QtでWindowsシステム時間を変更するにはどうすればよいですか? 私はこの方法を使用しましたが、失敗しました!\n```\n\n> #include <QApplication>\n> #include <iostream>\n> #include <time.h>\n> #include <windows.h>\n> #include <QDateTime>\n> #include <QDebug>\n> using namespace std;\n> bool setDate(int,int,int); \n> int main(int argc, char *argv[])\n> {\n> QApplication a(argc, argv);\n> MainWindow w;\n> w.show();\n> qDebug()<<QDateTime::currentDateTime()<<endl; //before change time\n> if(setDate(2015,1,1)) //set time\n> {\n> qDebug()<<QDateTime::currentDateTime()<<endl; //if succeed,output\n> time\n> } \n> return a.exec();\n> }\n> bool setDate(int year,int mon,int day)\n> {\n> SYSTEMTIME st;\n> GetSystemTime(&st); // Win32 API get time\n> st.wYear=year; //set year\n> st.wMonth=mon; //set month\n> st.wDay=day; //set day\n> \n> return SetSystemTime(&st); //Win32 API set time\n> }\n> \n```\n\n答:\n\n> Changing the system time requires admin rights. That means you need to: \n> システム時刻を変更するには、管理者権限が必要です。 つまり、次のことを行う必要があります。\n>\n> * Add the requireAdministrator option to your manifest so that the program\n> always has admin rights. That's a bad idea and you won't enjoy the UAC\n> dialog every time you start. \n> プログラムが常に管理者権限を持つように、マニフェストにrequireAdministratorオプションを追加します。\n> これは悪い考えであり、開始するたびにUACダイアログを楽しむことはできません。\n>\n> * Or, change the time by starting a separate process that runs as\n> administrator. Another executable with the appropriate manifest, a process\n> started with the runas shell verb, or one started with the COM elevation\n> moniker. \n> または、管理者として実行される別のプロセスを開始して時間を変更します。\n> 適切なマニフェストを持つ別の実行可能ファイル、runasシェル動詞で開始されたプロセス、またはCOM昇格モニカで開始されたプロセス。\n>\n>\n\n>\n> If this is gobbledygook to you, you need to read up on UAC. Start here: \n> これがごちゃごちゃしている場合は、UACを読む必要があります。 ここから始める: \n> <https://msdn.microsoft.com/en-\n> us/library/windows/desktop/dn742497(v=vs.85).aspx>\n\n* * *\n\n**Linux:** \n[Set system clock with QT on\nlinux](https://stackoverflow.com/q/50173637/9014308) \n問:\n\n> How would we go about changing the system time on a linux system\n> programatically using QT widget application ? \n> QTウィジェットアプリケーションを使用して、プログラムでLinuxシステムのシステム時間を変更するにはどうすればよいでしょうか。\n\n答:\n\n> I found a simple solution. As my system is very minimalist i dont want to\n> use things like dbus. As a root or sudoer this can be execute (fairly self\n> explainatory )- \n> 簡単な解決策を見つけました。 私のシステムはとてもミニマリストなので、dbusのようなものを使いたくありません。\n> ルートまたはsudoとしてこれを実行できます(かなり自明)-\n```\n\n> QString string = dateTime.toString(\"\\\"yyyy-MM-dd hh:mm\\\"\");\n> QString dateTimeString (\"date -s \");\n> dateTimeString.append(string);\n> int systemDateTimeStatus= system(dateTimeString.toStdString().c_str());\n> if (systemDateTimeStatus == -1)\n> {\n> qDebug() << \"Failed to change date time\";\n> }\n> int systemHwClockStatus = system(\"/sbin/hwclock -w\");\n> if (systemHwClockStatus == -1 )\n> {\n> qDebug() << \"Failed to sync hardware clock\";\n> }\n> \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T08:04:21.150", "id": "68108", "last_activity_date": "2020-06-29T08:04:21.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "68105", "post_type": "answer", "score": 2 } ]
68105
68108
68108
{ "accepted_answer_id": "68111", "answer_count": 1, "body": "\"WUB\"という文字列をスペースに変えて、解読を行うというプログラムなのですが、\n\n```\n\n song = \"AWUBWUBWUBBWUBWUBWUBC\"\n numbers = [int(i) for i in range(len(song))]\n spaces = []\n words = []\n for i in range(len(song)-3):\n one, two, three = song[i], song[i+1], song[i+2]\n if one == \"W\" and two == \"U\" and three == \"B\":\n numbers.pop(i)\n numbers.pop(i+1)\n numbers.pop(i+2)\n spaces.append(i)\n i += 3\n else:\n i+=1\n for i in range(len(numbers)):\n words.append(song(numbers[i]))\n for k in range(len(spaces)):\n words.insert(spaces[k], \" \")\n ans = ''.join(words)\n print(ans)\n \n```\n\nとしたところ、\n\n```\n\n TypeError Traceback (most recent call last)\n <ipython-input-21-cc5ee7fdeeb7> in <module>()\n 14 i+=1\n 15 for i in range(len(numbers)):\n ---> 16 words.append(song(numbers[i]))\n 17 for k in range(len(spaces)):\n 18 words.insert(spaces[k], \" \")\n \n TypeError: 'str' object is not callable\n \n```\n\nとなってしまいます。 \nintにしているつもりなのですが、どこでstrにすり替わってしまっているのか教えていただけると幸いです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T10:25:41.810", "favorite_count": 0, "id": "68110", "last_activity_date": "2020-06-29T14:57:49.950", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "36869", "post_type": "question", "score": 0, "tags": [ "python", "python3" ], "title": "str is not callable の原因が分からない", "view_count": 3936 }
[ { "body": "直接的には`words.append(song(numbers[i]))`という行が、`song(numbers[i])`という関数があって呼ばれているように見えるが、そんなものは無いのでエラーになっているということです。\n\n`song`は文字列なので、それと`numbers[i]`との関係が、本当は何をしようと考えていたか? で修正内容が変わってくるでしょう。\n\n* * *\n\nコメント対応:\n\n単純には`( )`を`[ ]`に変えることで、`song`から1文字づつ`words`に追加する処理に出来ます。\n\n```\n\n words.append(song[numbers[i]])\n \n```\n\nしかしそれをすると、今度は4回目に実行された`numbers.pop(i+1)`の行で`IndexError: pop index out of\nrange`になります。 \nこの時`i`は11で、`numbers`は [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 19, 20]\nでした。`i+1`が12なのでリストの要素数の範囲外ですね。\n\nだからまだまだプログラムは未完成状態でしょう。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T10:44:20.313", "id": "68111", "last_activity_date": "2020-06-29T14:57:49.950", "last_edit_date": "2020-06-29T14:57:49.950", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "68110", "post_type": "answer", "score": 3 } ]
68110
68111
68111
{ "accepted_answer_id": null, "answer_count": 1, "body": "クイックソートをスタックを使って書き直してみたいのですがどこをどうすればよいのかよくわからないです\n\n```\n\n using System;\n using System.Collections;\n \n class Queue_int :IEnumerable { \n \n int[] data; \n int max; \n int front, back, count;\n \n public Queue_int(int n) { \n data = new int[n]; \n max = n; \n front = back = count = 0; \n }\n \n public bool Enqueue(int n) {\n if (count==max) return false; \n data[back] = n;\n back = (back+1)%max;\n count += 1;\n return true; \n }\n \n public int Dequeue() {\n int temp = front;\n front = (front+1)%max; \n count -= 1;\n return data[temp]; \n }\n \n \n public int Front() {\n return data[front];\n }\n \n public bool isEmpty() {\n return (count==0);\n }\n \n public bool isFull() {\n return (count==max);\n }\n \n int Count() {\n return count;\n }\n \n public IEnumerator GetEnumerator() {\n \n int i=front;\n for ( int j=0; j<count; j++ ) {\n yield return data[i];\n i = (i+1)%max;\n }\n }\n \n public void List() {\n foreach (int k in this)\n Console.Write(\"{0} \", k);\n Console.WriteLine();\n }\n };\n \n class QuickSortQueue\n {\n public void quickSort(int[] s) {\n int N = s.Length;\n int first, last, pivot, i, j, temp;\n Queue_int rangeq = new Queue_int(100);\n \n rangeq.Enqueue(0);\n rangeq.Enqueue(N-1);\n \n while( !rangeq.isEmpty() ) {\n rangeq.List();\n first = rangeq.Dequeue();\n last = rangeq.Dequeue();\n if (first < last) {\n pivot = s[last];\n i = first;\n j = last - 1;\n while (true) {\n while ( (i < last) && (s[i] < pivot) ) i += 1;\n while ( (j >= first) && (s[j] > pivot) ) j -= 1;\n if (i >= j) break;\n temp = s[i]; s[i] = s[j]; s[j] = temp;\n i += 1;\n j -= 1;\n }\n temp = s[i]; s[i] = s[last]; s[last] = temp;\n rangeq.Enqueue(first); rangeq.Enqueue(i-1);\n rangeq.Enqueue(i+1); rangeq.Enqueue(last);\n }\n }\n }\n \n public void inOut() {\n int[] s = {4, 5, 2, 8, 7, 10, 8, 1, -10, -4, 9, 3, 0, 12, 0, 2, 100,-100,2};\n \n quickSort(s);\n for (int k=0; k<s.Length; k++) {\n Console.Write(\"{0} \", s[k]);\n }\n Console.WriteLine();\n return;\n }\n \n static void Main() {\n (new QuickSortQueue()).inOut();\n } \n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T12:29:41.090", "favorite_count": 0, "id": "68115", "last_activity_date": "2022-06-23T11:03:25.407", "last_edit_date": "2020-06-29T12:33:38.810", "last_editor_user_id": "3060", "owner_user_id": "40863", "post_type": "question", "score": 1, "tags": [ "c#", "sort" ], "title": "クイックソートをスタックを使って書き直す", "view_count": 671 }
[ { "body": "> どこをどうすればよいのかよくわからないです\n\nまず、`QuickSort` を 再帰を使ってちゃんと実装します。 \n次に、末尾再帰はループを使って書き換え可能 なので `QuickSort` を再帰呼び出していてる場所 \nの パラメータに設定する値を `Enqueue` して \n関数パラメータから値を取得する部分を `Dequeue` します。 \nこの時 Enqueue と `Dequeue` の順番を間違えないように。 \nクラスを使って `first` と `last` の値をセットで `Enqueue` `Dequeue` すると読みやすいと思います。\n\n少なくとも 質問のコードでは `Enqueue` と `Dequeue` で 格納する値と 取り出す変数の順番が逆になっているように見えます。\n\n### 詳細を追記\n\n時間が無くてちゃんと解析できていませんでしたが、質問のプログラムは `Queue` を使った \nクリックソートを正しく実装していたんですね。 \n`Queue` を `Stack` にする場合は どうしたらいいか? という質問だったんですね。\n\nその場合は答えは簡単で `first` 変数と `last` 変数を Stack から取り出す順番を \n変えるだけで動作します。\n\nQueue は 入れた順番に取り出し Stack は 最後に入れたものから取り出しますから・・\n\n```\n\n using System.Collections.Generic;\n \n class IntStack : Stack<int>\n {\n public void List()\n {\n foreach (int k in this)\n Console.Write(\"{0} \", k);\n Console.WriteLine();\n }\n public bool isEmpty()\n {\n return this.Count == 0;\n }\n public void Enqueue(int n)\n {\n Push(n);\n }\n \n public int Dequeue()\n {\n return Pop();\n }\n }\n \n```\n\nとやると 下記のような最小限の修正で Stack を使って動作します\n\n```\n\n var rangeq = new IntStack();\n \n last = rangeq.Dequeue();\n first = rangeq.Dequeue();\n \n \n```\n\nもしかして Queue が独自実装だったので Stack も 独自で実装する予定だったのですか?\n\n### 参考情報\n\n[Javaで実装した QuickSort\nの詳しい解説](http://www.ics.kagoshima-u.ac.jp/%7Efuchida/edu/algorithm/sort-\nalgorithm/quick-sort.html) \n[C++ で実装。 再帰しない QuickSort の例。性能についての解説。](https://programming-\nplace.net/ppp/contents/algorithm/sort/006.html)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T23:43:08.887", "id": "68125", "last_activity_date": "2020-07-01T03:24:40.130", "last_edit_date": "2020-07-01T03:24:40.130", "last_editor_user_id": "18851", "owner_user_id": "18851", "parent_id": "68115", "post_type": "answer", "score": 1 } ]
68115
null
68125
{ "accepted_answer_id": "68880", "answer_count": 1, "body": "※サーバーサイドの話になります。 \nこのAPIでサーバーサイドでサブスクリプションの検証を行っています。 \n`https://www.googleapis.com/androidpublisher/v3/applications/`\n\nこのAPIで`purchaseState`という値が返ってくるのですがこの値の示す意味がわかりません。 \nドキュメントを読んでも一言しか書いておらず、検索しても情報が見つかりませんでした。\n\nGoogleのドキュメントでは↓のように説明されています。\n\n```\n\n purchaseState integer The purchase state of the order. Possible values are:\n - 0 Purchased\n - 1 Canceled\n - 2 Pending\n \n```\n\n私の疑問点は以下のとおりです。 \n間違っている点はありますか?\n\n_**0[Purchased]**_ \nこのステータスが返るとき、有効期限である`expiryTimeMillis`に従って \n有効期限なら有償サービスを提供すべきと思っています。\n\n_**1[Canceled]**_ \nこのステータスは払い戻しを行ったときに返されると勝手に思っています。 \nユーザーによる月額課金更新のキャンセルのことではなく。 \nそして私はこのステータスが返されるとき、自動的に`expiryTimeMillis`が過去の日付になるのではないかと思っています。 \nこのステータスが返るとき、有償サービスの提供を取りやめるべきと思っています。\n\n_**2[Pending]**_ \nこれは保護者などによる購入の保留状態のことでしょうか? \nこのステータスが返るとき、有償サービスの提供を行わないのが正しいと思っています。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T15:18:30.900", "favorite_count": 0, "id": "68117", "last_activity_date": "2020-07-24T05:39:28.700", "last_edit_date": "2020-06-29T15:26:01.180", "last_editor_user_id": "10346", "owner_user_id": "10346", "post_type": "question", "score": 2, "tags": [ "android" ], "title": "Android サーバーでのレシート検証について", "view_count": 922 }
[ { "body": "こんにちは、サブスクリプションに関するご質問のようなので、\n\n**Purchases.Subscriptions** の値についてということでよろしいでしょうか?\n\n<https://developers.google.com/android-publisher/api-\nref/purchases/subscriptions#resource-representations>\n\nご質問いただいているパラメーターは **Purchases.Products** のもののようです。\n\n<https://developers.google.com/android-publisher/api-ref/purchases/products>\n\nこれはIABによる通常のアイテムの購入に関するレシートを取得するものでサブスクリプションに適用はできません。\n**Purchases.Subscriptions** の値をとるときは以下のAPIを利用します。\n\n<https://developers.google.com/android-publisher/api-\nref/purchases/subscriptions/get>\n\nこの点一旦ご確認いただき、手順も含めご説明願えれば回答しやすいかと思います。\n\n**Purchases.Products** に関する説明となりますが、\n\n**2=Pending**\nは購入が、決済などなんらかの利用で一時保留されていることを表します。たとえばクレジットカードの審査に時間がかかっているとか。銀行振込での決済を行っていて、振込確認を待っているなどの状態です。決済形式(国や地域によって異なります)によっては一週間程度かかるケースもあるようです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-24T05:26:31.530", "id": "68880", "last_activity_date": "2020-07-24T05:39:28.700", "last_edit_date": "2020-07-24T05:39:28.700", "last_editor_user_id": "37777", "owner_user_id": "37777", "parent_id": "68117", "post_type": "answer", "score": 2 } ]
68117
68880
68880
{ "accepted_answer_id": null, "answer_count": 1, "body": "# 問題\n\n以下のurlでレビューと電話番号のデータを取ろうとしたのですが、電話番号とレビューの`text`,`rating`以外のほとんどの値がnilになってしまいます。ただ、urlを直接webで叩くと意図したjsonのデータが確認できます。 \n`https://maps.googleapis.com/maps/api/place/details/json?place_id=\"PLACE\nID\"&fields=reviews,formatted_phone_number&key=\"api key\"` \n[リファレンス](https://developers.google.com/places/web-\nservice/details)には、取れていないデータの説明書きの最後にif\navailable.と記載されているのですが、これが何を意味しているかが分かりません。\n\n取れているデータはあるので文法上のミスないのかなと思います。 \nまた、Modelはapiを直接叩いて確認したデータを[quicktype](https://app.quicktype.io/)というのを使って生成したのでタイポも考えにくいです。\n\n```\n\n struct Empty: Codable {\n let result: Result\n let status: String?\n }\n \n // MARK: - Result\n struct Result: Codable {\n let formattedPhoneNumber: String?\n let reviews: [Review]\n }\n \n // MARK: - Review\n struct Review: Codable {\n let authorName: String?\n let authorurl: String?\n let language: String?\n let profilePhotourl: String?\n let rating: Int?\n let relativeTimeDescription, text: String?\n let time: Int?\n }\n \n```\n\njsonData (データをそのまんま見せていいのか不安になったので、実際のデータをxに置き換えています)\n\n```\n\n {\n \"html_attributions\" : [],\n \"result\" : {\n \"formatted_phone_number\" : \"xx-xxxx-xxxx\",\n \"reviews\" : [\n {\n \"author_name\" : \"xxxx\",\n \"author_url\" : \"https://www.google.com/maps/xxxxx/xxxxxxx/reviews\",\n \"language\" : \"xx\",\n \"profile_photo_url\" : \"https://xxxxx.com/-xxxxxxx/xxxxxx/xxxxxx/xxxxxxx/xxxxxx/photo.jpg\",\n \"rating\" : 4,\n \"relative_time_description\" : \"x か月前\",\n \"text\" : \"xxxxxxxxxxxxxx。\",\n \"time\" : 1234567\n },\n {\n \"author_name\" : \"xxxxxxxx\",\n \"author_url\" : \"https://www.google.com/maps/contrib/xxxxxxxx/reviews\",\n \"language\" : \"xx\",\n \"profile_photo_url\" : \"https://lh6.ggpht.com/-xxxxxxx/xxxxxxxx/xxxxxxxxx/xxxxxxxx/xxxxxxx/photo.jpg\",\n \"rating\" : 5,\n \"relative_time_description\" : \"x 週間前\",\n \"text\" : \"xxxxxxxxx\",\n \"time\" : 1234567\n }\n ]\n },\n \"status\" : \"OK\"\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T15:36:16.860", "favorite_count": 0, "id": "68118", "last_activity_date": "2020-07-01T15:30:19.183", "last_edit_date": "2020-07-01T09:51:05.513", "last_editor_user_id": "40865", "owner_user_id": "40865", "post_type": "question", "score": 0, "tags": [ "swift", "google-maps", "google-cloud", "google-api" ], "title": "google place api で意図したデータが取れない", "view_count": 157 }
[ { "body": "jsonData\nのご提示ありがとうございます。実際の中身をご提示いただけるまでは、何かの設定やオプションでキーが書き換えられると言う可能性も捨てきれなかったのですが、そんなこともなかったようです。\n\n「text,rating以外のほとんどの値がnil」と言うことですが、現在のあなたのコードを使うと、`language`, `rating`,\n`text`, および`time`の各項目は取得できているのではないでしょうか?\n\nこれは、\n\n**`Review`クラスのプロパティ名と全く同じキーがJSON中に存在していればデータが取れている**\n\nと言うことを表しています。\n\n一方データが取れていない方の項目ですが、`authorName`を取ってくるために必要な`\"authorName\"`なんてキーの項目はJSON中には存在しません。\n\n`\"authorurl\"`も`\"profilePhotourl\"`も`\"relativeTimeDescription\"`もJSON中には存在しません。ですから、\n\n**それらの項目が取れないのは当たり前**\n\nと言うことになります。\n\n* * *\n\n## 対応法その1\n\n**モデルのプロパティ名をJSONのキー名に完全に一致させる**\n\nと言うのが一つの方法です。\n\n```\n\n struct PlacesAPIResponse: Codable {\n let result: Result\n let status: String?\n }\n \n // MARK: - Result\n struct Result: Codable {\n let formatted_phone_number: String?\n let reviews: [Review]\n }\n \n // MARK: - Review\n struct Review: Codable {\n let author_name: String?\n let author_url: String?\n let language: String?\n let profile_photo_url: String?\n let rating: Int?\n let relative_time_description, text: String?\n let time: Int?\n }\n \n```\n\n(`Empty`なんて型名はあまりにもあれなんで、書き換えています。)\n\nご紹介いただいたquicktypeサイトでは、この形式のSwiftコードを出力できるようなオプションは見つかりませんでした。他の類似のサイトを探すか、自分で手を入れないといけないでしょう。\n\nただ、Swiftでは、スネークケースの識別子は原則使用しませんので、コードがSwiftっぽくなくなってしまいます。あまりこの方法を好まれる方はいないかもしれません。\n\n* * *\n\n## 対応方法その2\n\n**`CodingKeys`を明示して、プロパティ名とJSON側のキー名の対応を明記する**\n\nと言う手もあります。\n\n```\n\n import Foundation\n \n // MARK: - PlaceAPIResponse\n struct PlaceAPIResponse: Codable {\n let result: Result?\n let status: String?\n }\n \n // MARK: - Result\n struct Result: Codable {\n let formattedPhoneNumber: String?\n let reviews: [Review]?\n \n enum CodingKeys: String, CodingKey {\n case formattedPhoneNumber = \"formatted_phone_number\"\n case reviews\n }\n }\n \n // MARK: - Review\n struct Review: Codable {\n let authorName: String?\n let authorURL: String?\n let language: String?\n let profilePhotoURL: String?\n let rating: Int?\n let relativeTimeDescription, text: String?\n let time: Int?\n \n enum CodingKeys: String, CodingKey {\n case authorName = \"author_name\"\n case authorURL = \"author_url\"\n case language\n case profilePhotoURL = \"profile_photo_url\"\n case rating\n case relativeTimeDescription = \"relative_time_description\"\n case text, time\n }\n }\n \n```\n\nこのコードはquicktypeサイトで、Explicit CodingKey values in Codable typesと、Make all\nproperties optionalをONにして生成したものそのままです。\n\nちなみに自動生成したコードでは`authorURL`や`profilePhotoURL`のように`URL`の部分が大文字に変換されました。ご質問で使用されているコードは手作業で一部変更されたのでしょうか?\n\nなお、quicktypeサイトでそのまま使えそうな`CodingKeys`が生成されたのは、このExplicit CodingKey values in\nCodable typesオプションを指定した時だけでした。その他の場合には、使えもしない`CodingKeys`が出力されてしまいます。\n\nただし、ほとんどの項目名がスネークケースからキャメルケースへの機械的変換で済むのに、`CodingKeys`が指定されているのは、かえってコードが読みにくいと思われる方もいるでしょう。\n\n* * *\n\n# 対応法その3\n\n * **モデルのプロパティ名をJSONのキー名から機械的に変換したものに完全に一致させる**\n * **`JSONDecoder`で、`keyDecodingStrategy = .convertFromSnakeCase`を指定する**\n\nと言う手もあります。ご質問中には、`JSONDecoder`を使う部分のコードが示されていないので、以下はXcodeのPlaygroundなどで試せる形で記載しておきます。\n\n```\n\n import Foundation\n \n let jsonText = #\"\"\"\n {\n \"html_attributions\" : [],\n \"result\" : {\n \"formatted_phone_number\" : \"xx-xxxx-xxxx\",\n \"reviews\" : [\n {\n \"author_name\" : \"xxxx\",\n \"author_url\" : \"https://www.google.com/maps/xxxxx/xxxxxxx/reviews\",\n \"language\" : \"xx\",\n \"profile_photo_url\" : \"https://xxxxx.com/-xxxxxxx/xxxxxx/xxxxxx/xxxxxxx/xxxxxx/photo.jpg\",\n \"rating\" : 4,\n \"relative_time_description\" : \"x か月前\",\n \"text\" : \"xxxxxxxxxxxxxx。\",\n \"time\" : 1234567\n },\n {\n \"author_name\" : \"xxxxxxxx\",\n \"author_url\" : \"https://www.google.com/maps/contrib/xxxxxxxx/reviews\",\n \"language\" : \"xx\",\n \"profile_photo_url\" : \"https://lh6.ggpht.com/-xxxxxxx/xxxxxxxx/xxxxxxxxx/xxxxxxxx/xxxxxxx/photo.jpg\",\n \"rating\" : 5,\n \"relative_time_description\" : \"x 週間前\",\n \"text\" : \"xxxxxxxxx\",\n \"time\" : 1234567\n }\n ]\n },\n \"status\" : \"OK\"\n }\n \"\"\"#\n \n let jsonData = jsonText.data(using: .utf8)!\n \n struct PlacesAPIResponse: Codable {\n let result: Result\n let status: String?\n }\n \n // MARK: - Result\n struct Result: Codable {\n let formattedPhoneNumber: String?\n let reviews: [Review]\n }\n \n // MARK: - Review\n struct Review: Codable {\n let authorName: String?\n let authorUrl: String? //<- `authorurl`や`authorURL`ではダメ\n let language: String?\n let profilePhotoUrl: String? //<- 上記と同様\n let rating: Int?\n let relativeTimeDescription: String?\n let text: String?\n let time: Int?\n }\n \n do {\n let decoder = JSONDecoder()\n decoder.keyDecodingStrategy = .convertFromSnakeCase\n let response = try decoder.decode(PlacesAPIResponse.self, from: jsonData)\n print(response)\n } catch {\n print(error)\n }\n \n```\n\n`Review`のプロパティ名の一部`authorUrl`と`profilePhotoUrl`、それから`.convertFromSnakeCase`を指定している部分に注意して下さい。\n\n* * *\n\n対応法2の方は、`JSONDecoder`が理解できる変換規則に縛られずに自由にプロパティ名とJSONのキー名の対応が付けられるので、より自由度が高いと言えるでしょう。\n\nただ、このAPIのように綺麗にキャメルケースに変換できるキー名になっている場合は対応法3を好まれる人も多いかもしれません。\n\nご自身のコーディングスタイルに合わせて、どれかの方法を試してみて下さい。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-01T15:30:19.183", "id": "68191", "last_activity_date": "2020-07-01T15:30:19.183", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "68118", "post_type": "answer", "score": 0 } ]
68118
null
68191
{ "accepted_answer_id": null, "answer_count": 1, "body": "いつもお世話になっております。 \n現在firebaseでチャットソフトを作成しているのですが、バックエンド側の処理で思ったようにいかずつまづいてしまいました。\n\nデータベース上のチャットルームに読み込み権限と書き込み権限を付けたのですが、ruleから参照する方法が分からず質問させて頂きました。\n\nrule\n\n```\n\n {\n \n \"rules\": {\n \"rooms\" : {\n \".read\": \"auth != null\",\n \".write\": \"auth != null\",\n \"$room_id\" :{\n \".read\": \"root.child('rooms').child($room_id).child('read').val()=='true'\",\n \".write\": \"root.child('rooms').child($room_id).child('write').val()=='true'\",\n }\n }\n }\n }\n \n```\n\nデータベース\n\n```\n\n {\n \n \"rooms\" : {\n \"-ROOM_ID_1\" : {\n \"admin\" : false,\n \"img_upload\" : false,\n \"messages\" : {\n \"-MB-NAtBV1ybNEUM-DVS\" : {\n \"name\" : \"hoge.\",\n \"text\" : \"テスト\"\n }\n },\n \"read\" : true,\n \"room_name\" : \"部屋1\",\n \"write\" : true\n },\n \"-ROOM_ID_2\" : {\n \"admin\" : false,\n \"img_upload\" : false,\n \"messages\" : {\n \"-MB-BcDIyABa7Ngw23IM\" : {\n \"name\" : \"hoge\",\n \"text\" : \"テスト\"\n },\n \"-MB-NPjk4xd0h_JZTUjG\" : {\n \"name\" : \"hoge\",\n \"text\" : \"テスト\"\n }\n },\n \"read\" : true,\n \"room_name\" : \"部屋2\",\n \"write\" : true\n }\n }\n }\n \n```\n\nruleからデータベースのroom内のwriteを参照したいのですが、参照できず困っています。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T22:35:57.513", "favorite_count": 0, "id": "68121", "last_activity_date": "2020-06-30T16:08:05.890", "last_edit_date": "2020-06-30T16:08:05.890", "last_editor_user_id": "3068", "owner_user_id": "40868", "post_type": "question", "score": 0, "tags": [ "firebase" ], "title": "firebaseのruleの記載においてchildの中にロケーション変数を使用したい", "view_count": 35 }
[ { "body": "自己解決しました。 \nちょっと改良したため、こんな感じになりました。\n\n**データベース**\n\n```\n\n {\n \"admin-users\" : {\n \"9k3Uf---------------\" : true\n },\n \"black-list\" : {\n \"MAtSa-------------\" : true\n },\n \"rooms\" : {\n \"-MB3l-----------\" : {\n \"admin\" : false,\n \"author\" : \"\",\n \"img_upload\" : false,\n \"messages\" : {\n \"-MB3nu----------\" : {\n \"name\" : \"Haru Haru\",\n \"photoUrl\" : \"\",\n \"text\" : \"テスト\"\n }\n },\n \"photoUrl\" : \"\",\n \"read\" : true,\n \"room_name\" : \"部屋1\",\n \"write\" : true\n },\n \"-MB3m---------------\" : {\n \"admin\" : false,\n \"author\" : \"\",\n \"img_upload\" : false,\n \"photoUrl\" : \"\",\n \"read\" : true,\n \"room_name\" : \"部屋2\",\n \"write\" : false\n }\n }\n }\n \n```\n\n**ルール**\n\n```\n\n { \n \"rules\": {\n \"admin-users\" : {\n \".read\": \"auth != null && !root.child('black-list').child(auth.uid).exists()\",\n \".write\": \"root.child('admin-users').child(auth.uid).exists()\",\n },\n \"black-list\" : {\n \".read\": \"auth != null && !root.child('black-list').child(auth.uid).exists()\",\n \".write\": \"root.child('admin-users').child(auth.uid).exists()\",\n },\n \"rooms\" : {\n \".read\": \"root.child('admin-users').child(auth.uid).exists() || auth != null && !root.child('black-list').child(auth.uid).exists()\",\n \"$room_id\" :{\n \".read\": \"root.child('admin-users').child(auth.uid).exists() || auth != null && !root.child('black-list').child(auth.uid).exists() && data.child('read').val()==true\",\n \".write\": \"root.child('admin-users').child(auth.uid).exists() || auth != null && !root.child('black-list').child(auth.uid).exists() && data.child('write').val()==true\"\n }\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T10:41:54.607", "id": "68149", "last_activity_date": "2020-06-30T11:43:50.377", "last_edit_date": "2020-06-30T11:43:50.377", "last_editor_user_id": "3060", "owner_user_id": "40868", "parent_id": "68121", "post_type": "answer", "score": 0 } ]
68121
null
68149
{ "accepted_answer_id": "69101", "answer_count": 1, "body": "# 解決したいこと\n\nChart.js上で表示される値が、実際にDBに格納されているラベル・値共に対応していないため、正しいラベル・値を表示させたい\n\n### イメージ\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/bZHg6.png)](https://i.stack.imgur.com/bZHg6.png)\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/qibiK.png)](https://i.stack.imgur.com/qibiK.png)\n\n# 環境\n\n・Ruby:2.6.5 \n・Rails:5.2.4.3 \n・DB:PostgreSQL\n\n# 試したこと\n\nlogger.infoでどんな値が格納されたのか確認したのですが、Controllerの意図した順番ではありませんが、正しい内容(=ラベル・値が対応している)が格納できています。にもかかわらず、実際に表示される円グラフは、全く対応できておりません。\n\n```\n\n Started GET \"/records/3/aggregate_result\" for ::1 at 2020-06-30 08:09:17 +0900\n Processing by RecordsController#aggregate_result as HTML\n Parameters: {\"id\"=>\"3\"}\n User Load (0.2ms) SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" = $1 ORDER BY \"users\".\"id\" ASC LIMIT $2 [[\"id\", 3], [\"LIMIT\", 1]]\n ↳ /Users/user/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-5.2.4.3/lib/active_record/log_subscriber.rb:98\n (0.5ms) SELECT SUM(practice_time) AS sum_practice_time, \"practice_item\" AS practice_item FROM \"records\" LEFT OUTER JOIN \"practices\" ON \"practices\".\"record_id\" = \"records\".\"id\" WHERE \"records\".\"user_id\" = $1 GROUP BY \"practice_item\" [[\"user_id\", \"3\"]]\n ↳ app/controllers/records_controller.rb:59\n test {\"多球練習\"=>10, \"フットワーク\"=>30, \"サーブ練習\"=>50, \"オール\"=>20}\n \n```\n\n※本来の順番は、上の一枚目の画像の通りです。\n\n# コード\n\nController\n\n```\n\n class RecordsController < ApplicationController\n before_action :authenticate_user!\n \n def index\n @q = current_user.records.ransack(params[:q])\n @search_records = @q.result(distinct: true).includes(:practices).page(params[:page]).per(8)\n end\n \n def show\n @record = Record.find(params[:id])\n end\n \n def new\n @record = Record.new\n output = @record.outputs.build\n practice = @record.practices.build\n task = @record.tasks.build\n @item_array = [\"サーブ練習\",\"フットワーク\", \"3球目攻撃\",\"台上処理\",\"多球練習\",\"オール\"]\n end\n \n def create\n @record = Record.new(record_params)\n logger.info \"###### #{@record.inspect}\"\n if @record.save\n flash[:success] = \"練習内容の登録が完了しました。\"\n redirect_to records_url\n else\n flash[:alert] = \"登録に失敗しました。\"\n render :new\n end\n end\n \n def edit\n @record = Record.find_by(id: params[:id])\n @item_array = [\"サーブ練習\",\"フットワーク\", \"3球目攻撃\",\"台上処理\",\"多球練習\",\"オール\"]\n end\n \n def update\n @record = Record.find_by(id: params[:id])\n if @record.update(record_params)\n flash[:success] = \"練習内容の更新が完了しました。\"\n redirect_to records_url\n else\n flash[:alert] = \"更新に失敗しました。\"\n render :edit\n end\n end\n \n def destroy\n record = Record.find_by(id:params[:id])\n record.destroy\n \n redirect_to root_path, notice: \"練習記録を削除しました。\"\n end\n \n def aggregate_result\n @label = [\"3球目攻撃\", \"多球練習\", \"サーブ練習\", \"フットワーク\",\"オール\",\"台上処理\"]\n gon.label = @label\n @record = current_user.records.includes(:practices).select(:practice_time).group(:practice_item).sum(:practice_time)\n logger.info \"test #{@record.inspect}\"\n gon.data = @record.values\n end\n \n private\n \n def set_user\n @user = current_user || User.new\n end\n \n def record_params\n params.require(:record).permit(:record_id, :training_date, :learning_point, outputs_attributes:[:output_name, :id, :_destroy], practices_attributes:[:practice_item, :practice_time, :id, :_destroy], tasks_attributes:[:task_name, :id, :_destroy]).merge(user_id: current_user.id)\n end\n end\n \n```\n\nslim\n\n```\n\n = render 'records/flash_messages'\n h1 レポート\n \n canvas#myPieChart\n script src=\"https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.bundle.js\"\n javascript:\n var ctx = document.getElementById(\"myPieChart\");\n var myPieChart = new Chart(ctx, {\n type: 'pie',\n data: {\n labels: gon.label,\n datasets: [{\n backgroundColor: [\n 'rgba(255, 99, 132, 0.2)',\n 'rgba(54, 162, 235, 0.2)',\n 'rgba(255, 206, 86, 0.2)',\n 'rgba(192,240,0,0.2)',\n 'rgba(75, 192, 192, 0.2)',\n 'rgba(242,68,172,0.2)'\n ],\n data:#{@record.values}\n }]\n },\n options: {\n title: {\n display: true,\n text: '練習内容の内訳'\n }\n }\n });\n \n .d-flex\n .col-6.text-align: center\n = link_to '練習記録一覧に戻る', root_path, class: 'btn btn-primary'\n .col-6.text-align: center\n = link_to '練習記録を登録する', new_record_path, class: 'btn btn-primary'\n \n```\n\ndb.schema\n\n```\n\n ActiveRecord::Schema.define(version: 2020_06_29_125236) do\n \n # These are extensions that must be enabled in order to support this database\n enable_extension \"plpgsql\"\n \n create_table \"outputs\", force: :cascade do |t|\n t.text \"output_name\", null: false\n t.bigint \"record_id\"\n t.datetime \"created_at\", null: false\n t.datetime \"updated_at\", null: false\n t.index [\"record_id\"], name: \"index_outputs_on_record_id\"\n end\n \n create_table \"practices\", force: :cascade do |t|\n t.string \"practice_item\", null: false\n t.integer \"practice_time\", null: false\n t.bigint \"record_id\"\n t.datetime \"created_at\", null: false\n t.datetime \"updated_at\", null: false\n t.index [\"record_id\"], name: \"index_practices_on_record_id\"\n end\n \n create_table \"records\", force: :cascade do |t|\n t.string \"user_id\"\n t.text \"learning_point\", null: false\n t.date \"training_date\", null: false\n t.datetime \"created_at\", null: false\n t.datetime \"updated_at\", null: false\n end\n \n create_table \"tasks\", force: :cascade do |t|\n t.text \"task_name\", null: false\n t.bigint \"record_id\"\n t.datetime \"created_at\", null: false\n t.datetime \"updated_at\", null: false\n t.index [\"record_id\"], name: \"index_tasks_on_record_id\"\n end\n \n create_table \"users\", force: :cascade do |t|\n t.string \"email\", default: \"\", null: false\n t.string \"encrypted_password\", default: \"\", null: false\n t.string \"reset_password_token\"\n t.datetime \"reset_password_sent_at\"\n t.datetime \"remember_created_at\"\n t.datetime \"created_at\", null: false\n t.datetime \"updated_at\", null: false\n t.index [\"email\"], name: \"index_users_on_email\", unique: true\n t.index [\"reset_password_token\"], name: \"index_users_on_reset_password_token\", unique: true\n end\n \n add_foreign_key \"outputs\", \"records\"\n add_foreign_key \"practices\", \"records\"\n add_foreign_key \"tasks\", \"records\"\n end\n \n \n```", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T23:18:48.397", "favorite_count": 0, "id": "68123", "last_activity_date": "2020-07-29T14:08:55.340", "last_edit_date": "2020-07-24T11:18:11.903", "last_editor_user_id": "39475", "owner_user_id": "39475", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "ruby", "chart.js" ], "title": "Chart.jsのラベルと値が対応していない問題を解決したい", "view_count": 311 }
[ { "body": "`aggregate_result` メソッドを次のように書き換えれば、指定ラベルの順序どおりにグラフが描画されるようになるのではないでしょうか?\n\n```\n\n def aggregate_result\n # 1. ログインユーザーの親関係にあるRecordテーブルと、\n # 子関係にあるPracticeテーブルの全てのデータを取得する。\n # 2. 取得したデータから、Practiceテーブルのpractice_timeカラムにある\n # データを選択し、practice_itemごとにデータを分類し、\n # practice_timeカラムの合計値を計算する。\n # 3. その合計値を、@recordオブジェクトとして表示する。\n \n # MEMO: item_order の順序を参考に Hash を再構築し、その後ひとつの Hash として値を纏める\n item_order = %w[サーブ練習 フットワーク 3球目攻撃 台上処理 多球練習 オール]\n @record =\n current_user.records\n .includes(:practices)\n .select(:practice_time)\n .group(:practice_item)\n .sum(:practice_time)\n .then { |hash| item_order.map { |key| {key => hash[key]} } }\n .reduce { |hash, key_value| hash.update(key_value) }\n \n logger.info \"test #{@record.inspect}\"\n \n gon.label = @record.keys\n gon.data = @record.values\n end\n \n```\n\nメソッドチェーンを2つ以上使っての数珠繋ぎをやりすぎたパターンだとおもっているので、もしかしたら適切に別名のメソッドを定義して処理を渡してあげる必要があるかもしれません\n\nなにか参考になれば幸いです", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-29T14:08:55.340", "id": "69101", "last_activity_date": "2020-07-29T14:08:55.340", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3861", "parent_id": "68123", "post_type": "answer", "score": 2 } ]
68123
69101
69101
{ "accepted_answer_id": "68130", "answer_count": 1, "body": "[動くCSSのためのメモスライドショー](https://lopan.jp/css-animation-\nslideshow/)を参考にして、スライドショーを作成しました。 \n動くようになったのですが、もう少し手を加えたくて投稿しました。\n\nやりたいこと\n\n・次の画像に遷移するためのボタンを透明化して、画像を両サイドいっぱいにしたい。 \n-今はlightSeaGreenが設定されているので、そこを透明にするのはできるのですが、画像が思うように両サイドいっぱいにならないで困ってます。 \n・高さをもう少し短くしたい。どの部分を変更すれば高さの調節ができますでしょうか。\n\nよろしくお願いします。 \n\n```\n\n @charset \"utf-8\";\n \n .slideshow {\n position: relative;\n overflow: hidden;\n }\n input[name=\"slideshow\"] {\n display: none;\n }\n \n /* :::::: slideContents :::::: */\n .slideContents {\n position: relative;\n background: lightSeaGreen;\n text-align: center;\n -webkit-user-select: none;\n user-select: none;\n transition: transform .6s;\n }\n .slideContents section {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n transform: translateX(100%);\n transition: transform .6s cubic-bezier(0.215, 0.61, 0.355, 1);\n }\n .slideContents section img {\n max-width: 100%;\n padding: 0 50px;\n box-sizing: border-box;\n vertical-align: middle;\n }\n \n /* :::::: arrows :::::: */\n .arrow,\n .arrow label,\n .arrow .ico {\n position: absolute;\n }\n .arrow {\n top: 0;\n margin: 0;\n transition: background .3s;\n }\n .prev {\n left: 0;\n }\n .next {\n right: 0;\n }\n .arrow:hover {\n background: rgba(255,255,255,.2);\n }\n .arrow,\n .arrow label {\n cursor: pointer;\n width: 50px;\n height: 100%;\n }\n .arrow label {\n top: 0;\n left: 0;\n z-index: 1;\n }\n .arrow .ico {\n top: calc(50% - 6px);\n width: 12px;\n height: 12px;\n border-top: 3px solid #fff;\n opacity: 0;\n }\n .prev .ico {\n left: 50%;\n border-left: 3px solid #fff;\n transform: rotate(-45deg);\n transition: left .3s cubic-bezier(0.215, 0.61, 0.355, 1), opacity .3s;\n }\n .next .ico {\n right: 50%;\n border-right: 3px solid #fff;\n transform: rotate(45deg);\n transition: right .3s cubic-bezier(0.215, 0.61, 0.355, 1), opacity .3s;\n }\n .arrow:hover .ico {\n opacity: .6;\n }\n .prev:hover .ico {\n left: calc(50% - 6px);\n }\n .next:hover .ico {\n right: calc(50% - 6px);\n }\n \n /* :::::: mechanism :::::: */\n #switch1:checked ~ .slideContents #slide1,\n #switch2:checked ~ .slideContents #slide2,\n #switch3:checked ~ .slideContents #slide3,\n #switch4:checked ~ .slideContents #slide4,\n #switch5:checked ~ .slideContents #slide5 {\n position: relative;\n transform: none;\n }\n #switch1:checked ~ .slideContents #slide5,\n #switch1:checked ~ .slideContents #slide4,\n #switch2:checked ~ .slideContents #slide1,\n #switch2:checked ~ .slideContents #slide5,\n #switch3:checked ~ .slideContents #slide2,\n #switch3:checked ~ .slideContents #slide1,\n #switch4:checked ~ .slideContents #slide3,\n #switch4:checked ~ .slideContents #slide2,\n #switch5:checked ~ .slideContents #slide4,\n #switch5:checked ~ .slideContents #slide3 {\n transform: translateX(-100%);\n }\n #switch1:checked ~ .slideContents #slide3,\n #switch1:checked ~ .slideContents #slide4,\n #switch2:checked ~ .slideContents #slide4,\n #switch2:checked ~ .slideContents #slide5,\n #switch3:checked ~ .slideContents #slide5,\n #switch3:checked ~ .slideContents #slide1,\n #switch4:checked ~ .slideContents #slide1,\n #switch4:checked ~ .slideContents #slide2,\n #switch5:checked ~ .slideContents #slide2,\n #switch5:checked ~ .slideContents #slide3 {\n transition-duration: 0s;\n }\n \n /* :::::: arrow mechanism :::::: */\n .arrow label {\n pointer-events: none;\n }\n #switch1:checked ~ .prev label[for=\"switch5\"],\n #switch2:checked ~ .prev label[for=\"switch1\"],\n #switch3:checked ~ .prev label[for=\"switch2\"],\n #switch4:checked ~ .prev label[for=\"switch3\"],\n #switch5:checked ~ .prev label[for=\"switch4\"],\n #switch1:checked ~ .next label[for=\"switch2\"],\n #switch2:checked ~ .next label[for=\"switch3\"],\n #switch3:checked ~ .next label[for=\"switch4\"],\n #switch4:checked ~ .next label[for=\"switch5\"],\n #switch5:checked ~ .next label[for=\"switch1\"] {\n pointer-events: auto;\n }\n```\n\n```\n\n <!doctype html>\n <html lang=\"ja\">\n \n <meta charset=\"utf-8\">\n <body>\n <div class=\"slideshow\">\n <input type=\"radio\" name=\"slideshow\" id=\"switch1\" checked>\n <input type=\"radio\" name=\"slideshow\" id=\"switch2\">\n <input type=\"radio\" name=\"slideshow\" id=\"switch3\">\n <input type=\"radio\" name=\"slideshow\" id=\"switch4\">\n <input type=\"radio\" name=\"slideshow\" id=\"switch5\">\n <div class=\"slideContents\">\n <section id=\"slide1\">\n <img src=\"https://cdn.pixabay.com/photo/2020/04/24/10/23/pier-5086290_1280.jpg\">\n </section>\n <section id=\"slide2\">\n <img src=\"https://cdn.pixabay.com/photo/2020/06/02/07/51/luka-5249892_1280.jpg\">\n </section>\n <section id=\"slide3\">\n <img src=\"https://cdn.pixabay.com/photo/2020/04/13/17/16/netherlands-5039354_1280.jpg\">\n </section>\n <section id=\"slide4\">\n <img src=\"https://cdn.pixabay.com/photo/2020/04/15/12/09/summer-5046401_1280.jpg\">\n </section>\n <section id=\"slide5\">\n <img src=\"https://cdn.pixabay.com/photo/2020/04/11/20/35/lighthouse-5031977_1280.jpg\">\n </section>\n </div>\n <p class=\"arrow prev\">\n <i class=\"ico\"></i>\n <label for=\"switch1\"></label>\n <label for=\"switch2\"></label>\n <label for=\"switch3\"></label>\n <label for=\"switch4\"></label>\n <label for=\"switch5\"></label>\n </p>\n <p class=\"arrow next\">\n <i class=\"ico\"></i>\n <label for=\"switch1\"></label>\n <label for=\"switch2\"></label>\n <label for=\"switch3\"></label>\n <label for=\"switch4\"></label>\n <label for=\"switch5\"></label>\n </p>\n </div>\n \n \n </body>\n </html>\n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-29T23:40:48.387", "favorite_count": 0, "id": "68124", "last_activity_date": "2020-06-30T02:38:30.437", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40597", "post_type": "question", "score": 0, "tags": [ "html", "css" ], "title": "CSS スライドショーを完成させたい。", "view_count": 145 }
[ { "body": "> 今はlightSeaGreenが設定されているので、そこを透明にするのはできるのですが、画像が思うように両サイドいっぱいにならないで困ってます。\n\nimgにpaddingがついてますね。こちらを外せば問題ないかと\n\n> ・高さをもう少し短くしたい。どの部分を変更すれば高さの調節ができますでしょうか。\n\nslideContents に高さを設定すればよろしいと思います。\n\nCSSの調整についてですが \nCSSを試すにはChromeのF12のElementsタブでStyleなどを利用してCSSを動的にいじるとわかりやすいと思います。直接スタイルを変更したり、paddingをなくしたりといった操作が動的に対応ができます。 \n一度お試しを。\n\n```\n\n @charset \"utf-8\";\n \n .slideshow {\n position: relative;\n overflow: hidden;\n }\n input[name=\"slideshow\"] {\n display: none;\n }\n \n /* :::::: slideContents :::::: */\n .slideContents {\n position: relative;\n background: lightSeaGreen;\n text-align: center;\n -webkit-user-select: none;\n user-select: none;\n transition: transform .6s;\n height: 200px;\n }\n .slideContents section {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n transform: translateX(100%);\n transition: transform .6s cubic-bezier(0.215, 0.61, 0.355, 1);\n }\n .slideContents section img {\n max-width: 100%;\n padding: 0 0px;\n box-sizing: border-box;\n vertical-align: middle;\n height: -webkit-fill-available;\n width: fit-content;\n }\n \n /* :::::: arrows :::::: */\n .arrow,\n .arrow label,\n .arrow .ico {\n position: absolute;\n }\n .arrow {\n top: 0;\n margin: 0;\n transition: background .3s;\n }\n .prev {\n left: 0;\n }\n .next {\n right: 0;\n }\n .arrow:hover {\n background: rgba(255,255,255,.2);\n }\n .arrow,\n .arrow label {\n cursor: pointer;\n width: 50px;\n height: 100%;\n }\n .arrow label {\n top: 0;\n left: 0;\n z-index: 1;\n }\n .arrow .ico {\n top: calc(50% - 6px);\n width: 12px;\n height: 12px;\n border-top: 3px solid #fff;\n opacity: 0;\n }\n .prev .ico {\n left: 50%;\n border-left: 3px solid #fff;\n transform: rotate(-45deg);\n transition: left .3s cubic-bezier(0.215, 0.61, 0.355, 1), opacity .3s;\n }\n .next .ico {\n right: 50%;\n border-right: 3px solid #fff;\n transform: rotate(45deg);\n transition: right .3s cubic-bezier(0.215, 0.61, 0.355, 1), opacity .3s;\n }\n .arrow:hover .ico {\n opacity: .6;\n }\n .prev:hover .ico {\n left: calc(50% - 6px);\n }\n .next:hover .ico {\n right: calc(50% - 6px);\n }\n \n /* :::::: mechanism :::::: */\n #switch1:checked ~ .slideContents #slide1,\n #switch2:checked ~ .slideContents #slide2,\n #switch3:checked ~ .slideContents #slide3,\n #switch4:checked ~ .slideContents #slide4,\n #switch5:checked ~ .slideContents #slide5 {\n position: relative;\n transform: none;\n }\n #switch1:checked ~ .slideContents #slide5,\n #switch1:checked ~ .slideContents #slide4,\n #switch2:checked ~ .slideContents #slide1,\n #switch2:checked ~ .slideContents #slide5,\n #switch3:checked ~ .slideContents #slide2,\n #switch3:checked ~ .slideContents #slide1,\n #switch4:checked ~ .slideContents #slide3,\n #switch4:checked ~ .slideContents #slide2,\n #switch5:checked ~ .slideContents #slide4,\n #switch5:checked ~ .slideContents #slide3 {\n transform: translateX(-100%);\n }\n #switch1:checked ~ .slideContents #slide3,\n #switch1:checked ~ .slideContents #slide4,\n #switch2:checked ~ .slideContents #slide4,\n #switch2:checked ~ .slideContents #slide5,\n #switch3:checked ~ .slideContents #slide5,\n #switch3:checked ~ .slideContents #slide1,\n #switch4:checked ~ .slideContents #slide1,\n #switch4:checked ~ .slideContents #slide2,\n #switch5:checked ~ .slideContents #slide2,\n #switch5:checked ~ .slideContents #slide3 {\n transition-duration: 0s;\n }\n \n /* :::::: arrow mechanism :::::: */\n .arrow label {\n pointer-events: none;\n }\n #switch1:checked ~ .prev label[for=\"switch5\"],\n #switch2:checked ~ .prev label[for=\"switch1\"],\n #switch3:checked ~ .prev label[for=\"switch2\"],\n #switch4:checked ~ .prev label[for=\"switch3\"],\n #switch5:checked ~ .prev label[for=\"switch4\"],\n #switch1:checked ~ .next label[for=\"switch2\"],\n #switch2:checked ~ .next label[for=\"switch3\"],\n #switch3:checked ~ .next label[for=\"switch4\"],\n #switch4:checked ~ .next label[for=\"switch5\"],\n #switch5:checked ~ .next label[for=\"switch1\"] {\n pointer-events: auto;\n }\n```\n\n```\n\n <!doctype html>\n <html lang=\"ja\">\n \n <meta charset=\"utf-8\">\n <body>\n <div class=\"slideshow\">\n <input type=\"radio\" name=\"slideshow\" id=\"switch1\" checked>\n <input type=\"radio\" name=\"slideshow\" id=\"switch2\">\n <input type=\"radio\" name=\"slideshow\" id=\"switch3\">\n <input type=\"radio\" name=\"slideshow\" id=\"switch4\">\n <input type=\"radio\" name=\"slideshow\" id=\"switch5\">\n <div class=\"slideContents\">\n <section id=\"slide1\">\n <img src=\"https://cdn.pixabay.com/photo/2020/04/24/10/23/pier-5086290_1280.jpg\">\n </section>\n <section id=\"slide2\">\n <img src=\"https://cdn.pixabay.com/photo/2020/06/02/07/51/luka-5249892_1280.jpg\">\n </section>\n <section id=\"slide3\">\n <img src=\"https://cdn.pixabay.com/photo/2020/04/13/17/16/netherlands-5039354_1280.jpg\">\n </section>\n <section id=\"slide4\">\n <img src=\"https://cdn.pixabay.com/photo/2020/04/15/12/09/summer-5046401_1280.jpg\">\n </section>\n <section id=\"slide5\">\n <img src=\"https://cdn.pixabay.com/photo/2020/04/11/20/35/lighthouse-5031977_1280.jpg\">\n </section>\n </div>\n <p class=\"arrow prev\">\n <i class=\"ico\"></i>\n <label for=\"switch1\"></label>\n <label for=\"switch2\"></label>\n <label for=\"switch3\"></label>\n <label for=\"switch4\"></label>\n <label for=\"switch5\"></label>\n </p>\n <p class=\"arrow next\">\n <i class=\"ico\"></i>\n <label for=\"switch1\"></label>\n <label for=\"switch2\"></label>\n <label for=\"switch3\"></label>\n <label for=\"switch4\"></label>\n <label for=\"switch5\"></label>\n </p>\n </div>\n \n \n </body>\n </html>\n```", "comment_count": 6, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T01:27:20.630", "id": "68130", "last_activity_date": "2020-06-30T02:38:30.437", "last_edit_date": "2020-06-30T02:38:30.437", "last_editor_user_id": "22665", "owner_user_id": "22665", "parent_id": "68124", "post_type": "answer", "score": 0 } ]
68124
68130
68130
{ "accepted_answer_id": null, "answer_count": 1, "body": "* * *\n\n**環境** \nWindows10 pro \nWSL Ubuntu 20.04 LTS \nVim 8.1\n\n* * *\n\n**やりたいこと** \nVimで現在編集中のシェルスクリプトをデバッグするような方法があれば知りたいです。\n\n例として、私は通常以下の方法で自分の作成した、スクリプトの動作を確認しています。\n\nペイン「1」では下記図のようにteratail.shを編集中とします。 \nペイン「2」は自分が作ったスクリプトを確認するためのものです。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/RmXmq.png)](https://i.stack.imgur.com/RmXmq.png) \nただ、これだと試すのにペインを移動しなければならないので、 \n少し手間に思います。\n\nそのため理想としては... \n1.編集ウィンドウで(デバッグ)コマンド実行 \n2.ウィンドウが分割される。 \n3.分割されたウィンドウで編集中のシェルファイルが実行される\n\nという流れでできないのか?と考えています。\n\nコマンド的に言えば、Terminalコマンドを実行するとVimの画面が分割されますが、 \nそこに、編集中のファイルを渡してあげて、実行させるようなことがしたいのです。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/IBM7E.png)](https://i.stack.imgur.com/IBM7E.png)\n\n* * *\n\nやり方を知っている方 \nもし、方法があれば教えて欲しいと思います。 \n私の考え方が違う場合も教えて頂ければ幸いです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T00:27:30.920", "favorite_count": 0, "id": "68126", "last_activity_date": "2020-06-30T01:12:48.123", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37841", "post_type": "question", "score": 0, "tags": [ "linux", "ubuntu", "vim", "wsl" ], "title": "Vim 同じウィンドウで現在編集中のシェルスクリプトをデバッグする方法", "view_count": 298 }
[ { "body": "`:terminal` は引数で実行するコマンドを指定できます。無指定の場合は `$SHELL` が使われるので、通常はシェルが立ち上がります。 \nつまり以下のようなコマンドを実行すれば、現在のバッファを `bash` に渡して実行できます。`%` は現在バッファの名前に置き換えられて実行されます。\n\n```\n\n :terminal bash %\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T01:12:48.123", "id": "68129", "last_activity_date": "2020-06-30T01:12:48.123", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2541", "parent_id": "68126", "post_type": "answer", "score": 1 } ]
68126
null
68129
{ "accepted_answer_id": null, "answer_count": 2, "body": "C言語で行列を表示したいのですが, `scanf` で値を代入するのではなく, 固定値として `for`\n文を利用してあらかじめ値を代入するにはどうすればよいですか.\n\n表示結果として以下の様になってほしいです.\n\n```\n\n A =\n 1 2 3 4\n 5 6 7 8\n 9 10 11 12\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T02:22:09.310", "favorite_count": 0, "id": "68131", "last_activity_date": "2021-05-24T09:08:50.880", "last_edit_date": "2020-06-30T02:36:50.333", "last_editor_user_id": "3060", "owner_user_id": "39937", "post_type": "question", "score": -2, "tags": [ "c", "行列" ], "title": "C言語での行列表示", "view_count": 4339 }
[ { "body": "1からその配列のサイズ分までループ回して、その数値を代入していけばいいですね", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T02:34:29.613", "id": "68133", "last_activity_date": "2020-06-30T02:34:29.613", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "27481", "parent_id": "68131", "post_type": "answer", "score": 0 }, { "body": "3行4列をそのまま2次元配列で表現して、後は順繰り(ここでfor-loopを使用)に要素へ値を設定していけばよいかと思います。\n\n```\n\n const int M = 3;\n const int N = 4;\n \n int A[M][N];\n \n for (int m = 0; m < M; m++) {\n for (int n = 0; n < N; n++) {\n A[m][n] = n + (N * m) + 1;\n }\n }\n \n printf(\"A = \\n\");\n for (int m = 0; m < M; m++) {\n printf(\" \");\n for (int n = 0; n < N; n++) {\n printf(\" %d\", A[m][n]);\n }\n printf(\"\\n\");\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-01T08:22:53.343", "id": "68181", "last_activity_date": "2020-07-01T08:22:53.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2808", "parent_id": "68131", "post_type": "answer", "score": 0 } ]
68131
null
68133
{ "accepted_answer_id": null, "answer_count": 0, "body": "Eclipse 2019-09 R (4.13.0) を使用しています。 \n添付画像の、背景色が白(とても薄いグレー)になっている部分の色を変えたいのですが、どの項目で変えられるのか分かりません。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/NfwXA.png)](https://i.stack.imgur.com/NfwXA.png)\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/Qa7wX.png)](https://i.stack.imgur.com/Qa7wX.png)\n\nどうやら、以下の条件が揃うとこの色になるようです:\n\n 1. リストの項目\n 2. 選択している\n 3. フォーカスしていない(Eclipseの他の部分にフォーカスしている)\n\nただ、全てのリストがこうなるわけではないみたいですが・・・ \n白だと非常に見辛いので変えたいです。 \n下の画像の入力補完の方は、渋々文字色を変えて対処しています・・・", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T02:25:59.307", "favorite_count": 0, "id": "68132", "last_activity_date": "2020-06-30T02:25:59.307", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8078", "post_type": "question", "score": 1, "tags": [ "eclipse" ], "title": "Eclipseの色設定が分からない", "view_count": 114 }
[]
68132
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "SwiftにてTabBar にボタン を設置して押したら横に遷移としたいのですが、以下のコードではボタン自体が表示されません。どうしたらいいでしょうか?\n\n```\n\n let button:UIButton = UIButton()\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // Do any additional setup after loading the view.\n \n // タブバーに重ねるボタンを作成\n // ここではサイズとか位置は気にしない。\n let image = UIImage(named: \"button.jpg\")\n self.button.setBackgroundImage(image, for: .normal)\n self.button.addTarget(self, action: Selector((\"openModal\")),\n for: UIControl.Event.touchUpInside)\n \n // self.view ではなくて、self.tabBar にaddSubviewする\n self.tabBar.addSubview(self.button)\n } \n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T07:28:31.860", "favorite_count": 0, "id": "68136", "last_activity_date": "2020-06-30T08:24:23.557", "last_edit_date": "2020-06-30T07:40:04.243", "last_editor_user_id": "3060", "owner_user_id": "39481", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "Swift TabBar にボタン", "view_count": 89 }
[ { "body": "`tabBar`は、\n\n```\n\n @IBOutlet weak var tabBar: UITabBar!\n \n```\n\nてな感じで宣言され、正しく表示されているものと仮定しています。\n\n一番問題のあるところは、あなた自身のコメントが示しているようです。\n\n```\n\n // ここではサイズとか位置は気にしない。\n \n```\n\nあなたのコードでは`button`のサイズや位置を表す`frame`が未設定のままですが、その場合の動作は未定義になります。最近のiOSでは、対象viewの左上隅(`(0,\n0)`)に大きさ(0, 0)で追加されるようです。大きさがゼロですから、「表示されません」と言うことになります。\n\n(なお、古いバージョンのiOSなら違う動作になるかもしれません。)\n\n表示されるようにしたければ、正しく`frame`を設定してやって下さい。\n\n```\n\n @IBOutlet weak var tabBar: UITabBar!\n \n let button: UIButton = UIButton()\n \n override func viewDidLoad() {\n super.viewDidLoad()\n // Do any additional setup after loading the view.\n \n // タブバーに重ねるボタンを作成\n let image = UIImage(named: \"button.jpg\")\n self.button.setBackgroundImage(image, for: .normal)\n //↓`Selector((\"openModal\"))`ではなく、`#selector(openModal)`を使う\n self.button.addTarget(self, action: #selector(openModal),\n for: .touchUpInside)\n // ここではサイズとか位置は気にしないといけない!\n let origin: CGPoint = .zero //位置\n let size = image!.size //サイズ\n self.button.frame = CGRect(origin: origin, size: size)\n \n // self.view ではなくて、self.tabBar にaddSubviewする\n self.tabBar.addSubview(self.button)\n }\n \n @objc func openModal() {\n print(#function)\n //...\n }\n \n```\n\n* * *\n\n直接「表示されません」と言う事象には関係ありませんが、`Selector((\"openModal\"))`という書き方は非推奨です。必ず`#selector`構文を使って下さい。これによりSwiftコンパイラーがメソッド名の綴りミスや、`@objc`の付け忘れなどをコンパイル時にチェックしてくれるようになります。\n\nまた、`UITabBar`のような標準UI部品のview階層や動作を変更しようとすると、iOSのバージョンによってはうまく動かなくなったりする可能性がある上に、ユーザを混乱させ、Appleから「Human\nInterface Guidelineに適合していない」と判断される可能性もあります。\n\n(最近ネットでApp Storeからrejectされた理由を追っていると、HIG準拠のチェックはゆるいのかなという気はしますが。)\n\nなぜこのようなことを試しているのかを示していただければ、より良い代替手段をご提示できるかもしれません。", "comment_count": 6, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T08:24:23.557", "id": "68140", "last_activity_date": "2020-06-30T08:24:23.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "68136", "post_type": "answer", "score": 1 } ]
68136
null
68140
{ "accepted_answer_id": "68143", "answer_count": 2, "body": "以下のコードのCellの部分を別のCustomCell.swiftなどで実装したいのですが、どうすればよいのでしょうか?\n\n```\n\n override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n let cell = UITableViewCell()\n let rp = repo[indexPath.row]\n cell.textLabel?.text = rp[\"full_name\"] as? String ?? \"\"\n cell.detailTextLabel?.text = rp[\"language\"] as? String ?? \"\"\n cell.tag = indexPath.row\n return cell\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T08:42:23.930", "favorite_count": 0, "id": "68141", "last_activity_date": "2020-06-30T09:17:40.057", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40856", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "TableViewのCellを別クラスに移行したい", "view_count": 131 }
[ { "body": "そもそもの元のコードですが、`tableView(_:cellForRowAt:)`の中で、`let cell =\nUITableViewCell()`のようにセルクラス(今の場合は、`UITableViewCell`クラス)のイニシャライザを使ってセルのインスタンスを生成するのは、「誤り」と言ってしまって良いでしょう。\n\nコンパイルエラーも実行時エラーも出ないのでやってしまいがちなのですが、システムに大きな負荷をかけ、スクロールにもやたらと時間がかかったりするようになります。\n\n`tableView(_:cellForRowAt:)`の中でセルのインスタンスを取得する場合、必ず`dequeueReusableCell(withIdentifier:for:)`、または`dequeueReusableCell(withIdentifier:)`のどちらかのメソッドを使用して下さい。\n\nCustomCell.swiftに`CustomCell`と言うクラスが定義してあるとすると、例えば次のようになります。\n\n```\n\n override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n let cell = tableView.dequeueReusableCell(withIdentifier: \"CustomCell\", for: indexPath) as! CustomCell\n let rp = repo[indexPath.row]\n cell.textLabel?.text = rp[\"full_name\"] as? String ?? \"\"\n cell.detailTextLabel?.text = rp[\"language\"] as? String ?? \"\"\n cell.tag = indexPath.row\n return cell\n }\n \n```\n\n(実際のカスタムセルの場合、`textLabel`やら`detailTextLabel`やらは、適切なプロパティ名に変えてやる必要があるでしょう。)\n\nちなみに危険な強制キャスト`as!`を使っていますが、これは「もし設定が間違えていたらアプリをクラッシュさせてくれ」と言う意味でわざとやっています。一度実行すれば確実に検出できるような場所では、このようにわざとクラッシュしてしまう書き方をする場合があります。\n\n* * *\n\nさて、上記のコードがクラッシュしないような設定ですが、`UITableViewController`を使うなら、storyboard上で設定した方が楽かもしれませんが、ここではコードで設定する方法を書いておきます。\n\n```\n\n override func viewDidLoad() {\n super.viewDidLoad()\n // Do any additional setup after loading the view.\n self.tableView.register(CustomCell.self, forCellReuseIdentifier: \"CustomCell\")\n //...\n }\n \n```\n\n最初のコードで`withIdentifier:`に`\"CustomCell\"`と言う文字列を指定していますが、その文字列は`CustomCell`と言うクラスを表しているんだよ、と言うのを登録することになります。\n\n(本当は`\"CustomCell\"`と言う文字列は定数宣言しておいた方が良いところです。)\n\n* * *\n\n実際に上記の修正をやってみて、どのように表示されるか試してみて下さい。うまくいかない点やよくわからない点があれば、またコメントなどでお知らせください。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T09:15:11.043", "id": "68143", "last_activity_date": "2020-06-30T09:15:11.043", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "68141", "post_type": "answer", "score": 0 }, { "body": "`viewDidLoad`等、`UITableView`のインスタンスをメンバーに持つクラスで、`UITableView`を使い始める前に対象の`UITableView`のインスタンスに \n`register(_:forCellReuseIdentifier:)`か、`register(_ nib: UINib?,\nforCellReuseIdentifier identifier:\nString)`で、この`identifier`にはこのカスタムセル(のクラス)を使ってねと登録する必要があります。\n\nただし、上のソースで\n\n```\n\n let cell = UITableViewCell()\n \n```\n\nと毎回新規に`cell`を作成していますが、 \n`dequeueReusableCell(withIdentifier identifier: String) ->\nUITableViewCell?`や、`dequeueReusableCell(withIdentifier identifier: String, for\nindexPath: IndexPath) ->\nUITableViewCell`で、再利用可能なセルがないか確認した方がセルを毎回新規に作るよりパフォーマンスが向上すると思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T09:17:40.057", "id": "68144", "last_activity_date": "2020-06-30T09:17:40.057", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "14745", "parent_id": "68141", "post_type": "answer", "score": 0 } ]
68141
68143
68143
{ "accepted_answer_id": null, "answer_count": 1, "body": "Swiftにてカスタムセル 二つ それぞれちがうVC から追加したいのですが\n\n大元を Tab - Navi - List ( UIVC ) ほかの二つを Post Fol とします どちらも UIVC です\n\nそのさい カスタムセル を表示する List にはどのように書けばよろしいでしょうか ?\n\n```\n\n func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n return mainArray.count\n }\n \n func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n let postcell = tableView.dequeueReusableCell(withIdentifier: \"postcell\")!\n postcell.textLabel?.text = mainArray[indexPath.row]\n return postcell\n } \n \n```\n\nだと ひとつしか 登録できない とおもうのですが\n\n**追記**\n\n大元のVC\n\n```\n\n class List: UIViewController, UITableViewDataSource, UITableViewDelegate {\n \n var mainArray: [String] = []\n let initArray: [String] = []\n \n override func viewDidLoad() {\n super.viewDidLoad()\n tableView.dataSource = self\n tableView.delegate = self\n \n // Do any additional setup after the view.\n }\n \n @IBOutlet weak var tableView: UITableView!\n \n func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n return mainArray.count\n }\n \n func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n let postcell = tableView.dequeueReusableCell(withIdentifier: \"postcell\")!\n postcell.textLabel?.text = mainArray[indexPath.row]\n return postcell\n }\n \n func tableView(_ tableView: UITableView, didSelectRowAt className: UITableViewCell) {\n \n switch className {\n case is PostCell:\n \n guard let viewControlelr = storyboard?.instantiateViewController(withIdentifier: \"Post\") as? Post else {\n return\n }; navigationController?.pushViewController(viewControlelr, animated: true)\n \n \n case is FolderCell:\n \n guard let list = storyboard?.instantiateViewController(withIdentifier: \"List\") as? List else {\n return\n }; navigationController?.pushViewController(list, animated: true)\n \n default:\n return\n }\n \n }\n \n }\n \n```\n\n投稿するVC Post\n\n```\n\n class Post: UIViewController {\n \n var postString: String = \"\"\n \n @IBOutlet weak var postTextField: UITextField!\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // Do any additional setup after loading the view.\n }\n \n @IBAction func postBack(_ sender: Any) {\n self.navigationController?.popToRootViewController(animated: true)\n \n postTextField.text = postString\n \n guard let list = tabBarController?.viewControllers?[0] as? List else {\n return\n }\n \n let postString = postTextField.text ?? \"\"\n \n list.tableView?.beginUpdates()\n list.tableView?.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)\n list.tableView?.endUpdates()\n } \n \n } \n \n```\n\nFolder用のセルの追加のVC Fol\n\nまだコードはないのですが Post とほぼ同じで 追加するカスタムセル が FolderCell なだけです\n\n**追記**\n\nList に protcol を追加すると\n\n```\n\n Protocol 'ListEntryDelegate' cannot be nested inside another declaration\n \n```\n\nと、extention では\n\n```\n\n Declaration is only valid at file scope \n \n Use of undeclared type 'ListEntryDelegate' \n \n```\n\nというエラーが出ます\n\nなにかちがうのでしょうか ?\n\n追記 1\n\n```\n\n struct ListEntry {\n enum CellType: String {\n case post = \"postcell\"\n case folder = \"foldercell\"\n }\n /// 種類\n var cellType: CellType\n \n /// テキスト\n var text: String\n \n var array: [String]\n \n // 一つのセルに表示する情報が増えればプロパティを増やす\n //...\n }\n \n```\n\nに Post また Fol から\n\n```\n\n listView.mainArray.insert(folString, at: 0) \n \n```\n\nしようとすると\n\n```\n\n Cannot convert value of type 'String' to expected argument type 'ListEntry' \n \n```\n\nが出ます\n\n**追記 2**\n\nPostCell をタップしたときはPostにpostStringを入れて\nFolderCellをタップしたときはListのmainArrayにFolCellの配列folArrayを入れてNavigation\nControllerで遷移したいのです\n\n**追記**\n\nPost でButtonを押した場合は PostCell を追加 Fol でButtonを押した場合は FolCell というのは Post\nのInsartになにを付け足せばいいのでしょうか ?", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T08:53:55.330", "favorite_count": 0, "id": "68142", "last_activity_date": "2020-08-27T12:46:46.670", "last_edit_date": "2020-08-27T12:46:46.670", "last_editor_user_id": "32986", "owner_user_id": "39481", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "Swift カスタムセル 二つ", "view_count": 223 }
[ { "body": "更新後のご質問内容を読んで、以下のように理解しました。\n\n * 2種類のカスタムセルを表示したい`UITableView`は`List`(ViewController)に一つだけ\n * その`UITableView`では、セクション0だけを使用する\n * そのセクション0内では、post用のセル、folder用のセルが混在して表示される\n\n何か認識間違いがあれば、早めにお知らせください。\n\n(動作に支障があるわけではないんですが、viewControllerに`List`なんて名前をつけるのは、あまりiOSアプリにはないのでコードが読みづらいですね。`ListViewController`か、せめて`ListVC`くらいにしておいた方が良いと思います。作りかけのアプリのクラス名を変えるといろいろ本質的でないところで苦労する場合があるため、以下では`List`(や`Post`)のままでいきます。)\n\n* * *\n\nさて、一つの`UITableView`に「2種類のカスタムセルを表示したい」なんてことをするとなれば、「どこかにセルの種類を区別するための情報が必要」と言うことになります。\n\n`mainArray`とは別の配列を用意してそちらに情報を入れると言う方法は、アプリが複雑になるうちにどんどん処理が煩雑になっていずれ破綻するのでやめておきます。\n\n「一つのセル」に対応する情報は、「一つの型」で表すようにしましょう。\n\n### ListEntry.swift\n\n```\n\n import Foundation\n \n struct ListEntry {\n enum CellType: String {\n case post = \"postcell\"\n case folder = \"foldercell\"\n }\n /// 種類\n var cellType: CellType\n \n /// テキスト\n var text: String\n \n // 一つのセルに表示する情報が増えればプロパティを増やす\n //...\n }\n \n```\n\n`List`の`mainArray`は、`String`の配列ではなく、この`ListEntry`の配列にします。\n\n```\n\n class List: UIViewController, UITableViewDataSource, UITableViewDelegate {\n \n var mainArray: [ListEntry] = []\n //let initArray: [String] = []\n \n override func viewDidLoad() {\n super.viewDidLoad()\n tableView.dataSource = self\n tableView.delegate = self\n \n // Do any additional setup after the view.\n //以下はstoryboardで設定しているなら不要\n tableView.register(PostCell.self, forCellReuseIdentifier: ListEntry.CellType.post.rawValue)\n tableView.register(FolderCell.self, forCellReuseIdentifier: ListEntry.CellType.folder.rawValue)\n }\n \n //...\n } \n \n```\n\n`register(_:forCellReuseIdentifier:)`の呼び出しは、storyboardでやっているのなら不要ですが、やっていないなら、セルの種類全てについて必ず呼び出しておいて下さい。\n\n* * *\n\nさて、実際にセルの種類によって処理を分けないといけないところは、`ListEntry`の`cellType`プロパティの値をもとに場合分けしてやります。\n\n例えば、`tableView(_:cellForRowAt:)`はこんな感じにしないといけないでしょう。\n\n```\n\n func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n let listEntry = mainArray[indexPath.row]\n switch listEntry.cellType {\n case .post:\n let postcell = tableView.dequeueReusableCell(withIdentifier: listEntry.cellType.rawValue, for: indexPath) as! PostCell\n //実際には`textLabel`でなく、`PostCell`の専用プロパティを使用する必要があると思われる\n postcell.textLabel?.text = listEntry.text\n return postcell\n case .folder:\n let foldercell = tableView.dequeueReusableCell(withIdentifier: listEntry.cellType.rawValue, for: indexPath) as! FolderCell\n //実際には`textLabel`でなく、`FolderCell`の専用プロパティを使用する必要があると思われる\n foldercell.textLabel?.text = listEntry.text\n return foldercell\n }\n }\n \n```\n\n(ちなみに、危険とされている`as!`を使っているのは、「設定間違えてたらクラッシュしてくれ」と言う意図でわざとです。)\n\n* * *\n\nさて、`tableView(_:didSelectRowAt:)`の方ですが、「種類による場合わけ」が間違った形で書かれているので、大幅に書き直してもらわないと予測不能の障害が起こります。\n\nどうせ大幅に書き換えるならと言うことで、`Post`(ViewController)内で`List`にアクセスしている部分を書き換えておきます。現在のコードですと、どのタブにどのVCを表示するのか、と言うデザイン上の変更があると、コードまで書き換えないといけなくなります。ある程度は仕方ないのですが、できるだけコードとデザインの分離をする、と言うのが良い設計と言うことになっています。\n\n今のところ`Post`でやっているのは要素の追加だけのようなので、次のようなプロトコルを用意して、`List`クラスにそのプロトコルを実装させておきます。\n\n(実際には「要素の編集」も必要な気がしますが、その辺り「2種類のセルを使い分ける」と言う主題から離れすぎるので、この回答ではこれ以上深入りしないことにします。)\n\n(`List`と同じファイルに追加すること想定。)\n\n```\n\n protocol ListEntryDelegate: class {\n func addEntry(_ entry: ListEntry, at index: Int)\n }\n \n extension List: ListEntryDelegate {\n func addEntry(_ entry: ListEntry, at index: Int) {\n mainArray.insert(entry, at: index)\n tableView.insertRows(at: [IndexPath(row: index, section: 0)], with: .automatic)\n }\n }\n \n```\n\n上記のデリゲートを使用する前提の`Post`は次のような感じになるでしょう。\n\n```\n\n class Post: UIViewController {\n \n weak var delegate: ListEntryDelegate? //<- 追加\n \n var postString: String = \"\"\n \n @IBOutlet weak var postTextField: UITextField!\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // Do any additional setup after loading the view.\n }\n \n @IBAction func postBack(_ sender: Any) {\n self.navigationController?.popToRootViewController(animated: true)\n \n let postString = postTextField.text ?? \"\"\n \n //↓自前で`List`のメソッドを呼び出したりせず、デリゲートのメソッドを呼び出す\n let newEntry = ListEntry(cellType: .post, text: postString)\n delegate?.addEntry(newEntry, at: 0) //<- いつでも先頭に追加で良い?\n }\n }\n \n```\n\nさて、`Fol`(ViewController)側(VCのクラス名なんて、そうなんども書く必要があるわけでもないので、もう少しわかりやすい名前にした方が良いと思います)にも同様の変更を施すと、先ほどの`List`クラスの`tableView(_:didSelectRowAt:)`は次のような感じになるでしょう。\n\n```\n\n func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\n let listEntry = mainArray[indexPath.row]\n switch listEntry.cellType {\n case .post:\n guard let postVC = storyboard?.instantiateViewController(withIdentifier: \"Post\") as? Post else {\n return\n }\n postVC.delegate = self\n postVC.postString = listEntry.text\n //その他`postVC`に伝えるべき情報があればここで設定\n //postVC.〜 = 〜\n navigationController?.pushViewController(postVC, animated: true)\n case .folder:\n guard let folderVC = storyboard?.instantiateViewController(withIdentifier: \"Folder\") as? Fol else {\n return\n }\n folderVC.delegate = self\n //その他`folderVC`に伝えるべき情報があればここで設定\n //folderVC.〜 = 〜\n navigationController?.pushViewController(folderVC, animated: true)\n }\n }\n \n```\n\n`tableView(_:didSelectRowAt:)`の`didSelectRowAt:`に渡されるのは`IndexPath`型の値です。それを`UITableViewCell`型で宣言すると、実行時に予測不可能な障害が発生する可能性があります。\n\n(実際にはSwiftコンパイラが「これは`UITableViewDelegate`の`tableView(_:didSelectRowAt:)`じゃない!」と判断して、呼び出しさえされないはずですが。)\n\n* * *\n\n変更が多岐にわたって少しみにくいかと思いますが、どのクラスのどの部分を修正するのかをよく読み取ってお試しいただければと思います。\n\nなにぶん読みにくくなってしまったので、わからない点やうまくいかない点など出てくると思いますが、\n\n * 「2種類のカスタムセルを表示したい」→この質問へのコメント\n * それ以外の事柄 →新規の質問を立てる\n\nと言った使い分けをしてもらえると、後からこのスレを読まれる方がこれ以上混乱せずに済むかと思います。\n\n* * *\n\n### ご質問の「追記」について → `List`クラスのまとめ。\n\n説明の都合を優先して、コードをバラバラに小出しにしてしまったので、混乱させてしまったようです。`List`クラスを記載するファイル(List.swift\n?)に上記のすべての修正を適用すると、以下のような感じになります。\n\n```\n\n import UIKit\n \n class List: UIViewController, UITableViewDataSource, UITableViewDelegate {\n \n var mainArray: [ListEntry] = []\n //let initArray: [String] = []\n \n override func viewDidLoad() {\n super.viewDidLoad()\n tableView.dataSource = self\n tableView.delegate = self\n \n // Do any additional setup after the view.\n //以下はstoryboardで設定しているなら不要\n tableView.register(PostCell.self, forCellReuseIdentifier: ListEntry.CellType.post.rawValue)\n tableView.register(FolderCell.self, forCellReuseIdentifier: ListEntry.CellType.folder.rawValue)\n }\n \n @IBOutlet weak var tableView: UITableView!\n \n func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n return mainArray.count\n }\n \n func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n let listEntry = mainArray[indexPath.row]\n switch listEntry.cellType {\n case .post:\n let postcell = tableView.dequeueReusableCell(withIdentifier: listEntry.cellType.rawValue, for: indexPath) as! PostCell\n //実際には`textLabel`でなく、`PostCell`の専用プロパティを使用する必要があると思われる\n postcell.textLabel?.text = listEntry.text\n return postcell\n case .folder:\n let foldercell = tableView.dequeueReusableCell(withIdentifier: listEntry.cellType.rawValue, for: indexPath) as! FolderCell\n //実際には`textLabel`でなく、`FolderCell`の専用プロパティを使用する必要があると思われる\n foldercell.textLabel?.text = listEntry.text\n return foldercell\n }\n }\n \n func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\n let listEntry = mainArray[indexPath.row]\n switch listEntry.cellType {\n case .post:\n guard let postVC = storyboard?.instantiateViewController(withIdentifier: \"Post\") as? Post else {\n return\n }\n postVC.delegate = self\n postVC.postString = listEntry.text\n //その他`postVC`に伝えるべき情報があればここで設定\n //postVC.〜 = 〜\n navigationController?.pushViewController(postVC, animated: true)\n case .folder:\n guard let folderVC = storyboard?.instantiateViewController(withIdentifier: \"Folder\") as? Fol else {\n return\n }\n folderVC.delegate = self\n //その他`folderVC`に伝えるべき情報があればここで設定\n //folderVC.〜 = 〜\n navigationController?.pushViewController(folderVC, animated: true)\n }\n }\n } //<- ここで`List`のクラス定義は一旦終わっている\n \n protocol ListEntryDelegate: class {\n func addEntry(_ entry: ListEntry, at index: Int)\n }\n \n extension List: ListEntryDelegate {\n func addEntry(_ entry: ListEntry, at index: Int) {\n mainArray.insert(entry, at: index)\n tableView.insertRows(at: [IndexPath(row: index, section: 0)], with: .automatic)\n }\n }\n \n```\n\n`ListEntryDelegate`や`ListEntryDelegate`を記載する場所が、やってみたのと違っているのではないでしょうか?\n(わかりにくくてすいませんでした。)この内容で再度お試しください。", "comment_count": 25, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T13:13:59.117", "id": "68152", "last_activity_date": "2020-07-01T14:22:33.397", "last_edit_date": "2020-07-01T14:22:33.397", "last_editor_user_id": "13972", "owner_user_id": "13972", "parent_id": "68142", "post_type": "answer", "score": 0 } ]
68142
null
68152
{ "accepted_answer_id": null, "answer_count": 1, "body": "WordPressで管理しているサイトで、ページスピードの改善の際に「レンダリングを妨げるリソースの除外をする」というのがあったので、それに対応するために、scriptタグにdefer属性を付与しようと考えました。 \nそこでfunctions.phpに以下のコードを書いたのですが、他のjsが効かなくなってしまったので、何が原因知りたいです。また、何か良い方法はありますか?\n\n```\n\n if(!(is_admin())){\n //JS非同期読み込み→defer属性を付加 \n function replace_scripttag($tag){\n if(!preg_match('/\\b(defer|async)\\b/',$tag)){\n return str_replace(\"type='text/javascript'\",'defer',$tag);\n }\n return $tag;\n }\n add_filter('script_loader_tag','replace_scripttag');\n \n }\n \n```\n\nまた、この方法ではdefer属性が付与するのですが、以下のサイトを参照し、以下のコードを使用しても付与しませんでした。こちらも原因や改善方法などご教授いただけたら嬉しく思います。 \n<https://kinsta.com/blog/defer-parsing-of-javascript/#functions>\n\n```\n\n function defer_parsing_of_js( $url ) {\n if ( is_user_logged_in() ) return $url; //don't break WP Admin\n if ( FALSE === strpos( $url, '.js' ) ) return $url;\n if ( strpos( $url, 'jquery.js' ) ) return $url;\n return str_replace( ' src', ' defer src', $url );\n }\n add_filter( 'script_loader_tag', 'defer_parsing_of_js', 10 );\n \n```\n\n今回私は「レンダリングを妨げるリソースの除外をする」をするためにdefer属性を付与しようと考えたのですが、こっちの方が良いよ!などの他の意見ございましたら、お教えください。 \nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T09:57:40.133", "favorite_count": 0, "id": "68146", "last_activity_date": "2020-08-10T15:16:36.227", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37613", "post_type": "question", "score": 0, "tags": [ "javascript", "php", "wordpress" ], "title": "WordPressでレンダリングを妨げるリソースの除外をする際にdefer属性をscriptタグに付けたのですが、jsが効かなくなってしまった。", "view_count": 122 }
[ { "body": "読み込みタイミングの変更が反映されてそれで不具合が発生したのならばおそらく読み込んでいるJSファイル間での依存関係がおかしくなったのでは無いのでしょうか。 \nつまり、ファイルAとファイルBで依存関係A → Bの場合、元々同期的に読み込んでいる場合はA →\nBの順で読み込めていたので問題は出なかったが、今回Aを`defer`にしたので先にBが実行されてしまいAで読み込む必要があったグローバル変数が初期化されずにBを実行する時コケてしまったなどがありそうです。\n\nそういった場合、可能かどうかはJS実行環境によりますが[dynamic\nimport](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/import)などがこの場合有効な手段になるかと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-08-10T15:16:36.227", "id": "69430", "last_activity_date": "2020-08-10T15:16:36.227", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "41455", "parent_id": "68146", "post_type": "answer", "score": 0 } ]
68146
null
69430
{ "accepted_answer_id": null, "answer_count": 1, "body": "foreach,function関数を使って引数の連想配列のインデックスと要素を表示する関数のプログラミングコードを教えてほしいです。<?php\n以降の文が全く分かりません。よろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T10:31:32.787", "favorite_count": 0, "id": "68148", "last_activity_date": "2020-07-24T05:36:37.520", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "40874", "post_type": "question", "score": 0, "tags": [ "php" ], "title": "引数の連想配列のインデックスと要素を表示する関数をphpで作成する方法", "view_count": 428 }
[ { "body": "質問文コメントのリンク先QAサイトで解決済みかもしれませんが、コード例は下記のようになります。\n\n```\n\n <?php\n // 連想配列を引数にとる関数\n function myfunc($array) {\n // 連想配列のインデックスと要素を列挙するforeach文\n foreach($array as $key => $value) {\n echo \"$key: $value\\n\";\n }\n }\n \n $array = array(\"hoge\" => \"foo\", \"fuga\" => \"bar\", \"piyo\" => \"buzz\");\n myfunc($array)\n ?>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-24T05:36:37.520", "id": "68882", "last_activity_date": "2020-07-24T05:36:37.520", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9820", "parent_id": "68148", "post_type": "answer", "score": 1 } ]
68148
null
68882
{ "accepted_answer_id": null, "answer_count": 1, "body": "# 解決したいこと\n\nHerokuSchedullerを使い、こちらが指定した時間で、rake\ntaskを実行させたいのですが、実行させるメール送信機能のPreview(`test/mailers/previews/alert_mailer_preview.rb`)にエラーが発生しており、解決したいと考えております。\n\nエラー内容:wrong number of arguments (given 0, expected 1)\n\nuserを引数として渡しているはずなのに、Preview画面では一向に変わらずお手上げ状態です。お力貸して頂けますと幸いです。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/0ENrf.png)](https://i.stack.imgur.com/0ENrf.png)\n\nこの後の **「send_alert」** をクリックすると、下記の通り、「引数が間違っている(wrong number of arguments\n(given 0, expected 1))」と怒られてしまいます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/2ZHdf.png)](https://i.stack.imgur.com/2ZHdf.png)\n\n# 環境\n\nRuby:2.6.5 \nRails:5.2.4 \nDB:PostgreSQL \nHeroku Scheduller\n\n# コード\n\n**mailers/previews/alert.mailer_previrew.rb**\n\n```\n\n # Preview all emails at http://localhost:3000/rails/mailers/alert_mailer\n class AlertMailerPreview < ActionMailer::Preview\n def send_alert(user)\n @user = user\n mail(\n to: @user.email,\n subject: '練習記録を登録しましょう!'\n )\n # mail to: \"#{@user.email}\", subject: \"Hello,#{@user.email}\"\n # mail to: user.email, subject: '練習記録を登録しましょう!'\n end\n end\n app/mailers/application_mailer.rb\n \n class ApplicationMailer < ActionMailer::Base\n default from: '[email protected]'\n layout 'mailer'\n end\n \n```\n\n**terminal**\n\n```\n\n Started GET \"/rails/mailers/alert_mailer/send_alert\" for ::1 at 2020-06-30 15:53:55 +0900\n Processing by Rails::MailersController#preview as HTML\n Parameters: {\"path\"=>\"alert_mailer/send_alert\"}\n Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)\n \n ArgumentError - wrong number of arguments (given 0, expected 1):\n test/mailers/previews/alert_mailer_preview.rb:3:in `send_alert'\n \n Started POST \"/__better_errors/30c7823ed90f92ce/variables\" for ::1 at 2020-06-30 15:53:55 +0900\n \n```\n\n**app/views/alert_mailer/send_alert.html.slim** \n**app/views/alert_mailer/send_alert.text.html.slim**\n\n```\n\n = user.mail 様\n \n この度は「TTManager」を利用頂きましてありがとうございます。\n br/\n 練習記録の登録はお済みですか?お済みでない場合は、こちらからログインをお願い致します。\n br/\n = link_to 'https://vast-anchorage-69571.herokuapp.com/', do\n | ログインはこちら\n span\n \n```\n\n**app/models/user.rb**\n\n```\n\n class User < ApplicationRecord\n # Include default devise modules. Others available are:\n # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable\n devise :database_authenticatable, :registerable,:recoverable, :rememberable, :validatable, password_length: 6..128\n has_many :records\n \n def self.guest\n find_or_create_by(email: \"[email protected]\") do |user|\n user.password = SecureRandom.urlsafe_base64\n # user.confirmed_at = Time.now # Confirmable を使用している場合は必要\n end\n end\n end\n \n```\n\n**app/mailers/alert.mailer.rb**\n\n```\n\n class AlertMailer < ApplicationMailer\n def send_alert(user)\n @user = user\n mail to: @user.email, subject: '練習記録を登録しましょう!'\n # mail to: \"#{@user.email}\", subject: \"Hello,#{@user.email}\"\n # mail to: user.email, subject: '練習記録を登録しましょう!'\n end\n end\n \n```", "comment_count": 10, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T12:18:39.343", "favorite_count": 0, "id": "68150", "last_activity_date": "2020-07-03T00:15:31.587", "last_edit_date": "2020-07-03T00:12:50.023", "last_editor_user_id": "3060", "owner_user_id": "39475", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "ruby", "gmail" ], "title": "ActionMailerのPreview起動時に、引数が間違っている(wrong number of arguments (given 0, expected 1))と怒られるので解消したい", "view_count": 4110 }
[ { "body": "# 解決した方法\n\n**mailers/previews/alert.mailer_previrew.rb**\nを下記のように変更すると、「引数が間違っている」というエラーが解消しました。別のエラー(No Method\nError)が発生していますが、そちらは自分で解決策考えようと思います(nakanishiさん、ご指摘頂きありがとうございました)。\n\n### 修正前のコード\n\n```\n\n class AlertMailerPreview < ActionMailer::Preview\n def send_alert(user)\n @user = user\n mail(\n to: @user.email,\n subject: '練習記録を登録しましょう!'\n )\n # mail to: \"#{@user.email}\", subject: \"Hello,#{@user.email}\"\n # mail to: user.email, subject: '練習記録を登録しましょう!'\n end\n end\n \n```\n\n### 修正後のコード\n\n```\n\n class AlertMailerPreview < ActionMailer::Preview\n def send_alert\n @user = User.all\n AlertMailer.send_alert(@user)\n end\n end\n \n```\n\n### やったこと\n\n 1. `alert_mailer_preview.rb` では 引数 `(user)` を消した\n 2. 全ユーザーへの送信をテストしたいと思ったので、`@user = User.all` に変更した\n 3. 他Qiitaの記事を見て、`Mailer.アクション名(引数)` と記載した", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-02T23:39:31.293", "id": "68230", "last_activity_date": "2020-07-03T00:15:31.587", "last_edit_date": "2020-07-03T00:15:31.587", "last_editor_user_id": "3060", "owner_user_id": "39475", "parent_id": "68150", "post_type": "answer", "score": 1 } ]
68150
null
68230
{ "accepted_answer_id": null, "answer_count": 3, "body": "問題は「ハイフンで結合された単語の文字列を入力とし、ソートされた単語をハイフンで結合した文字列を返す関数を定義しなさい」です。 \n実装例として、以下 \ndef hyphen_sorted(connectedstring):\n\nprint(hyphen_sorted('red-green-blue'))\n\n実行例として \n'blue-green-red' \nとなるようにしたいです。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T13:00:53.027", "favorite_count": 0, "id": "68151", "last_activity_date": "2020-07-01T01:29:36.853", "last_edit_date": "2020-06-30T15:07:58.117", "last_editor_user_id": "19110", "owner_user_id": "40880", "post_type": "question", "score": -1, "tags": [ "python", "python3" ], "title": "pythonを用いています。以下のプログラムが作れなくて困っています。", "view_count": 229 }
[ { "body": "Split \nSorted \nJoin \nあたり組み合わせればなんとかなりそう", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T13:52:01.307", "id": "68154", "last_activity_date": "2020-06-30T13:52:01.307", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18637", "parent_id": "68151", "post_type": "answer", "score": 1 }, { "body": "Splitは文字列を分解する時に使用します。 \nここではred-green-blueを-で分解し、バラバラにします。 \nその後、Sortedでソートし、Joinでつなぎ合わせます。 \nスタックオーバーフローでは宿題の答えそのもの回答を求めることは、 \nあまりよく思われません。 \nヒントを元に自分でプログラムを書いてみて、それがうまく動作しない場合は、 \n再度質問すれば、回答してもらえると思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-01T01:29:24.397", "id": "68160", "last_activity_date": "2020-07-01T01:29:24.397", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24490", "parent_id": "68151", "post_type": "answer", "score": 0 }, { "body": "あまりシンプルではないですが、書いてみました。 \nこんな感じでどうでしょうか。\n\n```\n\n def hyphen_sorted(connectedstring):\n string_list = connectedstring.split('-')\n string_list.sort()\n return '-'.join(string_list)\n \n print(hyphen_sorted('red-green-blue'))\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-01T01:29:36.853", "id": "68161", "last_activity_date": "2020-07-01T01:29:36.853", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29034", "parent_id": "68151", "post_type": "answer", "score": 0 } ]
68151
null
68154
{ "accepted_answer_id": null, "answer_count": 2, "body": "問題は「与えられた単語が回文かどうかを調べる関数 isPalindrome を定義しなさい」です。\n\nテストコード\n\nprint(isPalindrome('Madam')) \nprint(isPalindrome('hello')) \nTrue \nFalse", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T13:44:48.720", "favorite_count": 0, "id": "68153", "last_activity_date": "2020-07-01T01:18:51.990", "last_edit_date": "2020-06-30T15:06:54.107", "last_editor_user_id": "19110", "owner_user_id": "40880", "post_type": "question", "score": -1, "tags": [ "python", "python3" ], "title": "回文かどうかを調べる関数がわかりません。", "view_count": 458 }
[ { "body": "スライス[::-1] \nUpper \nを組み合わせればなんとかなりそう", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-06-30T14:31:52.727", "id": "68155", "last_activity_date": "2020-06-30T14:31:52.727", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18637", "parent_id": "68153", "post_type": "answer", "score": 1 }, { "body": "回文かどうかを調べる関数を作成し、回文であればTrue、回文でなければFalseを返す関数を作成することになります。従って \n1 引数の文字の一番最初と一番最後を比較し、同じでなければFalseをかえす。 \n2 引数の頭から2番目と、最後から2番目を比較し、同じでなければFalseをかえす。 \n3 引数の頭から3番目と、最後から3番目を比較し、同じでなければFalseをかえす。 \n4 上記の処理を文字列の最後まで繰り返し、FalseにならなければTrueを返す。 \n文字列が偶数の場合はいいですが、奇数の場合は真ん中の文字は何でもいいことになりますので、 \n注意が必要です。 \n例 \nABBAは回文 \nABCBAも回文 \nABCABは回文じゃない。\n\nというような、プログラムを書くことになります。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-07-01T01:14:24.357", "id": "68159", "last_activity_date": "2020-07-01T01:18:51.990", "last_edit_date": "2020-07-01T01:18:51.990", "last_editor_user_id": "24490", "owner_user_id": "24490", "parent_id": "68153", "post_type": "answer", "score": 0 } ]
68153
null
68155