question
dict
answers
list
id
stringlengths
2
5
accepted_answer_id
stringlengths
2
5
popular_answer_id
stringlengths
2
5
{ "accepted_answer_id": "11088", "answer_count": 1, "body": "```\n\n hasOwnProperty.call(A, B)\n \n```\n\n・どういう意味でしょうか? \n・下記と同じ??\n\n```\n\n A.hasOwnProperty(B)\n \n```\n\n* * *\n\nhasOwnProperty上書きの件で、質問追記します。\n\n・for文と組合せた下記のような記述をよく見かけるのですが、\n\n```\n\n for (var key in obj ) {\n if ( obj.hasOwnProperty(key) ) {\n console.log(key + \":\" + obj[key]);\n }\n }\n \n```\n\n・「当初質問した内容の両者」が同じなら、Function.prototype.call()を使用した方が良いのではないかと思うのですが…\n\n```\n\n for (var key in obj ) {\n if ( hasOwnProperty.call(obj, key) ) {\n console.log(key + \":\" + obj[key]);\n }\n }\n \n```\n\n・Function.prototype.call()をあまり見かけないのは、hasOwnPropertyが上書きされることなどない、という前提に立っているからでしょうか? \n・そこまで考慮する必要はないってこと?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T00:12:09.087", "favorite_count": 0, "id": "11085", "last_activity_date": "2015-06-10T02:10:40.967", "last_edit_date": "2015-06-09T01:27:24.820", "last_editor_user_id": "7886", "owner_user_id": "7886", "post_type": "question", "score": 3, "tags": [ "javascript" ], "title": "hasOwnProperty.call(A, B) と A.hasOwnProperty(B)", "view_count": 1684 }
[ { "body": "はい、基本的には同じです。\n\nただし、`A.hasOwnProperty = null;` 等とメソッドが上書きされていた場合、前者は正常に動作し、後者はランタイム エラーになります。\n\n* * *\n\nオブジェクトが持つキーを自分でコントロールできるのであれば、`.call()`は使わなくて良いでしょう。できない場合 (例えばユーザー入力をキーにする)\nは、そのプロパティを信用できないので `.call()` 呼び出しのほうが良いです。この場合、他にも考慮すべきことがあって、例えば `__proto__`\nが上書きされるとプロトタイプチェーンが変化して予期せぬ挙動の原因になる可能性があります。\n\nなお、性能的には `.call()` 呼び出しのほうが若干悪いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T01:55:33.680", "id": "11088", "last_activity_date": "2015-06-10T02:10:40.967", "last_edit_date": "2015-06-10T02:10:40.967", "last_editor_user_id": "4809", "owner_user_id": "4809", "parent_id": "11085", "post_type": "answer", "score": 4 } ]
11085
11088
11088
{ "accepted_answer_id": null, "answer_count": 1, "body": "Rubyでリスト処理をするには,配列を使うのが普通なのかと思います.単純にCDRを取りたいとき,どうすればよいのでしょうか.shiftというメソッドがあるのを知りましたが,これには2つ問題があります. \n・副作用がある.フレッシュなものがほしい. \n・返値が削除された値(CAR)でCDRではない. \n解消するにはcloneとshiftを組み合わせ,さらにshift後の配列を取り出すという手間をかけるしかないのでしょうか.そもそも配列操作のどれが副作用ありでどれが新しいオブジェクトを作るのか,分かりやすいルールはあるのでしょうか.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T02:19:07.503", "favorite_count": 0, "id": "11091", "last_activity_date": "2015-06-08T03:05:41.940", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10037", "post_type": "question", "score": 1, "tags": [ "ruby" ], "title": "Rubyにおけるリスト処理", "view_count": 276 }
[ { "body": "```\n\n car = array[0]\n cdr = array[1..-1]\n \n```\n\nまたは\n\n```\n\n car, *cdr = array\n \n```\n\nメソッドが破壊的かどうかは統一されたルールは無いと思います。リファレンスマニュアルを見るしかないと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T03:05:41.940", "id": "11094", "last_activity_date": "2015-06-08T03:05:41.940", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3249", "parent_id": "11091", "post_type": "answer", "score": 4 } ]
11091
null
11094
{ "accepted_answer_id": null, "answer_count": 0, "body": "iosで発生する問題となります。 \nmonaca(onsenui)でテキストエリアなどにフォーカスした場合にキーボードが起動しますが、 \nキーボードが起動した状態で画面をスクロールするとons-toolbarが画面外に移動してしまいます。\n\nこちら回避方法あるでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T03:22:13.493", "favorite_count": 0, "id": "11096", "last_activity_date": "2015-06-08T03:45:40.553", "last_edit_date": "2015-06-08T03:45:40.553", "last_editor_user_id": "8360", "owner_user_id": "8360", "post_type": "question", "score": 3, "tags": [ "monaca", "onsen-ui" ], "title": "monacaでons-toolbarが画面外に消えてしまう。", "view_count": 263 }
[]
11096
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "PayPalのSetExpressCheckoutのAPIを呼び出したところ、レスポンスでエラーコード10400が返ってきたのですが、\n\n<https://www.paypal.jp/uploadedFiles/wwwpaypaljp/Supporting_Content/jp/manual/PP_JP_NVPAPI_DeveloperGuide_JP.pdf>\n\nによると、「OrderTotalがありません。」との記載になっていますが、 \n下記のパラメータ以外に必要なものはありますでしょうか。\n\n```\n\n [パラメーター]\n &METHOD=SetExpressCheckout\n &VERSION=52.0\n &USER=***\n &PWD=****** \n &SIGNATURE=XXXXXXXX\n &PAYMENTREQUEST_0_PAYMENTACTION=Sale \n &PAYMENTREQUEST_0_AMT=19.5\n &RETURNURL=XXXXXXX\n &CANCELURL=XXXXXXX\"\"\n \n [レスポンス]\n TIMESTAMP=2015-05-28T08:22:13Z\n &CORRELATIONID=******\n &ACK=Failure\n &VERSION=52.0\n &BUILD=7333778\n &L_ERRORCODE0=10400\n &L_SHORTMESSAGE0=Transaction refused because of an invalid argument. See additional error messages for details.\n &L_LONGMESSAGE0=Order total is missing.\n &L_SEVERITYCODE0=Error\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T04:26:37.633", "favorite_count": 0, "id": "11100", "last_activity_date": "2015-12-14T03:39:11.760", "last_edit_date": "2015-06-08T11:14:45.180", "last_editor_user_id": "8335", "owner_user_id": "9233", "post_type": "question", "score": 1, "tags": [ "paypal" ], "title": "10400コードエラー", "view_count": 545 }
[ { "body": "指定しているversionが古いので新しくしましょう。VERSION=122.0 で試してください。\n\n古いバージョンではPAYMENTREQUEST_0_* というパラメータが認識されないので \n必須である、PAYMENTREQUEST_0_AMTパラメータが指定なしとみなされて起こるエラーだと思います。\n\nなお、通貨はデフォルトで米国ドルです。 \n日本円で決済する場合は、PAYMENTREQUEST_0_CURRENCYCODE=JPY を送信して下さい。 \nまた、日本円の場合、PAYMENTREQUEST_0_AMTの値は整数を指定してください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-16T10:31:58.880", "id": "11415", "last_activity_date": "2015-06-16T10:31:58.880", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9226", "parent_id": "11100", "post_type": "answer", "score": 1 } ]
11100
null
11415
{ "accepted_answer_id": null, "answer_count": 2, "body": "iOSアプリで[こちら](http://qiita.com/hirobe/items/2baf629b7807b4c0d10f)の記事を参考にしてスクロールビューを実装しています。\n\niOS7では問題なく動くのですが、iOS8 iPhone6ではビューの中身のスクロールする部分の横幅が親ビューよりも広くなってしまいました。\n\n解決方法を知っていたら教えてください。\n\n画像の青い部分がスクロールビューの中身、赤い部分がスクロールビューです。 \n左が理想、右が現在です。\n\n![イメージ説明](https://i.stack.imgur.com/YBt6H.jpg)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T05:15:55.527", "favorite_count": 0, "id": "11104", "last_activity_date": "2015-07-08T07:23:02.560", "last_edit_date": "2015-07-08T07:23:02.560", "last_editor_user_id": "8772", "owner_user_id": "10043", "post_type": "question", "score": 0, "tags": [ "ios", "objective-c", "swift", "xcode" ], "title": "iPhone6でスクロールビューの中身のビューがスクロールビューの横幅と合わない", "view_count": 344 }
[ { "body": "赤い枠はUIScrollViewのframe、青い枠はUIScrollViewのcontentSizeに相当するかと思います。 \n何故意図しない動きになっているかは今の情報だけでは特定できませんが、frameやcontentSizeにどんな値を入れているのか、またはどんな値が入っているのかをNSLogして、何か思い当たるフシが無いかを探ってみてください。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T07:59:30.337", "id": "11110", "last_activity_date": "2015-06-08T07:59:30.337", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5605", "parent_id": "11104", "post_type": "answer", "score": 0 }, { "body": "「UIScrollViewとその中身のViewの幅を等しい」という制約を張ることで実現できます \n<http://qiita.com/hirobe/items/2baf629b7807b4c0d10f>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T02:39:50.440", "id": "11246", "last_activity_date": "2015-06-11T02:39:50.440", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9558", "parent_id": "11104", "post_type": "answer", "score": 2 } ]
11104
null
11246
{ "accepted_answer_id": null, "answer_count": 0, "body": "![画像の説明をここに入力](https://i.stack.imgur.com/zVyZb.jpg) \nmonacaでRSSを取得するサンプルを使ってアプリを開発したいのですが \n文字化けしてしまいます。\n\n<サンプル> \n<https://github.com/monaca/project-templates/tree/master/4-jqm-memo> \n変更点は以下の通りです。 \n<変更前>index.htmlの13行目 \nvar feedUrl = \"<http://feeds.bbci.co.uk/news/technology/rss.xml>\";\n\n<変更後1>facebook→titleの文字化け(世界のtoyota様) \nvar feedUrl =\n\"[http://www.facebook.com/feeds/page.php?id=158139660914197&format=rss20](http://www.facebook.com/feeds/page.php?id=158139660914197&format=rss20)\"; \n変更・・・[http://www.lottaleben.de/tools/rss-feed-fuer-facebook-seiten-\ngenerieren/で作成](http://www.lottaleben.de/tools/rss-feed-fuer-facebook-seiten-\ngenerieren/%E3%81%A7%E4%BD%9C%E6%88%90)\n\n<変更後2>ameba→取得年月日の文字化け(エビちゃん) \nvar feedUrl = \"<http://rssblog.ameba.jp/ebizo-ichikawa/rss.html>\"; \n変更・・・var feedUrl =\n\"[http://rssblog.ameba.jp/(アメーバID)/rss.html](http://rssblog.ameba.jp/\\(%E3%82%A2%E3%83%A1%E3%83%BC%E3%83%90ID\\)/rss.html)\";\n\n誠に恐れ入りますが、ご教授の程宜しくお願い致します。", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T06:14:11.667", "favorite_count": 0, "id": "11105", "last_activity_date": "2015-06-16T07:44:49.693", "last_edit_date": "2015-06-16T07:44:49.693", "last_editor_user_id": "7724", "owner_user_id": "7724", "post_type": "question", "score": 1, "tags": [ "monaca" ], "title": "RSSの内容が文字化けしてしまう", "view_count": 1017 }
[]
11105
null
null
{ "accepted_answer_id": "11151", "answer_count": 1, "body": "onClickに定義すればよいのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T06:54:37.087", "favorite_count": 0, "id": "11106", "last_activity_date": "2015-06-09T03:27:12.520", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10046", "post_type": "question", "score": -1, "tags": [ "onsen-ui" ], "title": "onsenでボタンを押したら外部リンクに飛ぶようにしたいのですが", "view_count": 1127 }
[ { "body": "onclickで大丈夫です。\n\n```\n\n onclick=\"window.open(url, target, options);\"\n \n```\n\ntarget \n・_self:URLがホワイトリストに載っている場合は、Cordova WebView。それ以外は、InAppBrowser \n・_blank:InAppBrowser \n・_system:システムのWebブラウザ\n\noptions ※InAppBrowserで使用するオプション。 \n・location: \nyes:ロケーションバー表示 \nno:ロケーションバー非表示\n\n詳細は[Inappbrowserプラグイン](http://docs.monaca.mobi/cur/ja/reference/phonegap_34/ja/inappbrowser/)をご参照ください。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T03:27:12.520", "id": "11151", "last_activity_date": "2015-06-09T03:27:12.520", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3516", "parent_id": "11106", "post_type": "answer", "score": 1 } ]
11106
11151
11151
{ "accepted_answer_id": null, "answer_count": 0, "body": "onsenUIをbrowserifyで使うには、どのようにrequireすればよいのでしょうか?\n\nons = require 'onsenui'\n\n上の記述だけでは、consoleに \nUncaught TypeError: Cannot read property 'documentElement' of undefined \nというエラーが出ます。\n\nonsenはbowerで入れました。 \n他にもrequireしなければならない依存しているものがありますか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T07:50:50.650", "favorite_count": 0, "id": "11109", "last_activity_date": "2015-06-08T07:50:50.650", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10048", "post_type": "question", "score": 1, "tags": [ "onsen-ui", "angularjs", "browserify" ], "title": "onsenUIをbrowserifyでrequireするには?", "view_count": 191 }
[]
11109
null
null
{ "accepted_answer_id": null, "answer_count": 2, "body": "```\n\n $html = file_get_contents(\"http://www.amazon.co.jp/s/fst=nb___mk_ja_JP=%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A&url;=node%3D466280&field-keywords;=%E6%96%B0%E5%88%8A\");\n //sjis変換\n $domDocument = new DOMDocument();\n $domDocument->loadHTML($html);\n $xmlString = $domDocument->saveXML();\n $xmlObject = simplexml_load_string($xmlString);\n var_dump($xmlObject);\n \n```\n\n結果\n\n```\n\n bool(false)\n \n```\n\nとなる。 \n別にamazon以外のサイトでやってみたらちゃんと整形されたものが出てきました。 \nこの違いはなんなのでしょうか?", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T08:15:09.400", "favorite_count": 0, "id": "11112", "last_activity_date": "2015-06-09T00:05:45.190", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10049", "post_type": "question", "score": 0, "tags": [ "php", "api" ], "title": "phpでAmazonのHTMLを取得してasinコードを取得したい", "view_count": 518 }
[ { "body": "## 概要\n\n質問のコメントにもありますが、例示されたURLで試すと、パースエラーが発生します。 \nAmazon が返す HTML に文法エラーがあるためです。\n\nこういったエラーがあるものを何とか通す方法はちょっと思い付かないので、原因の指摘のみで。\n\n## 詳細\n\n手持ちの環境 (PHP 5.6.9-pl0-gentoo) では、以下のエラーが発生しました (長いので最初の部分だけ)。\n\n```\n\n PHP Warning: simplexml_load_string(): Entity: line 1771: parser error : Double hyphen within comment: <!--\n <div id=\"main\" skeleton-key=\"results in php shell code on line 1\n \n Warning: simplexml_load_string(): Entity: line 1771: parser error : Double hyphen within comment: <!--\n <div id=\"main\" skeleton-key=\"results in php shell code on line 1\n PHP Warning: simplexml_load_string(): <div id=\"main\" skeleton-key=\"results--searchTemplate defaultLayout so_jp_ja--lef in php shell code on line 1\n \n```\n\n該当部分の XML を見ると、コメント `<!--` と `\\-->` の間に `\\--`\nが出現しているため、不正なコメントとなっています。このため、パースエラーが発生します。 \n試しに、このXMLソースから、該当部分の `<!--` から `\\-->` までを削除すると、パースに成功します。 \n(`\\--` を含んではならないという制限 (SGMLとの兼ね合いによるもの)、割と忘れられがちですよね。)\n\n## エラー原因の調査方法\n\n今回は、エラーが発生するコード断片まで分かっているのですから、 `php -a` による対話的シェルを起動して、一行ずつ実行し、適宜\n`var_dump()` で変数の内容を確認していけば\n(長ければファイルに書き出すのも手)、簡単に原因に辿り着けたと思います。実際、私はそういった方法で原因を把握しました。 \n今回の例では、 `$domDocument->loadHTML($html);` と `$xmlObject =\nsimplexml_load_string($xmlString);`\nで警告・エラーメッセージが表示されるので、HTMLがおかしいとすぐ気付けるかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T13:32:00.860", "id": "11127", "last_activity_date": "2015-06-08T13:32:00.860", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7831", "parent_id": "11112", "post_type": "answer", "score": 2 }, { "body": "人間用のHTMLをパースしてデータを取得するのはたいていの場合筋が悪い方法なので、APIを使うべきです。検索結果から商品を調べたいようですが、[Product\nAdvertising\nAPI](https://affiliate.amazon.co.jp/gp/advertising/api/detail/main.html)がたぶん使えるでしょう。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T00:05:45.190", "id": "11141", "last_activity_date": "2015-06-09T00:05:45.190", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "11112", "post_type": "answer", "score": 1 } ]
11112
null
11127
{ "accepted_answer_id": null, "answer_count": 1, "body": "jQueryプラグインを作ったのですが、読み込む必要がある画像の配置場所に迷っています。 \n普通にフォルダに配置するものでしょうか? \n読み込む画像は一つなのでいっそBase64でエンコードして埋め込んでしまおうかとも思ったのですが、それも微妙かな、と。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T08:27:48.393", "favorite_count": 0, "id": "11113", "last_activity_date": "2015-08-08T00:15:43.073", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "post_type": "question", "score": 1, "tags": [ "javascript", "jquery" ], "title": "jQueryプラグイン作成時の画像の場所", "view_count": 76 }
[ { "body": "画像の内容によりけりですが、ある程度の大きさの画像をdataurlで持つとブラウザによって出たり出なかったりなどつまらないことで頭を悩ませる必要があり、いわゆるイメージファイルをdataurlに入れる構造のプラグインにするのはあまりお勧めできない気がします。 \n文字の背景にボーダー柄を設定したい、と言った場合にはCanvasに1ピクセルづつ色を付けてbase64に変換し、cssで引き延ばすようにしています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T23:20:44.427", "id": "11137", "last_activity_date": "2015-06-08T23:20:44.427", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8136", "parent_id": "11113", "post_type": "answer", "score": 1 } ]
11113
null
11137
{ "accepted_answer_id": null, "answer_count": 0, "body": "monacaでスマホアプリを製作中です。 \nタブバーとナビゲーターを使って、TOPページ、ECページ、他数ページのアプリです。\n\nECページで、別ドメインのサイトをiFrameに埋め込み、進むボタンと戻るボタンをつけています。\n\n```\n\n <p id=\"iframe-back\" class=\"iframe-control\"><a href=\"JavaScript:frames['iFrame名'].history.back()\"><ons-icon icon=\"ion-ios-arrow-back\"></ons-icon></a></p>\n <p id=\"iframe-forward\" class=\"iframe-control\"><a href=\"JavaScript:frames['iFrame名'].history.forward()\"><ons-icon icon=\"ion-ios-arrow-forward\"></ons-icon></a></p>\n \n```\n\nAndroidでは挙動は正常なのですが、iOSで動かした時、TOPページから1ページ遷移し、 \n戻るボタンを押すと、アプリのトップに移動してしまいます。\n\nお分かりの方おられましたら、ご教授いただけますと幸いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T09:03:41.750", "favorite_count": 0, "id": "11115", "last_activity_date": "2015-06-08T09:03:41.750", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10052", "post_type": "question", "score": 1, "tags": [ "javascript", "monaca", "html5" ], "title": "iOSでのiFrameのhistory.back()の挙動について", "view_count": 709 }
[]
11115
null
null
{ "accepted_answer_id": null, "answer_count": 2, "body": "Xcode6,Objective-cで縦画面と横画面をボタンで切り替えられるアプリを作っています。 \n(縦画面と横画面ではデザインも機能も異なります。) \n縦画面時はホームボタン下(Portrait)で固定し、 \n横画面時は回転に伴い、ホームボタン右(LandScapeRight)と \nホームボタン左(LandScapeLeft)の回転を許可したいです。\n\nデバイスの回転はshouldAutorotateで管理しています。\n\n```\n\n @implementation UINavigationController (rotateControl)\n \n - (NSUInteger)supportedInterfaceOrientations\n {\n return [self.visibleViewController supportedInterfaceOrientations];\n }\n \n - (BOOL)shouldAutorotate\n {\n return YES;\n }\n \n @end\n \n```\n\n縦画面時はPortraitで固定しています。\n\n```\n\n - (NSUInteger)supportedInterfaceOrientations\n {\n return UIInterfaceOrientationMaskPortrait;\n }\n \n```\n\n横画面時はLandscapeで固定しています。\n\n```\n\n - (NSUInteger)supportedInterfaceOrientations\n {\n return UIInterfaceOrientationMaskLandscape;\n }\n \n```\n\n横画面時はステータスバー(デバイス)の向きに伴い \n横画面の上下回転をさせたいので \nアプリケーションの環境設定のDevice Orientationに \n\"Landscape Left\"と\"Landscape Right\"にチェックをつけています。\n\n![画像の説明をここに入力](https://i.stack.imgur.com/oVB23.png)\n\nしかし、iPhone6Plus(iOS8)の実機で動かすと \n横画面時に、180度回転させると、 \nステータスバーの位置は常に上にくるように移動するのですが、 \nそれに伴いUIViewが回転せず、固定されたままになってしまいます。 \n(iOS7のiPhone5実機、iPhone6およびiPhone6Plusのシミュレータでは期待動作です。)\n\nステータスバー(デバイス)の回転に伴い \n横画面の上下回転をさせるにはどうしたらよろしいでしょうか・・・ \nここ何日も詰まっていて困っています・・・ \nよろしくお願いいたします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T09:04:02.530", "favorite_count": 0, "id": "11116", "last_activity_date": "2015-06-22T01:04:30.190", "last_edit_date": "2015-06-09T06:09:28.427", "last_editor_user_id": "10053", "owner_user_id": "10053", "post_type": "question", "score": 4, "tags": [ "objective-c", "xcode6", "ios8" ], "title": "iOS8で横画面回転時に、デバイスの回転にともなってViewが回転せず、固定されてしまう", "view_count": 3364 }
[ { "body": "プログラムで操作する以前に、アプリケーションの環境設定で、180度回転を有効にしましょう。\n\n![画像の説明をここに入力](https://i.stack.imgur.com/tqhDQ.png)\n\n「Device Orientation」が、デフォルトでは **Upside Down** が無効になっているので、チェックを入れて、有効にしましょう。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T09:38:05.793", "id": "11118", "last_activity_date": "2015-06-08T09:38:05.793", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7362", "parent_id": "11116", "post_type": "answer", "score": 1 }, { "body": "どうやらiOS8のiPhone6PlusおよびiPad特有の事象のようです。\n\nデバイスの回転はNSNotificationCenterクラスで検知し、 \nデバイス回転時にViewにアフィン変換の回転アニメーションをつけることで \nデバイスの回転に伴いViewも回転させるようにしました。\n\n```\n\n [UIView animateWithDuration:0.5f // アニメーション速度\n delay:0.0f // 何秒後にアニメーションするか\n options:UIViewAnimationOptionCurveEaseIn\n animations:^{\n // ビューを180度回転\n float angle = 180.0 * M_PI / 180;\n CGAffineTransform t2 = CGAffineTransformRotate(t1, angle);\n \n } completion:^(BOOL finished) {\n // アニメーション終了時\n NSLog(@\"アニメーション終了\");\n }];\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-22T01:04:30.190", "id": "11590", "last_activity_date": "2015-06-22T01:04:30.190", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10075", "parent_id": "11116", "post_type": "answer", "score": 1 } ]
11116
null
11118
{ "accepted_answer_id": "11125", "answer_count": 1, "body": "アプリ制作のためにXcodeでC++を使っています。boost::optionalを使用していますが、\n\n> '...' is a protected member of \n> 'boost::optional_detail::optional_base>'\n\nというエラーが8個出ます。...は、以下のtypedefのvalue_type, reference_type, ... にあたります。\n\n```\n\n template<class T>\n class optional : public optional_detail::optional_base<T>\n {\n typedef optional_detail::optional_base<T> base ;\n \n public :\n \n typedef optional<T> this_type ;\n \n typedef BOOST_DEDUCED_TYPENAME base::value_type value_type ;\n typedef BOOST_DEDUCED_TYPENAME base::reference_type reference_type ;\n typedef BOOST_DEDUCED_TYPENAME base::reference_const_type reference_const_type ;\n #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES\n typedef BOOST_DEDUCED_TYPENAME base::rval_reference_type rval_reference_type ;\n typedef BOOST_DEDUCED_TYPENAME base::reference_type_of_temporary_wrapper reference_type_of_temporary_wrapper ;\n #endif\n typedef BOOST_DEDUCED_TYPENAME base::pointer_type pointer_type ;\n typedef BOOST_DEDUCED_TYPENAME base::pointer_const_type pointer_const_type ;\n typedef BOOST_DEDUCED_TYPENAME base::argument_type argument_type ;\n \n```\n\nまた、my_template_classですが、\n\n```\n\n template<class T> class my_template_class\n {\n private:\n T member_;\n ...\n }\n \n```\n\nという風に定義されていて、\n\n> Field has incomplete type 'テンプレート引数に入れたクラス名'\n\nというコンパイルエラーも出ています。どのように解決すればよいでしょうか。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T10:17:46.560", "favorite_count": 0, "id": "11122", "last_activity_date": "2015-06-08T11:04:53.047", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10054", "post_type": "question", "score": 1, "tags": [ "c++", "boost" ], "title": "boost::optional 使用時のコンパイルエラー 'value_type' is a protected member of 'boost::optional_detail::optional_base<my_template_class<my_class>>'", "view_count": 280 }
[ { "body": "コメントと同じものですが、ここに書かさせていただきます。 \nstd::shared_ptrを使用していたものをboost::optionalに変更した時に起きたので、Tの型のサイズが決定できなくなってしまったことが問題で‌​した。ありがとうございました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T11:04:53.047", "id": "11125", "last_activity_date": "2015-06-08T11:04:53.047", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10054", "parent_id": "11122", "post_type": "answer", "score": 2 } ]
11122
11125
11125
{ "accepted_answer_id": null, "answer_count": 1, "body": "どうやって確認していいのかわからず、専門家の知見を拝借させてください。\n\n仕事でphalconを使い始めました。英語マニュアルと格闘しながらModel周りを作っているのですが、例えばこんなコードではbindがうまく動いてくれませんでした。\n\n```\n\n $criteria = self::query();\n $criteria->betweenWhere('created', \":start:\", \":end:\");\n $criteria->bind(array(\"start\" => $start, \"end\" => $end));\n $criteria->bindTypes(\n array(\"start\"=>Column::TYPE_DATETIME,\"end\"=>Column::TYPE_DATETIME)\n );\n $row = $criteria->execute();\n \n```\n\n実行時のエラー\n\n```\n\n PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in\n \n```\n\nですが、以下のコードであれば正常に動作します。\n\n```\n\n $criteria = self::query();\n $criteria->where('created between :start: and :end:');\n $criteria->bind(array(\"start\" => $start, \"end\" => $end));\n $row = $criteria->execute();\n \n```\n\nで、これも動きます\n\n```\n\n $criteria = self::query();\n $criteria->betweenWhere('created', $start, $end);\n $row = $criteria->execute();\n \n```\n\nこれはつまり、betweenWhereはautobindしてくれているということでしょうか? \nであればSQLインジェクション対策としてそれに頼りたいと思うのですが、 \n実際のところどうなんでしょうか? \nご教授くださいm(__)m", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T10:26:41.360", "favorite_count": 0, "id": "11123", "last_activity_date": "2016-04-26T02:34:40.353", "last_edit_date": "2015-06-30T06:34:41.030", "last_editor_user_id": "8936", "owner_user_id": "8936", "post_type": "question", "score": 2, "tags": [ "php" ], "title": "phalcon のCriteriaのbetweenWhereはautobindなんでしょうか?", "view_count": 299 }
[ { "body": "自動バインドされている、というドキュメントの記述は見つけられませんでしたが、 Phalcon のソースコードを見たところ、次のような PHP\nコードと対応するようです。\n\n```\n\n $minimumKey = ...; $maxmumKey = ...;\n \n $criteria->andWhere(\n $expr . \" BETWEEN :\" . $minimumKey . \": AND :\" . $maximumKey . \":\",\n [$minimumKey => $minimum, $maximumKey => $maximum]\n );\n \n```\n\nZephier という PHP に似た言語で書かれているので、比較的読みやすいかと思います。\n\n<https://github.com/phalcon/cphalcon/blob/phalcon-v2.0.2/phalcon/mvc/model/criteria.zep#L381>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T10:55:17.167", "id": "11124", "last_activity_date": "2015-06-08T10:55:17.167", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "parent_id": "11123", "post_type": "answer", "score": 1 } ]
11123
null
11124
{ "accepted_answer_id": "11130", "answer_count": 1, "body": "OSはOS 10.10.1 Yosemete \npythonのバージョンは3.4.3 \nです。\n\n現在、mecab-pythonをインストールするためにpython-devをインストールしようとしています。\n\nしかし、ターミナルで \nbrew install python-dev \nと打っても \nError: No available formula for python-dev \nSearching formulae... \nSearching taps... \nと出てきて、\n\nsudo port install python-dev \nと打っても \nError: Port python-dev not found \nと出て来ます。 \npython3-devで試してもだめでした。\n\nどうしたらインストールできるんでしょうか・・・ \n助けてくださいよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T13:49:23.537", "favorite_count": 0, "id": "11128", "last_activity_date": "2015-06-09T03:07:10.187", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9610", "post_type": "question", "score": 1, "tags": [ "python" ], "title": "python-devがインストールできません", "view_count": 4923 }
[ { "body": "ヘッダーファイルはすでにインストールされているはずです。次のコマンドを実行してみてください。Pythonのヘッダーファイルがどこにあるかを,Cコンパイラのオプションとして出力します。\n\n`python-config --include`\n\nmecabについてはこちらでテストしていませんが、次のようにしてCコンパイラのオプションを引き渡してconfigureを実行します。\n\n`CFLAGS=$(python-config --include) ./configure`\n\nこの後`make`すればコンパイルが通るはずです。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T14:32:40.447", "id": "11130", "last_activity_date": "2015-06-09T03:07:10.187", "last_edit_date": "2015-06-09T03:07:10.187", "last_editor_user_id": "7837", "owner_user_id": "7837", "parent_id": "11128", "post_type": "answer", "score": 1 } ]
11128
11130
11130
{ "accepted_answer_id": "11138", "answer_count": 1, "body": "ruby初心者です。\n\nクラスインスタンス変数について勉強しております。 \nclass << self; endで定義した@valですが、 \nクラスの先頭で定義した@val = 10とは違うインスタンスのようです。\n\nclass << クラス名; end はクラスメソッドを定義するイディオムである \n認識なので、@valはクラスインスタンス変数であると思うのですが違うのでしょうか\n\n```\n\n class Ins\n @val = 10\n \n def foo\n @val\n end\n \n class << self\n @val = 15 #=> クラスインスタンス変数を参照しているようにみえる\n \n def bazz\n @val\n end\n end\n end\n \n class << Ins\n # puts self.bazz NoMethodErrorが発生する\n puts @val #=> ここでは15が出力される\n end\n \n puts Ins.bazz #=> ここでは10が出力される\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T14:11:40.390", "favorite_count": 0, "id": "11129", "last_activity_date": "2015-06-08T23:35:08.443", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8722", "post_type": "question", "score": 2, "tags": [ "ruby" ], "title": "特異クラスのインスタンス変数について", "view_count": 444 }
[ { "body": "次のコードを実行すると1個目の self と2個目の self が異なることがわかります。\n\n```\n\n class Ins\n p self #=> Ins\n class << Ins\n p self #=> #<Class:Ins>\n end\n end\n \n```\n\n`class << Ins` は Ins の特異クラスであり、Ins とは別のクラスです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T23:35:08.443", "id": "11138", "last_activity_date": "2015-06-08T23:35:08.443", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3249", "parent_id": "11129", "post_type": "answer", "score": 1 } ]
11129
11138
11138
{ "accepted_answer_id": null, "answer_count": 1, "body": "初学者です。\n\ndeviseでは、標準で「id」があり、これは、1.2.3.4...と、登録順になるとおもうのですが、\n\nこれとは、別に、「userid」というカラムを追加して、これを会員登録時に自動で生成したいと思っています。\n\n9桁の乱数は、\n\n```\n\n n = 9\n format(\"%0#{n}d\", SecureRandom.random_number(10**n))\n \n```\n\nで作成しようと、思っています。\n\nこれを、どこに、どのように書けば、ユーザー情報として登録されるのでしょうか。\n\nお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T15:09:47.310", "favorite_count": 0, "id": "11131", "last_activity_date": "2015-06-08T23:56:18.743", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10056", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "devise" ], "title": "Rails4+deviseで、乱数9桁のユーザーIDを生成する方法", "view_count": 940 }
[ { "body": "モデルクラスでコールバックを使うのがよいでしょう。コールバックについては例えば[Active Record コールバック -\nRailsガイド](http://railsguides.jp/active_record_callbacks.html)に説明があります。\n\n```\n\n class User < ActiveRecord::Base\n before_create :generate_userid\n \n private\n def generate_userid\n self.userid = (ユーザーIDを生成)\n end\n end\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T23:56:18.743", "id": "11140", "last_activity_date": "2015-06-08T23:56:18.743", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "11131", "post_type": "answer", "score": 1 } ]
11131
null
11140
{ "accepted_answer_id": "11213", "answer_count": 1, "body": "下記ソースコードでメソッドから[minizip](https://github.com/nmoinvaz/minizip)のunzip.cにある \nunzOpen2メソッドをバイトデータを解凍したところ、 \n圧縮前のサイズと一致している事はunz64local_GetCurrentFileInfoInternalメソッドの \nfile_info.uncompressed_sizeで確認できたのですが \n解析しても解凍後のデータがどこに保存されているのかわからず悩んでおります。\n\nZipFormatのように、特定のビットにデータが格納されるのでしょうか? \n<http://ja.wikipedia.org/wiki/ZIP_%28%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88%29> \n \n開発環境:MacOSX 10.10.3、xCode6.3.2、Objective-c\n\n```\n\n void uncompressByGzip(const char** ptrSrc, const int srcLength)\n {\n unz64_s unz64data;\n unzFile unzfiledata;\n \n unsigned long long int readdatasize;\n \n zlib_filefunc_def filefunc32 = {0};\n ourmemory_t unzmem = {0};\n \n unzmem.size = srcLength;\n unzmem.base = (char *)malloc(unzmem.size);\n memcpy(unzmem.base, ptrSrc, unzmem.size);\n \n fill_memory_filefunc(&filefunc32, &unzmem);\n unzfiledata = unzOpen2(\"__notused__\", &filefunc32);\n \n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T16:03:24.550", "favorite_count": 0, "id": "11132", "last_activity_date": "2015-07-15T01:05:22.520", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5261", "post_type": "question", "score": 1, "tags": [ "objective-c", "c++" ], "title": "minizipで解凍した実体がどこにあるのかわかりません。", "view_count": 613 }
[ { "body": "unzOpen2()を実行しただけでは解凍できません。 \nminizipでzip内のファイルを解凍するには以下の手順が必要です。\n\n(1) zipファイルをオープンする。\n\n```\n\n unzfiledata = unzOpen2(...)\n \n```\n\n(2) zip 内の解凍したいファイルPATHを指定する。\n\n```\n\n unzLocateFile(unzfiledata, ...)\n \n```\n\nzip内に1ファイルしかない場合は、\n\n```\n\n unzGoToFirstFile(unzfiledata)\n \n```\n\n(3) (2)で指定したzip内のファイルをオープンする\n\n```\n\n unzOpenCurrentFile(unzfiledata)\n \n```\n\n(4) (3)でオープンしたzip内のファイルを読取バッファに読み込む\n\n```\n\n unzReadCurrentFile(unzfiledata, ...)\n \n```\n\n(5) (3)でオープンしたzip内のファイルをクローズする。\n\n```\n\n unzCloseCurrentFile(unzfiledata)\n \n```\n\n※zip内の複数ファイルを読みたい場合は(2)~(5)を取得するzip内のファイル数分繰り返す。\n\n(6) (1)でオープンしたzipファイルをクローズする。\n\n```\n\n unzClose(unzfiledata)\n \n```\n\n※zipは複数ファイルを格納可能なためzip内のどのファイルを処理対象とするか(この質問の場合は読み込みたいか)を指定する必要があります。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T08:03:48.057", "id": "11213", "last_activity_date": "2015-07-15T01:05:22.520", "last_edit_date": "2015-07-15T01:05:22.520", "last_editor_user_id": "7343", "owner_user_id": "7343", "parent_id": "11132", "post_type": "answer", "score": 2 } ]
11132
11213
11213
{ "accepted_answer_id": "11198", "answer_count": 1, "body": "お世話になります \niOS7対応のswiftのコードで、uiviewに対して枠線をつけたいのですが、 \nうまくいかず困っております\n\n```\n\n self.layer.borderColor = UIColor.blackColor().CGColor\n self.layer.borderWidth = 1.0\n \n```\n\nおそらく上記はiOS8でしか動かなようでして。。。 \nquartzcoreを明示的にインポートしたらうまくいくかなって思いましたがダメでした。\n\n以下エラーを吐きます\n\n```\n\n 2015-06-09 13:54:59.860 shotworks_for_ph2_by_swift[43366:607] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x7fc5e04d86c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key borderColor.'\n *** First throw call stack:\n (\n 0 CoreFoundation 0x000000010d435495 __exceptionPreprocess + 165\n 1 libobjc.A.dylib 0x000000010d19499e objc_exception_throw + 43\n 2 CoreFoundation 0x000000010d4b9919 -[NSException raise] + 9\n 3 Foundation 0x000000010cd75530 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259\n 4 UIKit 0x000000010d716569 -[UIView(CALayerDelegate) setValue:forKey:] + 149\n 5 CoreFoundation 0x000000010d431400 -[NSArray makeObjectsPerformSelector:] + 224\n 6 UIKit 0x000000010d911893 -[UINib instantiateWithOwner:options:] + 1112\n 7 UIKit 0x000000010d78044b -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 302\n 8 UIKit 0x000000010d7806b6 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 44\n 9 shotworks_for_ph2_by_swift 0x000000010b02bc3b _TFC26shotworks_for_ph2_by_swift13EasySearchVCL9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 1163\n 10 shotworks_for_ph2_by_swift 0x000000010b02bd2f _TToFC26shotworks_for_ph2_by_swift13EasySearchVCL9tableViewfS0_FTCSo11UITableView21cellForRowAtIndexPathCSo11NSIndexPath_CSo15UITableViewCell + 79\n 11 UIKit 0x000000010d78af8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348\n 12 UIKit 0x000000010d770d5b -[UITableView _updateVisibleCellsNow:] + 2337\n 13 UIKit 0x000000010d782721 -[UITableView layoutSubviews] + 207\n 14 UIKit 0x000000010d716993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354\n 15 QuartzCore 0x000000010c7dd802 -[CALayer layoutSublayers] + 151\n 16 QuartzCore 0x000000010c7d2369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363\n 17 UIKit 0x000000010d70af70 -[UIView(Hierarchy) layoutBelowIfNeeded] + 521\n 18 UIKit 0x000000010d7cd7d6 -[UINavigationController _layoutViewController:] + 1077\n 19 UIKit 0x000000010d7cb0b4 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 395\n 20 UIKit 0x000000010d6fb68e -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 235\n 21 UIKit 0x000000010d6fa184 +[UIViewAnimationState popAnimationState] + 281\n 22 UIKit 0x000000010d991f7a -[UINavigationTransitionView transition:fromView:toView:] + 2504\n 23 UIKit 0x000000010d9915b0 -[UINavigationTransitionView transition:toView:] + 25\n 24 UIKit 0x000000010d7ce4d7 -[UINavigationController _startTransition:fromViewController:toViewController:] + 2893\n 25 UIKit 0x000000010d7ce787 -[UINavigationController _startDeferredTransitionIfNeeded:] + 547\n 26 UIKit 0x000000010d7cf238 -[UINavigationController __viewWillLayoutSubviews] + 43\n 27 UIKit 0x000000010d8e9895 -[UILayoutContainerView layoutSubviews] + 202\n 28 UIKit 0x000000010d716993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354\n 29 QuartzCore 0x000000010c7dd802 -[CALayer layoutSublayers] + 151\n 30 QuartzCore 0x000000010c7d2369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363\n 31 QuartzCore 0x000000010c7dd736 -[CALayer layoutIfNeeded] + 162\n 32 UIKit 0x000000010d7bca22 -[UIViewController window:setupWithInterfaceOrientation:] + 264\n 33 UIKit 0x000000010d6f3cad -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 4360\n 34 UIKit 0x000000010d6f2b9f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 36\n 35 UIKit 0x000000010d6f2aef -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 101\n 36 UIKit 0x000000010d6f1dfe -[UIWindow _updateToInterfaceOrientation:duration:force:] + 377\n 37 UIKit 0x000000010d7b070a -[UIViewController _tryBecomeRootViewControllerInWindow:] + 147\n 38 UIKit 0x000000010d6ecb1b -[UIWindow addRootViewControllerViewIfPossible] + 490\n 39 UIKit 0x000000010d6ecc70 -[UIWindow _setHidden:forced:] + 282\n 40 UIKit 0x000000010d6f5ffa -[UIWindow makeKeyAndVisible] + 51\n 41 UIKit 0x000000010d6b1c98 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1788\n 42 UIKit 0x000000010d6b5a0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660\n 43 UIKit 0x000000010d6c6d4c -[UIApplication handleEvent:withNewEvent:] + 3189\n 44 UIKit 0x000000010d6c7216 -[UIApplication sendEvent:] + 79\n 45 UIKit 0x000000010d6b7086 _UIApplicationHandleEvent + 578\n 46 GraphicsServices 0x000000010f56c71a _PurpleEventCallback + 762\n 47 GraphicsServices 0x000000010f56c1e1 PurpleEventCallback + 35\n 48 CoreFoundation 0x000000010d3b7679 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41\n 49 CoreFoundation 0x000000010d3b744e __CFRunLoopDoSource1 + 478\n 50 CoreFoundation 0x000000010d3e0903 __CFRunLoopRun + 1939\n 51 CoreFoundation 0x000000010d3dfd83 CFRunLoopRunSpecific + 467\n 52 UIKit 0x000000010d6b52e1 -[UIApplication _run] + 609\n 53 UIKit 0x000000010d6b6e33 UIApplicationMain + 1010\n 54 shotworks_for_ph2_by_swift 0x000000010b065ea7 main + 135\n 55 libdyld.dylib 0x000000010edd75c9 start + 1\n )\n libc++abi.dylib: terminating with uncaught exception of type NSException\n (lldb) bt\n * thread #1: tid = 0x19618a, 0x000000010ef04286 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT\n frame #0: 0x000000010ef04286 libsystem_kernel.dylib`__pthread_kill + 10\n frame #1: 0x000000010eed142f libsystem_pthread.dylib`pthread_kill + 90\n frame #2: 0x000000010ec32e59 libsystem_sim_c.dylib`abort + 101\n frame #3: 0x000000010ea88bf3 libc++abi.dylib`abort_message + 195\n frame #4: 0x000000010eaae51e libc++abi.dylib`default_terminate_handler() + 264\n frame #5: 0x000000010d194bfe libobjc.A.dylib`_objc_terminate() + 103\n frame #6: 0x000000010eaabe91 libc++abi.dylib`std::__terminate(void (*)()) + 8\n frame #7: 0x000000010eaabb3d libc++abi.dylib`__cxa_rethrow + 109\n frame #8: 0x000000010d194b11 libobjc.A.dylib`objc_exception_rethrow + 40\n frame #9: 0x000000010d3dfe34 CoreFoundation`CFRunLoopRunSpecific + 644\n frame #10: 0x000000010d6b52e1 UIKit`-[UIApplication _run] + 609\n frame #11: 0x000000010d6b6e33 UIKit`UIApplicationMain + 1010\n * frame #12: 0x000000010b065ea7 shotworks_for_ph2_by_swift`main + 135 at AppDelegate.swift:15\n frame #13: 0x000000010edd75c9 libdyld.dylib`start + 1\n frame #14: 0x000000010edd75c9 libdyld.dylib`start + 1\n (lldb)\n \n```\n\nどなたかお分かりになる方いらっしゃいますでしょうか\n\nよろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T16:39:28.117", "favorite_count": 0, "id": "11133", "last_activity_date": "2015-06-10T05:24:57.467", "last_edit_date": "2015-06-09T22:03:02.570", "last_editor_user_id": "403", "owner_user_id": "403", "post_type": "question", "score": 1, "tags": [ "ios", "swift", "uikit", "quartz" ], "title": "ios7対応のswiftコードでuiviewに枠線をつけたい", "view_count": 714 }
[ { "body": "エラーメッセージをちゃんと読むと、「UIViewクラスにはborderColorというキーがない」と書かれています(CALayerのborderColorを設定しようとしてエラーになったのではなく、UIViewのborderColorというキーを設定しようとして、それがなくてエラーになっています)。質問に書いたコードは`self.layer.borderColor`に対して設定していますが、もしかして、それとは別に対象Viewの設定でIdentity\ninspectorのUser Defined Runtime\nAttributesに、borderColorという誤ったキーを設定したゴミが残っていたりしませんか?(UIViewにborderColorというプロパティはありません。)\n\nUser Defined Runtime\nAttributesに不正キーが設定されていた場合、iOS8は警告ログが出力されて実行継続しますが、iOS7は例外で停止します。 \n質問に書かれたコード自体はiOS8でもiOS7でもちゃんと動作するはずです。\n\nUser Defined Runtime Attributesにゴミが残っているだけなら、それを削除するのが正しい対処だと思います。\n\n(6/10 14:15編集) \n自己回答は削除されたようなので、それに対するコメント部分は削除しました。また、CALayerのborderColorでなくUIViewのborderColorに対するアクセスでエラーになっていることを明確化し、他の人が見ても指摘ポイントが分かりやすいようにしました。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T00:00:25.740", "id": "11198", "last_activity_date": "2015-06-10T05:24:57.467", "last_edit_date": "2015-06-10T05:24:57.467", "last_editor_user_id": "9367", "owner_user_id": "9367", "parent_id": "11133", "post_type": "answer", "score": 3 } ]
11133
11198
11198
{ "accepted_answer_id": "11136", "answer_count": 1, "body": "お世話になります \nuicollectionviewを使っているのですが、iphone6だと隙間が空いてしまい、困っております \n<http://qiita.com/uro_uro_/items/6e86e6be575e22a6fb20> \nこの辺りを参考にやってるのですが、うまくいかずでして。。。 \nちなみにswiftでコードはこちらです\n\n```\n\n import UIKit\n \n class OtherKodawariVCL: GAViewController {\n \n @IBOutlet weak var baseview: UIScrollView!\n @IBOutlet weak var kodawariview: UICollectionView!\n weak var delegate: KodawariSearchVCLDelegate!\n var cell_width:CGFloat = 0\n let otherKodawariAry = [\"締切間近\",\"登録制\",\"研修なし\",\"平日のみ\",\"4時間以内\",\"交通費支給\",\"主婦・主夫歓迎\",\"高校生歓迎\",\"年齢不問\",\"制服あり\",\"服装自由\",\"髪型・カラー自由\",\"バイク・車通勤OK\",\"大量募集\",\"オープニングスタッフ\",\"紹介予定派遣\",\"駅近\",\"週払い\"]\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // Do any additional setup after loading the view.\n \n var nib = UINib(nibName: \"KodawariCell\", bundle:nil)\n self.kodawariview.registerNib(nib, forCellWithReuseIdentifier:\"KodawariCell\")\n self.kodawariview.reloadData()\n self.baseview.contentSize = CGSize(width: self.baseview.frame.size.width, height:CGFloat(480))\n let kodawari_width = self.kodawariview.frame.size.width\n cell_width = (kodawari_width-CGFloat(50))/2\n var device = UIDevice.currentDevice().model\n println(device)\n }\n \n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n // Dispose of any resources that can be recreated.\n }\n \n @IBAction func closeModal(sender: AnyObject) {\n self.dismissViewControllerAnimated(true, completion: nil)\n }\n @IBAction func decideKodawari(sender: AnyObject) {\n self.dismissViewControllerAnimated(true, completion: {\n self.delegate.doSearch()\n })\n }\n \n // MARK: - UICollectionViewDelegate Protocol\n func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {\n let cell:KodawariCell = collectionView.dequeueReusableCellWithReuseIdentifier(\"KodawariCell\", forIndexPath: indexPath) as! KodawariCell\n cell.check_text.text = otherKodawariAry[indexPath.row]\n //cell.check_image.image = UIImage(named: \"icon\")\n \n \n return cell\n }\n \n \n // func collectionView(_ collectionView: UICollectionView,\n // layout collectionViewLayout: UICollectionViewLayout,\n // sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize\n // {\n // \n // }\n \n func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {\n return 1\n }\n \n func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {\n return 18;\n }\n \n /*\n // MARK: - Navigation\n \n // In a storyboard-based application, you will often want to do a little preparation before navigation\n override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {\n // Get the new view controller using segue.destinationViewController.\n // Pass the selected object to the new view controller.\n }\n */\n \n }\n \n```\n\nよろしくお願いします。![画像の説明をここに入力](https://i.stack.imgur.com/1rguU.png)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T17:38:59.397", "favorite_count": 0, "id": "11134", "last_activity_date": "2015-06-08T22:28:02.317", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "403", "post_type": "question", "score": 0, "tags": [ "swift", "uicollectionview", "uicollectionviewcell" ], "title": "collectionviewの隙間を埋めたい", "view_count": 1623 }
[ { "body": "解決しました。お騒がせしました\n\n```\n\n func collectionView(_ collectionView: UICollectionView,\n layout collectionViewLayout: UICollectionViewLayout,\n sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize\n {\n let width = (self.kodawariview.frame.size.width-10)/2\n \n return CGSize(width: width, height: 50)\n }\n \n```\n\nこのメソッド内でうまく調整すればよかったみたいです", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T22:28:02.317", "id": "11136", "last_activity_date": "2015-06-08T22:28:02.317", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "403", "parent_id": "11134", "post_type": "answer", "score": 0 } ]
11134
11136
11136
{ "accepted_answer_id": null, "answer_count": 1, "body": "お世話になります。\n\nnode.jsでwebサーバーを作ったのですが、ウェブページにアクセスできません。(ブラウザに表示できません)\n\nファイル名 server.js\n\n```\n\n var http = require('http');\n var server = http.createServer();\n server.on('request', function(req, res) {\n res.writeHead(200, {'Content-Type': 'text/plain'});\n res.write('hello world');\n res.end();\n });\n \n server.listen(1337, '127.0.0.1');\n console.log(\"server listening ...\");\n \n```\n\nターミナルでの表示結果\n\n```\n\n [vagrant@localhost nodejs]$ node server.js\n \n server listening ...\n \n```\n\nlocalhost:1337でアクセスしたのですが、ブラウザ(chrome)にはこのウェブページにアクセスできませんと表示されてしまいます。\n\nアドバイスを頂いた通りを実行したところ下記の問題が発生しました。\n\n```\n\n [vagrant@localhost nodejs]$ curl http://localhost:1337/\n curl: (7) couldn't connect to host\n \n```\n\n常時プロキシを設定するには以下の通りにする良いと書いてあったので試してみましたがviが書き込み禁止と認識しているみたいです。\n\n```\n\n # vi /etc/bashrc\n \n (viで開いたので、一番最後の行とかに以下を追記)\n \n alias curl=\"curl -x http://proxy.jpn.hp.com:8080/\"\n \n (:wqで保存して終了)\n \n```\n\nchmodを使用してファイルの変更をするみたいなのですが、どのファイル(bashrc?)にどのようにして書き込むのか教えて下さい。\n\nよろしくお願い致します。", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-08T19:54:02.780", "favorite_count": 0, "id": "11135", "last_activity_date": "2015-06-09T07:11:20.773", "last_edit_date": "2015-06-09T07:11:20.773", "last_editor_user_id": "8149", "owner_user_id": "8149", "post_type": "question", "score": 0, "tags": [ "node.js" ], "title": "node.jsでwebサーバーを作ったのだがウェブページにアクセスできない", "view_count": 9883 }
[ { "body": "仮想環境で実行されているようですので、その環境のネットワークの問題かもしれません。 \nまずは下記のように同じ環境からのアクセスを試して見ましょう。\n\n```\n\n node server.js &\n curl http://localhost:1337/\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T06:15:16.117", "id": "11162", "last_activity_date": "2015-06-09T06:15:16.117", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "11135", "post_type": "answer", "score": 1 } ]
11135
null
11162
{ "accepted_answer_id": "11153", "answer_count": 1, "body": "MacOSXでは`command+control+f`のショートカットキーでウインドウのフルスクリーン切り替えを行うことができますが、emacsではキーの優先度が奪われてしまうためか、フルスクリーン切り替えを行うことができません\n\n```\n\n (kbd \"<C-s-268632070>\")\n \n```\n\n上記のコードでcommand+control+fのキーを判定することができるところまではわかったのですが、emacsからMacOSXのキーボードショートカットを実行する方法としてどういったものが考えられるでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T00:06:44.843", "favorite_count": 0, "id": "11142", "last_activity_date": "2015-06-09T04:00:37.387", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5840", "post_type": "question", "score": 1, "tags": [ "macos", "emacs" ], "title": "emacsでMacOSXのショートカットキーをバインドする方法", "view_count": 137 }
[ { "body": "こんなんでいかがでしょう \n`(global-set-key (kbd \"<C-s-268632070>\") 'toggle-frame-fullscreen)`\n\nここを参照しました。 \n<http://emacswiki.org/emacs/FullScreen#toc26>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T04:00:37.387", "id": "11153", "last_activity_date": "2015-06-09T04:00:37.387", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7837", "parent_id": "11142", "post_type": "answer", "score": 2 } ]
11142
11153
11153
{ "accepted_answer_id": "11174", "answer_count": 1, "body": "こんにちは!\n\nScalaでバッチ処理を実装したいのですが、 \n用途としてはDBに保存されているデータの日付型を確認し、現在時間がその日付を超えたらある処理を行う、のようにしたいです。\n\nあるいはサーバー側でそのような処理が行えるのなら、それも知りたいです。\n\nPlay Framework 2.3.x \nScala 2.11.6", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T01:19:51.447", "favorite_count": 0, "id": "11144", "last_activity_date": "2015-08-08T10:24:16.437", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9328", "post_type": "question", "score": 1, "tags": [ "mysql", "scala", "playframework" ], "title": "Scala バッチ処理で定期的にDB(MySQL)のデータを確認したい", "view_count": 545 }
[ { "body": "事故解決 \nonStartで実行時にスケジューラを起動\n\n```\n\n object Global extends GlobalSettings {\n override def onStart(app: Application) {\n \n Logger.info(\"Application has started for \" + app.mode + \" mode.\")\n \n val scheduler = QuartzSchedulerExtension(Akka.system)\n scheduler.schedules.foreach {\n case (key, setting) =>\n scheduler.schedule(\n setting.name,\n ${setting.name}\"))),\n setting.description.getOrElse(setting.name)\n )\n }\n \n }\n \n```\n\n参考: \n<http://qiita.com/rynkjm/items/ba356459f8da1d3e0ddf> \n<http://tech.aainc.co.jp/archives/9620>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T08:12:50.050", "id": "11174", "last_activity_date": "2015-06-09T08:12:50.050", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9328", "parent_id": "11144", "post_type": "answer", "score": 1 } ]
11144
11174
11174
{ "accepted_answer_id": null, "answer_count": 0, "body": "ハッシュタグからデータを取得します。 \nハッシュタグに関連する画像は18件あります。 \n(件数指定しない場合18件返ってくるということです)\n\n>\n> <https://api.instagram.com/v1/tags/>{hash_tag}/media/recent?client_id={id}&count=12\n\n上記で試すと正常?に動作するようで、ページングも可能となります。 \n12件取得、次に6件取得とできます。\n\n>\n> <https://api.instagram.com/v1/tags/>{hash_tag}/media/recent?client_id={id}&count=15\n\n件数指定を15件に設定した場合問題があり、 \nこの場合、全件(18件)データが返ってきます。\n\n投稿総数の多いハッシュタグで試すと問題なさそうだったりと、 \n件数指定が効かないケースのパターンがわかりません。\n\nこれが明確に API のバグなら仕様がないですが、 \n何か他のパラメーター不足などから起きている現象でしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T01:53:28.267", "favorite_count": 0, "id": "11145", "last_activity_date": "2015-06-09T01:53:28.267", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8704", "post_type": "question", "score": 1, "tags": [ "javascript", "api", "instagram" ], "title": "インスタグラム API での件数指定(count)が正常に機能しない?", "view_count": 761 }
[]
11145
null
null
{ "accepted_answer_id": "11152", "answer_count": 1, "body": "C系の文法を持つ言語については以下のような記述が可能であると思います。\n\n```\n\n while (foo) if (hoge) {\n ...\n }\n \n```\n\nこれは、こちらの書き方よりもブロックネストを抑えることができるのが利点ですが、\n\n```\n\n while (foo) {\n if (hoge) {\n ...\n }\n }\n \n```\n\n可読性的には「もしかしたら問題があるかもしれない」と考えています。\n\nただ、個人的にはネストを抑える効果は大きいと考えています。\n\n \nこの書き方は、一般的には問題がありますか?", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T02:28:47.770", "favorite_count": 0, "id": "11146", "last_activity_date": "2015-06-09T03:53:20.157", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9945", "post_type": "question", "score": 1, "tags": [ "java", "c#", "c++", "c" ], "title": "while, ifなどを連結する文法の可否について", "view_count": 621 }
[ { "body": "個人の自由ですが、ネストを抑えるという観点であれば、\n\n```\n\n while (foo) {\n if (!hoge)\n continue;\n ...\n }\n \n```\n\nと論理を反転し早期に脱出させます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T03:53:20.157", "id": "11152", "last_activity_date": "2015-06-09T03:53:20.157", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "11146", "post_type": "answer", "score": 11 } ]
11146
11152
11152
{ "accepted_answer_id": "11150", "answer_count": 1, "body": "LayoutのGUIエディタを用いて、Layoutを作成しています。\n\n例えば、TextViewの中身が動的に変わる場合、私は、今は空文字列に設定しています。 \n動的に変わる処理が走るまではユーザーには空文字列として見せたいからです。\n\nしかし、GUIエディタ上では、空文字列だと何かと作りにくいです。\n\nそこで、GUIエディタ上でのみ表示されるダミーテキスト(テキストに限らないですが)を指定する方法などがあれば知りたいです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T02:32:32.063", "favorite_count": 0, "id": "11147", "last_activity_date": "2015-06-09T03:05:44.607", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "427", "post_type": "question", "score": 2, "tags": [ "android" ], "title": "LayoutのGUIエディタにのみ表示されるダミーテキスト機能はあるか", "view_count": 486 }
[ { "body": "tools 名前空間というのがありまして。\n\n[Designtime Layout Attributes - Android Tools Project\nSite](http://tools.android.com/tips/layout-designtime-attributes)\n\nレイアウト XML のルート要素に xmlns:tools=\"http://schemas.android.com/tools\"\nを追加して、あとは個々の要素で android の代わりに tools を接頭辞に用いた属性を記入していきます。\n\n```\n\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n <LinearLayout\n xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n android:orientation=\"vertical\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\">\n <TextView\n android:layout_width=\"match_parent\"\n android:layout_height=\"wrap_content\"\n tools:text=\"Dummy Text\" />\n </LinearLayout>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T03:05:44.607", "id": "11150", "last_activity_date": "2015-06-09T03:05:44.607", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7558", "parent_id": "11147", "post_type": "answer", "score": 5 } ]
11147
11150
11150
{ "accepted_answer_id": "11166", "answer_count": 1, "body": "現在スイッチを押すと`TableView`のセルを一行挿入する処理を行おうとしているのですが、下記のコードだと挿入されません。 \n試しに`if`を抜けた後に`[self.tableView\nreloadData];`を入れて実行すると、スイッチを押した後にセルが挿入されるようになるのですが、アニメーションもなくてカクカクした動きになっています。なので`insertRowsAtIndexPaths`を使ってセルの挿入を行いたいのですが、なぜ挿入されないのでしょうか?`reloadData`が実行されるとセルが挿入されるということは、挿入の処理は正しく行えており、アニメーションがうまく行えていないということなのでしょうか...? \nどなたか分かる方がいれば教えていただきたいです。すみませんが、よろしくお願いします。\n\n```\n\n if (sw.on) {\n NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:1];\n \n [identifierInSection2 addObject:@\"pickerCell\"];\n [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];\n \n } else {\n NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];\n \n [identifierInSection2 removeLastObject];\n [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];\n }\n \n```", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T03:01:30.733", "favorite_count": 0, "id": "11149", "last_activity_date": "2015-06-09T10:31:34.610", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5210", "post_type": "question", "score": 1, "tags": [ "ios", "objective-c", "uitableview" ], "title": "insertRowsAtIndexPathsでセルが挿入されない", "view_count": 2680 }
[ { "body": "「挿入」ボタンを押すと、テーブルの2行目に行を挿入し、「削除」ボタンを押すと、テーブルの2行目を削除するプログラムを作ってみました。 \nテーブルに表示するデータであるNSMutableArray「dataArray」は、挿入時、2番目にアイテムを挿入し、削除時、2番目のアイテムを削除しています。ここがあなたのプログラムと異なるところですかね? \nなんの異常もなく動作することを確認のうえ、掲載しております。参考になさってください。\n\n_ViewController.h_\n\n```\n\n #import <UIKit/UIKit.h>\n \n @interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>\n \n @end\n \n```\n\n_ViewController.m_\n\n```\n\n #import \"ViewController.h\"\n \n @interface ViewController ()\n \n @property (weak, nonatomic) IBOutlet UITableView *tableView;\n @property (nonatomic) NSMutableArray *dataArray;\n \n @end\n \n @implementation ViewController\n \n - (void)viewDidLoad {\n [super viewDidLoad];\n \n self.dataArray = [@[@\"Line 0\"] mutableCopy];\n }\n \n - (IBAction)editTable:(UIBarButtonItem *)sender { // ツールバーに、「挿入」、「削除」ボタンアイテムを設置してある。\n if (sender.tag == 10) { // 挿入のボタンのtagが10\n NSString *newLine = [[NSString alloc] initWithFormat: @\"Line %ld\", self.dataArray.count];\n NSIndexPath *indexPath = [NSIndexPath indexPathForRow: 1 inSection: 0];\n [self.dataArray insertObject: newLine atIndex: 1];\n [self.tableView insertRowsAtIndexPaths: @[indexPath] withRowAnimation: UITableViewRowAnimationTop];\n } else { // 削除ボタンの処理\n if (self.dataArray.count > 1) { // テーブルの行数が1行なら、それ以上削除しない。\n NSIndexPath *indexPath = [NSIndexPath indexPathForRow: 1 inSection: 0];\n [self.dataArray removeObjectAtIndex: 1];\n [self.tableView deleteRowsAtIndexPaths: @[indexPath] withRowAnimation: UITableViewRowAnimationTop];\n }\n }\n }\n \n // Table View Delegate and DataSource\n - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {\n return 1;\n }\n \n - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {\n return self.dataArray.count;\n }\n \n - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {\n UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @\"Cell\" forIndexPath:indexPath];\n cell.textLabel.text = self.dataArray[indexPath.row];\n \n return cell;\n }\n \n @end\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T07:08:52.947", "id": "11166", "last_activity_date": "2015-06-09T10:31:34.610", "last_edit_date": "2015-06-09T10:31:34.610", "last_editor_user_id": "7362", "owner_user_id": "7362", "parent_id": "11149", "post_type": "answer", "score": 1 } ]
11149
11166
11166
{ "accepted_answer_id": "11155", "answer_count": 1, "body": "・下記CSSは、どういう意味でしょうか?\n\n```\n\n .a:active ~ .b {\n \n```\n\n・クラスaがアクティブ または、クラスbなら? \n・cssにおける ~ はどういう意味でしょうか? \n・否定? ビット演算子?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T04:55:57.623", "favorite_count": 0, "id": "11154", "last_activity_date": "2015-06-09T05:07:38.730", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 1, "tags": [ "css" ], "title": "CSSでビット演算子? .a:active ~ .b {", "view_count": 172 }
[ { "body": "間接セレクタですね。\n\n2番目以降の要素に対して有効になると言えば良いでしょうか...\n\n<http://www.hp-stylelink.com/news/2013/09/20130912.php#lowList01>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T05:07:38.730", "id": "11155", "last_activity_date": "2015-06-09T05:07:38.730", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2383", "parent_id": "11154", "post_type": "answer", "score": 1 } ]
11154
11155
11155
{ "accepted_answer_id": null, "answer_count": 1, "body": "css3 アニメーションで左にスライドして押し出すようにして、次の要素を見せたいのですが文字が重なってうまくいきません。\n\n.slideFirstを左にスライド(left:0→left:-300px)すると、控えていた.slideSecond(left:300px→left:0)もスライドして見せたい。 \n外側の#wrapは width:300pxの為、.slideSecondは見えていない状態にしたい。 \n文字が重なって横並びで控えている状態にはなりません。どこをどのようにしたらよいでしょうか。ご教示の程よろしくお願いいたします。 \nまた、jQueryではなく、css3アニメーションでなんとか出来ないでしょうか?\n\n```\n\n @charset \"utf-8\";\r\n \r\n /* CSS Document */\r\n \r\n #wrap {\r\n width: 300px;\r\n position: relative;\r\n }\r\n \r\n .slideFirst {\r\n position: absolute;\r\n left: 0;\r\n top: 10px;\r\n }\r\n \r\n .slideSecond {\r\n position: absolute;\r\n top: 10px;\r\n /*left: 300px;*/\r\n /*display: none;*/\r\n }\r\n \r\n \r\n /* animation */\r\n \r\n .slideFirst {\r\n -webkit-animation: slideFirst 1s ease-in-out 3.0s;\r\n animation: slideFirst 1s ease-in-out 3.0s;\r\n }\r\n \r\n @keyframes slideFirst {\r\n 0% {\r\n transform: translate(0px, 0px);\r\n }\r\n 100% {\r\n transform: translate(-300px, 0px);\r\n }\r\n }\r\n \r\n @-webkit-keyframes slideFirst {\r\n 0% {\r\n -webkit-transform: translate(0px, 0px);\r\n }\r\n 100% {\r\n -webkit-transform: translate(-300px, 0px);\r\n }\r\n }\r\n \r\n \r\n /* 右にあったものを左にスライドさせたい */\r\n \r\n .slideSecond {\r\n -webkit-animation: slideSecond 1s ease-in-out 3.0s;\r\n animation: slideSecond 1s ease-in-out 3.0s;\r\n }\r\n \r\n @keyframes slideSecond {\r\n 0% {\r\n transform: translate(300px, 0px);\r\n }\r\n 100% {\r\n transform: translate(0px, 0px);\r\n }\r\n }\r\n \r\n @-webkit-keyframes slideLeft {\r\n 0% {\r\n -webkit-transform: translate(300px, 0px);\r\n }\r\n 100% {\r\n -webkit-transform: translate(0px, 0px);\r\n }\r\n }\n```\n\n```\n\n <div id=\"wrap\">\r\n <div class=\"\">\r\n <div class=\"slideFirst\">\r\n <!-- スライド左へ -->\r\n <p class=\"logo\">最初に見えるテキストテキスト</p>\r\n </div>\r\n <div class=\"slideSecond\">\r\n <!-- スライド左へ -->\r\n <p class=\"txt\">スライド後に見えるテキスト</p>\r\n </div>\r\n </div>\r\n </div>\n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2015-06-09T05:08:05.577", "favorite_count": 0, "id": "11156", "last_activity_date": "2019-12-13T18:35:40.833", "last_edit_date": "2019-12-13T18:35:40.833", "last_editor_user_id": "32986", "owner_user_id": "8745", "post_type": "question", "score": 2, "tags": [ "jquery", "css" ], "title": "css3 アニメーションで左にスライドして次の要素を見せるには?", "view_count": 1988 }
[ { "body": "Flexboxを使うとやりやすいと思います。\n\n```\n\n @charset \"utf-8\";\r\n /* CSS Document */\r\n \r\n .container {\r\n display: flex;\r\n /* 横並び、単一行 */\r\n flex-flow: row nowrap;\r\n height: 100px;\r\n background-color: yellow;\r\n }\r\n \r\n .left {\r\n flex: 0 0 auto;\r\n width: 300px;\r\n height: 50px;\r\n background-color: #00ff00;\r\n }\r\n \r\n .right {\r\n flex: 0 0 auto;\r\n width: 300px;\r\n height: 50px;\r\n background-color: #00eeee;\r\n }\r\n \r\n #wrap {\r\n width: 300px;\r\n }\r\n /* animation */\r\n \r\n .slide-left {\r\n -webkit-animation: slide-left 1s ease-in-out 3.0s;\r\n animation: slide-left 1s ease-in-out 3.0s;\r\n /* 終了位置を維持 */\r\n animation-fill-mode: forwards;\r\n }\r\n \r\n @keyframes slide-left {\r\n 0% {\r\n transform: translate(0px, 0px);\r\n }\r\n 100% {\r\n transform: translate(-300px, 0px);\r\n }\r\n }\r\n \r\n @-webkit-keyframes slide-left {\r\n 0% {\r\n -webkit-transform: translate(0px, 0px);\r\n }\r\n 100% {\r\n -webkit-transform: translate(-300px, 0px);\r\n }\r\n }\n```\n\n```\n\n <div id=\"wrap\" class=\"container\">\r\n <div class=\"slide-left left\">\r\n <p class=\"logo\">最初に見えるテキストテキスト</p>\r\n </div>\r\n <div class=\"slide-left right\">\r\n <p class=\"txt\">スライド後に見えるテキスト</p>\r\n </div>\r\n </div>\n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T07:34:06.807", "id": "11170", "last_activity_date": "2015-06-09T07:34:06.807", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3516", "parent_id": "11156", "post_type": "answer", "score": 1 } ]
11156
null
11170
{ "accepted_answer_id": "11168", "answer_count": 1, "body": "Railsでモデルを使用しないコントローラーのparamsについて質問させてください。\n\nモデルというよりActiveRecordを利用しないタイプのparamsで、スマートにvalidationや複雑な処理を行う際にどのような方法が適しているのでしょうか。\n\n処理としては以下のようなものなど。\n\n * 問い合わせフォームのようなもので、DBに保存しないもの\n * APIのやり取りなど\n\nvalidationが中心になりますが、コントローラーで行わずに使いまわしの効きやすい方法など、お知恵をいただければ思います。\n\nできれば具体的なサンプルいただけると助かります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T05:50:38.853", "favorite_count": 0, "id": "11160", "last_activity_date": "2015-06-09T07:27:47.633", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8919", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails" ], "title": "Railsでモデルを使用しないコントローラーのparamsについて", "view_count": 1228 }
[ { "body": "\"DBを利用しないActiveRecord\"\nのようなものとして、[ActiveModel](https://github.com/rails/rails/tree/master/activemodel)\nがあり、バリデーションもARと同じように記述することが可能です。\n\n以下READMEより:\n\n```\n\n class Person\n include ActiveModel::Model\n \n attr_accessor :name, :age\n validates_presence_of :name\n end\n \n person = Person.new(name: 'bob', age: '18')\n person.name # => 'bob'\n person.age # => '18'\n person.valid? # => true\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T07:27:47.633", "id": "11168", "last_activity_date": "2015-06-09T07:27:47.633", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "76", "parent_id": "11160", "post_type": "answer", "score": 1 } ]
11160
11168
11168
{ "accepted_answer_id": null, "answer_count": 0, "body": "cocoapodsでいくつかのライブラリをインストールしました。その中に含まれているResourcesにある、Localizableや画像ファイルについて、ビルドしてもアプリにインストールされていない状態になっています。\n\n例えば、CTFeedbackのCTFeedbackLocalizable.stringsやAQSLINEActivityのcolor_AQSLINEActivity.pngなどがアプリに反映されない状況です。\n\nPodfileは以下のようです。(幾つか他のものは省略していますが)\n\n```\n\n platform :ios, '8.0'\n use_frameworks!\n \n pod 'CTFeedback'\n pod \"AQSLINEActivity\"\n \n```\n\n.xcworkspaceとPodsディレクトリを一度削除してpodsの再インストールしましたが改善しませんでした。\n\nどのようにすることで、自動的にビルドされるのでしょうか?どこを確認すべきでしょうか? \nもしくは手動でビルドするものなのでしょうか?\n\nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T06:34:23.930", "favorite_count": 0, "id": "11163", "last_activity_date": "2015-06-09T12:06:33.153", "last_edit_date": "2015-06-09T08:19:07.750", "last_editor_user_id": "2772", "owner_user_id": "2772", "post_type": "question", "score": 1, "tags": [ "swift", "xcode", "cocoapods" ], "title": "CocoapodsのResourcesにあるファイルが自動でビルドされない?", "view_count": 140 }
[]
11163
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "jQueryで、特定のクラス(以下.animate)が付与されていたら、その中の特定のクラス(.slideFirst)を探してアニメーションを実行させたいのですが、うまくいきません。 \n.animateのクラスは、最初から付与されているものではなく、スライドが一番前に来た時に、付与されるものです。以下、jsの一番最後に入れたのですが、動きません。\n\n//上部省略\n\n```\n\n if (index === 0) {\n current.$node.addClass('animate');\n \n```\n\n//上部、animateクラスを付与した後に、アニメーション実行を入れたいのですが、動きません。\n\n```\n\n $(function(){\n $('.animate').find('.slideFirst').stop().animate({left: '-500px', display: 'none'}, {'duration':500,'easing':'linear'});\n });\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T06:43:03.780", "favorite_count": 0, "id": "11164", "last_activity_date": "2019-12-13T20:02:20.197", "last_edit_date": "2015-06-09T15:59:20.520", "last_editor_user_id": "3516", "owner_user_id": "8745", "post_type": "question", "score": 1, "tags": [ "javascript", "jquery" ], "title": "jQueryで特定のクラスが付与されていたら、アニメーションを実行するには?", "view_count": 2219 }
[ { "body": "下記のどちらかで動くようになると思います。 \n・`slideFirst`を設定している要素に`position`を追加する \n・`left`の代わりに`marginLeft`を使用する\n\nまた、mok2pokさんがコメントに記載しているように、要素を消したいのであれば`opacity`を使用すればいけると思います。\n\nサンプル \n<http://codepen.io/negibouze/pen/xGqdyq>\n\n```\n\n $(function() {\r\n var $wrapper = $('.wrapper');\r\n var idList = [\r\n '#n1', '#n5', '#n4', '#n3', '#n2'\r\n ];\r\n var indexArray = [4, 3, 2, 1, 0];\r\n var attrIndex = 0;\r\n var attrList = [{\r\n bottom: 0,\r\n 'z-index': 10,\r\n opacity: 1\r\n },\r\n {\r\n bottom: '18%',\r\n 'z-index': 9,\r\n opacity: 1\r\n },\r\n {\r\n bottom: '30%',\r\n 'z-index': 8,\r\n opacity: 0.9\r\n },\r\n {\r\n bottom: '40%',\r\n 'z-index': 7,\r\n opacity: 0.7\r\n },\r\n {\r\n bottom: '50%',\r\n 'z-index': 6,\r\n //opacity: 0.4\r\n }\r\n ];\r\n var childAttrList = [{\r\n width: '100%'\r\n },\r\n {\r\n width: '83%'\r\n },\r\n {\r\n width: '73%'\r\n },\r\n {\r\n width: '63%'\r\n },\r\n {\r\n width: '53%'\r\n }\r\n ];\r\n \r\n // webkitAnimationEndを使用\r\n var move = function() {\r\n var aIndex = attrIndex;\r\n attrIndex = (attrIndex === idList.length - 1) ? 0 : attrIndex + 1;\r\n var nodes = idList.map(function(id) {\r\n return {\r\n $node: $wrapper.find(id)\r\n };\r\n });\r\n nodes.forEach(function(current, currentIndex, whole) {\r\n var index = indexArray[aIndex];\r\n // 移動中は見えなくする場合はこの辺で調整する\r\n if (index === 4) current.$node.css({\r\n opacity: 0\r\n });\r\n $('img', current.$node).animate(childAttrList[index], 1000);\r\n current.$node.animate(attrList[index], 1000, function() {\r\n // 移動中は見えなくする場合はこの辺で調整する\r\n if (index === 4) current.$node.animate({\r\n opacity: 0.4\r\n }, 500);\r\n current.$node.removeClass('animate');\r\n if (index === 0) {\r\n animate(current.$node);\r\n }\r\n });\r\n aIndex = (aIndex === whole.length - 1) ? 0 : aIndex + 1;\r\n });\r\n }\r\n var animate = function(obj) {\r\n obj.one('animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd', function() {\r\n move();\r\n });\r\n obj.addClass('animate');\r\n // position\r\n $('.animate').find('.set-position').stop().animate({\r\n left: '-150px',\r\n opacity: 0\r\n }, {\r\n 'duration': 1000,\r\n 'easing': 'linear',\r\n complete: function() {\r\n $(this).animate({\r\n left: '0px',\r\n opacity: 1.0\r\n }, 1500);\r\n }\r\n });\r\n // marginLeft\r\n $('.animate').find('.margin_left').stop().animate({\r\n marginLeft: '-150px',\r\n opacity: 0\r\n }, {\r\n 'duration': 1500,\r\n 'easing': 'linear',\r\n complete: function() {\r\n $(this).animate({\r\n marginLeft: '0px',\r\n opacity: 1.0\r\n }, 1000);\r\n }\r\n });\r\n }\r\n // 最初の1回を実行\r\n animate($('#n1'));\r\n /* \r\n // setIntervalを使用\r\n var move = function(isFirst) {\r\n var aIndex = attrIndex;\r\n attrIndex = (attrIndex === idList.length - 1) ? 0 : attrIndex + 1;\r\n var nodes = idList.map(function(id) {\r\n return {\r\n $node: $wrapper.find(id)\r\n };\r\n });\r\n nodes.forEach(function(current, currentIndex, whole) {\r\n var index = indexArray[aIndex];\r\n // 移動中は見えなくする場合はこの辺で調整する\r\n if (!isFirst && index === 4) current.$node.css({opacity:0});\r\n $('img', current.$node).animate(childAttrList[index], 1000);\r\n current.$node.animate(attrList[index], 1000, function() {\r\n // 移動中は見えなくする場合はこの辺で調整する\r\n if (!isFirst && index === 4) current.$node.animate({opacity:0.4}, 500);\r\n current.$node.removeClass('animate');\r\n if (index === 0) {\r\n current.$node.addClass('animate');\r\n }\r\n });\r\n aIndex = (aIndex === whole.length - 1) ? 0 : aIndex + 1;\r\n });\r\n }\r\n // 待ち時間が長いので最初の1回を実行\r\n move(true);\r\n setInterval(function() { move(false) }, 5100);\r\n */\r\n });\n```\n\n```\n\n .set-position {\r\n position: relative;\r\n }\r\n \r\n #slide {\r\n width: 320px;\r\n margin: 0 auto;\r\n text-align: center;\r\n }\r\n \r\n #slide ul {\r\n position: relative;\r\n height: 300px;\r\n list-style: none;\r\n padding-left: 0;\r\n }\r\n \r\n #slide li {\r\n position: absolute;\r\n overflow: hidden;\r\n width: 320px;\r\n margin: 0 auto;\r\n text-align: center;\r\n background: #fff;\r\n }\r\n \r\n #slide #n1 {\r\n bottom: 0;\r\n z-index: 10;\r\n opacity: 1;\r\n }\r\n \r\n #slide #n1 img {\r\n width: 100%;\r\n }\r\n \r\n #slide #n2 {\r\n bottom: 18%;\r\n z-index: 9;\r\n opacity: 1;\r\n }\r\n \r\n #slide #n2 img {\r\n width: 83%;\r\n }\r\n \r\n #slide #n3 {\r\n bottom: 30%;\r\n z-index: 8;\r\n opacity: 0.9;\r\n }\r\n \r\n #slide #n3 img {\r\n width: 73%;\r\n }\r\n \r\n #slide #n4 {\r\n bottom: 40%;\r\n z-index: 7;\r\n opacity: 0.7;\r\n }\r\n \r\n #slide #n4 img {\r\n width: 63%;\r\n }\r\n \r\n #slide #n5 {\r\n bottom: 50%;\r\n z-index: 6;\r\n opacity: 0.4;\r\n }\r\n \r\n #slide #n5 img {\r\n width: 53%;\r\n }\r\n \r\n img {\r\n background: #ccc;\r\n width: 50px;\r\n height: 70px;\r\n }\r\n \r\n \r\n /* 3秒止めてから2秒かけてscaleoutのkeyframesを実行(足して5秒)。jsの5秒と同じ。 */\r\n \r\n .animate {\r\n -webkit-animation: scaleout 2s ease-in-out 3s;\r\n animation: scaleout 2s ease-in-out 3s;\r\n }\r\n \r\n \r\n /* n1を1.5倍に拡大して消す */\r\n \r\n @-webkit-keyframes scaleout {\r\n 0% {\r\n -webkit-transform: scale(1);\r\n }\r\n 100% {\r\n -webkit-transform: scale(1.5);\r\n opacity: 0;\r\n }\r\n }\r\n \r\n @-moz-keyframes scaleout {\r\n 0% {\r\n transform: scale(1);\r\n -webkit-transform: scale(1);\r\n }\r\n 100% {\r\n transform: scale(1.5);\r\n -webkit-transform: scale(1.5);\r\n opacity: 0;\r\n }\r\n }\r\n \r\n @-webkit-keyframes scaleout {\r\n 0% {\r\n transform: scale(1);\r\n -webkit-transform: scale(1);\r\n }\r\n 100% {\r\n transform: scale(1.5);\r\n -webkit-transform: scale(1.5);\r\n opacity: 0;\r\n }\r\n }\r\n \r\n @-o-keyframes scaleout {\r\n 0% {\r\n transform: scale(1);\r\n -webkit-transform: scale(1);\r\n }\r\n 100% {\r\n transform: scale(1.5);\r\n -webkit-transform: scale(1.5);\r\n opacity: 0;\r\n }\r\n }\r\n \r\n @keyframes scaleout {\r\n 0% {\r\n transform: scale(1);\r\n -webkit-transform: scale(1);\r\n }\r\n 100% {\r\n transform: scale(1.5);\r\n -webkit-transform: scale(1.5);\r\n opacity: 0;\r\n }\r\n }\n```\n\n```\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js\"></script>\r\n \r\n <div id=\"slide\">\r\n <ul class=\"wrapper\">\r\n <li id=\"n1\"><img src=\"\" alt=\"イメージ1\" />\r\n <div class=\"set-position\">positionを設定</div>\r\n <div class=\"margin_left\">marginLeftを使用</div>\r\n </li>\r\n <li id=\"n2\"><img src=\"\" alt=\"イメージ2\" />\r\n <div class=\"set-position\">positionを設定</div>\r\n <div class=\"margin_left\">marginLeftを使用</div>\r\n </li>\r\n <li id=\"n3\"><img src=\"\" alt=\"イメージ3\" />\r\n <div class=\"set-position\">positionを設定</div>\r\n <div class=\"margin_left\">marginLeftを使用</div>\r\n </li>\r\n <li id=\"n4\"><img src=\"\" alt=\"イメージ4\" />\r\n <div class=\"set-position\">positionを設定</div>\r\n <div class=\"margin_left\">marginLeftを使用</div>\r\n </li>\r\n <li id=\"n5\"><img src=\"\" alt=\"イメージ5\" />\r\n <div class=\"set-position\">positionを設定</div>\r\n <div class=\"margin_left\">marginLeftを使用</div>\r\n </li>\r\n </ul>\r\n </div>\n```\n\n参考 \n[jQuery animate({left:“+=10”}) not\nworking](https://stackoverflow.com/questions/5723230/jquery-\nanimateleft-10-not-working)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2015-06-10T09:17:03.907", "id": "11218", "last_activity_date": "2019-12-13T20:02:20.197", "last_edit_date": "2019-12-13T20:02:20.197", "last_editor_user_id": "32986", "owner_user_id": "3516", "parent_id": "11164", "post_type": "answer", "score": 1 } ]
11164
null
11218
{ "accepted_answer_id": "11177", "answer_count": 1, "body": "JAVA標準の機能を使って、 \n外部サイトに存在する、JS外部ファイル内に定義されている関数を実行することはできるのでしょうか?\n\nたとえばあるサイトが、遷移先URLをブラウザ内でダイナミックに生成していて、HTMLからはその生成方法を知ることができないとき、HTTPのresponseを監視するなんて方法もあるのかもしれませんが、普通にこちらのサーバーサイドで相手WEBサーバーのjavascriptを実行して算出できたら楽だなと思いました。\n\nScriptEngineではJavaScript標準コマンドは実行できるようですが、外部関数を取り込めるような説明がなかったので、もしそういうものがあればおしえていただけますでしょうか。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T06:43:45.393", "favorite_count": 0, "id": "11165", "last_activity_date": "2015-06-09T09:33:18.403", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8396", "post_type": "question", "score": 1, "tags": [ "javascript", "java", "apache" ], "title": "【JAVA】ScriptEngine等を使って、外部サイトのJS関数を実行する", "view_count": 3678 }
[ { "body": "外部ファイルを`ScriptEngine#eval(Reader)`で読み込んだり、`engine.eval(\"load('./hello.js');\");`みたいに`load`する方法があるようです。\n\n**NashornLoadTest.java** \n\n```\n\n import java.io.*;\n import javax.script.*;\n \n public class NashornLoadTest {\n public static void main(String... args) throws Exception {\n ScriptEngineManager manager = new ScriptEngineManager();\n ScriptEngine engine = manager.getEngineByName(\"javascript\");\n //try (Reader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {\n try (Reader reader = new BufferedReader(new InputStreamReader(\n new FileInputStream(\"hello.js\"), \"UTF-8\"))) {\n engine.eval(reader);\n }\n //or engine.eval(\"load('./hello.js');\");\n engine.eval(\"hello('World!');\");\n }\n }\n \n```\n\n**hello.js** \n\n```\n\n function hello(name) {\n java.lang.System.out.println(\"Hello \" + name);\n };\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T09:33:18.403", "id": "11177", "last_activity_date": "2015-06-09T09:33:18.403", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "46", "parent_id": "11165", "post_type": "answer", "score": 1 } ]
11165
11177
11177
{ "accepted_answer_id": "11193", "answer_count": 1, "body": "Go言語を初めて1週間ほどですが、エラーハンドリングの方法について良い方法が思いつかなかった為、質問させて頂きます。 \n今回の例はjsonデコードですが、json#UnmarshalJSONが問題なのではなく、複数のメソッドを呼び出すメソッドを記述した際には普遍的に起こる問題かと思います。\n\n## 目的\n\n以下に示すコードのように、独自クラスTaskに対してjson.Unmarshalerインターフェイスを実装しようとしています。 \nなお、今回の問題とは直接関係ありませんが、m[\"original\"]の内容によってt.Originalの型を変更したい為、Original側にUnmarshalJSONを実装することはできません。\n\n```\n\n func (t *Task) UnmarshalJSON(d []byte) error {\n m := make(map[string]json.RawMessage)\n err = json.Unmarshal(d, &m)\n if err != nil {\n return err\n }\n \n json.Unmarshal([]byte(m[\"name\"]), &t.Name)\n json.Unmarshal([]byte(m[\"trigger\"]), &t.Trigger)\n json.Unmarshal([]byte(m[\"description\"]), &t.Description)\n json.Unmarshal([]byte(m[\"filter\"]), &t.Filter)\n originalUnmarshal([]byte(m[\"original\"]), &t.Original)\n return nil\n }\n \n```\n\n## 問題点\n\njson.UnmarshalやoriginalUnmarshalではエラーが発生する可能性があるため、返り値としてerrorを返しています。この部分のエラーハンドリングを考えたところ、以下のように`if\nerr != nil { return err }`だらけのコードとなってしまいました。\n\n```\n\n func (t *Task) UnmarshalJSON(d []byte) error {\n m := make(map[string]json.RawMessage)\n err = json.Unmarshal(d, &m)\n if err != nil {\n return err\n }\n \n err = json.Unmarshal([]byte(m[\"name\"]), &t.Name)\n if err != nil {\n return err\n }\n \n err = json.Unmarshal([]byte(m[\"trigger\"]), &t.Trigger)\n if err != nil {\n return err\n }\n \n err = json.Unmarshal([]byte(m[\"description\"]), &t.Description)\n if err != nil {\n return err\n }\n \n err = json.Unmarshal([]byte(m[\"filter\"]), &t.Filter)\n if err != nil {\n return err\n }\n \n err = originalUnmarshal([]byte(m[\"original\"]), &t.Original)\n if err != nil {\n return err\n }\n return nil\n }\n \n```\n\n## 調査・対応\n\n同じような問題で悩んでいる人を探した所、公式を含む以下のサイトが引っかかりました。 \n<https://groups.google.com/forum/#!topic/Golang-Nuts/sFgUpNvklmo> \n<http://blog.golang.org/errors-are-values> \n<http://jxck.hatenablog.com/entry/golang-error-handling-lesson-by-rob-pike>\n\nこれを元に汎用的なクラスを実装したところ、クロージャだらけになったものの一応実装自体はできました。\n\n```\n\n type MultipleFunction struct {\n err error\n }\n \n func (m *MultipleFunction) Execute(f func() error) {\n if m.err != nil {\n return\n }\n m.err = f()\n }\n \n func (m *MultipleFunction) Error() error {\n return m.err\n }\n \n func (t *Task) UnmarshalJSON(d []byte) error {\n var err error\n m := make(map[string]json.RawMessage)\n \n mf := MultipleFunction{}\n mf.Execute(func() error { return json.Unmarshal(d, &m) })\n mf.Execute(func() error { return json.Unmarshal([]byte(m[\"name\"]), &t.Name) })\n mf.Execute(func() error { return json.Unmarshal([]byte(m[\"trigger\"]), &t.Trigger) })\n mf.Execute(func() error { return json.Unmarshal([]byte(m[\"description\"]), &t.Description) })\n mf.Execute(func() error { return json.Unmarshal([]byte(m[\"filter\"]), &t.Filter) })\n mf.Execute(func() error { return originalUnmarshal([]byte(m[\"original\"]), &t.Original) })\n return mf.Error()\n }\n \n```\n\nしかし、「目的」で示したコードに対してややこしくなってしまっており、あまり良いコードとも思えません。 \nこういった場合の定番の方法は何かあるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T07:13:34.300", "favorite_count": 0, "id": "11167", "last_activity_date": "2015-06-10T14:21:01.323", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2728", "post_type": "question", "score": 4, "tags": [ "go" ], "title": "Go言語において複数のメソッドを呼ぶ際のエラーハンドリングでifが乱立してしまう", "view_count": 729 }
[ { "body": "汎用化しようとするのが誤りでしょう。上げられている資料 <http://jxck.hatenablog.com/entry/golang-error-\nhandling-lesson-by-rob-pike> に基づくならば、以下のような実装 `json2` にとどめるべきです。\n\n```\n\n type json2 struct {\n err error\n }\n \n func (j *json2) unmarshal(data []byte, v interface{}) error {\n if j.err != nil {\n return j.err\n }\n j.err = json.Unmarshal(data, v)\n return j.err\n }\n \n func (j *json2) originalUnmarshal(data []byte, v *Original) error {\n if j.err != nil {\n return j.err\n }\n j.err = originalUnmarshal(data, v)\n return j.err\n }\n \n```\n\n汎用化する仕組み/フレームワークをあらかじめ作るのではなく、 **必要な物だけを必要なときに書く** ことで、維持したいロジックをスッキリさせる方が\ngolang 的です。どうしても汎用化したいのであれば、 `json2`\nに相当するコードを自動生成(generate)するような方法を模索すべきではないでしょうか。\n\nなお、この `json2` を使うことで、元のコードは以下のように書き換わります。\n\n```\n\n func (t *Task) UnmarshalJSON(d []byte) error {\n m := make(map[string]json.RawMessage)\n j := &json2{}\n j.unmarshal(d, &m)\n j.unmarshal([]byte(m[\"name\"]), &t.Name)\n j.unmarshal([]byte(m[\"trigger\"]), &t.Trigger)\n j.unmarshal([]byte(m[\"description\"]), &t.Description)\n j.unmarshal([]byte(m[\"filter\"]), &t.Filter)\n j.originalUnmarshal([]byte(m[\"original\"]), &t.Original)\n return j.err\n }\n \n```\n\n* * *\n\n### 余談\n\n`json2` というよりは意味合いから `unmarshalContext` とすべきでした。まぁ説明のため短い名前を採用したということで、ご容赦を。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T16:44:58.527", "id": "11193", "last_activity_date": "2015-06-10T14:21:01.323", "last_edit_date": "2015-06-10T14:21:01.323", "last_editor_user_id": "208", "owner_user_id": "208", "parent_id": "11167", "post_type": "answer", "score": 3 } ]
11167
11193
11193
{ "accepted_answer_id": null, "answer_count": 1, "body": "現在、多重起動防止のためのwindow強制終了の処理にて困っております。\n\nプロセス名によせてPIDを取得しまくり、同プロセス名、違PIDのwindowを強制削除しまくる事で多重起動防止できると考え、調べてみました。検索すると沢山、同様の処理が出てまいりますので参考にしてみたところprocess.CloseMainWindowの箇所にて表題のエラーが発生します。\n\n不思議と、成功する事もあるのでかえって厄介です。\n\n以上、宜しくお願いいたします。\n\n```\n\n System.Diagnostics.Process hThisProcess = System.Diagnostics.Process.GetCurrentProcess();\n System.Diagnostics.Process[] hProcesses = System.Diagnostics.Process.GetProcessesByName(hThisProcess.ProcessName);\n int iThisProcessId = hThisProcess.Id;\n foreach (System.Diagnostics.Process hProcess in hProcesses){\n if (hProcess.Id != iThisProcessId){\n if (!hProcess.CloseMainWindow()){\n hProcess.Kill(); \n }\n else{\n Logger.Info(\"CloseMainWindow成功:\" + hProcess.Id);\n }\n }\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T07:29:10.193", "favorite_count": 0, "id": "11169", "last_activity_date": "2015-06-09T09:55:33.280", "last_edit_date": "2015-06-09T09:55:33.280", "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": 1, "tags": [ "c#" ], "title": "\"このオブジェクトに関連付けられているプロセスはありません。\" エラーの回避・解決法について", "view_count": 2470 }
[ { "body": "なんだかすごく危険そうなことをしていますが・・・ \n現コード全部捨てて Mutex による多重起動チェックにしませんか? \n他にも tips が紹介されていますし参照してください。 \n<http://dobon.net/vb/dotnet/process/checkprevinstance.html>\n\nあれ? ASP.NET なの?だとしたらわけがわからんコードなんだけど・・・", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T08:12:31.913", "id": "11173", "last_activity_date": "2015-06-09T08:12:31.913", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "11169", "post_type": "answer", "score": 1 } ]
11169
null
11173
{ "accepted_answer_id": "11187", "answer_count": 1, "body": "CakePHP2.6.4を使い始めたのですが、counterCacheを使ってみたいと考えています。 \nカウントと同時に更新日時も保存したいのですが、counterCacheのオプションなどありますでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T07:59:39.730", "favorite_count": 0, "id": "11171", "last_activity_date": "2015-06-09T12:20:15.737", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8910", "post_type": "question", "score": 1, "tags": [ "cakephp" ], "title": "CakePHP2のcounterCacheで更新日時もupdateしたいです", "view_count": 133 }
[ { "body": "`counterCache`ではカウント値の更新のみが行えます。 \nまた、更新には`updateAll`メソッドを使用しているので、`beforeSave`, `afterSave`などのコールバックも呼ばれません。\n\n子モデル保存時に、親モデルへ子モデルの最終更新時刻を保存したいのであれば、子モデル側の`afterSave`,\n`afterDelete`で親モデルを呼び出して更新時刻を保存します。\n\n例)\n\n```\n\n public function afterSave($created, $options = array()) {\n $parentId = $this->data['Child']['parent_id'];\n $lastUpdated = $this->field('updated', ['parent_id' => $parentId], ['updated' => 'desc']);\n $this->Parent->save([\n 'id' => $parentId,\n 'children_last_updated_at' => $lastUpdated\n ], [\n 'validate' => false,\n 'callbacks' => false,\n ]);\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T12:20:15.737", "id": "11187", "last_activity_date": "2015-06-09T12:20:15.737", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2668", "parent_id": "11171", "post_type": "answer", "score": 1 } ]
11171
11187
11187
{ "accepted_answer_id": null, "answer_count": 1, "body": "AudioUnit\nを使って音声の録音、再生を行なうプログラムを作成しているのですが、以下のようなバグに遭遇しました。色々手を尽くしては見たものの一向に改善しなかったため、質問させていただきます。\n\n録音側のAURenderCallbackStructに設定したコールバック関数 `AURenderCallback` 内中段の `NSMutableData\n*data` でメモリリークを起こしているようです。(`Instruments` の`Allocations`\nはずっと右肩上がりになっています:2.5KB/秒)\n\n色々調査した結果分かった事↓です。\n\n * (中略) 部分を削除しても現象に変化はありません\n * `AudioProcessor *rec`、`OSStatus status` の行を削除しても現象に変化はありません\n * `NSMutableData *data` を削除すると `Allocations` はすぐに一定になります\n * `NSMutableData *data` を `int` や `NSData`, `NSArray` に変更すると `Allocation` はすぐに一定になります。\n * `NSMutableDataやNSMutableArray`, `NSObject` では `Allocation` は一定にならず上昇をし続けたままになります\n * この現象はiPad mini (iOS 7.0.4) でのみ確認できていて、iPhone 4s (iOS7.1.1) では発生しませんでした。\n\n```\n\n OSStatus AURenderCallback(void *inRefCon,\n AudioUnitRenderActionFlags *ioActionFlags,\n const AudioTimeStamp *inTimeStamp,\n UInt32 inBusNumber,\n UInt32 inNumberFrames,\n AudioBufferList *ioData)\n { \n AudioProcessor *rec = (__bridge AudioProcessor *) inRefCon;\n \n OSStatus status = AudioUnitRender([rec audioUnit], ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, &testbufferList);\n \n \n NSMutableData *data = [[NSMutableData alloc] init];\n /*\n ~(中略)~\n */\n return noErr;\n }\n \n```\n\n以上、ご教示ください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T08:00:57.577", "favorite_count": 0, "id": "11172", "last_activity_date": "2015-08-05T01:20:15.877", "last_edit_date": "2015-06-09T08:13:23.793", "last_editor_user_id": "76", "owner_user_id": "10065", "post_type": "question", "score": 1, "tags": [ "objective-c", "iphone" ], "title": "NSMutableDataのインスタンスがiPad(iOS7.0.4)でのみリークする", "view_count": 205 }
[ { "body": "私はMacのAudioUnitはそれなりに知っていますがObjective-Cの \nメモリ管理システムにはあまり詳しくない、という者です。\n\nで、このソースは一見しただけでリークしそうな感じがする実装になっています。 \nallocは、メモリを確保するためのメソッドなので、呼ばれるたびに \nメモリを確保しますが、開放されている様子がないからです。 \nAURenderCallbackはかなりの頻度で実行されるので \nメモリ使用量が増えていくだろうな、というのがソースをみただけで想像できます。\n\nそもそも、AURenderCallback内でメモリ確保の処理を実行するのは \nあまり良い戦略ではないので、NSMutableData* dataをAURenderCallback内で \nはallocしないように処理を修正することをおすすめします。\n\nやり方はいろいろとあると思いますが、私ならばAURenderCallbackの引数として渡されてくる \nAudioProcessor側でallocしておき、AURenderCallbackで使うように実装します。 \nこのソースからだとAURenderCallback以外の部分がどうなっているか不明なので、 \n具体的なソースは書きませんが、AURenderCallback内ではメモリ確保の処理はできないことを \n前提にプログラムを書いたほうが良いことが多いです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-07-06T00:40:59.673", "id": "12060", "last_activity_date": "2015-07-06T00:40:59.673", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10410", "parent_id": "11172", "post_type": "answer", "score": 1 } ]
11172
null
12060
{ "accepted_answer_id": null, "answer_count": 0, "body": "初めて質問させていただきます。 \nPHPの`printer_open`についてです。\n\n以前Windows XPで動かしていたPHPのプログラムを、Windows 7で動かすための移行作業をしております。 \nXPではApache ver.1.3.29、PHP ver.4.3.9.9で動かしていました。 \n7にはApache ver.2.2.14、PHP ver.5.4.10をインストールし、ほとんどのプログラムは動いています。 \nただ、印刷を行うプログラムで以下のようなエラーが出ます。\n\n> Fatal error: Call to undefined function printer_open() in\n> C:\\Apache2.2\\htdocs\\~ on line 261\n\n対象の行に書かれているプログラムが、以下になります。\n\n```\n\n $handle = printer_open(\"Canon LBP3310\");\n \n```\n\nもちろん、対象のプリンターのドライバーはインストールしており、ネットワーク経由で印刷は可能な状態になっています。 \nまた、`c\\WINDOWS\\system32\\`に`php5ts.dll`、`c\\php\\ext\\`に`php_printer.dll`は入れており、`php.ini`で「`extension=php_printer.dll`」部分の`;`は外しております。\n\n原因に心当たりがある方がおりましたら、ご回答いただけますと幸いです。 \nよろしくお願いいたします。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2015-06-09T08:35:30.450", "favorite_count": 0, "id": "11176", "last_activity_date": "2019-05-30T15:55:54.997", "last_edit_date": "2019-05-30T15:55:54.997", "last_editor_user_id": "32986", "owner_user_id": "10068", "post_type": "question", "score": 3, "tags": [ "php" ], "title": "PHPのprinter_openでエラーが出ます", "view_count": 235 }
[]
11176
null
null
{ "accepted_answer_id": null, "answer_count": 2, "body": "Appストアに公開されているiOSアプリ(プッシュ通知を実装)を、現在のアカウント(アカウントA)から新しいアカウント(アカウントB)にiTunes\nconnect経由で譲渡しようと考えております。\n\n譲渡後のプッシュ通知について下記2点教えて頂けますでしょうか?\n\n①譲渡前のユーザー(アカウントAの時のユーザー)には、譲渡前と同様に譲渡後もプッシュ通知を送信する事は可能でしょうか?\n\n②譲渡後のユーザー(アカウントBの時のユーザー)には、アプリに何ら変更を加える事なしに、プッシュ通知を送る事は可能でしょうか?\n\n①、②について不可能な場合、プッシュ通知を送れるようになるプロセスについて教えて頂けると幸いです。\n\n宜しくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T09:39:37.160", "favorite_count": 0, "id": "11178", "last_activity_date": "2016-03-09T16:46:31.483", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10071", "post_type": "question", "score": 6, "tags": [ "ios", "push-notification" ], "title": "iOSアプリ譲渡後のプッシュ通知", "view_count": 1246 }
[ { "body": "これはあくまで予測なので保証し兼ねますが、答えようと思います。\n\nこの質問は、「各ユーザーはなんらかのサーバーに送っているPush通知のID」の扱いがアカウント移譲後にどのようになるかというものだと解釈しました。 \n予想としては二通りあります。 \n・今まで使っていたIDが無効になる \n・IDは無効にならない。 \n・証明書等が無効になり一切送れなくなる。\n\n1番目の場合、既存ユーザーでアクティブユーザーでない場合、2度と送られなくなります。新規ユーザーには影響ありません。 \n2番目の場合、既存ユーザーにも新規ユーザーにも送る事ができます。一番望ましいパターンです。 \n3番目の場合、送る事は出来ません。諦めて再実装するしかありません。\n\nアカウントの移譲の挙動はほとんどの人は経験がない事です。実際にどのようになるか不明です。リスクを覚悟した上で、素早く対応できる体制をとる事が、よりよい対策だと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T12:16:23.507", "id": "11291", "last_activity_date": "2015-06-12T12:16:23.507", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9558", "parent_id": "11178", "post_type": "answer", "score": 0 }, { "body": "直接的な回答というよりは代替案なのですが、 \n以前プッシュ通知に悩んだ者として知見を共有させて頂ければと思います。\n\nまず、iTunes connect経由でアプリの所属アカウントを変更した場合に、 \nデバイストークンIDがどうなるかという質問ですが、 \n実際に経験したことがないため、お答えできません...。\n\nただ、デバイストークンIDは変更が生じる前提で実装されることをオススメ致します。 \n理由としては、\n\n * iOS6→iOS7のアップデートタイミングでデバイストークンIDの仕様が変更されました \niOS6までは **デバイスごとの割当** でしたが、iOS7からは **デバイス&アプリごとに割当** に変更されました。\n\n * iOS9から **アプリをインストール度にデバイストークンIDが変更** されるようになりました。 \nつまり、一度アンインストールして、インストールし直すとデバイストークンIDが変更されるということです。\n\n * 今年中に2点の仕様変更が予定されています。 \n1: デバイストークンIDの **サイズが大きくなる** (32bytes→100bytesに変更) \n2: development, productionの **証明書が1つになる** (以前は、証明書ごとに別IDでした)\n\nといった過去の背景と今後の予定があるためです。\n\nよって、\n\n * 発行されたデバイストークンIDを端末内部に保持\n * アプリ起動ごとに(停止状態から起動した場合に)デバイストークンIDを確認\n * 確認したデバイストークンIDが端末内部に保存したデバイストークンIDと異なる場合は値を更新(端末内部およびサーバサイドのDBも更新)\n\nとされるのが良いと思います。\n\nこれであれば、懸念されていることにも対応可能になるかと思います。\n\nもちろん、ユーザがアプリを起動しないと更新されませんが、 \nデバイストークンIDはiOS更新ごとに仕様が変わるものなので、 \nプッシュ通知が届くか否かはベストエフォートと考えた方が良いです。\n\n少しでも参考になれば幸いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-09T02:51:40.320", "id": "20768", "last_activity_date": "2016-01-09T15:03:10.257", "last_edit_date": "2016-01-09T15:03:10.257", "last_editor_user_id": "8968", "owner_user_id": "8968", "parent_id": "11178", "post_type": "answer", "score": 1 } ]
11178
null
20768
{ "accepted_answer_id": null, "answer_count": 2, "body": "次のコードでhtmlを取得しましたが、\n\n```\n\n import urllib2\n fp = urllib2.urlopen('http://2689.web.fc2.com/1989/GS/GS1.html')\n html = fp.read()\n fp.close()\n \n```\n\n次のように文字化けしてしまいます。\n\n出力結果(一部)\n\n```\n\n <div class='score'>\n <p class='data-ce'><span>4??8???@1???@?????h?[???@56,000?l</span></p>\n <div class='float-clear'></div>\n <table border='1' cellspacing='2' class='board1'>\n \n```\n\nどのようにしたら、文字化けを直せるでしょうか?教えてください、お願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T10:32:14.193", "favorite_count": 0, "id": "11182", "last_activity_date": "2015-06-11T00:21:16.793", "last_edit_date": "2015-06-09T13:11:14.543", "last_editor_user_id": "49", "owner_user_id": "10072", "post_type": "question", "score": 5, "tags": [ "python" ], "title": "pythonでwebサイトからのhtml取得をしましたが文字化けします。", "view_count": 17374 }
[ { "body": "```\n\n html = fp.read()\n \n```\n\nこれを\n\n```\n\n html = fp.read().decode('shift_jis')\n \n```\n\nこのように変更すれば直せると思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T12:52:12.990", "id": "11190", "last_activity_date": "2015-06-09T12:52:12.990", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9575", "parent_id": "11182", "post_type": "answer", "score": 2 }, { "body": "`chardet`ライブラリの`detect`を使用すれば文字コードが判別できますので、それをUnicodeに`decode`すれば取得元がどんな文字コードでも対応できます。\n\n```\n\n import urllib\n import chardet\n \n url = 'http://2689.web.fc2.com/1989/GS/GS1.html'\n # データ取得\n data = ''.join(urllib.urlopen(url).readlines())\n # エンコーディング判別\n guess = chardet.detect(data)\n # Unicode化\n unicode_data = data.decode(guess['encoding'])\n \n```\n\nあとはBeautifulSoupなりPyQueryなりでスクレイピング等をすれば良いです。\n\n参考URL:<http://ymotongpoo.hatenablog.com/entry/20110103/1294032545>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T00:21:16.793", "id": "11241", "last_activity_date": "2015-06-11T00:21:16.793", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7214", "parent_id": "11182", "post_type": "answer", "score": 5 } ]
11182
null
11241
{ "accepted_answer_id": "18322", "answer_count": 1, "body": "条件が必要なときのみ通常使用している関連名はそのままにwhere句を使用したいと思い、関連の上書きを行う事で可能なのではと思い試してみています。\n\n```\n\n class Hoge < ActiveRecord::Base\n belongs_to :common\n belongs_to :common_flag, -> { where(flag: 1) }, class_name: 'Common'\n def self.where_flag\n common = common_flag\n super\n end\n end\n \n```\n\nrailsのドキュメントを参考に、上記のような記述をしましたが、上手くいきませんでした。\n\n```\n\n Hoge.where_flag\n \n```\n\nと呼んだところ、common_flagが\"undefined local variable or method\"だと言われ、\n\n```\n\n self.common_flag\n \n```\n\nとしてみたところ、common_flagが\"undefined method\"だと言われてしまいました。\n\n正しくはどのように記述すればいいのでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T12:19:17.340", "favorite_count": 0, "id": "11186", "last_activity_date": "2016-04-06T02:44:52.537", "last_edit_date": "2015-06-09T12:24:17.827", "last_editor_user_id": "7352", "owner_user_id": "7352", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails" ], "title": "associationをoverrideする方法", "view_count": 779 }
[ { "body": "belongs_to は、インスタンスに紐づく関連レコードを取得するものです。\n\n`#<Hoge id: 1, common_id: 1, ...`に対する`#<Common id: 1,\n...`を取得するものですからHogeクラス自体からCommonのレコードを取得することはできません。\n\nまた`belong_to`は、命名規則通りであれば`common_id`に紐づく1つのレコードを取得するので`where(flag:\n1)`は無意味であるため無視されます。\n\n正しい記述方法は、実際どのようなレコードがあって、どういう式でどういう結果を得たいかがないと分かりません。(もしかしたら求めているのはscopeかもしれませんし、そもそもそんな処理を書く必要がないものかもしれません)\n\n## コメントを受けての回答\n\n関連付けは、関連付けの役目だけにすべきだと思います。 \n(そもそも\"上書き\"なんてしたら。誰が現状どのような状態にあるか把握できるのでしょう?) \nやはりscopeで対応してはどうでしょうか。\n\n```\n\n class School\n has_many :student\n scope :pref, ->(str){ where(prefecture: str) }\n end\n class Student\n belongs_to :school\n scope :boys, ->{ where(gender: 'male') }\n end\n \n School.first.students.boys\n \n```\n\nscopeをmergeすることもできます。\n\n```\n\n School.includes(:students).joins(:students).merge( Student.boys )\n Student.includes(:school).joins(:school).merge( School.pref('tokyo') }\n \n```\n\n上記コードは、arelでも掛けます。\n\n```\n\n student_cond = Student.arel_table[:gender].eq('male')\n student_cond.to_sql #=> students.gender = 'male'\n School.includes(:students).joins(:students).where(student_cond)\n \n```\n\nただしこの場合は、includesを使わないと \n最初のSchool/Studentのレコードを取得して、関連するstudents/school無指定で再取得試みるので注意が必要です。\n\nちょっとトリッキーだと。こんなこともできます。\n\n```\n\n scope :has, ->(cond){ where(cond) }\n School.incldues(:students).joins(:students).merge( Student.has(gender: 'male') )\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-11-02T08:55:23.940", "id": "18322", "last_activity_date": "2015-12-07T11:02:08.050", "last_edit_date": "2015-12-07T11:02:08.050", "last_editor_user_id": "8335", "owner_user_id": "8335", "parent_id": "11186", "post_type": "answer", "score": 1 } ]
11186
18322
18322
{ "accepted_answer_id": "69394", "answer_count": 1, "body": "OpenSSLを使用して証明書のsubjectaltnameのothernameに日本語の性別を格納しようとしています。\n\nまず、openssl.cnfに以下の文を追加し、othernameの値を設定しました。\n\n```\n\n Sex = 1.1.1.5\n \n [ v3_req ]\n \n # Extensions to add to a certificate request\n \n basicConstraints = CA:FALSE\n keyUsage = nonRepudiation, digitalSignature, keyEncipherment\n \n subjectAltName = otherName:Sex;UTF8String:男性\n \n```\n\n次にOpenSSLコマンドでpemファイルを作成\n\n```\n\n openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout cert.pem\n -out cert.pem\n \n```\n\nブラウザに読み込むためpfxファイルを作成\n\n```\n\n openssl pkcs12 -export -out cert.pfx -in cert.pem -name \"test\"\n \n```\n\npfxファイルをブラウザにインポートした後、証明書ストアを確認したところ、othernameに16進数で値は入っていましたが、正確に変換されていませんでした。\n\n```\n\n Other Name:\n 1.1.1.5=0c 07 c2 92 6a c2 90 c2 ab\n \n```\n\n期待値としてはUTF-8の16進数に変換されていると思ったのですが結果としては16進数のShift-JISに近い値でした。\n\n```\n\n 「男性」の16進数UTF-8:   e7 94 b7 e6 80 a7\n 「男性」の16進数Shift-JIS:92 6a 90 ab\n \n```\n\n正しい値を設定するにはどうすれば良いでしょうか。よろしくお願いします。\n\n**追記** \n@sanadanへの指摘からopenssl.cnfをUTF-8で保存をして、上記処理を再度実施しました。 \n結果としてはまだうまく変換できませんでした。\n\nUTF8Stringの場合は正しく変換されていない。BITSTRINGの場合は先頭にゴミが入る。他のフォーマットを試してみたがうまく変換されない。正しくはe794b7\ne680a7 となるべき。\n\n```\n\n 設定1\n subjectAltName = otherName:Sex;UTF8String:男性\n 結果1\n Other Name:\n 1.1.1.5=0c 0c c3 a7 c2 94 c2 b7 c3 a6 c2 80 c2 a7\n \n \n \n 設定2\n subjectAltName = otherName:Sex;BITSTRING:男性\n 結果2\n Other Name:\n 1.1.1.5=03 07 00 e7 94 b7 e6 80 a7\n \n```\n\n上記のように先頭に無駄な文字が入ってしまいますが、BITSTRINGの場合が一番マシに変換できました。", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T12:30:07.793", "favorite_count": 0, "id": "11188", "last_activity_date": "2020-08-09T16:34:17.480", "last_edit_date": "2015-06-10T14:03:13.553", "last_editor_user_id": "9577", "owner_user_id": "9577", "post_type": "question", "score": 1, "tags": [ "windows", "openssl" ], "title": "OpenSSL: 証明書のSubjectaltname属性OtherNameにうまく日本語が設定できない。", "view_count": 1596 }
[ { "body": "設定ファイルがutf8なのにlatinとして受け取っているので、そのlatinをまたutf8にするパターンの文字化けでした。 \n5年も前なので解決済みでしょうが、私もはまってしまいました。 \nで、 `asn1` と `ASN1_generate_nconf` とにらめっこの末、以下の記述で解決しました。\n\n```\n\n FORMAT:UTF8,UTF8:男性\n \n```\n\nただ、設定ファイルの書き方によって、FORMATより前に色々書く必要があります。 \n私は以下の記述で解決しました。\n\n```\n\n otherName.1=1.1.1.5;FORMAT:UTF8,UTF8:男性\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2020-08-09T12:47:27.727", "id": "69394", "last_activity_date": "2020-08-09T16:34:17.480", "last_edit_date": "2020-08-09T16:34:17.480", "last_editor_user_id": "3060", "owner_user_id": "41438", "parent_id": "11188", "post_type": "answer", "score": 2 } ]
11188
69394
69394
{ "accepted_answer_id": null, "answer_count": 2, "body": "cordovaのmediaプラグインを利用して音楽再生のできるものを作成しようとしていますが、mediaプラグインにおいて、1ファイルの再生時間全体の取得ってできるでしょうか。 \nrangeを使って、100%のうち現在再生されているのは何%みたいなのを表示させたいと思っています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T13:55:50.753", "favorite_count": 0, "id": "11192", "last_activity_date": "2015-08-19T12:50:32.380", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9855", "post_type": "question", "score": 2, "tags": [ "monaca", "cordova" ], "title": "cordovaのmediaプラグイン1ファイルの再生時間全体の取得", "view_count": 242 }
[ { "body": "メディアプラグインの下記のメソッドを使用すると、全体の時間が分かります。\n\n```\n\n media.getDuration( )\n \n```\n\n参考情報 \n<http://docs.monaca.mobi/cur/ja/reference/phonegap_34/ja/media/>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T01:12:30.997", "id": "11264", "last_activity_date": "2015-06-12T01:12:30.997", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7461", "parent_id": "11192", "post_type": "answer", "score": 1 }, { "body": "user7461 さんも書かれていますが、\n\n演奏中における、現在の演奏位置(時間)は、media.getCurrentPosition() で取得できます。 \n全体の長さ(トラック全体の演奏時間)は、media.getDuration() で取得できます。\n\n但し、当方がAndroid環境で確認した限りでは、new Media() の直後に getDuration() を呼び出しても -1 が返され、play()\nを実行後に getCurrentPosition() のコールバック内で実行すると正しい値が返されました(私の環境だけなのか、仕様なのかはわかりません。)\n\n何パーセントか?を表示するとしたら、こんな感じでしょうか?\n\n```\n\n var totalTime = null;\n var media = new Media(url, onSuccess, onError);\n \n // ここで media.getDuration() とやると、-1 が返される?\n \n media.play();\n \n setInterval(function(){\n media.getCurrentPosition(function(position){\n if( totalTime == null )\n {\n totalTime = media.getDuration();\n }\n var elapsed = (100*position/totalTime).toFixed(1) + \"%\";\n document.getElementById('elapsed').innerHTML = elapsed;\n }, function(e){\n console.log(\"Error getting pos=\" + e);\n document.getElementById('elapsed').innerHTML = \"Error: \" + e;\n });\n }, 1000);\n \n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-20T08:28:47.157", "id": "11553", "last_activity_date": "2015-06-20T08:28:47.157", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9888", "parent_id": "11192", "post_type": "answer", "score": 1 } ]
11192
null
11264
{ "accepted_answer_id": "11203", "answer_count": 2, "body": "タイトル通りなのですが、railsで存在しないページにアクセスが有った場合に特定のページヘリダイレクトをかけるにはどうすればよいのでしょうか?\n\nActionControllerに下記のコードを追加してみたのですが、正しく動作しませんでした。\n\n```\n\n rescue_from ActionController::RoutingError, ActiveRecord::RecordNotFound, with: :render_404\n def render_404\n render action: \"works\"\n end \n \n```\n\n上記のApplicationControllerで制御する方法以外にも解決する方法などございましたら教えていただきたいです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-09T22:58:56.013", "favorite_count": 0, "id": "11197", "last_activity_date": "2015-06-10T04:52:35.740", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5840", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails" ], "title": "rails4で存在しないページにアクセスが有った時に特定のページヘリダイレクトしたい。", "view_count": 2691 }
[ { "body": "`redirect_to` を利用します。\n\n```\n\n def render_404\n redirect_to xxx_url\n end\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T00:55:37.500", "id": "11200", "last_activity_date": "2015-06-10T00:55:37.500", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "76", "parent_id": "11197", "post_type": "answer", "score": 2 }, { "body": "rescueする内容にMissingTemplateを追加すればよろしいかと。\n\n```\n\n rescue_from ActionView::MissingTemplate, with: :render_404\n def render_404\n render template: 'errors/error404', status: 404\n end\n \n```\n\n後、config/routes.rbにルーティングエラーを捕捉する処理を追加。\n\n```\n\n get '*unmatched_route', to: 'application#render_404'\n \n```\n\nとすればview/errors/error404.html.erbが表示されます。エラー番号に合わせてカスタマイズしたエラーページを表示する方法です。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T04:52:35.740", "id": "11203", "last_activity_date": "2015-06-10T04:52:35.740", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9202", "parent_id": "11197", "post_type": "answer", "score": 2 } ]
11197
11203
11200
{ "accepted_answer_id": null, "answer_count": 0, "body": "monacaを使用してbatterystatusを定期的に読み取るようなことは可能なのでしょうか?\n\nサンプルにあるコード\n\n```\n\n window.addEventListener(\"batterystatus\", onBatteryStatus, false);\n function onBatteryStatus(info) {\n // Handle the online event\n console.log(\"Level: \" + info.level + \" isPlugged: \" + info.isPlugged);\n }\n \n```\n\nを実装してみたのですが、動作させることが出来ません。 \nすみませんが、アドバイスをお願い致します。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T01:26:32.850", "favorite_count": 0, "id": "11201", "last_activity_date": "2015-06-10T02:46:55.187", "last_edit_date": "2015-06-10T02:46:55.187", "last_editor_user_id": "3639", "owner_user_id": "10077", "post_type": "question", "score": 1, "tags": [ "monaca" ], "title": "monacaで電源状態を取得する方法について", "view_count": 84 }
[]
11201
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "MAC OSX Yosemite 10.10.3を使用しています。\n\nこちらでMAMPをインストールし、SQLサーバApache、並びにMAMPのトップ画面の起動に成功しました。\n\nしかし、ここからツール→phpMyAdminを開くと以下のエラーが発生しSQL編集が行えません。 \n![画像の説明をここに入力](https://i.stack.imgur.com/Shjz4.png) \nエラーコード等で対応調べましたが、パーミッションの確認程度しか情報がありませんでした。 \n(/Application/MAMP/tmp/phpのパーミッション。)\n\nセッションのIDに不正な文字が入っているんでしょうか? \nどちらから設定できますか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T01:39:57.147", "favorite_count": 0, "id": "11202", "last_activity_date": "2015-08-10T04:09:32.557", "last_edit_date": "2015-06-10T05:00:03.877", "last_editor_user_id": "8000", "owner_user_id": "10057", "post_type": "question", "score": 1, "tags": [ "php", "macos", "phpmyadmin", "mamp" ], "title": "session_start(): The session id is too long or contains illegal characters", "view_count": 986 }
[ { "body": "`php.ini` で `session.use_strict_mode` を `Off` にするか\n\n```\n\n session.use_strict_mode = Off\n \n```\n\nブラウザのクッキー(PHPSESSID) を削除してみて下さい。\n\n<http://blog.tokumaru.org/2013/08/php-5.5.2-strict-sessions.html> \n<https://stackoverflow.com/questions/3185779/the-session-id-is-too-long-or-\ncontains-illegal-characters-valid-characters-are>", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T01:45:26.183", "id": "11243", "last_activity_date": "2015-06-11T01:45:26.183", "last_edit_date": "2017-05-23T12:38:56.083", "last_editor_user_id": "-1", "owner_user_id": "2432", "parent_id": "11202", "post_type": "answer", "score": 1 } ]
11202
null
11243
{ "accepted_answer_id": "11214", "answer_count": 4, "body": "(諸般の事情で該当のコードなどを提示することができないのですが、問題解決のために必要であれば別途用意いたします)\n\n表題の通り、InternetExplorer 11 において、開発者ツールを立ち上げていないと期待した挙動をしない問題に直面しております。\n\nいずれも JavaScript の絡んだ処理でしたので、ドキュメントモードなどが原因かと思いましたが、 meta\nタグを用いて以下のようにドキュメントモードを明示的に指定しても期待した動きになりませんでした。\n\n```\n\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n \n```\n\n開発者ツールを立ち上げると、リロードもせずに期待した動きをするようになります。 \n問題の切り分け、原因として何が考えられるでしょうか。\n\nなお、 Firefox、GoogleChrome ではとくに問題なく動作いたします。\n\n追記:ご指摘をうけ、利用している JavaScript のライブラリ、フレームワークを追記しました。\n\n * jQuery 2.1.4\n * Backbone.js 1.2.1\n * Marionette.js 2.3.1\n * lodash.js 3.8.0\n\n追記2:調査を進めた結果、サーバーに問い合わせが発生する箇所で、本来サーバーに記録されるログすらも生成されていないことが判明しました。 \nこれらは全て Ajax 通信によるやりとりのもので、やはり開発者ツールを立ち上げると正常にログが記録されておりました。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T05:46:33.743", "favorite_count": 0, "id": "11204", "last_activity_date": "2022-06-17T09:23:34.553", "last_edit_date": "2015-06-11T01:18:45.797", "last_editor_user_id": "5827", "owner_user_id": "5827", "post_type": "question", "score": 6, "tags": [ "javascript", "html5", "ajax", "backbone.js" ], "title": "IE11 で開発者ツールを起動していないと ConsoleAPI や Ajax 通信が期待した挙動をしない", "view_count": 7438 }
[ { "body": "[IE11でドキュメントモードが使用されるときのフローチャート](https://web.archive.org/web/20150926213022/http://blogs.msdn.com:80/b/ie_jp/archive/2015/05/25/10616897.aspx)がわかりやすいでしょうか。X-UA-\nCompatible meta tagでの指定はIE=8までとされています。 \nIE11でのedgeモードは\n\n```\n\n <!doctype html>\n \n```\n\nでの宣言となります。またその際、ローカルの互換表示一覧とイントラネット設定の影響も受けます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2015-06-10T06:18:35.693", "id": "11208", "last_activity_date": "2022-06-17T09:23:34.553", "last_edit_date": "2022-06-17T09:23:34.553", "last_editor_user_id": "19769", "owner_user_id": "4236", "parent_id": "11204", "post_type": "answer", "score": 2 }, { "body": "手元にIE11が無いので、確認はできていないのですが、以前にIE9でconsole.logを使った時に、consoleオブジェクトがundefinedでエラーになることがありました。\n\nconsole.logに対応していない場合は,\nロード時にとりあえずconsoleオブジェクトとconsole.log関数を生成してエラーにはしないようにすることで対応ができました。\n\n```\n\n (function () {\n if (typeof window.console === \"undefined\") {\n window.console = {}\n }\n if (typeof window.console.log !== \"function\") {\n window.console.log = function () {}\n }\n })();\n \n```\n\n参考サイト \n<http://qiita.com/1987yama3/items/c761cfc241033ffbfab5>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T06:29:44.413", "id": "11210", "last_activity_date": "2015-06-10T06:29:44.413", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9529", "parent_id": "11204", "post_type": "answer", "score": 7 }, { "body": "超ローテクになりますが、正常に動作するところまで、怪しい部分をコメントアウトして、原因の箇所を特定するという方法はいかがでしょうか?\n\n正常に動作するところから少しずつ、コメントを外してコードを追加していけば、エラーの箇所が特定できます。\n\nどこが悪いか皆目検討がつかない時につかえる手法です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T06:33:27.593", "id": "11211", "last_activity_date": "2015-06-10T06:33:27.593", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9529", "parent_id": "11204", "post_type": "answer", "score": 2 }, { "body": "> 開発者ツールを立ち上げていないと期待した挙動をしない問題\n\nこの部分がどの様な現象かわからないので、推測になりますが...\n\n> サーバーに問い合わせが発生する箇所で、本来サーバーに記録されるログすらも生成されていない\n\nIEのajaxのキャッシュの問題ではないでしょうか?\n\n```\n\n $.ajaxSetup({\n cache: false, // こいつを追加\n });\n \n```\n\n参考サイト \n<http://www.tailtension.com/jquery/1384/> \n<http://nobnoob.hatenablog.com/entry/2013/03/10/080419> \n他にも「ie ajax キャッシュ」で検索すると沢山出てきます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T08:05:13.850", "id": "11214", "last_activity_date": "2015-06-10T08:05:13.850", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9529", "parent_id": "11204", "post_type": "answer", "score": 11 } ]
11204
11214
11214
{ "accepted_answer_id": "11206", "answer_count": 1, "body": "javaで文字列に¥が入っているか調べたかったので\n\n```\n\n if(str.equals(\"¥\")){\n ~\n }\n \n```\n\nとしたところ、文字リテラルが閉じられていませんとコンパイルエラーになりました。 \nどう書けばいいのでしょうか。\n\n※このサイトでは¥が全角になっていますが、本当は半角です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T05:48:56.563", "favorite_count": 0, "id": "11205", "last_activity_date": "2015-06-10T13:16:01.453", "last_edit_date": "2015-06-10T13:16:01.453", "last_editor_user_id": "440", "owner_user_id": "9850", "post_type": "question", "score": 1, "tags": [ "java" ], "title": "javaで文字列に¥が入っているか調べたい", "view_count": 1556 }
[ { "body": "便宜上、本回答でも全角の¥を用います。\n\n * equalsメソッドは「文字列が同じであるか」を調べるメソッドですので、 **含まれている** には適しません。\n * 含まれているかを調べるにはcontainsメソッドを使います\n * Javaでは¥はエスケープ文字と呼ばれ、 **後ろに続く文字と合わせることで** 特殊な文字列を意味する記号となります。\n * ¥そのものを示す場合は ¥¥ と2つ並べます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T05:58:17.450", "id": "11206", "last_activity_date": "2015-06-10T05:58:17.450", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5778", "parent_id": "11205", "post_type": "answer", "score": 4 } ]
11205
11206
11206
{ "accepted_answer_id": null, "answer_count": 1, "body": "modxを使い始めてまだ間もないのですが、どうしても行き詰まってしまっているのでご質問させて下さい。\n\n現在MAMP上で作業を進めていて、外部PHPスクリプトからmodxオブジェクトを生成してコンテンツのデータベースの値(具体的にはテンプレート変数)を書き換えるという処理を行おうとしています。\n\n以下に従っています。\n\n<http://modx.jp/docs/dev/basic.html>\n\nまた、プログラムの処理自体は一度プラグインとして実装し、期待通りのDB内のデータを書き換えれることを確認しています。現在はPVをカウントする機能を作っているので、PVを定期的に0にリセットする処理を行いたいと思い、cronの利用を考えています。cronからだとプログラムをスクリプトとして用意しておく必要があると思い、現在プラグインで実装したものを通常のPHPスクリプトに書き換えようとしています。\n\nPHPスクリプトは以下です。\n\n```\n\n <?php\n \n // modxオブジェクト生成\n define('MODX_API_MODE', true);\n $path = dirname(__FILE__).'/';\n include($path.'index.php');\n $modx = new DocumentParser;\n $modx->db->connect();\n $modx->getSettings();\n \n $tmplvars_name = 'pvc.day';\n \n /*\n * 日のリアルタイムPVを0にリセット\n */\n // ページビューを計測しているか確認\n $pv = $modx->getTemplateVarOutput(array('pvc.day'));\n if ($pv !== false) {\n $res = $modx->dbQuery(\"SELECT id FROM modx_site_tmplvars WHERE name = '\".$tmplvars_name.\"'\");\n $arr = $modx->fetchRow($res);\n $modx->dbQuery(\"UPDATE modx_site_tmplvar_contentvalues SET value = 0 WHERE tmplvarid = \".$arr[\"id\"]);\n }\n \n```\n\nここで、\n\n$ /Applications/MAMP/bin/php/php5.6.7/bin/php ./reset_pv_day.php\n\nのようにスクリプトをを実行すると以下のようなエラーが出ます。\n\n> Notice: Undefined index: PATH_INFO in\n> /Applications/MAMP/htdocs/manager/includes/initialize.inc.php on line 170 \n> Warning: gethostbyaddr(): Address is not a valid IPv4 or IPv6 address in\n> /Applications/MAMP/htdocs/manager/includes/extenders/sub.document.parser.class.inc.php\n> on line 154 \n> Error\n\nまた以下のようにしてmodx libraryを使った方法も試してみたのですが、\n\n```\n\n // modx apiの読み込み\n $path = dirname(__FILE__).'/';\n include_once($path.'modxapi.php');\n // modxオブジェクトの生成\n $modx = new MODxAPI();\n \n```\n\n以下のようなエラーが出てしまいます。\n\n> Notice: Undefined index: PATH_INFO in\n> /Applications/MAMP/htdocs/manager/includes/initialize.inc.php on line 170 \n> Notice: Undefined index: REQUEST_URI in\n> /Applications/MAMP/htdocs/manager/includes/initialize.inc.php on line 130 \n> Notice: Undefined index: SERVER_PORT in\n> /Applications/MAMP/htdocs/manager/includes/initialize.inc.php on line 158 \n> Notice: Undefined index: HTTP_HOST in\n> /Applications/MAMP/htdocs/manager/includes/initialize.inc.php on line 137\n\nMAMP特有の問題かなと思い本番環境でも一応試してみたのですがErrorとなりうまく動作しません。\n\nご回答いただけますと非常に助かります、よろしくお願い致します...!\n\n現在の環境は以下のようになっています.\n\n * サーバ:MAMP\n * MODXのバージョン:1.0.14J-r9\n * PHPのバージョン:5.6.7\n * MySQLのバージョン:5.5.42\n * ブラウザ:Chrome", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T06:00:22.837", "favorite_count": 0, "id": "11207", "last_activity_date": "2016-09-30T01:42:07.187", "last_edit_date": "2015-06-10T06:09:14.477", "last_editor_user_id": "3639", "owner_user_id": "10084", "post_type": "question", "score": 1, "tags": [ "php" ], "title": "外部PHPスクリプトからmodxのAPIを利用してコンテンツのデータベースの値を書き換える方法について", "view_count": 366 }
[ { "body": "modxのAPIを使うことは諦め,PHPスクリプトから直接DBにアクセスする方法でテンプレート変数の値を書き換えることでひとまず解決しました.\n\nありがとうございました.\n\nSQLベタ書きであれですが,以下の感じのスクリプトで更新処理を行うようにしました.一応掲載させていただきます.\n\n```\n\n <?php\n \n /*\n * 日のリアルタイムPVを0にリセット\n */\n \n require_once 'config.php';\n \n try {\n $dbh = new PDO('mysql:host=localhost;dbname=database', $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));\n } catch (PDOException $e) {\n echo 'Connection failed: ' . $e->getMessage();\n }\n \n $tmplvars_name = 'pvc.day';\n \n $select_sql = \"SELECT id FROM modx_site_tmplvars WHERE name='\".$tmplvars_name.\"'\";\n $stmt = $dbh->query($select_sql);\n $result = $stmt->fetch(PDO::FETCH_ASSOC);\n echo $result[\"id\"];\n \n $update_sql = \"UPDATE modx_site_tmplvar_contentvalues SET value=0 WHERE tmplvarid=\".$result[\"id\"];\n echo $update_sql;\n echo \"\\n\";\n if($dbh->query($update_sql)) {\n echo \"Success!\";\n }else {\n echo \"Failed...\";\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T08:33:47.750", "id": "11215", "last_activity_date": "2015-06-10T08:33:47.750", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10084", "parent_id": "11207", "post_type": "answer", "score": 1 } ]
11207
null
11215
{ "accepted_answer_id": null, "answer_count": 1, "body": "ユーザ認証にDeviseを使っています。メール認証(:confirmable)を有効化したいのですが、なぜかできません。 \n今のところサインアップやログインは全て可能ですが、メール認証だけができません。 \n解決方法か解決のヒントだけでも教えていただければ幸いです。\n\n<やったこと> \ngemにdeviseを入れる。\n\n```\n\n gem 'devise'\n $ bundle install\n $ bundle exec rails generate devise:install\n \n```\n\n送信メール設定\n\n```\n\n <config/environments/development.rb>\n config.action_mailer.default_url_options = { :host => 'localhost:3000' }\n config.action_mailer.delivery_method = :smtp\n \n config.action_mailer.smtp_settings = {\n :address => \"smtp.gmail.com\",\n :port => 587,\n :user_name => '',\n :password => '',\n :authentication => 'cram_md5',\n :enable_starttls_auto => true\n }\n \n```\n\nUserモデルにDeviseのメール認証用コラムを追加\n\n```\n\n <db/migrate/*****_devise_create_users.rb>\n ## Confirmable\n t.string :confirmation_token\n t.datetime :confirmed_at\n t.datetime :confirmation_sent_at\n t.string :unconfirmed_email \n \n $rake db:create\n \n```\n\nUserモデルにdeviseメソッドの引数として:confirmableを指定。\n\n```\n\n <app/models/user.rb>\n devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable\n \n```\n\nroutesファイルにdeviseを指定\n\n```\n\n <config/routes.rb>\n devise_for :users\n \n```\n\nSign up画面からユーザー登録するとメールが送信されずにいきなり認証済みでシステム内に入ってしまいます。\n\n認証メールをスキップするskip_confirmation!を検索してもヒットしません。\n\n```\n\n $ grep -r skip_confirmation! * \n \n```\n\nUserのレコードを確認するとメール認証で入るべき項目が全てnilです。\n\n```\n\n [2] pry(main)> User.last\n => #<User id: 13, email: \"[email protected]\", encrypted_password: \"...\", sign_in_count: 1, current_sign_in_at: \"2015-06-10 06:38:43\", last_sign_in_at: \"2015-06-10 06:38:43\", confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, created_at: \"2015-06-10 06:38:43\", updated_at: \"2015-06-10 06:38:43\">\n \n```\n\nログを確認するとメールを送信している様子は一切ありません。\n\n```\n\n [no_token] Processing by Users::RegistrationsController#create as HTML\n [no_token] Parameters: {\"utf8\"=>\"✓\", \"authenticity_token\"=>\"iLnOw9NgUzjUHOGmF7X2ejvlfxbjyNqSe4NNBZVbltE=\", \"user\"=>{\"name\"=>\"pozedi\", \"email\"=>\"[email protected]\", \"password\"=>\"[FILTERED]\", \"password_confirmation\"=>\"[FILTERED]\"}, \"commit\"=>\"Sign up\"}\n [no_token] (0.6ms) BEGIN\n [no_token] User Exists (0.7ms) SELECT 1 AS one FROM \"users\" WHERE \"users\".\"email\" = '[email protected]' LIMIT 1\n [no_token] User Exists (0.8ms) SELECT 1 AS one FROM \"users\" WHERE (\"users\".\"email\" = '[email protected]' AND \"users\".\"deleted_at\" IS NULL) LIMIT 1\n [no_token] User Load (0.9ms) SELECT \"users\".* FROM \"users\" WHERE \"users\".\"deleted_at\" IS NULL AND \"users\".\"auth_token\" = '3TF5yoyxZjJdsKz12d-u' ORDER BY \"users\".\"id\" ASC LIMIT 1\n [no_token] SQL (0.8ms) INSERT INTO \"users\" (\"auth_token\", \"created_at\", \"email\", \"encrypted_password\", \"metadata\", \"name\", \"updated_at\") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING \"id\" [[\"auth_token\", \"3TF5yoyxZjJdsKz12d-u\"], [\"created_at\", \"2015-06-10 06:38:43.365969\"], [\"email\", \"[email protected]\"], [\"encrypted_password\", \"$2a$10$3GLpAyPdHupojLx2fRF4aO4PxCWLcJ/MTx6n.T3qNOapXd2OQgUIu\"], [\"metadata\", \"{}\"], [\"name\", \"pozedi\"], [\"updated_at\", \"2015-06-10 06:38:43.365969\"]]\n [no_token] (0.9ms) COMMIT\n [no_token] (0.6ms) BEGIN\n [no_token] SQL (1.0ms) UPDATE \"users\" SET \"current_sign_in_at\" = $1, \"current_sign_in_ip\" = $2, \"last_sign_in_at\" = $3, \"last_sign_in_ip\" = $4, \"metadata\" = $5, \"sign_in_count\" = $6, \"updated_at\" = $7 WHERE \"users\".\"id\" = 13 [[\"current_sign_in_at\", \"2015-06-10 06:38:43.417435\"], [\"current_sign_in_ip\", \"127.0.0.1/32\"], [\"last_sign_in_at\", \"2015-06-10 06:38:43.417435\"], [\"last_sign_in_ip\", \"127.0.0.1/32\"], [\"metadata\", \"{}\"], [\"sign_in_count\", 1], [\"updated_at\", \"2015-06-10 06:38:43.431023\"]]\n [no_token] (1.0ms) COMMIT\n [no_token] Redirected to http://localhost:3000/users/13\n [no_token] Completed 302 Found in 310ms (ActiveRecord: 7.3ms)\n \n```\n\nなぜでしょうか!?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T07:05:50.110", "favorite_count": 0, "id": "11212", "last_activity_date": "2015-06-11T12:43:43.287", "last_edit_date": "2015-06-10T07:32:04.710", "last_editor_user_id": "5793", "owner_user_id": "9202", "post_type": "question", "score": 3, "tags": [ "ruby-on-rails", "ruby", "devise" ], "title": "Deviseのメール認証が有効化されない", "view_count": 2583 }
[ { "body": "送信メールの設定で、Gmailを使う場合Gmail側のセキュリティ設定を下げないと \nメールが送られなかった気がします。 \nこちらでは以下の設定でメールは送れている感じです。\n\nプロジェクト作成\n\n```\n\n $ rails new sample\n \n```\n\nGemfile修正\n\n```\n\n gem 'devise'\n \n```\n\nルート用ページなどの用意\n\n```\n\n $ bundle install\n $ rails generate devise:install\n $ rails g controller Pages index\n $ rails g devise User\n \n```\n\ndevelopment.rb\n\n```\n\n config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } \n config.action_mailer.delivery_method = :smtp\n config.action_mailer.smtp_settings = { \n :address => \"smtp.gmail.com\", \n :port => 587,\n :user_name => \"メールアドレス\",\n :password => \"パスワード\",\n :authentication => :plain, \n :enable_starttls_auto => true\n }\n \n```\n\nuser.rb\n\n```\n\n devise :database_authenticatable, :registerable,\n :recoverable, :confirmable, :rememberable, :trackable, :validatable\n \n```\n\nroutes.rb\n\n```\n\n devise_for :users\n root 'pages#index'\n \n```\n\ndevise.rb\n\n```\n\n config.reconfirmable = false\n \n```\n\nYYYYMMDDXXXXXXX_devise_create_users.rb\n\n```\n\n t.string :confirmation_token\n t.datetime :confirmed_at\n t.datetime :confirmation_sent_at\n t.string :unconfirmed_email\n \n```\n\n上記設定して\n\n```\n\n $ rake db:migrate\n $ rails server\n \n```\n\ndevelopment.rbにしていしたGmailアカウントで \n[安全性の低いアプリを許可](https://www.google.com/settings/security/lesssecureapps)をオンに設定。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T12:14:33.907", "id": "11260", "last_activity_date": "2015-06-11T12:43:43.287", "last_edit_date": "2015-06-11T12:43:43.287", "last_editor_user_id": "5933", "owner_user_id": "5933", "parent_id": "11212", "post_type": "answer", "score": -1 } ]
11212
null
11260
{ "accepted_answer_id": null, "answer_count": 1, "body": "Routing Error \nNo route matches [POST] \"/\" \nと出てしまい詰まってしまいました。\n\n処理内容。 \nトップページにform_forでベータ版のメールアドレスを登録する入力窓を置き、そこにメールアドレスを入れてsubmitするとデータベースに保存されるという単純な処理なのですが、ルーティングエラーで先に進めません。 \n以下コントローラー\n\n```\n\n class RootController < ApplicationController\n def index\n @articles = Article.all\n end\n \n def new\n @guest = UserInvitationBetarelease.new\n end\n \n def create\n @guest = UserInvitationBetarelease.new(guest_params)\n @guest.save\n redirect_to root_index_path\n end\n \n private\n \n def guest_params\n params.require(:guest).permit(:email)\n end\n end\n \n```\n\n * 以下View\n\n= form_for :guest do |f| \n= f.text_field :email \n= f.submit \"送信\"\n\nルートファイルは以下 \n`resouces :root`\n\n教えていただければ幸いです", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T08:50:25.443", "favorite_count": 0, "id": "11216", "last_activity_date": "2015-06-10T10:12:59.317", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "1065", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "ruby" ], "title": "Ruby on Railsのルーティングエラーに関して", "view_count": 5544 }
[ { "body": "POST / が定義されていないのに、そこにアクセスした為のエラーです。 \n下記の rake コマンドで、現在定義されているルートを確認することができます。 \nこのコマンドの結果と、config/routes.rbの設定、formのaction属性を比べながら対応してはいかがでしょうか?\n\n```\n\n bin/rake routes\n \n```\n\nresources :root と指定した場合...\n\n```\n\n # config/routes.rb\n \n resources :root\n \n```\n\n以下のような感じで、`/root`から定義されるはずです。\n\n```\n\n $ bin/rake routes\n Prefix Verb URI Pattern Controller#Action\n root_index GET /root(.:format) root#index\n POST /root(.:format) root#create\n new_root GET /root/new(.:format) root#new\n edit_root GET /root/:id/edit(.:format) root#edit\n root GET /root/:id(.:format) root#show\n PATCH /root/:id(.:format) root#update\n PUT /root/:id(.:format) root#update\n DELETE /root/:id(.:format) root#destroy\n \n```\n\nformタグのaction URL が間違っているのでは無いでしょうか?\n\nそれと、厳密には調べていませんが、rootというリソース名やコントローラ名は、予約語に該当してしまいそうで、あまり良くないかと思います。変更することをおすすめします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T09:31:50.657", "id": "11219", "last_activity_date": "2015-06-10T10:12:59.317", "last_edit_date": "2015-06-10T10:12:59.317", "last_editor_user_id": "9529", "owner_user_id": "9529", "parent_id": "11216", "post_type": "answer", "score": 1 } ]
11216
null
11219
{ "accepted_answer_id": "11447", "answer_count": 1, "body": "boost::mpl::accumulate や fold のネストはどうやったら実装できますか。\n\n```\n\n namespace mpl=boost::mpl;\n \n typedef mpl::vector<mpl::int_<1>,mpl::int_<1>,mpl::int_<1>,mpl::int_<1>> vec1;\n typedef mpl::vector<mpl::int_<2>,mpl::int_<2>,mpl::int_<2>,mpl::int_<2>> vec2;\n typedef mpl::vector<mpl::int_<3>,mpl::int_<3>,mpl::int_<3>,mpl::int_<3>> vec3;\n typedef mpl::vector<vec1,vec2,vec3> vvec;\n \n typedef typename mpl::lambda\n <mpl::accumulate\n <mpl::_1 ,mpl::int_<0> ,mpl::plus<mpl::_1,mpl::_2> >\n >::type lam;\n \n typedef typename mpl::accumulate\n <vvec\n ,mpl::int_<0>\n ,mpl::plus<mpl::_1,lam::template apply<mpl::_2>::type>\n >::type result;\n \n```\n\nこのコードはコンパイルが通りませんでした。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T08:59:30.100", "favorite_count": 0, "id": "11217", "last_activity_date": "2015-06-17T15:44:04.823", "last_edit_date": "2015-06-10T13:13:41.883", "last_editor_user_id": "3639", "owner_user_id": "9247", "post_type": "question", "score": 2, "tags": [ "c++", "boost" ], "title": "boost::mpl::accumulate のネスト", "view_count": 113 }
[ { "body": "[Placeholder\nExpression](http://www.boost.org/doc/libs/1_50_0/libs/mpl/doc/refmanual/placeholder-\nexpression.html)に対して、`type`を使うと、placeholderにplaceholderの番号を代入してメタ式を評価してしまいます。\n\nまた、lambdaの中にメタ式をネストしてplaceholderを使う場合、placeholderには、一番近いlambdaのメタ引数が束縛されてしまいます。その結果、lambdaの中のplus式にメタ値が代入されてしまって、これはもはや式ではないので、accumulateの評価の際に、第三メタ引数にメタ式ではなくメタ値があるのでエラーになるのだと思います。 \nこれを防ぐためには、plusを別のlambdaで囲んで、外側のlambdaのメタ引数が束縛されないようにします。\n\n以上を考慮すると以下の様にコードを修正すれば良いです。\n\n```\n\n #include <boost/mpl/int.hpp>\n #include <boost/mpl/placeholders.hpp>\n #include <boost/mpl/apply.hpp>\n #include <boost/mpl/vector.hpp>\n #include <boost/mpl/lambda.hpp>\n #include <boost/mpl/accumulate.hpp>\n #include <boost/mpl/plus.hpp>\n \n #include <iostream>\n \n using namespace boost;\n \n typedef mpl::vector<mpl::int_<1>,mpl::int_<1>,mpl::int_<1>,mpl::int_<1>> vec1;\n typedef mpl::vector<mpl::int_<2>,mpl::int_<2>,mpl::int_<2>,mpl::int_<2>> vec2;\n typedef mpl::vector<mpl::int_<3>,mpl::int_<3>,mpl::int_<3>,mpl::int_<3>> vec3;\n typedef mpl::vector<vec1,vec2,vec3> vvec;\n \n typedef typename mpl::lambda<\n mpl::accumulate<\n mpl::_1, mpl::int_<0>, mpl::lambda<mpl::plus<mpl::_1, mpl::_2>>::type\n >\n >::type lamb;\n \n typedef typename mpl::accumulate<\n vvec\n , mpl::int_<0>\n , mpl::plus<mpl::_1, lamb::apply<mpl::_2>>\n >::type result;\n \n \n int main ()\n {\n static_assert(result::value == 24, \"\");\n }\n \n```\n\n上記のコードではテンプレートの`>>`等のC++11 specificな文法が一部使われているので、C++03でコンパイルする際は適切に変更してください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-17T15:38:40.527", "id": "11447", "last_activity_date": "2015-06-17T15:44:04.823", "last_edit_date": "2015-06-17T15:44:04.823", "last_editor_user_id": "9968", "owner_user_id": "9968", "parent_id": "11217", "post_type": "answer", "score": 1 } ]
11217
11447
11447
{ "accepted_answer_id": null, "answer_count": 1, "body": "```\n\n #include <gtk/gtk.h>\n #include <math.h>\n \n gboolean redraw(GtkWidget *w, gpointer user_data);\n gboolean draw(GtkWidget *w, gpointer user_data);\n \n int main(int argc, char **argv)\n {\n GtkWidget *win, *l1, *l2, *l3, *l4, *vbox, *hbox, *b1, *b2;\n gtk_init(&argc, &argv);\n \n /* make a window */\n win = gtk_window_new(GTK_WINDOW_TOPLEVEL);\n g_signal_connect(win, \"destroy\", gtk_main_quit, NULL);\n \n /* make a label, make a drawing area */\n l1 = gtk_label_new(\"New\");\n l2 = gtk_drawing_area_new();\n l3 = gtk_label_new(\"Redraw\");\n l4 = gtk_label_new(\"EXIT\");\n \n /*make a button*/\n b1 = gtk_button_new();\n b2 = gtk_button_new();\n \n /* make a vbox */\n vbox = gtk_vbox_new(FALSE, 0);\n gtk_container_add(GTK_CONTAINER(win), vbox);\n gtk_box_pack_start(GTK_BOX(vbox), l1, TRUE, TRUE, 0);\n gtk_box_pack_start(GTK_BOX(vbox), l2, TRUE, TRUE, 0);\n g_signal_connect(l2, \"expose_event\", G_CALLBACK(draw), NULL);\n gtk_widget_set_size_request(l2, 400, 200);\n \n /* make a hbox */\n hbox = gtk_hbox_new(TRUE, 0);\n gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);\n \n gtk_box_pack_start(GTK_BOX(hbox), b2, TRUE, TRUE, 0);\n g_signal_connect(b2, \"clicked\", G_CALLBACK(redraw), NULL);\n gtk_container_add(GTK_CONTAINER(b2), l3);\n \n gtk_box_pack_start(GTK_BOX(hbox), b1, TRUE, TRUE, 0);\n g_signal_connect(b1, \"clicked\", gtk_main_quit, NULL);\n gtk_container_add(GTK_CONTAINER(b1), l4);\n \n gtk_widget_show_all(win);\n \n gtk_main();\n \n return 0;\n }\n \n gboolean redraw(GtkWidget *w, gpointer user_data)\n { \n }\n \n gboolean draw(GtkWidget *w, gpointer user_data) \n {\n gdk_draw_rectangle(w->window, w->style->fg_gc[GTK_WIDGET_STATE(w)],\n TRUE, 100, 50, 200, 100);\n \n return TRUE;\n }\n \n```\n\n中央の部分に描画された図形がRedrawボタンを押すと消えたり現れたりするプログラムをredraw関数内に書きたいのですがアイデアが浮かびません。どなたかお力添えお願いできないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T10:22:47.753", "favorite_count": 0, "id": "11220", "last_activity_date": "2015-10-22T10:43:21.383", "last_edit_date": "2015-10-22T10:43:21.383", "last_editor_user_id": "10019", "owner_user_id": "10019", "post_type": "question", "score": -3, "tags": [ "c", "gtk" ], "title": "C言語についての質問", "view_count": 324 }
[ { "body": "まず redraw の clicked のパラメータに描画エリア l2 を渡します。\n\n```\n\n g_signal_connect(b2, \"clicked\", G_CALLBACK(redraw), l2);\n \n```\n\nそしてイベントハンドラで static 変数をトグルさせてその状態に従って描画エリアの表示/非表示を切り替えます。\n\n```\n\n gboolean redraw(GtkWidget *w, gpointer user_data)\n { \n static int visible = 1;\n GtkWidget *l2 = (GtkWidget*) user_data;\n visible = !visible;\n \n if (visible)\n gtk_widget_show(l2);\n else\n gtk_widget_hide(l2);\n return TRUE;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T10:39:19.723", "id": "11221", "last_activity_date": "2015-06-10T13:14:39.277", "last_edit_date": "2015-06-10T13:14:39.277", "last_editor_user_id": "440", "owner_user_id": "440", "parent_id": "11220", "post_type": "answer", "score": 1 } ]
11220
null
11221
{ "accepted_answer_id": null, "answer_count": 1, "body": "お世話になります。\n\nPostfixでパイプを使ってphpを実行する設定を行っております。 \n何か足りないものがあるのでしょうか? \nご教授のほどお願いします \n(以前別の環境で設定したところうまくいきました)\n\n* * *\n\n環境 \nLinux CentOS 6.6 \nPostfix 2.6.6\n\n1. \nmaster.cfにプログラム起動のパイプ処理を追加する。 \n参考で下記のように行いました\n\n```\n\n webmaster-test unix - n n - - pipe\n flags=R user=vmailuser argv=/usr/bin/php -f /tmp/test.php $sender\n \n```\n\n2. \ntransportでパイプに渡すメールアドレスを追加する。\n\n```\n\n webmaster@***.com webmaster-test\n \n```\n\nこれでwebmaster@***.comにメールを送信すると/tmp/test.phpが実行されると思うのですが実行されません。\n\n##\[email protected]→webmaster@***.comに送ったときのmaillogです。smtpのところにdisconnectと出ていますが、送受信はできています。\n\nJun 10 22:54:30 shcnwq postfix/smtpd[1624]: connect from\nwww937.sakura.ne.jp[219.94.128.177] \nJun 10 22:54:30 shcnwq postfix/smtpd[1624]: A3077A4DB2:\nclient=www937.sakura.ne.jp[219.94.128.177] \nJun 10 22:54:30 shcnwq postfix/cleanup[1637]: A3077A4DB2: message-\nid=<[email protected]> \nJun 10 22:54:30 shcnwq postfix/qmgr[1402]: A3077A4DB2: from=, size=1376,\nnrcpt=1 (queue active) \nJun 10 22:54:30 shcnwq postfix/virtual[1639]: A3077A4DB2: to=, relay=virtual,\ndelay=0.18, delays=0.15/0.03/0/0.01, dsn=2.0.0, status=sent (delivered to\nmaildir) \nJun 10 22:54:30 shcnwq postfix/qmgr[1402]: A3077A4DB2: removed \nJun 10 22:54:30 shcnwq postfix/smtpd[1624]: disconnect from\nwww937.sakura.ne.jp[219.94.128.177]", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T11:46:01.797", "favorite_count": 0, "id": "11223", "last_activity_date": "2015-06-11T00:10:17.900", "last_edit_date": "2015-06-10T14:11:24.010", "last_editor_user_id": "8168", "owner_user_id": "8168", "post_type": "question", "score": 0, "tags": [ "postfix" ], "title": "Postfixでパイプを使ってphpを実行する。", "view_count": 1027 }
[ { "body": "次のいずれかではないかと思います。\n\n 1. main.cf の transport_maps パラメータが transport ファイルを参照していない\n 2. postmap コマンドで transport ファイルをDB化していない\n 3. postmap コマンド実行後に postfix reload していない", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T00:10:17.900", "id": "11240", "last_activity_date": "2015-06-11T00:10:17.900", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3249", "parent_id": "11223", "post_type": "answer", "score": 1 } ]
11223
null
11240
{ "accepted_answer_id": "11259", "answer_count": 1, "body": "n の約数の個数を d(n) と表すことにする。 \n1から10までの整数に対し、 \nd(n) = 1 となるのは1個、 \nd(n) = 2 となるのは4個、 \nd(n) = 3 となるのは2個、 \nd(n) = 4 となるのは3個ある。\n\n一般に、 \n1からNまでの整数に対し、「約数の数がs個になる」のはいくつあるか調べるには \nどうすれば速く求まるでしょうか?\n\nとりあえずなんの工夫もしていないコードをあげておきます。\n\n```\n\n require 'prime'\n \n N = 10 ** 2\n h = {}\n (1..N).each{|i|\n s = 1\n i.prime_division.map{|j| s *= j[1] + 1}\n h.key?(s) ? h[s] += 1 : h[s] = 1\n }\n p h\n \n```\n\n出力結果 \n{1=>1, 2=>25, 3=>4, 4=>32, 6=>16, 5=>2, 8=>10, 9=>2, 10=>2, 12=>5, 7=>1}", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T13:02:43.023", "favorite_count": 0, "id": "11225", "last_activity_date": "2015-06-12T12:27:48.830", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5363", "post_type": "question", "score": 2, "tags": [ "ruby", "アルゴリズム" ], "title": "1からNまでの整数に対し、「約数の数がs個になる」のはいくつあるか調べるには?", "view_count": 939 }
[ { "body": "N が大きすぎると使えませんが、以下の二通りで求めてみました。 \n(ちなみに②の方が速い)\n\n①素数の列を使わない方法\n\n```\n\n N = 10 ** 2\n h = {1 => 1}\n ary = Array.new(N + 1, 1)\n ary[0], ary[1] = 0, 0\n (2..N).each{|i|\n i.step(N, i){|d|\n if d == i\n s = ary[d] + 1\n h.key?(s) ? h[s] += 1 : h[s] = 1\n else\n ary[d] += 1\n end\n }\n }\n p h\n \n```\n\n【コードの説明】 \naryに約数(自身を含まない)の個数をいれていくことにする。 \ni (< n) が n の約数なら、ary[n] を 1 増やす。 \ni が n のときは ary はそのままで、h には結果を反映させることにする。\n\n次のようにすればほんの少し速くなります。\n\n```\n\n N = 10 ** 7\n h = {1 => 1}\n ary = Array.new(N + 1, 1)\n ary[0], ary[1] = 0, 0\n (2..N / 2).each{|i|\n i.step(N, i){|d|\n if d == i\n s = ary[d] + 1\n h.key?(s) ? h[s] += 1 : h[s] = 1\n else\n ary[d] += 1\n end\n }\n }\n (N / 2 + 1..N).each{|i|\n s = ary[i] + 1\n h.key?(s) ? h[s] += 1 : h[s] = 1\n }\n p h\n \n```\n\n②素数の列を使う方法\n\n```\n\n require 'prime'\n \n # dを素因数分解したときのiの次数\n def d(d, i)\n s = 0\n while d % i == 0\n d /= i\n s += 1\n end\n s\n end\n \n # @ary[j]を@hへ反映させる\n def h(j)\n s = @ary[j]\n @h.key?(s) ? @h[s] += 1 : @h[s] = 1\n end\n \n N = 10 ** 7\n @h = {1 => 1}\n @ary = Array.new(N + 1, 1)\n n = 2\n Prime.each(N){|i|\n i.step(N, i){|d|\n @ary[d] *= d(d, i) + 1\n }\n (n..i).each{|j| h(j)}\n n = i + 1\n }\n (n..N).each{|j| h(j)}\n p @h\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T11:19:30.010", "id": "11259", "last_activity_date": "2015-06-12T12:27:48.830", "last_edit_date": "2015-06-12T12:27:48.830", "last_editor_user_id": "5363", "owner_user_id": "5363", "parent_id": "11225", "post_type": "answer", "score": 1 } ]
11225
11259
11259
{ "accepted_answer_id": "11227", "answer_count": 1, "body": "以下に該当する文字列を正規表現でマッチングさせたいのですが、どう書けば良いでしょうか?\n\n 1. 拡張子txtとjpgのファイルパス\n 2. txtとjpgという名前のファイル及びフォルダを含むパス\n\n実行環境は[RegExr](http://www.regexr.com/)です。 \n以下はtxtのみに絞ったテストケースです。\n\n```\n\n 該当する\n txt\n txt/\n /txt\n .txt\n foo.txt\n txt/foo.txt\n /foo.txt\n /txt/foo.txt\n /txt/foo/bar.baz\n /bar/txt/foo.txt\n /txt/txt/foo.bar\n \n \n 該当しない(1つ目の.txt には末尾にスペースあり)\n .txt \n .txtfoo\n .footxt\n .footxtbar\n .foo.txt.bar\n .foo.txt*.bar\n .foo.txt誤\n .foo.txt誤.bar\n .foo.誤txt\n .txt foo\n .foo.txt foo\n foo.誤txt\n txt.foo\n /txt.foo\n 誤txt/foo.bar\n bar/txt.foo\n /bar/txt.foo\n foo/bar/txt.baz\n /foo/bar/txt.baz\n /foo/bartxt/txt.baz\n /foo/bar.txt/txt.baz\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T14:10:43.457", "favorite_count": 0, "id": "11226", "last_activity_date": "2015-06-10T14:32:21.943", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3922", "post_type": "question", "score": 1, "tags": [ "正規表現" ], "title": "正規表現を使ったファイルやフォルダパスのマッチング", "view_count": 6899 }
[ { "body": "`/^(((.*\\/)?txt(\\/.*)?)|(.*\\\\.txt))$/gm`\n\n<http://www.regexr.com/3b66t>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T14:32:21.943", "id": "11227", "last_activity_date": "2015-06-10T14:32:21.943", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3639", "parent_id": "11226", "post_type": "answer", "score": 1 } ]
11226
11227
11227
{ "accepted_answer_id": null, "answer_count": 1, "body": "こんばんわ \n要素をドロップするとカウントが増え、ドロップエリアから外すとカウントが減るという動作を要素別にしたいです。 \nほんとはドロップするとクローンを作り、繰り返しドロップができるようにしたいです \n。以下のようなかんじでやってみましたがうまくできませんので教えていただきたいです \nよろしくお願いします \n<http://codepen.io/anon/pen/jPwrPR>\n\n```\n\n $(function() {\r\n \r\n $(\".dragDiv\").draggable();\r\n \r\n $(\"#div3\").droppable({\r\n accept: \".dragDiv\", // 受け入れる要素を指定\r\n drop: function(event, ui) {\r\n // dragされてきたオブジェクトを取得してクローン作製\r\n var dragId = ui.draggable.attr(\"id\");\r\n if ($(this).find(\".drop\" + dragId).length == 0) {\r\n $(this).append('<span class=\"drop' + dragId + '\">' + ui.draggable.text() + 'が置かれたよ</span>');\r\n }\r\n },\r\n out: function(event, ui) {\r\n var dragId = ui.draggable.attr(\"id\");\r\n $(this).find(\".drop\" + dragId).remove();\r\n }\r\n \r\n });\r\n });\n```\n\n```\n\n div {\r\n width: 150px;\r\n height: 150px;\r\n margin: 10px;\r\n color: #fff;\r\n text-align: center;\r\n }\r\n \r\n span {\r\n display: block;\r\n }\r\n \r\n #div1 {\r\n background: red;\r\n }\r\n \r\n #div2 {\r\n background: blue;\r\n }\r\n \r\n #div3 {\r\n width: 250px;\r\n height: 250px;\r\n background: gray;\r\n }\r\n \r\n \r\n /**\r\n div:nth-child(2n+1){\r\n background:red;\r\n }\r\n \r\n div:nth-child(2n+0){\r\n background:blue;\r\n }*/\n```\n\n```\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js\"></script>\r\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js\"></script>\r\n <div id=\"div1\" class=\"dragDiv\">\r\n グレイに置いてね1\r\n </div>\r\n \r\n <div id=\"div2\" class=\"dragDiv\">\r\n グレイに置いてね2\r\n </div>\r\n \r\n \r\n <div id=\"div3\">\r\n ここにおけるよ\r\n </div>\n```\n\n```\n\n $( \"#div3\" ).droppable({\n accept : \".dragDiv\" , // 受け入れる要素を指定\n drop : function(event , ui){\n // dragされてきたオブジェクトを取得してクローン作製\n var dragId = ui.draggable.attr(\"id\");\n if($(this).find(\".drop\" + dragId).length == 0){\n $(this).append('<span class=\"drop' + dragId +'\">' + 1 + '</span>');\n elseif($(this).find(\".drop\" + dragId).length == 1){\n $(.drop).text(2)\n };\n }deleteImage(ui.draggable);\n } ,\n out : function (event , ui){\n var dragId = ui.draggable.attr(\"id\");\n $(this).find(\".drop\" + dragId).remove();\n } \n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2015-06-10T15:19:04.287", "favorite_count": 0, "id": "11228", "last_activity_date": "2019-12-13T20:11:43.877", "last_edit_date": "2019-12-13T20:11:43.877", "last_editor_user_id": "32986", "owner_user_id": "10090", "post_type": "question", "score": 1, "tags": [ "jquery", "jquery-ui" ], "title": "jqueryで要素別にカウントしたい", "view_count": 417 }
[ { "body": "`out`を使うより、2つエリアを用意してその間を行き来するようにした方が制御が簡単な気がします(それぞれの`drop`で増減する)。\n\n```\n\n $(function() {\r\n \r\n var $gallery = $('#gallery');\r\n var $trash = $('#trash');\r\n var $list = $('ul', $trash);\r\n var $items = $('#items');\r\n \r\n $(\".drag\").draggable({\r\n revert: \"invalid\",\r\n containment: \"document\",\r\n helper: \"clone\",\r\n cursor: \"move\"\r\n });\r\n \r\n $gallery.droppable({\r\n accept: '#trash li',\r\n drop: function(event, ui) {\r\n ui.draggable.remove();\r\n $items.text($(\"li\", $list).length);\r\n }\r\n })\r\n \r\n $trash.droppable({\r\n accept: $('li', $gallery),\r\n drop: function(event, ui) {\r\n var obj = ui.draggable.clone();\r\n obj.draggable({\r\n revert: \"invalid\",\r\n containment: \"document\",\r\n cursor: \"move\"\r\n })\r\n obj.appendTo($list);\r\n $items.text($(\"li\", $list).length);\r\n }\r\n });\r\n });\n```\n\n```\n\n .flex {\r\n display: flex;\r\n flex-wrap: wrap;\r\n }\r\n .elem {\r\n width: 50px;\r\n height: 50px;\r\n margin: 5px;\r\n color: #fff;\r\n text-align: center;\r\n }\r\n .elem.div1 {\r\n background-color: #f00;\r\n }\r\n .elem.div2 {\r\n background-color: #00f;\r\n }\r\n ul {\r\n list-style-type: none;\r\n padding-left: 0;\r\n }\r\n #gallery {\r\n margin-bottom: 10px;\r\n width: 500px;\r\n height: 60px;\r\n background: #0ff;\r\n }\r\n #trash {\r\n width: 500px;\r\n height: 250px;\r\n background: #808080;\r\n }\n```\n\n```\n\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\r\n <script src=\"//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js\"></script>\r\n \r\n <div id=\"gallery\">\r\n <ul class=\"flex\">\r\n <li class=\"drag\">\r\n <div class=\"elem div1\">グレイに置いてね1</div>\r\n </li>\r\n <li class=\"drag\">\r\n <div class=\"elem div2\">グレイに置いてね2</div>\r\n </li>\r\n </ul>\r\n </div>\r\n <div id=\"trash\">\r\n ここに置けるよ:<span id=\"items\">0</span>\r\n <ul class=\"flex\"></ul>\r\n </div>\n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-16T07:51:30.360", "id": "11401", "last_activity_date": "2015-06-16T07:51:30.360", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3516", "parent_id": "11228", "post_type": "answer", "score": 1 } ]
11228
null
11401
{ "accepted_answer_id": null, "answer_count": 2, "body": "takahashiといいます。\n\nmonacaで開発をしています。 \nAndroid4.4以上の端末で以下の現象があります。\n\nアプリ内からCameraプラグインのgetPicture()でギャラリーを起動します。 \n内部ストレージ(左側に縦に並んでいる箇所)から画像を選択し、画像サイズを取得しようとすると \nSecurityExceptionが発生します。\n\n```\n\n E/DatabaseUtils(16641): java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/9C33-6BBD:Download/ダウンロード.jpg from pid=7821, uid=10385 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()\n E/DatabaseUtils(16641): at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:467)\n E/DatabaseUtils(16641): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:394)\n E/DatabaseUtils(16641): at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:387)\n E/DatabaseUtils(16641): at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:339)\n E/DatabaseUtils(16641): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:316)\n E/DatabaseUtils(16641): at android.os.Binder.execTransact(Binder.java:404)\n E/DatabaseUtils(16641): at dalvik.system.NativeStart.run(Native Method)\n \n```\n\n何か対応策があればご教授ください。\n\nちなみにQuickPikや別なギャラリーアプリを使うと上記の現象は発生しません。\n\nよろしくおねがいします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T15:20:47.353", "favorite_count": 0, "id": "11229", "last_activity_date": "2016-03-10T04:54:09.917", "last_edit_date": "2015-06-12T14:23:42.540", "last_editor_user_id": "10092", "owner_user_id": "10092", "post_type": "question", "score": 2, "tags": [ "monaca" ], "title": "Android4.4以上でFileプラグインで画像へアクセスするとSecurityException", "view_count": 808 }
[ { "body": "エラーメッセージに示されているよう[Android\nManifest](http://docs.monaca.mobi/2.9/ja/reference/config/android_configuration/)の`uses-\npermission`に`android.permission.MANAGE_DOCUMENTS`を加えてみてください。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T15:57:34.290", "id": "11231", "last_activity_date": "2015-06-10T15:57:34.290", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2376", "parent_id": "11229", "post_type": "answer", "score": 1 }, { "body": "<http://blog.kotemaru.org/2014/11/23/android-choose-picture.html> \n同じ症状かもしれません。 \n見てみて下さい。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-02-09T04:45:16.997", "id": "21884", "last_activity_date": "2016-02-09T04:45:16.997", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10346", "parent_id": "11229", "post_type": "answer", "score": -1 } ]
11229
null
11231
{ "accepted_answer_id": "11391", "answer_count": 2, "body": "facebook の canvas アプリとして Ruby on Rails & Heroku\nで作ったページを試しに表示してみたいなと思っているのですが、真っ白しか出ません。 \nわざと存在しないページを設定すると404ページが表示されてくれるので、script\nを書かなくても表示できるような気がするのですが、検索しても古そうな情報ばかりでちんぷんかんぷんです。\n\nroutes.rb に\n\n```\n\n post \"canvas_test\" => \"pootalo#canvas_test\"\n \n```\n\nを追加\n\nlayouts/canvas_test.html.erb に\n\n```\n\n <!DOCTYPE html>\n <html>\n <head>\n <title>test</title>\n </head>\n <body>\n <style type=\"text/css\">\n <!--\n body {\n background-color: green;\n }\n --> \n </style>\n canvas test 2\n </body>\n </html>\n \n```\n\nview のほうの canvas_test.html.erb は空\n\nあとコントローラーに\n\n```\n\n def canvas_test\n render :layout => 'canvas_test'\n end\n \n```\n\nを追加\n\nさらに application_controller.rb で\n\n```\n\n protect_from_forgery with: :exception\n \n```\n\nをコメントアウトしています。\n\nちゃんと https でリクエストしています。\n\nこれどうやったら表示できるようになるかご存知の方いますでしょうか? \nもしくは、私が根本的な勘違いをしているのか? \nアドバイスよろしくおねがいします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T15:49:36.637", "favorite_count": 0, "id": "11230", "last_activity_date": "2015-06-16T02:57:06.410", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "705", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "heroku", "facebook-api" ], "title": "Ruby on Rails & Heroku で作った静的ページが facebook canvas で表示できない", "view_count": 225 }
[ { "body": "まずはHerokuにアクセスが飛んでいるのか確認してみましょう。\n\n```\n\n heroku logs --tail\n \n```\n\nもしアクセスできていればログが出ますし、エラーが出ていればそれで解決できるはずです。アクセスが来ていなければFacebookアプリがHerokuにアクセスできていないということになります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T07:57:41.283", "id": "11251", "last_activity_date": "2015-06-11T09:06:56.670", "last_edit_date": "2015-06-11T09:06:56.670", "last_editor_user_id": "208", "owner_user_id": "10102", "parent_id": "11230", "post_type": "answer", "score": 1 }, { "body": "<https://teratail.com/questions/11343> \nteratailで質問したら解決しました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-16T02:57:06.410", "id": "11391", "last_activity_date": "2015-06-16T02:57:06.410", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "705", "parent_id": "11230", "post_type": "answer", "score": 2 } ]
11230
11391
11391
{ "accepted_answer_id": "11233", "answer_count": 1, "body": "お世話になります。\n\ntwitterauthを使いフォロワーのデータを取得しようとしたところ \n一部のフォロワーしか取得できません。 \n最後はscreen_nameもnameも19桁の数字のみが返ってきます。 \n以前は開発したときは動いていたのですが、改めて新しい環境にインストールしたところ \n上記の現象が出ました。 \n仕様変更などあったのでしょうか? \n解決方法などあればご教授ください\n\n開発環境 \nCentOS 6.6 \nphp 5.4.41\n\n## ソースコードの一部\n\n```\n\n $screen_name ='該当のscreen_name';\n $consumer_key ='該当のconsumer_key';\n $consumer_secret ='該当のconsumer_secret';\n $access_token ='該当のaccess_token';\n $access_token_secret ='該当のaccess_token_secret';\n $twid=\"\";\n require_once(\"/*******/twitterauth/twitterauth.php\");\n $to = new TwitterOAuth($consumer_key,$consumer_secret,$access_token,$access_token_secret);\n $req = $to->OAuthRequest(\"https://api.twitter.com/1.1/followers/list.json\",\"GET\",array('cursor' => '-1', 'screen_name' => $screen_name,'count'=>'5000'));\n $followerdata=json_decode($req, true);\n foreach ($followerdata as $key => $value1) {\n foreach ((array) $value1 as $key => $value2) {\n foreach ((array) $value2 as $key => $value3) {\n if($key=='screen_name'){\n $screen_name=$value3;\n echo $screen_name.',,,';\n }\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T15:59:48.377", "favorite_count": 0, "id": "11232", "last_activity_date": "2015-06-10T16:24:21.983", "last_edit_date": "2015-06-10T16:23:39.853", "last_editor_user_id": "2376", "owner_user_id": "8168", "post_type": "question", "score": 1, "tags": [ "php", "twitter" ], "title": "twitterauthを使いフォロワーのデータを取得", "view_count": 265 }
[ { "body": "示されているコードは様々な理由で不自然です。(好ましいTwitterOAuth.phpの使い方とは言えません。)\n\n[TwitterOAuth - PHPからTwitterツイート(2015年2月版) -\nQiita](http://qiita.com/tsunet111/items/9309801cd3e3bcf6e32a#php%E3%82%B3%E3%83%BC%E3%83%89)\n\nで紹介されているコードや[公式ドキュメント](https://twitteroauth.com/)が参考になるかと思うのでコメント欄もあわせてご覧ください。\n\n* * *\n\n> 一部のフォロワーしか取得できません。\n\n`followers/list` で一度に取得できる最大件数は200件です。\n([公式ドキュメント](https://dev.twitter.com/rest/reference/get/followers/list))\n\n* * *\n```\n\n $users = $to->get(\"followers/list\",array('cursor' => '-1', 'screen_name' => $screen_name,'count'=>'200'));\n // $users : object of Array of User object\n foreach ($users->users as $user) {\n echo $user->screen_name.',';\n }\n \n```\n\n(あまりきれいなコードではありませんが…)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T16:24:21.983", "id": "11233", "last_activity_date": "2015-06-10T16:24:21.983", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2376", "parent_id": "11232", "post_type": "answer", "score": 1 } ]
11232
11233
11233
{ "accepted_answer_id": null, "answer_count": 1, "body": "[ng-\nrepeat中に前の要素と比較して表示の出し分けをしたい](https://ja.stackoverflow.com/questions/9968/ng-\nrepeat%E4%B8%AD%E3%81%AB%E5%89%8D%E3%81%AE%E8%A6%81%E7%B4%A0%E3%81%A8%E6%AF%94%E8%BC%83%E3%81%97%E3%81%A6%E8%A1%A8%E7%A4%BA%E3%81%AE%E5%87%BA%E3%81%97%E5%88%86%E3%81%91%E3%82%92%E3%81%97%E3%81%9F%E3%81%84) \nこの質問と似たようなことで、日にちが変わったら(例:6/9から6/10へと日付を跨いだ時)リストに仕切りを入れたいのですが、うまくいかないのでアドバイスをどなたかお願いします。 \n上の回答では、\n\n```\n\n <div ng-repeat=\"item in items\">\n <div>{{items[$index-1].created_at === item.created_at ? '\\u00A0' : item.created_at}}</div>\n <div>{{item.item_id}}</div>\n </div>\n \n```\n\nというように書けばいいと書いてありました。そこで、\n\n```\n\n <ons-row class=\"shikiri\" ng-if=\"results[$index-1].attributes.updateDate|date:\"MM/dd\" !== \n result.attributes.updateDate|date:\"MM/dd\"\">\n \n```\n\nとng-ifで、日付を比較するような条件を上の回答を参考に書いたのですが、`|date:\"MM/dd\"` \nがエラーのようです。 \nnifty mbaasからのオブジェクトなので、.attributes.updateDateとして日付を取得しています。 \n(日付データは2015-06-10T15:15:48.754Zというような形式になっています。)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T17:13:26.247", "favorite_count": 0, "id": "11234", "last_activity_date": "2015-10-09T04:19:40.407", "last_edit_date": "2017-04-13T12:52:39.113", "last_editor_user_id": "-1", "owner_user_id": "8748", "post_type": "question", "score": 2, "tags": [ "monaca", "angularjs" ], "title": "ng-repeat中に前の要素と比較して表示の出し分けをしたい2", "view_count": 358 }
[ { "body": "ng-ifを\"で開始しているので、MM/ddは『”』でなく『'』で囲んでください。 \nこれだけで良さそうですが、なぜか結果をtoStringしないと正しく動きませんでした。\n\n```\n\n var app=angular.module(\"app\",[]);\r\n app.controller('mainController',['$scope', function ($scope) {\r\n var a = new Date(2015,5,9,12,0)\r\n \r\n $scope.items = [\r\n {\r\n \"item_id\": 1,\r\n \"user_id\": 1,\r\n \"created_at\": \"2015-06-10T15:15:48.754Z\"\r\n },\r\n {\r\n \"item_id\": 2,\r\n \"user_id\": 1,\r\n \"created_at\": \"2015-06-10T10:15:48.754Z\"\r\n },\r\n {\r\n \"item_id\": 3,\r\n \"user_id\": 1,\r\n \"created_at\": \"2015-06-09T15:15:48.754Z\"\r\n },\r\n {\r\n \"item_id\": 4,\r\n \"user_id\": 1,\r\n \"created_at\": \"2015-06-09T10:15:48.754Z\"\r\n },\r\n {\r\n \"item_id\": 5,\r\n \"user_id\": 1,\r\n \"created_at\": \"2015-06-09T05:15:48.754Z\"\r\n }\r\n ];\r\n }\r\n ]);\n```\n\n```\n\n <script src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.js\"></script>\r\n <div ng-app=\"app\">\r\n <div ng-controller=\"mainController\">\r\n <div ng-repeat=\"item in items\">\r\n <hr ng-if=\"$index != 0 && (items[$index-1].created_at|date:'MM/dd':'UTC').toString() !== (item.created_at|date:'MM/dd':'UTC').toString()\">\r\n <div>{{item.item_id}}</div>\r\n <div>pre:{{items[$index-1].created_at|date:'MM/dd':'UTC'}}</div>\r\n <div>cur:{{item.created_at|date:'MM/dd':'UTC'}}</div>\r\n </div>\r\n </div>\r\n </div>\n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T22:43:00.210", "id": "11239", "last_activity_date": "2015-06-11T01:28:57.117", "last_edit_date": "2015-06-11T01:28:57.117", "last_editor_user_id": "4191", "owner_user_id": "4191", "parent_id": "11234", "post_type": "answer", "score": 1 } ]
11234
null
11239
{ "accepted_answer_id": null, "answer_count": 2, "body": "こんばんは、現在、Qtでプログラミング中の学生です。 \n今、パソコンのWebカメラで撮影した映像をサーバー側プログラムとクライアント側プログラムで \nやり取りするコードを書いているのですが、まったくうまくいきません。 \nクライアントに送信はできるのですが、クライアント側で映像を再構築するとなぜか映像が切れ切れ(テレビの調子が悪い時のあの感じです。)になります。 \nそこで、UDP送信でカメラ映像をサーバ・クライアント側でやり取りするプログラムのヒントをいただけないでしょうか?\n\n私の方法を簡単に書いておきます。問題点を指摘していただくだけでも構いません。 \n「サーバ側」 \nWebカメラで動画撮影→OpenCVの関数でキャプチャー→QByteArrayに変換→QByteArrayのメンバ関数appendで画像の縦、横情報をつける→UDPのwriteDatagramでクライアントに送信 \n「クライアント側」 \nUDPのreadDatagramで情報取得→QByteArrayのメンバ関数indexOfで画像の縦、横の情報を探して取得(送る前にタグつけてるので、それを探させます)→QByteArrayのdata()関数でデータ型をcharに変更→ネットから拾ってきた関数(1)を使ってcharをQImageのデータ型に→QImageをQPixmapに→QPixmapをラベルに張り付ける\n\n関数(1)\n\n```\n\n QImage* MainWindow::char2QImage(char *cdata)\n {\n int channels = 3;\n QImage *qimg = new QImage(width_data, height_data, QImage::Format_ARGB32);\n char *data = cdata;\n for (int y = 0; y < height_data; y++, data += width_data * channels)\n {\n for (int x = 0; x < width_data; x++)\n {\n char r, g, b, a = 0;\n if (channels == 1)\n {\n r = data[x * channels];\n g = data[x * channels];\n b = data[x * channels];\n }\n else if (channels == 3 || channels == 4)\n {\n b = data[x * channels];\n g = data[x * channels + 1];\n r = data[x * channels + 2];\n }\n if (channels == 4)\n {\n a = data[x * channels + 3];\n qimg->setPixel(x, y, qRgba(r, g, b, a));\n }\n else\n {\n qimg->setPixel(x, y, qRgb(r, g, b));\n }\n }\n }\n return qimg;\n \n \n }\n \n```", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T18:18:47.490", "favorite_count": 0, "id": "11236", "last_activity_date": "2015-08-17T06:59:17.370", "last_edit_date": "2015-06-10T22:06:04.890", "last_editor_user_id": "3639", "owner_user_id": "10093", "post_type": "question", "score": 1, "tags": [ "opencv", "qt" ], "title": "Webカメラで撮影した映像をサーバからクライアントに送りたい", "view_count": 2553 }
[ { "body": "640*480*24bitカラーだと1フレーム7Mbpt超になりますので。目標のフレームレートが書かれていませんが、動画として成立するには最低15fpsぐらいでしょう。それだと100Mbpsを超えることになります。\n\nスループットが十分にないのであればデータ量を減らすしかありません。どうやって減らすかは回線速度との見合いです。100Mbpsはでないけど10Mbpsなら、というぐらいなら1フレームごとにJPEG圧縮でもいけるかもしれません。もっと細い回線では動画としてエンコードする必要があります。\n\nスループットが十分にあるはずなのに問題が起きるのであれば、送信側の送出間隔が短すぎて送信側のバッファがあふれているか受信側の処理が追いつかずにやはりバッファがあふれているということもあります。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T03:05:28.437", "id": "11272", "last_activity_date": "2015-06-12T03:05:28.437", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "11236", "post_type": "answer", "score": 0 }, { "body": "「サーバ側送信用の関数」 \n//カメラ映像を送信する処理を表す関数 \nvoid MainWindow::sendDatagram() \n{ \nint i; \n//画像データ→QByteArray \nba = new QByteArray(img->imageData, img->imageSize); \nqDebug() << \"w =\" << img->width; \nqDebug() << \"h =\" << img->height; \nqDebug() << \"ws =\" << img->widthStep;\n\n```\n\n //プロトコルの決定 画像データ(可変長)<W>画像横方向</W><H>画像縦方向</H>\n //QByteArrayにwidthを追加\n ba->append(\"<WSTART>\");\n sqwidth.setNum(img->width);\n ba->append(sqwidth);\n ba->append(\"</WEND>\");\n \n //QByteArrayにheightを追加\n ba->append(\"<HSTART>\");\n sqheight.setNum(img->height);\n ba->append(sqheight);\n ba->append(\"</HEND>\");\n \n //動画データの圧縮\n QByteArray comp = qCompress(*ba, 5);\n \n //動画データを送信\n for(i=0;i<comp.size();i=i+100){\n if(i<comp.size())\n //100こずつデータを送信\n udpserver.writeDatagram(comp.mid(i, 100), QHostAddress::LocalHost, 10000);\n else if(i>=comp.size()){\n i=i-100;\n //1つずつデータを送信\n for(;i==comp.size();i++)\n udpserver.writeDatagram(comp.mid(i, 1), QHostAddress::LocalHost, 10000);\n }\n \n```\n\n}\n\n```\n\n //送信完了した旨の表示\n ui->label_2->setText(\"transfer finished\");\n \n //QByteArrayの破棄\n delete ba;\n \n```\n\n}", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-18T05:55:25.107", "id": "11465", "last_activity_date": "2015-06-18T05:55:25.107", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10093", "parent_id": "11236", "post_type": "answer", "score": 1 } ]
11236
null
11465
{ "accepted_answer_id": null, "answer_count": 1, "body": "XCTestを使用しています。\n\n例えば、以下のfunc aaaのmarker をテストしたいとします。 \nすると、tableView.reloadで落ちてしまいます。 \nちなみにtableView.reloadはテストの結果に影響しません。\n\nそこで、tableView.reloadをこのテストの時だけコメントアウト \nしておくと、問題なくテストは実行できます。\n\nしかし、他のテストの時は、tableView.reloadは必要です。\n\nつまり、func aaaをテストしたいときは、 \ntableView.reloadをコメントアウトし、 \n他のテストをしたいときは、func aaaをコメントアウトしておかなければ \nなりません。\n\nTableViewのところで落ちるので、TableViewの初期化を行う \nViewDidLoad( )を テストのsetUpで読んでみても、 \nTableView.delegateのところで落ちてしまいます。\n\nこのような場合、どのような方法が有りますでしょうか?\n\n```\n\n var marker = 0\n func aaa ( ) {\n marker = 1\n \n tableView.reload\n }\n \n === test ====\n func testAAA () {\n aaa\n XCTAssertEqual ( marker, 1, \"\")\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T19:16:05.187", "favorite_count": 0, "id": "11237", "last_activity_date": "2015-08-10T05:19:03.893", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4646", "post_type": "question", "score": 1, "tags": [ "swift", "テスト" ], "title": "swiftでXCTest実行時だけ処理されないコードを作りたい", "view_count": 252 }
[ { "body": "コンパイルフラグを用いることで可能です。 \n<http://qiita.com/qmihara/items/a6b88b74fe64e1e05ca4>\n\n今回の場合に限って言えば、tabelViewの値がnilが入っているため落ちているのではないかと思われます。インスタンスを代入することで解決するかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T02:35:29.900", "id": "11245", "last_activity_date": "2015-06-11T02:35:29.900", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9558", "parent_id": "11237", "post_type": "answer", "score": 1 } ]
11237
null
11245
{ "accepted_answer_id": null, "answer_count": 0, "body": "androidアプリ開発をしています。初心者です、よろしくお願いします。\n\n自作のハード上の **LEDをBLE経由でandroid(Nexus5)から制御したい** のですが、 \n一度接続が切れると、再接続ができません。なぜなのでしょうか、、\n\n公式サンプルの「BluetoothLeGatt」を使用しています。 \nstatus:disconnectの状態でconnectを押した後のlogcatは以下の通りです:\n\nD/BluetoothLeService﹕ Trying to use an existing mBluetoothGatt for connection. \nclientConnect() - address=[device address(大文字)], isDirect=false \nbtif_get_address_type: Device [device address(小文字)] address type 0 \nbtif_get_device_type: Device [device address(小文字)] type 2 \ndevice already in iniator white list\n\nもし、情報が足りない部分がありましたら、加筆致します。 \nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-10T19:44:04.463", "favorite_count": 0, "id": "11238", "last_activity_date": "2015-06-10T22:08:11.447", "last_edit_date": "2015-06-10T22:08:11.447", "last_editor_user_id": "3639", "owner_user_id": "10094", "post_type": "question", "score": 1, "tags": [ "android", "bluetooth" ], "title": "BLE経由でandroidからLEDを制御したいが、再接続の方法が分かりません", "view_count": 614 }
[]
11238
null
null
{ "accepted_answer_id": "11249", "answer_count": 1, "body": "Eclipse上で作成したサーブレットを実際の別のマシンのTOMCATで動作させるための設定がわかりません\n\n開発環境は \nWindows7/64 \nEclipse4.4(32ビット) \nEclipseに内蔵されたTomcat8(32ビット) \nJRE1.8(32ビット) \nで、 \n動作環境は \nWindows2008R2 \nTomcat8(32ビット) \nJRE1.8(32ビット) \nです \nJRE等が32ビットなのはJNAから32ビットで作成されたDLLをコールするためです\n\nEclipse上では \nパッケージ名 TPack \nサーブレット名 TServ \nとして作成しました\n\nTomcatでは \nC:\\Program Files (x86)\\Apache Software Foundation\\Tomcat 8.0\\webapps \n配下に \nwebtestフォルダを作成し \nwebtest \n→WEB-INF \n-→classes \neclipseのプロジェクトのbuildフォルダ配下のclassファイルを全てコピー \n-→lib \njna.jar \nwin32-x86.jar \nというフォルダ構成にし、 \nWEB-INFフォルダ直下の \nweb.xmlファイルに\n\n```\n\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <web-app xmlns=\"http://xmlns.jcp.org/xml/ns/javaee\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://xmlns.jcp.org/xml/ns/javaee\n http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd\"\n version=\"3.1\"\n metadata-complete=\"true\">\n \n <servlet-mapping>\n <servlet-name>TServ</servlet-name>\n <url-pattern>/webtest/*</url-pattern>\n </servlet-mapping>\n </web-app>\n \n```\n\nとしてみたのですが、 \nThe requested resource is not available. \nとしかサーバが返してきません \nサーブレットの名前やurlを大文字小文字を組み合わせを変えてみたりしたのですが、やはり変わりませんでした\n\n正しいweb.xml等の記述方法を教えてください \nまた、現在はアプリのwebappsフォルダに配置しているのですが \n出来れば、別のフォルダにアプリを構築したいので、その記述方法も教えていただきたいです", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T03:31:36.177", "favorite_count": 0, "id": "11247", "last_activity_date": "2015-06-11T04:11:34.610", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10098", "post_type": "question", "score": 1, "tags": [ "java", "tomcat" ], "title": "Eclipse上で作成したサーブレットをTomcat上で実行", "view_count": 1829 }
[ { "body": "EclipseのTomcatでは、アプリケーション実行に問題ないことが前提ですが、\n\nプロジェクトエクスプローラーにて、対象のプロジェクトの上で右クリックをし、\n\nエクスポート > WARエクスポート\n\nでwar形式でエクスポートします。\n\nそれを動作させたいTomcatのwebappsにコピーしてから、Tomcatを起動してください。 \n自動的にwarファイルが展開され、アプリケーションとして搭載(デプロイ)されますのでお試しください。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T04:11:34.610", "id": "11249", "last_activity_date": "2015-06-11T04:11:34.610", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5778", "parent_id": "11247", "post_type": "answer", "score": 1 } ]
11247
11249
11249
{ "accepted_answer_id": null, "answer_count": 2, "body": "こんにちは。JavaScriptを使って、Beacon検知したらPush通知を送信したいのですが \nBeacon検知してもNCMBへPush通知が送信できません。以下ソース(一部抜粋)です。 \n何かいいサンプルがありますでしょうか? \n(本当はNearになったらPush通知を送信したいです) \nよろしくお願いいたします。\n\n```\n\n delegate.didRangeBeaconsInRegion = function (pluginResult) {\n var reg = pluginResult.region;\n var beac = pluginResult.beacons;\n for (i = 0; i < beac.length; i = i +1) {\n if (beac[i] != null) {\n console.log(beac[i].proximity);\n NCMB.Push.send(\n {\n \"deliveryTime\": {\"__type\": \"Date\", \"iso\": \"2013-09-31T17:41:09.106Z\"},\n \"immediateDeliveryFlag\": true,\n \"target\": ['ios'],\n \"message\": \"Hello! World!!\",\n \"dialog\": true,\n \"richUrl\": \"http://www.nifty.com\"\n }, \n {\n success: function() {\n console.log('success');\n // 成功\n },\n error: function(error) {\n // エラー\n console.log('Failed');\n }\n });\n }\n }\n };\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T04:05:02.480", "favorite_count": 0, "id": "11248", "last_activity_date": "2015-08-14T11:12:35.473", "last_edit_date": "2015-06-11T04:45:31.917", "last_editor_user_id": "5793", "owner_user_id": "10096", "post_type": "question", "score": 0, "tags": [ "monaca", "push-notification", "ibeacon" ], "title": "iBeaconを使用して、NCMBのpush通知をしたい", "view_count": 448 }
[ { "body": "私も、ibeaconを最近始めたのですが、テストする度にビルドしなきゃいけないのが面倒ですよね。。。 \n丁度、私もNear圏内になったらNCMBのデータストアにレコードを追加するような方法を考えていました。 \n<https://github.com/divineprog/evo-\ndemos/blob/master/Demos2014/iBeaconDemo/app.js> \nこのページの119行目とか参考になりませんか? \n進展があったら是非どんなコードにしたか教えてください。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T10:37:32.007", "id": "11257", "last_activity_date": "2015-06-11T10:37:32.007", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8748", "parent_id": "11248", "post_type": "answer", "score": 1 }, { "body": "解決できました。 \n原因) \njsフォルダの中のncmb-latest.min.js ファイルがなかったことです。Cordovaプラグインの追加でNifty MB\nを追加すると生成されるファイルのようです。 \n以下サンプルソースです。(一部抜粋)\n\n```\n\n delegate.didRangeBeaconsInRegion = function (pluginResult) {\n var reg = pluginResult.region;\n var beac = pluginResult.beacons;\n for (i = 0; i < beac.length; i = i +1) {\n if (beac[i] != null) {\n console.log(beac[i].proximity);\n NCMB.initialize(\"APIキー, \"クライアントキー\");\n NCMB.Push.send(\n {\n \"immediateDeliveryFlag\": true,\n \"target\": ['ios'],\n \"message\": \"Hello! Tony!!\",\n \"richUrl\": \"http://www.nifty.com\",\n }, \n {\n success: function() {\n console.log('success');\n // 成功\n },\n error: function(error) {\n // エラー\n console.log('Failed');\n }\n });\n }\n }\n };\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T06:15:10.073", "id": "11280", "last_activity_date": "2015-06-12T06:28:26.110", "last_edit_date": "2015-06-12T06:28:26.110", "last_editor_user_id": "5519", "owner_user_id": "10112", "parent_id": "11248", "post_type": "answer", "score": 1 } ]
11248
null
11257
{ "accepted_answer_id": "11265", "answer_count": 1, "body": "$resourceを利用して、JSONに記述した設定値を取得するとき、 \n非同期であるため、$resourceの戻り値が解決されません。 \n$resourceの$primiseにはresolveも無いので、どのように解決しますか?\n\n```\n\n myApp.factory('prop', function($resource) {\n return {\n getSetting: function(key) {\n var res = $resource('setting.json').query();\n return res.key;\n }\n }\n });\n \n```\n\n* * *\n\n非同期を同期にするのは難しそうなので、下記のようにしてkeyに対する値を非同期で返すことにしようと思います。\n\n```\n\n myApp.factory('prop', function($resource) {\n return {\n getSetting: function(key) {\n return $resource('setting.json').query().$promise.then(function(res) {\n return res[key];\n }\n }\n }\n });\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T08:06:12.813", "favorite_count": 0, "id": "11253", "last_activity_date": "2015-06-12T06:24:31.187", "last_edit_date": "2015-06-12T06:24:31.187", "last_editor_user_id": "9790", "owner_user_id": "9790", "post_type": "question", "score": 1, "tags": [ "angularjs" ], "title": "AnularJS $resource の取得値のresolveについて", "view_count": 646 }
[ { "body": "非同期で取得するのなら、上記のソースで言うと、query関数のコールバックまたはres.$promise.thenでJSONが取得されていることが確定するので、その中で処理するのはいかがでしょうか。\n\n同期的に処理するのは少し難しいと思います。 \n[AngularJSのngResourceで同期処理](https://ja.stackoverflow.com/questions/8405/angularjs%E3%81%AEngresource%E3%81%A7%E5%90%8C%E6%9C%9F%E5%87%A6%E7%90%86) \nこちらで質問させて頂いて一応同期的に処理するのは可能でしたが、少し仕掛けが必要でした。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T01:29:18.087", "id": "11265", "last_activity_date": "2015-06-12T01:29:18.087", "last_edit_date": "2017-04-13T12:52:39.113", "last_editor_user_id": "-1", "owner_user_id": "2232", "parent_id": "11253", "post_type": "answer", "score": 1 } ]
11253
11265
11265
{ "accepted_answer_id": null, "answer_count": 2, "body": "先日提出したiPhoneアプリがリジェクトされました。 \n要因の一つが2.10のiPadへも対応しなければならないということを知らなかったことです。 \nそこで困っていることが二つあります。\n\n一応iPadでも動けばいいとのことなのでDeploymentInfoのDevicesをユニバーサルにしてiOSシュミレータで実行したところ、画面内で全画面に対応しているところと、大きさがiPadに対応しておらず左上に固まったようになっているところとでバラバラになってしまいました。一応動作は問題ないのですが、これで提出しても問題ないでしょうか。\n\nまた A 76x76 app icon is required for iPad apps targeting iOS 7.0 and later \nというエラーが出ているのですが、76×76のアイコンを置いても消えません。 \nこれはどこにアイコンを設定すればよいのいでしょうか。\n\n初めての審査でよくわからないことが多く困っています。 \nどなたか、わかる方がいましたらよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T08:35:39.683", "favorite_count": 0, "id": "11255", "last_activity_date": "2015-06-11T10:46:25.440", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8802", "post_type": "question", "score": 1, "tags": [ "ios", "xcode", "iphone" ], "title": "iphoneアプリのiPadへの対応 リジェクト2.10", "view_count": 3384 }
[ { "body": "Appleからのメッセージの中に2.10とは別に、具体的な対処方法や問題箇所(iPadだとある画面でクラッシュするなど)は含まれていませんでしたか?\n\nユニバーサル対応をしろという事ではなく、iPad上でiPhoneアプリとして問題なく動作すれば良いはずです。 \nシミュレーターでも良いので一度iPadで実行して動作テストしてみてください。 \n(たしかiPad上では320x480ポイントで動作したと記憶していますので、 \nその画面サイズで動作することが最低限求められます。)", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T08:59:33.847", "id": "11256", "last_activity_date": "2015-06-11T08:59:33.847", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5605", "parent_id": "11255", "post_type": "answer", "score": 5 }, { "body": "ユニバーサルとiphone appとは、違いますよ。\n\niphone appとは、iPad の上では、iPhone emulatorの上で動くもの。\n\nユニバーサルは、iPhoneとiPadの両対応のもので、iPadの上では、ネーティブな画面サイズでレイアウト崩れなどは、おきては、ダメです。\n\niPadで、App Storeにいくと、iPhoneとiPadで、Appの種類を選べれますが、iPadと選んだ場合は、iPhone\nAppは、フィルターされて、選択対象になりません。iPhone Appと選べば、ダウンロード出来ますが。\n\n今回は、ユニバーサル対応できてないようなので、deployment deviceは、iPhoneにしたほうがいいのでは。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T10:46:25.440", "id": "11258", "last_activity_date": "2015-06-11T10:46:25.440", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "75", "parent_id": "11255", "post_type": "answer", "score": 0 } ]
11255
null
11256
{ "accepted_answer_id": null, "answer_count": 1, "body": "monacaデバッガーにあるような、丸いボタン(タップするとにゅっと複数のボタンが出る)は自作アプリでも利用可能でしょうか。これを実装するのに参考になるようなサイト等ありませんでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T15:33:38.140", "favorite_count": 0, "id": "11261", "last_activity_date": "2015-07-11T17:33:57.993", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8748", "post_type": "question", "score": 0, "tags": [ "monaca", "onsen-ui" ], "title": "monacaデバッガーのようなボタンは", "view_count": 393 }
[ { "body": "[このへん](http://codepen.io/nobitagit/full/ZYWVKw/)とか参考になりそうな気がします。 \n↑がぶっちぎりの一番人気でしたが、他にも[いろいろ](http://codepen.io/search?q=floating%20action&limit=all&order=popularity&depth=everything&show_forks=false)ありました。\n\nあとはGoogleのガイドラインとかですかね。 \n[Buttons: Floating Action Button\n](http://www.google.com/design/spec/components/buttons-floating-action-\nbutton.html#)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T17:05:03.790", "id": "11262", "last_activity_date": "2015-06-11T17:05:03.790", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3516", "parent_id": "11261", "post_type": "answer", "score": 1 } ]
11261
null
11262
{ "accepted_answer_id": "11273", "answer_count": 1, "body": "お問い合わせを受け付けた時にお問い合わせをした人とシステム運営者の両方に自動で受領メールを送付したいです。どのようにしたら送信できるでしょうか?\n\nお問い合わせした人に送るメール文言とシステム運営者に送る文言は異なります。\n\n**ユーザに送信**\n\n```\n\n class InquiryMailer < ActionMailer::Base\n default from: \"[email protected]\"\n \n \n def received_email(inquiry)\n @inquiry = inquiry\n mail to: \"[email protected]\", subject: \"webサイトからお問い合わせがありました。\"\n end\n \n \n def thanks_email(inquiry)\n @inquiry = inquiry\n mail to: inquiry.email, subject: \"【maimai】お問い合わせを受け付けました\"\n end\n end\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-11T23:40:36.877", "favorite_count": 0, "id": "11263", "last_activity_date": "2015-06-12T06:03:50.110", "last_edit_date": "2015-06-12T06:03:50.110", "last_editor_user_id": "208", "owner_user_id": "9453", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails" ], "title": "Rails Action Mailerで送信した人と管理者の両方にメールを送る方法", "view_count": 878 }
[ { "body": "received_email メソッドはお問い合わせした人(ユーザ)宛てですよね? \nそのメソッドとは別に「システム運営者宛に送信するメソッド」を作成します。\n\n後はメール送信のタイミングで上記2つのメソッドをコールすれば良いと思います。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T03:18:26.760", "id": "11273", "last_activity_date": "2015-06-12T03:18:26.760", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7208", "parent_id": "11263", "post_type": "answer", "score": 0 } ]
11263
11273
11273
{ "accepted_answer_id": "11293", "answer_count": 1, "body": "以下のような、ユーザがログインしているかどうかを判別するメソッドがあるとします。\n\n```\n\n class Api::SessionsController < Api::ApplicationController\n # GET /api/sessions/verify\n def verify\n if user_signed_in?\n head :ok\n else\n head :unauthorized\n end\n end\n end\n \n```\n\njQueryからこれを叩くとすると、以下のようになると思っています。\n\n```\n\n class @Session\n @verify: ->\n $.ajax\n type: 'GET'\n url: '/api/sessions/verify'\n .done ->\n true\n .fail ->\n false\n \n # 認証済みかどうか判断する\n \n Session.verify()\n .done ->\n # ok\n .fail ->\n # unauthorized\n \n```\n\n以上で、認証済みかどうかは処理できたのですが、ブラウザのコンソールに以下のようなエラーメッセージが表示されます。\n\n```\n\n GET http://localhost:3000/api/sessions/verify 401 (Unauthorized)\n \n```\n\nこれが表示される理由は分かるのですが、こういったエラーメッセージは、開発者が意図しない場合にのみ表示されるべきだと理解しており、意図しているケースのため表示したくありません。 \n一般的に、APIサーバが返す `> 400` なコードをjQuery側から処理する場合、どのように実装すればよいのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T02:19:45.393", "favorite_count": 0, "id": "11267", "last_activity_date": "2015-06-12T13:28:36.223", "last_edit_date": "2015-06-12T13:02:45.200", "last_editor_user_id": "8000", "owner_user_id": "8786", "post_type": "question", "score": 2, "tags": [ "javascript", "ruby-on-rails", "jquery", "google-chrome" ], "title": "Ajaxで401が返ってきても、コンソールにエラーが出力されないようにしたい", "view_count": 4813 }
[ { "body": "Google Chrome での次のような挙動について仰っているのだと思いますが・・・\n\n![screenshot](https://i.stack.imgur.com/Qtg1o.png)\n\nこれはブラウザから投げられる全てのリクエスト(`<img>` タグ等も含む)について Chrome 内部でやっていることで、現状これを Javascript\n側から制御することはできません。過去にバグ報告もあったようですが、結局は **開発者ツールの設定で** そのようなエラーを隠す機能が実装されただけでした。\n\n<https://code.google.com/p/chromium/issues/detail?id=124534>\n\nもしどうしてもこのようなエラーを表示したくないのであれば、ステータスコードは 200 のまま、レスポンスボディで API\nの返答を表すことになるかと思います。\n\n余談ですが、 401 はそのリソース(この場合\n`/api/sessions/verify`)にアクセスするために認証が必要、という印象があるので、いずれにせよ 401 を返すことには違和感があります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T13:28:36.223", "id": "11293", "last_activity_date": "2015-06-12T13:28:36.223", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "parent_id": "11267", "post_type": "answer", "score": 5 } ]
11267
11293
11293
{ "accepted_answer_id": null, "answer_count": 2, "body": "アプリケーション固有の設定情報はどのように定義するべきでしょうか。\n\n/config配下にmy_config.ymlを作成し、/config/initializers配下にmy_config.rbを作成したところエラーがでました。それぞれのファイルの内容は以下です。\n\nmy_config.yml:\n\n```\n\n COMMON: &COMMON\n author: \"user name\"\n logo:\n source: \"http://www.wings.msn.to/image/wings.jpg\"\n width:215\n height:67\n \n development:\n hoge: \"dev\"\n <<: *COMMON\n \n test:\n hoge: \"test\"\n <<: *COMMON\n \n production:\n hoge: \"pro\"\n <<: *COMMON\n \n```\n\nmy_config.rb:\n\n```\n\n MY_APP = YAML.load(File.read(\"/Users/*****/rails_projects/third_app/config/my_config.yml\"))[Rails.env]\n # *****はユーザー名\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T02:29:27.670", "favorite_count": 0, "id": "11269", "last_activity_date": "2016-04-11T11:31:52.420", "last_edit_date": "2015-10-14T07:07:33.927", "last_editor_user_id": "2599", "owner_user_id": "10111", "post_type": "question", "score": 2, "tags": [ "ruby-on-rails", "ruby" ], "title": "Ruby on Railsでの、アプリケーション固有の設定の定義の仕方を教えてください", "view_count": 287 }
[ { "body": "[RailsConfig ](https://github.com/railsconfig/rails_config)\nを利用すると、YAMLファイルから設定情報を読み込んで利用することが出来ます。設定は、RAILS_ENVごと (development,\nproduction, test, ...) に設定を分けて記載することもできます。\n\n同じようなgemで [Settingslogic](https://github.com/settingslogic/settingslogic)\nがありますが、1年ほど更新されていないので避けた方が良いかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T02:52:28.730", "id": "11270", "last_activity_date": "2015-06-12T02:52:28.730", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "76", "parent_id": "11269", "post_type": "answer", "score": 0 }, { "body": "質問内容のプログラムでも問題なく動くはずですが、どのようなエラーが発生していますか? \n環境に依存する値を管理するようなものとして、[Figaro](https://github.com/laserlemon/figaro)や[dotenv](https://github.com/bkeepers/dotenv)といったGemもあります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-16T03:43:43.423", "id": "11393", "last_activity_date": "2015-06-16T03:43:43.423", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9985", "parent_id": "11269", "post_type": "answer", "score": 1 } ]
11269
null
11393
{ "accepted_answer_id": "11363", "answer_count": 3, "body": "Laravel 5.0 で標準付属の Auth による User 認証を使っています。 \nその場合 Auth::user()->name などで現在ログイン中のユーザーのプロパティが得られますが、 \n今回 role というプロパティをもたせ、Auth::user()->role で取得できるようにしたいと考えています。\n\nusers テーブルには新しいカラム「role_id」を作り、用意した roles テーブルの id とひもづける予定です。 \nSQL文は次のようなものです。\n\n```\n\n SELECT users.*, roles.name AS role FROM `users` INNER JOIN `roles` ON users.role_id = roles.id\n \n```\n\n辿って行くと、「vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php」の\nretrieveById() で処理が行われているようなので次のように書き換えて動作することを確認しました。\n\n```\n\n public function retrieveById($identifier)\n {\n return $this->createModel()->newQuery()\n ->select(['users.*', 'roles.name as role'])\n ->join('roles', 'users.role_id', '=', 'roles.id')\n ->find($identifier);\n \n // return $this->createModel()->newQuery()->find($identifier);\n }\n \n```\n\n一応はこれでも目的の動作をしてはいますが、本来は何らかの拡張クラスを作って extend するべきなのでしょうか? \nもしそうであればどのフォルダにどのような形で追加したら良いのでしょうか。 \nフレームワークの使い方自体まだ不慣れで良く理解できていません。よろしくお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T02:58:32.470", "favorite_count": 0, "id": "11271", "last_activity_date": "2015-06-15T09:24:16.407", "last_edit_date": "2015-06-15T06:50:32.277", "last_editor_user_id": "10083", "owner_user_id": "10083", "post_type": "question", "score": 1, "tags": [ "php", "laravel" ], "title": "Laravel 5 の「Auth::user()」のプロパティにJOINしたデータを追加したい", "view_count": 6934 }
[ { "body": "laravelの標準ORMである、Eloquentで実装するのが一般的かと思います。 \nRoleモデルを作成し、belongsToMany()メソッドを使って、Userモデルと多対多のリレーションで紐付けます。テーブルは\nrolesテーブルと、role_userテーブルを作成します。 \n詳細な手順は下記の参考サイトをご覧ください。\n\n参考サイト\n\n * [初めてのLARAVEL 5 : (33) 多対多のリレーション モデル/DB編](https://laravel10.wordpress.com/2015/03/30/%E5%88%9D%E3%82%81%E3%81%A6%E3%81%AElaravel-5-33-%E5%A4%9A%E5%AF%BE%E5%A4%9A%E3%81%AE%E3%83%AA%E3%83%AC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3-%E3%83%A2%E3%83%87%E3%83%ABdb%E7%B7%A8/)\n * [Eloquent: Relationships](http://laravel.com/docs/5.1/eloquent-relationships#many-to-many)", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T17:56:15.057", "id": "11334", "last_activity_date": "2015-06-14T17:56:15.057", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9529", "parent_id": "11271", "post_type": "answer", "score": 2 }, { "body": "laravelアプリで、userに roleや\nPermissionを付与したいということであれば、[zizaco/entrust](https://github.com/Zizaco/entrust)\nパッケージを使うもの良いかと思います。\n\n<https://github.com/Zizaco/entrust>", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T18:04:05.597", "id": "11335", "last_activity_date": "2015-06-14T18:04:05.597", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9529", "parent_id": "11271", "post_type": "answer", "score": 2 }, { "body": "vendor配下はcomposerライブラリのディレクトリになりますので、 \n直接ソースコードを編集するのはお勧めしません。 \nupdateの度に書き換えられますし、 \nupdateをしないとなりますとバグフィックスなども受けられません。\n\n質問にあるような認証情報を取得できるようにするには、方法はいくつかありますが、 \nフレームワークを学ぶ上でも一番のベストプラクティスは認証ドライバーの追加、または拡張です。\n\nその際にどのフォルダに置くか、ですがLaravel5以上であればデフォルトのオートローダがpsr-4に対応していますので、 \nディレクトリやファイルの場所は特に関係ありません。 \nここでは **app/Autheinticate** 配下に作成する例として紹介します。\n\n`Illuminate/Auth/EloquentUserProvider.php`がデフォルトでEloquentを利用する認証クラスになっていますので、 \n該当のretrieveByIdメソッドをオーバライドするために、 \n`app/Autheinticate/AuthUserProvider.php`としてファイルを作成します。 \n\n```\n\n <?php\n namespace App\\Authenticate;\n \n use Illuminate\\Auth\\EloquentUserProvider;\n \n class AuthUserProvider extends EloquentUserProvider\n {\n \n /**\n * Retrieve a user by their unique identifier.\n * @param mixed $identifier\n * @return \\Illuminate\\Contracts\\Auth\\Authenticatable|null\n */\n public function retrieveById($identifier)\n {\n return $this->createModel()->newQuery()\n ->join('roles', 'users.role_id', '=', 'roles.id')\n ->find($identifier, ['users.*', 'roles.name as role']);\n }\n \n }\n \n```\n\n次に認証ドライバーとして追加します。(ここではwith_roleという名前にします) \nドライバー追加はサービスプロバイダーを利用しますので、 \napp/Providers配下にサービスプロバイダーを作成します。 \n\n```\n\n <?php\n namespace App\\Providers;\n \n use App\\Authenticate\\AuthUserProvider;\n use Illuminate\\Support\\ServiceProvider;\n \n class AuthServiceProvider extends ServiceProvider\n {\n \n /**\n * Register the service provider.\n *\n * @return void\n */\n public function register()\n {\n $this->app['auth']->extend('with_role', function () {\n $model = $this->app['config']['auth.model'];\n return new AuthUserProvider($this->app['hash'], $model);\n });\n }\n }\n \n```\n\nサービスプロバイダーからサービスコンテナへは`$this->app`でアクセスできます。 \n認証クラスはサービスコンテナにauthという名前で登録されていますので、 \n認証クラスへアクセスしてextendメソッドを利用します。 \nこのメソッドはドライバを追加する場合に利用します。 \n(認証、キャッシュ、セッション、データベース、ファイルストレージなどで利用するメソッドです) \n認証に利用するEloquentを継承したクラスをconfig/auth.phpのmodelから取得して、 \n作成したAuthUserProviderクラスのコンストラクタに渡す引数を記述します。 \n(Illuminate\\Auth\\EloquentUserProviderを継承しているため) \n作成したApp\\Providers\\AuthServiceProviderクラスをconfig/app.phpのproviders配列へ追記し、 \n最後にconfig/auth.phpのdriverにwith_roleを記述します。\n\n```\n\n 'driver' => 'with_role',\n \n```\n\nあとはいつも通り`\\Auth::user()`で取得できます。 \nドライバーを追加するメリットとしては、同じように追加したドライバや既存のドライバを\n\n```\n\n Auth::driver('eloquent')->user();\n Auth::driver('with_role')->user();\n \n```\n\nなどdriverメソッドを利用してそれぞれの用途に合わせた場面で認証情報を変更したり、 \nログインなども分けることができます。\n\n最新の5.1のマニュアルにはありませんでしたが、下記にも記載されていますので参考にしてみてください。 \n5.1でも拡張方法は同様です。 \n[Laravel 5.0 公式 | Extending The\nFramework](http://laravel.com/docs/5.0/extending) \n[Laravel 5.0 日本語訳 |\nフレームワークの拡張](http://readouble.com/laravel/5/0/dev/ja/extending.html)", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T05:40:40.713", "id": "11363", "last_activity_date": "2015-06-15T09:24:16.407", "last_edit_date": "2015-06-15T09:24:16.407", "last_editor_user_id": "609", "owner_user_id": "609", "parent_id": "11271", "post_type": "answer", "score": 1 } ]
11271
11363
11334
{ "accepted_answer_id": "11276", "answer_count": 3, "body": "```\n\n maven {\n url \"https://my.custom.repository/path\"\n }\n \n ...\n \n dependencies {\n ...\n compile 'my.custom.library:library-name:x.x.x@aar'\n }\n \n```\n\nのように、自分で作成したAndroidライブラリをGradleで`dependencies`の`compile`に指定するだけで読み込めるようにしたいのですが、どのようにすれば良いのでしょう? \nMavenの公開リポジトリには登録する必要はなく、リポジトリのURLを知っている人だけが使えればよいです。\n\nもしくは、手順を説明しているWebサイトがあれば教えてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T03:26:32.207", "favorite_count": 0, "id": "11274", "last_activity_date": "2015-06-15T00:32:58.490", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "450", "post_type": "question", "score": 1, "tags": [ "android", "android-studio" ], "title": "Androidで自作ライブラリをGradleで利用できるようにしたい", "view_count": 1829 }
[ { "body": "[mavenのインハウスリポジトリを作るよ -\nQiita](http://qiita.com/NewGyu/items/71b50d036eef64be9b96)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T03:58:53.350", "id": "11275", "last_activity_date": "2015-06-12T03:58:53.350", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2376", "parent_id": "11274", "post_type": "answer", "score": 0 }, { "body": "ライブラリプロジェクト側で、次の記述を追加します。\n\n```\n\n apply plugin: 'maven'\n \n uploadArchives {\n repositories.mavenDeployer {\n // mavenローカルにいれる設定\n repository url: \"file://$System.env.HOME/.m2/repository\"\n pom.version = '1.0.0'\n pom.groupId = 'com.mokelab'\n pom.artifactId = 'InputDialog-v4'\n }\n }\n \n // 通常のライブラリプロジェクトを作る設定が続きます\n \n```\n\nライブラリプロジェクトのビルドで、次のタスクを実行します。\n\n```\n\n $ sh gradlew clean uploadArchives\n \n```\n\nこれで、~/.m2/repositoryにライブラリがインストールされます。この`~/.m2/repository`に生成されたファイルツリーをどこかhttpで見れるところに置くと、質問の通りの指定ができるようになります。\n\n```\n\n maven {\n url \"https://my.custom.repository\"\n }\n \n```\n\nで、上記の例のライブラリを参照可能にするには、次のようなURLでアクセスできるようになっていればOKです。\n\n```\n\n https://my.custom.repository/com/mokelab/InputDialog-v4/1.0.0/InputDialog-v4-1.0.0.aar\n https://my.custom.repository/com/mokelab/InputDialog-v4/1.0.0/InputDialog-v4-1.0.0.pom\n ... その他m2/repositoryに生成される内容\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T04:12:57.927", "id": "11276", "last_activity_date": "2015-06-12T04:12:57.927", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "845", "parent_id": "11274", "post_type": "answer", "score": 2 }, { "body": "どうしても閉じたネットワーク内に建てる要件でなければbintrayを利用するのが手っ取り早いかと。\n\n閉じたネットワーク内に建てる場合はSonatype Nexusがまさにそんな利用用途です。 \nnexusはdockerで動かすのが簡単です。 \n<https://registry.hub.docker.com/u/sonatype/nexus/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T00:32:58.490", "id": "11343", "last_activity_date": "2015-06-15T00:32:58.490", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10140", "parent_id": "11274", "post_type": "answer", "score": 0 } ]
11274
11276
11276
{ "accepted_answer_id": "11285", "answer_count": 3, "body": "Javaで実行時間の計測処理を書こうとしたのですが、`System.currentTimeMillis()`や`System.nanoTime()`等で取得したミリ秒に対して、`hh:mm:ss\nSSS`の形式で文字列を取得したいだけなのにタイムゾーン考慮の必要性まで出てきて正直戸惑っています。\n\nPythonまでとは言わないまでも、もう少し簡単な方法はないでしょうか?自分で実装するしかありませんか? \nGuavaの`stopWatch`クラスも見てみましたが、指定形式への変換はなさそうでした。もしかしたら見落としているかもしれませんが・・・\n\n```\n\n long startTime = System.nanoTime();\n SimpleDateFormat date = new SimpleDateFormat(\"hh:mm:ss SSS\");\n System.out.println(date.format((System.nanoTime() - startTime) / 1000000));\n \n```\n\n上記の場合、出力結果が\n\n```\n\n 09:00:00 042\n \n```\n\nと出てしまいます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T05:42:48.087", "favorite_count": 0, "id": "11278", "last_activity_date": "2015-06-18T05:53:23.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7214", "post_type": "question", "score": 1, "tags": [ "java" ], "title": "ミリ秒をhh:mm:ss SSSに簡単に変換する方法", "view_count": 25531 }
[ { "body": "以下のformat()メソッドを共通処理として自分で実装し、 \n必要なところから呼び出すのが一番簡単ではないでしょうか?\n\n```\n\n public static void main(String[] args) {\n \n long startTime = System.currentTimeMillis();\n \n try {\n Thread.sleep(3000);\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n \n long endTime = System.currentTimeMillis();\n \n System.out.println(format(startTime, endTime));\n \n \n }\n \n private static String format(long startTime, long endTime) {\n Calendar start = Calendar.getInstance();\n Calendar end = Calendar.getInstance();\n Calendar result = Calendar.getInstance();\n \n start.setTimeInMillis(startTime);\n end.setTimeInMillis(endTime);\n \n long sa = end.getTimeInMillis() - start.getTimeInMillis() - result.getTimeZone().getRawOffset();\n \n result.setTimeInMillis(sa);\n \n SimpleDateFormat sdf = new SimpleDateFormat(\"mm:ss:SSS\");\n \n return sdf.format(result.getTime());\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T07:04:01.650", "id": "11282", "last_activity_date": "2015-06-12T07:04:01.650", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10115", "parent_id": "11278", "post_type": "answer", "score": 0 }, { "body": "調べました。\n\n<http://commons.apache.org/proper/commons-\nlang/apidocs/org/apache/commons/lang3/time/DurationFormatUtils.html>\n\nがあるようですね。\n\n```\n\n private static String format(long startTime, long endTime) {\n \n String diffTime = DurationFormatUtils.formatPeriod(startTime,\n endTime, \"HH:mm:ss.SSS\");\n \n return diffTime;\n \n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T08:28:58.650", "id": "11285", "last_activity_date": "2015-06-12T09:16:51.007", "last_edit_date": "2015-06-12T09:16:51.007", "last_editor_user_id": "7214", "owner_user_id": "10115", "parent_id": "11278", "post_type": "answer", "score": 3 }, { "body": "Joda-TimeではPeriodFormatterがありますが、Java8ではPeriodやDurationをフォーマットする方法は提供されていません。\n\n<https://stackoverflow.com/questions/20827047/formatting-a-duration-in-\njava-8-jsr310>", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-18T05:53:23.367", "id": "11464", "last_activity_date": "2015-06-18T05:53:23.367", "last_edit_date": "2017-05-23T12:38:56.083", "last_editor_user_id": "-1", "owner_user_id": "241", "parent_id": "11278", "post_type": "answer", "score": 2 } ]
11278
11285
11285
{ "accepted_answer_id": "11387", "answer_count": 2, "body": "ユーザ(`User`)毎にグループ化した アクセスログ(`AccessLog`)一覧を作っております。 \n表示項目で 最新のアクセス日(`newest_accessed_at`)をArelで取得したのですが、 \nその内容を ActiveRecord_Relationに入れると classがArel::Tableとなり\n`.page`等のメソッドが実行できなくなります。\n\nActiveRecord_Relationの内容に うまく Arelの内容をマージすることは可能でしょうか?\n\n```\n\n # model\n class User < ActiveRecord::Base\n has_many :access_logs\n end\n \n class AccessLog < ActiveRecord::Base\n belongs_to :user\n end\n \n # model or controller\n @access_logs = AccessLog.all\n @access_logs = @access_logs.group(:user_id).project(arel_table[:accessed_at].maximum.as('`newest_accessed_at`')) # ここでclassがArelになる\n # @access_logs = @access_logs.group(:user_id).select(\"`access_logs`.*, max(`access_logs`.`accessed_at`) AS `newest_accessed_at`\") # mysqlエラー\n @access_logs = @access_logs.page(10) # Arel::Tableだと `.page`が呼び出せない\n \n # views\n <% @access_logs.each do |access_log| %>\n <tr>\n <td><%= access_log.user.id %></td>\n <td><%= access_log.user.name %></td>\n <td><%= access_log.newest_accessed_at %></td>\n </tr>\n <% end %>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T06:45:51.790", "favorite_count": 0, "id": "11281", "last_activity_date": "2015-06-16T01:15:08.250", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9177", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "rails-activerecord" ], "title": "Arel::Tableの内容をActiveRecord_Relationにマージする方法", "view_count": 471 }
[ { "body": "arel を where に繋ぐ、という回答になっていませんが、目的を達成するのであれば、下記が使えると考えます。\n\n```\n\n AccessLog.group(:user).maximum(:accessed_at).each do |user, newest_accessed_at|\n p user.id\n p user.name\n p newest_accessed_at\n end\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T12:30:19.307", "id": "11292", "last_activity_date": "2015-06-12T12:30:19.307", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7471", "parent_id": "11281", "post_type": "answer", "score": 0 }, { "body": "selectメソッドも下記のようにArelのオブジェクトを引数に取れるようです。Rails 4.2で確認をしました。一度試してみてください。\n\n```\n\n @access_logs.group(:user_id).select(arel_table[:accessed_at].maximum.as('`newest_accessed_at`'))\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-16T01:07:33.730", "id": "11387", "last_activity_date": "2015-06-16T01:15:08.250", "last_edit_date": "2015-06-16T01:15:08.250", "last_editor_user_id": "10160", "owner_user_id": "10160", "parent_id": "11281", "post_type": "answer", "score": 1 } ]
11281
11387
11387
{ "accepted_answer_id": null, "answer_count": 1, "body": "GAのレポーティングAPIから数値を取得し、それをCSVで出力したいと考え、 \n下記のような関数をPythonで書きました。\n\n```\n\n \"\"\"GAから集計するための関数\"\"\"\n def get_results(service, profile_id):\n # Use the Analytics Service Object to query the Core Reporting API\n # for the number of sessions within the past seven days.\n return service.data().ga().get(\n ids='ga:' + profile_id,\n start_date='7daysAgo',\n end_date='today',\n dimensions='ga:date',\n metrics='ga:sessions').execute()\n \n \"\"\"集計した結果を表示する関数\"\"\"\n def print_data_table(results):\n output = []\n for header in results.get('columnHeaders'):\n output.append('%s' % header.get('name'))\n \n if results.get('rows',[]):\n for row in results.get('rows'):\n output.append('%s' % row)\n \n print(output)\n \n f = open('output.csv','wt')\n Writer = csv.writer(f,lineterminator='\\n')\n Writer.writerows(output)\n \n f.close()\n \n```\n\n上記の関数で数値を取得すると、\n\n```\n\n g,a,:,d,a,t,e\n g,a,:,s,e,s,s,i,o,n,s\n [,',2,0,1,5,0,6,0,5,',\",\", ,',1,',]\n [,',2,0,1,5,0,6,0,6,',\",\", ,',2,',]\n [,',2,0,1,5,0,6,0,7,',\",\", ,',3,',]\n [,',2,0,1,5,0,6,0,8,',\",\", ,',4,',]\n [,',2,0,1,5,0,6,0,9,',\",\", ,',5,',]\n [,',2,0,1,5,0,6,1,0,',\",\", ,',6,',]\n [,',2,0,1,5,0,6,1,1,',\",\", ,',7,',]\n [,',2,0,1,5,0,6,1,2,',\",\", ,',8,',]\n \n```\n\nというように出力され、不要なカンマが入ってしまいます。 \nPythonのcsvモジュールの仕様書を見てみたのですが、 \nどのように記述すれば、カンマが取れるのかわかりません。\n\n解決策をご教示いただけませんでしょうか? \nよろしくお願いいたします!", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T08:34:12.937", "favorite_count": 0, "id": "11286", "last_activity_date": "2015-06-12T16:12:55.400", "last_edit_date": "2015-06-12T08:38:08.273", "last_editor_user_id": "7214", "owner_user_id": "10116", "post_type": "question", "score": 0, "tags": [ "python", "csv", "google-analytics-api" ], "title": "pythonでリストをCSV出力する際に、不要なカンマが入ってしまうのを入らないようにしたいです。", "view_count": 11214 }
[ { "body": "結果から逆にたどると`get_results`の値は次の通りだったはず。\n\n```\n\n {\n \"columnHeaders\": [\n {\"name\": \"ga:date\"},\n {\"name\": \"ga:sessions\"}\n ],\n \"rows\": [\n [\"20150605\", \"1\"],\n [\"20150606\", \"2\"],\n [\"20150607\", \"3\"],\n [\"20150608\", \"4\"],\n [\"20150609\", \"5\"],\n [\"20150610\", \"6\"],\n [\"20150611\", \"7\"],\n [\"20150612\", \"8\"]\n ]\n }\n \n```\n\nであれば次のように書けば動きます\n\n```\n\n def print_data_table(results):\n \n header = [h.get('name') for h in results.get('columnHeaders')]\n output = [header] + results.get('rows',[])\n \n print(output)\n \n with open('output.csv','wt') as f:\n writer = csv.writer(f,lineterminator='\\n')\n writer.writerows(output)\n \n```\n\nCSVの内容\n\n```\n\n ga:date,ga:sessions\n 20150605,1\n 20150606,2\n 20150607,3\n 20150608,4\n 20150609,5\n 20150610,6\n 20150611,7\n 20150612,8\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T16:00:52.943", "id": "11298", "last_activity_date": "2015-06-12T16:12:55.400", "last_edit_date": "2015-06-12T16:12:55.400", "last_editor_user_id": "7837", "owner_user_id": "7837", "parent_id": "11286", "post_type": "answer", "score": 4 } ]
11286
null
11298
{ "accepted_answer_id": "11312", "answer_count": 1, "body": "検索して、参考サイトを探しているのですが \nbabelを利用してes6でプログラミングができる環境をrailsで構築する具体的な方法がわかりません。\n\nes6についてまったく経験が無いのですが \nそもそもそのような環境をrails上で構築することができるのでしょうか?\n\n参考サイトや導入方法など、簡単なものでもよいので意見がほしいです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T11:21:43.820", "favorite_count": 0, "id": "11290", "last_activity_date": "2015-06-13T09:05:52.230", "last_edit_date": "2015-06-13T06:03:37.400", "last_editor_user_id": "5840", "owner_user_id": "5840", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails" ], "title": "babelを利用した環境をrails4で構築することは可能ですか?", "view_count": 127 }
[ { "body": "```\n\n # Gemfile\n gem 'sprockets'\n gem 'sprockets-es6'\n \n```\n\nGemfileに上記を追加し、`javascripts`ディレクトリに`hoge.es6`ファイルを作成したら \nうまく出来ました。\n\nなぜsprocketsという名前のgemを追加するとbabelを利用できるのかはよくわかりません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T09:05:52.230", "id": "11312", "last_activity_date": "2015-06-13T09:05:52.230", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5840", "parent_id": "11290", "post_type": "answer", "score": 2 } ]
11290
11312
11312
{ "accepted_answer_id": null, "answer_count": 1, "body": "## 修正済\n\n文字だけでの質問が伝わりにくいものでしたので、現象の画像を追加し、何を問題にしているのか一目で分かるようにしました。合わせて、質問文を大幅に修正しました。\n\n以下、質問文です。よろしくお願いいたします。 \n\n* * *\n\niOSのカスタムキーボードを Keyboard Extension で作成しているのですが、Portrait表示と\nLandscape表示での制約を変更すると、回転時に表示を切り替えるときの動作が安定しません。\n\nたとえば、このような動作です。 \n(図はすべて、実機 iPhone 6 Plus のスクリーンショット) \n\n**図1:Portrait→回転→Landscape時のカスタムキーボード** \n![画像の説明をここに入力](https://i.stack.imgur.com/ikkzo.png) \n\n**図2:Landscape→回転→Portrait時のカスタムキーボード** \n![画像の説明をここに入力](https://i.stack.imgur.com/9wXXB.png) \n\n**図3:Portrait→回転→Landscape時のカスタムキーボード** \n![画像の説明をここに入力](https://i.stack.imgur.com/02WH3.png) \n\nシステムキーボードのような安定した動作にしたいと思っています。 \n\n**図4:Landscape→回転→Portrait時のシステムキーボード** \n![画像の説明をここに入力](https://i.stack.imgur.com/rpEpT.png) \n\n図1、図2、図3のように回転時にバネのように縮んだり伸びたりするキーボードを試行錯誤で修正した結果、現在このようなカスタムキーボードへと成長させることができました。 \n\n**図5:Landscape→回転→Portrait時のカスタムキーボード** \n![画像の説明をここに入力](https://i.stack.imgur.com/54hnV.png) \n\n一見システムキーボードに近いのですが、2点、違うところがあります。\n\n1点めは、Landscapeから\nPortraitへの回転開始時に、Landscape用のビューの上から、Portrait用のビューの頭がチラリと見えてしまうことです。(図5、左から2枚めの画像参照)\n\n2点めは、図3の不安定な動作が依然残っていることです。(図1と図2の現象はほぼ克服できました。)\n\nこの2つの問題点を解決し、システムキーボードのようなスムーズな回転遷移を実現するには、どのような方法があるでしょうか? \n \n\n長くなりまして申し訳ないのですが、今どのようなコードで問題の動作に直面しているかをご理解いただくために、作成中アプリの状態を詳しく書いてみます。\n\n作成中アプリの Keyboard Extension 用のグループ内には、以下のファイルが入っている状態です。\n\nKeyboardViewController.swift \nPortraitViewController.swift \nPortraitKeyboard.xib \nLandscapeViewController.swift \nLandscapeKeyboard.xib \nImages.xcassets\n\nKeyboardVIewControllerをコンテナViewControllerとして、PortraitViewControllerと\nLandscapeViewControllerを切り替えることで、縦長時と横長時で制約の違うキーボードを実現できるのではと考えてつくってみたものです。もし何か根本的に間違っている点などありましたら、それもご指摘いただけますとありがたいです。\n\nPortraitKeyboard.xibは、Interface Builder(以下 IB)の Identity Inspectorにて、File's\nOwnerの Classを PortraitViewControllerに指定しています。LandscapeKeyboard.xibも同様に、Classを\nLandscapeViewControllerに指定しています。\n\n各XibのViewには、システムキーボードのような形でボタンを並べています。各インスタンスの入れ子関係を図にしてみました。\n\n![画像の説明をここに入力](https://i.stack.imgur.com/KogmQ.png)\n\n実際は Row\nViewは4つで、ボタンの数はもう少し多いです。(開発中のカスタムキーボードのUIは、図1〜3や図5のサンプルキーボードのUIとは異なります。が、構造とコードは同様です。)\n\nBackground Viewの上下左右はベースの\nViewの上下左右とぴったり合わせています。他サブビューすべて、IB上で制約を設定しています。制約の`priority`は、Background\nViewの制約が`1000`、Row Viewの制約はすべて`999`、Buttonの制約はすべて`1000`となっております。\n\nUIButtonの\n`layer.cornerRadius`、`layer.shadowOffset`、`layer.shadowOpacity`、`layer.shadowRadius`も、IBで設定しています。`layer.shadowColor`は、`PortraitViewController`クラス、`LandscapeViewController`クラスにて、コードで設定しています。\n\n大体このような構造のものを作成しているとご理解いただければと思います。 \n \n\n以下コードを書きますが、UIButtonインスタンスにリンクするアクションや、プロトコル、デリゲート(テキスト入力等につかうもの)などは省き、表示に関係するところのみに限定いたします。\n\nどの swiftファイルも、`import`は`UIKit`のみです。\n\nPortraitViewController.swift内のコードはこのようになっております。\n\n```\n\n class PortraitViewController: UIInputViewController {\n \n @IBOutlet weak var row1: UIView!\n @IBOutlet weak var row2: UIView!\n @IBOutlet weak var row3: UIView!\n @IBOutlet weak var row4: UIView!\n private var rowAll: [UIView] = []\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n let nib = UINib(nibName: \"PortraitKeyboard\", bundle: nil)\n let objects = nib.instantiateWithOwner(self, options: nil)\n let keyboardView = objects[0] as! UIView\n self.view = keyboardView\n \n rowAll = [row1, row2, row3, row4]\n }\n \n override func viewDidAppear(animated: Bool) {\n super.viewDidAppear(animated)\n setShadowColorPortrait(rowAll)\n }\n \n private func setShadowColorPortrait(views: [UIView]) {\n for view in views {\n for button in view.subviews as! [UIButton] {\n button.layer.shadowColor = UIColor(\n red: 127/255.0,\n green: 137/255.0,\n blue: 146/255.0,\n alpha: 1.0).CGColor\n }\n }\n }\n \n }\n \n```\n\nLandscapeViewController.swiftのコードも、`nibName`と`private func`名が変わるのみで同様です。\n\nコンテナViewControllerとして使う KeyboardViewController.swiftのコードは、\n\n```\n\n class KeyboardViewController: UIInputViewController {\n \n private let portraitViewController = PortraitViewController()\n private let landscapeViewController = LandscapeViewController()\n \n //MARK: Constraints\n \n // 子viewの制約\n private var cViewWidthPortrait: NSLayoutConstraint!\n private var cViewHeightPortrait: NSLayoutConstraint!\n private var cViewWidthLandscape: NSLayoutConstraint!\n private var cViewHeightLandscape: NSLayoutConstraint!\n \n // キーボードの高さの制約\n private var cKeyboardHeight: NSLayoutConstraint!\n \n //MARK: Constraints Constants\n \n // Portrait表示におけるキーボードの高さ\n private var portraitHeight: CGFloat = 190.0\n private var portraitWidth: CGFloat!\n \n // Landscape表示におけるキーボードの高さ\n private var landscapeHeight: CGFloat = 150.0\n private var landscapeWidth: CGFloat!\n \n //MARK: Helper Bools\n private var firstTimeLoad: Bool!\n \n private var gotPortraitSize: Bool!\n private var gotLandscapeSize: Bool!\n \n private var appliedPortraitSize: Bool!\n private var appliedLandscapeSize: Bool!\n \n //MARK: Override Functions\n override func viewDidLoad() {\n super.viewDidLoad()\n \n firstTimeLoad = true\n gotPortraitSize = false\n appliedPortraitSize = false\n gotLandscapeSize = false\n appliedLandscapeSize = false\n \n // self.viewからはみ出すサブビューが表示されるように設定\n self.view.clipsToBounds = false\n \n // Add LandscapeViewController & its view as Child\n self.addChildViewController(landscapeViewController)\n self.view.addSubview(landscapeViewController.view)\n landscapeViewController.didMoveToParentViewController(self)\n landscapeViewController.view.setTranslatesAutoresizingMaskIntoConstraints(false)\n \n // Add PortraitViewController & its view as Child\n self.addChildViewController(portraitViewController)\n self.view.addSubview(portraitViewController.view)\n portraitViewController.didMoveToParentViewController(self)\n portraitViewController.view.setTranslatesAutoresizingMaskIntoConstraints(false)\n \n self.view.bringSubviewToFront(portraitViewController.view)\n \n // KeyboardViews' constraints Top & Left\n self.view.addConstraints(fixedConstraints(portraitViewController.view))\n self.view.addConstraints(fixedConstraints(landscapeViewController.view))\n \n // KeyboardViews' constraints Width & Height (XibのViewサイズそのままの状態)\n self.view.addConstraints(widthHeightConstraints())\n \n // キーボードの高さの制約を設定(ここでは変更せず、既定のままの状態)\n cKeyboardHeight = NSLayoutConstraint(item: self.view,\n attribute: .Height, relatedBy: .Equal,\n toItem: nil,\n attribute: .NotAnAttribute, multiplier: 1.0,\n constant: self.view.bounds.size.height)\n cKeyboardHeight.priority = 999\n self.view.addConstraint(cKeyboardHeight)\n }\n \n override func viewDidAppear(animated: Bool) {\n super.viewDidAppear(animated)\n \n if isLandscape() { // Landscapeだったら、\n // landscapeViewController.viewを Landscapeのキーボードサイズに固定する。\n applyViewSize(\"Landscape\")\n \n // Landscapeの viewを表示させ、Portraitのviewを隠す。\n landscapeViewController.view.hidden = false\n portraitViewController.view.hidden = true\n \n // キーボードの高さを変更する。\n changeKeyboardHeight(\"Landscape\")\n \n } else { // Portraitだったら、\n // portraitViewController.viewを Portraitのキーボードサイズに固定する。\n applyViewSize(\"Portrait\")\n \n // Portraitの viewを表示させ、Landscapeのviewを隠す。\n portraitViewController.view.hidden = false\n landscapeViewController.view.hidden = true\n \n // キーボードの高さを変更する。\n changeKeyboardHeight(\"Portrait\")\n }\n \n // 以後は起動時の処理ではないという合図\n firstTimeLoad = false\n }\n \n override func viewDidLayoutSubviews() {\n super.viewDidLayoutSubviews()\n \n if firstTimeLoad == true {\n // キーボード起動時であれば、何もしない\n return\n }\n \n var orientation: String!\n \n if isLandscape() { // Landscapeだったら、\n orientation = \"Landscape\"\n // Landscape用の viewを表示する。\n keyboardViewHidden(orientation)\n \n } else { // Portraitだったら、\n orientation = \"Portrait\"\n // Portrait用の viewを表示する。\n keyboardViewHidden(orientation)\n }\n \n // Portrait / Landscapeどちらかの、適切なキーボード縦横サイズが未適用状態であれば、\n if appliedLandscapeSize == false || appliedPortraitSize == false {\n // 適切なキーボード縦横サイズを適用し、子Viewの縦横を固定する。\n applyViewSize(orientation)\n }\n \n // キーボードの高さを変更する。\n changeKeyboardHeight(orientation)\n }\n \n //MARK: Hidden Control Functions\n private func keyboardViewHidden(orientation: String) {\n \n if orientation == \"Landscape\" { // Landscapeだったら、\n if landscapeViewController.view.hidden == false {\n // すでにLandscape表示であれば、何もしない。\n return\n } else {\n portraitViewController.view.hidden = true\n landscapeViewController.view.hidden = false\n }\n } else { // Portraitだったら、\n if portraitViewController.view.hidden == false {\n // すでにPortrait表示であれば、何もしない。\n return\n } else {\n landscapeViewController.view.hidden = true\n portraitViewController.view.hidden = false\n }\n }\n }\n \n //MARK: Constraints Functions\n private func widthHeightConstraints() -> [NSLayoutConstraint] {\n // 子ViewControler.viewの .Width、.Heightの制約を生成し、プロパティに格納する。\n \n cViewWidthLandscape = NSLayoutConstraint(item: self.landscapeViewController.view,\n attribute: .Width, relatedBy: .Equal, toItem: nil,\n attribute: .NotAnAttribute, multiplier: 1.0,\n constant: landscapeViewController.view.bounds.size.width)\n cViewHeightLandscape = NSLayoutConstraint(item: self.landscapeViewController.view,\n attribute: .Height, relatedBy: .Equal, toItem: nil,\n attribute: .NotAnAttribute, multiplier: 1.0,\n constant: landscapeViewController.view.bounds.size.height)\n cViewWidthPortrait = NSLayoutConstraint(item: self.portraitViewController.view,\n attribute: .Width, relatedBy: .Equal, toItem: nil,\n attribute: .NotAnAttribute, multiplier: 1.0,\n constant: portraitViewController.view.bounds.size.width)\n cViewHeightPortrait = NSLayoutConstraint(item: self.portraitViewController.view,\n attribute: .Height, relatedBy: .Equal, toItem: nil,\n attribute: .NotAnAttribute, multiplier: 1.0,\n constant: portraitViewController.view.bounds.size.width)\n return [cViewWidthLandscape, cViewHeightLandscape,\n cViewWidthPortrait, cViewHeightPortrait]\n }\n \n private func fixedConstraints(view: UIView) -> [NSLayoutConstraint] {\n // 子ViewController.viewの .Top、.Leftの制約を生成する。\n let top = NSLayoutConstraint(item: view,\n attribute: .Top, relatedBy: .Equal,\n toItem: self.view,\n attribute: .Top, multiplier: 1.0, constant: 0.0)\n let left = NSLayoutConstraint(item: view,\n attribute: .Left, relatedBy: .Equal,\n toItem: self.view,\n attribute: .Left, multiplier: 1.0, constant: 0.0)\n return [top, left]\n }\n \n private func isLandscape() -> Bool {\n // 現時点で Landscape表示が適当かどうかを判断する。\n let screenSize = UIScreen.mainScreen().bounds.size\n let screenH = screenSize.height\n let screenW = screenSize.width\n let isLandscapeNow = !(self.view.frame.size.width ==\n screenW * ((screenW < screenH) ? 1 : 0) +\n screenH * ((screenW > screenH) ? 1 : 0))\n return isLandscapeNow\n }\n \n private func getSystemKeyboardSize(orientation: String) {\n // 既定のキーボードの横サイズを取得し、制約のconstant値に使うプロパティに格納する。\n if orientation == \"Landscape\" {\n landscapeWidth = self.view.bounds.width\n \n // 既定Landscapeキーボードのサイズを取得済という合図\n gotLandscapeSize = true\n \n } else { // Portrait\n portraitWidth = self.view.bounds.width\n \n // 既定Portraitキーボードのサイズを取得済という合図\n gotPortraitSize = true\n }\n }\n \n private func applyViewSize(orientation: String) {\n // 取得した既定キーボードの横サイズ、自分の設定した縦サイズを、\n // 子ViewController.viewに適用する。\n \n if orientation == \"Landscape\" { // Landscapeだったら、\n if gotLandscapeSize == false {\n // Landscapeの既定キーボードサイズが未取得であれば、取得する。\n getSystemKeyboardSize(\"Landscape\")\n }\n if cViewHeightLandscape.constant == landscapeHeight {\n // すでに適当なLandscape用サイズが適用されていれば、何もしない。\n return\n } else {\n // LandscapeViewController.viewの制約 .Heihgt、.Widthを、\n // キーボードサイズに固定する。\n cViewHeightLandscape.constant = landscapeHeight\n cViewWidthLandscape.constant = landscapeWidth\n \n // LandscapeViewController.viewの縦横サイズを設定済という合図\n appliedLandscapeSize = true\n }\n } else { // Portraitだったら、\n if gotPortraitSize == false {\n // Portraitの既定キーボードサイズが未取得であれば、取得する。\n getSystemKeyboardSize(\"Portrait\")\n }\n if cViewHeightPortrait.constant == portraitHeight {\n // すでに適当なPortrait用サイズが適用されていれば、何もしない。\n return\n } else {\n // PortraitViewController.viewの制約 .Height、.Widthを、\n // キーボードサイズに固定する。\n cViewHeightPortrait.constant = portraitHeight\n cViewWidthPortrait.constant = portraitWidth\n \n // PortraitViewController.viewの縦横サイズを設定済という合図\n appliedPortraitSize = true\n }\n }\n }\n \n private func changeKeyboardHeight(orientation: String) {\n // キーボードの高さの制約を変更する。\n if orientation == \"Landscape\" { // Landscapeだったら、\n if cKeyboardHeight.constant == landscapeHeight {\n // すでに Landscape用の高さであれば、何もしない。\n return\n } else {\n cKeyboardHeight.constant = landscapeHeight\n }\n } else { // Portraitだったら、\n if cKeyboardHeight.constant == portraitHeight {\n // すでに Portrait用の高さであれば、何もしない。\n return\n } else {\n cKeyboardHeight.constant = portraitHeight\n }\n }\n }\n \n }\n \n```\n\nとなっています。\n\n`func isLandscape()`等のコードは、『[iOS 8 Custom Keyboard: Changing the\nHeight](https://stackoverflow.com/questions/24167909/ios-8-custom-keyboard-\nchanging-the-height)』を参考にしました。 \n \n\nこのカスタムキーボードの主な制約は上の通り KeyboradViewControllerクラスに書いているのですが、要点をまとめておきます。\n\n * `self.view.clipsToBounds = false`として、`self.view`からはみ出すサブビューの全体が表示されるように設定。\n * 子`ViewController.view`の制約`.Top`、`.Left`を、`self.view`の `.Top`、`.Left`に合わせる。\n * Portrait用の子`view`の `.Width`を Portrait時の既定キーボード幅に、`.Height`を自分が決めた値に、設定する。\n * Landscape用の子`view`の `.Width`を Landscape時の既定キーボード幅に、`.Height`を自分が決めた値に、設定する。\n * 子`view`のサブビューは、Interface Builderで設定した通りに表示される。(Portrait用の子`view`と Landscape用の子`view`には、ほぼ同じオブジェクトが配置されているが、制約の`constant`値は異なる)\n * インターフェイス回転時に、Portrait用の子`view`、Landscape用の子`view`、どちらかを表示し、どちらかを非表示にする。\n * インターフェイス回転時に、キーボードの高さ(`self.view`の制約`.Height`)の`constant`値を変更する。 \n \n\nこうした状態ですが、図3のような現象を無くすには、どこを修正するとよいでしょうか?\n\nシステムキーボードのようにキーボードの上端、下端、左端、右端がぶれずに安定して回転するカスタムキーボード、または、インターフェイスの回転開始時や回転終了直前にガクンとした印象の不安定な動作を見せないカスタムキーボードを、どうしたら実現できるのか、ということを知りたいと思っております。\n\n解決案、またはその手がかりなど、お教えいただけませんでしょうか?\n\nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T14:36:30.697", "favorite_count": 0, "id": "11294", "last_activity_date": "2016-10-19T03:25:37.557", "last_edit_date": "2017-05-23T12:38:56.467", "last_editor_user_id": "-1", "owner_user_id": "9833", "post_type": "question", "score": 6, "tags": [ "ios", "swift", "xcode" ], "title": "iOS Keyboard Extensionで、Portrait表示と Landscape表示の制約をスムーズに変更したい", "view_count": 1172 }
[ { "body": "見た目が伸び縮みするだけであるなら1つのビューコントローラーにまとめてしまって、updateViewConstraintsイベントの中で高さの制約をカスタマイズした方が見通しが良いように思われます。\n\n回転時に滑らかに変化するのか検証していないのですが、カスタムキーボードの高さをPortraitとLandscapeで変更したいという質問と回答を本家で見つけました。参考になるでしょうか。\n\n[iOS 8 Custom Keyboard: Changing the\nHeight](https://stackoverflow.com/questions/24167909/ios-8-custom-keyboard-\nchanging-the-height)\n\nLinkedとRelatedも参考になりそうです。\n\n# 追記 2015-06-22 20:24\n\nコメントした、高さは変更できないけれど簡単に部品をレイアウトするサンプルコード。\n\n```\n\n #import \"KeyboardViewController.h\"\n \n @interface KeyboardViewController ()\n \n @property (nonatomic, weak) IBOutlet UIButton *nextKeyboardButton;\n \n @end\n \n @implementation KeyboardViewController\n \n - (void)viewDidLoad {\n [super viewDidLoad];\n \n // CustomKeyboardView.xibではnextKeyboardButtonをAuto Layoutを使って配置してあります。\n UIView *view = [[[UINib nibWithNibName:@\"CustomKeyboardView\" bundle:nil] instantiateWithOwner:self options:nil] objectAtIndex:0];\n view.translatesAutoresizingMaskIntoConstraints = NO;\n [self.view addSubview:view];\n [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@\"H:|[view]|\" options:0 metrics:nil views:@{@\"view\":view}]];\n [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@\"V:|[view]|\" options:0 metrics:nil views:@{@\"view\":view}]];\n }\n \n - (IBAction)nextKeyboard:(id)sender {\n [self advanceToNextInputMode];\n }\n \n @end\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-22T00:29:59.887", "id": "11589", "last_activity_date": "2015-06-22T11:30:42.117", "last_edit_date": "2017-05-23T12:38:56.083", "last_editor_user_id": "-1", "owner_user_id": "7283", "parent_id": "11294", "post_type": "answer", "score": 1 } ]
11294
null
11589
{ "accepted_answer_id": null, "answer_count": 1, "body": "AppleWatchからiPhoneにリクエストを投げるのに、 \n[WKInterfaceController openParentApplication:userInfo reply: **^(NSDictonary\n*replyInfo, NSError *error)** { \nif(replyInfor){ \n・・・\n\nとありますが、 \n**^(NSDictonary *replyInfo, NSError *error)** \nは何をやっているのでしょうか?\n\nまたiPhoneでのAppleWatchのリクエスト受信で、 \n-(void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply: **(void (^)(NSDictionary *))reply** { \n・・・ \nの**(void (^)(NSDictionary *))reply**も何をやっているのかわかりません。 \n「^」がそもそもわからないからなのでしょうか。。\n\n参考になるURLでもかまいません。どなたか教えてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T15:18:50.280", "favorite_count": 0, "id": "11295", "last_activity_date": "2015-06-12T22:51:07.847", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8593", "post_type": "question", "score": 1, "tags": [ "ios", "objective-c" ], "title": "WKInterfaceControlerのメソッドで何を行っているか?", "view_count": 78 }
[ { "body": "`^`で始まる記法はブロックといって、他の言語ではクロージャとか無名関数などと呼ばれているものですが、大ざっぱにいうと処理をオブジェクトとして変数に格納したり、引数として渡せるという言語の機能です。\n\n<https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Blocks/Articles/bxGettingStarted.html#//apple_ref/doc/uid/TP40007502-CH7-SW2>\n\n↑上記の公式のドキュメントの他、「Objective-C ブロック」などの検索後で調べると良いです。\n\nさて、\n\n```\n\n reply:^(NSDictonary *replyInfo, NSError *error)\n \n```\n\nの部分は`reply`という名前で、`NSDictonary`と`NSError`の2つの引数をとるブロックを引数として渡している、ということになります。\n\nCocoaでは、ブロックは主に非同期のメソッドのコールバックとして利用されることが多く、このメソッドでもそのように使われています。\n\nこの`reply`に渡したブロック(処理の固まり)はアプリの呼び出しが完了したときにシステムから呼び出されます。 \nそうすることによって、非同期のメソッドの実行が完了したことを知らせることができるようになっています。\n\n呼び出されるアプリのほうでは、下記のデリゲートメソッドが呼び出されますので、\n\n```\n\n - (void)application:(UIApplication *)application\n handleWatchKitExtensionRequest:(NSDictionary *)userInfo\n reply:(void(^)(NSDictionary *replyInfo))reply;\n \n```\n\n例えば次のように、アプリケーション側から必要な情報を`NSDictionary`に詰めてブロックを呼び出すことで、Watch側に完了を知らせる(と同時に情報を渡す)ことができます。\n\n```\n\n - (void)application:(UIApplication *)application\n handleWatchKitExtensionRequest:(NSDictionary *)userInfo\n reply:(void(^)(NSDictionary *replyInfo))reply\n // 適当に何かする...\n \n NSDictionary *replyInfo = @{@\"aaa\": @\"bbb\"};\n reply(replyInfo); // 必要な処理が終わったらコールバックとしてブロックを呼び出す\n }\n \n```\n\nするとWatch側では引数として渡したブロックが呼び出されますので、そこで完了を知ることができ、必要ならあらかじめブロックとして渡した処理が実行されます。\n\n```\n\n [WKInterfaceController openParentApplication:nil reply:^(NSDictionary *replyInfo, NSError *error) {\n // アプリ側の呼び出しが完了したらこのブロックが呼び出される\n NSLog(@\"%@\", replyInfo); // {\"aaa\": \"bbb\"}\n }];\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T22:51:07.847", "id": "11301", "last_activity_date": "2015-06-12T22:51:07.847", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "11295", "post_type": "answer", "score": 1 } ]
11295
null
11301
{ "accepted_answer_id": "11314", "answer_count": 1, "body": "omniauthを使ってFacebook、Twitterのログインと通常のメールアドレス登録を実装しています。 \ndeviseでメール認証する(confirmable)ようにしました。。 \nFacebookとTwitterのログインのときには、メール認証せずにログインするようにしたいので \n下記のように`@user.skip_confirmation!`を追加し無事認証はできるようになったのですが \n認証メールが送られる状態です。どうすればメールを送らないようにできるでしょうか?\n\n```\n\n class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController\n \n def facebook\n callback_from :facebook\n end\n \n def twitter\n callback_from :twitter\n end\n \n private\n \n def callback_from(provider)\n provider = provider.to_s\n \n @user = User.find_for_oauth(request.env['omniauth.auth'])\n @user.skip_confirmation!\n if @user.persisted?\n flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: provider.capitalize)\n sign_in_and_redirect @user, event: :authentication\n else\n if provider == 'twitter'\n session[\"devise.twitter_data\"] = request.env[\"omniauth.auth\"].except(\"extra\")\n else\n session[\"devise.facebook_data\"] = request.env[\"omniauth.auth\"]\n end\n redirect_to new_user_registration_url\n end\n end\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T15:42:57.440", "favorite_count": 0, "id": "11297", "last_activity_date": "2015-06-13T15:30:35.067", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9161", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails" ], "title": "Rails4.2 Devise + omniauthでソーシャルログイン時はメール認証とメール送信をスキップしたい。", "view_count": 511 }
[ { "body": "@user.save!で保存してしまう\n\n```\n\n def callback_from(provider)\n provider = provider.to_s\n \n @user = User.find_for_oauth(request.env['omniauth.auth'])\n @user.skip_confirmation!\n @user.save!\n if @user.persisted?\n flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: provider.capitalize)\n sign_in_and_redirect @user, event: :authentication\n else\n if provider == 'twitter'\n session[\"devise.twitter_data\"] = request.env[\"omniauth.auth\"].except(\"extra\")\n else\n session[\"devise.facebook_data\"] = request.env[\"omniauth.auth\"]\n end\n redirect_to new_user_registration_url\n end\n end\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T15:30:35.067", "id": "11314", "last_activity_date": "2015-06-13T15:30:35.067", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9161", "parent_id": "11297", "post_type": "answer", "score": 0 } ]
11297
11314
11314
{ "accepted_answer_id": "12066", "answer_count": 2, "body": "```\n\n data Car = NamedCar String | NamedCarWithColorName String String\n \n```\n\n上のような `data` があった時に `NamedCarWithColorNameAndEngineType String String String`\nを後から追加することはできますか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T18:05:53.710", "favorite_count": 0, "id": "11299", "last_activity_date": "2015-07-24T12:49:52.760", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2112", "post_type": "question", "score": 3, "tags": [ "haskell" ], "title": "dataに後からdata constructorを追加できますか?", "view_count": 246 }
[ { "body": "定義に手を加えないという条件であれば、できません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-24T08:49:06.103", "id": "11675", "last_activity_date": "2015-06-24T08:49:06.103", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8654", "parent_id": "11299", "post_type": "answer", "score": 1 }, { "body": "できません。 \nこれはHaskellの「型」が安全に使用できることを意味します。\n\nたとえば、NamedCar -> Stringのような型を持つ関数を作成したとします。 \nこの関数はNamedCarとNamedCarWithColorNameの2種類の値について定義されているはずです。 \nもしも、後からNamedCarWithColorNameAndEngineTypeが追加できてしまうと、 \nこの関数は「失敗する可能性のある関数」となってしまいます。\n\n多くの動的型付けオブジェクト指向言語にあるような型の柔軟性はHaskellには存在しません。 \nしかし、Haskellでは「より厳密な理論を背景にした」同様のコーディングができます。 \nGHCの拡張機能のExistentialQuantificationを使用します。 \n質問の例ならば以下のようになります。\n\n```\n\n {-# LANGUAGE ExistentialQuantification #-}\n \n class CarClass c where\n showCar :: c -> String\n \n data Car = forall c . CarClass c => Car c\n \n instance CarClass Car where\n showCar (Car c) = showCar c\n \n data NamedCar = NamedCar String\n \n instance CarClass NamedCar where\n showCar (NamedCar n) = n\n \n data NamedCarWithColorName = NamedCarWithColorName String String\n \n instance CarClass NamedCarWithColorName where\n showCar (NamedCarWithColorName n c) = n ++ \" \" ++ c\n \n data NamedCarWithColorNameAndEngineType =\n NamedCarWithColorNameAndEngineType String String String\n \n instance CarClass NamedCarWithColorNameAndEngineType where\n showCar (NamedCarWithColorNameAndEngineType n c e) =\n n ++ \" \" ++ c ++ \" \" ++ e\n \n cars :: [Car]\n cars = [\n Car (NamedCar \"Lexus\"),\n Car (NamedCarWithColorName \"Crown\" \"Pink\"),\n Car (NamedCarWithColorNameAndEngineType \"M3\" \"Black\" \"M88/3\") ]\n \n main :: IO ()\n main = mapM_ (putStrLn . showCar) cars\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-07-06T04:18:58.213", "id": "12066", "last_activity_date": "2015-07-24T12:49:52.760", "last_edit_date": "2015-07-24T12:49:52.760", "last_editor_user_id": "269", "owner_user_id": "269", "parent_id": "11299", "post_type": "answer", "score": 4 } ]
11299
12066
12066
{ "accepted_answer_id": "11302", "answer_count": 1, "body": "ちょっと疑問に思っただけなので実際的な問題を抱えているわけではないのですが、 \nポインタとメモリブロックが与えられた時にそのポインタがメモリブロック内を指しているかどうかを調べるプログラム的方法はありますか?\n\n例えば、 \n文字列(つまりポインタ)とポインタが与えられた時にポインタが与えられた文字列内を指しているか? \nとか \nmallocで確保したメモリ内を与えられたポインタが指しているか? \nというようなことを調べる関数を書きたいということです。\n\n例として次のような擬似コードで\n\n```\n\n bool 適合チェック(Type *メモリの最初, Type *メモリの最後, Type *調べたいポインタ){\n return メモリの最初 <= 調べたいポインタ && 調べたいポインタ <= メモリの最後;\n }\n \n```\n\n(あるいは`bool 適合チェック(void *メモリの最初, size_t メモリのサイズ, void *調べたいポインタ)`のようなインターフェース) \nみたいな感じで書きたいように思いますが、 \n(おそらく多くの場面で期待するように動作するだろうと思われますが) \nCの規格上ポインタが有効なメモリブロック(と+1の)範囲内であれば \n比較したり減算したりということは有効ですが、 \n範囲外であれば、動作未定義となるのでこのようには書くことはできません。\n\nでは、実質的にCの規格に沿う形でこのような関数を記述することは出来ないのでしょうか? \nできるとすればどのように記述すればいいですか?\n\n※要素の型またはサイズが分かっている場合にはループして`==`で有効ポインタを全数チェックすることで可能かもしれませんがそれは避けたいです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T21:42:10.990", "favorite_count": 0, "id": "11300", "last_activity_date": "2015-06-15T04:08:07.800", "last_edit_date": "2015-06-12T21:52:11.607", "last_editor_user_id": "5044", "owner_user_id": "5044", "post_type": "question", "score": 4, "tags": [ "c", "ポインタ" ], "title": "ポインタの範囲適合チェック", "view_count": 918 }
[ { "body": "[c](/questions/tagged/c \"'c' のタグが付いた質問を表示\") 言語規格書 ISO/IEC 9899 \n[c++](/questions/tagged/c%2b%2b \"'c++' のタグが付いた質問を表示\") 言語規格書 ISO/IEC 14882 \nに通じていない人のために話の整理から\n\nISO/IEC 14882:1998 5.7 加減演算子 および ISO/IEC 9899:1999 6.5.6 加減演算子 \n`P` が配列オブジェクトの最後の要素を指すとき `(P)+1` は最後の要素を1つ越えたところを指す \n`Q` が配列オブジェクトの最後の要素を1つ越えたところを指すとき `(Q)-1` は最後の要素を指す \n`Q` を `*` の評価の対象としてはならない\n\nISO/IEC 14882:1998 5.9 関係演算子 その他のポインタ比較は未規定とする \nISO/IEC 9899:1999 6.5.8 関係演算子 その他のすべての場合動作は未定義とする\n\nなので `T array[N];` と `T val;` があるとき、提示のサンプルに\n\n```\n\n if (適合チェック(array, array+N, &val)) {...}\n \n```\n\nとしても結果は [c++](/questions/tagged/c%2b%2b \"'c++' のタグが付いた質問を表示\") の場合未規定\n[c](/questions/tagged/c \"'c' のタグが付いた質問を表示\") の場合未定義、ということです。\n\nISO/IEC 14882:1998 5.10 等価演算子 ISO/IEC 9899:1999 6.5.9 等価演算子 \n等価演算子に対しては「未定義」の文言が無い\n\nということで `==` なら安全ってことで。\n\nで、題意についてですけど・・・無い、んぢゃないっすかね? \nC/C++ の言語仕様書厳密合致の範囲で、なんですよね? \nていうことは「いかなる処理系でもこの方法で、ソース修正なしにうまく動く必然がある」ってことで。 \nオーダー O(1) のコストで実現するには、処理系の実装を問わずにどうこうは難しいと思われます。\n\nポインタ値の範囲だけわかっても \n- const なオブジェクトを指すポインタに対して書き込む deref はできない \n- 範囲は正しくても境界整合してないポインタ値を使うことはできない \nとかもっと別の制約がありそうですし。\n\nオイラなら言語規格書のレベルでの妥当性はあきらめて \n「今開発対象としているこの処理系ならこのコードで良し」として妥協します。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-12T23:33:22.460", "id": "11302", "last_activity_date": "2015-06-15T04:08:07.800", "last_edit_date": "2015-06-15T04:08:07.800", "last_editor_user_id": "8589", "owner_user_id": "8589", "parent_id": "11300", "post_type": "answer", "score": 2 } ]
11300
11302
11302
{ "accepted_answer_id": "11357", "answer_count": 1, "body": "Chefで npm とそのパッケージ `casperjs`を入れたいのですが方法がわからず躓いています。\n\n今まではNodejs本体だけしか必要なかったので `cookbook/nodejs/recipes/default.rb`に\n\n```\n\n package \"nodejs\"\n \n```\n\nとしていただけだったのですが、`npm`で`casperjs`もインストールする必要が出てきたため公開されてるレシピを利用して設定を行おうとしたのですが使い方がわかりませんでした。\n\n<https://github.com/redguide/nodejs>\n\nこちらを使ってBerkshelfで以前行った`rbenv`のように必要なパッケージのインストールを行いたいのですが、`include_recipe`を使う方法しか書いておらず先に進めていません。\n\nそもそもこの cookbook が Berkshelf で利用可能かさえもわかっていないのですが、 \nどのような手順で `npm`をインストールし`casperjs`パッケージを入れるか教えて頂けないでしょうか。\n\n参考までに現在行っている`rbenv`の設定を書いておきます。\n\n### Berksfile\n\n```\n\n cookbook \"rbenv\", github: 'fnichol/chef-rbenv'\n \n```\n\n### nodes/my_node.json\n\n```\n\n \"rbenv\": {\n \"rubies\": [\"2.2.0\"],\n \"global\": \"2.2.0\",\n \"root_path\": \"/opt/rbenv\",\n \"gems\": {\n \"2.2.0\": [\n { \"name\": \"activesupport\"}\n ]\n }\n },\n \"run_list\": [\n \"rbenv::system\"\n ]\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T00:14:39.907", "favorite_count": 0, "id": "11303", "last_activity_date": "2015-08-26T15:16:20.663", "last_edit_date": "2015-08-26T15:16:20.663", "last_editor_user_id": "2238", "owner_user_id": "3271", "post_type": "question", "score": 1, "tags": [ "node.js", "chef", "npm" ], "title": "npmパッケージをChefでインストールする方法", "view_count": 361 }
[ { "body": "上記の質問をした時は疲れていたせいか、どうすればよいか思いつかなかったのですが `rbenv`の場合とほぼ同じ方法でインストール出来ました。\n\n`node/foobar.json`に\n\n```\n\n \"nodejs\": {\n \"npm_packages\":[\n {\n \"name\": \"casperjs\"\n }\n ]\n },\n \n```\n\nという記述と `Berksfile`に\n\n```\n\n cookbook \"nodejs\", github: 'redguide/nodejs'\n \n```\n\nを追記して実行すると正常にcasperjsが使えるようになりました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T03:53:25.317", "id": "11357", "last_activity_date": "2015-06-15T03:53:25.317", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "parent_id": "11303", "post_type": "answer", "score": 1 } ]
11303
11357
11357
{ "accepted_answer_id": "11313", "answer_count": 1, "body": "以下のような画面構成で音楽プレイヤーを作成しています。 \n[アルバム一覧画面] → [選択されたアルバムの曲一覧画面] → [再生画面] \n画面の遷移はナビゲーションコントローラを用いています。\n\nそこで以下の手順で操作を行うと、`MPMusicPlaybackState`が正しい状態を取得しなくなります。 \n1. 起動するとアルバム一覧画面が表示されるので、任意のアルバムを選択する。 \n2. 曲一覧画面に移動するので、曲を選択する。 \n3. 再生画面に移動し音楽が再生される。 \nここでは問題なく`MPMusicPlaybackState`の取得、制御ができます。 \n4. ナビゲーションでアルバム一覧ページまで戻り、別のアルバムを選択し再生する。 \n5. すると音楽が再生されているにも関わらず`MPMusicPlaybackState`が常に`Paused`となり、 \n制御できなくなってしまいます。 \n6. 再度曲一覧まで戻り、別の曲を選択すると`MPMusicPlaybackState` \nが取得できるようになります。\n\nこれは画面の移動時に何か処理が足りないのでしょうか?\n\n色々調べたところ、以下のページで過去に似たような質問をされている方がいました。 \n<https://stackoverflow.com/questions/10118726/getting-wrong-playback-state-in-\nmp-music-player-controller-in-ios-5> \nかなり古い質問ですが、昔はバグとして存在していたのでしょうか? \niOS8で修正されたとコメントしている方もいますが・・・\n\n以下は再生・停止ボタンのコードです。\n\n```\n\n //再生・停止ボタンアクション\n @IBAction func playPauseB(sender: UIButton) {\n var playerStatus = player.playbackState\n if playerStatus == MPMusicPlaybackState.Playing{\n player.pause()\n playPauseBOutlet.setImage(playB, forState: UIControlState.Normal)\n } else if playerStatus == MPMusicPlaybackState.Paused {\n player.play()\n playPauseBOutlet.setImage(PauseB, forState: UIControlState.Normal)\n }\n }\n \n```\n\nご指摘やアドバイスお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T02:00:37.120", "favorite_count": 0, "id": "11304", "last_activity_date": "2015-06-13T10:23:55.810", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "9857", "post_type": "question", "score": 1, "tags": [ "swift" ], "title": "MPMusicPlaybackStateが正しい状態を取得しない。", "view_count": 527 }
[ { "body": "質問の内容だけでは処理が足りないかどうかは判断できないですが、MPMusicPlayerControllerのplaybackStateがおかしくなる現象は存在します。自分はiOS7とiOS8で確認しました。\n\n自分が確認した時の手順については、以下のページにまとめてあります。少し古いものですが。\n\nMPMusicPlayerController::playbackStateがおかしくなる問題 - 開発メモ \n<http://seeku.hateblo.jp/entry/2014/07/07/164821>\n\nこの現象への対策ですが、一番手っ取り早いのはplaybackStateを使わないことだと思われます。 \n(質問に書かれてるstackoverflow.comの回答と、本質的には同じことです)\n\n```\n\n import AVFoundation\n \n /// 再生中か?\n func isMusicPlayerPlaying() -> Bool {\n \n // player.playbackStateは信頼出来ないので、\n // AVAudioSessionで再生状況を調べる\n let av = AVAudioSession.sharedInstance()\n return av.otherAudioPlaying\n }\n \n```\n\nこんな感じで、AVAudioSessionのレベルで音声が再生されているかどうかをチェックすることが可能です。\n\nただし、AVAudioSessionのレベルで音声の再生状況を取得するようにした場合、\n**MPMusicPlayerControllerPlaybackStateDidChangeNotificationが送られてきても、その時点では、AVAudioSessionの再生状況に反映されてない**\nという問題が発生するため、MPMusicPlayerControllerからの通知を使ってる場合は、その部分で何らかの処理が必要になります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T10:23:55.810", "id": "11313", "last_activity_date": "2015-06-13T10:23:55.810", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7459", "parent_id": "11304", "post_type": "answer", "score": 1 } ]
11304
11313
11313
{ "accepted_answer_id": "11308", "answer_count": 1, "body": "時間を指定(7時、12時、21時)してNotificationを発行しようと以下のコードを書きました。しかし、コードのsetNotificationAlarmが呼ばれる瞬間にNotificationがでてきてしまい困っております。どこを直せば良いかわかりますか?\n\n補足: \nメソッドがOverrideされているのは別に用意されたFragmentでNotificationの設定を変更した時にそのFragmentから呼び出すためです。cancelAlarmメソッドはそのFragmentで設定を変更した時に以前にセットされたAlarmを解除するためのものです。あとこのメソッドはアプリ初回起動時にも呼ばれます。\n\n```\n\n /**\n * Setting alarm for notification.\n */\n @Override\n public void setNotificationAlarm(){\n if (mPref.getBoolean(PreferenceValue.NOTIFY_MORNING, true)){\n Calendar calendar = Calendar.getInstance();\n calendar.set(Calendar.HOUR_OF_DAY, 7);\n calendar.set(Calendar.MINUTE, 0);\n calendar.set(Calendar.SECOND, 0);\n Long startTime = calendar.getTimeInMillis();\n cancelAlarm(MORNING_INTENT);\n setAlarm(startTime, MORNING_INTENT);\n }\n if(mPref.getBoolean(PreferenceValue.NOTIFY_NOON, true)){\n Calendar calendar = Calendar.getInstance();\n calendar.set(Calendar.HOUR_OF_DAY, 12);\n calendar.set(Calendar.MINUTE, 0);\n calendar.set(Calendar.SECOND, 0);\n Long startTime = calendar.getTimeInMillis();\n cancelAlarm(NOON_INTENT);\n setAlarm(startTime, NOON_INTENT);\n }\n if(mPref.getBoolean(PreferenceValue.NOTIFY_NIGHT, true)){\n Calendar calendar = Calendar.getInstance();\n calendar.set(Calendar.HOUR_OF_DAY, 21);\n calendar.set(Calendar.MINUTE, 0);\n calendar.set(Calendar.SECOND, 0);\n Long startTime = calendar.getTimeInMillis();\n cancelAlarm(NIGHT_INTENT);\n setAlarm(startTime, NIGHT_INTENT);\n }\n }\n \n private void setAlarm(Long startTime, String intentKind){\n Intent intent = new Intent(MainActivity.this, NotificationService.class);\n intent.setType(intentKind);\n PendingIntent alarmIntent = PendingIntent.getService(MainActivity.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);\n AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);\n alarmManager.set(AlarmManager.RTC_WAKEUP, startTime, alarmIntent);\n }\n \n private void cancelAlarm(String intentKind){\n Intent intent = new Intent(MainActivity.this, NotificationService.class);\n intent.setType(intentKind);\n PendingIntent alarmIntent = PendingIntent.getService(MainActivity.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);\n AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);\n alarmManager.cancel(alarmIntent);\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T02:43:05.233", "favorite_count": 0, "id": "11306", "last_activity_date": "2015-06-13T04:15:05.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7232", "post_type": "question", "score": 0, "tags": [ "android" ], "title": "alarmmanagerの謎の挙動", "view_count": 306 }
[ { "body": "既に当日の7時を過ぎているからではないでしょうか。 \n`calendar.getTimeInMillis() < System.currentTimeMillis()`の場合には、 \n`calendar.getTimeInMillis() + 24 * 60 * 60 * 1000`の値を渡す必要があると思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T04:15:05.343", "id": "11308", "last_activity_date": "2015-06-13T04:15:05.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10126", "parent_id": "11306", "post_type": "answer", "score": 2 } ]
11306
11308
11308
{ "accepted_answer_id": null, "answer_count": 0, "body": "Railsでwebサービスの開発を行っているものです。\n\n現在ユーザの管理全般にはDeviceを使用しているのですが、 \nユーザがログインした後、あまり時間が立たないうちユーザがログアウト状態になってしまいます。\n\nDeviseでログインしたユーザのログイン持続時間を伸ばすのに良い方法はないでしょうか。 \nまた、omniauthでfacebookログインも対応しているのですが、そちらも同じようにログイン持続時間を伸ばしたいと思っています。\n\n同じような経験があるかたなどいらっしゃいましたら、教えていただければ幸いです。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T03:24:52.240", "favorite_count": 0, "id": "11307", "last_activity_date": "2015-06-13T03:24:52.240", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10125", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "devise" ], "title": "RailsのDeviceを用いてログインしたユーザのログイン持続時間を増やしたい", "view_count": 428 }
[]
11307
null
null
{ "accepted_answer_id": null, "answer_count": 0, "body": "Android4.x(chrome)\nでフリック実装しようとするとtouchstartかtouchmove内にpreventDefault()で機能を止めなくてはいけないのですが、 \nフリックする箇所がclickやscrollが利いているところなので、それを入れると今度は「クリックできない」「スクロールできない」と機能が失われます。。\n\n![ここのリスト型コンテンツの上でフリックしたいのだが、それを実装するにはtuchstart時にpreventDefaultでclickをなしにしないといけない。もしくはtouchmove時\\(scrollできなくなる\\)全てが共存する方法がしりたい](https://i.stack.imgur.com/4prI4.png)\n\nソースコードはこちらです。。 \n[Github:\n231行目です](https://github.com/kenjimorita/-study_javascript/blob/784e0a8fe703a6cd6ce7342a027ad8d0a2918ca3/newsto2/src/js/flick.js)\n\nフリックと", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T05:46:02.007", "favorite_count": 0, "id": "11310", "last_activity_date": "2015-06-13T05:46:02.007", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10127", "post_type": "question", "score": 1, "tags": [ "javascript", "android" ], "title": "Android4.x (chrome)でpreventDefaultとフリックを共存させるにはどうしたらいいのですか?", "view_count": 132 }
[]
11310
null
null
{ "accepted_answer_id": "11347", "answer_count": 1, "body": "C#からAndroid上の自作DLL経由でファイル内のある部分のバイナリーデータを取得するサンプルを作っています。\n\n下記ソースのfpはファイルポインタになっていて、ファイルの中身は10個のファイルのバイナリーが敷き詰められています。\n\n**■質問** \nファイル内のファイル5のデータとファイル6のデータの間にNULLがなかった場合、 \nファイルのオフセット位置をファイル5にしてファイルポインタを返すと \nオフセット位置以降のすべてのバイナリーがC#側に返るのでしょうか?\n\n現在テストしているとすごい数のバイト配列になっているので、 \nファイルの末端までのバイト配列が返っているのではないかと思っています。\n\nオフセット位置を指定して次のデータまでのバイト配列を返してもらうには \nデータ間にNULLがあれば良いのか、改行コードをいれるのか、 \nサイズ指定してmemcpyしたバッファを返せば良いのか \n調べているのですが答えにたどり着けません。\n\n**●C#**\n\n```\n\n [DllImport (\"ReadFile\")]\n private static extern byte[] GetFileMemory(int offset);\n \n```\n\n**●C++**\n\n```\n\n extern \"C\"{\n const char** GetFileMemory(int offset);\n }\n \n const char** GetFileMemory(int offset)\n {\n fseek(fp, offset, SEEK_SET);\n \n return (const char**)fp;\n }\n \n```", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-13T07:17:56.680", "favorite_count": 0, "id": "11311", "last_activity_date": "2015-06-15T01:36:21.110", "last_edit_date": "2015-06-13T10:47:01.847", "last_editor_user_id": "8000", "owner_user_id": "5261", "post_type": "question", "score": 1, "tags": [ "c#", "c++", "pinvoke" ], "title": "C++からC#へファイルポインタを返した時、ファイル終端までのデータが返る?", "view_count": 1461 }
[ { "body": "まず、 `fopen()` した時点では **ファイルの中身は読み込んでいません** 。実際にデータを読み取るためには、自分で確保したバッファを\n`fread()` 等に渡します。これを必要なサイズ or EOF に到達するまで繰り返すことになります。このあたりはまず C\n言語等の資料を参考にしてください。\n\n次に C# 側にマーシャリングするわけですが、C#側で管理される `byte[]` 型にする以上、その **配列全体をマネージヒープ上にコピー**\nしなければなりません。となるとサイズの情報が必要になりますが、C言語のポインタにはそんなものありませんから、\n\n * (確認していませんが)`MarshalAsAttribute.SizeConst` でサイズを指定しておく\n * `IntPtr` で受け取って `Marshal.Copy` する\n * C#側から `byte[]` を渡して、そこにC側でセットしてもらう\n\nなどのアプローチをとる必要があります。\n\n参考\n\n * [配列に対する既定のマーシャリング](https://msdn.microsoft.com/ja-jp/library/z6cfh6e6\\(v=vs.110\\).aspx)\n * [c# - Can IntPtr be cast into a byte array without doing a Marshal.Copy? - Stack Overflow](https://stackoverflow.com/a/9733059/2818869)\n\nなお、質問に提示された宣言でどのようなマーシャリングが行われたのか定かではありませんが、ヌル終端の文字列もしくは SafeArray\nとして扱われたのかなと考えています。\n\n>\n> Heap領域が1度膨れ上がるとアプリを落とすまで解放されないので、C++側(ネイティブ側)でリソースファイルを管理‌​しC#側のHeapに載らないようにしてます。\n\n今回の場合、いずれにせよ `byte[]` がマネージヒープに載るわけですし、 `Stream` クラスを使えば C#\nでもファイルの一部分だけを読み取ることができますが、それでも甲斐はあるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T01:31:15.873", "id": "11347", "last_activity_date": "2015-06-15T01:36:21.110", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "8000", "parent_id": "11311", "post_type": "answer", "score": 5 } ]
11311
11347
11347
{ "accepted_answer_id": "11317", "answer_count": 2, "body": "某所で \n`p = malloc(n*sizeof(Type));` \n... \n`p = realloc(p, ++n*sizeof(Type));` \n... \n`free(p);` \nのようなコード(実際のコードではありません)を見かけたんですが、 \n(今取り上げたい)問題はnが0から始まるってことです。 \n`malloc(0)`?と思ったので、ちょっと調べて見ました。 \nC99のドラフトによると、\n\n> 7.20.3 Memory management functions 1 \n> ... If the size of the space requested is zero, the behavior is \n> implementationdefined: either a null pointer is returned, or the \n> behavior is as if the size were some nonzero value, except that the \n> returned pointer shall not be used to access an object.\n\n私の(貧弱な英語力での解釈、間違ってたら指摘下さい、*以下同様)理解する所では、 \n「もしサイズに0が要求された場合の動作は処理系定義であり、 \nNULLポインタ または オブジェクトメモリブロックとしてはアクセスできないような非ゼロのポインタが返される。」 \nまた、freeの動作は、\n\n> The free function causes the space pointed to by ptr to be \n> deallocated, that is, made available for further allocation. If ptr is \n> a null pointer, no action occurs. Otherwise, if the argument does not \n> match a pointer earlier returned by the calloc, malloc, or realloc \n> function, or if the space has been deallocated by a call to free or \n> realloc, the behavior is undefined.\n\n「freeはポインタで指す領域を開放する。ポインタがNULLの場合は何もしない、ポインタがmalloc,calloc,reallocで返されたポインタでない場合、またはfree,reallocによって既に解放された領域の場合の動作は未定義」\n\nそして、realloc の動作\n\n> The realloc function deallocates the old object pointed to by ptr and \n> returns a pointer to a new object that has the size specified by size. \n> The contents of the new object shall be the same as that of the old \n> object prior to deallocation, up to the lesser of the new and old \n> sizes. Any bytes in the new object beyond the size of the old object \n> have indeterminate values. \n> If ptr is a null pointer, the realloc \n> function behaves like the malloc function for the specified size. \n> Otherwise, if ptr does not match a pointer earlier returned by the \n> calloc, malloc, or realloc function, or if the space has been \n> deallocated by a call to the free or realloc function, the behavior is \n> undefined. If memory for the new object cannot be allocated, the old \n> object is not deallocated and its value is unchanged.\n\n「realloc関数は古い領域を開放し指定されたサイズの新しい領域を指すポインタを返す。…もしもポインタがNULLの場合にはmallocの様に動作する。もしポインタがmalloc,calloc,reallocで返されたポインタでない場合、またはfree,reallocによって既に解放された領域の場合の動作は未定義。…」\n\nということで前置きが長くなりましたが、 \n`malloc(0)`の場合、NULLまたは、使用不能の非ゼロポインタが返される(どちらが返されるかは処理系定義である) \nということで、 \n`malloc(0)`が`NULL`を返した場合には特に問題は無いと思います。 \n**私が気になったのは、「使用不能の非ゼロポインタが返される」の場合。** \nfreeは、mallocが返した値のポインタを解放する、とあって問題ないけれども、 \nrealloc は、「使用不能の非ゼロポインタが返されたの場合」について動作が既定されていないように思う。 \n個人的には`NULL`の場合と同様の動作をするとすべきと思うがそこには含まれていない。 \n(新しい領域が確保された際にfreeされるという動作?) \nmalloc系の返値以外の場合は未定義とすることから暗にmalloc系の返値は受け入れるという主張があるとも言えると思うけども・。\n\nというか、 \n「NULLまたは、使用不能の非ゼロポインタが返される(どちらが返されるかは処理系定義である)」 \nではなく \nそもそも「サイズ0が指定された場合の動作が処理系定義」であって、だから書いていない?\n\n詳しい人論拠と共にどう考えるべきか(あるいは解釈が違う、別のところにこういう記述があるなど…)教えて下さい。", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T00:43:35.527", "favorite_count": 0, "id": "11315", "last_activity_date": "2015-06-14T01:36:21.457", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5044", "post_type": "question", "score": 7, "tags": [ "c" ], "title": "malloc(0)のreallocの挙動", "view_count": 1304 }
[ { "body": "実際[Visual C++のmalloc](https://msdn.microsoft.com/ja-\njp/library/6ewkz86d.aspx)は後者の実装になっているようですね。\n\n> size が 0 の場合、malloc 関数はヒープに長さが 0 のアイテムを割り当て、そのアイテムへの有効なポインターを返します。\n\nreallocの第1引数は「アクセスできないような非ゼロのポインタ」だとしても「malloc,calloc,reallocで返されたポインタ」は満たしているわけですから問題ないように思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T01:20:28.663", "id": "11316", "last_activity_date": "2015-06-14T01:20:28.663", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "11315", "post_type": "answer", "score": 4 }, { "body": "もうすこし正確に翻訳してみました。\n\n> either a null pointer is returned, or the behavior is as if the size \n> were some nonzero value, except that the returned pointer shall not be \n> used to access an object. \n> \n> NULLポインタを返すか、もしくは返されたポインタがオブジェクトへのアクセスに使えないことを除けば、サイズに0以外が要求されたように動作する。\n\nアクセスできないこと以外は`malloc`の引数に0以外のサイズを渡したときの戻り値と同じと言っているわけですから、`realloc`の引数に渡すことはなんの問題もありません。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T01:36:21.457", "id": "11317", "last_activity_date": "2015-06-14T01:36:21.457", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3639", "parent_id": "11315", "post_type": "answer", "score": 6 } ]
11315
11317
11317
{ "accepted_answer_id": "11349", "answer_count": 3, "body": "まず、自サイトにgoogle maps api v3\nを使って地図を表示させ、ユーザーに自由に場所やズームレベルを変更してもらいます(※この時、地図上にマーカーを付けたり、ストリートビューに変更することも可能とします)。\n\nそして、好きなタイミングでブラウザ上の「OK」ボタンを押すと、その地図をキャプチャして画像として取得する。というようなことをしたいのですが、この地図→画像変換をする良い方法が見つからずに困っております。。。最終的にはその画像をcanvasの背景画像として使用したいのですが、どなたか良い変換方法をご存知の方おられませんでしょうか?\n\n宜しくお願いします。\n\n【捕捉】\n\n無理にキャプチャではなくても、たとえばKMLなどの形式で外部出力する方法でも構いません。\n\n要件は、ユーザーが任意に変換させた地図情報を、(再度、サイトを開き直した時に)まったく同じ状態で再現出来ればそれでもOKです。\n\n動的マップ→静的マップの完全変換などでも、情報お持ちの方おられたは、是非お願いしますm(__)m", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T02:19:06.047", "favorite_count": 0, "id": "11319", "last_activity_date": "2015-06-15T03:21:53.300", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10130", "post_type": "question", "score": 1, "tags": [ "javascript" ], "title": "google maps api v3 を使って描画した地図をキャプチャする方法", "view_count": 1251 }
[ { "body": "> 無理にキャプチャではなくても、たとえばKMLなどの形式で外部出力する方法でも構いません。 \n> 要件は、ユーザーが任意に変換させた地図情報を、(再度、サイトを開き直した時に)まったく同じ状態で再現出来ればそれでもOKです。\n\ngoogle map api v3\nの状態をDB等に保存して、再度サイトを開き直した時にDBからapiにセットし直せば、地図を再現できるのではないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T20:52:08.150", "id": "11339", "last_activity_date": "2015-06-14T20:52:08.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9529", "parent_id": "11319", "post_type": "answer", "score": 1 }, { "body": "> 動的マップ→静的マップの完全変換などでも、情報お持ちの方おられたは、是非お願いします\n\ngoogle map api v3 の属性を使って、google static api v2 のURLを生成するのではどうでしょうか?\n\n参考サイト \n<https://developers.google.com/maps/documentation/staticmaps/> \n<http://syncer.jp/how-to-use-google-static-maps-api>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T20:56:24.413", "id": "11340", "last_activity_date": "2015-06-14T20:56:24.413", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9529", "parent_id": "11319", "post_type": "answer", "score": 1 }, { "body": "APIを経由しない使い方は利用規約違反になると思います。\n\n<https://developers.google.com/maps/terms>の10.1.3\n\nその為、地図の状態をGoogle MapsのAPIから取得して記録しなければなりません。\n\nページを閉じるときやリロードするときに現在の地図の中心座標とズームレベルをAPIで取得してlocalStorageに保存します。JavaScriptのonunloadイベントを使ってください。\n\nページを開いた時はJavaScriptのonloadイベントを使ってlocalStorageのデータを取得し地図に設定してください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T02:15:30.243", "id": "11349", "last_activity_date": "2015-06-15T03:21:53.300", "last_edit_date": "2015-06-15T03:21:53.300", "last_editor_user_id": "10022", "owner_user_id": "10022", "parent_id": "11319", "post_type": "answer", "score": 1 } ]
11319
11349
11339
{ "accepted_answer_id": "11450", "answer_count": 1, "body": "Python C/C++ APIで下記のようにforで0から引数としてとった整数までを表示させる物を書いているのですが、Ctrl-\nCを押しても割り込んで処理を停止させることができません。 \n9999999まで表示した後でKeyboardInterruptが出てしまいます。 \nどうすればいいのでしょうか? \nちなみにコンパイルは`python3 setup.py build_ext -i`でやっています。\n\n環境はOS X 10.10, Python3.4.3です\n\n```\n\n \n #include <iostream>\n #include <Python.h>\n \n static PyObject*\n for_int(PyObject *self, PyObject *args)\n {\n int x;\n \n if (!PyArg_ParseTuple(args, \"i\", &x))\n return NULL;\n for (int i=0; i<x; i++) {\n std::cout << i << \"\\n\";\n }\n Py_INCREF(Py_None);\n return Py_None;\n \n }\n \n static PyMethodDef For_INT_Methods[] = {\n {\"for_int\", for_int, METH_VARARGS,\n \"fast increment print\"}, \n {NULL, NULL, 0 , NULL}\n };\n \n static struct PyModuleDef for_int_module = {\n PyModuleDef_HEAD_INIT,\n \"for_int\",\n \"spam_doc_string\",\n -1,\n For_INT_Methods\n };\n \n PyMODINIT_FUNC\n PyInit_for_int(void)\n {\n PyObject *m;\n \n m = PyModule_Create(&for_int_module);\n if (m == NULL)\n return NULL;\n Py_INCREF(PyExc_KeyboardInterrupt);\n PyModule_AddObject(m, \"InterruptError\", PyExc_KeyboardInterrupt);\n return m;\n }\n \n \n int\n main(int argc, char *argv[])\n {\n PyImport_AppendInittab(\"for_int\", PyInit_for_int);\n Py_Initialize();\n PyImport_ImportModule(\"for_int\");\n }\n \n \n```\n\nコンパイルするためのsetup.py\n\n```\n\n \n from distutils.core import setup, Extension\n module = Extension('for_int', ['for.cpp'])\n setup(name='for',\n version='1.0',\n ext_modules=[module],\n )\n \n \n \n```\n\n**追記** \nforの部分でPyErr_CheckSignals()を呼び出すようにしました(code2) \nしかし、Ctrl-Cを押しても処理は止まりませんでした。\n\ncode2\n\n```\n\n \n for (int i=0; i<x; i++) {\n PyErr_CheckSignals(); # 追加\n std::cout << i << \"\\n\";\n }\n \n \n```", "comment_count": 9, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T02:19:34.860", "favorite_count": 0, "id": "11320", "last_activity_date": "2015-06-17T17:13:37.073", "last_edit_date": "2015-06-17T11:17:43.973", "last_editor_user_id": "5246", "owner_user_id": "5246", "post_type": "question", "score": 1, "tags": [ "python", "c++", "c" ], "title": "Python C/C++ APIでKeyboardInterruptで処理を停止できない", "view_count": 4950 }
[ { "body": "[例外処理 —— Python 3.4.3ドキュメント](http://docs.python.jp/3/c-api/exceptions.html)\nによると (強調は引用者による)、\n\n>\n> ある関数が呼び出した関数がいくつか失敗したために、その関数が失敗しなければならないとき、一般的にエラーインジケータを設定しません。呼び出した関数がすでに設定しています。\n> **エラーを処理して例外をクリアするか、あるいは(オブジェクト参照またはメモリ割り当てのような)それが持つどんなリソースも取り除いた後に戻るかのどちらか一方を行う責任があります。エラーを処理する準備をしていなければ、普通に続けるべきではありません。**\n> エラーのために戻る場合は、エラーが設定されていると呼び出し元に知らせることが大切です。エラーが処理されていない場合または丁寧に伝えられている場合には、\n> Python/C APIのさらなる呼び出しは意図した通りには動かない可能性があり、不可解な形で失敗するかもしれません。\n\n(最後の一文、「エラーが処理されていなかったり、注意深く伝搬されていなかったりした場合には」の誤訳だと思う -- 閑話休題)\n\nとのことなので、エラーを検知した場合、それを関数内で処理し切ってしまうか、あるいは処理を中止してエラーを伝搬させるかを、関数自身の責任で行わなければなりません。 \nシグナル発生時に中断したいならば、@masm さんがコメントで指摘されているように、 `PyErr_CheckSignals()`\nでシグナル発生をチェックした上で、発生していたらそこで中断するようにします。 \n`for_int()` の定義で、 `PyArg_ParseTuple()` が失敗したら `NULL`\nを返すようになっていますが、これと同様、`PyErr_CheckSignals()` がシグナルの発生を検知したら、`NULL`\nを返して終了するようにします。必要に応じてリソースの解放を行う必要もありますが、今回は不要ですね。\n\n```\n\n static PyObject*\n for_int(PyObject *self, PyObject *args)\n {\n int x;\n \n if (!PyArg_ParseTuple(args, \"i\", &x))\n return NULL;\n for (int i=0; i<x; i++) {\n // シグナルの発生を調べ、発生していたら中断する。\n if (PyErr_CheckSignals() != 0) {\n return NULL;\n }\n std::cout << i << \"\\n\";\n }\n Py_INCREF(Py_None);\n return Py_None;\n \n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-17T17:13:37.073", "id": "11450", "last_activity_date": "2015-06-17T17:13:37.073", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7831", "parent_id": "11320", "post_type": "answer", "score": 2 } ]
11320
11450
11450
{ "accepted_answer_id": null, "answer_count": 0, "body": "なぜこんなことが起こるのか全くわかりませんが、 \n表題のようにボタンがテキスト扱いのようになりクリックすらできなくなります。\n\n```\n\n <ons-button modifier=\"large\" class=\"login-button\" ng-click=\"myNavi.pushPage('test.html', {animation: 'slide', user: user});\">もっとみる</ons-button>\n \n <ons-button modifier=\"large\" class=\"login-button\" ng-click=\"myNavi.pushPage('test.html', {animation: 'slide', user: user});\">もっとみる</ons-button>\n \n```\n\n上記のようにふたつ記述すると下のボタンは必ずクリックできますが、上のボタンは必ずクリックできません。(テキストの上をクリックしているような挙動)\n\nChromeブラウザ、デバッカー、テストビルドで実機も確認しましたが、すべてクリックできませんでした。奇妙なことにChromeブラウザでF12のコンソールを表示させながらだとクリックできるようになります。同じような挙動の例はないか探したのですが見つからず途方に暮れております。。。\n\n何か思い当たることがあれば教えていただけないでしょうか。 \nよろしくおねがいいたします。\n\nonsenui.js version 1.3.0", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T03:47:33.710", "favorite_count": 0, "id": "11322", "last_activity_date": "2015-06-14T03:47:33.710", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10131", "post_type": "question", "score": 1, "tags": [ "onsen-ui" ], "title": "ons-bottunをふたつ配置すると片方のボタンがクリックすらできない", "view_count": 105 }
[]
11322
null
null
{ "accepted_answer_id": "11366", "answer_count": 2, "body": "Vagrant環境にCentOSをインストールし、monitでsidekiqを監視したものの、プロセスの停止は感知できますが、monitからsidekiqを立ち上げることができません(sidekiq\nfaled to startとなる)\n\nなお、monitを使わずに手動でrailsのルートディレクトリに移動した後(cd /var/www/my_app)sidekiqの起動コマンド(bundle\nexec sidekiq --pidfile /var/www/my_app/tmp/pids/sidekiq.pid --logfile\n/var/www/my_app/log/sidekiq.log --daemon)をたたくと起動することができます。\n\nmonitのバージョンと設定ファイルは以下のとおりなのですが、原因がわからず、困っています。\n\n■ バージョン情報\n\n```\n\n $ cat /etc/redhat-release\n CentOS release 6.6 (Final)\n \n $ monit -V\n This is Monit version 5.5\n \n $ sidekiq -V\n Sidekiq 3.3.4\n \n```\n\n■ /etc/monit.conf\n\n```\n\n set daemon 60 \n set logfile /var/log/monit.log\n set statefile /var/monit/state\n set httpd port 2812 and\n use address localhost # only accept connection from localhost\n allow localhost # allow localhost to connect to the server and\n include /etc/monit.d/*\n \n```\n\n■ /etc/monit.d/sidekiq\n\n```\n\n check process sidekiq \n with pidfile /var/www/my_app/tmp/pids/sidekiq.pid\n every 2 cycle\n start program = \"/bin/bash -l -c 'cd /var/www/my_app && bundle exec sidekiq --pidfile /var/www/my_app/tmp/pids/sidekiq.pid --logfile /var/www/my_app/log/sidekiq.log --daemon'\"\n stop program = \"/bin/bash -l -c 'cd /var/www/my_app && bundle exec sidekiqctl stop /var/www/my_app/tmp/pids/sidekiq.pid 10'\"\n \n```\n\n■ monit.log \n[GMT+1 Jun 14 02:57:24] error : 'sidekiq' process is not running \n[GMT+1 Jun 14 02:57:24] info : 'sidekiq' trying to restart \n[GMT+1 Jun 14 02:57:24] info : 'sidekiq' start: /bin/bash \n[GMT+1 Jun 14 02:57:54] error : 'sidekiq' failed to start ← これを解消したい\n\n■ sidekiq.log \n何も出力されない\n\nもし、なにかご存知の方いらっしゃいましたら、ご教示頂ければ幸いです。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T04:21:26.313", "favorite_count": 0, "id": "11323", "last_activity_date": "2015-06-15T06:08:51.107", "last_edit_date": "2015-06-15T03:46:19.900", "last_editor_user_id": "5902", "owner_user_id": "5902", "post_type": "question", "score": 1, "tags": [ "monitoring", "sidekiq" ], "title": "monitでsidekiqの停止を感知できるが、sidekiqを自動起動できない", "view_count": 1343 }
[ { "body": "ターミナルから手動で実行した時には上手く動いて、monitから実行した時には動かないということは、環境の違いにより、起動コマンドがエラーになるからだと思います。monitのデバッグ方法を2つ紹介します。\n\n 1. monitの環境をシュミレートしてデバッグ\n 2. monitの起動コマンドでログを出力\n\n## 1. monitの環境をシュミレートしてデバッグ\n\n```\n\n # monit runs as superuser\n $ sudo su\n \n # the -i option ignores the inherited environment\n # this PATH is what monit supplies by default\n $ env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/sh\n \n # try running start/stop program here\n $ ここであなたのスクリプトを実行\n \n```\n\n## 2. monitの起動コマンドでログを出力\n\nコマンドのラッパースクリプト\n\n```\n\n $ cat monit-wrapper.sh\n \n #!/bin/sh\n {\n echo \"MONIT-WRAPPER date\"\n date\n echo \"MONIT-WRAPPER env\"\n env\n echo \"MONIT-WRAPPER $@\"\n $@\n R=$?\n echo \"MONIT-WRAPPER exit code $R\"\n } >/tmp/monit.log 2>&1\n \n```\n\nmonitの設定\n\n```\n\n start program = \"/path/to/monit-wrapper.sh YOUR-START-SCRIPT AND ARGS\"\n stop program = \"/path/to/monit-wrapper.sh YOUR-STOP-SCRIPT AND ARGS\"\n \n```\n\n参考サイト \n<https://stackoverflow.com/questions/3356476/debugging-monit> \n<http://qiita.com/ogin_s57/items/370743d280ac216bf7c1>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T05:51:51.387", "id": "11364", "last_activity_date": "2015-06-15T06:02:56.140", "last_edit_date": "2017-05-23T12:38:56.467", "last_editor_user_id": "-1", "owner_user_id": "9529", "parent_id": "11323", "post_type": "answer", "score": 2 }, { "body": "私が以前にmonitを設定した時は、Rails3+rvm環境だったのですが、その時は switch user してから、起動スクリプトを実行しました。\n\n```\n\n check process delayed_job with pidfile /u/apps/thub/shared/pids/delayed_job.pid\n start program = \"/bin/su - YOUR_APP_USER -c 'cd /path/to/app/current; RAILS_ENV=production script/delayed_job start'\" \n stop program = \"/bin/su - YOUR_APP_USER -c 'cd /path/to/app/current; RAILS_ENV=production script/delayed_job stop'\"\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T06:08:51.107", "id": "11366", "last_activity_date": "2015-06-15T06:08:51.107", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9529", "parent_id": "11323", "post_type": "answer", "score": 1 } ]
11323
11366
11364
{ "accepted_answer_id": "11325", "answer_count": 2, "body": "クローラーを作ろうと思い、webページのリンクを抽出するコードを欠いていたのですが、 \n以下の部分で \"Attribute Error 'tuple' object hano attribute\nfind\"というエラーが出てしまいます。どうすれば回避できるでしょうか \n補足:御助言ありがとうございます。コード全体はこのようになってます。\n\n```\n\n def get_page(page):\n start_link = page.find(\"<a href=\")\n if start_link == -1:\n return None, 0\n start_quote = page.find('\"', start_link)\n end_quote = page.find('\"', start_quote+1)\n url = page[start_quote+1 : end_quote]\n return url, end_quote\n \n \n def all_get_links(page):\n while True:\n url, end_quote = get_page(page)\n if url:\n print(url)\n page = page[end_quote:]\n else:\n break\n \n \n print(all_get_links(get_page(\"http://www.yahoo.co.jp/\")))\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T06:40:14.190", "favorite_count": 0, "id": "11324", "last_activity_date": "2015-06-15T15:04:36.753", "last_edit_date": "2015-06-15T15:04:36.753", "last_editor_user_id": "2901", "owner_user_id": "9597", "post_type": "question", "score": 1, "tags": [ "python" ], "title": "pythonでのwebページのリンク抽出について", "view_count": 1225 }
[ { "body": "get_pageがtupleを返しているからではないでしょうか? \n`get_page`は`(url, end_quote)`のtupleを返しています。 \n最後の行でget_pageが返したtupleを引数にall_get_linksを呼んでいますが、そうなるとall_get_linksの引数のpageはtupleになってしまい、tupleにfindメソッドがないのでこのようなエラーが出ています。\n\nこのエラーは`tupleにはfindという属性がありません`という意味です。\n\n追記: 最後の行のget_pageの引数が`http://www.yahoo.co.jp/`なのでpage.findは`<a href=`という文字列を\n**見つけられません** 。(`http://www.yahoo.co.jp/`の中に`<a href=`という文字列は含まれていない)\nそのため返ってくるtupleは必ず`(None, 0)`になってしまいます。これを回避するためにはget_pageに渡す文字列には、きちんとした a tag\nが含まれるようにしてください。\n\n追記2: \n下記のような感じにするのはいかがでしょうか?\n\n```\n\n \n def get_page(page):\n start_link = page.find(\"<a href=\")\n if start_link == -1:\n return None\n start_quote = page.find('\"', start_link)\n end_quote = page.find('\"', start_quote+1)\n url = page[start_quote+1 : end_quote]\n print(url)\n return page[end_quote:]\n \n def all_get_links(page):\n while True:\n page = get_page(page)\n if page == None:\n break\n \n page = '<a href=\"http://rebuild.fm\">Rebuild.fm</a>'\n all_get_links(page) # http://rebuild.fm と表示される\n \n \n```\n\nこのやり方だとget_pageは文字列かNoneを返すようになります。Noneを返した場合、すぐにbreakして、whileから抜けるのでエラーにはなりません。Noneではない場合は必ず文字列を返すので、最初のようなエラーは起こりません。\n\n他のやり方として、html.parserのHTMLParserクラスを継承して使うのがいいと思います。 \n例としては下記のような感じでしょうか\n\n[20.2. html.parser— HTML および XHTML のシンプルなパーサー — Python 3.4.3\nドキュメント](http://docs.python.jp/3/library/html.parser.html)\n\n```\n\n \n from html.parser import HTMLParser\n \n class MyParser(HTMLParser):\n def handle_starttag(self, tag, attrs):\n attrs_dict = dict(attrs)\n if tag == \"a\":\n print(attrs_dict[\"href\"]) #hrefの内容を表示\n \n \n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T06:56:01.177", "id": "11325", "last_activity_date": "2015-06-15T14:30:16.663", "last_edit_date": "2015-06-15T14:30:16.663", "last_editor_user_id": "5246", "owner_user_id": "5246", "parent_id": "11324", "post_type": "answer", "score": 2 }, { "body": "最近、あまり使っていないのですが、昔、HTMLパーシングには、[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/bs4/doc/)をよく使っていました。\n\n```\n\n from bs4 import BeautifulSoup\n \n soup = BeautifulSoup(html_data)\n links = []\n for link in soup.find_all(\"a\"):\n if hasattr(link, \"href\"):\n links.append(link.attrs.get(\"href\"))\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T05:05:10.493", "id": "11362", "last_activity_date": "2015-06-15T05:05:10.493", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2314", "parent_id": "11324", "post_type": "answer", "score": 0 } ]
11324
11325
11325
{ "accepted_answer_id": "11327", "answer_count": 1, "body": "以下のコードを書きましたが、エラーになってしまいます。 \n$maxResultと$pageにはデータが入っていることが確認できています。さらに、パラメータを指定せずにリクエストを送るとデータを取得できます。どこが間違っているかわかりますか?\nよろしくお願いします。\n\n```\n\n if(isset($_GET['maxResult']))\n $maxResult = $_GET['maxResult'];\n if(isset($_GET['page']))\n $page = $_GET['page'];\n $st = $pdo->prepare(\"SELECT * FROM `hogehoge` ORDER BY `id` DESC LIMIT :page, :limit\");\n $st->bindValue(\":page\", $page, PDO::PARAM_INT);\n $st->bindValue(\":limit\", $maxResult, PDO::PARAM_INT);\n if($st->execute()){\n echo json_encode($st->fetchAll(PDO::FETCH_ASSOC));\n }else{\n sendError(\"failure\");\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T09:25:14.557", "favorite_count": 0, "id": "11326", "last_activity_date": "2015-06-14T12:40:17.067", "last_edit_date": "2015-06-14T12:40:17.067", "last_editor_user_id": "3639", "owner_user_id": "7232", "post_type": "question", "score": -1, "tags": [ "php", "mysql", "pdo" ], "title": "PDOのLIMITでエラー", "view_count": 393 }
[ { "body": "以前同じ挙動でハマった事がありますが、LIMIT句へのバインドは整数型でなければならなかったはずです。 \nPDO::PARAM_INTも必要ですが、$_GETや$_POSTで取得したパラメータは文字列として変数に格納されますので、\n\nbindValue(\":page\", (int)$page,\nPDO::PARAM_INT)やintvalを使って整数型へキャストさせると取得出来るかと思われます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T10:35:33.687", "id": "11327", "last_activity_date": "2015-06-14T10:35:33.687", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4271", "parent_id": "11326", "post_type": "answer", "score": 1 } ]
11326
11327
11327
{ "accepted_answer_id": null, "answer_count": 1, "body": "GoogleサンプルのMediaEffectを使って、OpenGLを動かしてみようと思いAndroid\nStudioでRUNしたところ以下のようなエラーがでてRUNしなくなりました。 \nたしか最初にRUNしたときは動いていたのですが。。 \nどうしたらいいか教えてください。\n\n```\n\n 06-14 10:57:47.178 7085-7085/? I/art﹕ Not late-enabling -Xcheck:jni (already on)\n 06-14 10:57:47.257 7085-7085/com.example.android.mediaeffects I/MainActivity﹕ Ready\n 06-14 10:57:47.281 7085-7101/com.example.android.mediaeffects D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true\n 06-14 10:57:47.284 7085-7085/com.example.android.mediaeffects D/﹕ HostConnection::get() New Host Connection established 0xb42b3ef0, tid 7085\n 06-14 10:57:47.307 7085-7085/com.example.android.mediaeffects D/Atlas﹕ Validating map...\n 06-14 10:57:47.351 7085-7101/com.example.android.mediaeffects D/﹕ HostConnection::get() New Host Connection established 0xb43d6240, tid 7101\n 06-14 10:57:47.365 7085-7101/com.example.android.mediaeffects I/OpenGLRenderer﹕ Initialized EGL, version 1.4\n 06-14 10:57:47.417 7085-7101/com.example.android.mediaeffects D/OpenGLRenderer﹕ Enabling debug mode 0\n 06-14 10:57:47.445 7085-7101/com.example.android.mediaeffects W/EGL_emulation﹕ eglSurfaceAttrib not implemented\n 06-14 10:57:47.445 7085-7101/com.example.android.mediaeffects W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb431e160, error=EGL_SUCCESS\n 06-14 10:57:47.528 7085-7100/com.example.android.mediaeffects D/﹕ HostConnection::get() New Host Connection established 0xb42b3cf0, tid 7100\n 06-14 10:57:47.542 7085-7100/com.example.android.mediaeffects E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 172\n Process: com.example.android.mediaeffects, PID: 7085\n java.lang.IllegalArgumentException: No config chosen\n at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:869)\n at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1023)\n at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1400)\n at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T11:04:52.550", "favorite_count": 0, "id": "11328", "last_activity_date": "2015-06-15T13:33:21.247", "last_edit_date": "2015-06-14T11:21:09.597", "last_editor_user_id": "3639", "owner_user_id": "5818", "post_type": "question", "score": 0, "tags": [ "android", "android-studio", "opengl-es" ], "title": "OpenGLでエラー", "view_count": 1267 }
[ { "body": "自己レスとなります。 \n実機を接続したらこのエラーは発生しませんでした。 \nよって、AVD Managerからエミュータを起動したときの話となります。 \nとりあえずは実機でやってみます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-15T13:33:21.247", "id": "11373", "last_activity_date": "2015-06-15T13:33:21.247", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5818", "parent_id": "11328", "post_type": "answer", "score": 1 } ]
11328
null
11373
{ "accepted_answer_id": "11332", "answer_count": 1, "body": "phpでJSON形式のデータを吐き出すプログラムをつくりました。 \nこれをObjective-Cから取得しようと思っているのですが、うまくいきません。 \nURLの部分を、東京電力電力供給状況API(<http://tepco-usage-\napi.appspot.com/latest.json>)に変更すると、正常に取得できているようですが、自作のJSONデータではnullが返ってきます。 \nウェブ方面にお詳しい方、ご教授願います。\n\n```\n\n NSString *urlString = @\"http://kokun.sakura.ne.jp/tutor/JSONTest.php\";\n NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];\n NSData *json = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];\n NSArray *array = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingAllowFragments error:nil];\n NSLog(@\"%@\",array);\n \n```\n\n【追記】 \n以下はJSON形式のデータを吐き出すphpプログラムの全文です。\n\n```\n\n <html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <title>JSONTest</title>\n </head>\n <body>\n <?php\n $array = array(\n \"name\" => \"shou\",\n \"date\" => \"2015-06-14 19:53:00\",\n \"content\" => \"hello world\",\n );\n $json = json_encode($array);\n echo $json;\n ?>\n \n </body>\n </html>\n \n```", "comment_count": 7, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T11:47:11.907", "favorite_count": 0, "id": "11329", "last_activity_date": "2015-06-14T14:07:15.277", "last_edit_date": "2015-06-14T14:07:15.277", "last_editor_user_id": "3639", "owner_user_id": "7699", "post_type": "question", "score": 1, "tags": [ "php", "objective-c", "json" ], "title": "Objective-CでJSONの取得がうまくいかない", "view_count": 765 }
[ { "body": "JSONTest.phpの中のHTMLコードは不要なので全部消してください。 \nphpファイルの中身はこれだけでOKです。\n\n```\n\n <?php\n \n $array = array(\n \"name\" => \"shou\",\n \"date\" => \"2015-06-14 19:53:00\",\n \"content\" => \"hello world\",\n );\n \n $json = json_encode($array);\n header(\"Content-type: application/json\");\n echo $json;\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T14:06:52.833", "id": "11332", "last_activity_date": "2015-06-14T14:06:52.833", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3639", "parent_id": "11329", "post_type": "answer", "score": 3 } ]
11329
11332
11332
{ "accepted_answer_id": "11754", "answer_count": 1, "body": "railsでgeneratorsを利用するために以下のgemを追加しました。\n\n```\n\n gem 'sprockets'\n gem 'sprockets-es6', require: 'sprockets/es6'\n gem 'browserify-rails'\n \n```\n\nこれで、`aseets/javascripts/`ディレクトリに`*.es6`ファイルを作成することで \nes6のコードを記述することで動作することを確認できました。\n\nしかしgeneratorsを利用しようとすると以下のエラーが発生します。\n\n```\n\n ReferenceError: Can't find variable: regeneratorRuntime\n \n```\n\nなにかsprockets-\nes6はbabelを利用しているようなので、generatorsもサポートされていると思うのですが、何かランタイムが必要なのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T13:12:49.413", "favorite_count": 0, "id": "11331", "last_activity_date": "2015-06-26T05:12:03.463", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5840", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "ecmascript-6" ], "title": "rails4でECMAScript6を利用するためにsprockets-es6を導入したがgeneratorsが利用できない", "view_count": 470 }
[ { "body": "ドキュメントには書かれていないようですが、babel の polyfill をロードする必要があるようです。\n\n`application.js` に下記の記述を加えたら動作しました。\n\n```\n\n //= require babel/polyfill\n \n```\n\n * rails 4.2.1\n * sprockets 3.2.0\n * sprockets-es6 0.6.2\n * browserify-rails 1.0.1", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-26T05:12:03.463", "id": "11754", "last_activity_date": "2015-06-26T05:12:03.463", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5789", "parent_id": "11331", "post_type": "answer", "score": 2 } ]
11331
11754
11754
{ "accepted_answer_id": null, "answer_count": 5, "body": "友人に頼まれてVS2010でC#.netでプログラムを組みました。 \n私のPCでは問題なく動作するのですが、同じwindows7の友人のPCで起動すると\n\n問題が発生したため、プログラムが正しく動作しなくなりました。プログラムは閉じられ、解決策がある場合はwindowsから通知されます。というメッセージが現れます。 \n![画像の説明をここに入力](https://i.stack.imgur.com/bNOJv.png)\n\nどこにどのようにすれば正常動作させることができるか思い当たる方はいらっしゃらないでしょうか? \n友人への受け渡しにレンタルサーバにexeファイルを圧縮したzipファイルをアップロードしてそれをダウンロードする形で渡したのですが、そういった渡し方が何かのセキュリティに引っかかったのではないかとも考えています。\n\nよろしくおねがいします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T14:54:02.747", "favorite_count": 0, "id": "11333", "last_activity_date": "2015-07-24T00:05:50.580", "last_edit_date": "2015-06-14T22:47:50.777", "last_editor_user_id": "2238", "owner_user_id": "8823", "post_type": "question", "score": 1, "tags": [ "windows", ".net", "visual-studio" ], "title": "visual studioで作ったプログラムが起動できない。", "view_count": 41227 }
[ { "body": "プログラムのエラー処理がなされていない場合に表示されるダイアログです。 \n自分のPCで動作するのは偶然なだけですので、きちんとエラー処理を行いましょう。どのようなエラーが発生しているのかはプログラム自身、および作者のあなたにしかわかりません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T23:34:10.193", "id": "11341", "last_activity_date": "2015-06-14T23:34:10.193", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "11333", "post_type": "answer", "score": 1 }, { "body": "【よくある可能性】\n\n * 必要なライブラリ(DLL)が不足しているか、バージョンが異なる。\n * .NET Frameworkのバージョンが古い、または、破損している。\n * 必要なアクセス権限が不足している。ファイルを書き込みできない等。\n * セキュリティソフトの影響を受けている。\n\n【解決策】 \n**参照しているライブラリのバージョンに矛盾がないか確認する。** \n\n```\n\n hoge.exe --- piyo.dll ver 1.0.1.0\n fuge.dll --- piyo.dll ver 1.0.0.9\n \n```\n\nこのような構成になっている場合、piyo.dllのバージョン違いによる影響を受けることがあります。 \nfuge.dllがpiyo.dll ver 1.0.1.0を参照するように修正する必要があります。\n\n**可能であれば、ログを確認してもらう**\n\n.NET アプリケーションが不正終了した場合、 **管理ツール→イベントビューア** の **Windowsログ→アプリケーション**\nにて例外を確認できます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-06-14T23:58:59.227", "id": "11342", "last_activity_date": "2015-06-14T23:58:59.227", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2207", "parent_id": "11333", "post_type": "answer", "score": 2 }, { "body": "一番ありそうな原因は、他の方の回答にあるようなライブラリや必要なファイルが無い、 \nといったものですが、ほかにも「そもそもプログラムにバグがある」可能性もあります。\n\nたとえば\n\n * あなたのパソコン固有のフォルダやファイルが無いと動かない仕組みではないか。\n * 特定のアプリやデータが無いと動かない仕組みではないか。\n\nといったあたりを確認されてみてはどうでしょうか? \n(これをバグと呼ぶかどうかは微妙かもしれませんが、期待通りに動かない原因、 \nという意味では広義のバグでしょう)\n\n一番手っ取り早いのは、きちんとしたエラー処理を行い、どんなエラーが出ているか \n具体的に突き止める手段をプログラムに付け加えることです。エラーが起きたら、 \nその内容やその時のデータをテキストファイルに出力するようなエラー処理を追加し、 \n改めてご友人のPCで動かしてもらう、というのが手っ取り早いかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-07-15T06:13:31.110", "id": "12373", "last_activity_date": "2015-07-15T06:13:31.110", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10538", "parent_id": "11333", "post_type": "answer", "score": 0 }, { "body": "あくまで可能性ですが、「プログラム中でDLLの動的読み込みを行っていて」「ロードするDLLが『他のコンピューターから取得されたファイル』とマークされている」場合はDLLの読み込みに失敗します。\n\n![画像の説明をここに入力](https://i.stack.imgur.com/inbRl.png)\n\nファイルを圧縮せずに配布したり、ZIPファイルをエクスプローラーで解凍しているような場合はセキュリティフラグが立ちますのでご確認ください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-07-15T21:57:07.770", "id": "12400", "last_activity_date": "2015-07-15T21:57:07.770", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5750", "parent_id": "11333", "post_type": "answer", "score": 0 }, { "body": "みなさんありがとうございました。 \nエラー処理をしていないというのはその通りでちゃんとエラー処理をするのが本来なのですが、部分的に自分で作っていない部分もありすべてを理解して作り直すのが困難であったため、動かしたいPCにVSを入れてそちら側でビルドすることで動かしました。\n\n皆さんありがとうございました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-07-24T00:05:50.580", "id": "12632", "last_activity_date": "2015-07-24T00:05:50.580", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8823", "parent_id": "11333", "post_type": "answer", "score": 0 } ]
11333
null
11342