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": "機械学習でrandom stateを変更しながら、出力をしています。 \n例えば、以下のプログラムで、random stateを0から20まで、全ての値を出力させるようなプログラムは可能でしょうか。 \n現状では、手作業で0から20まで変更して、いちいちjupyter notebook上で出力しています。\n\n```\n\n import numpy as np\n from sklearn.ensemble import RandomForestClassifier\n from sklearn.model_selection import LeaveOneOut\n from sklearn.model_selection import cross_val_score\n \n forest=RandomForestClassifier(n_estimators=100,random_state=0)\n data = np.loadtxt('mh.csv', delimiter=',',skiprows=1,dtype=float)\n labels = data[:, 0:1]\n features = data[:, 1:]\n loo=LeaveOneOut() \n scores = cross_val_score(forest, features, labels.ravel(), cv=loo) \n \n print('Mean accuracy: {:.3f}'.format(scores.mean())) \n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-23T13:43:37.917", "favorite_count": 0, "id": "52973", "last_activity_date": "2019-02-25T00:25:20.583", "last_edit_date": "2019-02-25T00:25:20.583", "last_editor_user_id": "3060", "owner_user_id": "31804", "post_type": "question", "score": 0, "tags": [ "python", "numpy" ], "title": "random stateを変えた値の出力の仕方", "view_count": 2757 }
[ { "body": "「ほぼ同じことを何回も繰り返す」というタスクなので、for文を使えばできます。しかも今回は「0から20まで変えながら繰り返す」という場合なので、単純にひとつの変数を0から20まで変化させながら繰り返すだけで良いです。\n\nたとえば下のプログラムは0から20までの数を出力します。\n\n```\n\n for i in range(0, 21):\n print(i)\n \n```\n\nこれと同じようにしつつfor文の中身を変えることで今回の問題は解決できます。\n\nおそらく何かしらの資料からPythonのプログラムをコピー&ペーストしつつ機械学習を学ばれている最中なのだと思います。より発展的なことがしたくなった場合Pythonというプログラミング言語自体をある程度理解しておかないと立ち行かなくなりますので、どれかひとつでもPythonのチュートリアルをこなしておくと今後ラクかと思います。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T13:22:19.180", "id": "52996", "last_activity_date": "2019-02-24T13:22:19.180", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "52973", "post_type": "answer", "score": 2 } ]
52973
null
52996
{ "accepted_answer_id": "52977", "answer_count": 1, "body": "Microsoft Docsで以下のページを見つけました。 \n<https://docs.microsoft.com/ja-jp/previous-versions/cc440974(v=msdn.10)> \n<https://docs.microsoft.com/ja-jp/previous-versions/cc406725(v=msdn.10)> \n2001年頃に出版されたようなのですが、この文章の書名をご存知の方はいらっしゃいますか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-23T15:16:29.660", "favorite_count": 0, "id": "52976", "last_activity_date": "2019-02-23T16:26:10.380", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29331", "post_type": "question", "score": 1, "tags": [ "c#" ], "title": "Microsoft Docsの文章:C#についての文章の引用元が分からない", "view_count": 83 }
[ { "body": "矢島聡 著 [C# プログラミングリファレンス](https://docs.microsoft.com/ja-jp/previous-\nversions/cc440970\\(v=msdn.10\\))というものみたいです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-23T16:26:10.380", "id": "52977", "last_activity_date": "2019-02-23T16:26:10.380", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2808", "parent_id": "52976", "post_type": "answer", "score": 2 } ]
52976
52977
52977
{ "accepted_answer_id": "52988", "answer_count": 1, "body": "webpackの設定をしているのですが、 \nloaderを配列で指定した場合、読み込む順番は、index番号が若い順で読み込まれるのでしょうか?\n\n```\n\n module.exports = {\r\n module: {\r\n rules: [\r\n {\r\n test: /\\.css$/,\r\n use: ['vue-style-loader', 'css-loader'] // vue-style-loaderが読み込まれてからcss-loaderが読み込まれる?\r\n },\r\n ],\r\n },\r\n }\n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T01:48:34.293", "favorite_count": 0, "id": "52984", "last_activity_date": "2019-02-24T04:36:37.490", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29531", "post_type": "question", "score": 0, "tags": [ "webpack" ], "title": "useを配列にした場合のloaderの読み込み順", "view_count": 268 }
[ { "body": "複数のloaderを適用する場合、 **右から左に適用されます** 。\n\nこの場合、cssファイルにまず`css-loader`が適用され、次に`vue-style-loader`が適用されます。\n\n[webpackのドキュメント](https://webpack.js.org/configuration/module/#ruleuse)に記載があります。\n\n> Loaders can be chained by passing multiple loaders, which will be applied\n> from right to left (last to first configured).\n\n推測ですが、`require`でインラインにloaderを指定する記法(`require('vue-style-loader!css-\nloader!./app.css')`)の場合は右から左に適用されると理解するのが自然なので、それに合わせているのではないかと思います。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T04:36:37.490", "id": "52988", "last_activity_date": "2019-02-24T04:36:37.490", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30079", "parent_id": "52984", "post_type": "answer", "score": 0 } ]
52984
52988
52988
{ "accepted_answer_id": null, "answer_count": 1, "body": "Javascriptを学んでおります。\n\n書き方がいくつかあるかと思うのですが、一般的な書き方は \n下記の2種類のうち、どちらが主流なのでしょうか?(これ以外の書き方もありますか?) \nまたそれぞれの書き方のメリット・デメリットはありますでしょうか?\n\nサイトによって書き方がバラバラで初心者にとって \n最初はどっちで書けばいいのかいまいちわかりません。\n\nよろしくお願いいたします。\n\n```\n\n function animal1(name, age, sex) {\r\n this.name = name,\r\n this.age = age,\r\n this.sex = sex,\r\n this.getName = function() {\r\n console.log(name);\r\n },\r\n this.getAge = function() {\r\n console.log(age);\r\n }\r\n this.getSex = function() {\r\n console.log(sex);\r\n }\r\n };\r\n \r\n var animal2 = function(name, age, sex) {\r\n this.name = name,\r\n this.age = age,\r\n this.sex = sex,\r\n this.getName = function() {\r\n console.log(name);\r\n },\r\n this.getAge = function() {\r\n console.log(age);\r\n }\r\n this.getSex = function() {\r\n console.log(sex);\r\n }\r\n };\r\n \r\n var tama = new animal1(\"tama\" , 13, \"female\");\r\n tama.getName();\r\n \r\n var mike = new animal2(\"mike\" , 11, \"male\");\r\n mike.getName();\n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T05:00:23.013", "favorite_count": 0, "id": "52989", "last_activity_date": "2019-02-25T06:17:31.960", "last_edit_date": "2019-02-24T05:08:08.563", "last_editor_user_id": "26264", "owner_user_id": "26264", "post_type": "question", "score": 4, "tags": [ "javascript" ], "title": "Javascriptのオブジェクトの書き方はどちらが主流なのでしょうか?", "view_count": 197 }
[ { "body": "前者 **関数宣言** のメリット\n\n * 関数式よりコードがシンプル\n * ソース上で、関数宣言より上に関数を呼ぶコードを書ける\n\n```\n\n var tama = new animal1(\"tama\", 13, \"female\");\n function animal1(name, age, sex) {\n ...\n }\n \n```\n\n後者 **関数式** のメリット\n\n * クラスのメソッドを書くには関数式にするしかなく、コンストラクタも関数式にしたほうが一貫性がある。\n * 関数を名前空間内に置くには、関数宣言だと二度手間になるので関数式のほうがシンプル。\n\n```\n\n // 名前空間 com.example.zoo の定義\n const com = {};\n com.example = {};\n com.example.zoo = {};\n // animal2 を 名前空間 com.example.zoo 内で定義\n com.example.zoo.animal2 = function(name, age, sex) { ... };\n // インスタンス化\n let mike = new com.example.zoo.animal2(...);\n \n```\n\n以上を踏まえても、 **たいした違いではないのでどっちでも**\n好きな方を選べばよいと思います。どちらかというと前者のほうがよく見るような気がしますが、個人的な印象でしかありません。\n\n状況が許すなら、最近はclass構文が好まれるという印象です。\n\n```\n\n class animal3 {\n constructor(name, age, sex) {\n this.name = name;\n this.age = age;\n this.sex = sex;\n }\n \n getName() {\n console.log(this.name);\n }\n \n getAge() {\n console.log(this.age);\n }\n \n getSex() {\n console.log(this.sex);\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T01:28:42.780", "id": "53005", "last_activity_date": "2019-02-25T06:17:31.960", "last_edit_date": "2019-02-25T06:17:31.960", "last_editor_user_id": "3475", "owner_user_id": "3475", "parent_id": "52989", "post_type": "answer", "score": 6 } ]
52989
null
53005
{ "accepted_answer_id": null, "answer_count": 3, "body": "QZSSのL1S信号を受信しようとおもっております。\n\n[SPRESENSE\nGNSS測位情報のNMEA出力方法について](https://ja.stackoverflow.com/questions/49401/spresense-\ngnss%E6%B8%AC%E4%BD%8D%E6%83%85%E5%A0%B1%E3%81%AEnmea%E5%87%BA%E5%8A%9B%E6%96%B9%E6%B3%95%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6)\n\n上記の投稿を参考にしてすすめましたが、NMEAセンテンスにて$QZGSVは受信できましたが、$QZQSMセンテンスをが受信できません。\n\nATコマンドは下記のように投げております。他にも必要なコマンドがございましたらご教授いただければ幸いです。 \n@GNS 0x29 \n@GCD \n\\---- NMEA出力 ----- \n@GSTP \n@AEXT", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T08:27:19.007", "favorite_count": 0, "id": "52991", "last_activity_date": "2019-04-26T01:20:28.740", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32300", "post_type": "question", "score": 2, "tags": [ "spresense" ], "title": "SPRESENSE $QZQSMセンテンスの受信について", "view_count": 580 }
[ { "body": "SPRESENSE SDKのNMEA出力ライブラリは下記のセンテンスのみ対応しているようです。 \n$xxGGA \n$xxGLL \n$xxGSA \n$xxGSV \n$xxGNS \n$xxRMC \n$xxVTG \n$xxZDA\n\n参考リンク \n<https://developer.sony.com/develop/spresense/developer-tools/api-\nreference/api-references-spresense-sdk/group__gnss__nmea.html> \n<https://developer.sony.com/ja/develop/spresense/developer-tools/get-started-\nusing-nuttx/nuttx-developer-guide#_nmea_output>\n\n両者で記載内容が微妙に異なっているのがちょっと気になりますが…", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T02:47:43.603", "id": "53200", "last_activity_date": "2019-03-05T02:47:43.603", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30568", "parent_id": "52991", "post_type": "answer", "score": 2 }, { "body": "ソニーのSPRESENSEサポート担当です。 \nご返事が遅くなり、大変申し訳ありません。\n\nお問い合わせのQZSSの$QZQSMによる災忌通報の通知についてですが、 \n残念ながら現在のファームウェアではまだ対応しておりません。 \nこちら現在検討を行っており、4月のアップデートにて対応を予定しております。\n\n今後ともSPRESENSEをどうぞよろしくお願いいたします。\n\nSPRESENSEサポートチーム", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-13T04:57:39.350", "id": "53395", "last_activity_date": "2019-04-26T01:18:49.313", "last_edit_date": "2019-04-26T01:18:49.313", "last_editor_user_id": "29520", "owner_user_id": "29520", "parent_id": "52991", "post_type": "answer", "score": 1 }, { "body": "ソニーのSPRESENSEサポート担当です。\n\nQZSSの$QZQSMによる災危通報の通知についてですが、 \n昨日リリースされましたSDK バージョン 1.2.1にて対応を致しました。 \n是非こちらのバージョンに更新頂き引き続きご利用いただけますでしょうか。\n\n今後ともSPRESENSEをどうぞよろしくお願いいたします。\n\nSPRESENSEサポートチーム", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-04-26T01:20:28.740", "id": "54487", "last_activity_date": "2019-04-26T01:20:28.740", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29520", "parent_id": "52991", "post_type": "answer", "score": 0 } ]
52991
null
53200
{ "accepted_answer_id": null, "answer_count": 1, "body": "makeコマンドにてビルドした際にエラーが発生しています。 \nLinuxの設定が悪いのか、Makefileの作りが悪いのか、シェルの作りが悪いのか判断できないため、ご教示頂きたいです。\n\n## 環境\n\n * raspberry pi 3 B+\n * openSUSE 64bit\n * Makefileとその中で呼び出しているシェルスクリプト \n * Makefile \n<https://github.com/hyperledger/fabric/blob/release-1.4/Makefile>\n\n * シェルスクリプト \n<https://github.com/hyperledger/fabric/blob/release-1.4/scripts/goListFiles.sh>\n\n## エラー内容\n\n```\n\n Creating .build/goshim.tar.bz2\n make: execvp: /bin/sh: Argument list too long\n make: *** [Makefile:316: .build/goshim.tar.bz2] Error 127\n \n```\n\n## エラー発生箇所\n\n```\n\n GOSHIM_DEPS = $(shell ./scripts/goListFiles.sh $(PKGNAME)/core/chaincode/shim)\n orderer: $(BUILD_DIR)/bin/orderer\n \n $(BUILD_DIR)/goshim.tar.bz2: $(GOSHIM_DEPS)\n @echo \"Creating $@\"\n @tar -jhc -C $(GOPATH)/src $(patsubst $(GOPATH)/src/%,%,$(GOSHIM_DEPS)) > $@\n \n```\n\n## 試したこと\n\n### 1.シェルの引数をxargsで分割してみる\n\n同じエラーが発生し、解決しませんでした。 \n下記に`@tar -jhc -C $(GOPATH)/src $(patsubst\n$(GOPATH)/src/%,%,$(GOSHIM_DEPS))`を置き換えたMakefileの一文を記載します。\n\n```\n\n @./scripts/goListFiles.sh $(PKGNAME)/core/chaincode/shim | sed s#$(GOPATH)/src/##g | xargs tar -jhc -C $(GOPATH)/src > $@\n \n```\n\n### 2.シェル引数の上限値を上げる\n\n下記で表示される値をあげてみましたが解決しませんでした。\n\n```\n\n getconf ARG_MAX\n \n```\n\n### 3.ARMでなく、x64のubuntu, centOSでビルド\n\nこちらは問題なくビルドが成功しました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T10:44:40.517", "favorite_count": 0, "id": "52994", "last_activity_date": "2019-02-24T20:21:49.157", "last_edit_date": "2019-02-24T14:13:19.727", "last_editor_user_id": "32047", "owner_user_id": "32047", "post_type": "question", "score": 2, "tags": [ "linux", "bash", "shellscript", "makefile" ], "title": "makeコマンドでビルド中に「make: execvp: /bin/sh: Argument list too long」エラーが発生", "view_count": 860 }
[ { "body": "GNU tarではアーカイブに追加するファイルを引数に指定する代わりに、`-T`オプションで指定したファイルから読み込ませることができます。\n\nRaspberry\npiのtarがこのオプションをサポートしていれば、ファイルのリストを適当なファイルに書き出して、tarの`-T`オプションでそのファイルを指定してみてはどうでしょうか。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T20:21:49.157", "id": "53001", "last_activity_date": "2019-02-24T20:21:49.157", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9464", "parent_id": "52994", "post_type": "answer", "score": 1 } ]
52994
null
53001
{ "accepted_answer_id": null, "answer_count": 0, "body": "お世話になります。 \n試験的にWordpressでブログを作って、運用してみています。 \nそこで、少し困ったことがあるので、質問させてください。 \n新規投稿を追加した際、保存したりせずにF5キーを押すと、勝手に記事IDが1増えてしまいます。 \nこれを増えないようにする方法ってないのでしょうか。 \nとりあえず、ざっと検索して、自動保存を無効化したらよいのかと思い、テーマディレクトリにある「functions.php」に下記記述を追加してみたりしたのですが、うまくいかないようです。\n\n```\n\n function autosave_stop(){\n wp_deregister_script(\"autosave\");\n }\n \n add_action(\"wp_print_scripts\", \"autosave_stop\");\n \n```\n\n何かよい方法があれば、教えていただけると幸いです。 \nなお、Wordpressは5.1を利用しています。\n\n以上、よろしくお願いいたします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T11:49:07.840", "favorite_count": 0, "id": "52995", "last_activity_date": "2019-02-24T11:49:07.840", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29034", "post_type": "question", "score": 0, "tags": [ "wordpress" ], "title": "Wordpressの記事の自動保存を無効化する方法", "view_count": 40 }
[]
52995
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "Manjaro Linuxがカーネルパニックを起こしたため、chrootを使った手法で修復を試みたのですが、最後の/mntのumountで \"umount:\n/mnt/dev/pts: target is busy\" とエラーになりumountできません。\n\n`fuser -v /mnt` で使用状況を確認したところ以下のようになっていました。\n\n```\n\n /mnt root kernel mount /mnt\n \n```\n\n現在のディレクトリは `pwd` で確認したところ `/` になっていました。\n\nどうすれば良いでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T14:58:26.673", "favorite_count": 0, "id": "52997", "last_activity_date": "2020-09-18T21:08:10.850", "last_edit_date": "2020-01-09T01:37:17.700", "last_editor_user_id": null, "owner_user_id": "32305", "post_type": "question", "score": 0, "tags": [ "linux", "kernel" ], "title": "\"umount: /mnt/dev/pts: target is busy\" とエラー表示され umount できない", "view_count": 494 }
[ { "body": "`/mnt/dev/pts` は chroot したさきの 仮想端末のデバイスファイルだと思います。 \n現在使用している 端末画面(黒い画面)が終了すれば busy 状態は解消すると思います。 \nなので、exitでchrootを終了してから umount /mnt だとどうですか?\n\n```\n\n # exit\n # umount /mnt\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T00:05:13.427", "id": "53002", "last_activity_date": "2019-02-25T02:04:33.007", "last_edit_date": "2019-02-25T02:04:33.007", "last_editor_user_id": "5008", "owner_user_id": "5008", "parent_id": "52997", "post_type": "answer", "score": 1 } ]
52997
null
53002
{ "accepted_answer_id": "53017", "answer_count": 1, "body": "自分なりに実装したのですがほんとは間違って言うであるやり方をしてる点がありましてそこをほんとはこう書いたほうがいいみたいなことが知りたくて質問をしました。 \n1 static int player_xみたいなやり方はほんはまずいのかと \n2 //各オブジェクト宣言 の部分はどうすればいいのか知りたい。 \nそれと将来性のあるちゃんとしたコードを書くためににはどうすればいいのか知りたい\n\n```\n\n #include \"DxLib.h\"\n #include \"math.h\"\n #include <string>\n using namespace std;\n static int key[256];\n static int Color = GetColor(255, 255, 255);\n static int player_x = 0;//プレイヤーのX座標\n static int player_y = 0;//プレイヤーのY座標\n \n //キー入力関数\n int KeyBord_Get(int keycode)\n {\n \n char tmpkey[256];\n GetHitKeyStateAll(tmpkey);\n for (int i = 0; i < 256; i++)\n {\n if (tmpkey[i] != 0)\n {\n key[i]++;\n }\n else\n {\n key[i] = 0;\n }\n \n }\n \n return key[keycode];\n }\n \n \n //ショットクラス\n class Shot\n {\n \n int width;\n int height;\n \n int gh;\n \n public:\n bool life;\n \n int x;\n int y;\n void Initialize(int xx,int yy,int ww,int hh,const char *ch)//初期化\n {\n x = xx;\n y = yy;\n width = ww;\n height = hh;\n life = false;\n gh = LoadGraph(ch);//画像読み込み\n \n }\n \n void Update()//計算\n {\n //確認用デバック\n DrawFormatString(0, 0, Color, \"test\");\n \n if (life == true)\n {\n y = y - 4;\n \n if (y < -10)\n {\n life = false;\n }\n }\n \n Draw();\n \n }\n \n void Draw()//描画\n {\n DrawGraph(x, y, gh, true);\n \n }\n \n };\n \n \n //ショット管理クラス\n class Player_Shot_Manager\n {\n private:\n \n #define shot_max 50\n int x;\n int y;\n bool state;\n int count;\n //Shot shot;\n Shot shot[shot_max];\n \n public:\n \n //初期化\n void Initilize()\n {\n state = false;\n count = 0;\n \n for (int i = 0; i < shot_max; i++)\n {\n //弾画像を読み込み\n \n shot[i].Initialize(-50, -50, 14, 3, \"resources/Player_Shot.png\");\n \n }\n \n \n }\n \n //更新\n void Update()\n {\n if (KeyBord_Get(KEY_INPUT_Z) >= 1)\n {\n if (count % 10 == 0)\n {\n state = true;\n if (state = true)\n {\n for (int i = 0; i < shot_max; i++)\n {\n if (shot[i].life == false)\n {\n shot[i].life = true;\n shot[i].x = player_x;\n shot[i].y = player_y;\n \n break;\n }\n \n }\n }\n }\n else\n {\n state = false;\n }\n }\n else {\n state = true;\n }\n \n for (int i = 0; i < shot_max; i++)\n {\n \n shot[i].Update();\n \n }\n \n count++;\n \n }\n \n \n //描画\n void Draw()\n {\n \n }\n \n \n };\n \n \n \n //プレイヤークラス\n class Player_Control\n {\n \n private:\n \n int gh;\n \n \n int width;\n int height;\n \n bool flag;\n \n \n public:\n int x;\n int y;\n Player_Control()\n {\n \n }\n \n void Draw()\n {\n DrawGraph(x, y, gh, true);\n //DrawGraph(x,y - 3,gh,true);\n \n \n }\n \n void Update()\n {\n player_x = x;\n player_y = y;\n if (KeyBord_Get(KEY_INPUT_UP) >= 1)\n {\n y = y - 2;\n }\n if (KeyBord_Get(KEY_INPUT_RIGHT) >= 1)\n {\n x = x + 2;\n }\n if (KeyBord_Get(KEY_INPUT_LEFT) >= 1)\n {\n x = x - 2;\n }\n if (KeyBord_Get(KEY_INPUT_DOWN) >= 1)\n {\n y = y + 2;\n }\n \n \n \n }\n \n void Initialize()\n {\n gh = LoadGraph(\"resources/Player.png\");\n //DrawFormatString(0,0,Color,\"aaaaa\");\n x = 200;\n y = 200;\n \n width = 45;\n height = 45;\n \n }\n \n };\n \n //各オブジェクト宣言\n Player_Shot_Manager shot;\n Player_Control player;\n \n //初期化\n void Game_Initialize()\n {\n shot.Initilize();\n player.Initialize();\n }\n //計算\n void Game_Update()\n {\n shot.Update();\n player.Update();\n \n }\n //描画\n void Game_Draw()\n {\n //Player_Shot_Manager.Draw();\n player.Draw();\n \n }\n \n int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {\n ChangeWindowMode(TRUE);\n if (DxLib_Init() == -1) { return -1; }\n \n \n Game_Initialize();\n //int x = LoadGraph(\"resources/Player_Shot.png\");\n while (ClearDrawScreen() == 0 && SetDrawScreen(DX_SCREEN_BACK) == 0 && ProcessMessage() == 0)\n {\n \n Game_Update();\n \n \n \n Game_Draw();\n \n //DrawGraph(100,100,x,true);\n \n \n \n \n ScreenFlip();\n if (CheckHitKey(KEY_INPUT_ESCAPE) == 1) { break; }\n }\n return 0;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-24T19:11:40.063", "favorite_count": 0, "id": "53000", "last_activity_date": "2019-02-25T06:18:35.713", "last_edit_date": "2019-02-25T01:11:10.187", "last_editor_user_id": "2238", "owner_user_id": null, "post_type": "question", "score": -1, "tags": [ "c++11" ], "title": "dxライブラリ 将来性のあるコードの書き方が知りたい", "view_count": 216 }
[ { "body": "ソースコードを精査する気になりませんが\n\nA1. 不必要な大域変数は良くないです。提示例ではプレイヤークラス `class Player_Control` が座標を持っていますので\n`player_x` 等は要らないはず。資源を二重管理するといずれ破綻するので、必要のないものは使わないようにしましょう。\n\nA2.\n逆に、必要な大域変数を使うのをためらう必要はありません。プログラムの起動から終了まで1つしかあってはならないブツなら大域変数にして問題ないですし、他の言語なら\n`static class` で実装するような手もあります。途中で複数個になりうるのであれば大域変数にするのはダメ。\n\n> 将来性のあるちゃんとしたコードを書くためには\n\nYAGNI 論なんてのもあります。 \n<https://ja.wikipedia.org/wiki/YAGNI> \n\"You ain't gonna need it.\" とか \"You Aren't Going to Need It.\"\nとか。「今必要のないことはするな」とか「不必要な拡張性を事前に持たせても無駄」とかいう意味です。\n\nいきなり「ちゃんとした」などと身構えずに、まずは敵や味方の動きが自分で納得のいく動作となるコードを(稚拙で良いので)書いてみましょう。そこで満足せずに「ここは二重管理になっていて美しくない」とか「ここは関数が長すぎて後から読めない」とか、直すべき場所を自分で見つけられるようになりましょう。そうすることで「ちゃんとしたコードとは何か」が身につくと思います。\n\nオイラ的には `class Player_Control`\nにプレイヤークラスなんてコメントを入れている時点で美学に反するので、クラス名を変えるとかコメントを変えるとかしたくなります。\n\nJavadoc (Doxygen) お勧めっすよ。 \nまず設計意図・実装方針をコメントの形で文章にする。 \nコードを実装するのはその後。 \n修正が必要になったら Javadoc の修正が先→コード修正が後。 \n時間経過で忘れたころに手直しが必要になっても文章がきっちり残っていて楽。 \n「仕様(設計意図)通りに、ちゃんと実装する」のにとても役立ちます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T06:18:35.713", "id": "53017", "last_activity_date": "2019-02-25T06:18:35.713", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "53000", "post_type": "answer", "score": 3 } ]
53000
53017
53017
{ "accepted_answer_id": null, "answer_count": 1, "body": "WindowsエクスプローラでDWGファイルを右クリックしてプロパティウィンドウを表示した時、 \nAutoCADと同じように「ファイルの概要」を追加し、表示・編集させることはできますか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T00:38:06.883", "favorite_count": 0, "id": "53003", "last_activity_date": "2019-02-25T03:04:44.467", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "31422", "post_type": "question", "score": 1, "tags": [ "windows" ], "title": "Windowsエクスプローラのプロパティ拡張について", "view_count": 191 }
[ { "body": "Windowsでは[Property System](https://docs.microsoft.com/en-\nus/windows/desktop/properties/windows-properties-system)が定義されています。 \nですので、DWGファイルに対する[Property Handler](https://docs.microsoft.com/en-\nus/windows/desktop/properties/building-property-\nhandlers)を実装し、[レジストリに登録](https://docs.microsoft.com/en-\nus/windows/desktop/properties/prophand-reg-\ndist)することができます。これが行われていればExplorerは自動的に「ファイルの概要」を表示し、編集機能を提供します。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T03:04:44.467", "id": "53008", "last_activity_date": "2019-02-25T03:04:44.467", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "53003", "post_type": "answer", "score": 2 } ]
53003
null
53008
{ "accepted_answer_id": null, "answer_count": 0, "body": "お世話になります。\n\nサイト移転を行う予定なのですが、少し特殊でして、\n\n現在のサイトを他ドメインの下層ページに移動するという \n形を考えております。\n\n現在のトップページ \n<https://old.example.jp/>\n\n引っ越し後のトップページのURL \n<https://new.example.jp/abc>\n\nなお転送するのはトップページへのアクセスだけでなく、下位ページに対しても必要になります。\n\nこの場合のhtaccessの記載方法、進め方がわからず \nもしわかりましたらご教授をお願いできますと幸いです。\n\n知識がなく大変恐れ入ります、、、\n\nお手数をお掛け致しますが、どうぞよろしくお願いいたします。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T00:58:28.067", "favorite_count": 0, "id": "53004", "last_activity_date": "2019-02-25T05:42:03.183", "last_edit_date": "2019-02-25T05:42:03.183", "last_editor_user_id": "29826", "owner_user_id": "32307", "post_type": "question", "score": 0, "tags": [ "apache", ".htaccess" ], "title": "サイトを別ドメインの下層ページに移転する際のhtaccessの設定について", "view_count": 64 }
[]
53004
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "初めて投稿いたします。 \n当方autoLayoutがよく理解できておらず、皆様のお力をお借りしたいと思い投稿いたしました。 \n現在テスト的に以下の動作をするアプリを作っています。 \n<テスト環境> \niOS12.1.4 \nxcode 10.1 \nswift 4.2 \n<動作内容> \n1:2つのビューがある(添付コードでは緑、赤) \n2:タップすると画面一杯のサイズに拡大される \n3:閉じるを押すと、元のサイズに戻る \n4:ビュー拡大時にスワイプすると、ビューは横移動(この時もう一方を移動前に拡大) \nというサンプルなのですが \n4のもう一方のビューの閉じるを押しても、元のサイズに戻りません。\n\nデバッグしていると4にて閉じるを押した時 \nViewController.viewへの制約に \n拡大中の制約が2つ重複している現象が発生していました。\n\nなぜこのような現象が発生するのか、どのように修正すればいいのか分かっておりません。 \nどなたかご教授して頂きたいと思います。\n\nサンプルコードですが以下に全文を乗せさせて頂きます。 \n何卒よろしくお願い致します。\n\n```\n\n import UIKit\n \n class ViewController: UIViewController, CustomViewDelegate {\n \n // 赤ビュー\n lazy var red: CustomView = CustomView.init(frame: CGRect.zero)\n \n // 緑ビュー\n var green: CustomView = CustomView.init(frame: CGRect.zero)\n \n // 保持用\n var saveCon : [NSLayoutConstraint] = []\n var conGreen : [NSLayoutConstraint] = [] // 緑ビュー制約\n var conRed : [NSLayoutConstraint] = [] // 赤ビュー制約\n \n // 拡大\n func scaleUp(upView: CustomView) { \n // 最前面に移動\n self.view.bringSubviewToFront(upView)\n \n // 赤ビューの制約無効\n if upView == red{\n NSLayoutConstraint.deactivate(conRed)\n }\n // 緑ビューの制約無効\n else{\n NSLayoutConstraint.deactivate(conGreen)\n }\n \n // 新規制約生成(画面いっぱいに広げる)、有効にする\n let constA = upView.topAnchor.constraint(equalTo: view.topAnchor)\n let constB = upView.bottomAnchor.constraint(equalTo: view.bottomAnchor)\n let constC = upView.leadingAnchor.constraint(equalTo: view.leadingAnchor)\n let constD = upView.trailingAnchor.constraint(equalTo: view.trailingAnchor)\n \n // 作成した制約保持(縮小時に使用するため)\n saveCon = [constA, constB, constC, constD]\n \n NSLayoutConstraint.activate(saveCon)\n \n UIView.animate(withDuration: 0.3, animations: {\n self.view.layoutIfNeeded()\n }, completion: { finished in\n \n })\n }\n \n // 縮小\n func scaleDown(downView: CustomView) {\n // 保持していた制約を使用して無効にする\n NSLayoutConstraint.deactivate(saveCon)\n \n // 赤ビューの元々の制約有効\n if downView == red{\n NSLayoutConstraint.activate(conRed)\n }\n // 緑ビューの元々の制約有効\n else{\n NSLayoutConstraint.activate(conGreen)\n }\n UIView.animate(withDuration: 0.3, animations: {\n self.view.layoutIfNeeded()\n }, completion: { finished in\n \n })\n }\n \n func swipeDirection(sender: UISwipeGestureRecognizer){\n let notSwipeView = sender.view != red ? red : green\n \n // スワイプされていないビュー:1つ後ろにinsertする\n //self.view.insertSubview(notSwipeView, at: 0)\n \n // スワイプされていないビュー:現在の制約無効\n if notSwipeView == red{\n NSLayoutConstraint.deactivate(conRed)\n }\n else{\n NSLayoutConstraint.deactivate(conGreen)\n }\n \n // スワイプされていないビュー:制約有効(拡大)\n let conNotSwipe1 = notSwipeView.topAnchor.constraint(equalTo: view.topAnchor)\n let conNotSwipe2 = notSwipeView.bottomAnchor.constraint(equalTo: view.bottomAnchor)\n let conNotSwipe3 = notSwipeView.leadingAnchor.constraint(equalTo: view.leadingAnchor)\n let conNotSwipe4 = notSwipeView.trailingAnchor.constraint(equalTo: view.trailingAnchor)\n NSLayoutConstraint.activate([conNotSwipe1, conNotSwipe2, conNotSwipe3, conNotSwipe4])\n \n DispatchQueue.main.asyncAfter(deadline: .now() + 0.01)\n {\n // スワイプビュー:制約無効(拡大)\n NSLayoutConstraint.deactivate(self.saveCon)\n \n // スワイプされていないビュー:制約保持(このビューを縮小するときに使用する)\n self.saveCon = [conNotSwipe1, conNotSwipe2, conNotSwipe3, conNotSwipe4]\n \n // 移動処理\n var currentConst : [NSLayoutConstraint]?\n // 左にスワイプ\n if sender.direction == UISwipeGestureRecognizer.Direction.left{\n let conMove1 = sender.view!.topAnchor.constraint(equalTo: self.view.topAnchor)\n let conMove2 = sender.view!.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)\n let conMove3 = sender.view!.widthAnchor.constraint(equalToConstant: 768)\n let conMove4 = sender.view!.trailingAnchor.constraint(equalTo: self.view.leadingAnchor)\n currentConst = [conMove1, conMove2, conMove3, conMove4]\n }\n // 右にスワイプ\n else if sender.direction == UISwipeGestureRecognizer.Direction.right{\n let conMove1 = sender.view!.topAnchor.constraint(equalTo: self.view.topAnchor)\n let conMove2 = sender.view!.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)\n let conMove3 = sender.view!.widthAnchor.constraint(equalToConstant: 768)\n let conMove4 = sender.view!.leadingAnchor.constraint(equalTo: self.view.trailingAnchor)\n currentConst = [conMove1, conMove2, conMove3, conMove4]\n }\n // スワイプビュー:制約有効(移動)\n NSLayoutConstraint.activate(currentConst!)\n \n UIView.animate(withDuration: 0.3, animations: {\n self.view.layoutIfNeeded()\n }, completion: { finished in\n // スワイプビュー:制約無効\n NSLayoutConstraint.deactivate(currentConst!)\n \n // スワイプビュー:元々の制約有効(縮小)\n if sender.view! == self.red{\n NSLayoutConstraint.activate(self.conRed)\n }\n else{\n NSLayoutConstraint.activate(self.conGreen)\n }\n \n // スワイプビュー:後ろに移動する\n self.view.insertSubview(sender.view!, at: 0)\n })\n }\n }\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // 赤ビュー\n red.backgroundColor = UIColor.red\n red.myDelegate = self\n view .addSubview(red)\n red.translatesAutoresizingMaskIntoConstraints = false\n let constRedA = red.topAnchor.constraint(equalTo: view.topAnchor, constant: 200)\n let constRedB = red.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 100)\n let constRedC = red.widthAnchor.constraint(equalToConstant: 200)\n let constRedD = red.heightAnchor.constraint(equalToConstant: 200)\n conRed = [constRedA, constRedB, constRedC, constRedD] // 赤ビューの初期制約セット\n NSLayoutConstraint.activate(conRed)\n \n // 緑ビュー\n green.backgroundColor = UIColor.green\n green.myDelegate = self\n view .addSubview(green)\n green.translatesAutoresizingMaskIntoConstraints = false\n let constGreenA = green.topAnchor.constraint(equalTo: view.topAnchor, constant: 200)\n let constGreenB = green.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -100)\n let constGreenC = green.widthAnchor.constraint(equalToConstant: 200)\n let constGreenD = green.heightAnchor.constraint(equalToConstant: 200)\n conGreen = [constGreenA, constGreenB, constGreenC, constGreenD] // 緑ビューの初期制約セット\n NSLayoutConstraint.activate(conGreen)\n }\n \n override func viewDidLayoutSubviews() {\n super.viewDidLayoutSubviews()\n }\n }\n \n \n \n \n \n // ----------------------------------------------------\n // CustomViewDelegate\n // ----------------------------------------------------\n protocol CustomViewDelegate : class {\n func scaleUp(upView: CustomView) // 拡大\n func scaleDown(downView: CustomView) // 縮小\n func swipeDirection(sender: UISwipeGestureRecognizer) // スワイプ\n }\n \n extension CustomViewDelegate\n {\n func scaleUp(upView: CustomView){}\n func scaleDown(downView: CustomView){}\n func swipeDirection(sender: UISwipeGestureRecognizer){}\n }\n \n // ----------------------------------------------------\n // CustomViewクラス\n // ----------------------------------------------------\n class CustomView: UIView , UIGestureRecognizerDelegate{\n weak var myDelegate : CustomViewDelegate?\n \n // MARK: 拡大・縮小\n lazy var scaleUpGes : UITapGestureRecognizer = {\n let ges: UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(scaleUp(_:)))\n ges.numberOfTapsRequired = 1\n ges.cancelsTouchesInView = false\n ges.delegate = self\n return ges\n }()\n @objc func scaleUp(_ sender: UITapGestureRecognizer){\n myDelegate?.scaleUp(upView: self)\n scaleUpGes.isEnabled = false\n }\n \n // 縮小(とりあえずボタン用意)\n lazy var scaleDownBtn : UIButton = {\n let btn : UIButton = UIButton(type: .custom)\n btn.setTitle(\"閉じる\", for: .normal)\n btn.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20.0)\n btn.setTitleColor(UIColor.black, for: .normal)\n btn.addTarget(self, action: #selector(scaleDown(_:)), for: .touchUpInside)\n btn.translatesAutoresizingMaskIntoConstraints = false\n return btn\n }()\n @objc func scaleDown(_ sender: UIButton){\n myDelegate?.scaleDown(downView: self)\n scaleUpGes.isEnabled = true\n }\n \n \n func setAutoLayout_scaleDownBtn(){\n scaleDownBtn.widthAnchor.constraint(equalToConstant: 120).isActive = true\n scaleDownBtn.heightAnchor.constraint(equalToConstant: 40).isActive = true\n scaleDownBtn.topAnchor.constraint(equalTo: topAnchor, constant: 10).isActive = true\n scaleDownBtn.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 10).isActive = true\n }\n \n // MARK: スワイプ\n lazy var swipe : [UISwipeGestureRecognizer] = {\n var ar : [UISwipeGestureRecognizer] = []\n let direction:[UISwipeGestureRecognizer.Direction] = [.left, .right]\n direction.forEach{ value in\n let sw = UISwipeGestureRecognizer.init(target: self, action: #selector(swipeMove(_:)))\n sw.numberOfTouchesRequired = 1\n sw.delegate = self\n sw.cancelsTouchesInView = false\n sw.direction = value\n ar.append(sw)\n }\n return ar\n }()\n \n @objc func swipeMove(_ sender: UISwipeGestureRecognizer){\n myDelegate?.swipeDirection(sender: sender)\n }\n \n required init?(coder aDecoder: NSCoder) {\n super.init(coder: aDecoder)\n //self.setUp()\n }\n \n override init(frame: CGRect) {\n super.init(frame: frame)\n self.setUp()\n }\n \n func setUp(){\n swipe.forEach{ value in // スワイプジェスチャ\n addGestureRecognizer(value)\n }\n addGestureRecognizer(scaleUpGes) // 拡大ジェスチャ\n addSubview(scaleDownBtn) // 縮小ボタン\n setAutoLayout_scaleDownBtn()\n }\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T02:14:27.393", "favorite_count": 0, "id": "53006", "last_activity_date": "2019-02-26T19:09:34.367", "last_edit_date": "2019-02-25T03:31:26.813", "last_editor_user_id": "19110", "owner_user_id": "32309", "post_type": "question", "score": 0, "tags": [ "swift", "swift4" ], "title": "アニメーション実施後、autoLayoutの制約が重複する", "view_count": 212 }
[ { "body": "現象を再現可能なコードを提示していただいているので試してみました。\n\n直接の原因は「閉じる」を押した時に「タップすると画面一杯のサイズに拡大される」と「元のサイズに戻る」の両方の処理が走ってしまっていることです。\n\n`print`文なんかを入れて動きをトレースするとすぐわかると思います。\n\n```\n\n // 拡大\n func scaleUp(upView: CustomView) {\n print(#function)\n //...\n }\n \n // 縮小\n func scaleDown(downView: CustomView) {\n print(#function)\n //...\n }\n \n```\n\nスワイプした後で「閉じる」を押すと\n\n```\n\n scaleUp(upView:)\n scaleDown(downView:)\n \n```\n\nのように表示されるはずです。\n\n`CustomView`クラスの`scaleUp(_:)`の中には`scaleUpGes.isEnabled =\nfalse`なんてコードが記載されていますが、スワイプで拡大されたviewではこのコードは実行されませんので、「タップで拡大」が有効になったままです。\n\n例えば、`ViewController`クラスの`swipeDirection(sender:)`メソッド内のどこかにこんなコードを追加する必要があるでしょう。\n\n```\n\n func swipeDirection(sender: UISwipeGestureRecognizer){\n let notSwipeView = sender.view != red ? red : green\n notSwipeView.scaleUpGes.isEnabled = false //<-\n \n //...\n }\n \n```\n\n* * *\n\n間接的には`saveCon`なんて「実行状態によって一体何が入っているのかよくわからなくなる変数」を導入してしまっていたり、全く同じ制約を操作を行う度に毎回作り直しているのも問題でしょう。\n\n上記したように、ジェスチャーの有効・無効の制御さえ、一貫性を持たせるのは大変なのですから、「現在どのviewでどんな制約がかかっているか」なんてことを`saveCon`なんて変数一つで一貫性のあるように管理するのは大変です。ちょっとした想定外の操作をされただけで、無効化されるべき制約が有効のままで残ってしまい、ご経験されたような制約矛盾の状態になったりします。\n\nあなたのコードの場合、せっかく`CustomView`を定義しているのですから、「現在有効な制約」をview自身に管理させるのが簡単で確実です。\n\n`CustomView`にこんなプロパティを追加してやります。\n\n```\n\n class CustomView: UIView, UIGestureRecognizerDelegate {\n weak var myDelegate : CustomViewDelegate?\n \n var activeConstraints: [NSLayoutConstraint] = [] {\n willSet {\n NSLayoutConstraint.deactivate(activeConstraints)\n }\n didSet {\n NSLayoutConstraint.activate(activeConstraints)\n }\n }\n \n //...\n }\n \n```\n\n`CustomView`に制約を付ける場合には、このプロパティを操作するだけにして、直接`NSLayoutConstraint.deactivate(_:)`や`NSLayoutConstraint.activate(_:)`は呼ばないようにします。\n\nざっくりこんな感じ。\n\n```\n\n // 拡大\n func scaleUp(upView: CustomView) {\n print(#function)\n // 最前面に移動\n self.view.bringSubviewToFront(upView)\n \n // 新規制約生成(画面いっぱいに広げる)、有効にする\n let constA = upView.topAnchor.constraint(equalTo: view.topAnchor)\n let constB = upView.bottomAnchor.constraint(equalTo: view.bottomAnchor)\n let constC = upView.leadingAnchor.constraint(equalTo: view.leadingAnchor)\n let constD = upView.trailingAnchor.constraint(equalTo: view.trailingAnchor)\n \n // 作成した制約保持\n upView.activeConstraints = [constA, constB, constC, constD]\n \n UIView.animate(withDuration: 0.3, animations: {\n self.view.layoutIfNeeded()\n }, completion: { finished in\n \n })\n }\n \n // 縮小\n func scaleDown(downView: CustomView) {\n print(#function)\n if downView == red {\n // 赤ビューの元々の制約有効\n red.activeConstraints = conRed\n } else{\n // 緑ビューの元々の制約有効\n green.activeConstraints = conGreen\n }\n UIView.animate(withDuration: 0.3, animations: {\n self.view.layoutIfNeeded()\n }, completion: { finished in\n \n })\n }\n \n func swipeDirection(sender: UISwipeGestureRecognizer){\n let notSwipeView = sender.view != red ? red : green\n notSwipeView.scaleUpGes.isEnabled = false\n \n // スワイプされていないビュー:制約有効(拡大)\n let conNotSwipe1 = notSwipeView.topAnchor.constraint(equalTo: view.topAnchor)\n let conNotSwipe2 = notSwipeView.bottomAnchor.constraint(equalTo: view.bottomAnchor)\n let conNotSwipe3 = notSwipeView.leadingAnchor.constraint(equalTo: view.leadingAnchor)\n let conNotSwipe4 = notSwipeView.trailingAnchor.constraint(equalTo: view.trailingAnchor)\n notSwipeView.activeConstraints = [conNotSwipe1, conNotSwipe2, conNotSwipe3, conNotSwipe4]\n \n self.view.layoutIfNeeded()\n DispatchQueue.main.async {\n // 移動処理\n let currentConst : [NSLayoutConstraint]\n if sender.direction == .left {\n // 左にスワイプ\n let conMove1 = sender.view!.topAnchor.constraint(equalTo: self.view.topAnchor)\n let conMove2 = sender.view!.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)\n let conMove3 = sender.view!.widthAnchor.constraint(equalToConstant: 768)\n let conMove4 = sender.view!.trailingAnchor.constraint(equalTo: self.view.leadingAnchor)\n currentConst = [conMove1, conMove2, conMove3, conMove4]\n } else {\n // 右にスワイプ\n let conMove1 = sender.view!.topAnchor.constraint(equalTo: self.view.topAnchor)\n let conMove2 = sender.view!.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)\n let conMove3 = sender.view!.widthAnchor.constraint(equalToConstant: 768)\n let conMove4 = sender.view!.leadingAnchor.constraint(equalTo: self.view.trailingAnchor)\n currentConst = [conMove1, conMove2, conMove3, conMove4]\n }\n // スワイプビュー:制約有効(移動)\n (sender.view as! CustomView).activeConstraints = currentConst\n \n UIView.animate(withDuration: 0.3, animations: {\n self.view.layoutIfNeeded()\n }, completion: { finished in\n // スワイプビュー:元々の制約有効(縮小)\n if sender.view! == self.red {\n self.red.activeConstraints = self.conRed\n } else{\n self.green.activeConstraints = self.conGreen\n }\n \n // スワイプビュー:後ろに移動する\n self.view.insertSubview(sender.view!, at: 0)\n })\n }\n }\n \n```\n\n(`viewDidLoad()`内で最初の制約を与える部分も同様ですが、省略しています。)\n\nこのような修正は必須ではありませんが、こうしておくと、先の`notSwipeView.scaleUpGes.isEnabled =\nfalse`なんてのを追加し忘れても破綻なく動作するはずです。よろしければお試しください。\n\n制約ベースのアニメーションを行おうとすると、どうしても制約を動的に操作する必要が出てくるのですが、`CustomView`のようなクラスを使用しない場合でも、「現在有効な制約」はviewごとに確実に管理することをお勧めします。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T19:09:34.367", "id": "53059", "last_activity_date": "2019-02-26T19:09:34.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "53006", "post_type": "answer", "score": 1 } ]
53006
null
53059
{ "accepted_answer_id": null, "answer_count": 0, "body": "以下のような、レイアウトが共通の色違い要素があったとします。(白黒白黒と続く想定)\n\n```\n\n <div class=\"Block\">\n <div class=\"Block__element\">白</div>\n <div class=\"Block__element\">黒</div>\n <div class=\"Block__element\">白</div>\n <div class=\"Block__element\">黒</div>\n </div>\n \n```\n\nその際のCSS(scss)を、 \ncssセレクタ(nth-of-type)でスタイルを当てるのか\n\n```\n\n .Block {\n &__element {\n &:nth-of-type(odd){\n 白色スタイル\n }\n &:nth-of-type(even){\n 黒色スタイル\n }\n }\n }\n \n```\n\nとするのか、 \nクラスにmodifierを付けて\n\n```\n\n <div class=\"Block\">\n <div class=\"Block__element--white\">白</div>\n <div class=\"Block__element--black\">黒</div>\n <div class=\"Block__element--white\">白</div>\n <div class=\"Block__element--black\">黒</div>\n </div>\n \n .Block {\n &__element {\n &--white{\n 白色スタイル\n }\n &--black{\n 黒色スタイル\n }\n }\n }\n \n```\n\nとした方が良いのか悩みました。 \nこのような場合に限り、nth-of-typeの方が改修などが楽なのではと思いましたが、 \nBEMで設計している以上、modifierを付けた方が良いのでしょうか。\n\nご回答、アドバイスのほど、よろしくおねがいいたします。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T03:10:39.147", "favorite_count": 0, "id": "53010", "last_activity_date": "2019-02-25T03:10:39.147", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30065", "post_type": "question", "score": 2, "tags": [ "html", "css" ], "title": "BEMのmodifierについて", "view_count": 182 }
[]
53010
null
null
{ "accepted_answer_id": "53087", "answer_count": 1, "body": "とある(サイズがかなり大きい)リポジトリを含んだプロジェクトに対して\"Jenkins上から\"repo\nsyncを実行したところ以下のエラーが発生し失敗してしまいます。\n\n```\n\n Cloning into 'repo_name'...\n Connection to xxx.xxx.xxx.xxx closed by remote host.\n fatal: The remote end hung up unexpectedly\n \n```\n\njenkinsからの実行ではなく、同じマシンのプロンプト上から実行した場合は問題なく成功いたします。 \nまた、このリポジトリ以外(サイズ小さめ)はjenkins上からの実行でも成功しています。\n\nこのリポジトリに対して同様にJenkins上からgit cloneをかけても同様エラーで失敗します。\n\n以下などを参考にバッファサイズを変更したりしてみましたが、現象変わらずでRPCやnginxのエラーメッセージは表示されておりません。 \n<https://stackoverflow.com/questions/6842687/the-remote-end-hung-up-\nunexpectedly-while-git-cloning>\n\nしかしながら \n調査の為にgit cloneに--progressオプションを付与してみたところ何故かjenkinsからの取得でも成功してしまいました。\n\nrepo syncコマンドを解析してみたところ、非TTY状況であるとrepo sync内部で実行しているgit fetchに--\nprogressを付与しないようにしているようのでこの点からも辻褄があいそうです。\n\n質問内容といたしましては \n・何故非TTY環境だとサイズの大きいリポジトリ時に失敗してしまうのか \n・上記状況でも--progressを付与すると成功するのはなぜか \n・(repo syncの中身は弄れないので)--progressなしでもjenkins上から成功できる方法はあるか \nとなります。", "comment_count": 7, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T05:26:34.340", "favorite_count": 0, "id": "53015", "last_activity_date": "2019-02-28T05:50:01.907", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23189", "post_type": "question", "score": 3, "tags": [ "git", "jenkins" ], "title": "Jenkinsから特定のリポジトリをrepo sync/git cloneすると失敗する", "view_count": 881 }
[ { "body": "コメント欄で教えて頂いた以下より \n<https://issues.jenkins-ci.org/browse/JENKINS-9168>\n\n> When cloning a large repository over HTTP, the git server goes quiet for\n> quite some time, busy computing a pack file. Normally, Apache is configured\n> such that a prolonged inactivity in a socket will trigger a shutdown. So\n> what the end user sees is that after a while, \"git clone\" fails by the\n> unexpected connection reset by the server.\n\nGit server側の設定によっては切断されてしまうとのことでした。 \n上記サイト内にも記載がありますが、サーバの設定を変えられる状況にない場合は--progressを付与するのがベターとのことなので \ngit clone/fetchを使用する際は--progressを使用することといたします。\n\nrepoの場合これは不可能ですが、しょうがないのでrepo内のscriptを編集することで実施します。 \n(repo側の問題の様に思えます)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T05:50:01.907", "id": "53087", "last_activity_date": "2019-02-28T05:50:01.907", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23189", "parent_id": "53015", "post_type": "answer", "score": 4 } ]
53015
53087
53087
{ "accepted_answer_id": null, "answer_count": 1, "body": "LogstashでPostgresqlに出力するときに次のようなエラーが出ます。\n\n```\n\n [ERROR][org.logstash.Logstash ] java.lang.IllegalAccessError: tried to access class org.postgresql.Driver$ConnectThread from class org.postgresql.Driver\n \n```\n\n出力を標準出力にすると動作するので、outputに問題があると思っています。 \nパイプラインファイルのoutputは次の通りです。\n\n```\n\n output {\n jdbc {\n driver_jar_path => \"/usr/share/java/postgresql.jar\"\n driver_class => \"org.postgresql.Driver\"\n connection_string => \"jdbc:postgresql://localhost:5432/testdb\"\n statement => [\"INSERT INTO test (result1, result2) VALUES (?, ?)\",\n \"test1\", \"test2\"\n ]\n }\n stdout { codec => rubydebug }\n }\n \n```\n\n何が間違っているのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T05:29:12.927", "favorite_count": 0, "id": "53016", "last_activity_date": "2019-03-05T09:13:03.477", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "31801", "post_type": "question", "score": 0, "tags": [ "postgresql" ], "title": "LogstashでPostgreSQLに出力するときのエラー", "view_count": 314 }
[ { "body": "inputやfilterで同じDBのJDBCを使っているとエラーになるようでした", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T09:13:03.477", "id": "53210", "last_activity_date": "2019-03-05T09:13:03.477", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "31801", "parent_id": "53016", "post_type": "answer", "score": 1 } ]
53016
null
53210
{ "accepted_answer_id": "53022", "answer_count": 1, "body": "下記の表にある「重要度・概要・説明」はプルダウンセルです。 \n重要度の選択値によって、下記<各列の選択肢>のように概要・説明の選択項目を動的に変更したいのですが、Excelで設定方法が分かりません。\n\n<各列の選択肢> \n・重要度:S,A,B \n・概要 \n重要度でSが選択されている場合:概要1,概要2,概要3 \n重要度でAが選択されている場合:概要4,概要5,概要6 \n重要度でBが選択されている場合:概要7,概要8,概要9 \n・説明 \n重要度でSが選択されている場合:説明1,説明2,説明3 \n重要度でAが選択されている場合:説明4,説明5,説明6 \n重要度でBが選択されている場合:説明7,説明8,説明9\n\n![Excel画像](https://i.stack.imgur.com/V2X1E.png)\n\nお分かりの方がいましたら、ご教授をお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T06:39:45.750", "favorite_count": 0, "id": "53019", "last_activity_date": "2019-02-25T08:00:53.350", "last_edit_date": "2019-02-25T06:45:52.937", "last_editor_user_id": "7626", "owner_user_id": "7626", "post_type": "question", "score": 0, "tags": [ "excel" ], "title": "Excelで1つのプルダウンセル選択肢に応じて、複数の別セルプルダウン選択肢を変更する", "view_count": 47 }
[ { "body": "知恵袋にてご回答を頂きました。\n\n[Yahoo知恵袋の回答](https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q10204039505)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T08:00:53.350", "id": "53022", "last_activity_date": "2019-02-25T08:00:53.350", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7626", "parent_id": "53019", "post_type": "answer", "score": 0 } ]
53019
53022
53022
{ "accepted_answer_id": "53032", "answer_count": 3, "body": "`float a float\nb`なのですが`cos`関数は引数にラジアンの値をいれてその`cos`が帰ってるくるとい仕様になっていますがつまりラジアンの値を入れる`float\na`が正解で`float b`は45というラジアンの値が入ってることになるので不正解ということなのでしょうか? \nまた三角関数のライブラリの`cos tan sin`の結果は `x y r` 各場所が1の時の角度つまり \n数学の早見表にある角度の値が帰ってくるという認識いいのでしょうか?`printf`で値を確認したのですが一応聞きました。\n\n```\n\n float a = cos(PI / 180 * 45);\n float b = cos(45);\n \n while (ClearDrawScreen() == 0 && SetDrawScreen(DX_SCREEN_BACK) == 0 && ProcessMessage() == 0)\n {\n x = cos(PI / 180 * angle) * r + 200;\n y = sin(PI / 180 * angle) * r + 200;\n angle += 4;\n \n \n //Sleep(200);\n DrawFormatString(0,50,Color,\" a %lf\",a);\n DrawFormatString(0, 65, Color, \" b %lf\", b);\n \n //DrawFormatString(10, 35, Color, \"%d\", angle);\n \n //DrawFormatString(0,0,Color,\"x: %d,Y: %d\",x,y);\n \n DrawGraph(x,y,gh,true);\n if (angle >= 360)\n {\n angle = 1;\n }\n \n \n \n \n \n ScreenFlip();\n if (CheckHitKey(KEY_INPUT_ESCAPE) == 1) { break; }\n }\n return 0;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T07:48:03.230", "favorite_count": 0, "id": "53021", "last_activity_date": "2019-04-11T07:14:06.257", "last_edit_date": "2019-04-11T07:14:06.257", "last_editor_user_id": "19110", "owner_user_id": null, "post_type": "question", "score": 1, "tags": [ "c++", "数学" ], "title": "c++ cos関数に入れる引数でラジアンと角度について知りたい。", "view_count": 6837 }
[ { "body": "`cos(45)` は 45 radian = `14.323944 π` の `cos` を求める正しいコードです。 `45 degree` の\n`cos` を求めたいのであれば誤りです。定義上 `2 π` で周期してしまうので、あまり大きな角度の `cos` `sin`\nは精度が出なくなります(ので適宜 `2 π` で角度を切ってしまうのが良いし、提示コードでもそうしていますね)。\n\n後半は文章がアレで数学的説明になっていないのですが、単純に `cos` は余弦、 `sin` は正弦、 `tan`\nは正接を、ラジアン角度体系で定義通りに返すだけです。半径1の円の円弧上のある1点から `x` 軸に垂らした垂線の足の `x` 値が `cos` 同様 `y`\n軸に垂らした垂線の足の `y` 値が `sin` ですよね。\n\n数学が苦手で提示コードの式が直観的でないということなら\n\n```\n\n inline double deg2rad(double deg) { return PI/180.0 * deg; }\n \n```\n\nなんてヘルパー関数を作っておいて `x=cos(deg2rad(angle)) * r + 200;` みたいに書けばいいでしょうし、あるいは\n\n```\n\n inline double degcos(double deg) { return cos(deg2rad(deg)); }\n \n```\n\nとか。ライブラリ関数を直に使うのがわかりにくいのであれば、ちょっと細工して自分のわかりやすいように書く工夫をしましょう。\n\n```\n\n if (angle >= 360)\n {\n angle = 1;\n }\n \n```\n\nはおかしいです(少なくともオイラは絶対に書かない)。どうしたら自然かは宿題かな。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T09:39:12.667", "id": "53024", "last_activity_date": "2019-02-25T11:21:39.410", "last_edit_date": "2019-02-25T11:21:39.410", "last_editor_user_id": "8589", "owner_user_id": "8589", "parent_id": "53021", "post_type": "answer", "score": 0 }, { "body": "C++のcos関数の引数には、ラジアンを単位とする角度を与えます。\n\nX度をラジアンに変換する式は、π * (X/180) ですから、45度のcosineを計算する式は、cos(π * 45 / 180)となります。 \nですから、 float a = cos(PI / 180 * 45); で求めた aの値が 45度のcosineの値です。\n\ncos(45)は、45度のcosineではなく、45ラジアンのcosineの値です。\n\n== \n質問の「cos tan sinの結果は x y r 各場所が1の時の角度」の部分は、意味が判りませんでした。\n\n>\n```\n\n> x = cos(PI / 180 * angle) * r + 200;\n> y = sin(PI / 180 * angle) * r + 200;\n> \n```\n\nx,y,rが揃っているのは、この部分だと思うのですが、xとyはX座標とY座標(原点からX軸方向に離れている距離と、原点からY軸方向に離れている距離)ですし、rは基準点(X座標が200、Y座標が200の点)からの(直線)距離です。(角度を表しているのはangleです)\n\nSin,cos,tanの各関数は、直角三角形の2辺の長さの比が返ってくる関数です。角度が返ってくる関数ではありません。\n\n下の図の頂点Aのところの角度が angleラジアン である場合、cos(angle)は b/h を返します。 \n同様に、sin(angle)はa/hを、tan(angle)はa/bを返します。\n\n[![直角三角形](https://i.stack.imgur.com/pJOKM.png)](https://i.stack.imgur.com/pJOKM.png)\n\n== \n直角三角形の辺の比を引数にとって、角度を返す関数は逆三角関数といいます。 \n逆三角関数には、arcsin,arccos,arctanの3種類があります。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T09:42:12.627", "id": "53025", "last_activity_date": "2019-02-25T09:42:12.627", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "53021", "post_type": "answer", "score": 2 }, { "body": "> `cos(angle)` は `b/h` を返しますとありますが `b` と `h` はこの場合の数値?はどうなっているのでしょうか?\n\nということなので三角比の基本から教えます。fumu 7 さんの直角三角形を利用させていただきます。 \n余弦 `cos` の定義は `cos(angle) = b/h` であるからこの値はただの分数を計算した値です。\n\nところで「分数の計算」は今まで数えきれないほどしてきたことと思います。そこで小学校のときを思い出しましょう。 \n「120 km の距離を 4時間かけて歩いた。」このとき、1時間あたりどのくらいの距離を歩いたでしょうか?答えは「歩いた距離を 4 等分」すればよいので\n`120(km)/4(時間) = 30 (km/時)` です。また、1 km 当たりにどのくらいの時間がかかっているでしょうか?答えは「歩いた時間を 120\n等分」すればよいので `4(時間)/120(km) = 1/30 (時間/km)` です。これは 1時間は 60分であるから `1/30 (時間/km) =\n60 * 1/30 = 2 (分/km)` のように考えられます。この単位の変換はおまけなので `1/30 (時間/km)` だけを考えても構わないです。 \nさらに、「100 m の長さのロープが 1000 円だった。」このとき、1 m 当たりの金額は `1000(円)/100(m) = 10 (円/m)`\nです。また、1 円 当たりの長さは `100(m)/1000(円) = 1/10 (m/円)` となります。\n\nこれらの例でわかったかと思いますが、`分子/分母` を計算した値は「分母を 1\nとみなしたときの分子の値」を表します。上の例で確認してみてください。それが終わったら `cos(angle)`\nの値は何を表しているかを考えましょう。`cos(angle) = b/h = 底辺の長さ/斜辺の長さ` です。ということは `cos(angle)`\nの値は「斜辺の長さが 1 のときの【底辺の長さ】」を表します。もっと簡単に言えば Fumu 7 さんの直角三角形を「斜辺の長さが 1\nとなるように拡大(または縮小)を行ったときの【底辺の長さ】」を表します。 \n`sin(angle)` も同様に考えると「斜辺の長さが 1\nとなるように拡大(または縮小)を行ったときの【高さ】」を表します。このとき出来た直角三角形をイメージすると「斜辺の長さが 1」「底辺の長さが\n`cos(angle)`」「高さが `sin(angle)`」ということになり、三平方の定理を用いると\n`1^2=cos^2(angle)+sin^2(angle)` という有名な等式や `tan(angle)` を考えると\n`tan(angle)=sin(angle)/cos(angle)` などという関係がわかります。\n\nまた、`tan(angle) = 高さ/底辺の長さ` であるので `tan(angle)` の値は Fumu 7 さんの図を「底辺の長さが 1\nとなるように拡大(または縮小)したときの【高さ】」を表すことになります。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T13:32:23.890", "id": "53032", "last_activity_date": "2019-02-25T13:37:36.697", "last_edit_date": "2019-02-25T13:37:36.697", "last_editor_user_id": "27509", "owner_user_id": "27509", "parent_id": "53021", "post_type": "answer", "score": 2 } ]
53021
53032
53025
{ "accepted_answer_id": null, "answer_count": 1, "body": "Python3.7を使っています。\n\n```\n\n import discord\n \n client = discord.Client()\n \n @client.event\n async def on_ready():\n print('We have logged in as {0.user}'.format(client))\n \n @client.event\n async def on_message(message):\n if message.author == client.user:\n return\n \n if message.content.startswith('Hi'):\n await message.channel.send('hello')\n \n client.run(\"Token\")\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T08:08:09.927", "favorite_count": 0, "id": "53023", "last_activity_date": "2019-12-17T09:02:05.423", "last_edit_date": "2019-02-25T08:13:23.417", "last_editor_user_id": "3060", "owner_user_id": null, "post_type": "question", "score": 3, "tags": [ "python", "python3", "discord" ], "title": "discordでこのプログラムのどこに何を入れればメッセージを送った人をメンションさせることができますか?", "view_count": 612 }
[ { "body": "`User` クラスの\n[`mention`](https://discordpy.readthedocs.io/ja/latest/api.html#discord.User.mention)\nを使うと表現できます。以下はサンプルコードです。\n\n```\n\n @client.event\n async def on_message(message):\n if message.author == client.user:\n return\n \n if message.content.startswith('Hi'):\n msg = f\"{message.author.mention} Hello!\"\n await message.channel.send(msg)\n \n```\n\n`f\" ... \"` はフォーマット文字列です。Python 3.7.2、discord.py 1.0.0a1691+gf686924 で動作確認しました。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T05:18:40.623", "id": "53049", "last_activity_date": "2019-02-26T05:18:40.623", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "53023", "post_type": "answer", "score": 2 } ]
53023
null
53049
{ "accepted_answer_id": null, "answer_count": 0, "body": "Word文書中にハイパーリンクでredmineのチケットを指定したとき、ジャンブ先がredmineのトップページの表示止まりになってしまいます. \n(例えば、`https://mng.example.jp/redmine/issues/100` など)\n\nハイパーリンクからredmineのチケットが表示されるようにするには、どういった対応が必要なのか、ご存知の方がおられましたらご教示ください.", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T09:47:08.667", "favorite_count": 0, "id": "53026", "last_activity_date": "2020-07-24T05:50:55.837", "last_edit_date": "2020-07-24T05:50:55.837", "last_editor_user_id": "3060", "owner_user_id": "21153", "post_type": "question", "score": 0, "tags": [ "redmine", "ms-word" ], "title": "Word に Redmine のチケットへのリンクを挿入しても、トップページが表示されてしまう", "view_count": 119 }
[]
53026
null
null
{ "accepted_answer_id": "53031", "answer_count": 1, "body": "Numo::NArrayを用いて数値計算をしようと考えています. \nそこで,以下のようなテストコードがあったとき,算術演算後の演算結果を標準出力したいのですが,下記に示すような標準出力になってしまいます. \nどのようにしたら配列の中身を標準出力できるのでしょうか.\n\n初めてNumo::NArrayを利用するのでわかりません. \nご教授宜しくお願い致します.\n\n```\n\n require 'numo/narray'\n \n list_size = 1_000_000\n range = (-100.0 .. 100.0)\n \n # Numo::NArray型に格納する配列を定義\n out1 = Array.new(list_size) do \n rand(range) + rand(range) * 1i\n end\n out2 = Array.new(list_size) do \n rand(range) + rand(range) * 1i\n end\n \n # Numo::NArray型を定義\n out1_na = Numo::DComplex.new(list_size)\n p \"Defined: out1_na = #{out1_na}\"\n out1_na.store(out1) # 配列out1を格納\n \n out2_na = Numo::DComplex.new(list_size)\n p \"Defined: out2_na = #{out2_na}\"\n out2_na.store(out2) # 配列out2を格納\n \n \n # 算術演算でテストする\n print \"和算\"\n plus = out1_na + out2_na\n puts \": #{plus}\"\n \n print \"減算\"\n minus = out1_na - out2_na\n puts \": #{minus}\"\n \n print \"乗算\"\n product = out1_na * out2_na\n puts \": #{product}\"\n \n print \"除算\"\n per = out1_na / out2_na\n puts \": #{per}\"\n \n```\n\n出力結果\n\n```\n\n $ ruby test_numoNArray.rb \n \"Defined: out1_na = #<Numo::DComplex:0x00007fe91b1f3b58>\"\n \"Defined: out2_na = #<Numo::DComplex:0x00007fe91b1f37c0>\"\n 和算: #<Numo::DComplex:0x00007fe91dd4bd50>\n 減算: #<Numo::DComplex:0x00007fe91dd4b9b8>\n 乗算: #<Numo::DComplex:0x00007fe91dd4b6c0>\n 除算: #<Numo::DComplex:0x00007fe91dd4b440>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T10:08:03.220", "favorite_count": 0, "id": "53027", "last_activity_date": "2019-02-25T12:34:30.860", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30173", "post_type": "question", "score": 1, "tags": [ "ruby" ], "title": "Numo::NArrayで定義した配列の標準出力方法について", "view_count": 78 }
[ { "body": "p メソッドで配列の内容を表示できます。要素数が多い場合は初めの方だけ表示します。\n\n```\n\n x = Numo::DComplex.new(5,4).seq\n p x\n \n```\n\n出力\n\n```\n\n Numo::DComplex#shape=[5,4]\n [[0+0i, 1+0i, 2+0i, 3+0i], \n [4+0i, 5+0i, 6+0i, 7+0i], \n [8+0i, 9+0i, 10+0i, 11+0i], \n [12+0i, 13+0i, 14+0i, 15+0i], \n [16+0i, 17+0i, 18+0i, 19+0i]]\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T12:34:30.860", "id": "53031", "last_activity_date": "2019-02-25T12:34:30.860", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "31056", "parent_id": "53027", "post_type": "answer", "score": 1 } ]
53027
53031
53031
{ "accepted_answer_id": "53029", "answer_count": 1, "body": "提示コード最下部の if(angle >=\n360)の部分なのですが書いててなんか違うなうな気がしたのですがやっぱり実装が間違て幼稚なコードになっている指摘を受けたので自分の力で修正を試みたのですが自分には実装がこれ以外おもいつかず質問してしました。 \n回答と解説お願いできますでしょうか。\n\n```\n\n #include \"DxLib.h\"\n #include \"math.h\"\n #include <string>\n #define PI 3.14159265359\n using namespace std;\n char key[256];\n \n //キー入力関数\n int KeyBord_Get(int keycode)\n {\n \n char tmpkey[256];\n GetHitKeyStateAll(tmpkey);\n for (int i = 0; i < 256; i++)\n {\n if (tmpkey[i] != 0)\n {\n key[i]++;\n }\n else\n {\n key[i] = 0;\n }\n \n }\n \n return key[keycode];\n }\n \n int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {\n ChangeWindowMode(TRUE);\n if (DxLib_Init() == -1) { return -1; } \n int Color = GetColor(255,255,255);\n int gh = LoadGraph(\"resources/Player.png\");\n int x = -200;\n int y = -200;\n \n int angle = 0;\n \n int r = 30;\n \n float t = PI / 180 * 4;\n \n \n float a = cos(PI / 180 * 45);\n float b = cos(45);\n \n while (ClearDrawScreen() == 0 && SetDrawScreen(DX_SCREEN_BACK) == 0 && ProcessMessage() == 0)\n {\n //x = cos(PI / 180 * angle) * r + 200;\n //y = sin(PI / 180 * angle) * r + 200;\n \n x = cos(PI / 180 * angle) * r + 200;\n y = sin(PI / 180 * angle) * r + 200;\n \n angle += 4;\n \n \n //Sleep(200);\n //DrawFormatString(0,50,Color,\" a %lf\",a);\n //DrawFormatString(0, 65, Color, \" b %lf\", b);\n \n //DrawFormatString(10, 35, Color, \"%d\", angle);\n \n DrawFormatString(0,0,Color,\"x: %d,Y: %d\",x,y);\n \n DrawGraph(x,y,gh,true);\n if (angle >= 360)\n {\n angle = 1;\n }\n \n \n \n \n \n ScreenFlip();\n if (CheckHitKey(KEY_INPUT_ESCAPE) == 1) { break; }\n }\n return 0;\n }\n \n```", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T10:32:38.987", "favorite_count": 0, "id": "53028", "last_activity_date": "2019-02-28T00:25:23.590", "last_edit_date": "2019-02-28T00:25:23.590", "last_editor_user_id": "2238", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "c++" ], "title": "dxライブラリ 円周するコードの実装に困っています。(改良)", "view_count": 239 }
[ { "body": "結局のところ「いきすぎちゃったら範囲内に戻す」ってことになるわけですが。\n\n359 度を 7 度進めて 366 度になったというとき 366 度は 6 度なわけです。これを求めるには剰余を使って\n\n```\n\n angle += delta_angle;\n angle %= 360;\n \n```\n\nとすれば、必ず 360 度未満の数値が得られることになります(ここんところ大丈夫? これに納得できないようだと先は長い)\n\n剰余は計算機の処理の中で最も遅い部類の演算なので、剰余演算を避けるには\n\n```\n\n if (angle>=360) angle-=360;\n \n```\n\nとすればよいことになります( 720 度より大きいとき挙動が違う。なおかつ今時は剰余コストより分岐コストのほうが高いかもしれないのでなんとも)。\n`angle=1;` だと無条件で `1` になってしまっておかしいですよね。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T11:46:37.130", "id": "53029", "last_activity_date": "2019-02-25T11:46:37.130", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "53028", "post_type": "answer", "score": 1 } ]
53028
53029
53029
{ "accepted_answer_id": null, "answer_count": 2, "body": "python3で複数の数値をinputから取得したいのですが下記の二つを試してもうまく動きません。なぜでしょうか?\n\n例1\n\n```\n\n s = input().split() #s_1 s_2を分割して取得し、sに値を入れる\n print(s) #出力:['s_1', 's_2']\n print(s[0]) #出力:s_1\n print(s[1]) #出力:s_2\n print(s[2]) #出力:s_3\n \n```\n\n例2\n\n```\n\n a,b,c = map(int,input().split())\n \n print(a+b+c)\n \n```\n\n出力 下記のように出したいです。\n\n```\n\n 5 8 7\n \n 20\n \n```\n\n他にいい方法があれば教えてください。よろしくお願いします。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T12:10:13.867", "favorite_count": 0, "id": "53030", "last_activity_date": "2021-12-30T03:34:31.117", "last_edit_date": "2019-02-25T12:37:33.470", "last_editor_user_id": "19110", "owner_user_id": "32316", "post_type": "question", "score": 0, "tags": [ "python", "python3" ], "title": "複数の数値をinputで一行で取得したい", "view_count": 14394 }
[ { "body": "[マルチポスト先](https://teratail.com/questions/176403) のコメントのように\n**入力した文字列と表示されたエラーメッセージ** を明記すると回答を得やすくなると思います。\n\n`a,b,c = map(int,input().split())`にて、入力が二つの時に`alueError: need more than 1\nvalue to unpack`が出ることが問題ならば、[アスタリスク*を使ったアンパック](https://note.nkmk.me/python-\ntuple-list-unpack/)で解決できるかもしれません。(python3以降のみ)\n\n上記リンク先で「アスタリスク*を使ったアンパック」をページ内検索すると、下記のように配列要素が2個でもエラーにならないコーディングをすることができます。\n\n```\n\n s = \"5 8\" #inputの代わりに再現性のある文字列代入を行っています\n a, b, *c = map(int, s.split())\n print(a, b, c)\n # 5 8 []\n \n```\n\nただしアスタリスク付きの引数は値の有無にかかわらず配列として展開されますので、[int型に変換](https://stackoverflow.com/a/31958097)する必要があります。\n\n```\n\n s = \"5 8 7\" #inputの代わりに再現性のある文字列代入を行っています\n a, b, *c = map(int, s.split())\n print(a, b, c)\n # 5 8 [7] #cが配列になってしまう\n \n s = \"5 8\" \n a, b, *c = map(int, s.split())\n c = c[0] if c else 0 #elseの値は省略時のデフォルト値\n print(a, b, c)\n # 5 8 0\n \n```\n\nちなみに使用できるアスタリスクの数は1つだけです。(複数のアスタリスクを使うと省略時の値をどの変数に入れるか確定できなくなるため) \nそのため変数`b`と`c`にアスタリスクを付けた下記のコードはエラーになるので、不定個の配列要素を許容する場合は別の解決策もご検討ください。\n\n```\n\n a, *b, *c = map(int, s.split())\n \n```\n\n> SyntaxError: invalid syntax", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T01:10:59.197", "id": "53040", "last_activity_date": "2019-02-26T01:18:37.943", "last_edit_date": "2019-02-26T01:18:37.943", "last_editor_user_id": "3060", "owner_user_id": "9820", "parent_id": "53030", "post_type": "answer", "score": 1 }, { "body": "「必ず 3 個の入力が与えられるので、その 3 個を受け取りたい」という風に固定長の入力を受け取りたいのであれば、例 2 のプログラムで動くはずです。\n\n```\n\n a, b, c = map(int, input().split())\n print(a + b + c)\n \n```\n\nそうではなくて「何個か分からないけど入力が与えられるので、それらを受け取りたい」という風に可変長の入力を受け取りたいのであれば、例 1\nと似た感じでリストとして受け取るのが便利です。\n\n```\n\n numbers = list(map(int, input().split()))\n print(numbers [0] + numbers [1] + numbers [2]) # (必ず 3 個は入力があると分かっている場合)\n \n```\n\nこのように受け取ると、`numbers[0]` に 1 つ目の入力、`numbers[1]` に 2 つ目の入力、`numbers[2]` に 3\nつ目の入力、……といった感じで格納されます。入力が何個あったかは `len(numbers)` で調べられます。\n\n## 動作の説明\n\nところでそもそも、上のプログラムたちはどのようにして入力を受け取っているのでしょうか。この点を理解しておくとエラーの原因を把握しやすくなるので、説明してみます。\n\n 1. まず、`input()` は 1 行の入力を **文字列として** 受け取る関数です。\n 2. 受け取った文字列を `split()` することで、空白文字で分割し、 **文字列のリストとして** 受け取ります。\n 3. `int()` は文字列を整数値に変換する関数です。`map()` を使うことで、リストの各要素に対してひとつずつ `int()` を適用することができます。この際、`map()` した後の値はリストではなく「イテレーター」というものになります。したがって `map(int, ...)` の部分によって **整数値のイテレーターとして** 受け取ることができます。\n 4. * 固定長の場合、`a, b, c = map( ... )` のように書くことによって、イテレーターの先頭から 3 個 整数値をもらってきてそれぞれ `a`、`b`、`c` に代入します。それぞれの変数には各々ひとつの **整数値** が格納されます。\n * 可変長の場合、イテレーターではなくてリストとしてもらっておくと `numbers[0]` のように添え字付けができるので便利です。`list()` を使うとイテレーターをリストに変換できるので `numbers = list(map( ... ))` のように書くと `numbers` には **整数値のリスト** が格納されます。\n\n具体例で見てみましょう。入力が `5 8 7` だったとすると、それぞれの関数によって以下のように処理されていきます。\n\n```\n\n ↓ input()\n \"5 8 7\" (文字列)\n ↓ split()\n [\"5\", \"8\", \"7\"] (文字列のリスト)\n ↓ map(int, ...)\n [5, 8, 7] を返すようなイテレーター\n ↓ list()\n [5, 8, 7] (整数値のリスト)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T04:23:09.617", "id": "53046", "last_activity_date": "2021-12-30T03:34:31.117", "last_edit_date": "2021-12-30T03:34:31.117", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "53030", "post_type": "answer", "score": 2 } ]
53030
null
53046
{ "accepted_answer_id": "53038", "answer_count": 1, "body": "Rの関数化についての質問です。\n\n関数の中身のfor文だけ実行すると破壊的になりうまくいきますが、、関数として実行すると非破壊的になって更新されていないようです。 \nグローバル変数が原因かと想像しているのですが、<<-を使ってもうまく行かず、という感じです。\n\n```\n\n func <- function(x1,df){\n for(i in 1:nrow(df)){\n df[i,x1+1] <- min(df[i,1:x1]) \n }\n }\n \n```\n\nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T14:18:41.050", "favorite_count": 0, "id": "53033", "last_activity_date": "2019-02-26T00:21:18.887", "last_edit_date": "2019-02-25T14:27:07.243", "last_editor_user_id": "12457", "owner_user_id": "12457", "post_type": "question", "score": 0, "tags": [ "r" ], "title": "Rの関数化とfor文", "view_count": 177 }
[ { "body": "関数の戻り値を指定してみてはどうでしょうか?\n\n```\n\n func <- function(x1,df){\n for(i in 1:nrow(df)){\n df[i,x1+1] <- min(df[i,1:x1]) \n }\n df #これを追加\n }\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T00:21:18.887", "id": "53038", "last_activity_date": "2019-02-26T00:21:18.887", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "163", "parent_id": "53033", "post_type": "answer", "score": 1 } ]
53033
53038
53038
{ "accepted_answer_id": null, "answer_count": 0, "body": "GCP の compute instance のイメージとして、docker image を指定することは可能でしょうか?\n\nインスタンス上に docker container を立ち上げて、attach\n等は出来るかと思うのですが、そもそものインスタンスのイメージに適用したいです。よろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-25T16:24:42.933", "favorite_count": 0, "id": "53036", "last_activity_date": "2019-02-25T16:24:42.933", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20779", "post_type": "question", "score": 0, "tags": [ "docker", "google-cloud" ], "title": "GCPのインスタンスのイメージとして docker image を用いたい", "view_count": 45 }
[]
53036
null
null
{ "accepted_answer_id": null, "answer_count": 0, "body": "Debian stretch にDropBoxをインストールし、C++のソースコードを編集しようとしています。 \n他のIDEでは、問題ないんですが、DropBoxフォルダ内に、Eclipse3.8で作成したプロジェクトを、他のPCで開こうとするとプロジェクトを見つけることができません。 \nWorkSpaceディレクトリ内の、.metadata当たりが原因なのこと思うのですが、\n\n解決方法は、無いでしょうか?", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T00:23:28.433", "favorite_count": 0, "id": "53039", "last_activity_date": "2019-02-26T05:45:17.123", "last_edit_date": "2019-02-26T05:45:17.123", "last_editor_user_id": "3060", "owner_user_id": "15090", "post_type": "question", "score": 0, "tags": [ "eclipse", "debian", "dropbox" ], "title": "Dropboxフォルダに保存したEclipseのプロジェクトが他のPCから開けない", "view_count": 97 }
[]
53039
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "<https://pypi.org/>\nから`matplotlib-3.0.2-cp37-cp37m-win_amd64.whl`をダウンロードしてコマンドプロンプトから\n\n```\n\n c:\\Users\\ユーザー名\\Downloads>pip install matplotlib-3.0.2-cp37-cp37m_amd.whl\n \n```\n\nと実行しても下記の様にエラー表示されてインストール出来ません。 \n対処方法が分かりましたら教えていただけないでしょうか?\n\n```\n\n Processing c:\\users\\m3170\\downloads\\matplotlib-3.0.2-cp37-cp37m-win_amd64.whl\n Collecting kiwisolver>=1.0.1 (from matplotlib==3.0.2)\n Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0000020FF8DE9B70>: Failed to establish a new connection: [WinError 10061] 対象のコンピューターによって拒否されたため、接続できませんでした。')': /simple/kiwisolver/\n \n```", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T02:01:45.717", "favorite_count": 0, "id": "53041", "last_activity_date": "2019-10-30T16:00:50.093", "last_edit_date": "2019-02-26T03:47:57.473", "last_editor_user_id": "5246", "owner_user_id": "32321", "post_type": "question", "score": 0, "tags": [ "python", "python3", "matplotlib" ], "title": "python3.7にmatplotlibがインストール出来ません。", "view_count": 1560 }
[ { "body": "proxy経由で接続する必要があるのではないでしょうか。下記のようにproxyオプションをつけて実行してみてください!\n\n```\n\n pip install --proxy http://[user:password@]proxyserver:port package\n \n```\n\n英語版だとこちらかと! \n<https://stackoverflow.com/questions/14149422/using-pip-behind-a-proxy>", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T03:09:18.873", "id": "53042", "last_activity_date": "2019-02-26T03:09:18.873", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23582", "parent_id": "53041", "post_type": "answer", "score": 1 } ]
53041
null
53042
{ "accepted_answer_id": "53056", "answer_count": 1, "body": "`gem install nmatrix-lapacke`をしたところ下記のようなエラーが出まして,正常にインストールされていない模様です. \n対処法を調査してもわからないので,どなたかご教授お願い致します\n\n以下,エラーログです.\n\n```\n\n $ gem install nmatrix-lapacke\n Building native extensions. This could take a while...\n ERROR: Error installing nmatrix-lapacke:\n ERROR: Failed to build gem native extension.\n \n current directory: /gpfs/home/home1/t163202/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nmatrix-lapacke-0.2.4/ext/nmatrix_lapacke\n /gpfs/home/home1/t163202/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20190226-36390-ps5zbi.rb extconf.rb\n using C++ standard... c++11\n g++ reports version... gcc\n checking for rb_array_const_ptr() in ruby.h... yes\n checking for -llapack... no\n creating nmatrix_lapacke_config.h\n creating Makefile\n \n current directory: /gpfs/home/home1/t163202/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nmatrix-lapacke-0.2.4/ext/nmatrix_lapacke\n make \"DESTDIR=\" clean\n \n current directory: /gpfs/home/home1/t163202/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nmatrix-lapacke-0.2.4/ext/nmatrix_lapacke\n make \"DESTDIR=\"\n compiling nmatrix_lapacke.cpp\n cc1plus: warning: command line option '-Wimplicit-int' is valid for C/ObjC but not for C++\n cc1plus: warning: unrecognized command line option '-Wno-self-assign'\n cc1plus: warning: unrecognized command line option '-Wno-constant-logical-operand'\n cc1plus: warning: unrecognized command line option '-Wno-parentheses-equality'\n cc1plus: warning: unrecognized command line option '-Wno-tautological-compare'\n compiling math_lapacke.cpp\n cc1plus: warning: command line option '-Wimplicit-int' is valid for C/ObjC but not for C++\n cc1plus: warning: unrecognized command line option '-Wno-self-assign'\n cc1plus: warning: unrecognized command line option '-Wno-constant-logical-operand'\n cc1plus: warning: unrecognized command line option '-Wno-parentheses-equality'\n cc1plus: warning: unrecognized command line option '-Wno-tautological-compare'\n compiling lapacke.cpp\n cc1plus: warning: command line option '-Wimplicit-int' is valid for C/ObjC but not for C++\n cc1plus: warning: unrecognized command line option '-Wno-self-assign'\n cc1plus: warning: unrecognized command line option '-Wno-constant-logical-operand'\n cc1plus: warning: unrecognized command line option '-Wno-parentheses-equality'\n cc1plus: warning: unrecognized command line option '-Wno-tautological-compare'\n linking shared-object nmatrix_lapacke.so\n /home/1/t163202/.linuxbrew/bin/ld: cannot find -llapack\n collect2: error: ld returned 1 exit status\n make: *** [nmatrix_lapacke.so] エラー 1\n \n make failed, exit code 2\n \n Gem files will remain installed in /gpfs/home/home1/t163202/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/nmatrix-lapacke-0.2.4 for inspection.\n Results logged to /gpfs/home/home1/t163202/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0-static/nmatrix-lapacke-0.2.4/gem_make.out\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T08:16:13.240", "favorite_count": 0, "id": "53051", "last_activity_date": "2019-02-26T13:28:35.810", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30173", "post_type": "question", "score": 0, "tags": [ "ruby", "rubygems" ], "title": "gemのインストールエラーがわからない", "view_count": 560 }
[ { "body": "依存するlapackというパッケージが存在しないためにエラーとなっています。 \nお使いのOSに該当のライブラリを導入して再度インストールしてみてください。\n\n<https://qiita.com/AnchorBlues/items/69c1744de818b5e045ab> \n<https://www.atmarkit.co.jp/flinux/rensai/linuxtips/a115makeerror.html>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T13:28:35.810", "id": "53056", "last_activity_date": "2019-02-26T13:28:35.810", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10174", "parent_id": "53051", "post_type": "answer", "score": 1 } ]
53051
53056
53056
{ "accepted_answer_id": null, "answer_count": 0, "body": "Google Indexing API 用のWordPressのプラグインを作っています。 \nリアルタイムに処理するリクエストは200が返ってきますが、バッチ処理の場合、404が返ってきてしまいます。\n\n```\n\n require_once plugin_dir_path( __FILE__ ).'/vendor/autoload.php';\n \n $client = new Google_Client();\n $client->setAuthConfig(plugin_dir_path( __FILE__ ).'/config/secret-key.json');\n // Setting Scope\n $client->addScope(\"https://www.googleapis.com/auth/indexing\");\n // Use batch\n $client->setUseBatch(true);\n \n $batch = new Google_Http_Batch($client,false,'https://indexing.googleapis.com');\n // example url\n $arr_url = array(\n \"https://example.com/job_option/job_op-title-job/\",\n \"https://example.com/job_option/job_op-44/\",\n \"https://example.com/job_option/job_op-title-job/job_op-31/\",\n );\n foreach ($arr_url as $url) {\n $postBody = new Google_Service_Indexing_UrlNotification();\n $postBody->setType('URL_UPDATED');//regist.update\n $postBody->setUrl($url);\n $service = new Google_Service_Indexing($client);\n $request = $service->urlNotifications->publish($postBody);\n $batch->add($request);\n }\n $results = $batch->execute();\n \n```\n\n上記のコードで404だったので調べて別の書き方をしてみました。\n\n```\n\n require_once plugin_dir_path( __FILE__ ).'/vendor/autoload.php';\n \n   $client->setAuthConfig( plugin_dir_path( __FILE__ ).'/config/secret-key.json');\n $client->addScope('https://www.googleapis.com/auth/indexing');\n \n $client->setUseBatch(true);\n $batch = new Google_Http_Batch($client);\n \n // after authorization done, send the request to Google api\n $endpoint = \"https://indexing.googleapis.com/batch\";\n \n \n $content = json_encode(array(\n \"url\" => \"https://example.com/job_option/job_op-title-job/job_op-31/\",\n \"type\" => \"URL_UPDATED\"\n ),JSON_FORCE_OBJECT);\n \n $request = new CreateRequest('POST', $endpoint, ['body' => $content]);\n \n $batch->add($request);\n $results = $batch->execute();\n \n```\n\nこの書き方でも同じように404が返ってきてしまいます。\n\nサービスアカウントは正しく作成しました。AWS上のCloudFrontで構築されているWordPressテストサイト(公開済み)からの送信しています。色々調べましたが解決の糸口が見つかりません。 \nどうかご教授いただきたいです。よろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T09:25:19.400", "favorite_count": 0, "id": "53052", "last_activity_date": "2019-02-26T09:25:19.400", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29473", "post_type": "question", "score": 2, "tags": [ "php", "wordpress", "google-api" ], "title": "Google Indexing API Batching Requests - 404 Not Found Response", "view_count": 136 }
[]
53052
null
null
{ "accepted_answer_id": null, "answer_count": 3, "body": "Discord.pyを使っていたのですが、ボットに下記のコードを使ってembedを表示させようとしても表示されません。どこを修正すればいいのでしょうか?\n\n```\n\n import discord\n \n client = discord.Client()\n \n @client.event\n async def on_ready():\n print('We have logged in as {0.user}'.format(client))\n \n @client.event\n async def on_message(message):\n if message.author == client.user:\n return\n if message.content.startswith('$test'):\n await message.channel.send((embed))\n embed=embedobj\n embed = discord.Embed(title=\"ぼっとヘルプ一覧\", colour=discord.Colour(0x112f43), url=\"https://discordapp.com\", description=\"```Prefix:$```\", timestamp=datetime.datetime.utcfromtimestamp(1551172370))\n \n embed.set_image()\n embed.set_thumbnail(url=\"http://3.bp.blogspot.com/-k74QBLjNuyg/TtiCcfDf2pI/AAAAAAAAAGw/coMwMiItguo/s1600/Mameshiba-Edamame-Wallpaper.jpg\")\n embed.set_author(name=\"eDaMAme#1597\", url=\"https://discordapp.com\", icon_url=\"https://bit.ly/2SsIBiC\")\n embed.set_footer(text=\"footer text\", icon_url=\"https://cdn.discordapp.com/embed/avatars/0.png\")\n \n embed.add_field(name=\"$hello\", value=\"挨拶をします\")\n embed.add_field(name=\"$weather\", value=\"お天気情報\")\n embed.add_field(name=\"$zisin\", value=\"地震情報\")\n embed.add_field(name=\"$happy,$sad,$angry\", value=\"絵文字表示\", inline=True)\n embed.add_field(name=\"そのほかいろいろ\", value=\"追加予定\", inline=True)\n \n await bot.say(embed=embed)\n \n client.run('token')\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T09:29:02.860", "favorite_count": 0, "id": "53053", "last_activity_date": "2022-06-21T15:07:23.210", "last_edit_date": "2019-02-26T12:34:58.530", "last_editor_user_id": "3060", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "python", "discord" ], "title": "Discord.pyを使っていたのですが、ボットに下記のコードを使ってembedを表示させようとしても表示されません。どこを修正すればいいのでしょうか?", "view_count": 1099 }
[ { "body": "asyncバージョンですね。もうそろそろ巨大アップデートがあるので、早めに新バージョンの[Rewrite](https://discordpy.readthedocs.io/ja/latest/index.html)に乗り換えたほうがいいですよ。\n\n本題に入りますが、まず`embed=embedobj`が気になります。embedobjは未定義のようです。この行は要らないと思います。 \nまた、`embed.set_image()`には引数がいります。画像を付けない場合はその行はなくてOKです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T10:08:40.983", "id": "53054", "last_activity_date": "2019-02-26T10:08:40.983", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29212", "parent_id": "53053", "post_type": "answer", "score": 1 }, { "body": "エラーは出てないですよね?\n\n```\n\n if message.author == client.user:\n \n```\n\nこれが問題ではないでしょうか?\n\n```\n\n if message.author == client.user:\n return\n \n```\n\nこれではユーザーが発したメッセージをはじくということになります。 \nBOTの発言をはじきたかったら\n\n```\n\n if message.author.bot:\n return\n \n```\n\nこのように書き換えましょう。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2020-05-09T01:18:12.827", "id": "66444", "last_activity_date": "2020-05-09T03:39:34.017", "last_edit_date": "2020-05-09T03:39:34.017", "last_editor_user_id": "32986", "owner_user_id": "40011", "parent_id": "53053", "post_type": "answer", "score": 0 }, { "body": "```\n\n import discord\n \n embed = discord.Embed(title=\"ぼっとヘルプ一覧\", colour=discord.Colour(0x112f43), url=\"https://discordapp.com\", description=\"```Prefix:$```\", timestamp=datetime.datetime.utcfromtimestamp(1551172370))\n embed.set_thumbnail(url=\"http://3.bp.blogspot.com/-k74QBLjNuyg/TtiCcfDf2pI/AAAAAAAAAGw/coMwMiItguo/s1600/Mameshiba-Edamame-Wallpaper.jpg\")\n embed.set_author(name=\"eDaMAme#1597\", url=\"https://discordapp.com\", icon_url=\"https://bit.ly/2SsIBiC\")\n embed.set_footer(text=\"footer text\", icon_url=\"https://cdn.discordapp.com/embed/avatars/0.png\")\n embed.add_field(name=\"$hello\", value=\"挨拶をします\")\n embed.add_field(name=\"$weather\", value=\"お天気情報\")\n embed.add_field(name=\"$zisin\", value=\"地震情報\")\n embed.add_field(name=\"$happy,$sad,$angry\", value=\"絵文字表示\", inline=True)\n embed.add_field(name=\"そのほかいろいろ\", value=\"追加予定\", inline=True)\n \n client = discord.Client(intents=discord.Intents.all())\n \n @client.event\n async def on_ready():\n print('We have logged in as {0.user}'.format(client))\n \n @client.event\n async def on_message(message):\n if message.author == client.user:\n return\n if message.content.startswith('$test'):\n await message.channel.send(embed=embed)\n \n client.run('token')\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2022-06-21T15:07:23.210", "id": "89512", "last_activity_date": "2022-06-21T15:07:23.210", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "53038", "parent_id": "53053", "post_type": "answer", "score": 0 } ]
53053
null
53054
{ "accepted_answer_id": null, "answer_count": 0, "body": "JSONP形式で返却するWebAPIを作成したい。(GETメソッド) \n環境はSpring4\n\n既にJSON形式で返却するAPIを実装済み。 \ncallbackパラメータを付与したときにJSONP形式で返却したい。\n\n<https://spring.io/blog/2014/07/28/spring-framework-4-1-spring-mvc-\nimprovements> \n上記を参考に、実装したが、実際の結果はJSON形式のままである。\n\n以下のファイルをコントローラと同階層に作成 \n※作成場所が不明だったため、正しい階層があれば知りたい \nサイトを参考に作成\n\n```\n\n @ControllerAdvice\n private static class JsonpAdvice extends AbstractJsonpResponseBodyAdvice {\n public JsonpAdvice() {\n super(\"callback\");\n }\n }\n \n```\n\nController \nresultBeanは、Listを含むクラスを定義\n\n```\n\n @RequestMapping(value = \"/AAA\", produces = MediaType.APPLICATION_JSON_VALUE)\n public class AAA{\n ~~\n @ResponseBody\n @RequestMapping(method = RequestMethod.GET)\n public resultBean getresult(\n @RequestParam(value = \"key\", required = true) final String key,\n final HttpServletRequest request, \n final HttpServletResponse response)\n {\n ~~\n return resultBean\n }\n \n```\n\nXMLの修正など、情報がなかったため、編集していません。 \nアノテーションをうまく認識してくれたら、うまくいくのか… \n何かお気づきの点・代替案あれば、ご教示ください。\n\nテストにはPOSTMANを使用してます。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-26T10:25:44.363", "favorite_count": 0, "id": "53055", "last_activity_date": "2019-02-26T10:25:44.363", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32326", "post_type": "question", "score": 0, "tags": [ "java", "json", "spring", "rest" ], "title": "RESTをJSONP形式で返却する(Spring MVC )", "view_count": 548 }
[]
53055
null
null
{ "accepted_answer_id": "53069", "answer_count": 1, "body": "xmlをDiscord.pyで常に取得して更新があったらDiscord上に通知するというコードが書きたいのですが書き方が分かりません。\n\nxmlはこれなのですが・・・ \n<http://www3.nhk.or.jp/sokuho/jishin/data/JishinReport.xml>\n\n追記 \nイベントは何を使えばいいのかと、 \nxml(URLのもの)を表示させるのにどのように変換するのかがわかりません。\n\nver \ndiscord.py 1.0.0a \npython 3.6.6\n\n現在自分のできることをするとメッセージのテンプレートしかできておりません。\n\n```\n\n @commands.command()\n async def jisin(self, ctx):\n if ctx.channel.id == 517714262198845460:\n embed = discord.Embed(title=\"MLSBOT緊急地震速報\", description='', color=0xff0000)\n replay = datetime.now().strftime(\"%Y年%m月%d日 %H時%M分\")\n embed.add_field(name=\"発生時間\", value=replay, inline=True)\n embed.add_field(name=\"深央\", value=\"震央\", inline=True)\n embed.add_field(name=\"深さ\", value=\"30km\", inline=True)\n embed.add_field(name=\"強さ(M)\", value=\"M3.4\", inline=True)\n embed.add_field(name=\"最大震度\", value=\"震度1\", inline=True)\n embed.add_field(name=\"最大震度1を観測した地域\", value=\"・○○\\n・××\\n・△△\", inline=True)\n await ctx.send(embed=embed)\n \n```\n\nbotに送信させたいメッセージは以下のような感じです。\n\n[![地震の各種情報が書かれている画像です。](https://i.stack.imgur.com/6bCOk.jpg)](https://i.stack.imgur.com/pjSuS.jpg)", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T04:11:07.327", "favorite_count": 0, "id": "53060", "last_activity_date": "2019-02-27T12:42:13.910", "last_edit_date": "2019-02-27T10:05:40.743", "last_editor_user_id": "32332", "owner_user_id": "32332", "post_type": "question", "score": 0, "tags": [ "python", "python3", "discord" ], "title": "discord.pyで地震速報botが作りたい", "view_count": 2621 }
[ { "body": "素朴に書くと、以下の流れを一定の時間間隔ごとに実行する Python プログラムを書くことになるでしょう。\n\n 1. URL から XML をダウンロード。\n 2. 変更があるかチェック。\n 3. 変更があれば、XML をパースして Python オブジェクトにする。文字コードに注意。\n 4. 必要な情報を読み取り、メッセージ用の文字列を作る。\n 5. Discord にメッセージを送る。\n\n1~3 の部分は、それぞれ適切なライブラリを使えば簡単に実装できそうです。検索するといくつかでてきます。XML\nの各種情報については[「NHKの地震情報を掻っ攫う方法」](https://qiita.com/ot1r/items/aff63d49273ef8be5993)という記事が詳しかったです。\n\nしかし、もし速報性の高い地震速報として使うのであればこのやり方にはやや問題があります。地震速報として機能させるためには地震情報が出てから数秒の内にはメッセージが送信されていることが望ましいですが、そのためにはほんの数秒単位ごとに\nNHK\nのサイトに対して繰り返しアクセスをかけることになります。[岡崎市立中央図書館事件](https://ja.wikipedia.org/wiki/%E5%B2%A1%E5%B4%8E%E5%B8%82%E7%AB%8B%E4%B8%AD%E5%A4%AE%E5%9B%B3%E6%9B%B8%E9%A4%A8%E4%BA%8B%E4%BB%B6)と、[同事件がウェブスクレイピングに与えた影響](https://vaaaaaanquish.hatenablog.com/entry/2017/12/01/064227)を鑑みるに、あまり高頻度なアクセスをすることにはリスクがあります。また、緊急地震速報が出てからこの\nXML が更新されるまでのラグがあるかもしれないことにも注意しておくべきでしょう。逆に、ある程度ラグがあって良いなら上のやり方で目的が達成できます。\n\nもし緊急地震速報 (EEW)\nのようなものを実装したいのであれば、[既存の類似アプリたちがどのように実装しているのか](https://www10.atwiki.jp/p2peq/pages/43.html)が参考になるかと思います。個人だと高度利用者向け緊急地震速報の利用は現実的でないので、「緊急地震速報\nby Extension」のように Twitter の API 経由で取得する方法などが考えられます。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T10:16:46.687", "id": "53069", "last_activity_date": "2019-02-27T12:42:13.910", "last_edit_date": "2019-02-27T12:42:13.910", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "53060", "post_type": "answer", "score": 0 } ]
53060
53069
53069
{ "accepted_answer_id": "53093", "answer_count": 2, "body": "PowerShellでGitのログ出力を加工しようとしたのですが、日本語が文字化けしてしまいます。 \n文字化けしないようにするにはどうしたら良いのでしょうか。\n\n以下、現象の発生するコード例です。\n\n```\n\n Invoke-Expression \"git log --oneline\" | Select-Object -First 5\n \n```\n\n* * *\n\n### 試したこと\n\n`$env:LANG = \"ja_JP.UTF-8\"` を実行することで `git log`\n単体実行での文字化けは治るのですが、パイプ処理や、リダイレクトでファイル出力すると、同様の文字化けが発生してしまいます。\n\n* * *\n\n### 環境\n\n * Windows10 Pro 64bit (1809)\n * PowerShell version 5.1.17763.316\n * git version 2.18.0.windows.1", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T04:15:52.680", "favorite_count": 0, "id": "53061", "last_activity_date": "2019-02-28T10:28:47.907", "last_edit_date": "2019-02-28T10:28:47.907", "last_editor_user_id": "14817", "owner_user_id": "14817", "post_type": "question", "score": 3, "tags": [ "git", "powershell", "文字化け" ], "title": "PowerShell処理でgitログが文字化けする", "view_count": 4731 }
[ { "body": "以下の2通りの方法で文字化けなく処理できるようになりました。\n\n* * *\n\n### 方法1: [Console]::OutputEncoding に UTF8 を指定する\n\n```\n\n $enc = [Console]::OutputEncoding\n try\n {\n [Console]::OutputEncoding = [Text.Encoding]::UTF8\n Invoke-Expression \"git log --oneline\" | Select-Object -First 5\n }\n finally\n {\n [Console]::OutputEncoding = $enc\n }\n \n```\n\n* * *\n\n### 方法2: nkf で SJIS に変換する\n\n`nkf32.exe` を入手し、gitコマンド出力をSJISに変換するバッチファイル(git_sjis.bat)を作る。\n\n```\n\n @echo off\n git %1 %2 %3 %4 %5 %6 %7 %8 %9 | nkf32.exe -s\n \n```\n\n```\n\n Invoke-Expression \".\\git_sjis.bat log --oneline\" | Select-Object -First 5\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T16:24:59.080", "id": "53074", "last_activity_date": "2019-02-27T16:52:49.543", "last_edit_date": "2019-02-27T16:52:49.543", "last_editor_user_id": "14817", "owner_user_id": "14817", "parent_id": "53061", "post_type": "answer", "score": 2 }, { "body": "一般論として、特にリダイレクトはあくまでバイト列を送受信するものであり、送り側と受け側での合意がなければやり取りできません。更にUNIX系ツールでは送受信されるデータを関与していないものが多いです。 \nところがWindowsでは状況がかなり異なります。基本的にコントロールパネルで設定されたエンコーディングでテキストデータがやり取りされていることを前提としています。その際、日本語においてはShift_JISしか設定できません。 \nまたPowerShellなどの多くのアプリケーションは受け取ったテキストをUnicodeに変換して処理するためエンコーディングが非常に重要となります。\n\n以上を踏まえて、送り側と受け側とでどのようなバイト列とするかをプログラムの組み合わせ毎に設計する必要があります。\n\n* * *\n\n質問では、`git`がログメッセージを出力し、`PowerShell`がその文字列を受け取ることとなっています。neeさんからも回答がありますが、それ以外にも方法があって、例えば`git\nlog`コマンドには[`--encoding`オプション](https://git-scm.com/docs/git-log#git-log---\nencodingltencodinggt)が存在します。環境変数`LANG`は特に設定せず\n\n```\n\n Invoke-Expression \"git log --encoding=Shift_JIS --oneline\" | Select-Object -First 5\n \n```\n\nとやる方法もあります。\n\nもちろん個別に指定するのではなく`i18n.logOutputEncoding`設定でデフォルト値を変更することもできます。ただし、`git`コマンドは`PAGER`を呼び出したりといろいろなプログラムと組み合わせるため、先に述べた通り、どのプログラムとどのプログラムをどのエンコーディングでやり取りするかを検討しなければなりませんので、万能な回答は難しいです。\n\n* * *\n\nneeさんの回答に`[Console]::OutputEncoding`を使った方法が挙げられていますが、罠があるため指摘しておきます。もちろん、送り側・受け側でUTF-8を使用するのは選択肢の一つとして正しいです。しかし、`[Console]::OutputEncoding`を変更するとそれに従ってコンソールのフォントも変更されます。手元の環境では`Consolas`に変更されました。この状態ですとプログラム間は正しくテキストをやり取りできていますが、コンソールが日本語を表示できません。一度、フォント設定を`MSゴシック`等に変更することで解消されますが、設定を行っていない環境では文字化けが解消していないかのような誤解を与えますのでお気を付けください。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T07:52:49.130", "id": "53093", "last_activity_date": "2019-02-28T08:15:40.227", "last_edit_date": "2019-02-28T08:15:40.227", "last_editor_user_id": "4236", "owner_user_id": "4236", "parent_id": "53061", "post_type": "answer", "score": 5 } ]
53061
53093
53093
{ "accepted_answer_id": null, "answer_count": 1, "body": "vue-cliを使ってvueの環境構築をするため、 \nnpmからvue-cliをインストールしたのですが、vueコマンドが認識されずにエラーになってしまいます。\n\n```\n\n npm i -g @vue/cli\n \n vue --version\n \n vue : 用語 'vue' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。\n 名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、再試行してください。\n 発生場所 行:1 文字:1\n + vue --version\n + ~~~\n + CategoryInfo : ObjectNotFound: (vue:String) [], CommandNotFoundException\n + FullyQualifiedErrorId : CommandNotFoundException\n \n```\n\nvue-cliをインストールした後に環境変数の設定をする必要があるのでしょうか? \n教えていただきたいです。\n\n環境はwindows10です。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T05:48:19.160", "favorite_count": 0, "id": "53062", "last_activity_date": "2019-02-28T09:00:05.757", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29531", "post_type": "question", "score": 1, "tags": [ "windows-10", "vue.js", "npm" ], "title": "vueコマンドが認識されない", "view_count": 7184 }
[ { "body": "node.jsのインストーラーを使った場合、デフォルトではインストール時にスクリプトのフォルダがPATHに追加されます。\n\n何かの理由でPATHにない場合は、`npm install -g`でのインストール先を`npm bin -g`で確認し、PATHに追加で解決するはずです。\n\n```\n\n > npm bin -g\n C:\\Users\\foobar\\AppData\\Roaming\\npm\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T09:00:05.757", "id": "53096", "last_activity_date": "2019-02-28T09:00:05.757", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "241", "parent_id": "53062", "post_type": "answer", "score": 2 } ]
53062
null
53096
{ "accepted_answer_id": "53064", "answer_count": 1, "body": "Grid-EYE(ROBOBA041)という温度センサの出力温度データを,ESP-\nWROOM-02をWebサーバとして用いて,ブラウザに表示したいと考えています.そこで以下のようなプログラムを作成しました.\n\n```\n\n #include <WiFiClient.h>\n #include <ESP8266WiFi.h>\n #include <ESP8266WebServer.h>\n #include <Wire.h>\n #include <GridEye.h>\n \n GridEye myeye = GridEye(GridEye_DeviceAddress_1);\n ESP8266WebServer server(80);\n \n void onroot() {\n String msg ;\n int pixel[64];\n msg += \"<!DOCTYPE html>\";\n msg += \"<html><head><meta charset=\\\"utf-8\\\">\";\n msg += \"<meta http-equiv=\\\"content-type\\\" content=\\\"text/html; \n charset=UTF-8\\\">\";\n msg += \"<title>Temperature</title><body>\";\n myeye.pixelOut(pixel); // Grid-EYEの温度データ読み出し\n for (int i = 0; i < 64; i++) {\n if (i && ((i % 8) == 0)) {\n msg += \"<br>\";\n }\n msg += \"<font size='3'>\" + String(pixel[i]* 0.25) + \"</font>\"; //温度デー \n タを表示\n msg += \"&nbsp;\";\n }\n msg += \"<p id=\\\"LED\\\"></p>\";\n msg += \"</body></html>\";\n server.send(200, \"text/html\", msg);\n }\n \n void setup() {\n Serial.begin(115200);\n Wire.begin();\n WiFi.config(IPAddress(***, ***, ***, ***), WiFi.gatewayIP(), \n WiFi.subnetMask());//使いたいIPアドレスを指定\n WiFi.begin(\"*******\", \"********\");\n \n WiFi.mode(WIFI_STA);\n \n // Web server setting\n server.on(\"/\", onroot);\n server.begin();\n }\n \n void loop() {\n server.handleClient();\n }\n \n```\n\nそして,このプログラムを実行したところ,以下のようにブラウザ出力されました. \n[![上記プログラム出力結果](https://i.stack.imgur.com/bijGn.png)](https://i.stack.imgur.com/bijGn.png)\n\nこの出力結果より,温度データを表示することはできたのですが,データの更新を行うことができません.ブラウザの更新ボタン(F5)を押下することで,データの更新を行うことはできるのですが,私としては更新を逐一自動的に行えるようにしたいのです.(ブラウザを表示させておくだけで,温度データの数値が一定周期ごとに切り替わるようにしたい) \nこの目的を実現させるには,どのようにプログラムを改変させればよいのでしょうか. \n初めての質問ということで,拙い文章となってしまいましたが,よろしくお願いします.\n\n補足 \nGrid-EYEは二次元温度データを8*8要素の数値として出力する赤外線アレイセンサです.なので出力される温度データも8*8(64)となっています.\n\n開発環境はArduinoIDEです", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T05:55:17.130", "favorite_count": 0, "id": "53063", "last_activity_date": "2019-02-27T06:30:19.943", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32334", "post_type": "question", "score": 0, "tags": [ "javascript", "html", "css", "arduino" ], "title": "温度センサによるデータをブラウザ出力し,自動的に更新するようにしたい", "view_count": 1315 }
[ { "body": "ブラウザのリロードでよいなら、`<META>`タグで以下の記述を行えば(プログラム中で出力すれば)指定間隔でページが再読み込みされます。\n\n```\n\n <meta http-equiv=\"refresh\" content=\"秒数\">\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T06:30:19.943", "id": "53064", "last_activity_date": "2019-02-27T06:30:19.943", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "53063", "post_type": "answer", "score": 0 } ]
53063
53064
53064
{ "accepted_answer_id": "53199", "answer_count": 1, "body": "※いただいたコメントにより修正しました。\n\n下記の機能を実装したwebサイトを制作したいです。\n\n・画像URLを入力またはアップロードで取得した画像をブラウザに表示する \n・表示した画像にマウスカーソルをのせると、PhotoshopやIllustratorで言うところのペンツールのような機能を持った **ツールA**\n※1に切り替わる \n・ **ツールA** で三角形以上の多角形を作ると、その多角形の内側を黒ベタに塗りつぶす \n・黒ベタが施された状態の画像※2を保存できるボタン \n※1: **ツールA** の動きは直線のみで、例えで出したペンツールに実装されているカーブ生成機能並びにカーブを調整するハンドルは不要です。 \n※2:画像サイズとファイル形式は元画像のまま。\n\n以上です。 \n下図は上記の機能を分かりやすくするためと、使用手順を説明する趣意の図です。 \n※下図において画像読込機能については都合により省略します。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/20eBw.jpg)](https://i.stack.imgur.com/20eBw.jpg)\n\n現状は画像読込機能のみ、HTML,css,jsで実装できました。 \n下記サンプルです。 \n<https://jsbin.com/fojaqedito/edit?html,js,output> \nしかし、その他の機能についてはどの言語で、どのように書けば実装できるのかが分からず困っています。 \nできればHTML,css,jsで実装したいですが他言語でも構いません。 \nご助力お願いいたします。\n\n```\n\n $(function () {\r\n \r\n //input url\r\n $('#url').change(function () {\r\n $('#main_file').fadeOut(1);\r\n $('#main_url').fadeIn(500);\r\n $('#view_url').prop('src', this.value);\r\n console.log(this.value);\r\n var file = $('#file')[0];\r\n file.value = \"\";\r\n });\r\n //input file\r\n $('#file').change(function (e) {\r\n var reader = new FileReader();\r\n reader.onload = function (e) {\r\n $('#main_url').fadeOut(1);\r\n $('#main_file').fadeIn(500);\r\n $('#view_file').prop('src', e.target.result);\r\n var url = $('#url')[0];\r\n url.value = \"\";\r\n }\r\n reader.readAsDataURL(e.target.files[0]);\r\n });\r\n \r\n //close\r\n $('.close').click(function () {\r\n $('.main').fadeOut();\r\n var url = $('#url')[0];\r\n url.value = \"\";\r\n var file = $('#file')[0];\r\n file.value = \"\";\r\n });\r\n \r\n });\n```\n\n```\n\n .main{\r\n display: none\r\n }\n```\n\n```\n\n <!DOCTYPE html>\r\n <html>\r\n <head>\r\n <meta charset=\"utf-8\">\r\n <meta name=\"viewport\" content=\"width=device-width\">\r\n <title>JS Bin</title>\r\n <script\r\n src=\"https://code.jquery.com/jquery-3.3.1.js\"\r\n integrity=\"sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=\"\r\n crossorigin=\"anonymous\"></script>\r\n </head>\r\n <body>\r\n <!-- input URL -->\r\n <input id=\"url\" type=\"text\" placeholder=\"URLを入力\">\r\n <!-- input file -->\r\n <input id=\"file\" type=\"file\" accept=\"image/*\">\r\n <!-- output url -->\r\n <div id=\"main_url\" class=\"main\">\r\n <img id=\"view_url\" class=\"view\">\r\n <button class=\"save\">保存</button>\r\n <button class=\"close\">クリア</button>\r\n </div>\r\n <!-- outoput file -->\r\n <div id=\"main_file\" class=\"main\">\r\n <img id=\"view_file\" class=\"view\">\r\n <button class=\"save\">保存</button>\r\n <button class=\"close\">クリア</button>\r\n </div>\r\n </body>\r\n </html>\n```", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T08:00:46.387", "favorite_count": 0, "id": "53065", "last_activity_date": "2019-03-05T02:45:48.107", "last_edit_date": "2019-03-03T21:56:13.593", "last_editor_user_id": "32275", "owner_user_id": "32275", "post_type": "question", "score": 0, "tags": [ "javascript", "html", "jquery", "css" ], "title": "読み込んだ画像の範囲指定したところを黒く塗りつぶしたい", "view_count": 1005 }
[ { "body": "`<canvas>` で実装するのがベストかと思います。コードは大きくなりそうなので、方針だけ書きます。\n\n 1. 指定された画像を `<canvas>` に描画する\n 2. 範囲指定のUIを実装する。`click`イベントハンドラで座標を記録して線を描くなど。\n 3. 範囲指定がおわったら、 \n 1. 指定領域を黒く塗る\n 2. [`toBlob()`](https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob)で画像をエンコードする。\n 3. エンコードが終わったら、[保存]ボタンを `<a download>`で作り、その href に [`URL.createObjectURL(blob)`](https://w3c.github.io/FileAPI/#dfn-createObjectURL) で生成したblob URLをセットする。\n\n個々のステップの実装で疑問がでたら個別に質問を立てるとよいかと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T02:45:48.107", "id": "53199", "last_activity_date": "2019-03-05T02:45:48.107", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3475", "parent_id": "53065", "post_type": "answer", "score": 2 } ]
53065
53199
53199
{ "accepted_answer_id": "53068", "answer_count": 1, "body": "下記の様なコードがあった場合、エラーケースではsplitでエラーが発生します。 \nmapなどを繋げて書いた際の途中でエラーが発生する場合、 \nRustでうまくエラーハンドリングするにはどの様に書くのが良いですか\n\n```\n\n use std::collections::HashMap;\n \n fn to_hash(kv: &str) -> Result< HashMap<String,String>, String> {\n let _hashmap = kv\n .split(',')\n .map(|kv| kv.split('='))\n .map(|mut kv| (kv.next().unwrap().into(), kv.next().unwrap().into()))\n .collect::<HashMap<String, String>>();\n Ok(_hashmap)\n \n // Err handling?\n }\n fn main() {\n // Ok.\n let kv1 = \"key1=value1,key2=value2,key3=value3\";\n match to_hash(kv1) {\n Ok(n) => println!(\"{:?}\",n),\n Err(e) => println!(\"{:?}\",e),\n }\n \n // Err.\n let kv2 = \"key1=value1,key2=value2,key3=value3,\";\n match to_hash(kv2) {\n Ok(n) => println!(\"{:?}\",n),\n Err(e) => println!(\"{:?}\",e),\n }\n \n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T08:50:03.553", "favorite_count": 0, "id": "53066", "last_activity_date": "2019-02-27T09:43:44.253", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32285", "post_type": "question", "score": 3, "tags": [ "rust" ], "title": "Rustのmapなどで繋げて記載した場合のエラーハンドリングについて", "view_count": 1183 }
[ { "body": "こんにちは、κeenです。 \nエラーが出て困っているわけではなくてエラーを適切に処理する方法を知りたいということでよろしいですか? \nRustでは回復不可能なパニックと、値として取り扱えるエラーは区別されています。今回はパニックが出て困っているのでエラーにしたいという質問として受け取りました。\n\n以下のように書き換えるのはどうでしょう。\n\n```\n\n // * .unwrap() を使うとパニックになってしまい、そのままプログラムが終了してしまうので極力使わない。\n // * ResultやOptionはそのまま伝播させて使う。\n \n use std::collections::HashMap;\n \n fn to_hash(kv: &str) -> Result<HashMap<String, String>, String> {\n kv.split(',')\n .map(|kv| kv.split('='))\n // 説明のわかりやすさのために型を明示する。なくてもコンパイルは通る\n .map(|mut kv| -> Option<(String, String)> {\n // `?` 演算子で `None` だった場合にそのまま関数(クロージャ)から返せる。\n Some((kv.next()?.into(), kv.next()?.into()))\n })\n // collectは Option<T>, Option<T>, ... のイテレータから Option<Tのコレクション> を作れる。\n .collect::<Option<HashMap<String, String>>>()\n // Option -> Resultの変換関数として `ok_or`, `ok_or_else` が用意されている\n .ok_or_else(|| \"error occurred\".into())\n // Err handling?\n }\n fn main() {\n // Ok.\n let kv1 = \"key1=value1,key2=value2,key3=value3\";\n match to_hash(kv1) {\n Ok(n) => println!(\"{:?}\", n),\n Err(e) => println!(\"{:?}\", e),\n }\n \n // Err.\n let kv2 = \"key1=value1,key2=value2,key3=value3,\";\n match to_hash(kv2) {\n Ok(n) => println!(\"{:?}\", n),\n Err(e) => println!(\"{:?}\", e),\n }\n }\n \n \n```\n\nブラウザで試すには以下 \n[https://play.rust-\nlang.org/?version=stable&mode=debug&edition=2018&gist=65b15377022eec393433a17ba896a720](https://play.rust-\nlang.org/?version=stable&mode=debug&edition=2018&gist=65b15377022eec393433a17ba896a720)\n\nコメントにも書いていますが\n\n * unwrapを使わない\n * OptionやResultは出来る限り伝播させる\n\nをするとエラーハンドリングできるようになります。\n\n大分旧くなってしまいましたが旧版の公式ドキュメントでこのあたりが丁寧に解説されています。 \n<https://doc.rust-jp.rs/the-rust-programming-language-ja/1.6/book/error-\nhandling.html> \n今は `try!` マクロは非推奨で [`?` が導入されました](https://rust-lang-nursery.github.io/edition-\nguide/rust-2018/error-handling-and-panics/the-question-mark-operator-for-\neasier-error-handling.html)がそれ以外は今でも使えるようです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T09:43:44.253", "id": "53068", "last_activity_date": "2019-02-27T09:43:44.253", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22816", "parent_id": "53066", "post_type": "answer", "score": 6 } ]
53066
53068
53068
{ "accepted_answer_id": null, "answer_count": 0, "body": "```\n\n import discord\n from discord.ext import commands\n import locale\n locale.setlocale(locale.LC_ALL, '')\n from datetime import datetime\n from discord.utils import find\n import traceback \n import requests\n import json\n import urllib.request\n import asyncio \n \n class MyBot(commands.Bot):\n def __init__(self, command_prefix):\n super().__init__(command_prefix)\n for cog in INITIAL_COGS:\n try:\n self.load_extension(cog)\n except Exception:\n traceback.print_exc()\n \n async def on_ready(self):\n while True:\n if #レポートに変更があったら:\n embed = discord.Embed(title=\"NHK緊急地震速報\", description='', color=0xff0000)\n embed.add_field(name=\"発生時間\", value=replay, inline=True)\n embed.add_field(name=\"深央\", value=sinnou, inline=True)\n embed.add_field(name=\"深さ\", value=hukasa, inline=True)\n embed.add_field(name=\"強さ(M)\", value=mg, inline=True)\n embed.add_field(name=\"最大震度\", value=\"震度\" + sindo, inline=True)\n embed.add_field(name=\"最大震度\" + sindo + \"を観測した地域\", value=location, inline=True)\n channel = self.get_channel(549218559792906268)\n await channel.send(embed=embed)\n eqreport = urllib.request.urlopen('http://www3.nhk.or.jp/sokuho/jishin/data/JishinReport.xml').read()\n await asyncio.sleep(5)\n \n```\n\nこのように一定時間に一回のコードの入手のやり方は分かるのですが、それをどのように保存すればいいのかとそのレポートとサイトを比べて変化があった場合を調べる方法が分かりません。\n\nご教授お願い致します。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T14:05:32.320", "favorite_count": 0, "id": "53071", "last_activity_date": "2019-02-27T14:18:34.600", "last_edit_date": "2019-02-27T14:18:34.600", "last_editor_user_id": "19110", "owner_user_id": "32332", "post_type": "question", "score": 0, "tags": [ "python", "python3", "discord" ], "title": "discord.pyによるデータの保存", "view_count": 340 }
[]
53071
null
null
{ "accepted_answer_id": "53080", "answer_count": 1, "body": "説明がしにくいため先に例を記載します。\n\ntable_a\n\n```\n\n id\n a\n b\n c\n d\n \n```\n\ntable_b\n\n```\n\n a_id c1 c2\n a x 1\n a y 2\n b x 1\n b y 2\n c x 1\n c y 2\n c z 3\n d x 1\n d y 3\n \n```\n\n欲しい結果\n\n```\n\n id count\n a 2\n b 2\n c 1\n d 1\n \n```\n\ntable_b内でa_id毎にc1とc2がありますが、これらが完全に一致するレコードをカウントしたいです。(idがaの場合、table_bには2レコードあるので、その2レコードのc1がxでc2が1,\nc1がyでc2が2の2つのレコードが完全に一致するidをカウントしたい。) \n(例だと自分も含んでa(自分)とbが一致するので2としていますが、含まなくても良いです)\n\n※データベースはredshiftですので、DB依存がない一般的なSQLで実現できると助かります。 \n※実際にはtable_aにはかなりの数のレコードが含まれます。 \n※table_bで、a_idに紐づくレコードも最大100以上存在します。 \n※table_bのa_idとc1ではユニークになりません。(a_id, c1, c2でユニークになります) \n※table_aにあり、table_bのa_idに含まれない場合にはcountは含まれる必要はありません。(含まれても良いです。)\n\nどのような情報でも助かりますのでお願い致します。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T14:24:10.627", "favorite_count": 0, "id": "53072", "last_activity_date": "2019-02-28T02:05:47.563", "last_edit_date": "2019-02-28T01:11:11.137", "last_editor_user_id": "13022", "owner_user_id": "13022", "post_type": "question", "score": 1, "tags": [ "sql" ], "title": "テーブルに紐づく属性が一致する数を数えたい", "view_count": 130 }
[ { "body": "`id`ごとのレコード数をまず計算しておき、2つの`id`間で`c1`,`c2`が同じレコード数を両者のレコード数と比較してはどうでしょうか。\n\n```\n\n WITH n AS (SELECT a_id,count(*) FROM table_b GROUP BY a_id)\n SELECT id1 id, count(id2)\n FROM (SELECT b1.a_id id1, b2.a_id id2\n FROM table_b b1\n JOIN table_b b2\n ON b1.c1=b2.c1 AND b1.c2=b2.c2\n JOIN n n1\n ON b1.a_id=n1.a_id\n JOIN n n2\n ON b2.a_id=n2.a_id\n WHERE n1.count=n2.count\n GROUP BY id1, id2, n1.count\n HAVING n1.count=count(*)) t\n GROUP BY id1;\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T02:05:47.563", "id": "53080", "last_activity_date": "2019-02-28T02:05:47.563", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9464", "parent_id": "53072", "post_type": "answer", "score": 1 } ]
53072
53080
53080
{ "accepted_answer_id": "53076", "answer_count": 1, "body": "**下記サイトに掲載されている内容を試すと期待した通り動作するのですが、なぜですか?** \n[【Twitter】埋め込み処理をAPIに投げずにローカルで行う](http://mizuff.hatenablog.com/entry/twitter-\noembed)\n\n本来であれば、下記コードを掲載する必要があると思うのですが、リンク先コードだけで正常動作する理由が分かりません。\n\n```\n\n <blockquote class=\"twitter-tweet\" data-lang=\"ja\"><p lang=\"ja\" dir=\"ltr\">『見つめて… ! もっと強く、強くです ! ムムムーン ! …曲がりませんね』<br><br>SSレアの堀裕子ちゃん登場です!<a href=\"https://t.co/mIoEjCBQs4\">https://t.co/mIoEjCBQs4</a> <a href=\"https://twitter.com/hashtag/%E3%83%87%E3%83%AC%E3%82%B9%E3%83%86?src=hash&amp;ref_src=twsrc%5Etfw\">#デレステ</a> <a href=\"https://t.co/Ffflbfgs4b\">pic.twitter.com/Ffflbfgs4b</a></p>&mdash; スターライトステージ (@imascg_stage) <a href=\"https://twitter.com/imascg_stage/status/774134264107372548?ref_src=twsrc%5Etfw\">2016年9月9日</a></blockquote>\n <script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n \n```\n\n* * *\n\n> ツイートのURL(細かく言えばscreen_nameとid)さえあればwidgets.jsがうまく処理してくれます\n\nそれなら、公式サイトでもそれだけ掲載しておけば良いと思うのですが¨\n\n* * *\n\n**追記**\n\n・リンク先ページに掲載されていた下記「埋め込み自作コード」を試しても同じ結果が表示されました \n・短く書けるなら短く書けたほうが良いと思うのですが、Twitterはなぜ上記のように長いコードを埋め込みコードとして提示するのか疑問に思い質問しました\n\n```\n\n <blockquote class=\"twitter-tweet\"><a href=\"https://twitter.com/imascg_stage/status/774134264107372548\"></a></blockquote>\n <script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T14:41:53.337", "favorite_count": 0, "id": "53073", "last_activity_date": "2019-02-28T17:32:06.220", "last_edit_date": "2019-02-28T17:32:06.220", "last_editor_user_id": "3060", "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "twitter" ], "title": "ツイートの埋め込み用コードを自作する、について", "view_count": 488 }
[ { "body": "> それなら、公式サイトでもそれだけ掲載しておけば良いと思うのですが\n\n[Embedded Tweets](https://developer.twitter.com/en/docs/twitter-for-\nwebsites/embedded-tweets/guides/embedded-tweet-parameter-\nreference)で埋め込み方や、widgets.jsの提供するJavaScript関数、`blockquote`に指定できるパラメーターなどすべて説明されています。\n\n埋め込み方の質問ではないと判断したためリンク紹介にとどめます。\n\n* * *\n\n> 短く書けるなら短く書けたほうが良いと思うのですが、Twitterはなぜ上記のように長いコードを埋め込みコードとして提示するのか\n\nその疑問はリンク先のFAQに既に答えられています。\n\n> ## What happens when an author deletes their Tweet?\n>\n> The Twitter widgets JavaScript will not display a fully-rendered Tweet if\n> the Tweet no longer exists on Twitter. The fallback `<blockquote>`\n> containing Tweet information will be visible on the page.\n\nTweetが削除されていれば表示しようがないため、埋め込んだ時点で得られていたテキストを表示する方がよいでしょう。付け加えると、SEO的にもTweetテキストに関連があるページとして検索エンジンに認識されます。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T00:57:39.000", "id": "53076", "last_activity_date": "2019-02-28T14:57:32.753", "last_edit_date": "2019-02-28T14:57:32.753", "last_editor_user_id": "4236", "owner_user_id": "4236", "parent_id": "53073", "post_type": "answer", "score": 2 } ]
53073
53076
53076
{ "accepted_answer_id": null, "answer_count": 0, "body": "下記のサイトを参考にして、ローカルにある音楽ファイルを再生することができました。\n\n<https://i-app-tec.com/ios/avaudioplayer.html>\n\n次に、web上にある音楽ファイルを、 \nURL(例えば、<https://example.com/data/sample.mp3> のようなもの)を指定して、再生しようとしています。\n\n単に\n\n```\n\n let audioUrl = URL(fileURLWithPath: \"https://example.com/data/sample.mp3\")\n \n```\n\nのように変更しても、うまく動きませんでした。\n\nどうすれば、再生できるのでしょうか?\n\n環境は下記のとおりです。\n\n```\n\n swift:4.2\n xcode:10.1\n \n```\n\nよろしくお願い致します。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-27T17:28:32.157", "favorite_count": 0, "id": "53075", "last_activity_date": "2019-02-27T17:28:32.157", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26865", "post_type": "question", "score": 0, "tags": [ "ios", "iphone", "swift4" ], "title": "swift4.2でURLを指定してweb上にある音楽ファイルを再生したい。", "view_count": 163 }
[]
53075
null
null
{ "accepted_answer_id": "53078", "answer_count": 2, "body": "`kill -0` という手段を初めて知ったので、`kill -0` の用途を質問させてください。\n\n[kill](http://linuxjm.osdn.jp/html/LDP_man-pages/man2/kill.2.html) の man\nには以下のように書かれています。\n\n> sig に 0 を指定した場合、シグナルは送られないが、 エラーのチェックは行われる。これを使って、プロセス ID や プロセスグループ ID\n> の存在確認を行うことができる。\n\nプロセスを制御する手段として、おなじみなのは、PID をファイルに保存しておき、プロセスを終了させたいときは PID ファイルの中身の PID を指定して\nkill するというものです。\n\nたとえばプロセス foobar を以下のように起動させて\n\n```\n\n foobar &\n echo $! > foobar.pid\n \n```\n\n終了させるとき\n\n```\n\n kill -9 $(cat foobar.pid)\n \n```\n\nここではシグナル 9 を送信( `kill -9` )していますが、冒頭に引用したように、シグナル 0 を送信( `kill -0`\n)することもできるようです。\n\n`kill -0` の用途としては、以下のような理解であっているでしょうか?\n\nプロセス foobar の状態と foobar.pid ファイルの存在有無は関係が無い。つまり、foobar.pid\nファイルが存在していたとしても、それがプロセス foobar が走っているという保証にはならない。ゆえに、プロセス foobar の状態を確認するために\nkill -0 を用いる。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T01:12:42.310", "favorite_count": 0, "id": "53077", "last_activity_date": "2019-02-28T02:01:13.160", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9592", "post_type": "question", "score": 10, "tags": [ "linux" ], "title": "kill -0 <PID> は何をするのでしょうか?", "view_count": 5480 }
[ { "body": "おおむね、その理解でよろしいかと存じますが、少し指摘をさせていただきます。\n\nまず、プロセスIDは使い回される場合があり、通常はインクリメントで増えていきますが、 `/proc/sys/kernel/pid_max`\nで定義される最大値を超えるとこれまでに使ったプロセスIDを利用した別のプロセスが実行される場合が有り、pidファイルに記載されたプロセスが走っている保証にはなりません。\n\nまた、sig 0についてですが、kill from util-linux 2.33.1 の`man 2 kill`\nによると、以下のとおりになり、記載された内容とは異なります。\n\n> If sig is 0, then no signal is sent, but existence and permission checks are\n> still performed; this can be used to check for the existence of a process ID\n> or process group ID that the caller is permitted to signal.\n>\n> sig に 0 を指定した場合、シグナルは送られないが、 プロセスの存在と権限のチェックは行われる。これを使って、送信者がシグナルを送信できるプロセス\n> ID や プロセスグループ ID の存在確認を行うことができる。\n\nという訳で、`kill` の権限があるかどうかの確認に使うことも可能そうです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T01:57:22.757", "id": "53078", "last_activity_date": "2019-02-28T01:57:22.757", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "29826", "parent_id": "53077", "post_type": "answer", "score": 7 }, { "body": "該当オプションはこの質問で私も初めて知りましたが、おおむね想定されている内容で合っているのではないでしょうか。\n\n`/var/run/***.pid`ファイルを使用する場合でも、何らかの理由でプロセスが終了しているのにPIDファイルが残り続けてしまう場合がごく稀にあります。\n\n`kill -0 <PID>`の方法であれば、上記のPIDファイルの有無によらず実際のプロセスの生存確認ができる、ということなのかなと思いました。 \n`kill -0\n<PID>`実行後に終了ステータス`$?`の値をチェックすることで生存確認ができるので、PIDを狙い撃ちでチェックしたいなら、よく使う`ps +\ngrep`や`pgrep`よりもシェルスクリプトなどの記述がすっきりするのかもしれません。\n\n参考: \n[What does `kill -0` do? - Unix & Linux Stack\nExchange](https://unix.stackexchange.com/q/169898/298771)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T02:01:13.160", "id": "53079", "last_activity_date": "2019-02-28T02:01:13.160", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "53077", "post_type": "answer", "score": 5 } ]
53077
53078
53078
{ "accepted_answer_id": "53082", "answer_count": 1, "body": "[![独学プログラマーという本の1ページです。](https://i.stack.imgur.com/4VSfI.jpg)](https://i.stack.imgur.com/4VSfI.jpg)\n\nstagesのリストの中のハングマンの書き方がわかりません。具体的には | と 0 が縦に揃わないことや右端の \", が縦に揃わない\nこれらの操作は手動でやるものですか? \nほんとに初歩的な質問ですみません。スラッシュもわからないです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T03:05:36.223", "favorite_count": 0, "id": "53081", "last_activity_date": "2019-02-28T03:20:47.767", "last_edit_date": "2019-02-28T03:09:36.467", "last_editor_user_id": "19110", "owner_user_id": "32343", "post_type": "question", "score": 4, "tags": [ "python", "python3", "python-idle" ], "title": "記号の入力の仕方がわかりません。", "view_count": 302 }
[ { "body": "```\n\n \"______ \",\n \"| \",\n \"| | \",\n \"| O \",\n \"| /|\\ \",\n \"| / \\ \",\n \"| \"\n \n```\n\n空白の個数は適当ですがおおよそこんな感じです。ポイントは\n\n * 環境によって、バックスラッシュは円記号として[表示される](https://ja.wikipedia.org/wiki/%E5%86%86%E8%A8%98%E5%8F%B7#Unicode%E3%81%8C%E6%8C%81%E3%81%A4%E5%95%8F%E9%A1%8C%EF%BC%88%E5%86%86%E8%A8%98%E5%8F%B7%E5%95%8F%E9%A1%8C%EF%BC%89)。打つ際も、キーボードに円記号が書かれているキーを打つことでしか直接入力できない場合がある。\n * 空白は全角スペースではなく半角スペースを用いるべき。幅を揃えやすくするため。\n * 顔の部分はゼロより大文字のオーの方が良さそう。ゼロの場合、丸に斜線を入れるフォントがあるので。\n * エディタやターミナルでずれて表示される場合は、[等幅フォント](https://ja.wikipedia.org/wiki/%E7%AD%89%E5%B9%85%E3%83%95%E3%82%A9%E3%83%B3%E3%83%88)を使うと良い。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T03:20:47.767", "id": "53082", "last_activity_date": "2019-02-28T03:20:47.767", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "53081", "post_type": "answer", "score": 2 } ]
53081
53082
53082
{ "accepted_answer_id": "53084", "answer_count": 1, "body": "```\n\n package chapter04;\n \n public class IncDec {\n \n public static void main(String[] args) {\n int a = 10, b = 10, c = 0, d = 0;\n \n System.out.println(\"a:\" + a + \" b:\" + b + \" c:\" + c + \" d:\" + d);\n \n c = a--;\n d = ++b;\n System.out.println(\"\\nc = a--; d = ++b;\");\n System.out.println(\"a:\" + a + \" b:\" + b + \" c:\" + c + \" d:\" + d);\n \n c = --a;\n d = b++;\n System.out.println(\"\\nc = --a; d = b++;\");\n System.out.println(\"a:\" + a + \" b:\" + b + \" c:\" + c + \" d:\" + d);\n \n d = ++a - b--;\n System.out.println(\"\\nd = ++a - b--;\");\n System.out.println(\"a:\" + a + \" b:\" + b + \" c:\" + c + \" d:\" + d);\n \n a--;\n ++b;\n System.out.println(\"\\na--; ++b;\");\n System.out.println(\"a:\" + a + \" b:\" + b + \" c:\" + c + \" d:\" + d);\n }\n \n }\n \n```\n\n<出力>\n\n```\n\n a:10 b:10 c:0 d:0\n \n c = a--; d = ++b;\n a:9 b:11 c:10 d:11\n \n c = --a; d = b++;\n a:8 b:12 c:8 d:11\n \n d = ++a - b--;\n a:9 b:11 c:8 d:-3\n \n a--; ++b;\n a:8 b:12 c:8 d:-3\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T03:45:25.597", "favorite_count": 0, "id": "53083", "last_activity_date": "2019-02-28T05:41:21.947", "last_edit_date": "2019-02-28T03:47:09.623", "last_editor_user_id": "29826", "owner_user_id": "32344", "post_type": "question", "score": 0, "tags": [ "java" ], "title": "どうして、この出力になるのか教えてください。", "view_count": 157 }
[ { "body": "出力の各行について説明します。\n\n```\n\n a:10 b:10 c:0 d:0\n \n```\n\n初期状態です。\n\n```\n\n c = a--; d = ++b;\n a:9 b:11 c:10 d:11\n \n```\n\ncにaの後置デクリメント、dにbの前置インクリメントを代入しています。後置では代入してから評価、前置では評価してから代入が行われるため、\n`cにaを代入して(c=10)からaをデクリメント(a=9)`、`bをインクリメントして(b=11)からdに代入`しています。\n\n```\n\n c = --a; d = b++;\n a:8 b:12 c:8 d:11\n \n```\n\n同様に、cにaの前置デクリメント、dにbの後置インクリメントを代入しています。\n\n```\n\n d = ++a - b--;\n a:9 b:11 c:8 d:-3\n \n```\n\nこれはパターンが変わり、dに(aの前置インクリメントからbの後置デクリメントを引いたもの)を代入しています。評価の順番は「aがインクリメントされ(aが9になる)、dにa-\nbが代入され(dが9-12=-3になる)、bがデクリメントされる(bが11になる)」という流れになります。\n\n```\n\n a--; ++b;\n a:8 b:12 c:8 d:-3\n \n```\n\naが後置デクリメント、bが前置インクリメントされます。代入はありませんが、aが8、bが12になっています。\n\n前置と後置についてはこの記事が参考になるかと存じます。 \n[前置と後置 - 演算子 - Java入門](https://www.javadrive.jp/start/ope/index7.html)", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T03:54:24.260", "id": "53084", "last_activity_date": "2019-02-28T05:41:21.947", "last_edit_date": "2019-02-28T05:41:21.947", "last_editor_user_id": "29826", "owner_user_id": "29826", "parent_id": "53083", "post_type": "answer", "score": 2 } ]
53083
53084
53084
{ "accepted_answer_id": "53090", "answer_count": 1, "body": "Eclipse による Java 開発から、Ruby に移ってきました。 \n呼び出し階層(Call Hierarchy)を表示する機能を持ったIDEはありますか?\n\n【追記】 \nEcliipse のように多階層が一括目視できるのが理想ですが、 \n呼び出し元、呼び出し先へのジャンプというものでも、情報をいただけますと幸いです。\n\nローカル、クラウド(SaaSなど)は問いません。\n\nGem を使っていると、Rails 本体の機能なのかプラグインの機能なのか、 \n要求を満たせそうなメソッドや機能はあるか、という調査に非常に時間がかかり、 \n困っている状況です。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T04:00:03.920", "favorite_count": 0, "id": "53085", "last_activity_date": "2019-02-28T06:30:44.143", "last_edit_date": "2019-02-28T05:14:28.917", "last_editor_user_id": "32345", "owner_user_id": "32345", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "ruby" ], "title": "Ruby (およびRails) のIDEで、呼び出し階層の表示機能があるものは存在しますか?", "view_count": 396 }
[ { "body": "要望にぴったりのものは無さそうですが、IDEとしては以下2つでしょうか。\n\n * RubyMine \nただし呼び出し階層(Call Hierarchy)ではなくクラス階層(Class Hierarchy)を表示するものです。 \n[Building Class Hierarchy](https://www.jetbrains.com/help/ruby/building-class-\nhierarchy.html)\n\n * Eclipse + Aptana Studio + RadRails \n使い方や画面は見つからなかったのですが、以下の記事があったので、おそらく出来るのでしょう。 \nAptana Studioはずっと更新が止まっているようなので、今も使えるのかは不明ですが。 \n[RadRailsのバージョンが1.0へ - Profiler,CallGraph Analyzer,Rails\nShellが追加](https://www.infoq.com/jp/news/2008/03/radrails-1-0-profiler-\nrailsshell?itm_source=presentations_about_RadRails&itm_medium=link&itm_campaign=RadRails) \n[Aptana RadRailsで始める JRuby on Rails超入門\n(2/3)](https://www.atmarkit.co.jp/ait/articles/0805/19/news116_2.html)\n\nIDEではなく、ユーティリティ的なツールとしては、こういうのが見つかりました。\n\n * [CodeQuery](https://ruben2020.github.io/codequery/) \\+ [eapache/starscope](https://github.com/eapache/starscope)\n\n> コード理解、コード閲覧、またはコード検索ツール。 これは、C、C\n> ++、Java、Python、Ruby、およびGoのソースコードを索引付けしてから検索または検索するためのツールです。\n> それはcscopeとctagsのデータベース上に構築され、そして素晴らしいGUIツールを提供します。 \n> ~途中省略~ \n> さらに、cscopeの代わりに、starscopeを使ってRuby、Go、およびJavascriptのサポートを追加します。\n\nそれからRubyのスクリプトで解析し・データを作って、他のツールで可視化する手法もあるようです。 \nこちらはそのスクリプト。\n\n * [callg.rb / コールグラフ作成スクリプト](http://www.namikilab.tuat.ac.jp/~sasada/prog/callg.html)\n * [eaceaser/ruby-call-graph](https://github.com/eaceaser/ruby-call-graph)\n * [mvidner/code-explorer](https://github.com/mvidner/code-explorer)\n * [ruby-prof/ruby-prof](https://github.com/ruby-prof/ruby-prof)\n\nこちらがビューワーです。\n\n * [KCachegrind](https://kcachegrind.github.io/html/Home.html)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T06:30:44.143", "id": "53090", "last_activity_date": "2019-02-28T06:30:44.143", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "53085", "post_type": "answer", "score": 0 } ]
53085
53090
53090
{ "accepted_answer_id": "53092", "answer_count": 1, "body": "お世話になります。\n\nPHPでsetlocaleを使わずに、ロケールの指定をしたいのですが、php.ini等でできるのでしょうか。 \nちなみに、.htaccessに\n\n```\n\n SetEnv LANG \"ja_JP.UTF-8\"\n \n```\n\nと記載してみましたが、反映されていないようです。 \n何か良い方法があれば、教えていただけると幸いです。\n\n以上、よろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T06:01:53.820", "favorite_count": 0, "id": "53088", "last_activity_date": "2019-02-28T07:37:10.027", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29034", "post_type": "question", "score": 0, "tags": [ "php" ], "title": "PHPのデフォルトのロケールを設定する方法", "view_count": 3295 }
[ { "body": "出来るようです。\n\n[PHP7.2をインストール後のphp.iniの設定](https://qiita.com/nao_tuboyaki/items/9615166e2374a565af80)\n\n> PHPをインストール後に最低限デフォルト値から変更する項目を書いておく \n> ※書いてある項目以外にもあるとは思います。 \n> 対象バージョン \n> PHP 7.2 \n> php.ini設定\n```\n\n> ; デフォルト文字コード\n> default_charset = UTF-8\n> ; mbstringのデフォルトの言語\n> mbstring.language = Japanese\n> ; HTTP入力文字のエンコーディングを内部文字のエンコーディングに自動変換なし\n> mbstring.encoding_translation = Off\n> ; 文字コードを自動検出する際の優先順位\n> mbstring.detect_order = UTF-8,SJIS,EUC-JP,JIS,ASCII\n> ; タイムゾーンを日本標準時間\n> date.timezone = Asia/Tokyo\n> ; HTTPのレスポンスによりPHPのバージョン情報を非表示\n> expose_php = Off\n> \n> ; 以下はPHP5.6以降で非推奨になっているのでコメントアウトしておく\n> ;mbstring.internal_encoding =\n> ;mbstring.http_input =\n> ;mbstring.http_output =\n> \n```\n\nちなみに、Apacheによる設定は、.htaccess ではなく、以下でやるようです。 \n[CentOSでApacheを日本語ロケール(ja_JP.utf8)で起動する](http://maeda.farend.ne.jp/blog/2010/01/05/apache-\nhttpd-lang/)\n\n> ApacheをRHEL/CentOSのパッケージで導入した場合(デフォルト) \n> ja_JP.utf8に設定するには、 /etc/sysconfig/httpd に以下の行を追加します。\n```\n\n HTTPD_LANG=ja_JP.utf8\n \n```\n\n> Apacheをソースコードからビルドしてインストールした場合 \n> /usr/local/apache2/bin/envvars に以下の行を追加します。このファイルは apachectl 実行時に読み込まれます。\n```\n\n LANG=ja_JP.utf8\n export LANG\n \n```\n\n類似の注意 \n[PHP動作環境で先頭の漢字のみ文字化けするケースがある](http://www.cross-\nring.net/web/DPOW/linux_server_setting/apache/616)\n\n> ちなみに、httpd.confに「SetEnv LANG ~」と書くことによる変更はできないようです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T07:37:10.027", "id": "53092", "last_activity_date": "2019-02-28T07:37:10.027", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "53088", "post_type": "answer", "score": 0 } ]
53088
53092
53092
{ "accepted_answer_id": null, "answer_count": 1, "body": "Pythonの勉強を始めた初心者です。Pythonのfor文ではinの後ろにはiterableオブジェクトを書けとの説明があります。しかしiterableではないset型がinの後ろに書けてしまいます。またfrozensetを生成するfrozen関数も引数はiterableとなっているのにset型でも生成できてしまいます。どのように考えたらよいのでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T06:23:33.840", "favorite_count": 0, "id": "53089", "last_activity_date": "2019-02-28T06:46:53.427", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22781", "post_type": "question", "score": 8, "tags": [ "python" ], "title": "Pythonのiterable", "view_count": 555 }
[ { "body": "`set`型、及び`frozenset`型は`iterable`です。以下のコードでTrueを表示するようなオブジェクトは`iterable`であるといえます。\n\n```\n\n s = set()\n try:\n iterator = iter(s)\n print(True)\n except TypeError as e:\n print(False)\n \n```\n\n`iterable` について [用語集 — Python 3.7.2\nドキュメント](https://docs.python.org/ja/3/glossary.html#term-iterable) \n`iter`について [組み込み関数 — Python 3.7.2\nドキュメント](https://docs.python.org/ja/3/library/functions.html#iter)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T06:40:20.710", "id": "53091", "last_activity_date": "2019-02-28T06:46:53.427", "last_edit_date": "2019-02-28T06:46:53.427", "last_editor_user_id": "29826", "owner_user_id": "29826", "parent_id": "53089", "post_type": "answer", "score": 7 } ]
53089
null
53091
{ "accepted_answer_id": "53097", "answer_count": 1, "body": "Rustの無限ループで安全にloop処理から抜ける方法は \nどの様に書けば良いですか。\n\n```\n\n use std::{thread, time};\n \n pub struct Worker { }\n \n trait WorkerTrait {\n fn run(&self);\n fn stop(&self);\n }\n \n impl Worker {\n fn run(&self) {\n thread::spawn(move || loop {\n println!(\"worker1 working \");\n thread::sleep(time::Duration::from_millis(1000)); // 擬似処理.\n // thread break?\n });\n }\n fn stop(&self) {\n // to break thread.\n }\n }\n fn main() {\n let w = Worker {};\n \n w.run();\n \n thread::sleep(time::Duration::from_secs(10));\n \n // stop thread.\n w.stop();\n }\n \n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T07:59:47.457", "favorite_count": 0, "id": "53094", "last_activity_date": "2019-02-28T09:30:55.247", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32285", "post_type": "question", "score": 3, "tags": [ "rust" ], "title": "Rustで安全にthread loopを止める方法", "view_count": 1327 }
[ { "body": "こんにちは。κeenです。 \nRustでスレッドに終了メッセージを送るにはいくつか方法があります。\n\n1つ目は `AtomicBool` を使って終了フラグを共有する方法。コードだと以下のようになります。\n\n```\n\n use std::sync::atomic::{AtomicBool, Ordering};\n use std::sync::Arc;\n use std::{thread, time};\n \n pub struct Worker {\n to_stop: Arc<AtomicBool>,\n }\n \n trait WorkerTrait {\n fn run(&self);\n fn stop(&self);\n }\n \n impl Worker {\n fn new() -> Self {\n Worker {\n to_stop: Arc::new(AtomicBool::new(false)),\n }\n }\n }\n \n impl WorkerTrait for Worker {\n fn run(&self) {\n let to_stop = Arc::clone(&self.to_stop);\n thread::spawn(move || loop {\n if to_stop.load(Ordering::Relaxed) {\n break;\n }\n println!(\"worker1 working \");\n thread::sleep(time::Duration::from_millis(1000)); // 擬似処理.\n // thread break?\n });\n }\n fn stop(&self) {\n self.to_stop.store(true, Ordering::Relaxed)\n }\n }\n fn main() {\n let w = Worker::new();\n \n w.run();\n \n thread::sleep(time::Duration::from_secs(10));\n \n // stop thread.\n w.stop();\n }\n \n```\n\nもう1つはチャネルを使ってメッセージを送る方法。 \nコード例は以下です。少し真面目に書いてみましたので長くなっています。\n\n```\n\n use std::any::Any;\n use std::sync::mpsc::{channel, SendError, Sender, TryRecvError};\n use std::thread::JoinHandle;\n use std::{thread, time};\n \n pub struct Worker {\n //スレッドに終了メッセージを送信するチャネル\n control: Option<Sender<Message>>,\n // threadのハンドル\n handle: Option<JoinHandle<()>>,\n }\n \n #[derive(Debug)]\n enum WorkerError {\n Channel(SendError<Message>),\n Thread(Box<dyn Any + Send + 'static>),\n ThreadNotStarted,\n }\n \n trait WorkerTrait {\n type Error;\n fn run(&mut self);\n fn stop(&mut self) -> Result<(), Self::Error>;\n }\n \n // スレッドに対するメッセージ。他に必要なら増やす。\n enum Message {\n Stop,\n }\n \n impl Worker {\n fn new() -> Self {\n Self {\n control: None,\n handle: None,\n }\n }\n }\n impl WorkerTrait for Worker {\n type Error = WorkerError;\n \n fn run(&mut self) {\n let (tx, rx) = channel();\n let handle = thread::spawn(move || loop {\n match rx.try_recv() {\n // メッセージが来るか、チャネルが閉じられたら(=Workerが破棄されたら)スレッドを止める\n Ok(Message::Stop) | Err(TryRecvError::Disconnected) => break,\n Err(TryRecvError::Empty) => {\n println!(\"worker1 working \");\n thread::sleep(time::Duration::from_millis(1000)); // 擬似処理.\n // thread break?\n }\n }\n });\n self.control = Some(tx);\n self.handle = Some(handle);\n }\n fn stop(&mut self) -> Result<(), Self::Error> {\n if let (Some(control), Some(handle)) = (self.control.take(), self.handle.take()) {\n // スレッドに終了メッセージを送り、\n control.send(Message::Stop).map_err(WorkerError::Channel)?;\n // 終了を待ち合わせる\n handle.join().map_err(WorkerError::Thread)?;\n Ok(())\n } else {\n Err(WorkerError::ThreadNotStarted)\n }\n }\n }\n fn main() {\n let mut w = Worker::new();\n \n w.run();\n \n thread::sleep(time::Duration::from_secs(10));\n \n // stop thread.\n w.stop().expect(\"stopping thread failed\");\n }\n \n \n```\n\nAtomicBoolを送る方法は簡単なのが特徴です。しかし1種類のメッセージ1度だけしか送れません。 \nチャネルを使う方は様々なメッセージを送れるので終了以外にもコミュニケーションを行いたい場合に有用です。しかしご覧の通りセットアップが多少手間です。 \n用途に合わせてお使い下さい。 \n因みにチャネルの方を本気で使いたいならcrossbeam_channelのようなクレイトもあるので併せて検討下さい。 \n<https://docs.rs/crossbeam-channel/0.3.8/crossbeam_channel/>\n\n因みに出来る限り元のコードに合わせてサンプルコードを書きましたが、`WorkerTrait` は以下のようなシグネチャの方が使いやすいと思います。\n\n```\n\n trait WorkerTrait {\n fn run() -> Self;\n fn stop(self);\n }\n \n```\n\nスレッドが走っていない状態のワーカがあると管理が面倒なので `run` でコンストラクタを兼ね、やはり終了したあとのワーカが残ると管理が面倒なので\n`stop` で `self` を消費してしまった方が良いと思います。もちろん、ワーカを使いまわしたいなどの要件があるならその限りではありませんが。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T09:30:55.247", "id": "53097", "last_activity_date": "2019-02-28T09:30:55.247", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22816", "parent_id": "53094", "post_type": "answer", "score": 4 } ]
53094
53097
53097
{ "accepted_answer_id": null, "answer_count": 0, "body": "FirebaseのCloud\nFunctionsで、Puppeteerを使用して絵文字入りのスクリーンショットを撮ろうとしているのですが、絵文字が文字化けしてしまいます。\n\nCloudFunctionsのPuppeteerが絵文字フォントを読み込んでいないのが原因のようなので、@font-\nfaceで絵文字フォントを指定しようとしているのですが、うまくいきません。\n\nCloud Functionsのコードは以下の通りです。 \n(以下のscreenshot()関数をCloudFunctionsのHTTPS関数内から呼び出しています。)\n\n```\n\n import * as functions from 'firebase-functions';\n import * as admin from 'firebase-admin';\n admin.initializeApp();\n const storage = admin.storage();\n const puppeteer = require('puppeteer');\n \n function screenshot() {\n (async () => {\n const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] });\n const page = await browser.newPage();\n await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36');\n await page.evaluate(() => {\n const style = document.createElement('style')\n style.textContent = `\n @font-face {\n font-family: \"emoji\";\n src:local(\"Noto Color Emoji\"),\n url(\"./NotoColorEmoji.ttf\");\n };\n @font-face {\n font-family: 'Noto Sans JP';\n font-style: normal;\n font-weight: 400;\n src: local(\"Noto Sans CJK JP\"),\n url(//fonts.gstatic.com/ea/notosansjp/v5/NotoSansJP-Regular.woff2) format('woff2'),\n url(//fonts.gstatic.com/ea/notosansjp/v5/NotoSansJP-Regular.woff) format('woff'),\n url(//fonts.gstatic.com/ea/notosansjp/v5/NotoSansJP-Regular.otf) format('opentype');\n };\n body, svg{ font-family: \"Noto Sans JP\", \"emoji\", sans-serif; };`\n document.head.appendChild(style);\n document.body.style.fontFamily = \"'Noto Sans JP', 'emoji' , sans-serif\";\n })\n await page.waitFor(5000); // waiting time to load font\n await page.goto(\"https://getemoji.com/\"); //絵文字入りのサイトに移動\n await page.screenshot({\n path: '/tmp/screenshot.png',\n omitBackground: true,\n })\n .then(() => {\n // スクリーンショットをstorageにアップロード\n storage.bucket('bucketName').upload('/tmp/screenshot.png')\n .then(() => {\n console.log(\"success\");\n })\n .catch(error => {\n console.log(error);\n });\n })\n .catch(e => {\n console.log(e);\n });\n })();\n }\n \n```\n\n上記の結果のスクリーンショットは以下のようになります。 \n[![画像の説明をここに入力](https://i.stack.imgur.com/03Z2t.png)](https://i.stack.imgur.com/03Z2t.png) \n\n解決策のわかる方いましたらアドバイスいただけると幸いです。", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T11:50:20.967", "favorite_count": 0, "id": "53098", "last_activity_date": "2019-02-28T13:39:21.310", "last_edit_date": "2019-02-28T13:39:21.310", "last_editor_user_id": "32353", "owner_user_id": "32353", "post_type": "question", "score": 0, "tags": [ "javascript", "node.js", "firebase", "puppeteer" ], "title": "Firebase Cloud FunctionsでPuppeteerで絵文字のスクリーンショットが文字化けする", "view_count": 722 }
[]
53098
null
null
{ "accepted_answer_id": "53101", "answer_count": 2, "body": "**GET statuses/oembed\nへのリクエストURLとして、2通りあり、何れでアクセスしても期待した結果を取得できるのですが、両者の違いは何ですか?** \n・上の方が新しくて、下の方が古い? \n・この件に関して言及しているページはどこかにないですか?(いつまでサポートするとか、そう言った情報があれば知りたいのですが…)\n\n * `https://publish.twitter.com/oembed` についての[Twitter公式ドキュメント](https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-oembed.html)\n * `https://api.twitter.com/1/statuses/oembed.json` についての[非公式翻訳ドキュメント](http://westplain.sakuraweb.com/translate/twitter/Documentation/REST-APIs/Public-API/GET-statuses-oembed.cgi)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T12:33:59.473", "favorite_count": 0, "id": "53099", "last_activity_date": "2019-02-28T16:20:01.563", "last_edit_date": "2019-02-28T16:20:01.563", "last_editor_user_id": "3060", "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "twitter" ], "title": "https://publish.twitter.com/oembed と https://api.twitter.com/1/statuses/oembed.json について", "view_count": 202 }
[ { "body": "[公式ドキュメント](https://developer.twitter.com/en/docs/tweets/post-and-engage/api-\nreference/get-statuses-oembed.html)には <https://publish.twitter.com/oembed>\nが記載されていますし、<https://api.twitter.com/1/statuses/oembed.json>\nを使った場合エラーになる質問も英語版Stackoverflowで見つかりました。 \n(回答に対して返答がないため、URLが原因だったとははっきり言えないのですが…。)\n\n<https://stackoverflow.com/questions/28634341/statuses-oembed-of-twitter-rest-\napi-v1-1-returns-errors-message-sorry-t>\n\n<https://api.twitter.com/1/statuses/oembed.json> を使わねばならない理由がないのであれば\n<https://publish.twitter.com/oembed> を使うべきでしょう。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T12:51:45.007", "id": "53100", "last_activity_date": "2019-02-28T12:51:45.007", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "parent_id": "53099", "post_type": "answer", "score": 2 }, { "body": "<https://api.twitter.com/1/statuses/oembed.json> はTwitter REST API\nv1であり、[2013/6/11に廃止](https://blog.twitter.com/developer/en_us/a/2013/api-v1-retirement-\nfinal-\ndates.html)されています。[web.archive.orgに残るドキュメントページ](http://web.archive.org/web/20130910195245/https://dev.twitter.com/docs/api/1/get/statuses/oembed)も。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-28T13:49:26.283", "id": "53101", "last_activity_date": "2019-02-28T13:49:26.283", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "53099", "post_type": "answer", "score": 3 } ]
53099
53101
53101
{ "accepted_answer_id": null, "answer_count": 0, "body": "原因を特定できず、このカテゴリで質問させていただきます。 \nRaspberry pi-Debian-apache2-PHP5の環境でサイトを作成しました。 \nWindows PCのブラウザからは問題なく動作できたのですが、 \nlinux のX WindowのブラウザからだとJavaScriptが全く動作しません。 \nalertを出すだけのサンプルでテストしても動きませんでした。 \nX Windowで自作ローカルサイトをアクセス JS動かず \n別のRasPiからX Windowで自作サイトをリモートアクセス JS動かず \nでした。yahoo等の他サイトは問題なく動きます。 \n何か設定に漏れがあるのでしょうか。ご教授お願い致します。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T01:10:33.027", "favorite_count": 0, "id": "53102", "last_activity_date": "2019-03-01T01:35:51.417", "last_edit_date": "2019-03-01T01:35:51.417", "last_editor_user_id": "32358", "owner_user_id": "32358", "post_type": "question", "score": 0, "tags": [ "javascript", "php", "apache", "raspberry-pi" ], "title": "X windowで自作サイトのJavascriptが実行できません", "view_count": 87 }
[]
53102
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "SQL初心者です。 \n初歩的な質問となり恐縮ですが、ご教示頂けると幸いです。\n\nnumber90以下の人たちだけを、月別で集計したいのですが、 \nその構文をご教示いただけないでしょうか。\n\n[![画像の例ですと、20180823は3、20180930は2、とゆうような情報が欲しいです。](https://i.stack.imgur.com/1dE0y.png)](https://i.stack.imgur.com/1dE0y.png)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T01:35:03.193", "favorite_count": 0, "id": "53103", "last_activity_date": "2019-03-01T02:34:18.770", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32359", "post_type": "question", "score": 1, "tags": [ "sql" ], "title": "SQLで特定の番号以下の人たちだけを、月別で集計したい", "view_count": 74 }
[ { "body": "```\n\n create table mytable (\n datetimesend date,\n id char(1),\n number integer\n );\n \n insert into mytable (datetimesend ,id, number ) values \n ('2018-08-23','a',34),\n ('2018-08-23','b',23),\n ('2018-08-23','c',95),\n ('2018-08-23','d',78),\n ('2018-09-30','e',50),\n ('2018-09-30','f',6),\n ('2018-09-30','g',99)\n ;\n \n```\n\n単純に、`where`句で指定すれば良いと思いますが、どうでしょうか。\n\n```\n\n select sum(number) as sum, year(datetimesend) as year, month(datetimesend) as month\n from mytable where number <= 90 group by year,month;\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T02:34:18.770", "id": "53106", "last_activity_date": "2019-03-01T02:34:18.770", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2808", "parent_id": "53103", "post_type": "answer", "score": 2 } ]
53103
null
53106
{ "accepted_answer_id": "53105", "answer_count": 1, "body": "```\n\n class Orange:\n def _init_ (self,w,c):\n self.weight=w\n self.color=c\n print(\"Created!\")\n \n or1=Orange(10,\"dark\") \n \n```\n\n`TypeError: Orange() takes no argument` と出てしまいます。どこが違うのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T02:10:36.407", "favorite_count": 0, "id": "53104", "last_activity_date": "2019-03-01T10:59:51.340", "last_edit_date": "2019-03-01T10:59:51.340", "last_editor_user_id": "29826", "owner_user_id": "32343", "post_type": "question", "score": 0, "tags": [ "python", "python-idle" ], "title": "pythonのオブジェクト指向のエラー", "view_count": 174 }
[ { "body": "Pythonのコンストラクタは `_init_` ではなく `__init__` です。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T02:14:01.160", "id": "53105", "last_activity_date": "2019-03-01T02:14:01.160", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29826", "parent_id": "53104", "post_type": "answer", "score": 4 } ]
53104
53105
53105
{ "accepted_answer_id": "53109", "answer_count": 1, "body": "ReactJS中のJSXの中の { を表示させたいのですが、どのようにすればよいですか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T02:37:33.460", "favorite_count": 0, "id": "53107", "last_activity_date": "2019-03-01T14:32:37.213", "last_edit_date": "2019-03-01T14:32:37.213", "last_editor_user_id": "76", "owner_user_id": null, "post_type": "question", "score": 1, "tags": [ "react-jsx" ], "title": "JSXで { を表示させたい", "view_count": 54 }
[ { "body": "JavaScriptの文字列を使います。例えば以下のようにするとdiv要素の中に`{`と表示されます。\n\n```\n\n <div>{\"{\"}</div>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T02:59:14.687", "id": "53109", "last_activity_date": "2019-03-01T02:59:14.687", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30079", "parent_id": "53107", "post_type": "answer", "score": 1 } ]
53107
53109
53109
{ "accepted_answer_id": "53115", "answer_count": 1, "body": "PyInstallerでtest1.pyとtest2.pyをそれぞれ別の実行ファイルにしつつ、同じフォルダに配置したいのですが、何か方法はないでしょうか。\n\n試しに、PyInstallerの「--distpath」オプションで作成先のフォルダを変更してみましたが、やはりtest1とtest2のように別々のフォルダに保存されてしまうようです。\n\nちなみに、「--onefile」オプションで同じディレクトリに保存はできるのですが、起動速度などの観点から今回はこのオプションを使わずに実装したいと考えています。\n\n何か良い方法があれば、教えていただけると幸いです。 \n以上、よろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T02:55:28.310", "favorite_count": 0, "id": "53108", "last_activity_date": "2020-07-11T16:58:04.033", "last_edit_date": "2020-07-11T16:58:04.033", "last_editor_user_id": "3060", "owner_user_id": "29034", "post_type": "question", "score": 0, "tags": [ "python", "pyinstaller" ], "title": "PythonのPyInstallerでの複数ソースの実行ファイル作成", "view_count": 2113 }
[ { "body": "以下にちょうど同じ要望が出ていて、解決しています。 \nただし解決方法である `COLLECT` の詳細は、まだ文書化が不足しているようです。\n\nそういうわけで、対処方法は以下になると思われます。\n\n[Multipackage Bundles](https://pythonhosted.org/PyInstaller/spec-\nfiles.html#multipackage-bundles) の説明を元に、以下の作業を行う。\n\n * それぞれ作りたい `.exe` ファイル毎に `spec file` を作成する\n * 上記をまとめた1つの `spec file` を作成し、`Analysis(...)`, `PYZ(...)`, `EXE(...)` はそれぞれユニークな名前になるようにして、分離したまま追記していく\n * `COLLECT(...)` はすべてをまとめた1つだけを指定する\n * `MERGE(...)` と `--onefile` は使わない\n\n[Multiple executables in different directories\n#3663](https://github.com/pyinstaller/pyinstaller/issues/3663)\n\n> 私は複数の実行ファイルを構築しようとしています。 このスペックファイル[0]を持つmain.pyとmain2.pyがあります。 \n> PyInstallerを実行した後、私はdist\\main\\main.exeとdist\\main2\\main2.exeを得ます。 \n> PyInstallerがすべての実行ファイルを同じディレクトリに置くことは可能ですか? \n> [spec fileへのリンク](https://github.com/Siecje/qml-\n> testing/blob/8c3449b5a41c1d700ab2562afe7a5e5c54db2f8d/main.spec)\n>\n> あなたはMEREGEを使っていますが、これは壊れていて、誰かにそれを直すように求めています。 \n> 手助けをしたい場合は、未解決の問題を検索してください。 \n> これ以外に、PyInstallerは複数の実行ファイルを1つのディレクトリに入れることができます。 \n> もちろん、あなたは単一のCOLLECTを使わなければなりません。\n>\n> シングルコレクトをどのように使いますか? \n> この例では、複数のCOLLECTステートメントがあります。 \n> [説明へのリンク](https://pythonhosted.org/PyInstaller/spec-files.html#example-\n> merge-spec-file)\n>\n> @altendkyのおかげで、すべてを1つのCOLLECTに* args [0]として渡すことができます。 \n> COLLECTはどこに文書化されていますか?\n```\n\n> coll_main = COLLECT(exe_main,\n> a_main.binaries,\n> a_main.zipfiles,\n> a_main.datas,\n> exe_main2,\n> a_main2.binaries,\n> a_main2.zipfiles,\n> a_main2.datas,\n> strip=False,\n> upx=True,\n> name='main')\n> \n```\n\n>\n> COLLECTは文書化されていません。 多分あなたは#1371を助けたいです。\n\nちなみに文書化の要望はまだ処理されていないようです。 \n[Document COLLECT\n#3741](https://github.com/pyinstaller/pyinstaller/issues/3741)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T04:49:27.630", "id": "53115", "last_activity_date": "2019-03-01T04:49:27.630", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "53108", "post_type": "answer", "score": 0 } ]
53108
53115
53115
{ "accepted_answer_id": null, "answer_count": 1, "body": "現在Maya上でのログ情報を出力するような仕組みを作成しているのですが、インストールを必要とする外部ソフトウェアやライブラリを使用せず、Maya単体でGPUの名前(GeForce\nGTX ~等)を取得できる方法を探しています。\n\n調べた限りでは、OpenMayaAPIの「[OpenMayaRender.MRenderer.GPUDeviceHandle()](https://help.autodesk.com/view/MAYAUL/2018/JPN/?guid=__py_ref_class_open_maya_render_1_1_m_renderer_html)」とかが近そうですが、そもそもハンドラだから名前は取れないし、じゃあハンドルから名前取るような関数があるのかと探していますが見つからず、といった状況です。\n\nMaya単体(OpenMayaAPI, os,\nsys等ビルトイン含む)でGPUの情報を取得する方法をご存知の方がいらっしゃいましたら、ご教授の方お願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T02:59:45.427", "favorite_count": 0, "id": "53110", "last_activity_date": "2019-07-24T01:04:22.987", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20642", "post_type": "question", "score": 3, "tags": [ "python" ], "title": "Maya+Python(含:OpenMayaAPI)で現在のPCのグラボ(GPU)名を取得したい", "view_count": 77 }
[ { "body": "自己解決しました。\n\n```\n\n from maya import cmds\n cmds.ogs(di=True)\n \n```\n\nと記述すればグラボ情報を見ることができました(Adapterの項目)。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T09:22:32.750", "id": "53118", "last_activity_date": "2019-07-24T01:04:22.987", "last_edit_date": "2019-07-24T01:04:22.987", "last_editor_user_id": "32986", "owner_user_id": "20642", "parent_id": "53110", "post_type": "answer", "score": 1 } ]
53110
null
53118
{ "accepted_answer_id": "53112", "answer_count": 1, "body": "AWSのRDS(Aurora/MySQL)にて現在使用されているディスク容量を確認したいのですが、ぱっと見ではマネージメントコンソール中にそのようなものはありませんでした。 \nデータベースが使用しているディスク容量はどこで確認できますか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T03:10:45.117", "favorite_count": 0, "id": "53111", "last_activity_date": "2021-03-13T10:40:24.103", "last_edit_date": "2021-03-13T10:40:24.103", "last_editor_user_id": "3060", "owner_user_id": "4715", "post_type": "question", "score": 2, "tags": [ "mysql", "amazon-rds" ], "title": "AWS RDS(Aurora)で使用されているディスク容量はどこで確認できますか?", "view_count": 7826 }
[ { "body": "`[Billed] Volume Bytes Used` で確認できます。\n\nRDSの管理コンソールからインスタンスを選んで Monitoring の2ページ目にありました。 \nもしくは CloudWatch でVolumeBytesUsed メトリクスを検索してみてください。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T03:30:32.943", "id": "53112", "last_activity_date": "2019-03-01T03:30:32.943", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "53111", "post_type": "answer", "score": 3 } ]
53111
53112
53112
{ "accepted_answer_id": "53227", "answer_count": 1, "body": "PHPで通知機能を作成しようとしています、ロジック面での質問です。\n\n実装したい内容\n\n 1. データベースに新規内容が登録されたら通知を表示(検索でなんとかなりそう)\n 2. 通知から登録された内容が表示されている画面に遷移(ここまでは検索でなんとかなりそう)\n 3. 一度遷移して、画面を閲覧したら通知が消えるようにしたい\n\nこの3はどういう考え方をすれば実装できるでしょうか?\n\n追記 \n・通知はブラウザで表示したい \n・閲覧済みのフィールド追加可能 \n・認証、ログイン機能を付けているので個々に対応したものに上記の通知機能を付けたい \nログインはuser IDを自動で振り分けているのでそれを紐づける予定\n\n調べた結果markAsReadとかも使えそうなのか、と思考を巡らせております。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T03:31:45.147", "favorite_count": 0, "id": "53113", "last_activity_date": "2019-03-06T02:11:29.727", "last_edit_date": "2019-03-05T07:11:27.340", "last_editor_user_id": "31799", "owner_user_id": "31799", "post_type": "question", "score": 1, "tags": [ "php" ], "title": "内容を閲覧後に表示を消すことができる通知機能を実装したい", "view_count": 160 }
[ { "body": "データベース(MySQL)を利用した通知機能です。 \nPHPだけではちょっと実装をできないのでご注意ください。\n\nどのようなデータベースかはわかりませんが、 \n仮に以下のようなテーブルとデータがあったとします。\n\n```\n\n create table Customer(cus_id integer NOT NULL PRIMARY KEY, cus_name varchar(100));\n create table News(news_id integer NOT NULL PRIMARY KEY, news_title varchar(100));\n insert Customer SET cus_id = 1, cus_name = \"須田区叔母風呂\";\n insert News SET news_id = 1, news_title = \"バージョンアップのお知らせ\";\n insert News SET news_id = 2, news_title = \"バージョンダウンのお知らせ\";\n \n```\n\nそこに「顧客毎にニュースを閲覧履歴」テーブルを作ります。\n\n```\n\n create table CustomerMarkAsReadNews(cus_id integer NOT NULL, news_id integer NOT NULL, \n PRIMARY KEY(cus_id,news_id), FOREIGN KEY (cus_id) \n REFERENCES Customer(cus_id),FOREIGN KEY (news_id) \n REFERENCES News(news_id));\n \n```\n\n「須田区叔母風呂」が「バージョンアップのお知らせ」のNewsを開いたタイミングで「顧客毎にニュースを閲覧履歴」テーブルにデータを代入します\n\n```\n\n insert CustomerMarkAsReadNews SET cus_id = 1, news_id = 1;\n \n```\n\n通知機能ではNewsを取得するときに「顧客毎にニュースを閲覧履歴」と結合します。 \n条件としては \nログインしている「須田区叔母風呂」の「顧客毎にニュースを閲覧履歴」のデータがないNews\n\n```\n\n SELECT * FROM News\n LEFT JOIN CustomerMarkAsReadNews\n ON News.news_id = CustomerMarkAsReadNews.news_id \n AND CustomerMarkAsReadNews.cus_id = 1\n WHERE CustomerMarkAsReadNews.news_id is Null;\n \n```\n\nPHPで利用しているフレームワークやライブラリがわからないのでデータとのやり取りだけを記載させていただきました。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-06T02:11:29.727", "id": "53227", "last_activity_date": "2019-03-06T02:11:29.727", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22665", "parent_id": "53113", "post_type": "answer", "score": 1 } ]
53113
53227
53227
{ "accepted_answer_id": "53117", "answer_count": 1, "body": "URL先のデータを保存する方法が調べてもわかりませんでした。\n\nurlwatchというものがあると助言いただいたのですがいまいちわかりません・・\n\n教えてください。\n\ndiscordのbotに関する質問なのですが・・・\n\n-追記- \n<http://www3.nhk.or.jp/sokuho/jishin/data/JishinReport.xml>\n\nこれを \n保存 \n↓ 5秒後 \nサイトと先ほど保存したものを比べる \n↓ 変化あり-------------↓変化なし \nメッセージを送信--------はじめに戻る \n↓ \n上書き保存 \n↓ \nはじめに戻る\n\nという動作を作りたいです。\n\nわたしが想定ついている方法としましてはこのようなものです。\n\n```\n\n class MyBot(commands.Bot):\n async def on_ready(self):\n while True:\n #URLを開く\n #中身を保存\n await asyncio.sleep(5)\n #URLを開く\n #もしURL先のページと保存した内容が同じなら\n return\n #もし違うなら\n channel = self.get_channel(525064127056707585)\n await channel.send(\"test\")\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T04:15:17.227", "favorite_count": 0, "id": "53114", "last_activity_date": "2019-03-01T10:49:54.650", "last_edit_date": "2019-03-01T10:49:54.650", "last_editor_user_id": "32332", "owner_user_id": "32332", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "discord.pyでURL先のデータを保存する方法", "view_count": 1102 }
[ { "body": "`urllib` や `requests`\nを利用して対象のXMLを取得、ファイルのハッシュサムやXMLを解析した結果を保存しておき、定期的に取得して差分があるかどうか確認することで実現可能です。\n\nデータの保存については、ローカルにファイルとして保存する方法( `tempfile`\nモジュールを使うと良いでしょう)や、解析した結果などをメモリ上に保存する方法があります。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T09:21:48.343", "id": "53117", "last_activity_date": "2019-03-01T09:21:48.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29826", "parent_id": "53114", "post_type": "answer", "score": 1 } ]
53114
53117
53117
{ "accepted_answer_id": null, "answer_count": 0, "body": "今までsublime textを使用してプログラムを書いてました。\n\nmac os high sierra \nubuntu 14.04\n\nvagrantで起動しているlinuxの中にインストールしたpython3でデバックしていました。\n\n今回、macのテキストエディタをvs codeに変えようと思ってインストールしたのですが以下の警告文が出てきます。\n\n> The macOS system install of Python is not recommended, some \n> functionality in the extension will be limited. Install another \n> version of Python for the best experience.\n\nこれはデバックに使うpythonにMacにインストールされたものを使うのはやめましょうという事だと思います。 \n多分、macに入っているpythonが古い(2.7系)からだと思います。\n\nなるべくMacのシステムをいじりたくはないのでvagrantのubuntu14.04にインストールしたpython3をvs\ncodeのデバックに当てたいのですが、そのような事が可能なのでしょうか\n\n**質問** \nvagrantでubuntuを起動した状態でmacから仮想環境内のpythonを使用できるのかという事です。 \nもしくはこの警告文が出ないようにしてデバック機能なしでsublime textのように使用したいです。\n\n詳しい方教えて頂けると幸いです。 \nよろしくお願いします。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T06:49:06.377", "favorite_count": 0, "id": "53116", "last_activity_date": "2019-07-24T01:02:11.100", "last_edit_date": "2019-07-24T01:02:11.100", "last_editor_user_id": "32986", "owner_user_id": "22565", "post_type": "question", "score": 0, "tags": [ "python", "python3", "vagrant", "vscode" ], "title": "vs codeとmacに入れたvagrantでうまく環境を構築するには?", "view_count": 134 }
[]
53116
null
null
{ "accepted_answer_id": null, "answer_count": 0, "body": "現在、synergy(無料版)を使い、serverーclient間(どちらのOSもubuntu 16.04)でマウスとキーボードのシェアを行っています。\n\n10台のclientと1台のserverをセットアップして、すべてのserver-client間で動作確認はできました。\n\nここで質問です。 \nこのシェアできる最大の数を増やすことは可能でしょうか?。\n\nすこし分かりにくいのですが、synergy\nconfigurationでグラフィカルに設定できる最大の数は15だと認識しています。(添付したイメージでボックスの数が15ですので、そのように考えています。)\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/vsElW.png)](https://i.stack.imgur.com/vsElW.png) \nこの最大の数を増やすことは可能でしょうか?\n\nもしどなたかご存知の方がおられましたら、ご教授をお願いします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T16:40:12.713", "favorite_count": 0, "id": "53119", "last_activity_date": "2019-03-01T16:40:12.713", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "11048", "post_type": "question", "score": 0, "tags": [ "ubuntu" ], "title": "synergyでマウスをシェアできるclientの最大数を増やすことは可能ですか?", "view_count": 43 }
[]
53119
null
null
{ "accepted_answer_id": "53157", "answer_count": 1, "body": "Python のスクリプトを書いています。\n\n最初は signal を受信したらハンドラ内でファイル I/O 処理など様々な処理を書いていました。スクリプトを実行し、`kill -TERM <PID>`\nを実行するとシグナルハンドラ `handler()` が呼ばれ、様々な処理をするコードです。\n\n```\n\n import signal\n import time\n import os\n \n \n def handler(num, frame):\n print(\"handler\")\n # do something\n \n \n signal.signal(signal.SIGTERM, handler)\n print(\"sleep... {0}\".format(os.getpid()))\n time.sleep(60)\n \n```\n\nが、ふと、signal ハンドラ内で重い処理をおこなっていいのか疑問に思い、ググったり、いろいろ調べたところ\n[Linuxプログラミングインタフェース](https://www.oreilly.co.jp/books/9784873115856/)「21章\nシグナルハンドラの設計」に以下のように書いてありました。\n\n>\n> 「すべてのシステムコール、ライブラリ関数が、シグナルハンドラ内で安全に実行できる訳ではありません。その理由を理解するには、リエントラントな関数、および非同期シグナルセーフな関数という\n> 2 つの概念が必要になります。(p.444)\n\nここで、「非同期シグナルセーフ」はいわゆるスレッドセーフのことのようです。\n\nつまり、ファイル I/O\n等の処理はたとえばマルチスレッドとして実装し、シグナルハンドラからはスレッドを起こすだけ、といったようにしないといけない。と理解したのですが、このような理解であっているでしょうか?\n\nたとえばこのような実装をイメージしています:\n\n```\n\n import signal\n import threading\n import time\n import os\n \n event = threading.Event()\n \n \n def funcA():\n print(\"start funcA\")\n event.wait()\n print(\"end funcA\")\n \n \n def handler(num, frame):\n print(\"handler\")\n event.set()\n \n \n signal.signal(signal.SIGTERM, handler)\n th = threading.Thread(target = funcA)\n th.start()\n print(\"sleep... {0}\".format(os.getpid()))\n time.sleep(60)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T16:58:05.507", "favorite_count": 0, "id": "53120", "last_activity_date": "2019-03-03T06:01:31.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9592", "post_type": "question", "score": 1, "tags": [ "python", "マルチスレッド" ], "title": "Python でのシグナルハンドラ内の処理", "view_count": 1576 }
[ { "body": "> >\n> 「すべてのシステムコール、ライブラリ関数が、シグナルハンドラ内で安全に実行できる訳ではありません。その理由を理解するには、リエントラントな関数、および非同期シグナルセーフな関数という\n> 2 つの概念が必要になります。(p.444)\n\nシステムによって「非同期シグナルセーフな関数(システムコール)」は具体的に定められており、シグナルハンドラ中ではこれ以外の関数(システムコール)を呼んではいけないことになっています。スレッドセーフとは異なります。\n\n<https://docs.oracle.com/cd/E19683-01/816-3976/gen-24356/index.html> \n<https://www.jpcert.or.jp/sc-rules/c-sig30-c.html>\n\nシグナルハンドラにおけるリエントラントとは、シグナルハンドラの処理中に再度割り込みが発生しても安全であることを意味します。(広義の「非同期シグナルセーフ」)\n\n> [Python のシグナルハンドラは、低水準 (C言語)\n> のシグナルハンドラ内で実行されるわけではありません。](https://docs.python.org/ja/3.8/library/signal.html)\n\nということなので、Pythonのレベルでは「非同期シグナルセーフ」がどのように要求されているかはまた異なります。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T06:01:31.813", "id": "53157", "last_activity_date": "2019-03-03T06:01:31.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "53120", "post_type": "answer", "score": 2 } ]
53120
53157
53157
{ "accepted_answer_id": "53122", "answer_count": 1, "body": "`app/views/layouts/application.html.haml`\n\nの1行目で\n\n`!!! 5`\n\nという表記がありましたが、これは何を意味しているのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T17:51:39.620", "favorite_count": 0, "id": "53121", "last_activity_date": "2019-03-03T06:07:30.023", "last_edit_date": "2019-03-03T06:07:30.023", "last_editor_user_id": "30079", "owner_user_id": "12896", "post_type": "question", "score": 5, "tags": [ "ruby-on-rails", "html", "haml" ], "title": "!!! 5 という表記はなにを表していますか?", "view_count": 141 }
[ { "body": "それは`<!DOCTYPE html>`を表しています。\n\n`.haml`という拡張子が示すとおり、それはHamlというテンプレート言語で書かれたものであり、HTMLに変換されます。`<!DOCTYPE\nhtml>`はHTML5のDOCTYPE宣言であり、それに対応するHamlの記法が`!!! 5`です。\n\n[Hamlのドキュメントの!!!の節](http://haml.info/docs/yardoc/file.REFERENCE.html#doctype-)に説明があります。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-01T18:06:09.880", "id": "53122", "last_activity_date": "2019-03-01T18:06:09.880", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30079", "parent_id": "53121", "post_type": "answer", "score": 6 } ]
53121
53122
53122
{ "accepted_answer_id": "53127", "answer_count": 7, "body": "お世話になります。\n\n業務で、今度の四月から開始される『働き方改革』の中に、複数月の平均が80時間を超えてはならないと \nいうのがあり、それを求めるためのツールをAccessで作成しています。\n\n四月から始まり、三月で終わる一年の期間の中で、二ヶ月以上の連続した組み合わせ(4-5,4-5-6,4-5-6-7~1-2-3,2-3まで)の平均を算出するのですが、数を数えてみると合計で66パターンの組み合わせができてしまいます。これを人数分だけ計算するとなると、かなりの時間がかかると思います。 \n勿論、一つ一つ行って、一度でも80時間超えがあれば、そこで確認済みにすれば良い話ではあるのですが、これをもっと効率的にやりたいと思っています。\n\n上記のような、『総当たりの平均』を求めるやり方で、もっと効率の良い方法はありますでしょうか?SQLなどでできれば、とてもエレガントだとは思いますが…。SQLの平均の記述が解らないのではなく、コードのようにループさせなくて済む方法です。\n\n強引にコードに直すと、下記のようになると思います。\n\n```\n\n    Dim arr(11) As Long ' ここでは宣言しかしていませんが、既に中身があるものと思ってください。\n    Dim d0 As Long, d1 As Long, d2 As Long\n Dim val As Double\n Dim flg As Boolean\n \n flg = False\n For d0 = 0 To 11 - 1\n For d1 = d0 + 1 To 12 - 1\n val = 0#\n For d2 = d0 To d1\n val = val + arr(d2)\n If (val / ((d1 - d0) + 1) > 80) Then\n flg = True\n GoTo End_for\n End If\n Next\n Next\n Next\n \n End_for:\n \n```\n\nよろしくお願いいたします。", "comment_count": 10, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T01:09:07.277", "favorite_count": 0, "id": "53123", "last_activity_date": "2019-03-11T06:51:53.987", "last_edit_date": "2019-03-02T02:44:03.977", "last_editor_user_id": "9374", "owner_user_id": "9374", "post_type": "question", "score": 6, "tags": [ "sql", "アルゴリズム" ], "title": "12ヶ月の中の複数月の平均を求めるアルゴリズム", "view_count": 826 }
[ { "body": "(面白そうなんで考えてみました。回答として妥当では無いと思うのですが、コメント欄には書ききれなそうだったので…他の方がこんな問題に対してどういうふうに考えられるのか興味あります。)\n\n* * *\n\n * 連続する2ヶ月の平均が80時間超ならば、少なくともどちらかが80時間超 \n * (裏)連続する2ヶ月の平均が80時間以下ならば、少なくともどちらかが80時間以下\n\nと\n\n * 連続する3ヶ月(m1,m2,m3)平均が80時間超で、かつ、その期間に含まれる連続する2ヶ月平均(※組み合わせは(m1,m2),(m2,m3)の2パターン)が全て80時間以下なら、端の月(期間の開始月m1、終了月m3、の2月)のいずれも80時間超\n\nは正しそうで、ここから\n\n * 連続するnヶ月平均が80時間超で、かつ、その期間に含まれる連続するn-1ヶ月平均が全て(※組み合わせは2パターン)80時間以下なら、端の月のいずれも80時間超\n\nも言えそうな気がするので\n\n 1. 80時間超の月と前月との2ヶ月平均\n 2. 80時間超の月と翌月との2ヶ月平均\n 3. 80時間超の月と、翌直近の80時間超の月との間の平均\n\nを調べれば良さそうに思われます。\n\n単月での80時間超は許容される、というのが3.以外に1.,2.も調べないといけないのに繋がっているのかな、と。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T05:45:54.090", "id": "53125", "last_activity_date": "2019-03-02T05:56:09.900", "last_edit_date": "2019-03-02T05:56:09.900", "last_editor_user_id": "2808", "owner_user_id": "2808", "parent_id": "53123", "post_type": "answer", "score": 0 }, { "body": "『働き方改革』については、[時間外労働の上限規制の「2~6ヵ月平均で80時間以内」とは?【労働基準法改正\n2019】](http://ttps://www.ieyasu.co/media/max_80h-average/) の記事を参考にしました。\n\nこの記事によると、「複数月の平均が80時間を超えてはならない」というのは正確には「2ヵ月ないし6か月平均で80時間以内」ということで、 \nその意味は、“2ヵ月、3ヵ月、4ヵ月、5ヵ月、6か月のいずれの期間においても、月平均80時間以内にしなければならない”。\n\nそうすると、平均を計算しないといけないパターンは、以下の45種類 \n2か月:11パターン(4月から、5月から、・・・、2月から) \n3か月:10パターン(4月から、5月から、・・・、1月から) \n4か月:9パターン(4月から、5月から、・・・、12月から) \n5か月:8パターン(4月から、5月から、・・・、11月から) \n6か月:7パターン(4月から、5月から、・・・、10月から)\n\n月の時間外労働時間が80時間を超えているかどうかの判断にも計算時間がかかるので、80時間を超えるケースが見つかるまで、全てのパターンを順に計算してみる以下のような愚直なコードのほうが計算時間は短くなると思います。\n\n```\n\n Dim overtime(12) As Double ' 12か月(4月から3月まで)の時間外労働時間の配列(データは事前に入れられていると想定)\n Dim numOfMonth as Integer, startMonth as Integer, ov as Integer\n Dim val As Double\n Dim flg As Boolean\n \n flg = False\n For numOfMonth = 2 To 6 '平均をとる月の数を、2から6まで変えて調べる\n For startMonth = 0 to 12-numOfMonth '\n val = 0#\n For ov = startMonth To startMonth + numOfMonth -1\n val = val + overtime(ov)\n Next ov\n If ((val / numOfMonth) > 80) Then '月平均時間外労働時間が80時間超えか?\n flg = True\n GoTo End_for\n End If\n Next startMonth\n Next numOfMonth\n \n End_for:\n ' flagの値に基づいて、結果を表示する\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T06:29:33.707", "id": "53127", "last_activity_date": "2019-03-02T06:29:33.707", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "53123", "post_type": "answer", "score": 0 }, { "body": "Fumu 7さんの回答ですが\n\n> そうすると、平均を計算しないといけないパターンは、以下の45種類 \n> 2か月:11パターン(4月から、5月から、・・・、2月から) \n> 3か月:10パターン(4月から、5月から、・・・、1月から) \n> 4か月:9パターン(4月から、5月から、・・・、12月から) \n> 5か月:8パターン(4月から、5月から、・・・、11月から) \n> 6か月:7パターン(4月から、5月から、・・・、10月から)\n\nもう少し簡略化できます。\n\n4か月パターンですが1例を挙げると4-7で平均80時間を超える場合、平均の原理から4-5と6-7のどちらかが80時間を超えることになります。4-5も6-7も2か月パターンで検査済みですから、4か月パターンをチェックする必要はありません。同様に5か月、6か月も省略可能です。\n\n * 2か月: 4-5, 5-6, 6-7, 7-8, 8-9, 9-10, 10-11, 11-12, 12-1, 1-2, 2-3\n * 3か月: 4-6, 5-7, 6-8, 7-9, 8-10, 9-11, 10-12, 11-1, 12-2, 1-3\n\nの計21パターンの検査で済みます。 \n考え方次第ですが、ここまで絞り込めたのであれば、もう愚直にハードコーディングされるのも1つの手です。\n\n* * *\n\nyukihaneさんの考え方はここから更に数学的に候補を減らしたものです。ただし「80時間超の月」を探す処理が必要になっていますのでSQLでの記述は難しくなります。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T08:22:58.377", "id": "53190", "last_activity_date": "2019-03-04T08:22:58.377", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "53123", "post_type": "answer", "score": 0 }, { "body": "もし、 CTE が使える DB につながっているのであれば、以下のようにすると、 66 パターンを sql 上で一発で取得できたりします。(下記は、\nmysql の場合)\n\n```\n\n -- base は、適宜、 DB からの月次の集計結果クエリに置き換える\n with recursive base as (\n select 4 as `month`, 74 as hours\n union all\n select 5, 75\n union all\n select 6, 76\n union all\n select 7, 77\n union all\n select 8, 78\n union all\n select 9, 79\n union all\n select 10, 80\n union all\n select 11, 81\n union all\n select 12, 82\n union all\n select 1, 83\n union all\n select 2, 84\n union all\n select 3, 85\n ), unioned as (\n select CAST(`month` as CHAR(255)) as months, `month` as last_month, 1 as num_months, hours * 1.0 as hours from base\n union all\n select concat(months, '-', `month`), `month` as last_month, num_months + 1, (unioned.hours * num_months + base.hours) * 1.0 / (num_months + 1)\n from unioned inner join base on (unioned.last_month) % 12 + 1 = base.`month`\n where unioned.last_month <> 3\n )\n select * from unioned\n where num_months > 1;\n \n```\n\n実行結果\n\n```\n\n +----------------------------+------------+------------+-------+\n | months | last_month | num_months | hours |\n +----------------------------+------------+------------+-------+\n | 4-5 | 5 | 2 | 74.5 |\n | 5-6 | 6 | 2 | 75.5 |\n | 6-7 | 7 | 2 | 76.5 |\n | 7-8 | 8 | 2 | 77.5 |\n | 8-9 | 9 | 2 | 78.5 |\n | 9-10 | 10 | 2 | 79.5 |\n | 10-11 | 11 | 2 | 80.5 |\n | 11-12 | 12 | 2 | 81.5 |\n | 12-1 | 1 | 2 | 82.5 |\n | 1-2 | 2 | 2 | 83.5 |\n | 2-3 | 3 | 2 | 84.5 |\n | 4-5-6 | 6 | 3 | 75.0 |\n | 5-6-7 | 7 | 3 | 76.0 |\n | 6-7-8 | 8 | 3 | 77.0 |\n | 7-8-9 | 9 | 3 | 78.0 |\n | 8-9-10 | 10 | 3 | 79.0 |\n | 9-10-11 | 11 | 3 | 80.0 |\n | 10-11-12 | 12 | 3 | 81.0 |\n | 11-12-1 | 1 | 3 | 82.0 |\n | 12-1-2 | 2 | 3 | 83.0 |\n | 1-2-3 | 3 | 3 | 84.0 |\n | 4-5-6-7 | 7 | 4 | 75.5 |\n | 5-6-7-8 | 8 | 4 | 76.5 |\n | 6-7-8-9 | 9 | 4 | 77.5 |\n | 7-8-9-10 | 10 | 4 | 78.5 |\n | 8-9-10-11 | 11 | 4 | 79.5 |\n | 9-10-11-12 | 12 | 4 | 80.5 |\n | 10-11-12-1 | 1 | 4 | 81.5 |\n | 11-12-1-2 | 2 | 4 | 82.5 |\n | 12-1-2-3 | 3 | 4 | 83.5 |\n | 4-5-6-7-8 | 8 | 5 | 76.0 |\n | 5-6-7-8-9 | 9 | 5 | 77.0 |\n | 6-7-8-9-10 | 10 | 5 | 78.0 |\n | 7-8-9-10-11 | 11 | 5 | 79.0 |\n | 8-9-10-11-12 | 12 | 5 | 80.0 |\n | 9-10-11-12-1 | 1 | 5 | 81.0 |\n | 10-11-12-1-2 | 2 | 5 | 82.0 |\n | 11-12-1-2-3 | 3 | 5 | 83.0 |\n | 4-5-6-7-8-9 | 9 | 6 | 76.5 |\n | 5-6-7-8-9-10 | 10 | 6 | 77.5 |\n | 6-7-8-9-10-11 | 11 | 6 | 78.5 |\n | 7-8-9-10-11-12 | 12 | 6 | 79.5 |\n | 8-9-10-11-12-1 | 1 | 6 | 80.5 |\n | 9-10-11-12-1-2 | 2 | 6 | 81.5 |\n | 10-11-12-1-2-3 | 3 | 6 | 82.5 |\n | 4-5-6-7-8-9-10 | 10 | 7 | 77.0 |\n | 5-6-7-8-9-10-11 | 11 | 7 | 78.0 |\n | 6-7-8-9-10-11-12 | 12 | 7 | 79.0 |\n | 7-8-9-10-11-12-1 | 1 | 7 | 80.0 |\n | 8-9-10-11-12-1-2 | 2 | 7 | 81.0 |\n | 9-10-11-12-1-2-3 | 3 | 7 | 82.0 |\n | 4-5-6-7-8-9-10-11 | 11 | 8 | 77.5 |\n | 5-6-7-8-9-10-11-12 | 12 | 8 | 78.5 |\n | 6-7-8-9-10-11-12-1 | 1 | 8 | 79.5 |\n | 7-8-9-10-11-12-1-2 | 2 | 8 | 80.5 |\n | 8-9-10-11-12-1-2-3 | 3 | 8 | 81.5 |\n | 4-5-6-7-8-9-10-11-12 | 12 | 9 | 78.0 |\n | 5-6-7-8-9-10-11-12-1 | 1 | 9 | 79.0 |\n | 6-7-8-9-10-11-12-1-2 | 2 | 9 | 80.0 |\n | 7-8-9-10-11-12-1-2-3 | 3 | 9 | 81.0 |\n | 4-5-6-7-8-9-10-11-12-1 | 1 | 10 | 78.5 |\n | 5-6-7-8-9-10-11-12-1-2 | 2 | 10 | 79.5 |\n | 6-7-8-9-10-11-12-1-2-3 | 3 | 10 | 80.5 |\n | 4-5-6-7-8-9-10-11-12-1-2 | 2 | 11 | 79.0 |\n | 5-6-7-8-9-10-11-12-1-2-3 | 3 | 11 | 80.0 |\n | 4-5-6-7-8-9-10-11-12-1-2-3 | 3 | 12 | 79.5 |\n +----------------------------+------------+------------+-------+\n 66 rows in set (0.00 sec)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T11:29:21.427", "id": "53193", "last_activity_date": "2019-03-04T11:44:35.313", "last_edit_date": "2019-03-04T11:44:35.313", "last_editor_user_id": "754", "owner_user_id": "754", "parent_id": "53123", "post_type": "answer", "score": 0 }, { "body": "SQLで総当たりを求めると考えると \n再帰CTEの使えないACCESSでやるのであれば、素直に66通りの組み合わせテーブルを作るのが良いんじゃないでしょうか\n\n仮に組み合わせテーブルを \nFromTo(from Integer,to integer)として \n(1,2) \n(1,3) \n... \n(1,12) \n(2,3) \n... \n(2,12) \n(11,12) \nの66レコードを用意し \nあとは\n\n```\n\n SELECT \n FromTo.from, \n FromTo.to, \n (select avg(時間) from クエリ1 where 月番号>= FromTo.from and 月番号<=FromTo.to) AS 平均時間\n FROM \n FromTo;\n \n```\n\nのようなクエリで取れます\n\n月番号は年度ごとに4月~翌3月を1~12になるように調整している前提です \n例えばこんなクエリ\n\n```\n\n SELECT \n IIf(Month(年月)<4,Year(年月)-1,Year(年月)) AS 年度, \n IIf(Month(年月)<4,Month(年月)+9,Month(年月)-3) AS 月番号, \n テーブル1.時間\n FROM \n テーブル1\n WHERE \n (((IIf(Month(年月)<4,Year(年月)-1,Year(年月)))=2018));\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-06T14:54:37.617", "id": "53249", "last_activity_date": "2019-03-06T14:54:37.617", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9811", "parent_id": "53123", "post_type": "answer", "score": 0 }, { "body": "* パターンが有限\n * 年度単位で、人別に残業時間を集計する必要がありそう\n\nという点を踏まえると、各パターンを計算するSQLを愚直に書き、結果をUNIONで結合するのが簡単かな、思いました。\n\n以下のような感じを考えています。\n\n```\n\n -- テスト用の仮テーブル\n CREATE TABLE test (\n name varchar \n ,year int\n ,month int\n ,hour float);\n \n -- テスト用データの準備 \n INSERT INTO test VALUES ('A', 2019, 4, 60.0)\n INSERT INTO test VALUES ('A', 2019, 5, 30.0)\n INSERT INTO test VALUES ('A', 2019, 6, 20.0)\n INSERT INTO test VALUES ('A', 2019, 7, 40.0)\n INSERT INTO test VALUES ('A', 2019, 8, 80.0)\n INSERT INTO test VALUES ('A', 2019, 9, 70.4)\n INSERT INTO test VALUES ('A', 2019, 10, 100.4)\n INSERT INTO test VALUES ('A', 2019, 11, 20.4)\n INSERT INTO test VALUES ('A', 2019, 12, 30.4)\n INSERT INTO test VALUES ('A', 2019, 1, 30.4)\n INSERT INTO test VALUES ('A', 2019, 2, 10.4)\n INSERT INTO test VALUES ('A', 2019, 3, 20.4)\n INSERT INTO test VALUES ('B', 2019, 4, 10.4)\n INSERT INTO test VALUES ('B', 2019, 5, 30.4)\n INSERT INTO test VALUES ('B', 2019, 6, 60.4)\n INSERT INTO test VALUES ('B', 2019, 7, 10.4)\n INSERT INTO test VALUES ('B', 2019, 8, 30.4)\n INSERT INTO test VALUES ('B', 2019, 9, 60.4)\n INSERT INTO test VALUES ('B', 2019, 10, 10.4)\n INSERT INTO test VALUES ('B', 2019, 11, 30.4)\n INSERT INTO test VALUES ('B', 2019, 12, 60.4)\n INSERT INTO test VALUES ('B', 2019, 1, 10.4)\n INSERT INTO test VALUES ('B', 2019, 2, 30.4)\n INSERT INTO test VALUES ('B', 2019, 3, 60.4)\n \n -- パターン別に計算してUNION\n SELECT name, year, '4-5' AS 'target', avg(hour) AS 'avg_hour' FROM test WHERE month In (4, 5) GROUP BY year, name\n union\n SELECT name, year, '5-6' AS 'target', avg(hour) AS 'avg_hour' FROM test WHERE month In (5, 6) GROUP BY year, name\n union\n (以下略)\n \n \n```\n\n80時間超過を抽出したければ、`HAVING avg(hour) > 80`を 各パターンのクエリの最後に加える手もあります。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-10T16:19:04.483", "id": "53348", "last_activity_date": "2019-03-10T16:19:04.483", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12561", "parent_id": "53123", "post_type": "answer", "score": 0 }, { "body": "皆さん、ありがとうございます。 \n皆さんのヒントを元に、自分なりに考えてみた『自己レス』です。\n\nもっと良い方法があると思いますので、指摘などしていただければ幸いです。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/3ekLn.jpg)](https://i.stack.imgur.com/3ekLn.jpg)\n\nこんなテーブルを作成しました。m0からm11には、四月から始まり、翌年三月までの \n残業時間が入っている者とします。\n\nその結果、下記のコードを実行しました。\n\n```\n\n Private Sub calcTotalAverage()\n Dim d0 As Long, d1 As Long, d2 As Long\n Dim condition As String\n Dim dtSt As Date\n \n dtSt = #2018/04/01#\n \n ' 6か月間総当たり\n For d0 = 0 To 11 - 1\n For d1 = d0 + 1 To 12 - 1\n \n          ' 最長六ヶ月のため\n If ((d1 - d0) > 6) Then\n Exit For\n End If\n \n SQL = \"UPDATE T_overtime SET [最大平均時間] = \"\n \n condition = \"(\"\n For d2 = d0 To d1\n condition = condition & \"m\" & d2 & \" + \"\n Next\n condition = condition & \"0) / \" & (d1 - d0 + 1)\n SQL = SQL & condition & \",[最大平均開始月] = '\" & Format(DateAdd(\"m\", d0, dtSt), \"m月\") & \"',[最大平均終了月] = '\" & Format(DateAdd(\"m\", d1, dtSt), \"m月\") & \"' WHERE [最大平均時間] < \" & condition\n \n CurrentDb.Execute (SQL)\n Next\n Next\n \n End Sub\n \n```\n\n最終的に、平均の最大値が80を超えているかどうかを見るので、ひとまず愚直に全員の最大の平均時間を算出しました。その上で、『最大平均時間』が80を超えているかどうかを見れば良いかと。\n\nここまでは単純に総当たりですが、皆様から教えていただいた『素数の平均』の考え方が入れば、もっと \n効率よくなるのではないかと思うのですが、いかがでしょうか。\n\nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-11T06:35:03.607", "id": "53358", "last_activity_date": "2019-03-11T06:51:53.987", "last_edit_date": "2019-03-11T06:51:53.987", "last_editor_user_id": "9374", "owner_user_id": "9374", "parent_id": "53123", "post_type": "answer", "score": 0 } ]
53123
53127
53125
{ "accepted_answer_id": "53131", "answer_count": 1, "body": "下記のソースコード下部のLineクラスのプロパティであるlineNodeをシーンに追加した際に線色を白に指定しているにも関わらず黒く表示されてしまいます。現状どこが間違っているのか見当がつかない状況です。 \nLineクラス内のgeometryにmaterialを追加すれば反映されるはずだと思っているのですが、コードを実行した際にそうならないようです。 \n下記コードはxcodeのGameテンプレートを書き換えたものです。 \nswift4.2になります。\n\n```\n\n import UIKit\n import SpriteKit\n import GameplayKit\n import SceneKit\n \n class GameViewController: UIViewController {\n \n var scene:SCNScene!\n var selectedNode:SCNNode!\n \n @IBOutlet weak var sceneView: SCNView!\n override func viewDidLoad() {\n super.viewDidLoad()\n \n if let view = self.view as! SKView? {\n // Load the SKScene from 'GameScene.sks'\n if let scene = SKScene(fileNamed: \"GameScene\") {\n // Set the scale mode to scale to fit the window\n scene.scaleMode = .aspectFill\n \n // Present the scene\n view.presentScene(scene)\n }\n \n view.ignoresSiblingOrder = true\n \n view.showsFPS = true\n view.showsNodeCount = true\n }\n \n //まずは基本となるSCNSceneを追加します。これが無いと始まりません\n scene = SCNScene()\n \n //SCNNodeを追加しますが、このSCNNodeに物体としてのSCNBoxを作成して関連づけます。\n let boxGeometry = SCNBox(width: 1.0, height: 1.0, length: 1.0, chamferRadius: 0.1)\n let boxNode = SCNNode(geometry: boxGeometry)\n scene.rootNode.addChildNode(boxNode)\n \n sceneView.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height)\n sceneView.center = self.view.center\n sceneView.scene = scene\n sceneView.autoenablesDefaultLighting = true;\n sceneView.allowsCameraControl = true;\n \n let cameraNode = SCNNode()\n cameraNode.camera = SCNCamera()\n cameraNode.camera?.zFar = 100\n cameraNode.camera?.zNear = 0\n scene.rootNode.addChildNode(cameraNode)\n // place the camera\n cameraNode.position = SCNVector3(x: 0, y: 0, z: 10)\n \n let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.objTap(_:)))\n sceneView.addGestureRecognizer(tapGesture)\n \n sceneView.backgroundColor = .gray\n \n \n \n //lineクラスのテスト\n let p1 = SCNVector3(2, 2, 0)\n let p2 = SCNVector3(-2, 2, 0)\n let p3 = SCNVector3(-2, -2, 0)\n let p4 = SCNVector3(2, -2, 0)\n let line = Line()\n line.addPoint(vector: p1)\n line.addPoint(vector: p2)\n line.addPoint(vector: p3)\n line.addPoint(vector: p4)\n line.makeGeometry()\n scene.rootNode.addChildNode(line.lineNode)\n \n \n \n }\n \n \n @objc\n func objTap(_ gestureRecognize: UIGestureRecognizer){\n let p = gestureRecognize.location(in: sceneView)\n \n \n let hitResults = sceneView.hitTest(p, options: [:])\n \n if hitResults.count > 0 {\n let result = hitResults[0]\n self.selectedNode = result.node\n }\n \n \n if self.selectedNode != nil{\n \n \n let sphereGeometry = SCNSphere(radius: 0.2)\n self.selectedNode.geometry = sphereGeometry\n \n \n \n }\n \n \n \n \n \n }\n \n \n override var shouldAutorotate: Bool {\n return true\n }\n \n override var supportedInterfaceOrientations: UIInterfaceOrientationMask {\n if UIDevice.current.userInterfaceIdiom == .phone {\n return .allButUpsideDown\n } else {\n return .all\n }\n }\n \n override var prefersStatusBarHidden: Bool {\n return true\n }\n }\n \n \n \n class Line{\n var points: [SCNVector3] = []\n var lineNode:SCNNode = SCNNode()\n var source:SCNGeometrySource!\n var indices: [UInt32]!\n var maxPointsNum:Int = 100\n \n \n func addPoint(vector:SCNVector3){\n points.append(vector)\n if points.count > self.maxPointsNum{\n points.remove(at: 0)\n }\n }\n \n func makeGeometry(){\n source = SCNGeometrySource(vertices: points)\n indices = {var rtn = [UInt32]();for i in 0..<points.count-1{rtn += [UInt32(i), UInt32(i+1)]};return rtn}()\n let element = SCNGeometryElement(indices: indices, primitiveType: .line)\n let geometry = SCNGeometry(sources: [source], elements: [element])\n let material = SCNMaterial()\n material.diffuse.contents = UIColor.white\n geometry.materials = [material]\n lineNode.geometry = geometry\n }\n \n \n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T02:45:07.067", "favorite_count": 0, "id": "53124", "last_activity_date": "2019-03-02T08:40:38.540", "last_edit_date": "2019-03-02T07:25:55.640", "last_editor_user_id": "76", "owner_user_id": "25745", "post_type": "question", "score": 0, "tags": [ "swift", "ios", "swift4" ], "title": "SceneKitのSCNGeometryで線を描いた時に色をつけることができない。", "view_count": 476 }
[ { "body": "検索してみたところ、次のような本家英語版StackOverflowの記事が見つかりました。\n\n[Color line in scene kit?](https://stackoverflow.com/q/28387305/6541007)\n\nリンク先の回答には数式なんかも示されていますが、要約と若干の補足をすると、`diffuse`と言うのは「拡散反射」を指定するプロパティであり、`SceneMaterial`のデフォルトのライティングモデル(および大抵の3D描画のライティングモデル)では\n**表面**\nの光源に対する向きから計算した係数が`diffuse`に掛けられる(斜め向いている面を暗くする)のに対して、表面なんてものがない線分の場合、この係数が0になっちゃう、と言う意味の説明が書いてあります。\n\n解決策としては、\n\n * ライティングモデルとして`SCNLightingModelConstant`を用いる\n * `diffuse`ではなく`emission`プロパティを操作する\n\nなんてものが挙げられています。\n\n前者をSwift 4.2の文法に合わせてあなたのコードに適用するとこうなります。\n\n```\n\n func makeGeometry(){\n source = SCNGeometrySource(vertices: points)\n indices = {var rtn = [UInt32]();for i in 0..<points.count-1{rtn += [UInt32(i), UInt32(i+1)]};return rtn}()\n let element = SCNGeometryElement(indices: indices, primitiveType: .line)\n let geometry = SCNGeometry(sources: [source], elements: [element])\n let material = SCNMaterial()\n material.lightingModel = .constant //<-\n material.diffuse.contents = UIColor.white\n geometry.materials = [material]\n lineNode.geometry = geometry\n }\n \n```\n\n後者に関しては、私が試したところではうまくいかなかったので割愛します。ご自身で試してみて、うまくいった場合には自己回答していただければと思います。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T08:40:38.540", "id": "53131", "last_activity_date": "2019-03-02T08:40:38.540", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "53124", "post_type": "answer", "score": 0 } ]
53124
53131
53131
{ "accepted_answer_id": "53128", "answer_count": 1, "body": "いつもお世話になっています。 \n【質問の主旨】で示すJavaScriptコード(promise.js)について質問です。 \nご存知の方がいらっしゃいましたらご教示を願います。\n\n* * *\n\n### 【質問の主旨】\n\n```\n\n function runAsync(value) {\n return new Promise((resolve, reject) => {\n setTimeout(() => {\n if (typeof value === 'number') {\n resolve(value * 2);\n } else {\n reject(new Error(`${value}は数値ではありません。`));\n }\n }, 500);\n });\n }\n \n runAsync(15)\n .then(response => console.log(`成功[${response}]`))\n .catch(error => console.log(`失敗[${error}]`))\n .finally(() => console.log('終了'));\n \n```\n\nこのファイルを実行すると2秒後にrunAsync関数の引数になっている数字が、2倍に変化してコンソール画面に表示されるコードです。\n\n```\n\n .finally(() => console.log('終了'));\n ^\n TypeError: runAsync(...).then(...).catch(...).finally is not a function\n \n```\n\n`node promise.js`でターミナルから実行すると上記のエラーが表示されます。なぜでしょうか?\n\n### 【質問の補足】\n\n```\n\n runAsync(15)\n .then(response => console.log(`成功[${response}]`))\n .catch(error => console.log(`失敗[${error}]`));\n \n```\n\n上記の通りメソッド2つに減らすと、`成功[30]`とだけ表示されます\n\n* * *\n\n以上、ご確認のほどよろしくお願い申し上げます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T05:59:40.440", "favorite_count": 0, "id": "53126", "last_activity_date": "2019-03-02T07:25:23.800", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32232", "post_type": "question", "score": 1, "tags": [ "javascript", "node.js", "promise" ], "title": "Promiseオブジェクトのfinallyメソッドを実行するとエラーが出るのはなぜでしょうか?", "view_count": 1513 }
[ { "body": "node.jsのバージョンが古いと思われます。\n\nPromiseのfinallyは比較的新しいメソッドなので、古い環境では使用できません([MDN](https://developer.mozilla.org/en-\nUS/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally#Browser_compatibility))。\n\nnode.jsで使用するには、 **node.jsのv10以上** が必要です。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T07:25:23.800", "id": "53128", "last_activity_date": "2019-03-02T07:25:23.800", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30079", "parent_id": "53126", "post_type": "answer", "score": 5 } ]
53126
53128
53128
{ "accepted_answer_id": null, "answer_count": 1, "body": "現在、<https://example.com> にてあるサービスを運営しており、 \nその上で、<https://corp.example.com> で会社HPを表示したい状態です。\n\n * example.comはムームードメインで取得\n * <https://example.com> のサーバーはAWS(ELB)\n * CloudFlareをネームサーバーに設定\n * 会社HPはWordPressで、エックスサーバーのサーバー上にある\n\n試みたことは、\n\n 1. example.comをエックスサーバーに登録 \n⇒すでにムームードメインではCloudFlareをネームサーバーに設定しているため、できず(やり方がわからず)\n\n 2. 元々ムームードメインで取得していたexample.bizのネームサーバーをエックスサーバーに設定し、corp.example.biz(comではなくbiz)にて、WordPressをインストールし、CloudFlareからCNAMEでcorp.example.bizを設定 \n⇒できず(無効なURLです。プログラム設定の反映待ちである可能性があります。しばらく時間をおいて再度アクセスをお試しください。となる)\n\n 3. 2の状態で半日待ってみる \n⇒変わらず\n\nどのような設定であれば、<https://corp.example.com> で会社HPを表示することができるのでしょうか。 \nもしくはそもそも不可能などあれば教えて頂きたいです。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T11:31:46.053", "favorite_count": 0, "id": "53134", "last_activity_date": "2019-03-03T00:59:22.323", "last_edit_date": "2019-03-03T00:25:59.520", "last_editor_user_id": "32373", "owner_user_id": "32373", "post_type": "question", "score": 0, "tags": [ "network", "dns" ], "title": "ムームードメインでexample.comを取得し、CloudFlareをネームサーバーにした状態で、corp.example.comでエックスサーバーのWordPressを表示するためにはどうすればいいか", "view_count": 183 }
[ { "body": "# ムームードメインの設定\n\nネームサーバをCloudFlareのものに設定してください。設定すべきネームサーバは、CloudFlareのコントロールパネルのDNSのページに記載があります。\n\n# CloudFlareの設定\n\n 1. example.comのゾーンを作る\n 2. `corp`のAレコードを作る。IPアドレスはエックスサーバのものを指定する\n\n上記の通りになっているか、確認または設定してください。\n\ncorpに対するNSレコードを作成されているようですが誤りです。削除してください。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T00:59:22.323", "id": "53149", "last_activity_date": "2019-03-03T00:59:22.323", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "5793", "parent_id": "53134", "post_type": "answer", "score": 0 } ]
53134
null
53149
{ "accepted_answer_id": "53136", "answer_count": 1, "body": "環境はUbuntuです。'Open'コマンドをインストールしようとしたら以下のようにエラーが出ます。\n\n```\n\n sudo apt-get install open\n Reading package lists... Done\n Building dependency tree\n Reading state information... Done\n E: Unable to locate package open\n \n```\n\nちなみに\"Open\"というコマンドを使ったら以下のように表示されます\n\n```\n\n Command 'Open' not found, did you mean:\n \n command 'open' from deb kbd\n command 'pen' from deb pen\n \n```", "comment_count": 8, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T12:19:10.170", "favorite_count": 0, "id": "53135", "last_activity_date": "2019-03-03T06:59:43.013", "last_edit_date": "2019-03-03T06:59:43.013", "last_editor_user_id": "29826", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "linux", "ubuntu" ], "title": "'Open'がインストールできません。", "view_count": 299 }
[ { "body": "Linux Mint 19 (Ubuntu 18.04 LTS)の環境ですが、\"Open\"というパッケージは見つかりません。 \nインストールの前にまずは`apt search パッケージ名`で検索をしてみてください。\n\n```\n\n $ sudo apt search \"open\"\n $ sudo apt search \"^open$\"\n $ sudo apt search \"^Open$\"\n \n```\n\n以下のサイトで「完全に一致するもの」を条件に検索をした場合にも”Open\"は存在しないようです。\n\n[Ubuntu パッケージ検索](https://packages.ubuntu.com/)", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T12:57:17.257", "id": "53136", "last_activity_date": "2019-03-02T12:57:17.257", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "53135", "post_type": "answer", "score": 0 } ]
53135
53136
53136
{ "accepted_answer_id": "53139", "answer_count": 1, "body": "[やろうとしているアプリケーション](https://github.com/SpiderLabs/social_mapper) \n環境はWindows System for Linuxです。(PCはWindowsで、ubuntuをダウンロードして行っています。) \n今Prerequisitesの4まで行ったのですが、4の\n\n```\n\n Open social_mapper.py and enter social media credentials into global variables at the top of the file\n Command 'Open' not found, did you mean:\n \n command 'open' from deb kbd\n command 'pen' from deb pen\n \n Try: sudo apt install <deb name>\n \n```\n\nと表示され、できません。そして、\n\n```\n\n sudo apt-get instal openまたはkbd\n E: Unable to locate package deb\n \n```\n\nとでます。 \nここから、どうすればできますか?", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T13:44:35.630", "favorite_count": 0, "id": "53138", "last_activity_date": "2019-03-02T14:23:54.863", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": null, "post_type": "question", "score": -1, "tags": [ "linux", "ubuntu" ], "title": "https://github.com/SpiderLabs/social_mapper でエラー", "view_count": 167 }
[ { "body": "> `Open social_mapper.py and enter social media credentials into global\n> variables at the top of the file`\n\nとは、各種SNSの認証情報を `social_mapper.py`\n[上部の変数](https://github.com/SpiderLabs/social_mapper/blob/726071510c060896bb7c4d77d3feb01a0deecc73/social_mapper.py#L30-L61)に入力する、という意味です。\n\nこのため、ユーザー名やパスワードをこの部分に入力してください。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T14:23:54.863", "id": "53139", "last_activity_date": "2019-03-02T14:23:54.863", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29826", "parent_id": "53138", "post_type": "answer", "score": 2 } ]
53138
53139
53139
{ "accepted_answer_id": null, "answer_count": 1, "body": "Spring\nRoo初心者です。STSにRooをインストールしようしたんですが、STSで以下のエラーが出ました。どうもリポジトリからダウンロード失敗のようです。\n\nどうすればいいでしょうか、誠に恐縮ですが、教えていただけたら大変助かります。\n\nProblems occurred while performing installation: Unable to read repository at\n<https://download.springsource.com/release/TOOLS/extensions/sts380/c>... \nUnable to read repository at\n<https://download.springsource.com/release/TOOLS/extensions/sts380/c>... \npeer not authenticated", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T15:09:53.380", "favorite_count": 0, "id": "53140", "last_activity_date": "2019-03-02T15:14:26.067", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32380", "post_type": "question", "score": 0, "tags": [ "java", "spring" ], "title": "STSでRooをインストール時、リポジトリの読み取り失敗", "view_count": 116 }
[ { "body": "ネットワーク接続をネイティブからマニアルに変更してもダメでした。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T15:14:26.067", "id": "53142", "last_activity_date": "2019-03-02T15:14:26.067", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29442", "parent_id": "53140", "post_type": "answer", "score": -1 } ]
53140
null
53142
{ "accepted_answer_id": null, "answer_count": 1, "body": "parcelを使ってVueをバンドルしようとしているのですが、 \nApp.vueの1行目で「Unexpected token (1:0) >」というエラーが出ます。 \n解決策をしらべましたがよくわかりませんでした。 \n一回目のビルドの際のみ \n「npm WARN [email protected] requires a peer of css-loader@* but none is\ninstalled. You must install peer de」というエラーメッセージが出ていました。 \n以下ファイルの階層はすべて同じです。\n\n * package.json\n\n```\n\n \"dependencies\": {\n \"vue\": \"^2.6.8\"\n },\n \"devDependencies\": {\n \"babel-core\": \"^6.26.3\",\n \"babel-helper-vue-jsx-merge-props\": \"^2.0.3\",\n \"babel-plugin-transform-vue-jsx\": \"^3.7.0\",\n \"babel-preset-env\": \"^1.7.0\",\n \"parcel-bundler\": \"^1.11.0\",\n \"parcel-plugin-vue\": \"^1.5.0\"\n }\n \n```\n\n * App.vue\n\n```\n\n <template>\n <div>\n {{ message }}\n </div>\n </template>\n <style>\n </style>\n <script >\n export default {\n name: 'App',\n data() {\n return {\n message: 'Hello Vue!'\n }\n }\n }\n </script>\n \n```\n\n * index.html\n\n```\n\n <!DOCTYPE html>\n <head>\n <meta charset=\"utf-8\">\n </head>\n \n <html>\n \n <body>\n <div id=\"app\">\n <script src=\"./index.js\"></script>\n </div>\n </body>\n \n </html>\n \n```\n\n * index.js\n\n```\n\n import Vue from 'vue'\n import App from './App.vue'\n \n new Vue({\n render: h => h(App)\n }).$mount('#app')\n \n```\n\n \n \nまたもう一件、 \npackage.jsonに以下を記載すると\n\n```\n\n \"scripts\": {\n \"start\": \"parcel index.html -o\"\n }\n \n```\n\n`-o`オプションでエラーが出るのはなぜでしょうか? \n`error: option`-o, --out-file ' argument missing`", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T19:49:43.393", "favorite_count": 0, "id": "53144", "last_activity_date": "2019-03-03T11:07:56.047", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32383", "post_type": "question", "score": 2, "tags": [ "vue.js", "npm", "build" ], "title": "parcelを使ってVueをバンドルするとエラー「Unexpected token (1:0) >」", "view_count": 246 }
[ { "body": "parcel のvueのプラグインが非推奨になっていたためのエラーでした。 \n`parcel-plugin-vue` をuninstallし、 \npackage.jsonにalias `\"vue\": \"./node_modules/vue/dist/vue.common.js\"`を追加することで解決。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T11:07:56.047", "id": "53169", "last_activity_date": "2019-03-03T11:07:56.047", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32383", "parent_id": "53144", "post_type": "answer", "score": 1 } ]
53144
null
53169
{ "accepted_answer_id": null, "answer_count": 0, "body": "bootstrap4のCDNを使用してVueコンポーネントを作成しているのですが、navbarのitemがVerticalとなってしまいます。下記ソースコードです。\n\n【header.vue】 \n\n```\n\n <template>\r\n <header class=\"row\">\r\n <nav class=\"navbar navbar-toggleable-md navbar-light\">\r\n <a class=\"navbar-brand\" href=\"/\">PIZZA PLANET</a>\r\n <ul class=\"navbar-nav\">\r\n <li class=\"nav-item\">\r\n <a class=\"nav-link\" href=\"\">home</a> \r\n </li>\r\n <li class=\"nav-item\">\r\n <a class=\"nav-link\" href=\"\">menu</a> \r\n </li>\r\n </ul>\r\n </nav>\r\n </header>\r\n </template>\r\n \r\n <style>\r\n header{\r\n margin-bottom: 20px;\r\n \r\n }\r\n \r\n .navbar-brand{\r\n font-size: 1.5em; \r\n }\r\n \r\n \r\n \r\n </style>\n```\n\n【index.html】\n\n```\n\n <!DOCTYPE html>\r\n <html lang=\"en\">\r\n <head>\r\n <meta charset=\"utf-8\">\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\r\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\">\r\n <link rel=\"icon\" href=\"<%= BASE_URL %>favicon.ico\">\r\n <title>Pizza Planet</title>\r\n <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\" integrity=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"anonymous\">\r\n </head>\r\n <body>\r\n <noscript>\r\n <strong>We're sorry but pizza-planet doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>\r\n </noscript>\r\n <div id=\"app\"></div>\r\n <!-- built files will be auto injected -->\r\n </body>\r\n </html>\n```\n\ncssでfloatなど試しましたが、横並びにできませんでした。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T22:27:55.287", "favorite_count": 0, "id": "53146", "last_activity_date": "2019-03-04T12:20:02.170", "last_edit_date": "2019-03-04T12:20:02.170", "last_editor_user_id": "76", "owner_user_id": "30614", "post_type": "question", "score": 0, "tags": [ "html", "vue.js", "bootstrap4" ], "title": "nav-itemが横並びにできない", "view_count": 1153 }
[]
53146
null
null
{ "accepted_answer_id": "53152", "answer_count": 1, "body": "プログラム初心者です。 \n現在、以下のような5文字のアルファベットが大量に並んでいるcsvファイルがあって、このcsvファイルから4文字一致する(一文字だけ異なる)ものだけを全て抜き出してアウトプットしたいと考えております。(abaseとabash、abaseとabateが4文字一致するので、こちらをアウトプットしたいです。)\n\nabase \nabash \nabate \nabbey ・・・・\n\ncsvファイルをインポートするところまではできたのですが、4文字一致する(1文字だけ異なる)ところがなかなか分からずにいます。\ncharAt()で二つのデータを比較する(abaseとabash以下全てのデータを一つずつ比較、最後まで行ったら次はabashとabate以下全てのデータを一つずつ比較)という方法論を考えているのでこちらの方向性でよろしいでしょうか?\n\n## 追記\n\n一致するというのは、文字と、その位置が一致することを指しています。例文では、abaseをabashを指していて、両方ともアウトプットできたらと考えております。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T23:33:34.993", "favorite_count": 0, "id": "53147", "last_activity_date": "2019-03-03T03:23:25.060", "last_edit_date": "2019-03-03T03:22:41.007", "last_editor_user_id": "19110", "owner_user_id": "26303", "post_type": "question", "score": 0, "tags": [ "java", "java8" ], "title": "JavaでCSVファイルの読み込みと類似する文字のアウトプットをしたい。", "view_count": 188 }
[ { "body": "**_charAt()で二つのデータを比較する(abaseとabash以下全てのデータを一つずつ比較、最後まで行ったら次はabashとabate以下全てのデータを一つずつ比較)という方法論を考えているのでこちらの方向性でよろしいでしょうか?_**\n\n何を持って「よろしい」とするのかによります。単に所望の回答が出せれば「よろしい」のなら、それで回答は出せるので「よろしい」と言うことになります。\n\n* * *\n\nただ、そのような方法だと時間計算量がO(N*N)のオーダーになる(NはCSV中の単語数…CSV中の「5文字のアルファベット」を便宜上「単語」と呼ぶことにします)ので、単語数が増えた時の計算量が大きくならない方が良いいと言うのであれば、アルゴリズムを工夫すべきでしょう。\n\n例えば **abaseとabash、abaseとabateが4文字一致する**\n等場合、abaseとabashは`abas*`というパターンで一致する、abaseとabateは`aba*e`というパターンで一致する、と考えられます。\n\n少し見方を変えると、`abas*`というパターンにマッチする単語はabaseとabash、`aba*e`というパターンにマッチする単語はabaseとabate、と言えます。\n\n以下のコードはすべてのパターンとそのパターンにマッチする単語をリストアップし、一つのパターンにマッチする単語が2個以上あれば、それを出力する、という方針で書かれています。\n\n```\n\n package wordsmatch;\n \n import java.util.ArrayList;\n import java.util.HashMap;\n import java.util.List;\n import java.util.Map;\n \n /**\n *\n * @author dev\n */\n public class WordsMatch {\n \n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n String[] words = {\n \"abase\",\n \"abash\",\n \"abate\",\n \"abbey\"\n };\n //パターンごとにマッチする単語のListを作る\n Map<String, List<String>> patternToWordsMap = new HashMap<>();\n for( String word: words ) {\n for( String pattern: createPatterns(word) ) {\n if( !patternToWordsMap.containsKey(pattern) ) {\n patternToWordsMap.put(pattern, new ArrayList<>());\n }\n patternToWordsMap.get(pattern).add(word);\n }\n }\n //マッチする単語Listが2つ以上の単語を含む場合、その単語Listを出力する\n patternToWordsMap.entrySet().stream()\n .filter(entry -> entry.getValue().size() >= 2)\n .forEach(entry -> {\n System.out.println(\"(\"+entry.getKey()+\")\"+entry.getValue());\n });\n }\n \n /**\n * 4文字一致するパターンを全て生成する\n * \"abase\"なら、[\"*base\", \"a*ase\", \"ab*se\", \"aba*e\", \"abas*\"]を返す\n * @param word\n * @return \n */\n private static String[] createPatterns(String word) {\n String[] patterns = new String[word.length()];\n for( int i = 0; i < word.length(); ++i ) {\n StringBuilder pattern = new StringBuilder(word);\n pattern.replace(i, i+1, \"*\");\n patterns[i] = pattern.toString();\n }\n return patterns;\n }\n }\n \n```\n\n「csvファイルをインポートするところまでは」ご自身でできたという方なら、そこにつながるようにするのはそれほど難しくないだろうと思います。お試しください。できれば「abaseとabash以下全てのデータを一つずつ比較、最後まで行ったら次はabashとabate以下全てのデータを一つずつ比較」の方針で作られたコードと、単語数を増やした時にどの程度の処理速度差が出るのかも比べてみられると良いでしょう。\n\n* * *\n\n結果の出力の方法などが細かく指定されている場合には、このコードの考え方ではうまく対応できないかもしれません。その場合には、ご質問を修正してどんな条件があるのかを明確にしてください。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T03:03:11.213", "id": "53152", "last_activity_date": "2019-03-03T03:23:25.060", "last_edit_date": "2019-03-03T03:23:25.060", "last_editor_user_id": "19110", "owner_user_id": "13972", "parent_id": "53147", "post_type": "answer", "score": 0 } ]
53147
53152
53152
{ "accepted_answer_id": null, "answer_count": 1, "body": "Javaで実装した、論理演算の吸収律を適用する以下のようなアルゴリズムをPythonに書き直しております。\n\n```\n\n 1 Vector matrix = [ [a], [a, b], [a, c] ];\n 2 for (int i = 0; i < matrix.size(); i++) {\n 3 Vector element_left = matrix.get(i);\n 4\n 5 for (int j = i+1; j < matrix.size(); j++) {\n 6 Vector element_right = matrix.get(j);\n 7\n 8 if (isIncluded(left, right)) {\n 9 // 左辺の要素が右辺の要素が部分集合であれば\n 10 matrix.remove(j);\n 11 j--;\n 12 }\n 13 }\n 14 }\n \n```\n\n10,11行目の「i番目の要素がj番目の部分集合である場合、j番目の要素を削除して、jをデクリメントする処理」をPythonで実装する方法がわかりません。\n\nこの処理をPythonで実現する書き方をご教示いただけないでしょうか。 \n初歩的な質問でお手数おかけいたしますが、どうぞよろしくおねがいします。 \n※ PythonのSet{}を使う方法もあるかと思いますが、可能であれば2次元配列を使用した方法ですと幸甚です。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-02T23:46:14.377", "favorite_count": 0, "id": "53148", "last_activity_date": "2019-03-04T04:13:41.087", "last_edit_date": "2019-03-03T00:59:46.473", "last_editor_user_id": "28758", "owner_user_id": "28758", "post_type": "question", "score": 0, "tags": [ "python", "java", "アルゴリズム" ], "title": "Pythonでの論理演算の吸収律を適用するアルゴリズムの実装について", "view_count": 99 }
[ { "body": "あるリストが別のリストに対して集合として部分集合になっているかどうかは、ご指摘の通り `set` の\n[`set.issubset()`](https://docs.python.org/3.7/library/stdtypes.html#frozenset.issubset)\nを使うと簡単に判定できます。\n\nこれを使いたくない場合、Java の方で `isIncluded()` を実装したのと同じように Python\nでも実装できるはずです。たとえば、部分集合の定義通り、片方の要素が他方に全て含まれているかどうか逐一検査するというやり方です\n(ただし要素の重複を無視するかどうかは決める必要があります)。\n\nリストから要素を削除する方法も Java 同様 `matrix.remove(matrix[i])` を使ったり、あるいは `del matrix[i]`\nを使ったりすることで実現できます。今回はインデックスで削除しているので `del matrix[i]` の方が向いていそうです。\n\n補足:ただし私だったら、ループしながら削除するのではなく、別の新しいリストを用意して、ループしながらそれに append していく方法を選びそうです。in-\nplace ではなくなりますが、インデックス周りのバグが起きにくそうだからです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T04:13:41.087", "id": "53182", "last_activity_date": "2019-03-04T04:13:41.087", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "53148", "post_type": "answer", "score": 1 } ]
53148
null
53182
{ "accepted_answer_id": null, "answer_count": 0, "body": "pc windows10 \nvroid v0.5.0 \nunity 2017.4.15f1 \nUniVRM 0.50\n\nunityにunivrmをインストールし、 \nvroidのvrmデータをunityにインストールしました。 \n[![状態](https://i.stack.imgur.com/wC2eZ.png)](https://i.stack.imgur.com/wC2eZ.png)\n\n画像の状態となり \nmodel rig animationのボタンが表示されません。 \nそうしたら表示できますか。 \n困っています。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T05:00:38.817", "favorite_count": 0, "id": "53154", "last_activity_date": "2019-03-03T05:00:38.817", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32379", "post_type": "question", "score": 0, "tags": [ "unity3d" ], "title": "vroidのunityへのインポート", "view_count": 56 }
[]
53154
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "初心者ですが宜しくおねがいします。\n\nterrainで使うブラシ機能で生やす木、その木をmayaで作り、インポートしました。 \n生やすこと自体はできたのですが、当たり判定について悩んでいます。\n\nカプセルコライダーなら当たり判定は付き、問題ありませんが木の形が少し特殊なのでメッシュコライダーのように密着した当たり判定にしたいのです。 \nしかしメッシュコライダーを使用するとterrain上で生やした木には当たり判定がつきません。(プレハブ上では当たり判定はつきます) \nカプセルコライダーでないといけないのでしょうか??", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T05:57:37.287", "favorite_count": 0, "id": "53155", "last_activity_date": "2019-03-05T09:41:38.637", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32387", "post_type": "question", "score": 1, "tags": [ "unity3d" ], "title": "terrainに生やす木の当たり判定について", "view_count": 345 }
[ { "body": "カプセルコライダーでないといけないわけではないですが、 \nカプセルなど複数のコライダーを上手く配置してそれらしくするのが良いでしょう。\n\n木:幹部分に判定を配置 \n草:通常の判定は行わず、ニーアオートマタみたく走りが解除されるよろめく特殊判定(要自作)を配置するとよいかも?", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T01:36:20.773", "id": "53198", "last_activity_date": "2019-03-05T01:36:20.773", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25396", "parent_id": "53155", "post_type": "answer", "score": 0 } ]
53155
null
53198
{ "accepted_answer_id": null, "answer_count": 2, "body": "プログラミング初心者です。初歩的な質問をしてしまい誠に申し訳ございません。 \nCSVファイルのデータを扱いやすくするために、二次元配列への変換を検討しております。\n\nCSVファイルの構造は以下のとおりです。\n\n```\n\n abase\n abash\n abate\n abbey ・・・・\n \n```\n\n現在、[JavaでCSVファイルの読み込みを行う](https://uxmilk.jp/48018)\nのページを参考に下記コードを書いたところ、アウトプットが以下のように表示されます。\n\n```\n\n import java.io.File;\n import java.io.FileReader;\n import java.io.BufferedReader;\n import java.io.IOException;\n \n class Sample {\n public static void main(String args[]) {\n try {\n File f = new File(\"sample.csv\");\n BufferedReader br = new BufferedReader(new FileReader(f));\n \n String[][] data = new String[2][2];\n String line = br.readLine();\n for (int row = 0; line != null; row++) {\n data[row] = line.split(\",\", 0);\n line = br.readLine();\n }\n br.close();\n \n // CSVから読み込んだ配列の中身を表示\n for(int row = 0; row < data.length; row++) {\n for(int col = 0; col < data.length; col++) {\n System.out.println(data[row][col]);\n }\n } \n \n } catch (IOException e) {\n System.out.println(e);\n }\n }\n }\n \n```\n\n```\n\n nul\n nul\n nul\n nul\n \n```\n\n列が一列しかない場合は二次元配列への変換がそもそもできないという認識でよろしいでしょうか。また、何か他の代替案等ございましたらご教示いただけますと幸いです。\n\nどうぞよろしくお願いいたします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T06:00:05.247", "favorite_count": 0, "id": "53156", "last_activity_date": "2019-03-03T19:12:26.333", "last_edit_date": "2019-03-03T07:21:56.950", "last_editor_user_id": "26303", "owner_user_id": "26303", "post_type": "question", "score": 1, "tags": [ "java" ], "title": "1列×数千行のCSVファイルを二次元配列に変換するには", "view_count": 1098 }
[ { "body": "```\n\n data[row] = line.split(\",\", 0);\n \n```\n\nのところに問題があるのだと思います。\n\nsplitメソッドは文字列を区切り文字(上記のコードではカンマ)で区切って複数の文字列に分割するものです。 \nそして、splitメソッドの第2引数は、返す分割後文字列の数を指定するものです。 \nそれが、0なので、一つも文字列を返さないという意味になって、nul (空文字列)が返されているのでしょう。\n\n```\n\n data[row] = line.split(\",\");\n \n```\n\nに変更してみてください。\n\n== \n補足(おせっかい) \n== \nCSVは、\"comma-separated values\" (カンマで区切った[複数の]値)、もしくは\"comma-separated vector\"\n(カンマで区切った値の列)の略語で、普通はCSVファイルの各行にはカンマが含まれています。\n\nしかし、質問のデータは各行にカンマを含まない文字列があるだけです。 \nだから、その文字列(\"abase\"など)をカンマで区切るのは無意味です。\n\n1行読みだしたら、それを配列の要素に代入する、というのを繰り返すだけでCSVファイルの内容を、配列dataに入れることができますよ。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T07:57:02.683", "id": "53161", "last_activity_date": "2019-03-03T07:57:02.683", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "53156", "post_type": "answer", "score": 2 }, { "body": "「数千行」のファイルならば、`String[][] data = new String[2][2];` の変数宣言はダメでしょう。 \nさらに、おそらく行数は固定では無いでしょうから、ArrayListに格納する方が良いのでは?\n\n以下のような手順で処理すれば良いと思われます。 \n元のテキストデータの、連続する奇数行目と偶数行目でペアとして扱うことを想定しています。\n\n 1. 可変行数のテキストファイルの読み込みは、例えばこの記事の内容をサブルーチンとして呼び出す。 \n[テキストファイルからArrayListを作る(30分)](http://www.coderesume.com/modules/answer/?quiz=j02500)\n\n``` ArrayList<String> textLines = new ArrayList<String>();\n\n boolean result = false;\n result = readTextFileLines(\"sample.csv\", textLines);\n \n```\n\n 2. 上記結果が奇数行だった場合に、ArrayListに無効なデータを示す空文字列か何かを1つ追加しておく。\n``` if (textLines.size() % 2 == 1) {\n\n textLines.add(\"\");\n }\n \n```\n\n 3. ArrayListのsize()を使って2次元配列を宣言する。\n``` int rowcount = textLines.size() / 2;\n\n String[][] data = new String[rowcount][2];\n \n```\n\n 4. 2次元配列にArrayListからデータをコピーしていく。\n``` for(int row = 0; row < rowcount; row++) {\n\n data[row][0] = textLines.get(row * 2);\n data[row][1] = textLines.get(row * 2 + 1);\n }\n \n```\n\n 5. 作成した2次元配列データを表示するなり、ハミング距離を調べるなり、何らかの処理を行う。\n\n元のテキストデータを、どのように2次元配列に配置するか、の想定が変われば、2. 3. 4. の処理がそれに合わせて変わることになります。\n\n* * *\n```\n\n import java.io.BufferedReader;\n import java.io.FileNotFoundException;\n import java.io.FileReader;\n import java.io.IOException;\n import java.util.ArrayList;\n \n class Sample {\n \n public static void main(String args[]) {\n try {\n ArrayList<String> textLines = new ArrayList<String>();\n boolean result = false;\n result = readTextFileLines(\"sample.csv\", textLines);\n if (result == false) {\n return;\n }\n if (textLines.size() % 2 == 1) {\n textLines.add(\"\");\n }\n int rowcount = textLines.size() / 2;\n String[][] data = new String[rowcount][2];\n for(int row = 0; row < rowcount; row++) {\n data[row][0] = textLines.get(row * 2);\n data[row][1] = textLines.get(row * 2 + 1);\n }\n for(int row = 0; row < data.length; row++) {\n for(int col = 0; col < data.length; col++) {\n System.out.println(data[row][col]);\n }\n }\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n \n public static boolean readTextFileLines( String filePath, ArrayList<String> textLines )\n {\n boolean result = false;\n FileReader fr = null;\n BufferedReader br = null;\n try\n {\n fr = new FileReader( filePath );\n br = new BufferedReader( fr );\n String line = br.readLine();\n while( line != null )\n {\n textLines.add( line );\n line = br.readLine();\n }\n result = true;\n }\n catch( FileNotFoundException e )\n {\n System.out.println( e );\n }\n catch( IOException e )\n {\n System.out.println( e );\n }\n finally\n {\n try\n {\n if( br != null ) {\n br.close();\n }\n else if( fr != null ) {\n fr.close();\n }\n }\n catch( IOException e )\n {\n System.out.println(e);\n }\n }\n return result;\n }\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T09:29:25.197", "id": "53165", "last_activity_date": "2019-03-03T19:12:26.333", "last_edit_date": "2019-03-03T19:12:26.333", "last_editor_user_id": "26370", "owner_user_id": "26370", "parent_id": "53156", "post_type": "answer", "score": 1 } ]
53156
null
53161
{ "accepted_answer_id": null, "answer_count": 1, "body": "GCP上にWordPressを使って、ブログを運営しています。ロードバランサーを使って、負荷分散をして行きたいですのですが、設定方法でつまづいています。ウェブでもなかなかよい説明ブログなどが見つかりません。よくまとまっているサイトなどがあれば教えてください。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T06:17:09.507", "favorite_count": 0, "id": "53158", "last_activity_date": "2019-04-21T17:31:29.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32386", "post_type": "question", "score": 0, "tags": [ "google-cloud" ], "title": "ロードバランサーの設定方法", "view_count": 46 }
[ { "body": "GCP使っているのであればkubernetesを使ってみてはいかがでしょうか? \nをwordpressであれば \n参考資料 \n<https://github.com/utshav2008/k8wordpressmysqlcluster>\n\n<https://qiita.com/taketora/items/024049272abc47abe3b4>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-04-21T17:31:29.557", "id": "54372", "last_activity_date": "2019-04-21T17:31:29.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19329", "parent_id": "53158", "post_type": "answer", "score": 0 } ]
53158
null
54372
{ "accepted_answer_id": null, "answer_count": 1, "body": "書籍\"Electronではじめるアプリ開発\"のchapter4の始めで詰まってしまいました。 \n(5)表示される画像に(4)で書いているHello, Electron and React JSXが表示されることを期待しているのですが、なぜ出ないか? \nどなたか教えてくださいませんか。\n\n(1)entryのindex.js\n\n```\n\n import { app } from \"electron\";\n import createMainWindow from \"./createMainWindow\";\n \n let mainWindow = null;\n \n app.on(\"ready\", () => {\n mainWindow = createMainWindow();\n });\n \n app.on(\"window-all-closed\", () => {\n if (process.platform !== \"darwin\"){\n app.quit();\n }\n });\n \n app.on(\"activate\", (_e, hasVisibleWindows) =>{\n if (!hasVisibleWindows){\n mainWindow = createMainWindow();\n }\n });\n \n```\n\n(2)createMainWindow.js\n\n```\n\n import { BrowserWindow } from \"electron\";\n \n class MainWindow{\n constructor(){\n this.windows = new BrowserWindow({ width: 800, height: 600 });\n this.windows.loadURL('file://${__dirname}/../../index.html');\n this.windows.on(\"closed\", ()=>{\n this.windows = null;\n });\n }\n }\n \n function createMainWindow(){\n return new MainWindow();\n }\n \n export default createMainWindow;\n \n```\n\n(3)loadするhtml\n\n```\n\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"UTF-8\">\n <title>Markdown Editor</title>\n <link rel=\"stylesheet\" href=\"node_modules/photon/dist/css/photon.css\">\n <style type=\"text/css\">\n #app {\n position: absolute;\n top: 8px;\n bottom: 8px;\n left: 8px;\n right: 8px;\n }\n </style>\n </head>\n <body>\n <div class=\"window\">\n <div id=\"app\" class=\"window-content\"></div>\n </div>\n <script>require(\"./dist/renderer/app.js\")</script>\n </body>\n </html>\n \n```\n\n(4)app.jsx\n\n```\n\n import React from \"react\";\n import { render } from \"react-dom\"\n \n render(<div>Hello, Electron and React JSX</div>, document.getElementById(\"app\"));\n \n```\n\n(5)表示される画像 \n[![表示される画面](https://i.stack.imgur.com/gFE5t.png)](https://i.stack.imgur.com/gFE5t.png)", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T07:28:20.190", "favorite_count": 0, "id": "53159", "last_activity_date": "2021-03-17T16:14:50.957", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32388", "post_type": "question", "score": 0, "tags": [ "reactjs", "electron" ], "title": "Reactのrenderで何も表示されない", "view_count": 1872 }
[ { "body": "以下の記述のシングルクォートをバッククォートにしないと動かないかと思います!\n\n>\n```\n\n> 'file://${__dirname}/../../index.html'\n> \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2021-03-17T08:24:11.200", "id": "74716", "last_activity_date": "2021-03-17T16:14:50.957", "last_edit_date": "2021-03-17T16:14:50.957", "last_editor_user_id": "3060", "owner_user_id": "44376", "parent_id": "53159", "post_type": "answer", "score": 1 } ]
53159
null
74716
{ "accepted_answer_id": "53163", "answer_count": 1, "body": "REST APIで提供されているサービスを用いて、Pythonの配列へデータを取得したいと考えています。\n\n対象のAPIは、URLの最後の文字列を変更することによって取得できるデータが変わるため、一度に取得できるように、配列とif文を用いてみました。 \nしかし「AttributeError: 'list' object attribute 'append' is read-\nonly」というエラーメッセージが出てしまう状態です。\n\napi_dataが読み込み専用だといわれているのは分かるのですが、これに対しどう対処すべきかが判断できず、以下のソースについて、ご助言をいただけますと幸いです。\n\n```\n\n import requests\n \n # api info\n url = 'https://hogehoge.com/'\n endpoint = 'api/'\n moji = [\n 'abcdefg',\n 'none',\n 'hijklmn',\n 'opqrstu',\n 'vwxyz' \n ]\n \n \n # 配列「moji」のデータ数だけループしてデータ取得(0からカウント)\n api_data = []\n for count in range(0,len(moji)):\n \n if moji[count] == 'none':\n api_data.append= ('none')\n else:\n api_data.append = requests.get(url + endpoint + moji[count])\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T07:42:28.330", "favorite_count": 0, "id": "53160", "last_activity_date": "2019-03-03T08:28:27.457", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32389", "post_type": "question", "score": 0, "tags": [ "python", "array" ], "title": "Pythonでの配列とif文についてです。", "view_count": 473 }
[ { "body": "`append` はメソッドなので、代入するものでは無いです。 \nあと、`requests.get()` は結果の `text` を格納するのでは? \n以下のようにしてみてください。\n\n```\n\n if moji[count] == 'none':\n api_data.append('none')\n else:\n api_data.append(requests.get(url + endpoint + moji[count]).text)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T08:28:27.457", "id": "53163", "last_activity_date": "2019-03-03T08:28:27.457", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26370", "parent_id": "53160", "post_type": "answer", "score": 0 } ]
53160
53163
53163
{ "accepted_answer_id": "53164", "answer_count": 1, "body": "[行っているアプリケーション](https://github.com/SpiderLabs/social_mapper) \n最後のpythonを実行したのですが、できません。どうすればできるようになりますか?(myhomeに写真が入っています。)\n\n```\n\n python social_mapper.py -f imagefolder -i /lan/social_mapper/myhome -m fast\n -fb\n >Traceback (most recent call last):\n File \"social_mapper.py\", line 931, in <module>\n for filename in os.listdir(args.input):\n OSError: [Errno 2] No such file or directory: '/lan/social_mapper/myhome/'\n \n```", "comment_count": 7, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T08:10:55.473", "favorite_count": 0, "id": "53162", "last_activity_date": "2019-03-03T11:02:51.327", "last_edit_date": "2019-03-03T11:02:51.327", "last_editor_user_id": "19110", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "python", "ubuntu", "wsl" ], "title": "エラーが出てできません: OSError: [Errno 2] No such file or directory", "view_count": 3232 }
[ { "body": "> `OSError: [Errno 2] No such file or directory: '/lan/social_mapper/myhome/'`\n\nこれは、 `'/lan/social_mapper/myhome/'` というディレクトリが存在しないというエラーです。\n\n> myhomeに写真が入っています。\n\nとのことですが、[これまでの質問](https://ja.stackoverflow.com/questions/53138/https-github-\ncom-spiderlabs-social-\nmapper-%E3%81%A7%E3%82%A8%E3%83%A9%E3%83%BC)を確認するにWindows Subsystems for\nLinuxをお使いのようなので、おそらくWindowsではそのようなディレクトリがあるものの、Linux内部の環境では存在ないか、認識出来ていないではないでしょうか。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T09:11:07.337", "id": "53164", "last_activity_date": "2019-03-03T09:11:07.337", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29826", "parent_id": "53162", "post_type": "answer", "score": 1 } ]
53162
53164
53164
{ "accepted_answer_id": "53167", "answer_count": 1, "body": "環境はubuntuです。tar.gzファイルを解凍したいのですが、できません。 \n以下のように試しましたが、だめでした。(ファイル名はgeckodriver-v0.24.0-linux64.tar.gz) \n① \ntar xvzf geckodriver-v0.24.0-linux64.tar.gz \n>gzip: stdin: not in gzip format \ntar: Child returned status 1 \ntar: Error is not recoverable: exiting now\n\n② \ntar -xfz geckodriver-v0.24.0-linux64.tar.gz\n\n> tar: z: Cannot open: No such file or directory \n> tar: Error is not recoverable: exiting now\n\n③ \nfile geckodriver-v0.24.0-linux64.tar.gz\n\n> geckodriver-v0.24.0-linux64.tar.gz: HTML document, ASCII text, with very\n> long lines, with no line terminators", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T09:39:57.607", "favorite_count": 0, "id": "53166", "last_activity_date": "2019-03-03T11:04:17.370", "last_edit_date": "2019-03-03T11:04:17.370", "last_editor_user_id": "19110", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "linux", "ubuntu", "tar" ], "title": "tar.gzファイルが解凍できません。", "view_count": 16680 }
[ { "body": "エラーメッセージに出ている通り、ファイルがgz形式でないのが原因です。何らかの理由でダウンロード(保存)に失敗していると思われるので、再ダウンロードしてみてください。\n\n**エラーメッセージ**\n\n> tar xvzf geckodriver-v0.24.0-linux64.tar.gz \n> gzip: stdin: **not in gzip format**\n\n→ \"ファイルがgzip形式では無い\"\n\n> file geckodriver-v0.24.0-linux64.tar.gz \n> geckodriver-v0.24.0-linux64.tar.gz: **HTML document, ASCII text** , with\n> very long lines, with no line terminators\n\n→ \"ファイルは(恐らく)HTMLファイルでテキストファイルだ\"\n\n<https://github.com/mozilla/geckodriver/releases/tag/v0.24.0> \n<https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz>\n\n* * *\n\nエラーメッセージは非常に重要です。英語で表示されていてもまずは機械翻訳で構わないので自分で読み解く習慣を付けることをおすすめします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T09:51:04.103", "id": "53167", "last_activity_date": "2019-03-03T09:59:34.803", "last_edit_date": "2019-03-03T09:59:34.803", "last_editor_user_id": "3060", "owner_user_id": "3060", "parent_id": "53166", "post_type": "answer", "score": 4 } ]
53166
53167
53167
{ "accepted_answer_id": "53170", "answer_count": 1, "body": "Vecをthreadで利用するコードを書いた所 \ncannot borrow as mutableとエラーが出ました。 \nエラーコード(E0596)にはmutが必要と書いてありますがmutはつけています。 \nどの様にすればエラーが取れますでしょうか?\n\n```\n\n use std::vec::Vec;\n use std::sync::Arc;\n use std::{thread,time};\n \n fn main() {\n let arc: Arc<Vec<i32>> = Arc::new(Vec::new());\n \n let mut _arc = Arc::clone(&arc);\n thread::spawn(move || {\n for x in 1..=10 {\n _arc.push(x);\n }\n });\n \n thread::sleep(time::Duration::from_secs(3));\n arc.iter().map(|n| println!(\"{:?}\",n));\n }\n \n```\n\n```\n\n error[E0596]: cannot borrow data in a `&` reference as mutable\n --> src/main.rs:11:13\n |\n 11 | _arc.push(x);\n | ^^^^ cannot borrow as mutable\n \n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T10:54:33.963", "favorite_count": 0, "id": "53168", "last_activity_date": "2019-03-03T11:48:47.283", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32285", "post_type": "question", "score": 2, "tags": [ "rust" ], "title": "ArcとVecのmutableエラー'cannot borrow as mutable'について", "view_count": 1577 }
[ { "body": "`Arc`で包んだデータは不変の参照としてしかアクセスできません。データを可変にするには、`Arc`で包む前に内部可変性を提供するコンテナで包んでおく必要があります。複数スレッドからのアクセスに対応しているのは`RwLock`や`Mutex`などです。`RwLock`を使うと以下のようになります。\n\n```\n\n use std::sync::{Arc, RwLock};\n use std::vec::Vec;\n use std::{thread, time};\n \n fn main() {\n let arc = Arc::new(RwLock::new(Vec::new())); // Arc<RwLock<Vec<i32>>>型\n \n let arc2 = Arc::clone(&arc);\n thread::spawn(move || {\n for x in 1..=10 {\n if let Ok(mut v) = arc2.write() {\n v.push(x);\n }\n }\n });\n \n thread::sleep(time::Duration::from_secs(3));\n if let Ok(v) = arc.read() {\n v.iter().for_each(|n| println!(\"{:?}\", n));\n };\n }\n \n```\n\n内部可変性についてはこちらのドキュメントが参考になると思います。 \n<https://doc.rust-jp.rs/book/second-edition/ch15-05-interior-mutability.html>\n\nまた手前味噌ですが、以前このような記事も書きましたので、よかったら参考にしてください。 \n<https://qiita.com/tatsuya6502/items/bed3702517b36afbdbca>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T11:48:47.283", "id": "53170", "last_activity_date": "2019-03-03T11:48:47.283", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "14101", "parent_id": "53168", "post_type": "answer", "score": 3 } ]
53168
53170
53170
{ "accepted_answer_id": "53173", "answer_count": 1, "body": "APIで取得した辞書型リストproduct_info[0]からproduct_info[6]のデータについて、それぞれproductとvolumeを表示させたいのですが、その表示がうまくいかずに悩んでいます。 \n辞書型リストにおけるprintでの指定の仕方はどのようにすればいいのでしょうか。\n\n```\n\n # ※product_infoの中身はAPIで取得した内容をそのまま転記しております。\n product_info=[]\n product_info=[\n '{\"product\":\"hogeA\",\"id\":54,\"volume\":240}', \n '{\"product\":\"hogeB\",\"id\":85,\"volume\":332}', \n '{\"product\":\"hogeC\",\"id\":102,\"volume\":1023}',\n 'none',\n 'none',\n 'none',\n 'none'\n ]\n \n for count in range(0,len(product_info)):\n if product_info[count] == 'none':\n print('売り切れ')\n else:\n print(product_info[count]['product','volume'])\n \n```", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T12:48:51.863", "favorite_count": 0, "id": "53171", "last_activity_date": "2019-03-03T14:18:16.037", "last_edit_date": "2019-03-03T14:14:16.483", "last_editor_user_id": "32389", "owner_user_id": "32389", "post_type": "question", "score": 0, "tags": [ "python", "array" ], "title": "Pythonにおける辞書型リストの呼び出し方についてです。", "view_count": 83 }
[ { "body": "> 格納されたデータはAPIで取得\n\nというところから、これは辞書型ではなくJSONデータのように見えます。このため、一旦JSONとしてパースすると良さそうです。\n\n```\n\n import json\n \n # ...\n \n for product in product_info:\n if product == 'none':\n print('売り切れ')\n else:\n product_info = json.loads(product)\n print(product_info['product'], product_info['volume'])\n \n```\n\n※ `in` 記法を利用し、不要な`count` 変数を削減しました", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T14:18:16.037", "id": "53173", "last_activity_date": "2019-03-03T14:18:16.037", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29826", "parent_id": "53171", "post_type": "answer", "score": 1 } ]
53171
53173
53173
{ "accepted_answer_id": "53178", "answer_count": 1, "body": "テストケースが通りません。 \n入力結果を何個か確認したところあってそうなのですがどこがテストケースにひかかっているか不明です。 \n解説いただければ幸いです。\n\n▼問題文 \n正整数 \nA,Bが与えられます。\n\nAも Bも割り切る正整数のうち、N番目に大きいものを求めてください。\n\nなお、与えられる入力では、 \nAも Bも割り切る正整数のうち N番目に大きいものが存在することが保証されます。\n\n制約 \n入力は全て整数である。 \n1≤A,B≤100 \nAも Bも割り切る正整数のうち、K番目に大きいものが存在する。 \nN≥1\n\n▼コード\n\n```\n\n import java.util.ArrayList;\n import java.util.Scanner;\n \n public class Main {\n public static void main(String args[]) {\n Scanner scn = new Scanner(System.in);\n int a = scn.nextInt();\n int b = scn.nextInt();\n int n = scn.nextInt();\n \n ArrayList<Integer> list = new ArrayList<>();\n \n int i = 1;\n do {\n if (a % i == 0 && b % i == 0) {\n list.add(i);\n }\n i++;\n } while (i < a);\n \n System.out.println(list.get((list.size()-n)));\n }\n }\n \n```\n\n\\-- \n引用 \nABC 120 B - K-th Common Divisor \n<https://atcoder.jp/contests/abc120/tasks/abc120_b>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T18:29:31.040", "favorite_count": 0, "id": "53176", "last_activity_date": "2019-03-04T14:44:55.957", "last_edit_date": "2019-03-04T14:44:55.957", "last_editor_user_id": "32396", "owner_user_id": "32396", "post_type": "question", "score": 1, "tags": [ "java", "アルゴリズム" ], "title": "テストケースに通らない理由がわかりません。", "view_count": 408 }
[ { "body": "ざっと見て、一番怪しそうなのは\n\n```\n\n } while (i < a);\n \n```\n\nのところです。例えば`a=6, b=12`のとき、6も両方の数を割り切る正整数ですが、この条件式だと除外されてしまいます。\n\n`i <= a`としてみたらどうでしょうか。\n\n* * *\n\nちなみに`do while`ではなく`for`を使った方が分かりやすいと思います。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-03T23:49:16.780", "id": "53178", "last_activity_date": "2019-03-03T23:49:16.780", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3605", "parent_id": "53176", "post_type": "answer", "score": 5 } ]
53176
53178
53178
{ "accepted_answer_id": "53180", "answer_count": 1, "body": "たとえば、 mysqldump を実行するとき、 `-p` オプションを指定すると、パスワードを標準入力からクエリするような動作になります。\n\nこの、最初の処理が始まる前のクエリはフォアグラウンドだが、その後の本処理がスタートした後はバックグラウンドで実行したいような場面は、いくつか他にもあると思っています。\n\n### 質問\n\n * bash において、フォアグラウンドで実行したジョブを、途中からバックグラウンドに移行させることはできますか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T03:01:13.920", "favorite_count": 0, "id": "53179", "last_activity_date": "2019-03-04T03:26:23.727", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "754", "post_type": "question", "score": 2, "tags": [ "bash" ], "title": "bash でフォアグラウンドで実行したジョブをバックグラウンドに移行させることはできますか?", "view_count": 151 }
[ { "body": "`ctrl`+`z`で停止したジョブを`bg`コマンドでバックグラウンドにできます。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T03:26:23.727", "id": "53180", "last_activity_date": "2019-03-04T03:26:23.727", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25936", "parent_id": "53179", "post_type": "answer", "score": 4 } ]
53179
53180
53180
{ "accepted_answer_id": null, "answer_count": 0, "body": "■課題 \nexcelブックを開くタイミングで、作業グループを自動解除する方法を探してます。 \n対象は1つのブックだけではなく、とある数台のPCで開くブックを全て対象にしたいと考えます。 \n(環境=win7+Excel2010、Win10+excel2016、2つ利用)\n\n■理由 \n作業グループに気づかずに編集すると、意図しない変更が発生し、これを回避したいと考えます。\n\n■当方の試行錯誤 \n個人用マクロブック(PERSONAL.XLSB)に次のようなマクロを入れてみました。\n\n```\n\n Sub auto_open()\n If ActiveWindow.SelectedSheets.Count > 1 Then\n MsgBox \"作業グループを解除します\"\n ActiveWindow.SelectedSheets(1).Select\n End If\n End Sub\n \n```\n\n単なるブック(Book1.xlsmなど)にマクロを入れると、動作したのですが、 \n個人用マクロブック(PERSONAL.XLSB)にマクロを入れると、エラーになりました。 \ntypename(ActiveWindow)=\"Nothing\"となっていることが原因だと考えます。\n\n少し直せば、解決するでしょうか? 別の方法で解決するでしょうか?\n\n以上、 \n本課題の解決方法ご存知の方いらっしゃいましたら、ご教授よろしくお願いします。\n\n* * *\n\n**コメントより追記**\n\n * エラーは以下です。 \n「実行時エラー'91':オブジェクト変数またはWithブロック変数が設定されていません。」\n\n * エラーを確認した環境は、win7+excel2010でした。\n * `ActiveWorkbook.Worksheets(1).Select`も上と同じエラーでした。\n * `typename(ActiveWorkbook)`も\"Nothing\"でした。 \n`ActiveWindow`も`ActiveWorkbook`も\"Nothing\"という状況なので、 \n個人用マクロブック(PERSONAL.XLSB)のauto_openのタイミングでは、 \n`ActiveWindow`も`ActiveWorkbook`も定まっていない様子です", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T04:05:02.180", "favorite_count": 0, "id": "53181", "last_activity_date": "2019-03-05T02:19:29.397", "last_edit_date": "2019-03-05T02:19:29.397", "last_editor_user_id": "7676", "owner_user_id": "31158", "post_type": "question", "score": 0, "tags": [ "vba", "excel" ], "title": "excel vba、開いたブック内の作業グループを自動解除したい", "view_count": 1954 }
[]
53181
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "**環境** \nWindows 10 Pro \nVagrant 2.2.4 \nVirtualBox 6.0.4 r128413 (Qt5.6.2) \nbox: laravel/homestead (virtualbox, 7.1.0) \nVagrantのプラグイン: vagrant-hostmanager(1.8.9 global) \nHyper-Vインストール済み\n\n### 行ったこと\n\n * VirtualBoxのバージョンを6に上げた\n * Vagrantを最新版にした\n * Hyper-Vをインストールした\n\nVirtualBoxがバージョン6からHper-\nVと共存できるようになったとのことでVirtualBoxとVagrantのバージョンを最新版に上げてHyper-\nVをインストールしたらSSHの部分でタイムアウトするようになりました。VirtualBoxで見ようにも起動しても画面が見れず、閉じようとすると停止中から進みません。\n\n調べてみるとSSHの鍵があっていない?とのことなのですがVagrantでうまく起動させられない状態で、その上homesteadは通常のVagrantfileと書き方が違うようなのでどのようにすればいいか教えていただきたいです。\n\nログは以下の通りです。\n\n```\n\n Bringing machine 'homestead-7' up with 'virtualbox' provider...\n ==> homestead-7: Importing base box 'laravel/homestead'...\n ==> homestead-7: Matching MAC address for NAT networking...\n ==> homestead-7: Checking if box 'laravel/homestead' version '7.1.0' is up to date...\n ==> homestead-7: Setting the name of the VM: homestead-7\n ==> homestead-7: Clearing any previously set network interfaces...\n ==> homestead-7: Preparing network interfaces based on configuration...\n homestead-7: Adapter 1: nat\n homestead-7: Adapter 2: hostonly\n ==> homestead-7: Forwarding ports...\n homestead-7: 80 (guest) => 8000 (host) (adapter 1)\n homestead-7: 443 (guest) => 44300 (host) (adapter 1)\n homestead-7: 3306 (guest) => 33060 (host) (adapter 1)\n homestead-7: 4040 (guest) => 4040 (host) (adapter 1)\n homestead-7: 5432 (guest) => 54320 (host) (adapter 1)\n homestead-7: 8025 (guest) => 8025 (host) (adapter 1)\n homestead-7: 27017 (guest) => 27017 (host) (adapter 1)\n homestead-7: 22 (guest) => 2222 (host) (adapter 1)\n ==> homestead-7: Running 'pre-boot' VM customizations...\n ==> homestead-7: Booting VM...\n ==> homestead-7: Waiting for machine to boot. This may take a few minutes...\n homestead-7: SSH address: 127.0.0.1:2222\n homestead-7: SSH username: vagrant\n homestead-7: SSH auth method: private key\n Timed out while waiting for the machine to boot. This means that\n Vagrant was unable to communicate with the guest machine within\n the configured (\"config.vm.boot_timeout\" value) time period.\n \n If you look above, you should be able to see the error(s) that\n Vagrant had when attempting to connect to the machine. These errors\n are usually good hints as to what may be wrong.\n \n If you're using a custom box, make sure that networking is properly\n working and you're able to connect to the machine. It is a common\n problem that networking isn't setup properly in these boxes.\n Verify that authentication configurations are also setup properly,\n as well.\n \n If the box appears to be booting properly, you may want to increase\n the timeout (\"config.vm.boot_timeout\") value.\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T04:28:48.450", "favorite_count": 0, "id": "53183", "last_activity_date": "2022-01-12T00:16:38.233", "last_edit_date": "2022-01-12T00:16:38.233", "last_editor_user_id": "3060", "owner_user_id": "29433", "post_type": "question", "score": 0, "tags": [ "ubuntu", "vagrant", "wsl" ], "title": "VagrantのSSH鍵が合わなくなったようなのでSSHで中に入らない方法で修正したい", "view_count": 1131 }
[ { "body": "結論から言いますとHype-Vがやはり関係していたようです。\n\nHyper-Vをアンインストールして再起動してみたらタイムアウトせず問題なく起動しました。 \n何がエラーになっていたかまではどのログを見るべきかもわからなかったのでわかりませんでした。 \nHyper-Vと共存できるようなことを見た気がしましたがまだ完全ではないのかもしれません。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T08:28:05.180", "id": "53191", "last_activity_date": "2019-03-04T08:28:05.180", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "29433", "parent_id": "53183", "post_type": "answer", "score": 1 } ]
53183
null
53191
{ "accepted_answer_id": null, "answer_count": 2, "body": "Githubのみでローカルフォルダをアップロードしたい (GitやFTPソフトを利用せず)\n\nファイルはアップロードできるのですが、\n\nフォルダを作って、そこにフォルダやファイルをアップロードしたい\n\nどうぞよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T04:52:46.543", "favorite_count": 0, "id": "53184", "last_activity_date": "2019-03-04T05:01:12.890", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32402", "post_type": "question", "score": 1, "tags": [ "github" ], "title": "Githubのみでローカルフォルダをアップロードしたい (Git利用せず)", "view_count": 2080 }
[ { "body": "[英語版スタックオーバーフローにおける同様の質問](https://stackoverflow.com/questions/18773598/creating-\nfolders-inside-github-com-repo-without-using-git)が参考になります。\n\nファイルを作るインターフェースで`/`(スラッシュ)をファイル名に用いることで、そのファイルを新しいフォルダの中に作ることができます。リンク先は英語ですが、動画があるのでやり方が分かるかと思います。\n\n注意点としては、この方法だとフォルダを作ると同時にその中にファイルができるということです。gitでは空のフォルダは扱われないためこれは避けられない制約です。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T04:59:50.343", "id": "53185", "last_activity_date": "2019-03-04T04:59:50.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30079", "parent_id": "53184", "post_type": "answer", "score": 2 }, { "body": "空のフォルダのみを作成する方法は無いみたいなので、ダミーでも構わないので空のファイルを以下の手順で作成してみてください。 \nリポジトリのトップ画面にある`Create new\nfile`で新規ファイルの作成画面に移るので、ファイル名の入力欄に`/`で区切れば自動でフォルダが作成されるようです。\n\n参考: \n[Creating new folders in GitHub repository via the\nbrowser](https://github.com/KirstieJane/STEMMRoleModels/wiki/Creating-new-\nfolders-in-GitHub-repository-via-the-browser)\n\n![](https://camo.githubusercontent.com/29f2fd0f075716239c61d9cd7dd58c5b02ca297a/687474703a2f2f692e737461636b2e696d6775722e636f6d2f3949666d6a2e676966)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T05:01:12.890", "id": "53186", "last_activity_date": "2019-03-04T05:01:12.890", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "53184", "post_type": "answer", "score": 4 } ]
53184
null
53186
{ "accepted_answer_id": null, "answer_count": 1, "body": "お世話になります。\n\n自分は元Javaソフトの保守をやっていました。 \n現在、Ruby on Rails を使って、開発に取り組んでおります。\n\nメソッド引数において、ハッシュを用いた可変長的なオプションの指定が、Ruby on Railsの特徴と思っていますが、 \nオプションで指定できるもの(指定を想定されているもの)の一覧を表示することは可能でしょうか。 \nリファレンスなどから、読み解くしか無いでしょうか。\n\n調査時間短縮のため、ご教示くださいますと幸いです。\n\n## 補足(経緯)\n\n現状解決している悩みですが、上記の相談に至った経緯はざっくり以下のような感じです。\n\n * 現状動いているDBに、commentを含むカラム追加が必要になった。\n * 新たにmigrationファイルを出力した。(rails g migration AddTo~~を使って)\n * add_column というメソッドが生成されたが、commentの追加方法がわからない。\n * ネット上で検索をしてみたが、先人の知恵が見つからない。\n * ソースコードをざっくり見てみたところ、comment を含む定義が見つかった。\n * ただ、明確な指定方法がわからなかった。\n * 末尾に comment: \"***\" を単純に追加したところ、migrationで反映された。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T07:14:48.197", "favorite_count": 0, "id": "53188", "last_activity_date": "2019-04-20T05:12:03.667", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": 3, "tags": [ "ruby-on-rails", "ruby" ], "title": "Ruby (Rails) における、使用可能なオプションの調査方法について", "view_count": 118 }
[ { "body": "rails における、 api ドキュメントのオフィシャルっぽいものは、以下のサイトから参照できます。\n\n> <https://api.rubyonrails.org/>\n\n今回の、 `add_column` については、上から検索していくと、次のページが発見され、そこから、 `comment`\nオプションの説明についても、参照できたかな、と思っています。\n\n<https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-\ni-add_column>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-04-20T05:12:03.667", "id": "54332", "last_activity_date": "2019-04-20T05:12:03.667", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "754", "parent_id": "53188", "post_type": "answer", "score": 1 } ]
53188
null
54332
{ "accepted_answer_id": "53239", "answer_count": 1, "body": "PCはWindowsです。ubuntuの環境が欲しくて、USBにubuntuのisoファイルを入れました。そのあとに、再起動してubuntuをスタートさせようとしたら以下のようにエラーが出ます。 \n[![このようにエラーが出ます。](https://i.stack.imgur.com/vpZeP.jpg)](https://i.stack.imgur.com/vpZeP.jpg) \nエラーの詳細は下の2文です。 \n(initramfs) Unable to find a medium containing a live file system \n[figure ex.) 135.392108] usb 3-4: device descriptor ewad/all, error -110\n\nいろいろ試したのですが、だめでした。(BIOSなどをいじったのですがだめでした。) \nやりたいことはUbuntuをUSBにいれて持ち運べるようにしたいです。ただし、入っているWindowsは何も壊さないようにしたいです。 \nUSB ドライブ側とソケット側の 2.0/3.0の意味は分かりません。 \n使っているのはUSBはUSB3.0です。 \nUbuntuのバージョンは18.04.2。iso.ファイルはUniversal-USB-installerで入れました。 \nBIOS画面の、BOOTでUEFIとLEGACYモードを両方試したのですが、だめでした。 \nダウンロード先は[ダウンロードのふぁいる](http://cdimage.ubuntulinux.jp/releases/18.10/ubuntu-\nja-18.10-desktop-amd64.iso)このUbuntu Japanese\nTeamのところです。[ダウンロードのホームページ](https://www.ubuntulinux.jp/download/ja-\nremix)64ビットの18.10です。 \nmd5sumはb36979d580c4a95979cdf19bce609513 です。", "comment_count": 9, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T07:25:13.357", "favorite_count": 0, "id": "53189", "last_activity_date": "2019-03-06T15:40:42.277", "last_edit_date": "2019-03-06T15:40:42.277", "last_editor_user_id": "3060", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "ubuntu" ], "title": "USBからUbuntuが起動できない", "view_count": 2182 }
[ { "body": "お使いの機器では Ubuntu の USB 起動メディア(sdc)が、USB 3.0 のポートを使用して起動すると、起動の途中で I/O\nエラーが発生しておりシステムが起動できない状態のようです。\n\n```\n\n blk_update_request: I/O error, dev sdc, sector 30218839\n Buffer I/O error on dev sdc1, logical block 15108392, async page read\n Buffer I/O error on dev sdc1, logical block 15108393, async page read\n Buffer I/O error on dev sdc1, logical block 15108394, async page read\n Buffer I/O error on dev sdc1, logical block 15108395, async page read\n \n```\n\nWindows で USB 3.0 ポートが問題なく使用できているのであれば、Ubuntu\nではドライバが対応していない、別途アップデートを行う必要があるかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-06T09:10:11.320", "id": "53239", "last_activity_date": "2019-03-06T09:10:11.320", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22888", "parent_id": "53189", "post_type": "answer", "score": 1 } ]
53189
53239
53239
{ "accepted_answer_id": "53196", "answer_count": 1, "body": "JavaScriptでの配列のコピー及び加工についてかれこれ丸一日悩んでいて、どうしても分からない事があったので質問します。\n\n*やりたいこと* \nざっくり言うと受け取った配列から余因子行列を作成することです。詳しくは以下\n\n 1. 配列(A)を受け取る(例えば今回は二次元配列に3x3行列が格納されているものとします)\n 2. Aの2行目以降を新しい配列(D)にコピー\n 3. 繰返し処理でDのそれぞれの要素(今回は二行目と三行目)からi番目の要素を削除\n 4. Dを出力\n 5. 2に戻る\n\n入力: A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] \n出力: 1回目: [[5, 6], [8, 9]] \n2回目: [[4, 6], [7, 9]] \n3回目: [[4, 5], [7, 8]]\n\n現段階で書いたコードは以下の通りです。\n\n```\n\n this.dimention = 3\n arrayMatrix = [[1, 2 , 3], [4, 5, 6], [7, 8, 9]]\n for (var i = 0; i < this.dimention; i++) {\n var Dij = new Array(this.dimention)\n for (var k = 0; k < this.dimention; k++) {\n Dij[k] = arrayMatrix[k]\n }\n Dij = Dij.slice(1)\n for (var j = 0; j < this.dimention - 1; j++) {\n Dij[j].splice(i, 1)\n }\n console.log(Dij)\n }\n \n```\n\nまずDを使い回すためにコピーしているのですが要素を削除すると元の配列にも影響し次のDの作成ができなくなってしまいます。 \nそのためシャローコーピでなくコードの様なディープコピーを色々試してみたのですがどうしても元の配列の要素も削除されてしまいます。 \nそもそも実装方法でもっといいものがあるような気がしてならないです。\n\n解決方法でなくても何か参考になることがあれば是非教えて頂きたいです。\n\n追記 \n以下の方法で現状目的は達成されました。これでも3重ループになってしまっているので、他のいい実装方法があれば教えて頂きたいです。\n\n```\n\n dimention = 3\n arrayMatrix = [[1, 2 , 3], [4, 5, 6], [7, 8, 9]]\n for (var i = 0; i < this.dimention; i++) {\n var Dij = []\n for (var k = 0; k < this.dimention - 1; k++) {\n Dij.push([])\n for (var l = 0; l < this.dimention; l++) {\n if (l !== i) {\n Dij[k].push(arrayMatrix[k + 1][l])\n }\n }\n }\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T15:24:38.657", "favorite_count": 0, "id": "53195", "last_activity_date": "2021-12-25T09:06:01.753", "last_edit_date": "2021-12-25T09:06:01.753", "last_editor_user_id": "32986", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "javascript", "array" ], "title": "JavaScriptでの配列のコピー及び加工", "view_count": 113 }
[ { "body": "「コードの様なディープコピー」とありますが、あなたのコードは全くディープコピーになっていません。\n\n * 単なる代入 ⇒ コピーにさえならない\n * 一番外側の配列だけコピー ⇒ シャローコピー (あなたのコード)\n * 内側の配列もコピーを作る ⇒ ディープコピー\n\n(この回答を書くためにネット上を検索したら、あまりにも多くの記事で「シャローコピー」「ディープコピー」の意味を間違っていたのでびっくりしましたが…。)\n\nJavaScriptの配列のコピーには色々なやり方があるのでディープコピーの方法もいろいろですが、できるだけ上側のあなたのコードを活かすなら、\n\nこの部分:\n\n```\n\n var Dij = new Array(this.dimention)\n for (var k = 0; k < this.dimention; k++) {\n Dij[k] = arrayMatrix[k]\n }\n \n```\n\nをこんな風に書き換えてみてください。\n\n```\n\n var Dij = new Array(this.dimention)\n for (var k = 0; k < this.dimention; k++) {\n Dij[k] = arrayMatrix[k].concat() //<- \n }\n \n```\n\nあるいはこの4行をまとめてこんな風に書いてしまうこともできます。\n\n```\n\n var Dij = arrayMatrix.map(innerArr => innerArr.concat());\n \n```\n\n上に書いたようにいろいろな方法がありますが、「内側の配列もコピーを作る」と言うことをしていないのに「ディープコピー」と呼ぶのは間違っている、と言うのは覚えておいてください。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T18:03:30.557", "id": "53196", "last_activity_date": "2019-03-04T18:03:30.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "53195", "post_type": "answer", "score": 1 } ]
53195
53196
53196
{ "accepted_answer_id": "54373", "answer_count": 1, "body": "rubyonrailsでmysql5.7とruby:2.4.2でKubernetesをやってみよう思い\n\ndatabase.ymlを\n\n```\n\n adapter: mysql2\n encoding: utf8\n pool: <%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %>\n database: rails_production\n host: <%= ENV['DATABASE_HOST'] %>\n username: root\n password: <%= ENV['DATABASE_ROOT_PASSWORD'] %>\n port: <%= ENV['DATABASE_PORT'] %>\n \n```\n\nに設定し \nmysql5.7でdeploymentするとCrashLoopBackOffがでます\n\n`gcloud compute disks create --size 200GB mysql-data`\n\n```\n\n apiVersion: extensions/v1beta1\n kind: Deployment\n metadata:\n name: mysql\n labels:\n app: mysql\n spec:\n replicas: 1\n selector:\n matchLabels:\n app: mysql\n template:\n metadata:\n labels:\n app: mysql\n spec:\n containers:\n - image: mysql:5.7\n name: mysql\n env:\n - name: MYSQL_ROOT_PASSWORD\n valueFrom:\n secretKeyRef:\n name: rails\n key: database_root_password\n ports:\n - containerPort: 3306\n name: mysql\n volumeMounts:\n - name: mysql-persistent-storage\n mountPath: /var/lib/mysql\n volumes:\n - name: mysql-persistent-storage\n gcePersistentDisk:\n pdName: mysql-data\n fsType: ext4\n \n```\n\nkubectl describe pod\n\n```\n\n Name: mysql-55c74486f6-89j7r\n Namespace: default\n Priority: 0\n PriorityClassName: <none>\n Node: gke-myrails-default-pool-e9785f10-b4l5/10.140.0.10\n Start Time: Mon, 04 Mar 2019 20:00:46 +0000\n Labels: app=mysql\n pod-template-hash=1173004292\n Annotations: kubernetes.io/limit-ranger: LimitRanger plugin set: cpu request for container mysql\n Status: Running\n IP: 10.0.0.15\n Controlled By: ReplicaSet/mysql-55c74486f6\n Containers:\n mysql:\n Container ID: docker://488be36176d5f260a09159e69a43ac0825da8c9c6c736574df16dc8d91e32504\n Image: mysql:5.7\n Image ID: docker-pullable://mysql@sha256:888d433748dbccc8388a665134b1906f13f599753ef190546903181b7312027d\n Port: 3306/TCP\n Host Port: 0/TCP\n Args:\n --ignore-db-dir = lost + found\n State: Terminated\n Reason: Error\n Exit Code: 127\n Started: Mon, 04 Mar 2019 20:01:18 +0000\n Finished: Mon, 04 Mar 2019 20:01:18 +0000\n Last State: Terminated\n Reason: Error\n Exit Code: 127\n Started: Mon, 04 Mar 2019 20:01:04 +0000\n Finished: Mon, 04 Mar 2019 20:01:04 +0000\n Ready: False\n Restart Count: 2\n Requests:\n cpu: 100m\n Environment:\n MYSQL_ROOT_PASSWORD: <set to the key 'database_root_password' in secret 'rails'> Optional: false\n Mounts:\n /var/lib/mysql from mysql-persistent-storage (rw)\n /var/run/secrets/kubernetes.io/serviceaccount from default-token-7xrkt (ro)\n Conditions:\n Type Status\n Initialized True\n Ready False\n ContainersReady False\n PodScheduled True\n Volumes:\n mysql-persistent-storage:\n Type: GCEPersistentDisk (a Persistent Disk resource in Google Compute Engine)\n PDName: mysql-data\n FSType: ext4\n Partition: 0\n ReadOnly: false\n default-token-7xrkt:\n Type: Secret (a volume populated by a Secret)\n SecretName: default-token-7xrkt\n Optional: false\n QoS Class: Burstable\n Node-Selectors: <none>\n Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s\n node.kubernetes.io/unreachable:NoExecute for 300s\n Events:\n Type Reason Age From Message\n ---- ------ ---- ---- -------\n Normal Scheduled 36s default-scheduler Successfully assigned default/mysql-55c74486f6-89j7r to gke-myrails-default-pool-e9785f10-b4l5\n Normal SuccessfulAttachVolume 30s attachdetach-controller AttachVolume.Attach succeeded for volume \"mysql-persistent-storage\"\n Normal Pulled 4s (x3 over 18s) kubelet, gke-myrails-default-pool-e9785f10-b4l5 Container image \"mysql:5.7\" already present on machine\n Normal Created 4s (x3 over 18s) kubelet, gke-myrails-default-pool-e9785f10-b4l5 Created container\n Normal Started 4s (x3 over 18s) kubelet, gke-myrails-default-pool-e9785f10-b4l5 Started container\n Warning BackOff 4s (x3 over 17s) kubelet, gke-myrails-default-pool-e9785f10-b4l5 Back-off restarting failed container\n \n```\n\n```\n\n Initializing database\n 2019-03-04T19:07:34.627201Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).\n 2019-03-04T19:07:34.628690Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.\n 2019-03-04T19:07:34.628756Z 0 [ERROR] Aborting\n \n```\n\nとなります。誰かこの直し方知っている方いますでしょうか? \n教えてください。よろしくお願いします。", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-04T20:10:05.787", "favorite_count": 0, "id": "53197", "last_activity_date": "2019-04-21T17:37:29.030", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19329", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "kubernetes", "google-kubernetes-engine" ], "title": "mysql5.7をdeploymentするとエラーがでる", "view_count": 246 }
[ { "body": "mysql5.6に変更しました。 \nmysql5.7ではまずimageをつくらないとだめみたいです", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-04-21T17:37:29.030", "id": "54373", "last_activity_date": "2019-04-21T17:37:29.030", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19329", "parent_id": "53197", "post_type": "answer", "score": 0 } ]
53197
54373
54373
{ "accepted_answer_id": null, "answer_count": 1, "body": "お世話になります。\n\nRuby on Rails の開発を始めて、少し経ちました。 \nStackOverFlow、Qiitaなど含めて、ネット上でソースコードを多くみてきましたが、 \nそのほとんどがコメントがありません。 \nライブラリのオーバーライドもコメントが無く、困ることがあります。 \nそのため、メソッド名から推測して詳細は目を瞑るか、親クラスのメソッドのコードを探すか、2択になります。\n\n確かに、コメントが無くても理解できるのが良いコードだと思いますが、無理やり無くしているように感じることも多いです。 \nRailsの開発は、コメントを無くすほうが良い、というような風潮がありますか?\n\nよろしくお願いいたします。", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T03:03:08.477", "favorite_count": 0, "id": "53201", "last_activity_date": "2019-07-24T22:29:10.297", "last_edit_date": "2019-07-24T01:09:17.667", "last_editor_user_id": "2238", "owner_user_id": null, "post_type": "question", "score": 2, "tags": [ "ruby-on-rails", "ruby" ], "title": "Rails の コメントの少なさについて", "view_count": 405 }
[ { "body": "私の主観ではありますが、Ruby on\nRailsに限らず、Javaのコードであっても、それこそどんな言語やフレームワークであっても、StackOverflowやQiitaに直接書かれているコードはコメントが少ない傾向にあると思います。私自身もそういった所で載せるコードを作る場合は、積極的にコメントを書こうとすることはありません。これには妥当な理由があります。\n\nまず、これらの所で書かれるコードは、問題の再現するためや説明するためのコードであって、なんらかの完成したプロダクトではなく、その断片の場合が多いです。優れた質問では、さらに最低限再現できるところまで落とし込んで書いてしまっていますので、あるがままでしかないコードとして、特にコメントを入れる必要性が無くなると思います。回答の方は、すでに本文に解説が書いています。コードは実際の動作確認用の補足に過ぎないからです。コード内に本文と同じことをコメントをしても冗長なだけになるでしょう。Qiitaの記事についても同様です。\n\nRuby on\nRailsを用いたプログラムがどのような傾向なのかを見るには、(実験的な断片等ではない)完成したプロダクトを見ないと何も言えないと思います。例えば、[Redmine](https://github.com/redmine/redmine)、[mastodon](https://github.com/tootsuite/mastodon)、[GitLab\nCE](https://gitlab.com/gitlab-org/gitlab-ce)等です。\n\nさて、それらを踏まえての傾向ですが、結局、これまた主観的な意見になしまっているのですが、Ruby on\nRailsというレールに乗っている限りコメントを入れることはないと思われます。例えば、コントローラーのクラスは場所や名前や親クラスからなんというコントローラーのクラスなのかが自明です。また、標準的なルーティングではどのようなパスでどのメソッドを付かれるのかも自明であり、`show`や`index`などはわざわざ説明する必要性はないとなります。逆に、レールから外れる場合や、レール外の部分については、コメントが書かれる傾向があると思います。\n\nただ、プレジェクト毎の方針の違いは必ずあるでしょうし、オープンソースとクローズドなプロダクトではまた傾向が変わってくると思いますので、一概にはなんとも言えないと思います。Ruby\non Rails以外でも、オープンソースですと、コメントが全くないというプロダクトも珍しくないですから。(あ、それ、俺の作った…)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-07-24T22:29:10.297", "id": "56869", "last_activity_date": "2019-07-24T22:29:10.297", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7347", "parent_id": "53201", "post_type": "answer", "score": 4 } ]
53201
null
56869
{ "accepted_answer_id": null, "answer_count": 1, "body": "現在Googleフォームでアップロード機能を使ったフォームの運用を考えています。\n\nまずGoogleフォームの仕様ですが \n送信前に回答者がファイルのアップロードを行った時点で \n回答者がオーナーのファイルが回答者のドライブ(直下)に保存されます。\n\nその後フォームを送信すると \nフォーム作成者側のドライブのファイル保存場所に \nフォーム作成者側がオーナーのアップロードファイルが保存されます。\n\nそこでですが、このままですと \n回答者が意識してフォーム送信後に \n自分のドライブ直下にアップされたファイルを消していかないと \nドライブ直下にアップロードファイルが溜まり続ける状態となってしまうため \nなんとかGASやその他の手段(あれば)を用いて \nフォーム送信後に回答者のアップロードファイルを削除したいと考えております。\n\n現状、インターネットや書籍を参考に、フォームのGASでは以下のように \n回答内容を取得してメールを送信するプログラムを書いております。\n\n```\n\n function noticeFileUpload(e) {\n var itemResponses = e.response.getItemResponses();\n \n for (var i = 0; i < itemResponses.length; i++) { \n var itemResponse = itemResponses[i]; \n var question = itemResponse.getItem().getTitle(); \n var answer = itemResponse.getResponse();\n \n Logger.log(question);\n Logger.log(answer);\n \n if(question == \"提出書類\"){\n var fileId = answer;\n var file = DriveApp.getFileById(fileId);\n \n var address = 'メールアドレス'; \n var title = '【Google Form送信テスト】ファイルがアップロードされました'; \n var content = 'ファイルがアップロードされました。\\n\\n'\n + 'ファイル名:' + file.getName()\n + '\\n\\n'\n + '※このメールはGoogleフォームからの自動送信メールです。'; \n \n GmailApp.sendEmail(address, title, content);\n }\n }\n }\n \n```\n\nこのように、回答内容を取得するコードはわかるのですが \n回答者が自分のドライブにアップしたファイルを取得する具体的なコードがわかりません。\n\n回答内容で保存されたファイルの名前から、自動付加された後ろのアカウント名を削除し \n同じ名前のファイルをドライブ直下から検索→削除といった処理をしなければならないのでしょうか。 \n(その場合、既に同じ名前のファイルがあった場合などの対応も気がかりです)\n\nすいませんがご教授いただけると助かります。 \nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T05:56:41.753", "favorite_count": 0, "id": "53202", "last_activity_date": "2019-03-05T06:30:00.343", "last_edit_date": "2019-03-05T06:30:00.343", "last_editor_user_id": "32411", "owner_user_id": "32411", "post_type": "question", "score": 0, "tags": [ "google-apps-script" ], "title": "Googleフォームのアップロード機能でアップした回答者のファイルをフォーム送信後に削除したい", "view_count": 5040 }
[ { "body": "結論から言えば、可能です。\n\n以下のドキュメントを読めば、やり方の一助になります。\n\n[Forms Service | Apps Script | Google\nDevelopers](https://developers.google.com/apps-script/reference/forms/) \n[Drive Service | Apps Script | Google\nDevelopers](https://developers.google.com/apps-script/reference/drive/)\n\nGoogle Apps\nScript自体の書き方については、ご自身で勉強していただくしかないのが実情でありますが、ES5をベースとして、インターネット上や書籍にも多数の情報があり、比較的入門者にも学びやすい言語であるため、頑張ってください。 \n[Overview of Google Apps Script | Apps Script | Google\nDevelopers](https://developers.google.com/apps-script/overview) \n[【保存版】初心者向け実務で使えるGoogle Apps Script完全マニュアル](https://tonari-it.com/google-apps-\nscript-manual/)\n\n### 追記 2019-03-05_15-29-37\n\nGoogle Form側のWebクライアントの機能で、回答結果をスプレッドシートに書き込むことが出来ます(新しい回答も自動的に追記・編集されていきます)。\n\nそして、このスプレッドシートには回答者がアップロードしたファイルのGoogle\nDrive側のURLも回答の項目として記載されているため、このURLからファイルのIDを取得、 `DriveApp.getFileById`\nを利用して[File](https://developers.google.com/apps-\nscript/reference/drive/file)を取得し、後は `File.getParents`\nで親[Folder](https://developers.google.com/apps-\nscript/reference/drive/folder)を取得することで`Folder.removeFile`を実行して実際にファイルを削除することが出来ます。", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T06:06:13.723", "id": "53205", "last_activity_date": "2019-03-05T06:29:45.893", "last_edit_date": "2019-03-05T06:29:45.893", "last_editor_user_id": "29826", "owner_user_id": "29826", "parent_id": "53202", "post_type": "answer", "score": 1 } ]
53202
null
53205
{ "accepted_answer_id": "53213", "answer_count": 1, "body": "いつもお世話になっております。 \n下記の質問についてご存知の方がいらっしゃいましたらご教示を願います。\n\n* * *\n\n### 【質問の主旨】\n\nGitHubで公開されている[advanced-interactivity-in-\namp](https://github.com/googlecodelabs/advanced-interactivity-in-amp)を、Mac\nOSのホームディレクトリに`git clone`した後、node_modulesとして **Express**\nをインストールするためにはどうすれば良いでしょうか?パスの書きかえが必要が気がしますが、その内容が分かりません。\n\n### 【質問の補足】\n\n1\\.\n\n下記の手順でMac OSのホームディレクトリにある、[advanced-interactivity-in-\namp](https://github.com/googlecodelabs/advanced-interactivity-in-\namp)ディレクトリにExpressをインストールしようとしましたが、node_modulesディレクトリに含まれるはずのExpressはインストールできませんでした。\n\n```\n\n $ pwd\n $ /Users/MYNAME\n $ git clone https://github.com/googlecodelabs/advanced-interactivity-in-amp.git\n $ npm install -g express-generator\n /Users/MYNAME/.anyenv/envs/ndenv/versions/v8.11.3/bin/express -> /Users/MYNAME/.anyenv/envs/ndenv/versions/v8.11.3/lib/node_modules/express-generator/bin/express-cli.js\n $ ls\n CONTRIBUTING.md LICENSE README.md app.js package.json static // node_modulesがない\n \n```\n\n2\\.\n\n`$ npm install -g express-\ngenerator`を実行するとExpressを含むnode_modulesディレクトリは下記の位置にインストールされます。\n\n```\n\n $pwd\n /Users/MYNAME/.anyenv/envs/ndenv/versions/v8.11.3/lib/node_modules/express-generator\n \n```\n\n3\\.\n\nNode.jsの管理は[こちらのページ](https://h2ham.net/anyenv)を参考にして **anyenv** を使っています。\n\n4\\.\n\n現在のパスの設定は下記の通りです。\n\n```\n\n $ pwd\n /Users/MYNAME\n $ view .bash_profile\n #!/bash/profile\n export PATH=$HOME/.anyenv/bin:$PATH\n eval \"$(anyenv init -)\"\n \n```\n\n5. \n今回の質問に関係するツールやパッケージのバージョンは以下の通りです。\n\n```\n\n $ node -v\n v8.11.3\n $ ndenv versions\n v10.15.1\n v10.8.0\n v4.3.0\n v4.3.1\n v4.7.0\n * v8.11.3 (set by /Users/MYNAME/.anyenv/envs/ndenv/version)\n $ anyenv versions\n ndenv:\n v10.15.1\n v10.8.0\n v4.3.0\n v4.3.1\n v4.7.0\n * v8.11.3 (set by /Users/MYNAME/.anyenv/envs/ndenv/version)\n rbenv:\n * system (set by /Users/MYNAME/.anyenv/envs/rbenv/version)\n $ npm -v\n 6.8.0\n $ express --version \n 4.16.0\n \n```\n\n* * *\n\n以上、ご確認のほどよろしくお願い申し上げます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T05:56:57.623", "favorite_count": 0, "id": "53203", "last_activity_date": "2019-03-05T12:39:54.097", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32232", "post_type": "question", "score": 0, "tags": [ "node.js", "shellscript", "npm" ], "title": "所定のディレクトリにnode_modulesとしてのExpressをインストールするためにはどうすれば良いでしょうか?", "view_count": 350 }
[ { "body": "git clone後、 \n1\\. `cd advanced-interactivity-in-amp` \n2\\. `npm install` \nで必要なモジュールが`node_modules`にインストールされます。\n\n余談ですが、 \n1\\. `npm\ninstall`の`-g`はglobalオプションで、Node.jsで書かれたコマンド(npmなど)をインストールする場合に使います。global(今回の例ではndenv配下)にインストールされるので、カレントディレクトリに依存せずにコマンドが使えるようになります \n2\\. `npm\ninstall`だけの場合は、カレントディレクトリの`package.json`の記述に従って、カレントディレクトリにモジュールがインストールされます。Expressは`package.json`に依存するモジュールとして記述されているので、特に指定は必要ありません", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T12:39:54.097", "id": "53213", "last_activity_date": "2019-03-05T12:39:54.097", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7900", "parent_id": "53203", "post_type": "answer", "score": 4 } ]
53203
53213
53213
{ "accepted_answer_id": "53207", "answer_count": 1, "body": "以下のデータフレーム ex があります。\n\n> ex \n> name score test rank \n> 1 john 80 0 4 \n> 2 taro 60 0 3 \n> 3 betty 70 NA 2 \n> 4 hanako 50 0 1\n\ntestがNAのとき、rankもNAにしたいとき\n\n> mutate(ex,rank = if_else(test == 0,true = rank,false = NA))\n\nと入力するとエラーが出る一方、\n\n> mutate(ex,rank = if_else(test == 0,true = rank,false = 0))\n\nと入力すると望んだ結果が得られます。 \nどうしてこのようなことになるのか、教えていただければ幸いです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T06:04:04.763", "favorite_count": 0, "id": "53204", "last_activity_date": "2019-03-05T07:19:50.410", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32412", "post_type": "question", "score": 1, "tags": [ "r" ], "title": "R言語 if_elseの挙動について", "view_count": 797 }
[ { "body": "`dplyr::if_else()` は、引数`true`と `false`に与える型が同じでなければいけません。 \n今回はrank列が実数なので、 `NA`の中でも実数を指定する`NA_real_` を与える必要があります。\n\n`mutate(ex, rank = if_else(test == 0, true = rank, false = NA_real_))`\n\nまた、質問の\n\n> testがNAのとき、rankもNAにしたいとき\n\nでは下記のようにするのが良いと思います。\n\n```\n\n mutate(ex, rank = if_else(is.na(test), true = NA_real_, false = rank))\n #> # A tibble: 4 x 4\n #> name score test rank\n #> <chr> <dbl> <dbl> <dbl>\n #> 1 john 80 0 4\n #> 2 taro 60 0 3\n #> 3 betty 70 NA NA\n #> 4 hanako 50 0 1\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T07:11:22.983", "id": "53207", "last_activity_date": "2019-03-05T07:19:50.410", "last_edit_date": "2019-03-05T07:19:50.410", "last_editor_user_id": "6020", "owner_user_id": "6020", "parent_id": "53204", "post_type": "answer", "score": 3 } ]
53204
53207
53207
{ "accepted_answer_id": null, "answer_count": 0, "body": "お世話になってます。初心者ですがなにとぞよろしくお願いします。\n\nformの中に本人確認実施フラグを作りたいですが、optionから受け取ったtrueまたfalseはselectのvalue変数gui->{check_flag}\nへ設置したいです。以下のようなコードでどのように連携すればいいのかわかりません。詳しい方は教えて頂ければ助かります。\n\n**該当部分のソースコード**\n\n```\n\n <select name=\"check_flag\" value=\"<%= gui->{check_flag} %>\">\n <option value=\"true\" >true</option>\n <option value=\"false\" selected >false</option>\n </select>\n \n```\n\n**画面表示**\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/M4Xcc.png)](https://i.stack.imgur.com/M4Xcc.png)\n\n3/6追加: \nint32_tさんのおしゃる通り、selectタグにvalue属性がありません。コードは以下のように改造しました。\n\n```\n\n <select class=\"form-control\" name=\"check_flag\" id=\"check_flag\">\n   <option value=\"false\" <%= gui->{check_flag} eq \"false\" ? 'selected' : '' %>>実施しない</option>\n   <option value=\"true\" <%= gui->{check_flag} eq \"true\" ? 'selected' : '' %>>実施する</option>\n </select>\n \n```", "comment_count": 5, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T06:11:33.740", "favorite_count": 0, "id": "53206", "last_activity_date": "2019-03-06T02:12:40.027", "last_edit_date": "2019-03-06T02:12:40.027", "last_editor_user_id": "20329", "owner_user_id": "20329", "post_type": "question", "score": 0, "tags": [ "perl" ], "title": "optionから受け取った選択しをselectのvalue変数へ", "view_count": 577 }
[]
53206
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "お世話になります。 \n現在モンテカルロ法を高速化しようとOpen MPを使って並列化処理を行なっているのですが、Open\nMPを使ったときと使わなかった時を比べると、実行速度は若干速くなり、逆に結果の精度は悪くなりました。 \nこの原因は何でしょうか?わかる方教えてください。よろしくお願いいたします。\n\n下記プログラムはモンテカルロ法を使って円周率を求めるものです。\n\n【実行結果】 \n・openMPなしの場合 \n3.141556216 120948\n\n・openMPありの場合(同じコードで複数回実行) \n3.102521972 103864 \n3.104310832 108247 \n3.106061276 109388\n\n【実行環境】 \ng++ (clangではなくGNUの方です) \nCPUは2コア4スレッドです。\n\n```\n\n #include <iostream>\n #include <random>\n #include <chrono>\n #include <iomanip>\n #include <omp.h> //openMPを使わない時はコメントアウトします\n \n using namespace std;\n const long int N=1'000'000'000;\n \n random_device seed_gen;\n std::mt19937 engine(seed_gen());\n std::uniform_real_distribution<double> dist(0.0,1.0);\n \n \n int main(void)\n {\n double x,y,val=0.0;\n long int count=0;\n chrono::system_clock::time_point start, end;\n \n start = chrono::system_clock::now();\n \n #pragma omp parallel for reduction(+:count) //同様\n for (long int loop=0; loop < N; ++loop)\n {\n x=dist(engine);\n y=dist(engine);\n if(x*x+y*y<=1.) count++;\n }\n end = std::chrono::system_clock::now();\n double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();\n val=4*double(count)/N;\n \n cout<<setprecision(10)<<val<<\" \"<<elapsed<<endl;\n \n return 0;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T17:01:04.870", "favorite_count": 0, "id": "53216", "last_activity_date": "2019-03-05T22:33:27.653", "last_edit_date": "2019-03-05T22:33:27.653", "last_editor_user_id": "4236", "owner_user_id": "19263", "post_type": "question", "score": 1, "tags": [ "c++", "openmp" ], "title": "Open MPで並列化したら精度が落ちるモンテカルロ法", "view_count": 684 }
[ { "body": "[疑似乱数生成(メルセンヌ・ツイスター)の並列化](https://ja.stackoverflow.com/q/38446/4236)とほぼ同じ問題を抱えています。\n\nOpenMPの並列ループ内で乱数`engine`を参照しています。マルチスレッド安全ではない気がします。最善でもスレッド間で同じ乱数値を取得することになりその時点で精度は1スレッド分程度に落ちます。つまり8並列であれば`N/8`回の施行しか意味を持たなくなる。最悪な場合、`std::mt19937`の内部状態がスレッド間で不適切に更新され、乱数として機能しないもしくは乱数の精度が極端に落ちることも考えられます。\n\nところで、C言語及びC++言語ではBasic風に変数宣言を関数先頭に列挙すべきではありません。特にC++言語では宣言個所でコンストラクターが動作するため不適切です(更にはデストラクターの実行順が不要になった順ではなく、宣言と逆順に固定される点も不適切)。更に今回の場合、変数`x`、`y`はループ内で並列に更新するわけですから、ループ内で宣言すべきです。\n\n```\n\n #pragma omp parallel\n {\n std::mt19937 engine{ std::random_device{}() };\n std::uniform_real_distribution<double> dist{ 0.0, 1.0 };\n #pragma omp for reduction(+:count)\n for (long int loop=0; loop < N; ++loop) {\n auto x=dist(engine);\n auto y=dist(engine);\n if(x*x+y*y<=1.) count++;\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T22:32:38.903", "id": "53219", "last_activity_date": "2019-03-05T22:32:38.903", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "53216", "post_type": "answer", "score": 3 } ]
53216
null
53219
{ "accepted_answer_id": "53221", "answer_count": 2, "body": "複数のデータフレームがあり、それぞれのデータフレームの大きさを知りたく、次のようなコードを書いています。\n\n```\n\n dfs =['df_a', 'df_b', 'df_c']\n \n for df_name in dfs:\n   print(df_name)\n df_name.shape\n \n```\n\ndf_nameが、文字列であり、.shapeは使えないというエラーが出てきます(その通りなのですが)。\n\n```\n\n 'str' object has no attribute 'shape'\n \n```\n\nどのようにすれば、データフレームについて、繰り返しの処理を行えるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T20:56:00.893", "favorite_count": 0, "id": "53217", "last_activity_date": "2019-03-12T03:00:26.207", "last_edit_date": "2019-03-12T03:00:26.207", "last_editor_user_id": "3060", "owner_user_id": "20148", "post_type": "question", "score": 0, "tags": [ "python", "pandas" ], "title": "Pythonでデータフレーム名に対して繰り返しの処理を行うには?", "view_count": 1697 }
[ { "body": "データフレームの名前とインスタンスを dictで管理すると良いのではないでしょうか\n\n```\n\n dfs = {'df_a':df_a, 'df_b':df_b, 'df_c':df_c}\n for name, df in dfs.items():\n print(name)\n print(df.shape)\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T23:33:06.030", "id": "53221", "last_activity_date": "2019-03-05T23:33:06.030", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24801", "parent_id": "53217", "post_type": "answer", "score": 1 }, { "body": "データフレームであれば、そのままprint(df_a.shape)でサイズがわかります。\n\n```\n\n import pandas as pd\n \n df_a = pd.DataFrame(index =[1,1], columns=[\"a\",\"b\"])\n df_b = pd.DataFrame(index =[1,1], columns=[\"a\",\"b\"])\n df_c = pd.DataFrame(index =[1,1], columns=[\"a\",\"b\"])\n \n dfs = [df_a, df_b, df_c]\n \n for df_names in dfs:\n print(df_names.shape)\n \n```\n\nリストに入れる前にデータフレームを作成して、それをリストに入れるだけです。 \n例では適当なデータフレームを作成してます。 \n質問のリストはただの文字列になっているようなので、Pandasの.shapeが作用しません。使おうとしているメソッドが正しい型のものを参照しているのか注意すると、原因が導きやすくなります。\n\n参考になれば幸いです。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-06T07:42:05.750", "id": "53236", "last_activity_date": "2019-03-06T07:47:40.533", "last_edit_date": "2019-03-06T07:47:40.533", "last_editor_user_id": "30590", "owner_user_id": "30590", "parent_id": "53217", "post_type": "answer", "score": 1 } ]
53217
53221
53221
{ "accepted_answer_id": "53242", "answer_count": 2, "body": "お世話になります。 \n現在、数年前にruby1.8.2で開発されたアプリケーションの改修にアサインされた、新人エンジニアです。 \nよろしくお願いいたします。\n\nrbenvでruby1.8.2を使えるようにまでは出来たのですが、 \n外部ライブラリのインストール時に度々引っかかってしまい、開発環境の構築が進まない状態です。\n\nruby1.8.2はすでにサポート終了しており、ネット上にもあまり情報が多くない状態で困ってしまいました。\n\nこういう昔に開発されたアプリケーションの改修における開発環境構築において \n何かコツやポイントがあればご教示いただけると誠に幸いです。\n\nOSはUbuntu18.04 LTSを使用しています。 \nアプリケーションのコードはGitLabからPullできるようにしています。\n\n何卒よろしくお願いいたします。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-05T21:08:18.787", "favorite_count": 0, "id": "53218", "last_activity_date": "2019-03-06T11:17:09.200", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "32419", "post_type": "question", "score": 1, "tags": [ "ruby", "ubuntu" ], "title": "Rubyの1.8.2(サポート切れバージョン)での開発環境の構築(2019.3.6時点)", "view_count": 172 }
[ { "body": "サポートされていない=何かあったら自分で責任取るってことですよね\n\n選択肢1 バージョンアップ \n[ruby](/questions/tagged/ruby \"'ruby' のタグが付いた質問を表示\")\n(に限らず)開発環境一式新しいバージョンを用意して自作プログラムを新しいプラットフォーム上で動かしてみる。まっとうだけど面倒な道です。過去互換性を切り捨ててバージョンアップを行う傾向のある\n[php](/questions/tagged/php \"'php' のタグが付いた質問を表示\")\nなどでは結局作り直しなのかも。一通り動作検証が済んだころには主要ライブラリの次のバージョンがリリースされていたりして賽の河原かもしれません。でもサポートも得られそうですし情報収集が楽なのはこっちでしょう。\n\n選択肢2 野良ビルド \n外部ライブラリの当時のバージョンのソースを入手し野良ビルドします。っていうか商用 UNIX\nの世界ではこれが当たり前でした。どうせサポート外バージョンであるわけで、ならば野良ビルドし動作保証も自分でしましょう。ただ、世間情勢の変化とか致命的脆弱性とかの関連で一部ライブラリは最新に更新する必要があったりしますし、それを見極める目が無い人にはお勧めできません。\n\nポイント1\n古いものを使い続けるか最新に更新するかの判断はひとえに情報収集次第なところがあります。日本語に翻訳された記事を待つくらいなら開発元の英語資料を読むほうが手っ取り早くて正確です。\n\nポイント2 どっちを採用するにせよ手戻りが面倒なので、仮想マシン上で作業しこまめにスナップショットを取るのが良いでしょう。", "comment_count": 2, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-06T01:53:09.723", "id": "53224", "last_activity_date": "2019-03-06T01:53:09.723", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "53218", "post_type": "answer", "score": 1 }, { "body": "Ubuntu18.04を使うのは諦めてください。ruby1.8を扱うには新しすぎます。\n\n古いアプリケーションが前提なので、rubyは1.8.2を用意しなければならないでしょうが、ruby自体素直に正しくビルドできるか怪しいです。\n\nアプリケーションが依存するライブラリも、pure\nrubyで書かれているものならともかく、外部のライブラリ(例えばDBとか)に依存するものは現在のOSが提供するものでは互換性がなくビルドすらままならないものが多数出てきます。古いバージョンを持ってきたとしても、それをビルドするのにまたそちらの互換性問題を解決しなければなりませんし、バイナリパッケージシステムが前提になっている現代の環境との齟齬に起因するトラブルも背負い込むことになります。\n\nまず現在アプリケーションが動いている環境を調査し、それに合わせた環境を作るのがよいでしょう。どのみちテストではその環境が必要になります。\n\nrubyのライブラリは、gemというパッケージ形式になっていれば、<https://rubygems.org>\nから古いバージョンが取得できます。しかし、1.8の頃だと古すぎて大分怪しいです。これも現在の環境からコピーしたほうが早いです。\n\nRuby1.8の本は古書店や図書館にいけばまだまだ見つかると思います。\n\n* * *\n\nもし、「現在の環境で古いアプリケーションを動くようにする」のがミッションなのであれば、たいていの場合それは諦めて1から作り直した方が早くなると思います。\n\nまずRuby自体メジャーバージョンアップに伴って大きな変更が行われています。それぞれのバージョン間では以降のためにそれなりの配慮がされていますが、1.8->2.3のような大ジャンプは難しいです。1.8->1.9->...のように段階を踏むことが必要です。\n\nそれにあわせて、ライブラリも適切なバージョンを選んで移行していく必要があります。現在使用しているものが運良く継続してメンテナンスされていたとしても、互換性を考えつつ環境を作るのはなかなか面倒です。\n\nメンテナンスされていなければどうしようもありません。自分で直すのも、別のライブラリに移行するのも、大変な手間がかかります。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2019-03-06T11:17:09.200", "id": "53242", "last_activity_date": "2019-03-06T11:17:09.200", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "53218", "post_type": "answer", "score": 2 } ]
53218
53242
53242