question
dict | answers
list | id
stringlengths 2
5
| accepted_answer_id
stringlengths 2
5
⌀ | popular_answer_id
stringlengths 2
5
⌀ |
---|---|---|---|---|
{
"accepted_answer_id": "17159",
"answer_count": 3,
"body": "以下のような(idが数値から始まっている)無効なid属性を含むページがあるとします。\n\n```\n\n <div id=\"1\">HELLO</div>\n \n```\n\nこのページ内でChrome DevToolsを起動して「Elements」→「Copy CSS Path」で要素のセレクタを抽出してみると `#\\31`\nという値がコピーされました。\n\n試しにこの値を使って要素を参照してみるとエラーになります。\n\n```\n\n > document.querySelector('#\\31')\n ✗ Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#' is not a valid selector.\n \n```\n\nもともと無効な属性を指定しているため意図しない動作であることは想像できるのですが、この場合に抽出されたセレクタ値 `#\\31`\nは意味のある値なのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-01T19:23:09.150",
"favorite_count": 0,
"id": "17152",
"last_activity_date": "2015-10-02T00:27:47.667",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2391",
"post_type": "question",
"score": 1,
"tags": [
"html",
"google-chrome-devtools"
],
"title": "DevToolsにおける無効なid属性のセレクタの扱い",
"view_count": 10413
}
|
[
{
"body": "31は16進数でASCIIコードの\"1\"ですね。 \n<http://www9.plala.or.jp/sgwr-t/c_sub/ascii.html>\n\nJavaScriptでは文字列リテラルで\\xを使ってエスケープすると16進数の文字コードを指定できます。 \n<http://www.tohoho-web.com/js/string.htm>\n\nつまり '#\\x31' であれば '#1' と同じ文字列となります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T00:00:26.970",
"id": "17155",
"last_activity_date": "2015-10-02T00:00:26.970",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3416",
"parent_id": "17152",
"post_type": "answer",
"score": 0
},
{
"body": "まず、id属性値\"1\"は無効ではありません。 \n<https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute>\n\nCSSセレクタ `#\\31` はそのままスタイルシートに書けばちゃんと動きます。\"1\" がエスケープされているのですね。 \nただし、`#\\31` を JavaScript の文字列として書くには、`\\` をエスケープする必要がありますから、`\"#\\\\31\"`\nとする必要がありますね。\n\nざっと CSS の規格を眺めてみましたが、この場合に数値をエスケープする必要はなさそうなので、DevTools\nの挙動は間違ってはいないもののちょっとおかしいですね。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T00:26:44.363",
"id": "17158",
"last_activity_date": "2015-10-02T00:26:44.363",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3475",
"parent_id": "17152",
"post_type": "answer",
"score": 0
},
{
"body": "「CSS エスケープ」などで調べてみて下さい。\n\nid が数字で始まる場合は CSSセレクタにそのまま書けないのでエスケープする必要があります。 \n`id=\"1\"` ですと、1の文字コードが16進数で31なので `#\\31` になります。 \n後続の文字とは空白で区切ります。 \n`id=\"123\"` の場合、`#\\31 23` です。後続の数字は許されているのでそのままです。\n\nJavaScript の `document.querySelector('#\\31')` が失敗したのは、JavaScript の文字列リテラルも `\\`\nでエスケープを行なうからです。 \n文字列 `\\31` を表現するには `'\\\\31'` としなければなりません。 \nつまり、 \n\n```\n\n document.querySelector(\"#\\\\31\");\n \n```\n\nで成功するはずです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T00:27:47.667",
"id": "17159",
"last_activity_date": "2015-10-02T00:27:47.667",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "17152",
"post_type": "answer",
"score": 2
}
] |
17152
|
17159
|
17159
|
{
"accepted_answer_id": "17154",
"answer_count": 1,
"body": "RubyMine7.1.4 \nruby-2.2.3-p173 SDK\n\nの環境で開発をしています。\n\ntest_spec.rb(仮)にテストケースを書いて、RubMineでテストをしようとしましたが \n下記のエラーでRspecの起動に失敗してしまいます\n\nError running Test: test: Cannot find RSpec runner script for ruby-2.2.3-p173\nSDK\n\nPreferenceのRuby SDK and Gems \nでruby-2.2.3-p173が選択されていることと\n\n試しにプロジェクト下で \ngem install rspecをしたので \ngemsの一覧には \nrspec(3.3.0)と表示されていました。(エラーは修正できませんでした)\n\nRubyMine上でGemfileを作成し、Bundle installした後も同じエラーがでます。\n\nターミナルから直接rspecを起動すると成功します\n\nどういったRubyMineの設定で \nRspecがRubyMineから起動できるかご教授ください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-01T19:57:14.653",
"favorite_count": 0,
"id": "17153",
"last_activity_date": "2015-10-01T23:16:12.457",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5839",
"post_type": "question",
"score": 0,
"tags": [
"ruby",
"rubygems",
"rubymine"
],
"title": "RubyMineでRspecが動かない",
"view_count": 1527
}
|
[
{
"body": "以下の手順で実行オプションを確認してください。 \n(以下の例はRailsを使わない素のRubyプロジェクトです)\n\n[](https://i.stack.imgur.com/nMiFv.png)\n\nUse project SDKになっているか?\n\n[](https://i.stack.imgur.com/WdmEM.png)\n\nbundle execで実行するようになっているか? \n(逆にチェックを外すと動く場合もある)\n\n[](https://i.stack.imgur.com/HJPyp.png)\n\nそれでもダメならhataさんの設定ウインドウを追記してください。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-01T23:16:12.457",
"id": "17154",
"last_activity_date": "2015-10-01T23:16:12.457",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "85",
"parent_id": "17153",
"post_type": "answer",
"score": 1
}
] |
17153
|
17154
|
17154
|
{
"accepted_answer_id": "17169",
"answer_count": 2,
"body": "cssのtransformプロパティについて質問があります。 \ntransformプロパティに、translate(xpx, ypx)を指定した場合のデータを取得するには、どのようにしたらよいでしょうか? \nこの時、文字列以外の形式で取得したいです。 \nウェブブラウザ:Google Chrome バージョン 45.0.2454.101 m\n\n・試したこと \n1.jqueryでcssを適用した場合\n\n```\n\n $(element).css('transform', 'translate(xpx, ypx)');\n \n```\n\nもしくは\n\n```\n\n $(element).css('-webkit-transform', 'translate(xpx, ypx)');\n \n```\n\nと指定すると、\n\n```\n\n $(element)[0].style.transform\n $(element)[0].style.webkitTransform\n \n```\n\nで値が文字列で取得できる。\n\n```\n\n $(element).css('transform')\n $(element).css('-webkit-transform')\n \n```\n\nではnoneが返ってくる。\n\n2.cssを直接指定 \ncssで直接指定し、上記のプロパティで取得しようとしても\n\n```\n\n $(element)[0].style.transform\n $(element)[0].style.webkitTransform\n \n```\n\nでは空文字が返ってくる。\n\n```\n\n $(element).css('transform')\n $(element).css('-webkit-transform')\n \n```\n\nではnoneが返ってくる。\n\nなお、firefox(41.0.1)では \njqueryでcss適用しても、css直接指定しても、\n\n```\n\n $(element).css('transform')\n \n```\n\nでmatrixとしてデータが返ってくるのは確認済みです。\n\nソースを張っておきますのでご確認ください。 \njqueryで指定\n\n```\n\n $('#rect1').css('transform', 'translate(50px, 50px)');\r\n $('#rect1').css('-webkit-transform', 'translate(50px, 50px)');\r\n $('#rect1').css('-moz-transform', 'translate(50px, 50px)');\r\n $('#rect1').css('-o-transform', 'translate(50px, 50px)');\r\n $('#rect1').css('-ms-transform', 'translate(50px, 50px)');\r\n \r\n \r\n $('#value1').text('style.transform: '+$('#rect1')[0].style.transform);\r\n $('#value2').text('style.webkitTransform: '+$('#rect1')[0].style.webkitTransform);\r\n $('#value3').text('transform: ' + $('#rect1').css('transform'));\r\n $('#value4').text('-webkit-transform: ' + $('#rect1').css('-webkit-transform'));\r\n $('#value5').text('-moz-transform: ' + $('#rect1').css('-moz-transform'));\r\n $('#value6').text('-o-transform: ' + $('#rect1').css('-moz-transform'));\r\n $('#value7').text('-ms-transform: ' + $('#rect1').css('-moz-transform'));\n```\n\n```\n\n <?xml version=\"1.0\" ?>\r\n <svg width=\"500\" height=\"500\" viewBox=\"0 0 500 500\" xmlns=\"http://www.w3.org/2000/svg\" style='background:gray;'>\r\n <rect id='rect1' x=\"0\" y=\"0\" width=\"100\" height=\"100\" />\r\n </svg>\r\n <p id='value1'></p>\r\n <p id='value2'></p>\r\n <p id='value3'></p>\r\n <p id='value4'></p>\r\n <p id='value5'></p>\r\n <p id='value6'></p>\r\n <p id='value7'></p>\n```\n\ncssで指定\n\n```\n\n $('#value1').text('style.transform: '+$('#rect1')[0].style.transform);\r\n $('#value2').text('style.webkitTransform: '+$('#rect1')[0].style.webkitTransform);\r\n $('#value3').text('transform: ' + $('#rect1').css('transform'));\r\n $('#value4').text('-webkit-transform: ' + $('#rect1').css('-webkit-transform'));\r\n $('#value5').text('-moz-transform: ' + $('#rect1').css('-moz-transform'));\r\n $('#value6').text('-o-transform: ' + $('#rect1').css('-moz-transform'));\r\n $('#value7').text('-ms-transform: ' + $('#rect1').css('-moz-transform'));\n```\n\n```\n\n #rect1 {\r\n transform: translate(50px, 50px);\r\n -moz-transform: translate(50px, 50px);\r\n -webkit-transform: translate(50px, 50px);\r\n -o-transform: translate(50px, 50px);\r\n -ms-transform: translate(50px, 50px);\r\n }\n```\n\n```\n\n <?xml version=\"1.0\" ?>\r\n <svg width=\"500\" height=\"500\" viewBox=\"0 0 500 500\" xmlns=\"http://www.w3.org/2000/svg\" style='background:gray;'>\r\n <rect id='rect1' x=\"0\" y=\"0\" width=\"100\" height=\"100\" />\r\n </svg>\r\n <p id='value1'></p>\r\n <p id='value2'></p>\r\n <p id='value3'></p>\r\n <p id='value4'></p>\r\n <p id='value5'></p>\r\n <p id='value6'></p>\r\n <p id='value7'></p>\n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2015-10-02T01:13:15.883",
"favorite_count": 0,
"id": "17160",
"last_activity_date": "2019-12-13T14:10:45.593",
"last_edit_date": "2019-12-13T14:10:45.593",
"last_editor_user_id": "32986",
"owner_user_id": "10728",
"post_type": "question",
"score": 3,
"tags": [
"jquery",
"css"
],
"title": "CSSのtransform、translateを取得するには?",
"view_count": 12431
}
|
[
{
"body": "> 2.cssを直接指定 \n> cssで直接指定し、上記のプロパティで取得しようとしても\n>\n> $(element)[0].style.transform \n> $(element)[0].style.webkitTransform\n>\n> では空文字が返ってくる。\n\nこの部分は仕様通りの動作です。[`element.style`では`style`属性の設定値のみが返されます](https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/style)。ですのでid指定の外部CSS値は反映されません。\n\n外部CSSも含めたスタイルは`window.getComputedStyle(element)`で求められます。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T01:31:38.037",
"id": "17162",
"last_activity_date": "2015-10-02T03:04:27.977",
"last_edit_date": "2015-10-02T03:04:27.977",
"last_editor_user_id": "5750",
"owner_user_id": "5750",
"parent_id": "17160",
"post_type": "answer",
"score": 0
},
{
"body": "Chrome では`getComputedStyle`で \"none\" が返るようですね。なぜでしょうか。\n\n```\n\n rect = document.querySelector(\"#rect1\");\n transform = getComputedStyle(react).transform;\n // firefox -> \"matrix(1, 0, 0, 1, 50, 50)\"\n // chrome -> \"none\"\n \n```\n\n文字列でなく行列を得たい場合、Chrome\nは`WebKitCSSMatrix`が`translate`関数などを使った文字列をパース出来るようなので`style.transform`が使える場合はこれでいいかもしれません。 \nFirefox の`DOMMatrix`は`matrix`関数しかパースしないように見えますが、こちらは\n`getComputedStyle`が機能するので、これを使えばよさそうです。 \n(これが仕様に沿ったやり方かはまったく分かりません)\n\n```\n\n rect = document.querySelector(\"#rect1\");\n \n // chrome\n matrix = new WebKitCSSMatrix(rect.style.transform);\n // firefox\n matrix = new DOMMatrix(getComputedStyle(rect).transform);\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T04:24:11.427",
"id": "17169",
"last_activity_date": "2015-10-02T04:24:11.427",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "17160",
"post_type": "answer",
"score": 2
}
] |
17160
|
17169
|
17169
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "任意のURL(ファイルの種類は不明)からHTMLを取得するPHPプログラムを作成しています。 \n取得したいのはHTMLのみですが、ファイルの種類が分からないためHTML以外の巨大なファイルを読み込む可能性があります。 \nURLからcurl_execでファイルの内容を取得する際に、ファイルサイズが大きかった場合に以下のエラーでプログラムが落ちてしまいます。\n\n```\n\n Allowed memory size of *** bytes exhausted\n \n```\n\nプログラムの先頭にini_set(\"memory_limit\", \"-1\");を追加しても駄目でした。 \nファイルサイズがはかり知れないためこの方法による回避はやめたいです。\n\n次に考えたのが、curl_execの前にヘッダーのみ取得してヘッダーからContent-Lengthを取得する方法ですが、Content-\nLengthの記述があるとは限らないのでこの方法も駄目でした。\n\n```\n\n $header = @shell_exec(\"curl -I {$url}\")\n \n```\n\n次に考えたのが、fopenでファイルの先頭だけ取得してHTMLかどうかを判別する方法です。\n\n```\n\n $fp= @fopen($url, \"r\", false, $context);\n if ($fp) {\n $head = @fread($fp, 1000);\n fclose($fp);\n }\n \n if (preg_match(\"/^(<\\!DOCTYPE|<html)/i\", trim($head), $matches) > 0) {\n $html = curl_exec($url);\n }\n \n```\n\n判別の仕方は良くないかも知れませんが、この方法ではある程度上手くいきました。 \nただしヘッダー取得の方法やこの方法だと2度URLにアクセスするため、全体の処理に時間がかかってしまいます。 \n時間をかけずメモリエラーを出さずにHTMLを取得する方法はないでしょうか?",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T01:17:10.753",
"favorite_count": 0,
"id": "17161",
"last_activity_date": "2015-11-01T07:46:51.000",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12530",
"post_type": "question",
"score": 0,
"tags": [
"php"
],
"title": "PHPのcURLでURLからファイルを取得する前にサイズを知る方法",
"view_count": 1915
}
|
[
{
"body": "HTTPで受信するデータサイズを事前に知るポータブルな方法はありません。したがって、任意のURLに対して確実に処理するには、データサイズによらず動作するよう考慮する必要があります。\n\n簡便な方法としては、一旦ファイルに出力してしまって処理する方法が考えられます(`CURLOPT_FILE`)。しかし、大きなファイルに当たると受信と出力に時間がかかりますし、極端に大きなファイルの場合ディスクがあふれるかもしれません。\n\n確実な方法は、受信したデータを逐次処理する方法です。cURLであれば`CURLOPT_WRITEFUCTION`というのが使えるようです。試してないですが何となくこんな感じで動くようです。\n\n```\n\n curl_setopt($ch, CURLOPT_HEADER, 1);\n curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'callback');\n \n curl_exec($ch);\n curl_close($ch);\n \n function callback($res, $response){\n // なにかする\n return strlen($response); // return 0 とかするとそこで中断するようです\n }\n \n```\n\nヘッダもでてくるので、Conetnt-TypeやContent-Lengthも併せてチェックすれば良いでしょう。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T06:53:40.253",
"id": "17176",
"last_activity_date": "2015-10-02T06:53:40.253",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5793",
"parent_id": "17161",
"post_type": "answer",
"score": 1
}
] |
17161
| null |
17176
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "Realmに落とし込んで使いたいと思っています。 \n参考になるものや、元とできるものをご存知無いでしょうか?\n\n内部辞書が使えれば一番なんですが。\n\n一応これは、かな漢字変換には使えなそうです。 \n<http://qiita.com/doraTeX/items/9b290f4e39f1e100558b>\n\n情報お持ちでしたら、よろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T02:46:11.343",
"favorite_count": 0,
"id": "17166",
"last_activity_date": "2015-10-02T07:31:28.840",
"last_edit_date": "2015-10-02T07:31:28.840",
"last_editor_user_id": "5519",
"owner_user_id": "10845",
"post_type": "question",
"score": 2,
"tags": [
"ios8"
],
"title": "かな漢字変換の辞書を作りたいが、元にできる物をご存知無いでしょうか?",
"view_count": 178
}
|
[
{
"body": "どういう辞書をご期待なのかよくわかりません。 \n\\- 権利フリーで無償利用可能なのが良いとか \n\\- NDA 契約を結んだ上で有償になるが、賢いのがいいとか \n\\- どんなサイズを想定しているかとか\n\nたとえば SKK Openlab <http://openlab.ring.gr.jp/skk/index-j.html> \nたとえば tamago <http://flex.phys.tohoku.ac.jp/texi/egg/egg_toc.html> \nたとえば Wnn (FreeWnn, OpenWnn)\n\nネタが古い・・・っすね。もっと新しいのがきっとあるはずですけどオイラこっち系は詳しくないっす。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T06:30:42.753",
"id": "17173",
"last_activity_date": "2015-10-02T06:30:42.753",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8589",
"parent_id": "17166",
"post_type": "answer",
"score": 1
},
{
"body": "かなり古いですが、下記のページが参考になると思います。\n\n[フリーのかな漢字変換辞書たち] \n<http://homepage2.nifty.com/baba_hajime/free-dic/>\n\n茶筌の辞書は、形態素分析に使われています。 \nまた、松本研究室(茶筌の開発元)に辞書の情報があります。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T06:36:45.310",
"id": "17174",
"last_activity_date": "2015-10-02T06:36:45.310",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "217",
"parent_id": "17166",
"post_type": "answer",
"score": 2
}
] |
17166
| null |
17174
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "### 発生している問題\n\nAlertDialogを出したいのですが、ビルドエラーになってしまいます。 \n調べてみましたが、わからないので教えて下さい。\n\n> val dialogBuilder = AlertDialog.Builder(this)\n\nここでエラーメッセージが出てます。\n\n* * *\n\n### エラーメッセージ\n\n```\n\n Error:(195, 45) None of the following functions can be called with the arguments supplied:\n public constructor Builder(context: android.content.Context!) defined in android.app.AlertDialog.Builder\n public constructor Builder(context: android.content.Context!, theme: kotlin.Int) defined in android.app.AlertDialog.Builder\n \n```\n\n## 該当のソースコード\n\n```\n\n package jp.yahuu.hogehoge.app.activities\n \n import android.app.AlertDialog\n import android.content.DialogInterface\n import android.content.Intent\n import android.net.Uri\n import android.os.Bundle\n import android.provider.SearchRecentSuggestions\n import android.webkit.JavascriptInterface\n import android.widget.Toast\n import jp.yahuu.hogehoge.app.R\n import jp.yahuu.hogehoge.app.UserLogoutActivity\n import jp.yahuu.hogehoge.app.advertising.AdvertisingIdentifierManager\n import jp.yahuu.hogehoge.app.constants.Constants\n import jp.yahuu.hogehoge.app.data.feed.user.User\n import jp.yahuu.hogehoge.app.fragment.WebFragment\n import jp.yahuu.hogehoge.app.proguardHelper.NonObfuscate\n import jp.yahuu.hogehoge.app.suggestionsProvider.SuggestionsProvider\n import jp.yahuu.hogehoge.app.web.*\n import kotlin.properties.Delegates\n \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n //履歴消去選んだ場合\n private fun showLogoutDialog() {\n \n // AlertDialog.Builderオブジェクト生成\n \n val dialogBuilder = AlertDialog.Builder(this)\n \n dialogBuilder.setTitle(\"検索履歴を削除します\")\n dialogBuilder.setMessage(\"操作は取り消すことができません。よろしいですか?\")\n \n val self = this\n \n dialogBuilder.setPositiveButton(\"削除\", object: DialogInterface.OnClickListener {\n \n override fun onClick(dialog: DialogInterface, which: Int) {\n \n // val suggestions = SearchRecentSuggestions(\n // self,\n // SuggestionsProvider.Authority,\n // SuggestionsProvider.Mode\n // )\n //\n // suggestions.clearHistory()\n //\n // Toast.makeText(self, \"検索履歴を削除しました\", Toast.LENGTH_SHORT).show()\n \n }\n \n })\n \n dialogBuilder.setNegativeButton(\"キャンセル\", object: DialogInterface.OnClickListener {\n \n override fun onClick(dialog: DialogInterface, which: Int) {\n \n dialog.cancel()\n \n }\n \n })\n \n dialogBuilder.setCancelable(true)\n dialogBuilder.create().show()\n \n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2015-10-02T03:46:55.400",
"favorite_count": 0,
"id": "17168",
"last_activity_date": "2022-04-03T16:00:45.053",
"last_edit_date": "2020-12-22T05:39:42.440",
"last_editor_user_id": "3060",
"owner_user_id": "10715",
"post_type": "question",
"score": 0,
"tags": [
"java",
"android",
"kotlin"
],
"title": "AlertDialogを出したいが、ビルドエラーになってしまう。",
"view_count": 3103
}
|
[
{
"body": "`this` ではなく、以下の形式で activity 名を付けてみてください。\n\n**変更前:**\n\n```\n\n AlertDialog.Builder(this)\n \n```\n\n**変更後:**\n\n```\n\n AlertDialog.Builder(yourActivitiyName.this)\n \n```\n\n* * *\n\n_この投稿は @user9156 さんのコメント の内容を元に コミュニティwiki として投稿しました。_",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2020-12-22T05:36:10.807",
"id": "72818",
"last_activity_date": "2020-12-22T05:36:10.807",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3060",
"parent_id": "17168",
"post_type": "answer",
"score": 1
}
] |
17168
| null |
72818
|
{
"accepted_answer_id": null,
"answer_count": 4,
"body": "Javaの経験は浅いです。 \nApache Tomcat/6.0.20 直下のlogを見ましたけど、特に異常はなさそうです。 \n下記のエラーの解消方法を教えていただけますか?\n\n**HTTPステータス**\n\n> 500 -\n\n**type 例外レポート メッセージ**\n\n**説明**\n\n> The server encountered an internal error () that prevented it from\n> fulfilling this request.\n\n**例外**\n\n```\n\n java.lang.StringIndexOutOfBoundsException: String index out of range: -9\n java.lang.String.substring(String.java:1938)\n java.lang.String.substring(String.java:1905)\n pds.document.provider.PosFile.parseTag(PosFile.java:104)\n pds.document.provider.PatentDocument.init(PatentDocument.java:66)\n pds.servlet.ShowPatentDocument.showPatentDocumentImpl(ShowPatentDocument.java:116)\n pds.servlet.ShowPatentDocument.doPost(ShowPatentDocument.java:74)\n pds.servlet.ShowPatentDocument.doGet(ShowPatentDocument.java:38)\n javax.servlet.http.HttpServlet.service(HttpServlet.java:617)\n javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\n \n```\n\n**注意**\n\n> 原因のすべてのスタックトレースは、Apache Tomcat/6.0.20のログに記録されています",
"comment_count": 7,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T04:58:11.427",
"favorite_count": 0,
"id": "17170",
"last_activity_date": "2015-10-07T07:08:17.087",
"last_edit_date": "2015-10-03T15:16:22.727",
"last_editor_user_id": "12546",
"owner_user_id": "12546",
"post_type": "question",
"score": 3,
"tags": [
"java",
"apache",
"tomcat"
],
"title": "HTTPステータス 500 エラーの調査及び解決方法を教えてください",
"view_count": 132583
}
|
[
{
"body": "何らかのソフトウェア製品を使われていてその利用上で生じているエラーのようですので、メーカーのサポート窓口に問い合わせてください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T07:01:23.083",
"id": "17177",
"last_activity_date": "2015-10-02T07:01:23.083",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5793",
"parent_id": "17170",
"post_type": "answer",
"score": 3
},
{
"body": "Tomcatを使っていてHTTPステータス500エラーが出るのは、大抵の場合は、デプロイしたWebアプリにバグがあるか、何らかの設定が誤っているかのいずれかです。\n\n具体的な原因を知るためには出力されたログを解析する必要があります。 \n本件質問のスタックトレースで注目すべき箇所は次のところです。\n\n```\n\n java.lang.StringIndexOutOfBoundsException: String index out of range: -9\n java.lang.String.substring(String.java:1938)\n :\n pds.document.provider.PosFile.parseTag(PosFile.java:104)\n pds.document.provider.PatentDocument.init(PatentDocument.java:66)\n \n```\n\nエラーが出た直接の原因は\n\n```\n\n java.lang.StringIndexOutOfBoundsException: String index out of range: -9\n java.lang.String.substring(String.java:1938)\n \n```\n\nとあるように、文字列の中をsubstring()で参照しようとしたときに負の値を指定したことによるものです。 \n[Java API String\nsubstring](http://docs.oracle.com/javase/jp/8/docs/api/java/lang/String.html#substring-\nint-)\n\nではどこで負の値を指定したのかというと、\n\n```\n\n pds.document.provider.PosFile.parseTag(PosFile.java:104)\n \n```\n\nとなっているので `PosFile.java` の104行目の可能性が高いです。 \nおそらく`PosFile.parseTag()`メソッドに何らかのバグがあるのでしょう。あるいは`parseTag()`メソッドに渡される引数に誤りがあるのでしょう。具体的なことは該当するソースを見ないとわかりません。 \nもしかすると、クラス名やメソッド名から察するにposファイルとやらの内容を解析しているようなので、そのposファイル自体が本来満たしているべき規約や規格に添っていない可能性もあります。\n\n* * *\n\nスタックトレースの見方については以下のリンクが参考になると思います。\n\n * [デバッグのヒント教えます(2):スタックトレースからデバッグのヒントを読み取る - @IT](http://www.atmarkit.co.jp/ait/articles/0605/20/news012.html)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T07:04:08.277",
"id": "17179",
"last_activity_date": "2015-10-03T15:21:21.033",
"last_edit_date": "2015-10-03T15:21:21.033",
"last_editor_user_id": "8000",
"owner_user_id": "10492",
"parent_id": "17170",
"post_type": "answer",
"score": 4
},
{
"body": "長く使っていたもので、アプリケーションを修正出来ないとすれば、使い方に問題がある可能性もありますね。スタックトレースの情報から\n何かしらの入力された文字数が短すぎるか、添字の計算が間違っていると推測できます。\n\nこのエラーに再現性があるのであれば、異常時と正常時のデータを比較して、 \n普段の使い方と違うところがないか確認するとなにか分かるかもしれません。\n\nまた、JAR しか無いのは紛失したのでしょうか? \nそれとも ソースコードにアクセスする権限がないのでしょうか。 \nその辺を確認して開発元なり、所有者に問合せしてみるのが良いと思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T07:40:35.667",
"id": "17182",
"last_activity_date": "2015-10-02T07:40:35.667",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5008",
"parent_id": "17170",
"post_type": "answer",
"score": 0
},
{
"body": "jarしかないとコメントにありますが、 \nTomcatでアプリケーションを動かしている場合、下記のディレクトリにアプリケーションのwarが展開されたフォルダが必ずあり、 \n展開前のwarファイルも存在する可能性が高いです。\n\n$tomcat_home/webapps\n\ntomcatのディレクトリがApache Tomcat/6.0.20であれば、下記のディレクトリになると思います。 \nApache Tomcat/6.0.20/webapps\n\nあと、気になった点が1点あります。 \n質問では「Apache Tomcat/6.0.20直下のlogを見た」とありますが、 \n通常Tomcatのログは以下のディレクトリにcatalina.outというファイル名で出力されます。 \n$tomcat_home/logs\n\nApache Tomcat/6.0.20/logs/catalina.out \nというファイルはありませんか?",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T07:08:17.087",
"id": "17346",
"last_activity_date": "2015-10-07T07:08:17.087",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12620",
"parent_id": "17170",
"post_type": "answer",
"score": 0
}
] |
17170
| null |
17179
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "セレクトピッカーが反応する部分のコードは以下になります。\n\n```\n\n <div class=\"mod_form\">\n <form>\n <div class=\"mod_form_select\">\n <select class=\"Select2\" name=\"sample1\" select id=\"select_test\" onchange=\"getS(this,'Question2');\">\n <option value=\"\">Please Select</option>\n \n```\n\nios8ではタップしてセレクトピッカーが出ないようなことはなかったです(自分のデバイスだけかもしれませんが)。\n\n具体的に言いますと、何回かタップしているとそのうちセレクトピッカーが出てきて普通にセレクトできるようになる時があります。何回やっても出てこないときは何の反応もありません。ただ反応がおかしいセレクト(出たり消えたりが繰り返されます。それもすごいスピードです)がたまに現れたりします。そういった現象もios8ではありませんでした。\n\nコーディングのし直しをしないといけないのでしょうか?ちなみにonsenUIを最新にアップデートしても直りませんでした。\n\nvppを通して配布しているアプリですが今のところ「反応しない」との声は聞かれません。\n\nただそのうちios9が普及してくれば必ずこの問題は出てくると思われます。 \nどなたか同じ問題に直面している人、または問題を克服する方法をお知りのかた、ぜひ御教示いただけたらと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T06:38:54.940",
"favorite_count": 0,
"id": "17175",
"last_activity_date": "2015-10-02T07:59:57.527",
"last_edit_date": "2015-10-02T07:59:57.527",
"last_editor_user_id": "8532",
"owner_user_id": "9174",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"monaca",
"onsen-ui"
],
"title": "Monaca+OnsenUIアプリのios9でのタップ反応が悪化(セレクトピッカーが出ない)",
"view_count": 290
}
|
[] |
17175
| null | null |
{
"accepted_answer_id": "17181",
"answer_count": 1,
"body": "お世話になります。\n\nフォーム上に貼り付けたボタンに、テキストファイルをドラッグドロップしてきて、 \n指定してあるテキストエディタをProcess.Startで立ち上げてファイルを開こうとしています。\n\nボタンを押すと、テキストエディタが開くということはできますが、それでは \nエクスプローラーから編集したいファイルを開くということが一度にできません。\n\nそのため、ボタンを単純にクリックすれば、引数なしで外部プログラムを起動させ、 \nドラッグドロップならば引数付きで起動するようにしたいと思ったのですが…。\n\nボタン自体はドラッグドロップは受け付けないのでしょうか。 \nAllowDropをTrueにしただけでテストしても、ドラッグ時に×のマウスカーソルの \nままです。\n\n実装そのものができないのでしょうか。 \nそれとも、他に何か原因がありますでしょうか。\n\nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T07:02:50.877",
"favorite_count": 0,
"id": "17178",
"last_activity_date": "2015-10-02T07:31:01.847",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9374",
"post_type": "question",
"score": 1,
"tags": [
"c#"
],
"title": "C# ボタンコントロールにドラッグドロップをさせたい",
"view_count": 1887
}
|
[
{
"body": "`AllowDrop`を設定しても、ドラッグイベントを処理しなければドロップすることはできません。以下を参考に実装してみて下さい。\n\n```\n\n private void Form1_Load(object sender, EventArgs e)\n {\n button1.AllowDrop = true;\n \n // TODO:デザイナーで以下のイベントを登録する\n button1.DragEnter += button1_DragEnter;\n button1.DragOver += button1_DragEnter;\n button1.DragDrop += button1_DragDrop;\n }\n \n \n // DragEnter, DragOverの実装\n void button1_DragEnter(object sender, DragEventArgs e)\n {\n // 目的の操作(この場合はCopy)ができることと、\n // データの種類を確認する\n if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy\n && e.Data.GetDataPresent(DataFormats.FileDrop))\n {\n // Copyのエフェクトを表示する\n e.Effect = DragDropEffects.Copy;\n }\n else\n {\n // 対応していない場合\n e.Effect = DragDropEffects.None;\n }\n }\n // DragDrop時の処理\n void button1_DragDrop(object sender, DragEventArgs e)\n {\n // DragEnterと同様の判定を行う\n if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy\n && e.Data.GetDataPresent(DataFormats.FileDrop, true))\n {\n // 実際にデータを取り出す\n var data = e.Data.GetData(DataFormats.FileDrop, true) as string [];\n \n // データが取得できたか判定する\n if (data != null)\n {\n foreach (var filePath in data)\n {\n Console.WriteLine(filePath);\n }\n }\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T07:31:01.847",
"id": "17181",
"last_activity_date": "2015-10-02T07:31:01.847",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5750",
"parent_id": "17178",
"post_type": "answer",
"score": 1
}
] |
17178
|
17181
|
17181
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "```\n\n ffmpeg -i test.mp4 -threads 2 -codec:v libx264 -s:v 1280x720 -aspect:v 16:9 -b:v 256k -map 0 -f segment -segment_format mpegts -segment_time 10 -segment_list stream.m3u8 streamfiles/stream%03d.ts\n \n```\n\nffmpeg のこのコマンドでエンコードを行うと、\n\n> Unknown encoder 'libx264'\n\nという表示がでて libx264 がないという表示がでます。\n\n私は iOS でストリーム再生がしたくて動画を mp4 に h.264 でエンコードしたいのですが、これは libx264\nが元からなくてできないんでしょうか?\n\n`ffmpeg -formats` で見たところ、 libx264 はなくて h264 がありました。しかし、映像/音声コーデックの種類は D と E\nだけで V がありませんでしたし、 h264 でやった場合も同じ `Unknown encoder` とでます。\n\nこの場合 V がないとエンコードができないんでしょうか? \nもし V が必要なのであれば追加方法を教えてください。よろしくお願いします。",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2015-10-02T07:18:00.763",
"favorite_count": 0,
"id": "17180",
"last_activity_date": "2019-05-04T17:04:05.583",
"last_edit_date": "2019-05-04T17:04:05.583",
"last_editor_user_id": "32986",
"owner_user_id": "9349",
"post_type": "question",
"score": 1,
"tags": [
"ffmpeg"
],
"title": "ffmpegのlibx264について質問です。",
"view_count": 5127
}
|
[] |
17180
| null | null |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "cocos2dxの **Javascipt** 版でブラウザ上のゲームを製作しています.\n\n**SpriteBatchNode** を利用してDraw関数の呼び出し回数を少なくしているのですが, \nAndroidやiOSからブラウザを開いてプレイしてみると, \n画像は正しく表示されているものの,Draw関数のコール回数がまったく減っていません.\n\nPCからプレイすると意図通りの動作が行われ,Draw関数のコール回数が激減しています. \n(約3000→8)\n\nBatchNodeはスマートフォンなどでは利用できないのでしょうか.",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T08:50:09.147",
"favorite_count": 0,
"id": "17184",
"last_activity_date": "2015-10-02T08:50:09.147",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12538",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"cocos2d-x"
],
"title": "cocos2dx (javascript)のBatchNodeについて",
"view_count": 44
}
|
[] |
17184
| null | null |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "```\n\n func sendRequest(request: NSMutableURLRequest) -> NSDictionary {\n var response: AutoreleasingUnsafeMutablePointer<NSURLResponse?>=nil\n var err: NSError?\n \n var dataVal: NSData = NSURLConnection.sendSynchronousRequest(request, returningResponse: response, error: &err)!\n \n \n println(dataVal)\n \n var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataVal, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary\n return jsonResult\n \n```\n\nしたから2行目で以下のエラーが出てしまいます。 \nexc_bad_instruction (code= EXC_l386_INVOP,subcode=0x0)\n\n原因がわからないので些細なことでもわかるかたアドバイスよろしくお願い致します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T11:19:24.550",
"favorite_count": 0,
"id": "17187",
"last_activity_date": "2017-05-28T05:49:16.523",
"last_edit_date": "2017-05-28T05:49:16.523",
"last_editor_user_id": "5519",
"owner_user_id": "12541",
"post_type": "question",
"score": 1,
"tags": [
"swift",
"php",
"xcode",
"json"
],
"title": "NSData型をNSJSONSerializationするとエラーがでてしまう。",
"view_count": 129
}
|
[] |
17187
| null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "```\n\n func getJson(param: models)-> Dictionary{\n let url = \"https://test.com/\" + models + \".php\"\n let json = JSON(data:super.HttpRequest())\n print(json.type) /* print結果 \"Dictionary\" */\n print(json) /* jsonの内容は意図したデータが帰ってきております。 */\n print(json['name']) /* 左の指定で「山田太郎」も問題ございません。 */\n return json\n }\n /* call */\n myClass.getJson()\n \n```\n\nhttpRequestを実行し、jsonデータを受信するためのプログラムを作成しておりますが、 \n戻り値のデータ型を「Dictionary」にすると、 \n「Reference to generic type 'Dictionary' requires arguments in\n<...>」というエラーになってしまいます。 \nJSON関数から受け取った状態の「json」変数のtypeを「print」しても「Dictionary」となるのですが、戻り値の「->Dictionary」のところがエラーになります。\n\nご教授いただけませんでしょうか。よろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T12:04:50.617",
"favorite_count": 0,
"id": "17189",
"last_activity_date": "2015-12-31T17:54:30.520",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12504",
"post_type": "question",
"score": 1,
"tags": [
"swift",
"xcode"
],
"title": "Swiftでの「Dictionary型」戻り値について",
"view_count": 1415
}
|
[
{
"body": "エラーメッセージの内容は、「`Dictionary`を関数の返り値とする場合にはジェネリクス型の指定(たとえば、`Dictionary<String,\nAnyObject>`)をする必要がある」というものですが、ここでは関係ありません。\n\nSwiftyJSONを利用されているのだと思われますが、`type`プロパティが返却する型情報は単にJSONのルート要素の型を示しており、Swift上での型は`JSON`になります。\n\n```\n\n func getJson(param: models) -> JSON {\n let url = \"https://test.com/\" + models + \".php\"\n let json = JSON(data:super.HttpRequest())\n return json\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T12:43:45.090",
"id": "17190",
"last_activity_date": "2015-10-02T13:00:06.603",
"last_edit_date": "2015-10-02T13:00:06.603",
"last_editor_user_id": "5337",
"owner_user_id": "5337",
"parent_id": "17189",
"post_type": "answer",
"score": 1
}
] |
17189
| null |
17190
|
{
"accepted_answer_id": "17203",
"answer_count": 1,
"body": "Laravel 5.1を使用しております。\n\n既存のデータベースを使いLaravelでWebサイトをリニューアルしようとしております。\n\n\"persons\"というテーブルを使いたいので、Personというモデルを作成、アクセスしようとしたところ、\n\nSQLSTATE[42S02]: Base table or view not found: 1146 Table 'データベース名.people'\ndoesn't exist (SQL: select count(*) as aggregate from `people`)\n\nというエラーが出てきました。 \n調べたところ、Pluralizerが働いているようなので、コアコードを削除を試みましたが、削除箇所がわからず..、またコアをいじらずpersonsテーブルを使う方法があれば試したいのですが..\n\n(具体的にはInflector.phpのperson関連を削除してみても変わらず、といったところです。 \nまた、postsテーブルなどにはアクセス出来ております。)\n\n初歩的な質問かもしれませんが、ご存知の方がいればご教示いただければ幸いです。m(_ _)m",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T13:05:52.967",
"favorite_count": 0,
"id": "17191",
"last_activity_date": "2015-10-02T22:04:11.090",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12543",
"post_type": "question",
"score": 1,
"tags": [
"php",
"laravel"
],
"title": "Laravel5のPluralizerに関して",
"view_count": 296
}
|
[
{
"body": "[Laravelのドキュメント](http://laravel.com/docs/5.1/eloquent)によると、モデルではテーブルを指定することが可能です!\n\n秘訣はLaravelのドキュメントの「[`Defining\nModels`](http://laravel.com/docs/5.1/eloquent#defining-models) `-> Table\nNames`」というところで見つかります。特に`protected $table =\n'persons';`という文を通して、自分のテーブルを指定することができそうです。\n\n超簡単なモデル例:\n\n```\n\n class Person extends Model\n {\n protected $table = 'persons';\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T22:04:11.090",
"id": "17203",
"last_activity_date": "2015-10-02T22:04:11.090",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4129",
"parent_id": "17191",
"post_type": "answer",
"score": 0
}
] |
17191
|
17203
|
17203
|
{
"accepted_answer_id": "17204",
"answer_count": 1,
"body": "`undefined method `page' for\n<Article::ActiveRecord_Relation:0x007ffabcd88560>` というエラーが出力されます。\n\nGemfileでkaminariをインストールした後、コントローラーに以下を記述しました。\n\n```\n\n @asc_avg_star = Article.order('avg_star ASC').page(params[:page]).per(2)\n \n```\n\n記事をそのお気に入りの平均を昇順で表示させようとしています。 \nググりましたが、解決に結びつきません。 \nよろしくお願いいたします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T13:45:04.947",
"favorite_count": 0,
"id": "17193",
"last_activity_date": "2015-10-02T22:15:19.087",
"last_edit_date": "2015-10-02T19:45:41.140",
"last_editor_user_id": "85",
"owner_user_id": "11188",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "gem kaminari で undefined method `page' for",
"view_count": 3576
}
|
[
{
"body": "`Article.all.page(params[:page])`でまず`page`メソッドが使えるかを確認してみてください。\n\nあと`rails server`の再起動はされましたか?",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T22:15:19.087",
"id": "17204",
"last_activity_date": "2015-10-02T22:15:19.087",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3271",
"parent_id": "17193",
"post_type": "answer",
"score": 0
}
] |
17193
|
17204
|
17204
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "データベースを切り替えたあとに、取得したデータの$hasManyアソシエーションした部分の一部が紐づかないです。\n\n<テーブル>\n\n * postsテーブル\n * tagsテーブル\n * posts_tagsテーブル(中間テーブル)\n\n<モデル>\n\n * post.php\n * tag.php\n * posts_tag.php($name = 'PostsTag')\n\n<db環境>\n\n * 開発環境('develompent')\n * テスト環境('testDb')\n\n※database.phpは省略\n\ndbを切り替えた後に、取得したデータが正しくとれません。 \n下記を見てください。 \npostモデルに中間テーブルのモデルであるPostsTagを$hasmanyしています。 \nこのとき取得したデータである$dataの[PostsTag]には、PostsTagモデルのデータは取れますが、、、、、 \n**サブで定義した?[PostsTag_Sub]には、PostsTagモデルのデータは取れません!!!!!!!!!!!!!**\n\nちなみにdbを切り替えなければ、データは全て正しく取れます。\n\n困ってます。教えてください。\n\n```\n\n //post.php\n \n class Post extends AppModel\n {\n \n public $hasMany = [\n 'PostsTag',\n 'PostsTag_Sub' => [\n 'className' => 'PostsTag',\n ],\n ];\n \n public function getData()\n {\n //開発環境(development)にいる\n $oldDb = $this->Tag->useDbConfig; //development\n // テスト環境(testDb)に切り替える。\n $database = 'testDb';\n $this->dbChange($database);\n //データ取得\n $data = $this->find('all');\n print_r($data);\n } \n //データベース切り替え処理\n public function dbChange($database)\n {\n $this->useDbConfig = $database;\n $this->tag->useDbConfig = $database;\n $this->posts_tag->useDbConfig = $database;\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T15:16:48.350",
"favorite_count": 0,
"id": "17195",
"last_activity_date": "2015-10-04T03:36:13.367",
"last_edit_date": "2015-10-04T03:36:13.367",
"last_editor_user_id": "8000",
"owner_user_id": "12545",
"post_type": "question",
"score": 0,
"tags": [
"php",
"cakephp"
],
"title": "モデル内でuseDbConfigを変更すると、hasManyアソシエーションがうまく動作しない",
"view_count": 257
}
|
[
{
"body": "この場合 `PostsTag` と `PostsTag_Sub` は同じクラスでも別インスタンスになるようですから、`PostsTag_Sub` に対しても\nDbConfig を変更する必要があるのではないでしょうか。\n\n```\n\n public function dbChange($database)\n {\n $this->useDbConfig = $database;\n $this->PostsTag->useDbConfig = $database;\n $this->PostsTag_Sub->useDbConfig = $database;\n }\n \n```\n\n※質問に書かれたコードとマニュアル等から推測しただけなので、動作確認はしていません",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T03:29:33.083",
"id": "17239",
"last_activity_date": "2015-10-04T03:29:33.083",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "17195",
"post_type": "answer",
"score": 1
}
] |
17195
| null |
17239
|
{
"accepted_answer_id": "17206",
"answer_count": 1,
"body": "phpMyAdminのインストールは以下のようにしました。\n\n```\n\n $ sudo yum install epel-release\n $ sudo yum install phpmyadmin\n \n```\n\nデータベースは作成済みです。\n\n* * *\n\n**環境**\n\nCentOS 7.1.1503 \nNginx 1.8.0 \nphp 5.4.16 \nMariaDB 10.1.7\n\n## phpMyAdminにアクセスできない\n\n独自ドメインは仮に`example.me`とします。\n\n`/etc/nginx/conf.d/phpmyadmin.conf`に以下を追記しました。\n\n```\n\n server {\n listen 80;\n server_name phpmyadmin.example.me;\n \n location /phpMyAdmin {\n root /usr/share;\n index index.php;\n }\n \n location ~ ^/phpMyAdmin.+\\.php$ {\n fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n include fastcgi_params;\n }\n }\n \n```\n\n一応以下のコマンドも入力しました。\n\n```\n\n $ sudo chown nginx /var/lib/php/session\n \n```\n\nこの状態でMySQLとNginxを再起動し、`http://phpmyadmin.example.me/phpMyAdmin`にアクセスしてみましたが、「File\nnot found.」と返ってきます。\n\n* * *\n\n内容の変更を試してみました。\n\n`/etc/nginx/conf.d/phpmyadmin.conf`の内容を以下に変更します。\n\n(<http://oxynotes.com/?p=8457>の内容をほぼ丸コピさせて頂きました。ただ、nginx.confではなく、conf.d/phpmyadmin.confに書きました。)\n\n```\n\n server {\n listen 80;\n server_name phpmyadmin.example.me;\n \n index index.html index.htm index.php;\n root html;\n \n location /phpMyAdmin {\n alias /usr/share/phpMyAdmin/;\n try_files $uri $uri/ /index.php;\n \n location ~ ^/phpmyadmin(.+\\.php)$ {\n alias /usr/share/phpMyAdmin;\n fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;\n fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin;\n include fastcgi_params;\n fastcgi_intercept_errors on;\n allow 160.16.74.43;\n deny all;\n }\n }\n \n }\n \n```\n\nこの状態でNginxを再起動し`http://phpmyadmin.example.me/phpMyAdmin`にアクセスしたところ、画像のようなメッセージが返ってきました。\n\n<https://kie.nu/2KLH>\n\nもとからファイル名も表示されていません。(加工したのはモザイク部分だけです)\n\n* * *\n\nなかなか情報が見つからず、苦戦している状況です。\n\n初心者ですみませんが、お力を貸していただけると嬉しいです。\n\nよろしくお願いします。",
"comment_count": 4,
"content_license": "CC BY-SA 4.0",
"creation_date": "2015-10-02T16:46:49.607",
"favorite_count": 0,
"id": "17198",
"last_activity_date": "2020-10-10T11:30:20.937",
"last_edit_date": "2020-10-10T11:30:20.937",
"last_editor_user_id": "3060",
"owner_user_id": "12505",
"post_type": "question",
"score": 3,
"tags": [
"centos",
"nginx",
"phpmyadmin"
],
"title": "NginxでphpMyAdminにアクセスしようとするとFile not foundと返される",
"view_count": 7164
}
|
[
{
"body": "2つ目の設定についてコメントします。\n\n * 「location ~ ^/phpmyadmin(.+.php)$」だと URL のパスが「/phpMyAdmin/」(大文字含む)にマッチしないので、FastCGI ではなく普通のファイルとみなされてしまいます。\n\n * 「fastcgi_param SCRIPT_FILENAME」には PHPファイル名を \"$1\" で渡す必要があります。\n\nしたがって、location 箇所を以下のようにすればいいと思います。\n\n```\n\n location /phpMyAdmin {\n alias /usr/share/phpMyAdmin/;\n try_files $uri $uri/ /index.php;\n \n location ~ ^/phpMyAdmin/(.+\\.php)$ { #変更\n alias /usr/share/phpMyAdmin; #必要なし? \n fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;\n fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin/$1; #変更\n include fastcgi_params;\n fastcgi_intercept_errors on;\n allow 160.16.74.43;\n deny all;\n }\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T03:12:07.313",
"id": "17206",
"last_activity_date": "2015-10-03T03:12:07.313",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4603",
"parent_id": "17198",
"post_type": "answer",
"score": 2
}
] |
17198
|
17206
|
17206
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "```\n\n <textarea name=\"\" id=\"content\" cols=\"30\" rows=\"10\" placeholder=\"テスト\"></textarea> \n <input type=\"text\" name=\"\" id=\"name\" cols=\"30\" rows=\"10\" placeholder=\"名前\">\n \n```\n\n上のように、2つのエリアから入力した情報を取得しようと考えています。\n\nJsの方は、\n\n```\n\n //3.\"message\"データストアからメッセージを取ってくる\n ds.stream().sort(\"desc\").next(function(err, datas) {\n datas.forEach(function(data) {\n renderMessage(data);\n });\n });\n \n //4.\"message\"データストアのプッシュイベントを監視\n ds.on(\"push\", function(e) {\n renderMessage(e);\n });\n \n var last_message = \"dummy\";\n \n function renderMessage(message) {\n var message_html = '<p class=\"post-text\">' + escapeHTML(message.value.content) + '</p>';\n var date_html = '';\n if(message.value.date) {\n date_html = '<p class=\"post-date\">'+escapeHTML( new Date(message.value.date).toLocaleString())+'</p>';\n }\n $(\"#\"+last_message).before('<div id=\"'+message.id+'\" class=\"post\">'+message_html + date_html +'</div>');\n last_message = message.id;\n }\n function post() {\n //5.\"message\"データストアにメッセージをプッシュする\n var content = escapeHTML($(\"#content\").val());\n var name = escapeHTML($(\"#name\").val());\n if (content && content !== \"\") {\n ds.push({\n title: \"タイトル\",\n content: content,\n name: name,\n date: new Date().getTime()\n }, function (e) {});\n }\n $(\"#content\").val(\"\");\n $(\"#name\").val(\"\");\n }\n \n $('#post').click(function () {\n console.log(name);\n post();\n })\n $('#content').keydown(function (e) {\n if (e.which == 13){\n post();\n return false;\n }\n });\n $(\"#name\").keydown(function (e) {\n if (e.which == 13){\n post();\n return false;\n }\n });\n });`\n \n```\n\nこのようになっています。\n\npostがクリックされた時に、contentは表示されるのですが、nameの方は表示されません。 \nデータストアからどのような流れでcontentが取得されているのか分からないのですが、 \nnameはどのように記述すれば良いのでしょうか?\n\nお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T17:02:38.833",
"favorite_count": 0,
"id": "17199",
"last_activity_date": "2016-04-30T23:32:41.313",
"last_edit_date": "2015-11-02T19:42:47.243",
"last_editor_user_id": "76",
"owner_user_id": "8415",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"milkcocoa"
],
"title": "入力したvalueを取得して表示したい",
"view_count": 333
}
|
[
{
"body": "表示されないのは表示していないからではないでしょうか。 \nrenderMessage()にてmessage.value.nameを出力している箇所が見当たりませんが・・・",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T06:58:45.090",
"id": "17211",
"last_activity_date": "2015-10-03T06:58:45.090",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12551",
"parent_id": "17199",
"post_type": "answer",
"score": 1
}
] |
17199
| null |
17211
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "UniRx(Unity用Reactive Extension)を使用して、 \nカードリストのような画面を作成しようとしています。\n\n個別のボタンであれば、ボタンと対になる処理を書けば良いので、 \nクリック通知があったらSubscribeに〜する。といった書き方ができますが \nリスト構造の場合、ボタンが押されただけではどこのインデックスのボタンが \n押されかがわかりません。\n\n.netの新しいバージョンであればObeservableCollectionなどが使えそうなのですが、 \nUnityでは使用できませんでした。\n\nMVPパターンで作成しているので、 \nデータのやり取りはあくまでModel側がおこない \nイベントやアクションなどはView側が受け持って \nModel側とView側のやり取りは、Presenter側に書きます。\n\nですので、どこのインデックスのボタンが押されたかは \nView側に書きたいのですが、どのように関連付ければ良いのかがわかりません。\n\n考え方やサンプルソースなどを教えていただけないでしょうか?\n\n追記:IndexOfを使って自分自身を検索するようにしようとしたのですが、 \nラムダ式の中で自分自身を渡す方法がわからず。 \nIObservable`<Unit>`のUnitではなく、IObservable`<Unit>`を渡したい\n\n```\n\n /// <summary>\n /// ボタンのリスト\n /// </summary>\n public List<Button> ButtonList = new List<Button>();\n /// <summary>\n /// ボタンイベント通知リスト\n /// </summary>\n List<IObservable<Unit>> abc = new List<IObservable<Unit>>();\n /// <summary>\n /// ボタン通知のハッシュリスト\n /// </summary>\n List<int> abcHash = new List<int>();\n \n void Start () \n {\n abc.Add(ButtonList[0].OnClickAsObservable());\n abcHash.Add(abc[0].GetHashCode());\n \n abc.Add(ButtonList[1].OnClickAsObservable());\n abcHash.Add(abc[1].GetHashCode());\n \n abc.Add(ButtonList[2].OnClickAsObservable());\n abcHash.Add(abc[2].GetHashCode());\n \n abc.Add(ButtonList[3].OnClickAsObservable());\n abcHash.Add(abc[3].GetHashCode());\n \n foreach(IObservable<Unit> test in abc)\n {\n test.Subscribe(\n _ => ButtonClicked(abcHash.IndexOf(test自身のハッシュ値を取得したい)))\n );\n }\n }\n \n private void ButtonClicked(int index)\n {\n Debug.Log(\"index=\" + index.ToString());\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T17:43:49.133",
"favorite_count": 0,
"id": "17200",
"last_activity_date": "2015-12-05T04:19:21.383",
"last_edit_date": "2015-10-03T05:29:05.673",
"last_editor_user_id": "5261",
"owner_user_id": "5261",
"post_type": "question",
"score": 1,
"tags": [
"c#",
"unity3d"
],
"title": "Reactive Extensionを使用して、ボタンリストの何番目のボタンが押されたかを知るには",
"view_count": 1035
}
|
[
{
"body": "各ループ中の変数に`i`の値を代入しておけばラムダ式から参照できます。\n\n```\n\n for(int i = 0; i < abc.Count; i++)\n {\n int n = i; // ループ内の変数に代入\n abc[i].Subscribe(\n _ => ButtonClicked(n)\n );\n \n }\n \n```\n\nなお`i`のスコープは各ループの外であるため最終的に値が`abc.Count`となり、参照すると意図した動作にはなりません。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T21:31:29.500",
"id": "17202",
"last_activity_date": "2015-10-02T21:31:29.500",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5750",
"parent_id": "17200",
"post_type": "answer",
"score": 2
},
{
"body": "ViewはPresenterに何を渡すんですか? \n`List<Button>`ですか? \n`List<IObservable<Unit>>`ですか?\n\nコードでpublicになっているので`List<Button>`で渡すとするなら、\n\n```\n\n List<Button> buttonList = new List<Button>(){ new Button() , new Button() , new Button() };\n \n //------\n \n foreach(var x in buttonList)\n {\n x.OnClickAsObservable().Subscribe(_ => ButtonClicked(buttonList.IndexOf(x)));\n }\n \n buttonList[0].Click(); //-> index=0\n buttonList[1].Click(); //-> index=1\n buttonList[2].Click(); //-> index=2\n \n```\n\n`List<IObservable<Unit>>`で渡そうとするなら \nそもそも通知したいのは「何番のボタンが押された」ですので、 \n`IObservable<int>`で渡すほうがいいと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-11-05T03:45:26.493",
"id": "18418",
"last_activity_date": "2015-11-05T04:08:24.560",
"last_edit_date": "2015-11-05T04:08:24.560",
"last_editor_user_id": "13127",
"owner_user_id": "13127",
"parent_id": "17200",
"post_type": "answer",
"score": 0
}
] |
17200
| null |
17202
|
{
"accepted_answer_id": "17205",
"answer_count": 1,
"body": "下記のコードのように`THREE.SCENE`インスタンスに、`THREE.MMD.PMX`インスタンスからメッシュを生成して追加したところ表示はできたのですが、`THREE.MMD.VMD`インスタンスを使用してアニメーションさせる手順が分かりません。\n\n`goml`の`<mmd model=\"foo.pmx\" motion=\"bar.vmd\"\nonLoad=\"parent.jThree.MMD.play(true);\"/>`と同等の処理を、プログラマティックに行う方法はありますか?\n\n```\n\n <script src=\"https://code.jquery.com/jquery-2.1.4.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/59naga/j3/3acd7a85f179a3ab02bae3c563e00ca90801b3b6/lib/jThree.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/59naga/j3/3acd7a85f179a3ab02bae3c563e00ca90801b3b6/lib/jThree.Stats.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/59naga/j3/3acd7a85f179a3ab02bae3c563e00ca90801b3b6/lib/jThree.MMD.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/59naga/j3/3acd7a85f179a3ab02bae3c563e00ca90801b3b6/lib/jThree.Trackball.js\"></script>\r\n <script src=\"http://coffeescript.org/extras/coffee-script.js\"></script>\r\n <script type=\"text/coffeescript\">\r\n # Private\r\n camera= null\r\n renderer= null\r\n trackball= null\r\n \r\n resize= ->\r\n camera= new THREE.PerspectiveCamera 45, innerWidth / innerHeight, 1, 1000\r\n camera.position.set 0, 20, 70\r\n renderer.setSize innerWidth,innerHeight\r\n \r\n trackball= new THREE.TrackballControls camera\r\n \r\n # Main\r\n window.addEventListener 'resize',->\r\n return unless renderer\r\n resize()\r\n \r\n # document.addEventListener 'DOMContentLoaded',->\r\n requestAnimationFrame ->\r\n scene= new THREE.Scene\r\n \r\n directionalLight= new THREE.DirectionalLight '#ffffff', 1\r\n directionalLight.position.set 0, 7, 10\r\n scene.add directionalLight\r\n \r\n geometry= new THREE.CubeGeometry 50, 1, 50\r\n material= new THREE.MeshLambertMaterial {color:'#999999'}\r\n cube= new THREE.Mesh geometry, material\r\n cube.position.set 0, -.5, 0\r\n scene.add cube\r\n \r\n pmx= new THREE.MMD.PMX\r\n pmx.load 'https://cdn.rawgit.com/59naga/j3/3acd7a85f179a3ab02bae3c563e00ca90801b3b6/example/miku/index.pmx',(pmx)->\r\n pmx.createMesh {},(mesh)->\r\n scene.add mesh\r\n \r\n vmd= new THREE.MMD.VMD\r\n vmd.load 'https://cdn.rawgit.com/59naga/j3/3acd7a85f179a3ab02bae3c563e00ca90801b3b6/example/miku/im5066365.vmd',(vmd)->\r\n cAnimation= vmd.generateCameraAnimation\r\n lAnimation= vmd.generateLightAnimation\r\n mAnimation= vmd.generateMorphAnimation pmx\r\n sAnimation= vmd.generateSkinAnimation pmx\r\n \r\n # do staff?\r\n \r\n requestAnimationFrame -> render()\r\n render= ->\r\n trackball.update() if trackball\r\n renderer.render scene,camera\r\n \r\n requestAnimationFrame render\r\n \r\n renderer=\r\n if window.WebGLRenderingContext\r\n new THREE.WebGLRenderer\r\n else\r\n new THREE.CanvasRenderer\r\n \r\n resize()\r\n \r\n document.body.appendChild renderer.domElement\r\n \r\n </script>\r\n <style>\r\n body {\r\n margin: 0;\r\n background-color: #abc;\r\n }\r\n </style>\n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-02T17:44:41.267",
"favorite_count": 0,
"id": "17201",
"last_activity_date": "2015-10-03T01:56:30.160",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9834",
"post_type": "question",
"score": 1,
"tags": [
"coffeescript",
"three.js"
],
"title": "jThree.jsのgomlを使用せず、`THREE.MMD.VMD`を使用してアニメーションさせたい",
"view_count": 233
}
|
[
{
"body": "静止して立ったままのポーズで分かりにくいですが、まばたきや動きのある.vmdを使用しても動作するようなコードが用意できたので、自己解決とさせて頂きます。\n\n> 参考:[jThree.MMD.js…`<goml>`を使用せずアニメーションさせたい · Issue #2 ·\n> j3-jp/jThree](https://github.com/j3-jp/jThree/issues/2)\n```\n\n <style>\r\n body {\r\n margin: 0;\r\n background-color: #abc;\r\n }\r\n </style>\r\n <script src=\"https://code.jquery.com/jquery-2.1.4.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/59naga/j3/e19f703b64e1f088aa8be484e75ded9a698489e3/lib/jThree.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/59naga/j3/e19f703b64e1f088aa8be484e75ded9a698489e3/lib/jThree.Stats.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/59naga/j3/e19f703b64e1f088aa8be484e75ded9a698489e3/lib/jThree.MMD.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/59naga/j3/e19f703b64e1f088aa8be484e75ded9a698489e3/lib/jThree.Trackball.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/mrdoob/stats.js/6b5cba034e5a30941b01da3fa785da49338fa676/build/stats.min.js\"></script>\r\n <script src=\"http://coffeescript.org/extras/coffee-script.js\"></script>\r\n <script type=\"text/coffeescript\">\r\n # Private\r\n camera= null\r\n renderer= null\r\n trackball= null\r\n \r\n resize= ->\r\n camera= new THREE.PerspectiveCamera 45, innerWidth / innerHeight, 1, 1000\r\n camera.position.set 0, 20, 70\r\n renderer.setSize innerWidth,innerHeight\r\n \r\n trackball= new THREE.TrackballControls camera\r\n \r\n # Main\r\n window.addEventListener 'resize',->\r\n return unless renderer\r\n resize()\r\n \r\n # document.addEventListener 'DOMContentLoaded',->\r\n requestAnimationFrame ->\r\n stats= new Stats\r\n stats.domElement.style.position= 'absolute'\r\n stats.domElement.style.left= '0px'\r\n stats.domElement.style.top= '0px'\r\n \r\n scene= new THREE.Scene\r\n \r\n directionalLight= new THREE.DirectionalLight '#ffffff', 1\r\n directionalLight.position.set 0, 7, 10\r\n scene.add directionalLight\r\n \r\n geometry= new THREE.CubeGeometry 50, 1, 50\r\n material= new THREE.MeshLambertMaterial {color:'#999'}\r\n cube= new THREE.Mesh geometry, material\r\n cube.position.set 0, -.5, 0\r\n scene.add cube\r\n \r\n endless= yes\r\n pmx= new THREE.MMD.PMX\r\n pmx.load 'https://cdn.rawgit.com/59naga/j3/e19f703b64e1f088aa8be484e75ded9a698489e3/example/miku/index.pmx',(pmx)->\r\n pmx.createMesh {},(mesh)->\r\n vmd= new THREE.MMD.VMD\r\n vmd.load 'https://cdn.rawgit.com/59naga/j3/e19f703b64e1f088aa8be484e75ded9a698489e3/example/miku/im5066365.vmd',(vmd)->\r\n # vmd.load 'bower_components/j3/example/miku/im5066365.vmd',(vmd)->\r\n hasAd= pmx.bones.some (bone)-> bone.additionalTransform\r\n addTrans= new THREE.MMD.MMDAddTrans pmx, mesh if hasAd\r\n \r\n mAnimation= vmd.generateMorphAnimation pmx\r\n morph= new THREE.MMD.MMDMorph mesh, mAnimation if mAnimation\r\n morph.play endless if morph\r\n \r\n sAnimation= vmd.generateSkinAnimation pmx\r\n skin= new THREE.MMD.MMDSkin mesh, sAnimation if sAnimation\r\n skin.play endless if skin\r\n \r\n delta= 0\r\n if mesh.geometry.MMDIKs.length\r\n ik= new THREE.MMD.MMDIK mesh\r\n physi= new THREE.MMD.MMDPhysi mesh if window.Ammo\r\n \r\n renderer.renderPluginsPre.unshift\r\n render: ->\r\n if window.Ammo\r\n physi.preSimulate delta if physi\r\n THREE.MMD.btWorld.stepSimulation delta\r\n physi.postSimulate delta if physi\r\n \r\n scene.add mesh\r\n \r\n resetBone= ->\r\n bones= mesh.bones;\r\n for bone,i in mesh.geometry.bones\r\n mesh.bones[i].position.set bone.pos[0], bone.pos[1], bone.pos[2]\r\n mesh.bones[i].quaternion.set bone.rotq[0], bone.rotq[1], bone.rotq[2], bone.rotq[3]\r\n \r\n clock= new THREE.Clock\r\n requestAnimationFrame -> render()\r\n render= ->\r\n delta= clock.getDelta()\r\n stats.begin()\r\n \r\n resetBone()\r\n \r\n morph.update delta if morph\r\n skin.update delta if skin\r\n ik.update delta if ik\r\n addTrans.update delta if addTrans\r\n \r\n trackball.update() if trackball\r\n \r\n renderer.render scene,camera\r\n \r\n stats.end()\r\n requestAnimationFrame render\r\n \r\n renderer=\r\n if window.WebGLRenderingContext\r\n new THREE.WebGLRenderer\r\n else\r\n new THREE.CanvasRenderer\r\n \r\n resize()\r\n \r\n document.body.appendChild renderer.domElement\r\n document.body.appendChild stats.domElement\r\n </script>\n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T01:50:30.723",
"id": "17205",
"last_activity_date": "2015-10-03T01:56:30.160",
"last_edit_date": "2015-10-03T01:56:30.160",
"last_editor_user_id": "9834",
"owner_user_id": "9834",
"parent_id": "17201",
"post_type": "answer",
"score": 0
}
] |
17201
|
17205
|
17205
|
{
"accepted_answer_id": "17224",
"answer_count": 1,
"body": "iOS8以降で、ソフトの初期値を保存しておくにはどうしたらいいでしょうか?\n\n初期値の変更も保存したいのですが・・・\n\nよろしくお願いします。\n\nswift\n\n```\n\n // 「ud」というインスタンスをつくる。\n let ud = NSUserDefaults.standardUserDefaults()\n \n // キーがidの値をとります。\n var udId : AnyObject! = ud.objectForKey(\"id\")\n \n // これで表示してみたり。\n print(udId)\n \n // キーidに「taro」という値を格納。(idは任意の文字列でok)\n ud.setObject(\"taro\", forKey: \"id\")\n \n // キーidの値を削除\n ud.removeObjectForKey(\"id\")\n \n```\n\nサンプル\n\n```\n\n import UIKit\n \n class ViewController: UIViewController {\n \n override func viewDidLoad() {\n super.viewDidLoad()\n // Do any additional setup after loading the view, typically from a nib.\n }\n \n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n // Dispose of any resources that can be recreated.\n }\n \n @IBAction func display() {\n let ud = NSUserDefaults.standardUserDefaults()\n var udId : AnyObject! = ud.objectForKey(\"id\")\n println(udId)\n }\n \n @IBAction func put() {\n let ud2 = NSUserDefaults.standardUserDefaults()\n ud2.setObject(\"taro\", forKey: \"id\")\n }\n \n @IBAction func delete() {\n let ud3 = NSUserDefaults.standardUserDefaults()\n ud3.removeObjectForKey(\"id\")\n }\n \n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T03:34:01.050",
"favorite_count": 0,
"id": "17207",
"last_activity_date": "2015-10-04T01:55:36.123",
"last_edit_date": "2015-10-04T01:55:36.123",
"last_editor_user_id": "10845",
"owner_user_id": "10845",
"post_type": "question",
"score": 0,
"tags": [
"ios8",
"xcode7"
],
"title": "初期設定値とその変更値を保存しておくには?",
"view_count": 210
}
|
[
{
"body": "`NSUserDefaults`クラスを使います。これはiOSのバージョンに関係ありません。iOS8以前と以降で、変化することはありません。\n\n[NSUserDefaults Class\nReference](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/)",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T13:08:31.250",
"id": "17224",
"last_activity_date": "2015-10-03T13:08:31.250",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7362",
"parent_id": "17207",
"post_type": "answer",
"score": 0
}
] |
17207
|
17224
|
17224
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Vagrantで、CentOSを導入し、ruby on railsの開発環境を構築しました。\n\nherokuをインストール後、\n\n```\n\n git push heroku master\n \n```\n\nで、Herokuにリポジトリをプッシュし、\n\n```\n\n heroku open\n \n```\n\nを打つと以下のエラーが出ます。\n\n```\n\n [vagrant@vagrant-centos65 sample]$ heroku open\n Opening peaceful-bayou-2427... failed\n ! Heroku client internal error.\n ! Search for help at: https://help.heroku.com\n ! Or report a bug at: https://github.com/heroku/heroku/issues/new\n \n Error: Unable to find a browser command. If this is unexpected, Please rerun with environment variable LAUNCHY_DEBUG=true or the '-d' commandline option and file a bug at https://github.com/copiousfreetime/launchy/issues/new (Launchy::CommandNotFoundError)\n Command: heroku open\n Version: heroku-toolbelt/3.42.15 (x86_64-linux) ruby/2.0.0\n Error ID: c716dec578b84cc4805fea546d15328b\n \n \n More information in /home/vagrant/.heroku/error.log\n \n```\n\n色々原因を調べてみたのですが、結局解決できず困っています。。\n\nどうすればいいのかご存知の方、教えていただきたいです。 \nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T05:17:12.647",
"favorite_count": 0,
"id": "17208",
"last_activity_date": "2015-12-02T15:13:04.443",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12549",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"heroku",
"vagrant"
],
"title": "vagrant上でheroku openが出来ないです",
"view_count": 552
}
|
[
{
"body": "`/home/vagrant/.heroku/error.log`も見た方が確実ですがブラウザが見つけられないようですね。 \n(同じ環境が手元に無いため、以下はすべて推測になります)\n\nherokuコマンドが使うブラウザは環境変数`BROWSER`で変更できるらしいので、例えばFirefoxを使うならば、\n\n```\n\n BROWSER=firefox heroku open\n \n```\n\nと実行するか、あらかじめ\n\n```\n\n export BROWSER=firefox\n \n```\n\nのように設定しておけばよいはずです。\n\nしかし、開発用の仮想環境にはGUIのブラウザなどインストールしていないかもしれません。 \nその場合w3m, lynx, wget, curlなどのツールを利用する手もありますが、あきらめてホスト側で閲覧するのが快適でしょう。 \n下記のように`BROWSER`を`echo`にしておけば`heroku\nopen`でURLが出力されると思うので、それを普段利用しているブラウザで開けばよいのではないでしょうか。\n\n```\n\n BROWSER=echo heroku open\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T14:07:11.863",
"id": "17226",
"last_activity_date": "2015-10-03T14:07:11.863",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "17208",
"post_type": "answer",
"score": 1
}
] |
17208
| null |
17226
|
{
"accepted_answer_id": "17210",
"answer_count": 1,
"body": "空の新規ファイルにtemplate.txtの内容を1行目に挿入したいです。 \ntemplate.txtの中身はこの3行、cの最後に改行はありません。\n\n```\n\n a\n b\n c\n \n```\n\n試したコマンド\n\n```\n\n :execute '0r template.txt'\n \n```\n\nもうひとつ\n\n```\n\n :0r !cat template.txt\n \n```\n\nどれも最後に改行が含まれてしまい、4行になってしまいます。 \ntemplate.txtと同じ内容になるように挿入する方法を教えてください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T06:43:48.820",
"favorite_count": 0,
"id": "17209",
"last_activity_date": "2015-10-03T06:53:51.227",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10022",
"post_type": "question",
"score": 2,
"tags": [
"vim"
],
"title": "新規ファイルを開いた時にテキストファイルの内容を挿入したい",
"view_count": 144
}
|
[
{
"body": "1行目を削除すれば大丈夫です。\n\n`read template.txt | 1 delete _`",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T06:53:51.227",
"id": "17210",
"last_activity_date": "2015-10-03T06:53:51.227",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2541",
"parent_id": "17209",
"post_type": "answer",
"score": 2
}
] |
17209
|
17210
|
17210
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "自分のサイトにOGPタグを付けてオブジェクトデバッガーでテストしました。 \n結果以下の様なエラーが出ます。一見、プレビューでは正しく動いているように見えますが・・・。\n\n\"Object at URL '<https://makeyourownemblem.herokuapp.com/>' of type 'article'\nis invalid because the given value\n'/assets/makeyourownemblem-6b8a416ab775207c550c1ed587fdfc250bca16ff190fef9bc8bb5b8f40630f1f.png'\nfor property 'og:image:url' could not be parsed as type 'url'.\"\n\nこれは何が問題なのでしょうか?ご存知のかたご教示ください。 \nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T06:59:18.053",
"favorite_count": 0,
"id": "17212",
"last_activity_date": "2015-10-03T12:58:19.053",
"last_edit_date": "2015-10-03T12:58:19.053",
"last_editor_user_id": "3639",
"owner_user_id": "4784",
"post_type": "question",
"score": 1,
"tags": [
"facebook",
"open-graph-protocol"
],
"title": "'og:image:url' could not be parsed as type 'url'",
"view_count": 123
}
|
[
{
"body": "`og:image:url`の値が URL としてパースできないと書かれていますね。 \nパスは URL と見なされないという事だと思います。ドメインなども含めて記述する必要がありそうです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T07:37:07.583",
"id": "17213",
"last_activity_date": "2015-10-03T07:37:07.583",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "17212",
"post_type": "answer",
"score": 1
}
] |
17212
| null |
17213
|
{
"accepted_answer_id": "17250",
"answer_count": 6,
"body": "クロージャーの理解に苦慮しています。 \n以下にサンプルプログラムを添付します。swiftプログラムです。 \n動作については理解していますが、関数(func)内の関数で、内部の関数はその外の変数にアクセス可能というクロージャーの理解はしています。疑問点は以下の通りです。\n\n```\n\n let inc = makeIncrementer(10, 5)\n \n```\n\nによって、incの定数に\"15\"が設定されますよね。\n\n```\n\n inc() // 15\n \n```\n\nで、inc()とは何?という疑問があります。またinc()を繰り返す度に5が足されるのか、makeIncrementerのaddValueの値が5を足されると思いますが、var\nvがなぜ値を保持しているのかも疑問です。\n\n何か理解が間違っていると思いますので、教えていただけないでしょうか?質問を端的に言うとinc()とは何?ということです。\n\n以下、リストを添付します。よろしくお願いします。\n\n```\n\n func makeIncrementer(initValue: Int, addValue: Int) -> () -> Int {\n var v = initValue\n func incrementer() -> Int {\n v += addValue\n return v\n }\n \n return incrementer\n }\n \n let inc = makeIncrementer(10, 5)\n inc() // 15\n inc() // 20\n inc() // 25\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T08:08:29.900",
"favorite_count": 0,
"id": "17214",
"last_activity_date": "2015-10-05T14:16:38.130",
"last_edit_date": "2015-10-05T12:54:05.720",
"last_editor_user_id": "8000",
"owner_user_id": "8593",
"post_type": "question",
"score": 5,
"tags": [
"swift",
"クロージャ"
],
"title": "func内の変数保持について(クロージャーの理解)",
"view_count": 4608
}
|
[
{
"body": "[詳解Swift 荻原剛志著](http://www.sbcr.jp/products/4797380491.html)\n\nこの書籍の、「Chapter12 クロージャ、12.2\n変数のキャプチャ」に、説明があります。ひとことで説明すると、クロージャがローカル変数を参照し続けているので、ローカル変数は解放されず、メモリに保持されたままになる、ということだそうです。誤解を与えてはいけないので、詳しくは、この書籍に直接あたってください。\n\nクロージャ(というより、この場合はネスト関数)を解放すれば、ローカル変数も解放されます。\n\n```\n\n // 解放されるタイミングを調べるため、deinitを実装したクラスを定義する。\n class MyClass {\n var lValue: Int = 0\n \n init(lValue: Int) {\n self.lValue = lValue\n }\n \n deinit {\n print(\"Released with \\(lValue)\") // 解放された時点のlValueの値を出力\n }\n }\n \n func makeIncrementer(lValue a: MyClass, rValue b: Int) -> () -> Int {\n var innerValue = a.lValue\n func incrementer() -> Int {\n innerValue += b\n a.lValue = innerValue\n return innerValue\n }\n return incrementer\n }\n \n // nilを代入して解放するためにOptional型で宣言する。\n var myClass: MyClass! = MyClass(lValue: 20)\n // nilを代入して解放するためにOptional型で宣言する。\n var innerFunc: (() -> Int)! = makeIncrementer(lValue: myClass, rValue: 10) // 20に10を加算する。\n innerFunc() // 30\n innerFunc() // 40\n myClass = nil // myClassを解放しようとするが、deinitが呼ばれない。\n innerFunc() // 50 \n innerFunc = nil // 出力:Released with 50\n // innerFuncを解放した時点で、myClassが解放されたことがわかる。\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T09:45:51.283",
"id": "17216",
"last_activity_date": "2015-10-04T04:07:39.953",
"last_edit_date": "2015-10-04T04:07:39.953",
"last_editor_user_id": "7362",
"owner_user_id": "7362",
"parent_id": "17214",
"post_type": "answer",
"score": 0
},
{
"body": ">\n```\n\n> let inc = makeIncrementer(10, 5)\n> \n```\n\n>\n> によって、incの定数に\"15\"が設定されますよね。\n\nちがいます。これにより`inc`が保持するのは関数オブジェクトです。`makeIncrementer`の定義を見れば分かるようにreturnしているのはIntではなく`incrementer`という関数です。この時点では、関数オブジェクトが作られただけで、まだ実行されていません。\n\nこのようにして作られた関数オブジェクトはその後の\n\n```\n\n inc()\n \n```\n\nで始めて実際に実行されます。\n\n`incrementer`の中で参照されている`v`や`addValue`のスコープは、`makeIncrementer`ローカルです。本来は`incrementer`を抜けた時点で消滅するのですが、クロージャである`incrementer`が`v`や`addValue`を参照し続けているため、スコープを抜けても残ったままになります。そのため、`addValue`は`makeIncrementer`を呼び出したときの`5`がいつまでも残っていますし、`v`は実行する度に5ずつ増えていきます。\n\nなお、もう一度`makeIncrementer`を呼び出したときにまた作られる`v`や`addValue`や関数オブジェクトは先ほど作成したものとは別になります。\n\n```\n\n let inc = makeIncrementer(10, 5)\n inc() // 15\n let inc2 = makeIncrementer(3, 1)\n inc2() // 4\n inc() // 20\n inc2() //5\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T23:14:30.770",
"id": "17235",
"last_activity_date": "2015-10-04T10:09:53.777",
"last_edit_date": "2015-10-04T10:09:53.777",
"last_editor_user_id": "5793",
"owner_user_id": "5793",
"parent_id": "17214",
"post_type": "answer",
"score": 3
},
{
"body": "> var vがなぜ値を保持しているのかも疑問です。\n\nSwift の開発環境が手元にないので、golang で同じ様なモノを書いてみました。\n\n**counter.go**\n\n```\n\n package main\n \n import \"fmt\"\n \n func newCounter(initValue, addValue int) (func() int, func() int, func()) {\n v := initValue\n \n inc := func() int {\n v += addValue\n return v\n }\n \n get := func() int {\n return v\n }\n \n reset := func() {\n v = initValue\n }\n \n return inc, get, reset\n }\n \n func main() {\n inc, get, reset := newCounter(10, 5)\n \n fmt.Println(inc()) // => 15\n fmt.Println(inc()) // => 20\n reset()\n fmt.Println(get()) // => 10\n }\n \n```\n\nもっと本来的な書き方があるはずですが、それはさておいて、`newCounter` 関数内にある変数 `v` がどの様に扱われているのかを見てみます。\n\n```\n\n $ go run -gcflags='-m=1' counter.go\n :\n ./counter.go:6: moved to heap: v // v := initValue\n ./counter.go:9: &v escapes to heap // v += addValue (in inc())\n ./counter.go:14: &v escapes to heap // return v (in get())\n ./counter.go:18: &v escapes to heap // v = initValue (in reset())\n \n```\n\nスタック領域ではなくヒープ領域に移動させられていて、そのメモリ領域を `inc()`, `get()`, `reset()`\n関数では参照しています。おそらく、swift でも同じ事をしているのではないかと推測します。\n\n# 処理系の中には必要に応じて被参照変数をスタック <-> ヒープ間でコピーしていたりします",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T10:20:30.763",
"id": "17245",
"last_activity_date": "2015-10-04T10:20:30.763",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "17214",
"post_type": "answer",
"score": 1
},
{
"body": "> Swift closures and Objective-C blocks are compatible, so you can pass Swift\n> closures to Objective-C methods that expect blocks. Swift closures and\n> functions have the same type, so you can even pass the name of a Swift\n> function.\n>\n> Closures have similar capture semantics as blocks but differ in one key way:\n> Variables are mutable rather than copied. In other words, the behavior of\n> __block in Objective-C is the default behavior for variables in Swift.\n>\n> [Interacting with Objective-C APIs - Using Swift with Cocoa and Objective-C\n> (Swift\n> 2)](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-\n> CAPIs.html)\n\nにある通り、Swiftのクロージャは、Objective-Cのblocksと互換性を持つものです。\n\nそちらの実装については公開されている情報が多いため、blocksについて知ることでクロージャについて理解が深まると思います。\n\n両者の動作のの違いとして、Objective-\nCにおけるblocksは、自動変数のキャプチャを値のコピーで行っていましたが、Swiftのクロージャでは常に`__block`が指定されているものとして扱います。\n\nさて、blocksがどう実装されているかというと、この実体はObjective-\nCクラスのインスタンスです(この説明は厳密には正しくないのですが、Swiftにおいてクロージャが参照型に分類されていることから、クラスだと考えた方が楽だと思います)。\n\n変数のキャプチャは、このクラスのインスタンス変数になることを意味します。Swiftでは必ず`__block`指定子でキャプチャされることは既に述べました。このとき、`__block`ストレージ型として扱われます。\n\n> __block変数は、その変数のレキシカルスコープと、その変数のレキシカルスコープ内で宣言または \n> 作成されたすべてのブロックおよびブロックのコピーとの間で共有されるストレージ内に存在しま \n> す。したがって、このストレージは、スタックフレーム内で宣言されているブロックのコピーが、フ \n> レームの終了後も存続する場合は(たとえば、後で実行するために、どこかのキューに入れられてい \n> る場合)、そのスタックフレームが破棄された後も存続します。特定のレキシカルスコープ内の複数 \n> のブロックが、同時に1つの共有変数を使用できます。\n>\n> 最適化のために、ブロックストレージは、ブロック自身と同様に、スタック上に置かれます。 \n> Block_copyを使用してブロックがコピーされた場合(または、Objective-Cで、そのブロックにcopy \n> が送信された場合)は、変数はヒープにコピーされます。したがって、__block変数のアドレスは時 \n> 間の経過とともに変化する可能性があります。\n>\n> [ブロックプログラミングトピック](https://developer.apple.com/jp/documentation/Blocks.pdf)\n\n要約すると、ローカル変数や関数の引数など、現在の環境(レキシカルスコープ)を、ランタイムが上手く管理することで、共有できるようにしてくれる、ということです。\n\nObjective-\nCにおいては、blocksをスタックもしくはヒープのどちらで管理するべきかコンパイラが判断できなかった場合に、必要に応じて明示的に`copy`を呼ぶ辛い場面もありましたが、Swiftのクロージャでは意識する必要はありません。\n\n`__block`ストレージ型の`var\nv`をインスタンス変数に持つ、クロージャ`incrementer`が、`inc`の正体である…、と考えるのが比較的分かりやすいと思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T12:17:06.623",
"id": "17246",
"last_activity_date": "2015-10-04T12:17:06.623",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5337",
"parent_id": "17214",
"post_type": "answer",
"score": 5
},
{
"body": "`inc()`は、`let inc`の定数名に、incrementer関数へ渡す引き数`()`をつけたものです。inc\nは、incrementerの略だと思われます。\n\n関数は、引き数を渡した時点で `return`にあるものを返しますから、makeIncrementer関数内の\n\n```\n\n return incrementer\n \n```\n\nでは、まだ incrementer関数の引き数は渡していないため、incrementer関数は実行されていません。これは、incrementer関数への\n**参照** を`return`で返している状態です。\n\n```\n\n let inc = makeIncrementer(10, 5)\n \n```\n\nでは、makeIncrementer関数のパラメータ`(initValue: Int, addValue: Int)`に適合する引き数`(10,\n5)`を渡していますので、makeIncrementer関数が実行されています。`() -> Int`という関数型の関数\nincrementerへの参照が`return`で返され、定数 incに割り当てられています。定数名を Option+クリックすると、定数\nincが関数型となっている様子が確認できます。(Playgroundでは右側でも見れます。)\n\n[](https://i.stack.imgur.com/gVdui.png)\n\nですが、incrementer関数のパラメータ`()`に適合する引き数`()`は渡されていないため、incrementer関数はまだ実行されていません。Int型の`15`という値は返ってきていません。定数\nincは、incrementer関数を参照している状態です。\n\n`let inc` → `func incrementer`を参照 \n`func incrementer` → `func makeIncrementer` の`var v`と`addValue`を参照\n\nと、`let inc`から makeIncrementer関数のローカル変数/定数まで、参照がつながっています。`let inc`が\nincrementer関数を参照している限り、`var v`と`addValue`も参照され続けるということです。\n\n参照されている間は状態が維持されますから、makeIncrementer関数の実行が終わっても、v変数と\naddValue定数は存在し続けます。inc定数からの参照の連鎖が、v変数と addValueを繋ぎとめているからです。仮に、\n\n```\n\n let inc = makeIncrementer(10, 5)()\n \n```\n\nとここで、incrementer関数の引き数`()`を渡すと、`Int`が`return`で返されて、関数は実行終了となります。定数\nincに、Int型の`15`が入った状態です。この定数 incと incrementer関数は参照関係にはなりません。\n\n[](https://i.stack.imgur.com/6O0U5.png)\n\n参照関係のときに何が起きているかを確かめるために、以下のように、コードの各所に`print`を追加してみてはいかがでしょうか。 (Xcode 7、Swift\n2で書いています。)\n\n```\n\n func makeIncrementer(initValue: Int, addValue: Int) -> () -> Int {\n print(\"makeIncrementer関数の実行\")\n print(\"initValue: \\(initValue), addValue: \\(addValue)\")\n \n var v = initValue\n print(\"makeIncrementer内 var v = \\(v)\")\n \n func incrementer() -> Int {\n print(\"incrementer関数の実行\")\n print(\"参照している v = \\(v), addValue = \\(addValue)\")\n \n v += addValue\n print(\"incrementer return v = \\(v)\")\n return v\n }\n return incrementer\n }\n \n print(\"----- let inc 宣言 -----\")\n let inc = makeIncrementer(10, addValue: 5)\n \n print(\"----- inc() 1回目 -----\")\n inc()\n \n print(\"----- inc() 2回目 -----\")\n inc()\n \n print(\"----- inc() 3回目 -----\")\n inc()\n \n```\n\nコンソールを見ると、`inc()`が、makeIncrementer関数は実行しないで、incrementer関数だけを実行している様子が確認できます。inc定数は、makeIncrementer関数ではなく、incrementer関数を直に参照しているからです。\n\n[](https://i.stack.imgur.com/DLFcz.png)\n\n`inc()`を呼び出したときに、新たに`initValue`に`10`が代入されて……というような\nmakeIncrementer関数の処理は行われません。よって、v変数に新しい\ninitValue値が代入されることもありません。このincrementer関数が参照している`v`は、関数実行終了後も\ninc定数から続く参照によってそのまま保持され、また新たに別の場所で`inc()`と書いてincrementer関数を呼び出しても、inc定数から続く参照の連鎖につながっているままの値を使うことになる、という訳です。\n\n定数や変数は、値や参照を保持するのが仕事ですから、定数や変数から参照の連鎖がつながっているローカル変数/定数は結果、保持されることになります。関数は処理を実行するのが仕事ですから、関数のクロージャ内から外の変数/定数への参照は、実行時のみの一時的なものとなります。が、定数や変数がその関数を参照している場合には、定数/変数が参照の連鎖をどこまでもたどって、参照状態とその先にある値を保持してくれるようです。(厳密にシステムがどう働くかという視点で見ると、この説明はちょっと違うと思いますが、今ひとまずのところはこのようなイメージが理解の助けになるのではないでしょうか。詳しいことは、他の方のご回答をご覧いただければと思います。)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T20:35:16.473",
"id": "17250",
"last_activity_date": "2015-10-05T14:16:38.130",
"last_edit_date": "2015-10-05T14:16:38.130",
"last_editor_user_id": "9833",
"owner_user_id": "9833",
"parent_id": "17214",
"post_type": "answer",
"score": 2
},
{
"body": "他の方の回答で「何が起きているか」についての説明は十分と思いますが、関連するキーワードが出ていないので補足します。\n\nプログラミング言語の一般的概念として、変数には「スコープ」と「エクステント」という属性があります。「スコープ」はその変数がコードのどの場所から見えるのか、「エクステント」はその変数がいつからいつまで存在するのか、です。\n\n例えばCでは以下の変数がサポートされています:\n\n * グローバル変数: スコープはプログラム全体。エクステントはプログラム起動から終了まで\n * トップレベルのstatic変数: スコープはファイル内。エクステントはプログラム起動から終了まで\n * 関数内static変数: スコープは関数内。エクステントはプログラム起動から終了まで\n * auto変数: スコープはブロック内。エクステントは変数の定義からブロックを抜けるまで\n\nこのうち、最後のauto変数を「ローカル変数」と呼ぶことが多いです。このことから、Cおよびその派生言語では「ローカル変数」というのに「スコープもエクステントもブロック内のみ」というイメージがついてしまっています。\n\nしかし、他の言語、特に関数オブジェクト(第一級関数)を持つ言語では「ローカル変数」は\n\n * スコープはブロック内。エクステントはそのブロックに入った後からずっと\n\nとすることが多いです。ずっと、というのは意味的にはプログラム終了までずっと存在し続けるということです。現実には、どこからも参照されなくなった時点でGCが回収してくれるのでメモリの心配をする必要はありませんが。\n\n今回の例で言えば、var\nvのスコープはmakeIncrementerの中、つまりその中に書かれたコードからしか読み書きできないが、makeIncrementerに入るたびに新たなvが作られて、それは(GCで回収されるまで)ずっとメモリ上に残っている(無限エクステント)、ということになります。\n\nCのauto変数のようにスコープとエクステントをブロックに合わせる方式では、変数はスタックで管理できますが、「ブロックスコープ、無限エクステント」のローカル変数では管理は多少複雑になります。が、そのへんは言語処理系がうまい具合に取り計らってくれるので、性能チューニングをしているのでもなければあまり気にする必要はありません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T21:45:53.943",
"id": "17251",
"last_activity_date": "2015-10-04T21:45:53.943",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5258",
"parent_id": "17214",
"post_type": "answer",
"score": 3
}
] |
17214
|
17250
|
17246
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "sample.mp3というデータを再生しようとするときに「引数が足りない」というエラーがでてしまいます。もしご存知の方は、ご指摘いただけますようお願いします。\n\n```\n\n override func viewDidLoad() {\n super.viewDidLoad()\n \n let sound_data = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(\"sample\", ofType: \"mp3\")!)\n var audioPlayer: AVAudioPlayer = AVAudioPlayer(contentsOfURL: sound_data, error: nil)//ここでエラーがでてしまいます。\n audioPlayer.play()\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T09:36:44.243",
"favorite_count": 0,
"id": "17215",
"last_activity_date": "2017-01-04T03:29:44.153",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12536",
"post_type": "question",
"score": -1,
"tags": [
"swift"
],
"title": "音声再生時のエラー",
"view_count": 918
}
|
[
{
"body": "Swift 2から`try`, `catch`, `throw`という新しい構文が導入され、エラー処理の仕組みが大きく変わりました。\n\n<https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html#//apple_ref/doc/uid/TP40014097-CH42-ID508>\n\n同時に`NSError`のダブルポインタを取るメソッドは自動的に`throws`に変換されるようになったので、`NSError`の引数は無くなりました。変わりに、`try`を付けてメソッドを呼び出す必要があります。\n\n```\n\n let sound_data = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(\"sample\", ofType: \"mp3\")!)\n do {\n let audioPlayer = try AVAudioPlayer(contentsOfURL: sound_data)\n audioPlayer.play()\n } catch let error as NSError {\n print(error)\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T18:35:26.493",
"id": "17231",
"last_activity_date": "2015-10-04T06:53:10.240",
"last_edit_date": "2015-10-04T06:53:10.240",
"last_editor_user_id": "7362",
"owner_user_id": "5519",
"parent_id": "17215",
"post_type": "answer",
"score": 0
}
] |
17215
| null |
17231
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "OSの言語モードを調べる方法はありますか? \n一応、ドキュメントを探したものの見つけられませんでした。\n\nOSの設定に合わせてメッセージ(日本語 or 英語)を表示させたいと思っています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T10:44:15.943",
"favorite_count": 0,
"id": "17217",
"last_activity_date": "2015-10-03T11:18:03.377",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12441",
"post_type": "question",
"score": 2,
"tags": [
"android",
"ios",
"monaca"
],
"title": "OSの表示言語を調べる方法はありますか?",
"view_count": 149
}
|
[
{
"body": "Monaca(Cordova)だと\n[navigator.globalization.getPreferredLanguage](http://docs.monaca.mobi/cur/ja/reference/phonegap_34/ja/globalization/#navigator-\nglobalization-getpreferredlanguage) が使えそうですね。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T11:18:03.377",
"id": "17218",
"last_activity_date": "2015-10-03T11:18:03.377",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "17217",
"post_type": "answer",
"score": 1
}
] |
17217
| null |
17218
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Facebookのオブジェクトデバッガーで以下のURLをチェックしたところ \n<https://makeyourownemblem.herokuapp.com/showemblem/2> \n「We're sorry, but something went wrong」 \nと出てしまい、全くOGPタグを認識しません。\n\nこれは何が悪いのでしょうか?ちなみにOGPはこんな感じです。どこも悪くなさそうに見えます。\n\n```\n\n <meta property=\"og:title\" content=\"Make Your Own Emblem\" />\n <meta property=\"og:type\" content=\"article\" />\n <meta property=\"og:url\" content=\"https://makeyourownemblem.herokuapp.com/\" />\n <meta property=\"og:image\" content=\"https://makeyourownemblem.herokuapp.com/assets/makeyourownemblem-6b8a416ab775207c550c1ed587fdfc250bca16ff190fef9bc8bb5b8f40630f1f.png\" />\n <meta property=\"og:site_name\" content=\"Make Your Own Emblem\" />\n <meta property=\"og:description\" content=\"This App Make Your Emblem. You might be able to submit this instead of existing candidate for 2020!!\" />\n <meta property=\"og:locale\" content=\"ja_JP\" />\n <meta property=\"fb:admins\" content=\"618693892\" />\n <meta property=\"fb:app_id\" content=\"1659344774309585\" />\n \n```\n\nどなたかご存知のかたよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T12:23:36.067",
"favorite_count": 0,
"id": "17221",
"last_activity_date": "2020-10-18T07:15:43.943",
"last_edit_date": "2015-10-03T12:46:18.910",
"last_editor_user_id": "3639",
"owner_user_id": "4784",
"post_type": "question",
"score": 0,
"tags": [
"facebook",
"open-graph-protocol"
],
"title": "FB Object Debugger でWe're sorry, but something went wrong",
"view_count": 119
}
|
[
{
"body": "おそらくRuby on Railsで作成中の Webアプリケーションかと思いますが、それのエラー(500)です。 \nエラーメッセージですのでOGPタグも含まれていない筈です。問題のURLにブラウザでアクセスして確認してみて下さい。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T12:55:42.577",
"id": "17222",
"last_activity_date": "2015-10-03T12:55:42.577",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "17221",
"post_type": "answer",
"score": 1
}
] |
17221
| null |
17222
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "homebrewを利用してインストールしたpostgresqlの初期化が失敗してしまいます。\n\n状況 \nmacbook airからproへ買い替えデータの移行を実施 \nrailsでサーバアクセス時に下記エラーが発生\n\n```\n\n PG::ConnectionBad (could not connect to server: No such file or directory\n Is the server running locally and accepting\n connections on Unix domain socket \"/tmp/.s.PGSQL.5432\"?\n ):\n \n```\n\n一度、postgresql(9.4.4)をhomebrewからアンインストールして再度インストール。 \n`initdb /usr/local/var/postgres -E utf8`を実施するも下記エラーが発生\n\n```\n\n The files belonging to this database system will be owned by user \"Kuma\".\n This user must also own the server process.\n \n The database cluster will be initialized with locale \"ja_JP.UTF-8\".\n initdb: could not find suitable text search configuration for locale \"ja_JP.UTF-8\"\n The default text search configuration will be set to \"simple\".\n \n Data page checksums are disabled.\n \n initdb: directory \"/usr/local/var/postgres\" exists but is not empty\n If you want to create a new database system, either remove or empty\n the directory \"/usr/local/var/postgres\" or run initdb\n with an argument other than \"/usr/local/var/postgres\".\n \n```\n\n[ここ](https://stackoverflow.com/questions/27700596/homebrew-postgres-\nbroken)を参考にJamesさんの回答通り下記コマンドを実行。 \n`rm -rf /usr/local/var/postgres` \nさらに`mkdir /usr/local/var/postgres`を実施するも \n`mkdir: /usr/local/var/postgres: File exists`とフォルダがかってに作成されておりうまくいきません。 \nどなたか本件の解決方法知らないでしょうか?",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T12:59:16.293",
"favorite_count": 0,
"id": "17223",
"last_activity_date": "2015-10-03T12:59:16.293",
"last_edit_date": "2017-05-23T12:38:56.467",
"last_editor_user_id": "-1",
"owner_user_id": "12232",
"post_type": "question",
"score": 1,
"tags": [
"macos",
"postgresql"
],
"title": "postgresqlの初期化失敗 (homebrew使用)",
"view_count": 822
}
|
[] |
17223
| null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "<https://github.com/plataformatec/devise/blob/1a0192201b317d3f1bac88f5c5b4926d527b1b39/app/controllers/devise/sessions_controller.rb>\n\nで、\n\n`respond_with(resource, serialize_options(resource))`\n\nという処理で最終的に、`.erb`に処理を渡していると思うのですが、 \n`respond_with`の動きがわかりません。\n\n```\n\n def serialize_options(resource)\n methods = resource_class.authentication_keys.dup\n methods = methods.keys if methods.is_a?(Hash)\n methods << :password if resource.respond_to?(:password)\n { methods: methods, only: [:password] }\n end\n \n```\n\nで、\n`methods`と`only`をキーに持つHashを作っていて`respond_with`はこのHashを引数に受け取っているようではありますが...\nこの2つのキーにはどういう意味があるのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T13:58:26.313",
"favorite_count": 0,
"id": "17225",
"last_activity_date": "2015-10-05T10:05:53.913",
"last_edit_date": "2015-10-05T10:05:53.913",
"last_editor_user_id": "85",
"owner_user_id": "9008",
"post_type": "question",
"score": 1,
"tags": [
"ruby-on-rails",
"ruby",
"devise"
],
"title": "Deviseのrespond_withの引数で渡される、serialize_optionsのキーの意味を知りたい",
"view_count": 756
}
|
[
{
"body": "完全には理解できていませんが、このコミット(特にテスト)を見てなんとなく役割がわかりました。\n\n<https://github.com/plataformatec/devise/commit/3cedba1de8345b5f5f9055acd5513e893ed8d497>\n\nmethods には config/initializers/devise.rb の authentication_keys が利用されます。\n\nデフォルトは :email になっています。\n\n```\n\n # config.authentication_keys = [ :email ]\n \n```\n\nこれを :subdomain に変えたりすると、認証時にuser.emailではなくuser.subdomainが使われるようです。(おそらく)\n\n```\n\n config.authentication_keys = [ :subdomain ]\n \n```\n\nあとはGitHubのblameやhistoryを使ってコミットログをさかのぼったり、pryやRubyMineを使ってじっくりデバッグ実行したりするとその他の不明な点も解決されるのではないでしょうか?\n\n以上、ご参考までに。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T01:05:11.613",
"id": "17254",
"last_activity_date": "2015-10-05T01:05:11.613",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "85",
"parent_id": "17225",
"post_type": "answer",
"score": 1
}
] |
17225
| null |
17254
|
{
"accepted_answer_id": "17228",
"answer_count": 1,
"body": "Macにvimをインストールして+clientserverにしようと考えています。\n\n```\n\n $ brew uninstall vim\n \n```\n\nとしてアンインストールの後\n\n```\n\n $ brew install vim --with-client-server\n \n```\n\nとしています。でも\n\n```\n\n $ vim --version\n \n```\n\nでオプション内容を確認するとずっと\n\n```\n\n -clientserver\n \n```\n\nのままです。なにがおかしいのでしょうか?\n\nMac OS Yosemite 10.10.5 \nVIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 7 2015 10:01:56) \nMacOS X (unix) version \nIncluded patches: 1-729",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T14:19:58.183",
"favorite_count": 0,
"id": "17227",
"last_activity_date": "2015-10-03T15:06:06.523",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9202",
"post_type": "question",
"score": 1,
"tags": [
"vim"
],
"title": "Macにvimをインストールして+clientserverにする方法は?",
"view_count": 975
}
|
[
{
"body": "Macに最初からインストールされている vim を実行しているのだと思います。 \n[こういった解説](http://bulblub.com/2010/11/18/homebrew%E3%81%A7%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%97%E3%81%9F%E3%82%82%E3%81%AE%E3%82%92%E5%84%AA%E5%85%88%E7%9A%84%E3%81%AB%E4%BD%BF%E3%81%86/\n\"homebrewでインストールしたものを優先的に使う\")などを参考に`PATH`を変更するか、どちらの vim\nを実行するか明示的に指定するようにして下さい。 \n下記のコマンドは参考です。\n\n```\n\n # 環境変数 PATH を表示\n echo $PATH\n # どこの vim が優先されるか確認\n which vim\n # Homebrew の vim を実行\n /usr/local/bin/vim\n # プリインストールの vim を実行\n /usr/bin/vim\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T15:06:06.523",
"id": "17228",
"last_activity_date": "2015-10-03T15:06:06.523",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "17227",
"post_type": "answer",
"score": 4
}
] |
17227
|
17228
|
17228
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "HTMLメールのコーディングで困っており、質問させてください。\n\n<https://www.campaignmonitor.com/css/> \nこちらの情報によればoutlook2007/2010はhead内でのCSSの定義およびクラス名セレクタをサポートしているはずなのですが、以下のHTMLでは無視されてしまいます。 \n何か記述間違いなどありますでしょうか。よろしくお願いいたします。\n\n```\n\n <!DOCTYPE html>\n <html lang=\"ja\">\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-2022-jp\">\n <meta http-equiv=\"Content-Language\" content=\"ja\">\n <style type=\"text/css\">\n .test {color:red;}\n </style>\n </head>\n <body leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" bgcolor=\"#FFF\" style=\"margin:0; padding:0; -webkit-text-size-adjust:none; -ms-text-size-adjust:none;\">\n <div class=\"test\">DIVテスト</div>\n \n <table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#FFF\" style=\"margin: 1% 0 2% 0;\">\n <tr>\n <td class=\"test\" width=\"100%\" valign=\"middle\">テスト</td>\n </tr>\n </table>\n </body>\n </html>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T17:02:05.417",
"favorite_count": 0,
"id": "17230",
"last_activity_date": "2015-10-03T17:02:05.417",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12507",
"post_type": "question",
"score": 4,
"tags": [
"html",
"css"
],
"title": "Outlook2007/2010はHTMLメールのstyleブロック内のCSSを無視する?",
"view_count": 160
}
|
[] |
17230
| null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Monacaを使用して、Android及びiOS向けのハイブリッドアプリを制作しています。 \n端末上のファイルを任意のFTPサーバーにアップロードしたいと思っております。 \nCordovaプラグインでFileTransferプラグインをインストールし、以下のコードでアップロードしようとしています。\n\n```\n\n var win = function(r) { \n alert(\"Success\"); \n } \n \n var fail = function(error) { \n alert(\"failed\"); \n console.log(\"upload error code \" + error.code); \n console.log(\"upload error source \" + error.source); \n console.log(\"upload error target \" + error.target); \n } \n \n function hoge(){ \n var options = new FileUploadOptions; \n options.fileKey=\"file\"; \n options.fileName=\"myphoto.jpg\"; \n options.mimeType=\"image/jpeg\"; \n var params = {}; \n params.value1 = \"ftpid\"; //FTPサーバーID \n params.value2 = \"ftppassword\"; //FTPサーバーPass \n options.params = params; \n \n var ft = new FileTransfer(); \n var path = \"/sdcard/\"+'monaca.jpg'; \n ft.upload(path, encodeURI(\"ftp.server.url.com\"), win, fail, options); \n } \n \n```\n\nファイルは端末の/sdcard/直下に配置しております。 \nこのft.uploadのところで失敗しているようですが、上記のfailで出力されるlogでは、\n\n```\n\n upload error code null \n upload error source null \n upload error target null \n \n```\n\nと表示され内容がわかりません。\n\nデバッグ環境は \n実機:NEXUS5 \nAndroidバージョン: 5.1.1 \nCordovaバージョン: 4.1.0 \nFileTransferバージョン:0.4.8\n\nどなたかご教授願えないでしょうか",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T19:18:11.057",
"favorite_count": 0,
"id": "17232",
"last_activity_date": "2016-09-09T05:28:04.733",
"last_edit_date": "2015-10-03T19:50:13.170",
"last_editor_user_id": "12553",
"owner_user_id": "12553",
"post_type": "question",
"score": 3,
"tags": [
"javascript",
"monaca",
"cordova"
],
"title": "Monacaによるハイブリットアプリ制作にてFileTransferのUploadでFTP送信できない。",
"view_count": 666
}
|
[
{
"body": "自己解決いたしました。 \nft.upload(path, encodeURI(\"ftp.server.url.com\"), win, fail, options); \nの、ftpサーバーの指定の部分がまずかったようです。 \nFileTransferのupload関数ではFTPに直接ファイルをアップロードできませんでした。 \nサーバーにファイル保存用のphpを置き、そのphpファイルをURLで指定することで解決しました。 \n結果次のようなコードにしました\n\n```\n\n ft.upload(path, encodeURI(\"http://server.url.com/receive.php\"), win, fail, options);\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-03T20:36:26.780",
"id": "17234",
"last_activity_date": "2015-10-03T20:36:26.780",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12553",
"parent_id": "17232",
"post_type": "answer",
"score": 1
}
] |
17232
| null |
17234
|
{
"accepted_answer_id": null,
"answer_count": 3,
"body": "monacaを利用しハイブリッドアプリを作成しています。 \nボタンを押下にて、アプリ内で保持したメールアドレスへメーラー等を起動せず自動送信したいです。 \niosであればmailto,\nandroidであればwebintent等を利用すればメーラーの起動まではたどり着きますが、自動送信(バックグラウンド送信)の方法が分かりません。 \nどのような手法が考えられるか、ご教示ください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T02:31:19.753",
"favorite_count": 0,
"id": "17237",
"last_activity_date": "2015-12-22T09:42:24.497",
"last_edit_date": "2015-10-04T09:05:52.940",
"last_editor_user_id": "12556",
"owner_user_id": "12556",
"post_type": "question",
"score": 6,
"tags": [
"android",
"ios",
"monaca"
],
"title": "メーラーを起動せずバックグラウンド送信したい",
"view_count": 1307
}
|
[
{
"body": "smtp実装したプラグインを作るか、自前で中継ウェブサービス立ち上げるか、どちらかですかね。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T09:26:22.223",
"id": "17243",
"last_activity_date": "2015-10-04T09:26:22.223",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12569",
"parent_id": "17237",
"post_type": "answer",
"score": 1
},
{
"body": "以前成功した方法を共有します。\n\nFrontierMailというKou様が作成されたオープンソースを利用しました。 \n(4年前から更新が止まっているため最新環境では動作するか未検証です)\n\nこちらのReadMe手順に従いFrameworkを作成します。 \n<https://github.com/kkoudev/FrontierMail>\n\nプロジェクトにFrameworkを追加し、以下のような実装でメールが送信できます。\n\nテストクラスの実装引用です。\n\n```\n\n - (void)testSMTPSendPlainText {\n \n // メールメッセージを作成する\n FRMailMessage* message = [FRMailMessage mailMessage];\n \n // 件名を設定する\n [message setSubject:MAIL_SUBJECT];\n \n // FROM名とアドレスを設定する\n [message setFromAddress:[FRMailAddress mailAddressWithName:MAIL_FROM_NAME address:MAIL_FROM_ADDRESS]];\n \n // 送信先名称とアドレスを設定する\n [message addToAddress:[FRMailAddress mailAddressWithName:MAIL_TO_NAME address:MAIL_TO_ADDRESS]];\n \n // MIMEパーツを作成する\n FRMimePart* mimeTextPart = [FRMimePart mimePart];\n \n // 本文を設定する\n [mimeTextPart setText:MAIL_MESSAGE];\n \n // メールメッセージへMIME情報を設定する\n [message setMimePart:mimeTextPart];\n \n // SMTPセッションを作成する\n FRSMTPSession* session = [FRSMTPSession\n smtpWithConnectionType:FRSMTPConnectionTLS \n hostAddress:SMTP_HOST\n portNo:SMTP_PORT_NO];\n \n // セッションへ接続する\n [session connect:SMTP_ACCOUNT password:SMTP_PASSWORD];\n \n // メールを送信する\n [session sendMailMessage:message]; \n \n }\n \n```\n\n自分のGmailのアカウントをSMTPサーバとして使用しました。 \nSMTP_ACCOUNTとSMTP_PASSWORDには自分のGmailアカウント名とパスワードを入れました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-21T04:54:57.360",
"id": "17886",
"last_activity_date": "2015-10-21T04:54:57.360",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "11109",
"parent_id": "17237",
"post_type": "answer",
"score": 0
},
{
"body": "MailCore2というメール送受信のためのライブラリがあります。 \n<https://github.com/MailCore/mailcore2>\n\niOS/Android両対応で現在もアップデートし続けているようです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-23T08:19:31.107",
"id": "17980",
"last_activity_date": "2015-10-23T08:19:31.107",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3227",
"parent_id": "17237",
"post_type": "answer",
"score": 0
}
] |
17237
| null |
17243
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "言語はruby、seleniumのバージョンは2.2、ブラウザはfirefox31.4です。\n\nFacebookでログインボタンをクリックした後、メンバーページへ移動するのですが、 \nそのメンバーページではかなり高い確率でいつまで経っても読み込みが終わらないため、タイムアウトの時間を長く設定してもエラーで終了してしまいます。\n\n```\n\n /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/net/protocol.rb:158:in `rescue in rbuf_fill': Net::ReadTimeout (Net::ReadTimeout)\n \n```\n\nそのため強制的に読み込みを停止させる、読み込み中であっても次の画面へ遷移させる、などのなんらかの方法で次に進ませたいのですが、何か良い解決策はありませんでしょうか? \n宜しくお願いします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T03:08:26.433",
"favorite_count": 0,
"id": "17238",
"last_activity_date": "2016-10-15T16:01:14.933",
"last_edit_date": "2015-10-04T03:19:47.583",
"last_editor_user_id": "5337",
"owner_user_id": "12557",
"post_type": "question",
"score": 2,
"tags": [
"ruby",
"selenium"
],
"title": "Selenium Webdriverで絶対に読み込みがタイムアウトになるのをなんとかしたい",
"view_count": 4679
}
|
[
{
"body": "自分も同じようなサイトで困って読み込みがやけに長ければ無理やりescを押したりするようにコードを書きましたが上手くいきませんでした。 \nで、結果的にベストな方法では無いと思っていますが、例外処理を書いてしまうという方法で今でも何とかしてます。 \n読み込みがいつでも長い場合はこれでは対処できないと思いますが稀に長くない時に突破出来るかと思います。\n\n```\n\n def try(n=5) #5回くらい例外処理実行\n #通常処理\n driver.quit #ブラウザ終了\n rescue => e\n driver.quit #ブラウザ終了\n if n==0\n raise e\n else\n try(n-1)\n end\n end\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T09:08:37.477",
"id": "17242",
"last_activity_date": "2015-10-04T09:08:37.477",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12568",
"parent_id": "17238",
"post_type": "answer",
"score": 1
}
] |
17238
| null |
17242
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "```\n\n using UnityEngine;\n using System.Collections;\n \n public class ScrollObject : MonoBehaviour {\n public float speed = 1.0f;\n public float startPosition;\n public float endPosition;\n \n void Update() {\n //毎フレームxポジションを少しずつ移動させる\n transform.Translate(-1 * speed * Time.deltaTime, 0, 0);\n //スクロールが目標ポイントまで到達したかをチェック\n if (transform.position.x <= endPosition) ScrollEnd();\n }\n \n void ScrollEnd() {\n //スクロールする距離分を戻す\n transform.Translate(-1 * (endPosition - startPotion), 0, 0);\n //毎ゲームオブジェクトにアタッチされているコンポーネントにメッセージを送る\n SendMessage(\"onScrollEnd\", SendMessageOptions.DontRequireReceiver);\n }\n }\n \n```\n\nエラー:\n\n```\n\n Assets/Script/ScrollObject.cs(21,56): error CS0103: The name `startPotion' does not exist in the current context\n Assets/Script/ScrollObject.cs(21,27): error CS1502: The best overloaded method match for `UnityEngine.Transform.Translate(float, float, float)' has some invalid arguments\n Assets/Script/ScrollObject.cs(21,27): error CS1503: Argument `#1' cannot convert `object' expression to type `float'\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T06:33:42.863",
"favorite_count": 0,
"id": "17240",
"last_activity_date": "2015-10-04T15:08:11.147",
"last_edit_date": "2015-10-04T10:29:38.823",
"last_editor_user_id": "7290",
"owner_user_id": "12567",
"post_type": "question",
"score": -1,
"tags": [
"unity3d"
],
"title": "Unityのスクリプトでエラーが出ます",
"view_count": 14178
}
|
[
{
"body": "ScrollObject.csの21行目にあるstartPotionの綴りが間違っています。 \nstartPositionと書き換えることでエラーは消えると思います。\n\nエラーの対応方法がわからない場合、下記を試してみてください。\n\n 1. エラーは英語のメッセージですが、分からなければgoogle翻訳などで日本語にしてみてください。 \n * 原文:The name `startPotion' does not exist in the current context\n * 翻訳:名前` startPotion 'は現在のコンテキスト内に存在しません\n 2. エラーをダブルクリックするとエディタの該当行へ移動します。上記エラーメッセージを意識してよく見直してみてください。\n 3. それでも意味がわからない場合、Googleでエラーメッセージを調べてみると同じエラーで苦労した人の解決策が見つかるかもしれません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T15:08:11.147",
"id": "17248",
"last_activity_date": "2015-10-04T15:08:11.147",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4850",
"parent_id": "17240",
"post_type": "answer",
"score": 3
}
] |
17240
| null |
17248
|
{
"accepted_answer_id": "17280",
"answer_count": 1,
"body": "SwiftでiOSのプログラミング時、データベースなど組み込むとき、保存場所に慣習などあるのでしょうか?\n\nアップグレード時、上書きされる保存場所、されない保存場所を、実機でそれぞれどのように設定すればいいでしょうか?\n\n教えていただければ幸いです。\n\nよろしくお願いいたします。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-04T13:17:02.643",
"favorite_count": 0,
"id": "17247",
"last_activity_date": "2015-10-05T12:28:49.363",
"last_edit_date": "2015-10-05T08:06:09.477",
"last_editor_user_id": "10845",
"owner_user_id": "10845",
"post_type": "question",
"score": -2,
"tags": [
"ios"
],
"title": "データベースなど、アップグレード時上書きされない格納場所と、上書きされる格納場所の設定方法",
"view_count": 173
}
|
[
{
"body": "ディレクトリのパス取得は、つぎの関数を用いるのが定型となっています。\n\n[Foundation Functions\nReference](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/#//apple_ref/c/func/NSSearchPathForDirectoriesInDomains)\n\n```\n\n func NSSearchPathForDirectoriesInDomains(_ directory: NSSearchPathDirectory, _ domainMask: NSSearchPathDomainMask, _ expandTilde: Bool) -> [String]\n \n```\n\n`NSSearchPathDirectory`を`NSSearchPathDirectory.DocumentDirectory`、`NSSearchPathDomainMask`を`NSSearchPathDomainMask.UserDomainMask`とすると、アプリが保存する書類ファイルが格納されるDocumentsフォルダのパスを取得できます。 \n(引数`expandTilde`は、`~`を使って、ユーザディレクトリの先頭から始める(`false`)か、ルートディレクトリから始める(`true`)かを選択します) \n返り値は、パスの配列になります。クラウドサービスを使って、Documentsフォルダの場所が複数になるということを想定しているんでしょうが、とくにむずかしいことをしていなければ、この配列の要素数は1です。\n\n```\n\n let pathArray = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)\n let documentPath = pathArray[0]\n \n```\n\n> アップグレード時、上書きされる保存場所\n\nアップグレードで上書きされるのは、アプリケーション本体のみと、私は認識しています。アプリケーション本体は、保存場所にはならない(保存場所にすべきでない)ので、「ない」という回答でいいかと思います。\n\nじっさいに実機で各ディレクトリの場所を出力してみて、iOSのディレクトリ構造がどうなっているか、勉強なさるといいでしょう。コンピュータのセキュリティで使われる概念に「Sand\nBox」というものがありますが、iOSでは、これを採用して、アプリケーションごとにそれぞれのDocumentsフォルダが作られることがわかると思います。万一iPhone/iPadがハッキングされても、ハック対象のアプリのみに被害がとどまり、ほかのアプリの安全が保たれるというしくみです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T12:28:49.363",
"id": "17280",
"last_activity_date": "2015-10-05T12:28:49.363",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7362",
"parent_id": "17247",
"post_type": "answer",
"score": 1
}
] |
17247
|
17280
|
17280
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "おそらく \n<https://devnet.jetbrains.com/message/5526866>\n\nJohn Hunter氏の\n\n> when I start debugging, no breakpoints are ever hit (it does open up the\n> page in chrome and I get the message ''JetBrains IDE Support is debugging\n> this tab). I have set breakpoints in my ES6 js files and the generated js\n> files. I feel like I am missing something, but I don't know what.\n\nの発言と同じ現象が起こっているようです。\n\nその後の発言を見ると、\n\n`gulp.src` を触るとうまくいったよ的な展開になっている感じがしますが、\n\nプロジェクト内で、 \n`gulp.src(['plugin/**/*.es6'])`で検索してもヒットしませんし、 \n`gulp.src`で検索すると、`node_modules`の中に数件ヒットしますが、いったいどこをいじればよいのでしょうか?(というか`node_modules`の中をいじくるものなのでしょうか...)\n\nどなたかES6のブレイクポイントが上手く動いた方はいませんか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T00:38:54.257",
"favorite_count": 0,
"id": "17253",
"last_activity_date": "2016-11-24T15:59:39.540",
"last_edit_date": "2015-10-05T10:04:38.773",
"last_editor_user_id": "85",
"owner_user_id": "9008",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"ruby-on-rails",
"gulp",
"npm",
"rubymine"
],
"title": "RubyMine(もしくはJetBrains製品)でES6のブレイクポイントが機能しない",
"view_count": 269
}
|
[
{
"body": "引用されているやり取りを読みましたが、`gulp.src` のことには特に触れられていないと思います。\n\n挙がっている話としては、\n\n * [規格に沿った](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?hl=en_US) sourcemap が生成され、それが .js ファイルから `//@sourceMappingURL` で正しく関連付けられていることが必要\n * WebStorm の babel file watcher を使えば期待通りにブレークポイントが機能したが、 babel-gulp を使うとブレークポイントが機能しなかった。最終的には、 gulp-sourcemaps が生成した .js.map ファイルに間違った `sourceRoot` が出力されていたようで、正しい値を指定したら動くようになった(これが最後に載っている gulpfile)\n\nというところでしょうか。\n\nMark氏の書かれた二つの gulpfile を比べると、 `includeContent`\nの指定も増えているのが気になりますが・・・とりあえず上記二点を確認してみてはいかがでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T13:32:40.387",
"id": "17285",
"last_activity_date": "2015-10-05T13:32:40.387",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "17253",
"post_type": "answer",
"score": 1
}
] |
17253
| null |
17285
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "ffmpegのエンコードでnot found\nlibx264とでたので調べたところ、/usr/lib/になかったのでインストールしようとしたんですが何回やってもできなくてここに質問しました。 \n私がやったのはx264をgit cloneでダウンロードしてコンパイルしました。\n\n * git cloneでx264のダウンロード\n * x264のディレクトリ内でconfigureの実行\n * その後、makeとmake installを実行\n\nしかし、以上を実行しても/usr/lib/にはなくて/usr/local/bin/にx264が追加されただけでした。 \nこれはインストールするものを間違っているのでしょうか? \nまた、もしlibx264をインストールできたとしてもすぐにffmpegで使えますか? \nいれたあとにffmpegをまたコンパイルする必要があるんでしょうか\n\nよろしくお願いします。\n\n追記\n\n使っているOSはraspbianです。 \nconfigureの実行結果は\n\n```\n\n platform: ARM\n byte order: little-endian\n system: LINUX\n cli: yes\n libx264: internal\n shared: no\n static: no\n asm: yes\n interlaced: yes\n avs: avxsynth\n lavf: yes\n ffms: no\n mp4: no\n gpl: yes\n thread: posix\n opencl: yes\n filters: resize crop select_every \n debug: no\n gprof: no\n strip: no\n PIC: no\n bit depth: 8\n chroma format: all\n \n```\n\nこのようにでました。 \nmakeの結果は以下の通りです。\n\n```\n\n rm -f libx264.a\n ar rc libx264.a common/mc.o common/predict.o common/pixel.o common/macroblock.o common/frame.o common/dct.o common/cpu.o common/cabac.o common/common.o common/osdep.o common/rectangle.o common/set.o common/quant.o common/deblock.o common/vlc.o common/mvpred.o common/bitstream.o encoder/analyse.o encoder/me.o encoder/ratecontrol.o encoder/set.o encoder/macroblock.o encoder/cabac.o encoder/cavlc.o encoder/encoder.o encoder/lookahead.o common/threadpool.o common/arm/mc-c.o common/arm/predict-c.o common/opencl.o encoder/slicetype-cl.o common/arm/cpu-a.o common/arm/pixel-a.o common/arm/mc-a.o common/arm/dct-a.o common/arm/quant-a.o common/arm/deblock-a.o common/arm/predict-a.o\n ranlib libx264.a\n gcc -o x264 x264.o input/input.o input/timecode.o input/raw.o input/y4m.o output/raw.o output/matroska.o output/matroska_ebml.o output/flv.o output/flv_bytestream.o filters/filters.o filters/video/video.o filters/video/source.o filters/video/internal.o filters/video/resize.o filters/video/cache.o filters/video/fix_vfr_pts.o filters/video/select_every.o filters/video/crop.o filters/video/depth.o input/avs.o input/thread.o input/lavf.o libx264.a -ldl -L. -pthread -L/usr/local/lib -lavformat -lavcodec -lxcb -lX11 -lasound -lSDL -lz -lswresample -lswscale -lavutil -lrt -lm -L/usr/local/lib -lswscale -lavutil -lrt -lm -lm -lpthread -ldl\n \n```",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T01:48:41.950",
"favorite_count": 0,
"id": "17255",
"last_activity_date": "2015-10-05T13:36:55.907",
"last_edit_date": "2015-10-05T13:36:55.907",
"last_editor_user_id": "8000",
"owner_user_id": "9349",
"post_type": "question",
"score": 1,
"tags": [
"raspberry-pi",
"ffmpeg",
"raspbian"
],
"title": "libx264のインストールについて質問です。",
"view_count": 2882
}
|
[
{
"body": "私の環境で試しましたところ `configure`、`make`、`make install` の順でインストールできました。\n\n> しかし、これを実行しても/usr/lib/にはなくて/usr/local/bin/にx264が追加されただけでした。\n\n`configure` オプションに `--enable-shared` が無いので実行コマンドのみビルドされています。 \nインストール先を変えたいのでしたら `--prefix=/usr` を指定します。\n\n> また、もしlibx264をインストールできたとしてもすぐにffmpegで使えますか? \n> いれたあとにffmpegをまたコンパイルする必要があるんでしょうか\n\nShared ライブラリなので大丈夫なのではないかと思います。 \nただ、試したわけではなりませんのでご自身で確認されてみてください。\n\n**configure オプションの確認方法**\n\n`configure` はオプションがあるので次のようにして必要なオプションを確認します。\n\n```\n\n $ ./configure --help\n \n```\n\n必要そうなオプションは この辺りでしょうか。\n\n```\n\n --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local]\n \n --enable-shared build shared library\n \n```\n\n私の環境だと次のオプションも必要でした。\n\n```\n\n --disable-asm disable platform-specific assembly optimizations\n \n```\n\n**configure の実行例**\n\n```\n\n $ ./configure --prefix=/usr/local --enable-shared --disable-asm\n Warning: libavformat is not supported without swscale support\n platform: X86_64\n byte order: little-endian\n system: LINUX\n cli: yes\n libx264: internal\n shared: yes\n static: no\n asm: no\n interlaced: yes\n avs: avxsynth\n lavf: no\n ffms: no\n mp4: no\n gpl: yes\n thread: posix\n opencl: yes\n filters: crop select_every\n debug: no\n gprof: no\n strip: no\n PIC: yes\n bit depth: 8\n chroma format: all\n \n You can run 'make' or 'make fprofiled' now.\n \n```\n\n**make & make install の実行例**\n\n```\n\n $ make\n cat common/opencl/x264-cl.h common/opencl/bidir.cl common/opencl/downscale.cl common/opencl/intra.cl common/opencl/motionsearch.cl common/opencl/subpel.cl common/opencl/weightp.cl | ./tools/cltostr.sh common/oclobj.h\n dependency file generation...\n (略)\n \n $ sudo make install\n install -d /usr/local/bin\n install x264 /usr/local/bin\n install -d /usr/local/include\n install -d /usr/local/lib\n install -d /usr/local/lib/pkgconfig\n install -m 644 ./x264.h /usr/local/include\n install -m 644 x264_config.h /usr/local/include\n install -m 644 x264.pc /usr/local/lib/pkgconfig\n ln -f -s libx264.so.148 /usr/local/lib/libx264.so\n install -m 755 libx264.so.148 /usr/local/lib\n \n```\n\n**インストール先の確認**\n\n```\n\n $ ls -l /usr/local/lib\n 合計 1052\n lrwxrwxrwx. 1 root root 14 10月 5 12:23 2015 libx264.so -> libx264.so.148\n -rwxr-xr-x. 1 root root 1071160 10月 5 12:23 2015 libx264.so.148\n drwxr-xr-x. 2 root root 4096 10月 5 12:34 2015 pkgconfig\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T03:35:13.683",
"id": "17258",
"last_activity_date": "2015-10-05T05:13:49.483",
"last_edit_date": "2015-10-05T05:13:49.483",
"last_editor_user_id": "5008",
"owner_user_id": "5008",
"parent_id": "17255",
"post_type": "answer",
"score": 1
}
] |
17255
| null |
17258
|
{
"accepted_answer_id": "17287",
"answer_count": 1,
"body": "Strutsを使用しています。 \nサーバー内のJSPにアクセスし、サーバーが停止している(ERR_CONNECTION_REFUSEDの)場合はサーバー停止中画面(html)に遷移したいのですが、方法が分かりません。 \n現在は、Tomcatのメンテナンスモードについて調査中ですが、まだ解決には至っていません。 \n解決方法の分かる方がいましたら、ご教授をお願いします。\n\n掲載:[teratail 「 Struts:サーバーが停止している場合に、サーバー停止中画面(html)に遷移したい\n」](https://teratail.com/questions/17290)",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T05:11:02.513",
"favorite_count": 0,
"id": "17259",
"last_activity_date": "2015-10-06T12:27:25.820",
"last_edit_date": "2015-10-05T08:26:04.670",
"last_editor_user_id": "10492",
"owner_user_id": "7626",
"post_type": "question",
"score": 1,
"tags": [
"tomcat",
"struts"
],
"title": "Struts:サーバーが停止している場合に、サーバー停止中画面(html)に遷移したい",
"view_count": 932
}
|
[
{
"body": "Tomcatを停止している状態で、HTTPリクエストに対して「サーバー停止中画面」を表示するには、ApacheなどのHTTPサーバーが必要です。Tomcatを止めて、Apacheを動かして\nあらゆるリクエストに対して 決まった HTML を返せば良いと思います。\n\nまた、OS を停止している状態の場合は、「サーバー停止中画面」専用のWebサーバを別途用意して、DNSレコードを書き換えて 向き先を変更する手法があります。\n\n(ご参考までに追記) 他にも手法はあるので ソーリーサーバー、ソーリーページ などで検索すると色々情報が得られると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T13:55:56.683",
"id": "17287",
"last_activity_date": "2015-10-06T12:27:25.820",
"last_edit_date": "2015-10-06T12:27:25.820",
"last_editor_user_id": "5008",
"owner_user_id": "5008",
"parent_id": "17259",
"post_type": "answer",
"score": 3
}
] |
17259
|
17287
|
17287
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "activity_main.xml\n\n```\n\n <RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/tools\" android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\" android:paddingLeft=\"@dimen/activity_horizontal_margin\"\n android:paddingRight=\"@dimen/activity_horizontal_margin\"\n android:paddingTop=\"@dimen/activity_vertical_margin\"\n android:paddingBottom=\"@dimen/activity_vertical_margin\" tools:context=\".MainActivity\">\n \n <Button\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:text=\"add Filter\"\n android:id=\"@+id/ButtonAddFilter\"\n android:layout_alignParentTop=\"true\"\n android:layout_alignParentLeft=\"true\"\n android:layout_alignParentStart=\"true\" />\n \n <Button\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:text=\"Remove Filter\"\n android:id=\"@+id/ButtonRemoveFilter\"\n android:layout_alignParentTop=\"true\"\n android:layout_alignParentRight=\"true\"\n android:layout_alignParentEnd=\"true\" />\n </RelativeLayout>\n \n```\n\nMainActivity.java\n\n```\n\n public class MainActivity extends Activity {\n \n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n \n Button buttonAddFilter = (Button) findViewById(R.id.ButtonAddFilter);\n buttonAddFilter.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n Intent intent = new Intent(MainActivity.this, FilterService.class);\n startService(intent);\n }\n });\n \n Button buttonRemoveFilter = (Button) findViewById(R.id.ButtonRemoveFilter);\n buttonRemoveFilter.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n Intent intent = new Intent(MainActivity.this, FilterService.class);\n stopService(intent);\n }\n });\n }\n }\n \n```\n\nfilter.xml\n\n```\n\n <LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:orientation=\"vertical\" android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\">\n \n <ImageView\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\" />\n \n </LinearLayout>\n \n```\n\nFilterService.java\n\n```\n\n public class FilterService extends Service {\n \n private View mView;\n private WindowManager mWindowManager;\n \n @Override\n public int onStartCommand(Intent intent, int flags, int startId) {\n \n LayoutInflater layoutInflater = LayoutInflater.from(this);\n \n WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(\n WindowManager.LayoutParams.MATCH_PARENT,\n WindowManager.LayoutParams.MATCH_PARENT,\n WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, \n WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,\n PixelFormat.TRANSLUCENT \n );\n \n mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);\n \n mView = layoutInflater.inflate(R.layout.filter, null);\n \n mView.setBackgroundColor(Color.argb(80, 0, 0, 0));\n \n mWindowManager.addView(mView, layoutParams);\n \n return START_NOT_STICKY;\n }\n \n @Override\n public void onDestroy() {\n super.onDestroy();\n mWindowManager.removeView(mView);\n }\n \n @Nullable\n @Override\n public IBinder onBind(Intent intent) {\n return null;\n }\n }\n \n```\n\nこれは画面にフィルターをかける処理です。この場合、ステータスバーが暗くなりません。 \nステータスバーの場所までmWindowManagerを反映させる、またはステータスバーを違和感が無いように暗くする処理はあるのでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T06:24:09.403",
"favorite_count": 0,
"id": "17261",
"last_activity_date": "2016-10-09T04:24:25.840",
"last_edit_date": "2015-10-05T07:14:01.380",
"last_editor_user_id": "7290",
"owner_user_id": "9850",
"post_type": "question",
"score": 1,
"tags": [
"android",
"java",
"android-studio",
"android-layout"
],
"title": "ステータスバーにもフィルターをかけたい",
"view_count": 466
}
|
[
{
"body": "これをやってみてください。\n\n```\n\n WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(\n WindowManager.LayoutParams.MATCH_PARENT,\n getStatusBarHeight(),\n WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,\n WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |\n WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |\n WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,\n PixelFormat.TRANSLUCENT);\n \n layoutParams.gravity = Gravity.TOP|Gravity.CENTER; \n \n mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);\n \n mView = layoutInflater.inflate(R.layout.filter, null);\n \n mView.setBackgroundColor(Color.argb(80, 0, 0, 0));\n \n mWindowManager.addView(mView, layoutParams);\n \n private static int getStatusBarHeight(android.content.res.Resources res) {\n return (int) (24 * res.getDisplayMetrics().density);\n }\n \n```\n\nPermissionも忘れないです。\n\n```\n\n <uses-permission android:name=\"android.permission.SYSTEM_OVERLAY_WINDOW\" />\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-09T01:27:14.377",
"id": "17443",
"last_activity_date": "2015-10-09T01:27:14.377",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2437",
"parent_id": "17261",
"post_type": "answer",
"score": 1
}
] |
17261
| null |
17443
|
{
"accepted_answer_id": "17279",
"answer_count": 1,
"body": "OnsenUIでWebアプリを開発しています。\n\nその中でカルーセル(ons-\ncarouselコンポーネント)を使用する画面があり、左右に続くコンテンツがあるかどうかをユーザに示す矢印(\"<\"と\">\")を表示したいと考えています。\n\n矢印の表示はOnsenUIの標準機能で可能でしょうか? \nそれとも、自力で実装するしかないでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T07:14:04.640",
"favorite_count": 0,
"id": "17262",
"last_activity_date": "2015-10-05T12:27:10.980",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"post_type": "question",
"score": 1,
"tags": [
"onsen-ui"
],
"title": "カルーセルで左右に矢印を出したい",
"view_count": 624
}
|
[
{
"body": "Onsen UIの`onsen-css-components-blue-basic-theme.css`の2731行に`ons-list-\nitem`の`>`を表示するクラス`.list__item--\nchevron:before`がありますので、これをコピーし左用(`<`)、右用(`>`)のクラスを作成すれば実現できます。\n\nCSS\n\n```\n\n .carousel-item-chevron-l:before {\n position: absolute;\n left: 16px;\n top: 50%;\n color: #ddd;\n line-height: 28px;\n height: 28px;\n -webkit-transform: translateY(-50%);\n -moz-transform: translateY(-50%);\n -ms-transform: translateY(-50%);\n -o-transform: translateY(-50%);\n transform: translateY(-50%);\n font-size: 28px;\n font-family: FontAwesome;\n font-style: normal;\n font-weight: normal;\n content: \"\\f104\";\n }\n .carousel-item-chevron-r:before {\n position: absolute;\n right: 16px;\n top: 50%;\n color: #ddd;\n line-height: 28px;\n height: 28px;\n -webkit-transform: translateY(-50%);\n -moz-transform: translateY(-50%);\n -ms-transform: translateY(-50%);\n -o-transform: translateY(-50%);\n transform: translateY(-50%);\n font-size: 28px;\n font-family: FontAwesome;\n font-style: normal;\n font-weight: normal;\n content: \"\\f105\";\n }\n \n```\n\nHTML\n\n```\n\n <ons-carousel-item>\n <div class=\"carousel-item-chevron-l\"></div>\n <div class=\"carousel-item-chevron-r\"></div>\n </ons-carousel-item>\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T12:27:10.980",
"id": "17279",
"last_activity_date": "2015-10-05T12:27:10.980",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9566",
"parent_id": "17262",
"post_type": "answer",
"score": 1
}
] |
17262
|
17279
|
17279
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "先日、音声再生のプログラムを記述したのですが、音声が再生されません。ご指摘の程、よろしくお願いします。\n\n```\n\n import UIKit\n import AVFoundation\n \n class ViewController: UIViewController {\n \n var player:AVAudioPlayer?\n \n let sound_data = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(\"sample\", ofType: \"mp3\")!)\n \n override func viewDidLoad() {\n super.viewDidLoad()\n // Do any additional setup after loading the view, typically from a nib.\n \n do {\n let player = try AVAudioPlayer(contentsOfURL: sound_data)\n player.play()\n }\n catch let error as NSError {\n print(error)\n }\n \n player?.prepareToPlay()\n \n }\n \n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n // Dispose of any resources that can be recreated.\n }\n \n @IBAction func play(sender: UIButton) {\n player?.play()\n }\n \n @IBAction func pause(sender: UIButton) {\n player?.pause()\n }\n \n @IBAction func stop(sender: UIButton) {\n player?.stop()\n player?.currentTime = 0\n \n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T07:59:36.203",
"favorite_count": 0,
"id": "17264",
"last_activity_date": "2015-10-05T23:15:17.623",
"last_edit_date": "2015-10-05T08:05:22.147",
"last_editor_user_id": "12536",
"owner_user_id": "12536",
"post_type": "question",
"score": 0,
"tags": [
"swift"
],
"title": "音声が再生されません",
"view_count": 617
}
|
[
{
"body": "mp3を再生するためにAVAudioPlayerのインスタンスを生成してますが、それがどこにも参照されないまま解放されてるのが原因かと思われます。\n\n以下のように修正してはどうでしょうか?\n\n```\n\n override func viewDidLoad() {\n super.viewDidLoad()\n \n do {\n // ローカル変数に格納していたのを修正\n player = try AVAudioPlayer(contentsOfURL: sound_data)\n player?.play()\n }\n catch let error as NSError {\n print(error)\n }\n \n player?.prepareToPlay()\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T08:21:57.330",
"id": "17267",
"last_activity_date": "2015-10-05T08:21:57.330",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7459",
"parent_id": "17264",
"post_type": "answer",
"score": 2
}
] |
17264
| null |
17267
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "表題のように、「AppDeledate」内のイベントからTabBarControllerのtabbarにバッジをセットしたいのですが、TabBarControllerのtabbarを参照する方法がわかりません。初歩的な質問かもしれませんが、ご教授願いたく思っております。\n\n具体的には、Push通知(didReceiveRemoteNotification)イベントの発火で4つあるタブの4番目にバッジの内容を更新したいという事でございます。\n\n```\n\n func application(application: UIApplocation, didReceiveRemoteNotification userInfo: [NSObject : AnyObjevt]) {\n let tb = TabBarController()\n tb.tabbar.items![3].badgeValue = \"3\" /* new or 3 etc...*/\n ↑当然エラーとなります。\n }\n \n```\n\n今回のこの質問のように、AppDelegateの発火イベント(通知イベント以外でも)から、他のViewのテキストボックスの内容や、ラベルの内容などの操作をするための方法がわかりません。\n\n例えば、FirstViewControllerのボタンを押下すると、SecondViewController内のテキストボックスの値を変更するなど。AppDelegateも含め、異なるViewクラス間の操作の基本が、Swift初めて間もなく理解できておりませんで、よろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T08:02:40.737",
"favorite_count": 0,
"id": "17265",
"last_activity_date": "2021-02-13T05:16:39.510",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12504",
"post_type": "question",
"score": 0,
"tags": [
"swift"
],
"title": "Swift「AppDelegate」内のイベントからTabBarのバッジをセットしたい",
"view_count": 1316
}
|
[
{
"body": "AppDelegate.swiftの内容に変更を加えていなければ(もちろんコードの追加はなさっているわけですが)、プロパティ`window`がありますね?\n\n```\n\n if let tabBarController = self.window?.rootViewController as? UITabBarController {\n }\n \n```\n\nで、TabBar Controllerを取得できます。\n\n```\n\n if let tabBarController = self.window?.rootViewController as? UITabBarController {\n tabBarController.tabBar.items![3].badgeValue = \"3\"\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T08:17:31.670",
"id": "17266",
"last_activity_date": "2015-10-05T08:33:38.573",
"last_edit_date": "2015-10-05T08:33:38.573",
"last_editor_user_id": "7362",
"owner_user_id": "7362",
"parent_id": "17265",
"post_type": "answer",
"score": 1
},
{
"body": "iOS13からはSceneDelegateでないと基本windowが取得できなくなったようで`sceneWillEnterForeground(_\nscene: UIScene)`で呼ぶことで行けました!\n\n```\n\n class SceneDelegate: UIResponder, UIWindowSceneDelegate {\n \n var window: UIWindow?\n \n func sceneWillEnterForeground(_ scene: UIScene) {\n if let tabBarController = self.window?.rootViewController as? UITabBarController {\n tabBarController.tabBar.items![3].badgeValue = \"3\"\n }\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2021-02-13T05:16:39.510",
"id": "73963",
"last_activity_date": "2021-02-13T05:16:39.510",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "32641",
"parent_id": "17265",
"post_type": "answer",
"score": 0
}
] |
17265
| null |
17266
|
{
"accepted_answer_id": "17273",
"answer_count": 3,
"body": "Swiftでビューコントローラーの \nあるCGPointを含むsubviewsを取得する方法はありますか?\n\n以下のようにfor文で全てのsubviewに対して、`containsPoint`をして、 \n判定する方法しかないでしょうか?\n\n```\n\n @IBAction func hundleTapGR(sender: UITapGestureRecognizer) {\n \n print(\"タップ\")\n let point = sender.locationInView(self.view)\n let subviews = NSMutableArray()\n \n for v in self.view.subviews {\n if v.tag == 1 {\n let view = v as! UIView\n if view.layer.containsPoint(point) == true {\n subviews.addObject(view)\n }\n }\n }\n print(subviews)\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T08:39:19.520",
"favorite_count": 0,
"id": "17268",
"last_activity_date": "2015-10-16T16:10:47.317",
"last_edit_date": "2015-10-16T16:10:47.317",
"last_editor_user_id": "5519",
"owner_user_id": "12297",
"post_type": "question",
"score": 1,
"tags": [
"swift"
],
"title": "Swiftでビューコントローラーの あるCGPointを含むSubviewを取得する方法はありますか?",
"view_count": 1258
}
|
[
{
"body": "CGRectContainsPoint(_ rect: CGRect, _ point:\nCGPoint)かUIView.pointInside(_:withEvent:)を使うと良いと思います。といっても地道に判定するのは変わりないですが。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T09:12:52.500",
"id": "17270",
"last_activity_date": "2015-10-05T09:12:52.500",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "238",
"parent_id": "17268",
"post_type": "answer",
"score": 1
},
{
"body": "まず、Swift2.0の時代になっても、まだ`NS(Mutable)Array`にしがみつくことは、やめにしましょう。すなおにSwiftの`Array`型を使ってください。\n\n```\n\n func hundleTapGR(recognizer: UITapGestureRecognizer) {\n print(\"タップ\")\n let point = recognizer.locationInView(self.view)\n let views = self.view.subviews // Subviewsの配列を取得\n // Arrayのメソッド、filterを活用。pointがフレーム内にあるSubviewをフィルタリング。\n let viewsInPoint: [UIView] = views.filter({(subView: UIView) -> Bool in\n return subView.tag == 1 && CGRectContainsPoint(subView.frame, point)\n })\n 結果を出力\n for view in viewsInPoint {\n print(\"x = \\(view.center.x), y = \\(view.center.y)\")\n }\n }\n \n```\n\n`Array`のメソッド、`map`、`reduce`、`filter`を使うと、`for`文で何行も書いていたコードが、1行で書けちゃいます。勉強する価値が、おおいにあると思いませんか?\n\n* * *\n\n「対象のViewが、座標変換(transform)していたらどないすんねん?」という問題が、別回答で提起されていますが、それは、わざわざ`convertPoint()`を使わなくても処理できます。`UIGestureRecognizer`のメソッド`locationInView()`の使いかたを工夫します。\n\n```\n\n func tapped(recognizer: UITapGestureRecognizer) {\n let tappedViews = self.view.subviews.filter({(subview: UIView) -> Bool in\n return subview.bounds.contains(recognizer.locationInView(subview))\n })\n print(\"number = \\(tappedViews.count)\")\n }\n \n```\n\nかえって、簡潔なコードになりましたね。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T11:00:06.333",
"id": "17273",
"last_activity_date": "2015-10-06T06:17:36.970",
"last_edit_date": "2015-10-06T06:17:36.970",
"last_editor_user_id": "7362",
"owner_user_id": "7362",
"parent_id": "17268",
"post_type": "answer",
"score": 0
},
{
"body": "ダイレクトなAPIはありません。\n\n`CALayer` の `containsPoint(_:)` メソッドは、レイヤーの `frame` ではなく `bounds`\nがそのポイントを含むか否かなので、質問のコードはたぶん正常に動作しません。\n\nSwift では `CGRect` が拡張されていて、`contains(point: CGPoint) -> Bool`\nを持っていますので、一番手っ取り早いのは:\n\n```\n\n let subviews = view.subviews.filter {\n $0.frame.contains(point)\n }\n \n```\n\nなのですが、`frame`はそのviewに`transform`がかかっているときは[無意味な可能性がある](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instp/UIView/frame)ので:\n\n> If the transform property is not the identity transform, the value of this\n> property is undefined and therefore should be ignored.\n```\n\n let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))\n view.transform = CGAffineTransformMakeRotation(CGFloat(M_PI * 45 / 180))\n view.frame // -> {x -20.711 y -20.711 w 141.421 h 141.421}\n view.frame.contains(CGPoint(x: 1, y: 1)) // -> true\n \n```\n\nこのような場合に正確に調べたい場合は、座標系を変換して `bounds` と比較した方がよいです。\n\n```\n\n let subviews = self.view.subviews.filter {\n $0.bounds.contains(view.convertPoint(point, toView: $0))\n }\n \n```\n\nこの場合 `$0.layer.containsPoint(view.convertPoint(point, toView: $0))`\nと同じですが、`UIView` 使っているときには `.layer` は直接触らない方が良いと思っているので、僕は`bounds.contains`\nを使います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T13:36:52.890",
"id": "17286",
"last_activity_date": "2015-10-05T13:36:52.890",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3489",
"parent_id": "17268",
"post_type": "answer",
"score": 4
}
] |
17268
|
17273
|
17286
|
{
"accepted_answer_id": "17292",
"answer_count": 3,
"body": "## まずそもそもRailsがないのでgemでインストール\n\nまずそもそもRailsがないので、インストール。 \n\n(1) `gem install rails`\n\n## プロジェクトを作る\n\n`rails new hoge_project`\n\n(2) この`rails new`で自動で`bundler`で`rails`が入る (`bundle exec rails`で動く)。\n\n## 共通のbundleは嫌なので、 --path vendor/bundle\n\n`bundler`で扱うものは、プロジェクトごとで扱いたいので、 \n`hoge_project`ディレクトリに移動して、 \n(3)`bundle install --path vendor/bundle`\n\n## 以上の操作で全部で3つのrails\n\n上記操作で合計3つのrailsが私のPCに入ったことになり、 \n最終的に(3)の手順でいれた`rails`を`bundle exec rails`の形で使うのが主流のように感じるのですが、認識に間違いはないでしょうか?\n\n## 質問\n\nQ0. そもそも認識に間違いはないか? \nQ1. 使わない2つのrailsは削除するのかどうか? \nQ2. 手順(2)で自動で入るrailsは不要に思えるスキップできないか? \nQ3. 他のフレームワークでもこのようにたくさんの同じようなものが入るのが一般的なのだろうか?(言語問わず何か似たようなものがあれば)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T09:03:49.253",
"favorite_count": 0,
"id": "17269",
"last_activity_date": "2016-01-11T02:00:33.220",
"last_edit_date": "2015-10-05T10:32:26.710",
"last_editor_user_id": "9008",
"owner_user_id": "9008",
"post_type": "question",
"score": 2,
"tags": [
"ruby-on-rails",
"ruby",
"rubygems",
"bundler"
],
"title": "一般的で無駄のないRailsのインストール手順はありますか?",
"view_count": 1146
}
|
[
{
"body": "`rails new`したときに自動で実行されるbundle\ninstallでは、(後述するようにBundlerでのgemのインストール先をいじっていないのであれば)Railsは新たにインストールされる事は無かったと思います。自動生成されるGemfileに記載される`rails`のバージョンは`rails\nnew`で読み込まれる`rails`と同じバージョンですし、特に指定しなければ`gem install`と`bundle\ninstall`ではインストール先は同じです。\n\nただし、Railsが直接依存しないがGemfileで指定されているgemはインストールされてしまいます。あとで`bundle exec --path\n...`を実行するのが前提なのであれば、`rails new APPNAME -B`でbundle installの自動実行をキャンセルすることができます。\n\nもしくは、かならず`bundle install --path 決まったパス`を実行することにしているのであれば、あらかじめ`bundle config\n--global path 決まったパス`を実行しておけばいちいち`bundle install`に`--path`を指定する必要はありません。`rails\nnew`が自動実行する`bundle install`に任せてしまえます。\n\nBundlerで別のパスに改めてRailsをインストールするのであれば、`rails\nnew`したときのRailsは不要です。削除したければ削除して良いでしょう。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T12:22:44.047",
"id": "17278",
"last_activity_date": "2015-10-05T12:22:44.047",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5793",
"parent_id": "17269",
"post_type": "answer",
"score": 1
},
{
"body": "> Q0. そもそも認識に間違いはないか?\n\n間違いがあるように思います。 \n(2)の時は(1)でインストールしたrailsを利用し新たにrailsがインストールされないと思います。\n\nbundlerはインストールPATHを変更しない限り、同名、同バージョンのrubygemsがンストール済みの場合、新たにインストールしません。\n\n結果としてインストールされるrailsは2つになるかと思います。\n\n> Q1. 使わない2つのrailsは削除するのかどうか?\n\n後述しますが私なら最初からvendor/bundle配下にrailsをインストールします。\n\n> Q2. 手順(2)で自動で入るrailsは不要に思えるスキップできないか?\n\n`rails new hoge_project --skip-bundle` すれば`bundle install`せずにrailsプロジェクトを作れます。\n\n> Q3. 他のフレームワークでもこのようにたくさんの同じようなものが入るのが一般的なのだろうか?(言語問わず何か似たようなものがあれば)\n\nPerlならCarton、PHPならComposer、nodejsならnpmあたりがbundlerと似たような機能を提供しているように思います。しかしそれらに見識がないので詳しくご説明ができません。\n\n* * *\n\n最後に蛇足ですが、最初から`vendor/bundle`配下にrailsをインストールする方法をご紹介したいと思います。\n\n 1. プロジェクトディレクトリを作って移動する \n`mkdir hoge_project && cd hoge_project`\n\n 2. Gemfileを作る \n`bundle init` \nhoge_project配下にGemfileがつくられます。\n\n 3. Gemfileにrailsを追加する \n`echo “gem ‘rails’” >> Gemfile` \nエディタでGemfileを編集していただいて構いません。\n\n 4. bundle installする \n`bundle install --path vendor/bundle` \n`vendor/bundle`を指定してbundle installする。\n\n 5. rails newする \n`bundle exec rails new .` \nピリオドを忘れずにつけてください。`HogeProject`なrailsプロジェクトができます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T15:02:31.477",
"id": "17292",
"last_activity_date": "2015-10-11T10:00:59.783",
"last_edit_date": "2015-10-11T10:00:59.783",
"last_editor_user_id": "9008",
"owner_user_id": "2646",
"parent_id": "17269",
"post_type": "answer",
"score": 6
},
{
"body": "<https://ja.stackoverflow.com/a/17292/9008> \nで回答は頂いていますがRVMを使った場合の例を記載しておきます。\n\n 1. プロジェクトディレクトリを作って移動する \n`mkdir hoge_project && cd hoge_project`\n\n 2. rvm系の準備 \n`echo '2.3.0' > .ruby-version` \n`echo 'hoge_project' > .ruby-gemset` \n`cd -` \n`cd -` \nrvm系の設定をしたあと、ディレクトリを出て入り直さないといけない。 \n`gem install bundler` \nbundlerをrvmで指定したruby用にインストール。\n\n 3. Gemfileを作る \n`bundle init` \nhoge_project配下にGemfileがつくられます。\n\n 4. vimでGemファイルを修正 \n`gem \"rails\"`の部分がコメントアウトされているのでコメントアウトを取る\n\n 5. bundle installする \n`bundle install --path vendor/bundle` \n`vendor/bundle`を指定してbundle installする。\n\n 6. rails newする \n<https://ja.stackoverflow.com/a/17278/9008> \nで頂いた回答を参考に \n`bundle exec rails new . -B` \nこのときGemfileをオーバーライトしますかというようなメッセージがでるのでYESと答える。(`-B`を付けずにYESと答えてしまうとうまくいかなかった)\n\n 7. オーバーライトされたGemfileでもう一度 bundle install \n`bundle install` \n一度`--path\nvendor/bundle`して実行しているので、`.bundle/config`ファイルが作られ、`vendor/bundle`にインストールすることを記憶しているので、今回から`--path\nvendor/bundle`は不要。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-01-11T02:00:33.220",
"id": "20815",
"last_activity_date": "2016-01-11T02:00:33.220",
"last_edit_date": "2017-04-13T12:52:38.920",
"last_editor_user_id": "-1",
"owner_user_id": "9008",
"parent_id": "17269",
"post_type": "answer",
"score": 0
}
] |
17269
|
17292
|
17292
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "`TableView`のセルの大きさをコンテンツの内容に応じて変えたいのですが、どうすればいいのかが分かりません。例えば以下のような`TableView`のセルがあるとします。\n\n[](https://i.stack.imgur.com/PMM4x.jpg)\n\nこのセルの一番上にある`TextView`の行が増えたり減ったりすることに応じてセルの高さを変えたいです。これを実現するには`AutoLayout`だけで可能でしょうか? \nまた、`TextView`の下にある画像は表示するかしないかが選択でき、画像を表示しない場合だと`ImageView`がなくなった分だけセルの高さを縮めるといったことも行いたいです。 \n以上のことを行うにはどうすればいいでしょうか? \n自分で`AutoLayout`を設定したりしたものの、セルの高さがずっと変わりません。 \nどなたか分かる方がいれば教えていただきたいです。 \nすみませんが、宜しくお願いします。\n\n\\---追記---\n\niOSのバージョンは9.0.1、Xcodeのバージョンは7.0.1で、Storyboardを使っています。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T09:49:08.180",
"favorite_count": 0,
"id": "17271",
"last_activity_date": "2016-10-20T15:00:29.477",
"last_edit_date": "2015-10-06T00:54:05.487",
"last_editor_user_id": "5210",
"owner_user_id": "5210",
"post_type": "question",
"score": 1,
"tags": [
"ios",
"objective-c",
"uitableview",
"autolayout"
],
"title": "TableViewのセルの大きさを可変にする",
"view_count": 1384
}
|
[
{
"body": "> (CGFloat)tableView:heightForRowAtIndexPath \n> 読んで字のごとく、各行の高さを決めるメソッド。 \n> tableView:cellForRowAtIndexPath: よりも先に呼び出される。\n\n<http://qiita.com/kotaroito/items/8bd2f10833e07f7a5809>\n\n```\n\n コードをここに入力- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{\n // 表示したい文字列\n NSString *text = _objects[indexPath.row];\n // 表示最大幅・高さ\n CGSize maxSize = CGSizeMake(200, CGFLOAT_MAX);\n // 表示するフォントサイズ\n NSDictionary *attr = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:17.0]};\n \n // 以上踏まえた上で、表示に必要なサイズ\n CGSize modifiedSize = [text boundingRectWithSize:maxSize\n options:NSStringDrawingUsesLineFragmentOrigin\n attributes:attr\n context:nil\n ].size;\n \n // 上下10pxずつの余白を加えたものと70pxのうち、大きい方を返す\n return MAX(modifiedSize.height + 20, 70);}\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-22T08:50:48.820",
"id": "17946",
"last_activity_date": "2015-10-22T09:05:26.533",
"last_edit_date": "2015-10-22T09:05:26.533",
"last_editor_user_id": "12902",
"owner_user_id": "12902",
"parent_id": "17271",
"post_type": "answer",
"score": 1
},
{
"body": "おそらくTextViewはスクロールさせないだろうという前提です。\n\nStoryboardでは \n\\- TextViewには高さのConstraintは設定しない。上下左右のConstraintは設定する。 \n\\- TextViewのScrolling Enabledはオフにする。 \n\\- ImageViewには高さのConstraintを設定して、カスタムセルにIBOutletプロパティとして持たせる。\n\nコードでは \n\\-\nviewDidLoaded()あたりでrowHeightとestimatedRowHeightをテーブルに設定する。estimatedRowHeightはご自身のセルに合わせてだいたいの値を設定する。\n\n```\n\n self.tableView.rowHeight = UITableViewAutomaticDimension;\n self.tableView.estimatedRowHeight = 100.0;\n \n```\n\n * 画像を表示しない場合はtableView(tableView:cellForRowAtIndexPath:)でStoryboardで設定したImageViewの高さConstraintに0.0を設定する。\n\n以上でAutoLayoutのみでTextViewの高さが自動的に変わり、ImageViewが必要ない場合にその分セルの高さが小さくなると思います。\n\nもしTextViewをスクロール可能な状態で高さを制限したい場合は、UITextViewのサブクラスでintrinsicContentSizeをオーバーライドすることになるはずです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T14:03:42.397",
"id": "23301",
"last_activity_date": "2016-03-21T00:00:07.243",
"last_edit_date": "2016-03-21T00:00:07.243",
"last_editor_user_id": "238",
"owner_user_id": "238",
"parent_id": "17271",
"post_type": "answer",
"score": 1
}
] |
17271
| null |
17946
|
{
"accepted_answer_id": "17276",
"answer_count": 2,
"body": "**質問背景**\n\n```\n\n $(cd $(dirname $0)/.. && pwd)\n \n```\n\nについてネット検索してみたら、\n\n```\n\n $(cd $(dirname $0) && pwd)\n \n```\n\nに関するページが見つかりました\n\n**質問**\n\n * 両者の違いを教えてください\n * `/..` に特別な意味はある?\n\n**最終的に知りたいこと**\n\n```\n\n $(cd $(dirname $0)/.. && pwd)\n \n```\n\nは、どういう意味でしょうか? 多分、どのような環境でも動作するように設定していると思うのですが…",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T11:33:21.747",
"favorite_count": 0,
"id": "17274",
"last_activity_date": "2015-10-05T13:12:38.697",
"last_edit_date": "2015-10-05T12:51:58.597",
"last_editor_user_id": null,
"owner_user_id": "7886",
"post_type": "question",
"score": 6,
"tags": [
"bash",
"sh"
],
"title": "$(cd $(dirname $0)/.. && pwd) と $(cd $(dirname $0) && pwd) の違い",
"view_count": 10655
}
|
[
{
"body": "最初に質問に答えると次のようになります。\n\n * `$(cd $(dirname $0) && pwd)` ... 実行中のスクリプトがあるディレクトリの絶対パス (`/` で始まるパス) 文字列\n * `$(cd $(dirname $0)/.. && pwd)` ... 実行中のスクリプトがあるディレクトリの親ディレクトリの絶対パス文字列\n\nここで使われているシェル変数やコマンド、構文の意味は次のとおりです。\n\n * `$0` は実行中のスクリプトのパス (`bash` や `sh` に渡された引数そのもの) を表します。 \n * [`dirname`](http://pubs.opengroup.org/onlinepubs/009696799/utilities/dirname.html) は引数で与えたパス文字列のディレクトリ部分を返すコマンドです。\n * [`pwd`](http://pubs.opengroup.org/onlinepubs/009696799/utilities/pwd.html) はカレントディレクトリを絶対パスで返すコマンドです。\n * `$( ... )` はシェルで `...` を実行した結果 (標準出力) の文字列に置き換えられます。\n\n一般に `$(cd DIR && pwd)` は、ディレクトリ `DIR` (相対パスを含む) の絶対パスを取得するためのポータブルな方法と考えられます。\n\n実際に実行してみるのが理解が早いでしょう。次のようなファイル `script.sh` をいろんな場所に置いて実行してみてください。\n\n```\n\n #!/bin/sh\n echo $0\n echo $(dirname $0)\n echo $(cd $(dirname $0) && pwd)\n echo $(cd $(dirname $0)/.. && pwd)\n \n```\n\n`/tmp/script.sh` に置いて実行した場合は次のようになります。\n\n```\n\n $ bash /tmp/script.sh \n /tmp/script.sh\n /tmp\n /tmp\n /\n \n```\n\nポイントは bash にスクリプトとして相対パスを指定して実行したときです。\n\n```\n\n $ cd /tmp\n $ bash script.sh \n script.sh\n .\n /tmp\n /\n \n```\n\n相対パスが渡されても `pwd` により絶対パスが得られていることがわかります。\n\nまた `pwd` はシェルが `$PWD`\nで保持する「論理的な」カレントディレクトリを返します。次のようなシンボリックリンクを含むディレクトリに移動して実行してみるとそれがわかります。\n\n```\n\n $ ln -s . /tmp/dir\n $ cd /tmp/dir/dir/dir/dir\n $ bash script.sh \n script.sh\n .\n /tmp/dir/dir/dir/dir\n /tmp/dir/dir/dir\n \n```\n\n`script.sh` の実体が置かれているディレクトリは `/tmp` ですが、 `pwd` は `cd` で移動した論理的なカレントディレクトリ\n`/tmp/dir/dir/dir/dir` を返しています。シンボリックリンクの影響を排除した絶対パスを得るには `pwd -P` が使えます。\n\n```\n\n $ cd /tmp/dir/dir/dir/dir\n $ pwd\n /tmp/dir/dir/dir/dir\n $ pwd -P\n /tmp\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T12:06:44.380",
"id": "17276",
"last_activity_date": "2015-10-05T12:28:58.303",
"last_edit_date": "2015-10-05T12:28:58.303",
"last_editor_user_id": "9873",
"owner_user_id": "9873",
"parent_id": "17274",
"post_type": "answer",
"score": 8
},
{
"body": "質問の内容とは関係がありませんが、スクリプトファイルのパスにスペースやタブが含まれている場合を考慮しておいた方が良いかと思います。\n\n```\n\n $ pwd\n /home/nemo\n \n $ mkdir $'foo bar'\n \n foo\\ bar/a.sh:\n ==============\n #!/bin/bash\n echo $(cd $(dirname $0) && pwd)\n ==============\n \n $ ls foo\\ bar/\n a.sh\n \n $ ./foo\\ bar/a.sh\n /home/nemo\n \n```\n\nとなってしまいます。\n\nこれは、\n\n```\n\n $ dirname ./foo bar/a.sh\n .\n bar\n \n```\n\nとなってしまうためです。なので、クォートしておいた方が無難かな、と思います。\n\n```\n\n => echo $(cd \"$(dirname \"$0\")\" && pwd)\n \n $ foo\\ bar/a.sh\n /home/nemo/foo bar\n \n```\n\nさらに、パス名に改行コードが含まれている可能性も考慮する必要があるかもしれません(その場合は更に `$(cd ..)` 全体をクォートします)。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T13:12:38.697",
"id": "17284",
"last_activity_date": "2015-10-05T13:12:38.697",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "17274",
"post_type": "answer",
"score": 3
}
] |
17274
|
17276
|
17276
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "IBM Containers を使用したところ、アプリケーションの(おそらく)ネットワーク接続問題でアプリが高頻度で停止します。\n\nこのアプリでは、コンテナで起動しているアプリはslackへ接続するhubotで、slackへのwebsocket通信が一定時間途絶えるとアプリが停止する作りになっています。IBM\nContainersのグループ機能を使ったり、コンテナ内部でアプリをデーモン化し再起動する運用もためしましたが、いろいろと試行錯誤した10日間で約200回以上の停止がありました。試しに、自宅サーバへコンテナを移動した後には問題なく稼働しています。\n\nIBM Containers上で websocket通信が規制されているなどの制限事項があるのでしょうか?",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T11:45:42.663",
"favorite_count": 0,
"id": "17275",
"last_activity_date": "2015-10-05T12:18:32.450",
"last_edit_date": "2015-10-05T12:18:32.450",
"last_editor_user_id": "76",
"owner_user_id": "12591",
"post_type": "question",
"score": 1,
"tags": [
"bluemix"
],
"title": "Bluemix Containers サービス利用で制限等ありますか?",
"view_count": 117
}
|
[] |
17275
| null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "startServiceで起動したサービスがActivityと同一プロセスで動作する前提であれば、 \nサービスとActivityのデータのやりとりはバインド等の煩雑な方法を利用せずに、 \nandroid.app.Applicationインスタンスをグローバル変数的に利用して良いのでしょうか?\n\n言い換えると、サービスが実行中であれば必ずそのベースとなるApplicationインスタンスが存在するのでしょうか?\n\nAndroidの一般的な作法が判っていないので見当違いなことを言っているかもしれませんが、 \n回答いただけると大変助かります。 \nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T12:30:26.247",
"favorite_count": 0,
"id": "17281",
"last_activity_date": "2016-07-15T17:22:14.920",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12592",
"post_type": "question",
"score": 3,
"tags": [
"android"
],
"title": "Androidでのサービスとの通信方法について",
"view_count": 1490
}
|
[
{
"body": "> アプリケーション コンポーネントが開始し、アプリケーションに他に実行中のコンポーネントがない場合、Android システムは実行用のシングル\n> スレッドを持つアプリケーション用の新しい Linux プロセスを開始します。\n>\n> [プロセスとスレッド](http://developer.android.com/intl/ja/guide/components/processes-\n> and-threads.html)\n\nAndroidのコンポーネント、\n\n * `Activity`\n * `BroadcastReceiver`\n * `ContentProvider`\n * `Service`\n\nのいずれかが動作すると、Androidシステムはアプリケーションプロセスを開始します。このとき、`android.app.Application`インスタンスの`onCreate()`が呼び出されます。\n\nですので、\n\n> サービスが実行中であれば必ずそのベースとなるApplicationインスタンスが存在するのでしょうか?\n\nという問いに対しては、「必ず存在する」が答えとなります。\n\nただしプロセスはOSによって殺されるため、`Application`は短命なデータストアとして、スレッドセーフな設計で作る必要があると思います。また、同じデータを読み取ることはできますが、通信的なことはできません。\n\n`Activity`が書き込んだ値を`Service`で読み取るというような単純なことは実現できますが、それであれば`Intent`に`data`を持たせてもいいわけです。\n\n逆に`Service`が書き込んだ値を`Activity`が読み取るには、いつ`Service`の処理が終わったのかを`Activity`が判断できない(それであれば、`BroadcastReceiver`でデータの受け渡しを行った方が良い)ですし、先に述べた通り`Application`プロセスがOSに殺されて、`Service`がセットした値が失われている可能性があります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T15:09:08.353",
"id": "17381",
"last_activity_date": "2015-10-07T15:09:08.353",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5337",
"parent_id": "17281",
"post_type": "answer",
"score": 1
}
] |
17281
| null |
17381
|
{
"accepted_answer_id": "17306",
"answer_count": 2,
"body": "`ListBox`上の`ListBoxItem`、または`ListBox`上の`ListBox.Background`が見えている領域に対してDrag&Dropを行い、要素の並べ替え/挿入を行おうとしています。\n\nこの時、`ListBox`の背景要素にDropした際、Dropした位置によって適切な挿入先のIndexを計算する方法が分からず、詰まってしまっています。\n\n**\\- 出来たこと** \n`ListBox`上の`ListBoxItem`に対するDropは、`DragEventArgs.OriginalSource`を使って現在Dropしようとしている先の`FrameworkElement`を特定→`ListBox.ItemsSource`から`DataContext`の内容で探す……などの方法でDrop先Indexを計算する事ができました。\n\n**\\- 出来なくて困っていること(知りたいこと)** \n`ListBox`上のDrop位置において、以下の図のような領域⇔Index値となる計算をしたいのですが、以下の3点を計算・区別する方法が分かりませんでした。\n\n 1. `ListBoxItem`間のMarginの位置へのDrop時のIndex計算\n 2. `WrapPanel`での折り返し位置(図上のIndex 4の位置)へのDrop時のIndex計算\n 3. 1,2に含まれない末尾全般領域(図上のIndex 6の位置)へのDrop時のIndex計算\n\n[](https://i.stack.imgur.com/8L9NI.png)\n\n実現方法が分かる方、よろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T12:56:39.553",
"favorite_count": 0,
"id": "17283",
"last_activity_date": "2015-10-09T06:27:20.587",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "6119",
"post_type": "question",
"score": 4,
"tags": [
"c#",
".net",
"wpf",
"xaml"
],
"title": "ListBoxの背景にDrap&Dropする際にDrop先Indexを計算するには?",
"view_count": 719
}
|
[
{
"body": "泥臭い解法ですが…`ListBoxItem`の領域を左上から順に取得し、マウス座標の手前にあるかどうかを判定する方法で実装できます。\n\n下記のサンプルコードでは、`GetNextItem`メソッドでマウス座標直後にある`ListBoxItem`を取得し、リスト内のインデックスは`MoveItem`メソッド内の`IList.IndexOf`で取得しています。\n\n**MainWindow.xaml.cs**\n\n```\n\n using System.Collections;\n using System.Collections.Generic;\n using System.Linq;\n using System.Windows;\n using System.Windows.Controls;\n using System.Windows.Input;\n using System.Windows.Media;\n \n namespace WpfApplication1\n {\n /// <summary>\n /// MainWindow.xaml の相互作用ロジック\n /// </summary>\n public partial class MainWindow : Window\n {\n private ListBoxItem DropTarget;\n \n public MainWindow()\n {\n InitializeComponent();\n \n Loaded += MainWindow_Loaded;\n LstSample.MouseMove += LstSample_MouseMove;\n LstSample.PreviewMouseLeftButtonUp += LstSample_PreviewMouseLeftButtonUp;\n LstSample.Drop += LstSample_Drop;\n }\n \n private void LstSample_MouseMove(object sender, MouseEventArgs e)\n {\n if (e.LeftButton != MouseButtonState.Pressed || DropTarget == null)\n {\n return;\n }\n DragDrop.DoDragDrop((ListBox)sender, DropTarget, DragDropEffects.Move);\n }\n \n private void LstSample_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)\n {\n DropTarget = null;\n }\n \n private void LstSample_Drop(object sender, DragEventArgs e)\n {\n if (DropTarget == null)\n {\n return;\n }\n var listBox = (ListBox)sender;\n var list = (IList)listBox.ItemsSource;\n MoveItem(list, DropTarget, GetNextItem(listBox, e.GetPosition(listBox)));\n listBox.ItemsSource = null;\n listBox.ItemsSource = list;\n }\n \n /// <summary>\n /// Dropした位置の直後にあるListBoxItemを取得する。該当がなければnullを返す\n /// </summary>\n /// <param name=\"listBox\"></param>\n /// <param name=\"drop\"></param>\n /// <returns></returns>\n private static ListBoxItem GetNextItem(ListBox listBox, Point drop)\n {\n return listBox.ItemsSource.OfType<ListBoxItem>().FirstOrDefault(q =>\n {\n //ListBoxItemの左上座標\n var p = q.TranslatePoint(new Point(), listBox);\n //ドロップした位置が、現在のListBoxItem上端より上\n if (drop.Y < p.Y - q.Margin.Top) return true;\n //ListBoxItem中央下部座標\n p.Offset(q.Width / 2d, q.Height);\n //ドロップした位置が、現在のListBoxItem下端より下\n if (p.Y < drop.Y) return false;\n //ドロップした位置が、現在のListBoxItem行内\n return (drop.X < p.X);\n });\n }\n \n private static void MoveItem(IList list, ListBoxItem target, ListBoxItem next)\n {\n var delIndex = list.IndexOf(target);\n if (next == null)\n {\n list.Add(target);\n }\n else\n {\n var index = list.IndexOf(next);\n delIndex += (index < delIndex) ? 1 : 0;\n list.Insert(index, target);\n }\n list.RemoveAt(delIndex);\n }\n \n private void MainWindow_Loaded(object sender, RoutedEventArgs e)\n {\n var list = new List<ListBoxItem>\n {\n GetItem(\"1\"),\n GetItem(\"2\"),\n GetItem(\"3\"),\n GetItem(\"4\"),\n GetItem(\"5\"),\n };\n LstSample.ItemsSource = list;\n LstSample.Items.IsLiveSorting = true;\n }\n \n private ListBoxItem GetItem(string content)\n {\n var item = new ListBoxItem\n {\n Content = content,\n Width = 150,\n Height = 150,\n Margin = new Thickness(15),\n HorizontalContentAlignment = HorizontalAlignment.Center,\n Background = new SolidColorBrush(Colors.AliceBlue),\n };\n item.PreviewMouseLeftButtonDown += (sender, e) =>\n {\n DropTarget = item;\n };\n return item;\n }\n }\n }\n \n```\n\n**MainWindow.xaml**\n\n```\n\n <Window x:Class=\"WpfApplication1.MainWindow\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n xmlns:d=\"http://schemas.microsoft.com/expression/blend/2008\"\n xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"\n xmlns:local=\"clr-namespace:WpfApplication1\"\n mc:Ignorable=\"d\"\n Title=\"MainWindow\" Height=\"350\" Width=\"525\" >\n <Grid>\n <ListBox Name=\"LstSample\" ScrollViewer.HorizontalScrollBarVisibility=\"Disabled\" AllowDrop=\"True\">\n <ListBox.ItemsPanel>\n <ItemsPanelTemplate>\n <WrapPanel />\n </ItemsPanelTemplate>\n </ListBox.ItemsPanel>\n </ListBox>\n </Grid>\n </Window>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T04:53:52.553",
"id": "17306",
"last_activity_date": "2015-10-06T04:53:52.553",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9820",
"parent_id": "17283",
"post_type": "answer",
"score": 2
},
{
"body": "Drop可能な領域にDrop用の`ListBoxItem`を敷き詰めたダミーの`ListBox`を新たに設けてはどうでしょうか。これで元の`ListBoxItem`のMargin領域、折り返し領域、要素未配置領域は考慮せずに済むかと思います。図表の黒枠の通りの`ListBox`を新たに作成するようなイメージです。\n\n処理の流れのみで申し訳ないですが、 \n仮に元の並べ替え・挿入対象の`ListBox`を「ItemsPanel」、新たな`ListBox`を「DropItemsPanel」として、「ItemsPanel」の`ListBoxItem`Drag開始で「DropItemsPanel」を有効化し、「DropItemsPanel」の`ListBoxItem`へDropします。そのIndex値を取得し、「ItemsPanel」の並べ替え・挿入処理を行い、「DropItemsPanel」を再び非表示、という実装です。\n\n**Window1.xaml**\n\n```\n\n <Window x:Class=\"WpfApplication1.Window1\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Title=\"Window1\" Height=\"400\" Width=\"600\">\n <Grid> \n <ListBox Name=\"ItemsPanel\" ScrollViewer.HorizontalScrollBarVisibility=\"Disabled\">\n <ListBox.ItemsPanel>\n <ItemsPanelTemplate>\n <WrapPanel />\n </ItemsPanelTemplate>\n </ListBox.ItemsPanel>\n <ListBoxItem Background=\"Aquamarine\" Width=\"100\" Height=\"100\" Margin=\"10\" Content=\"1\" HorizontalContentAlignment=\"Center\" />\n <ListBoxItem Background=\"Aquamarine\" Width=\"100\" Height=\"100\" Margin=\"10\" Content=\"2\" HorizontalContentAlignment=\"Center\" />\n <ListBoxItem Background=\"Aquamarine\" Width=\"100\" Height=\"100\" Margin=\"10\" Content=\"3\" HorizontalContentAlignment=\"Center\" />\n <ListBoxItem Background=\"Aquamarine\" Width=\"100\" Height=\"100\" Margin=\"10\" Content=\"4\" HorizontalContentAlignment=\"Center\" />\n <ListBoxItem Background=\"Aquamarine\" Width=\"100\" Height=\"100\" Margin=\"10\" Content=\"5\" HorizontalContentAlignment=\"Center\" />\n <ListBoxItem Background=\"Aquamarine\" Width=\"100\" Height=\"100\" Margin=\"10\" Content=\"6\" HorizontalContentAlignment=\"Center\" />\n </ListBox>\n <ListBox Name=\"DropItemsPanel\" ScrollViewer.HorizontalScrollBarVisibility=\"Disabled\" AllowDrop=\"True\" Opacity=\"0.5\" Margin=\"-60,0,-60,0\">\n <ListBox.ItemsPanel>\n <ItemsPanelTemplate>\n <WrapPanel />\n </ItemsPanelTemplate>\n </ListBox.ItemsPanel>\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"1\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"2\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"3\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"4\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"5\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"6\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"7\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"8\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"8\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"8\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"8\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"8\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"8\" />\n <ListBoxItem Width=\"120\" Height=\"120\" BorderBrush=\"DarkBlue\" BorderThickness=\"1\" Content=\"8\" />\n </ListBox>\n </Grid>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-09T06:27:20.587",
"id": "17469",
"last_activity_date": "2015-10-09T06:27:20.587",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5133",
"parent_id": "17283",
"post_type": "answer",
"score": -1
}
] |
17283
|
17306
|
17306
|
{
"accepted_answer_id": "17505",
"answer_count": 1,
"body": "質問の要点を分かりやすくするために、ソースコードを簡略化しました。 \nサイト関係者に迷惑をかけまして、申し訳ありませんでした。\n\n質問ですが、画面を見ていただけると分かりますが、selectのそれぞれのカラーボタン(D・F・H・M・S)を同一色に押した場合、時計全体の色を付けるCボタンそのものの色も同じになるように設定したいのです。1つでも違う色が設定されれば、Cボタンは白になるように設定しています。\n\nもう1つの質問は、一度時計を消したら、好みに設定した時計の色をその背景色のときの初期の状態に戻すようにしたいのです。 \nソースコードでは、背景色がsilverのときの初期の時計の色は\"mediumblue\",背景色がmediumblueのときの初期の時計の色は\"black\",背景色が\"black\"のときの初期の時計の色は\"silver\"と設定しています。\n\n2つの質問とも\"ifの条件式\"で組み立てる必要があると思いますが、うまくいかなくて頭が混乱しています。ご教示お願いします。\n\n```\n\n <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n <html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=shift_jis\"> \n <meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\">\n \n <title></title>\n \n <style type=\"text/css\">\n <!--\n .butt {\n BACKGROUND:maroon; \n COLOR:gold;\n }\n #clock {\n color:silver;\n }\n #clockCOLOR {\n background:lightpink;\n background-color:silver;\n color:black;\n }\n #color1 {\n background:lightpink;\n background-color:silver;\n color:black;\n }\n #color2 {\n background:lightpink;\n background-color:silver;\n color:black;\n }\n #color3 {\n background:lightpink;\n background-color:silver;\n color:black;\n }\n #color4 {\n background:lightpink;\n background-color:silver;\n color:black;\n }\n #color5 {\n background:lightpink;\n background-color:silver;\n color:black;\n }\n //-->\n </style>\n \n <script type=\"text/javascript\"> \n <!--\n function bg1() {\n document.bgColor = \"silver\";\n document.getElementById('Od').style.color='mediumblue';\n document.getElementById('Of').style.color='mediumblue';\n document.getElementById('Oh').style.color='mediumblue';\n document.getElementById('Om').style.color='mediumblue';\n document.getElementById('Os').style.color='mediumblue';\n document.getElementById(\"clockCOLOR\").style.background=\"mediumblue\";\n document.getElementById(\"color1\").style.background=\"mediumblue\";\n document.getElementById(\"color2\").style.background=\"mediumblue\";\n document.getElementById(\"color3\").style.background=\"mediumblue\";\n document.getElementById(\"color4\").style.background=\"mediumblue\";\n document.getElementById(\"color5\").style.background=\"mediumblue\";\n }\n function bg2() {\n document.bgColor = \"mediumblue\";\n document.getElementById('Od').style.color='black';\n document.getElementById('Of').style.color='black';\n document.getElementById('Oh').style.color='black';\n document.getElementById('Om').style.color='black';\n document.getElementById('Os').style.color='black';\n document.getElementById(\"clockCOLOR\").style.background=\"black\";\n document.getElementById(\"color1\").style.background=\"black\";\n document.getElementById(\"color2\").style.background=\"black\";\n document.getElementById(\"color3\").style.background=\"black\";\n document.getElementById(\"color4\").style.background=\"black\";\n document.getElementById(\"color5\").style.background=\"black\";\n }\n function bg3() {\n document.bgColor = \"black\";\n document.getElementById('Od').style.color='silver';\n document.getElementById('Of').style.color='silver';\n document.getElementById('Oh').style.color='silver';\n document.getElementById('Om').style.color='silver';\n document.getElementById('Os').style.color='silver';\n document.getElementById(\"clockCOLOR\").style.background=\"silver\";\n document.getElementById(\"color1\").style.background=\"silver\";\n document.getElementById(\"color2\").style.background=\"silver\";\n document.getElementById(\"color3\").style.background=\"silver\";\n document.getElementById(\"color4\").style.background=\"silver\";\n document.getElementById(\"color5\").style.background=\"silver\";\n }\n //-->\n </script>\n \n <script type=\"text/javascript\">\n <!--\n function clockCOLOR1() {\n document.getElementById(\"Od\").style.color=\"silver\";\n document.getElementById(\"Of\").style.color=\"silver\";\n document.getElementById(\"Oh\").style.color=\"silver\";\n document.getElementById(\"Om\").style.color=\"silver\";\n document.getElementById(\"Os\").style.color=\"silver\";\n document.getElementById(\"clockCOLOR\").style.background=\"silver\";\n document.getElementById(\"color1\").style.background=\"silver\";\n document.getElementById(\"color2\").style.background=\"silver\";\n document.getElementById(\"color3\").style.background=\"silver\";\n document.getElementById(\"color4\").style.background=\"silver\";\n document.getElementById(\"color5\").style.background=\"silver\";\n }\n function clockCOLOR2() {\n document.getElementById(\"Od\").style.color=\"mediumblue\";\n document.getElementById(\"Of\").style.color=\"mediumblue\";\n document.getElementById(\"Oh\").style.color=\"mediumblue\";\n document.getElementById(\"Om\").style.color=\"mediumblue\";\n document.getElementById(\"Os\").style.color=\"mediumblue\";\n document.getElementById(\"clockCOLOR\").style.background=\"mediumblue\";\n document.getElementById(\"color1\").style.background=\"mediumblue\";\n document.getElementById(\"color2\").style.background=\"mediumblue\";\n document.getElementById(\"color3\").style.background=\"mediumblue\";\n document.getElementById(\"color4\").style.background=\"mediumblue\";\n document.getElementById(\"color5\").style.background=\"mediumblue\";\n }\n function clockCOLOR3() {\n document.getElementById(\"Od\").style.color=\"black\";\n document.getElementById(\"Of\").style.color=\"black\";\n document.getElementById(\"Oh\").style.color=\"black\";\n document.getElementById(\"Om\").style.color=\"black\";\n document.getElementById(\"Os\").style.color=\"black\";\n document.getElementById(\"clockCOLOR\").style.background=\"black\";\n document.getElementById(\"color1\").style.background=\"black\";\n document.getElementById(\"color2\").style.background=\"black\";\n document.getElementById(\"color3\").style.background=\"black\";\n document.getElementById(\"color4\").style.background=\"black\";\n document.getElementById(\"color5\").style.background=\"black\";\n }\n function Col11() {\n document.getElementById(\"Od\").style.color=\"silver\";\n document.getElementById(\"color1\").style.background=\"silver\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col12() {\n document.getElementById(\"Od\").style.color=\"mediumblue\";\n document.getElementById(\"color1\").style.background=\"mediumblue\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col13() {\n document.getElementById(\"Od\").style.color=\"black\";\n document.getElementById(\"color1\").style.background=\"black\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col21() {\n document.getElementById(\"Of\").style.color=\"silver\";\n document.getElementById(\"color2\").style.background=\"silver\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col22() {\n document.getElementById(\"Of\").style.color=\"mediumblue\";\n document.getElementById(\"color2\").style.background=\"mediumblue\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col23() {\n document.getElementById(\"Of\").style.color=\"black\";\n document.getElementById(\"color2\").style.background=\"black\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col31() {\n document.getElementById(\"Oh\").style.color=\"silver\";\n document.getElementById(\"color3\").style.background=\"silver\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col32() {\n document.getElementById(\"Oh\").style.color=\"mediumblue\";\n document.getElementById(\"color3\").style.background=\"mediumblue\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col33() {\n document.getElementById(\"Oh\").style.color=\"black\";\n document.getElementById(\"color3\").style.background=\"black\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col41() {\n document.getElementById(\"Om\").style.color=\"silver\";\n document.getElementById(\"color4\").style.background=\"silver\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col42() {\n document.getElementById(\"Om\").style.color=\"mediumblue\";\n document.getElementById(\"color4\").style.background=\"mediumblue\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col43() {\n document.getElementById(\"Om\").style.color=\"black\";\n document.getElementById(\"color4\").style.background=\"black\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col51() {\n document.getElementById(\"Os\").style.color=\"silver\";\n document.getElementById(\"color5\").style.background=\"silver\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col52() {\n document.getElementById(\"Os\").style.color=\"mediumblue\";\n document.getElementById(\"color5\").style.background=\"mediumblue\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n function Col53() {\n document.getElementById(\"Os\").style.color=\"black\";\n document.getElementById(\"color5\").style.background=\"black\";\n document.getElementById(\"clockCOLOR\").style.background=\"white\";\n }\n //-->\n </script>\n </head>\n \n <body bgcolor=\"black\">\n <div id=\"clock\" style=\"visibility:hidden\">\n <div id=\"Od\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n <div id=\"Of\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n <div id=\"Oh\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n <div id=\"Om\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n <div id=\"Os\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n </div>\n \n <script type=\"text/javascript\">\n \n (function() {\n \"use strict\";\n \n function $(sel) {\n return document.getElementById(sel);\n } \n \n function $$(sel) {\n if (typeof document.getElementsByClassName === 'undefined') {\n return document.getElementsByName(sel);\n }\n return document.getElementsByClassName(sel);\n }\n \n var dCol = '', //date colour.\n sCol = '', //seconds colour.\n mCol = '', //minutes colour.\n hCol = '', //hours colour.\n fCol = '', //face color\n ClockHeight = 40,\n ClockWidth = 40,\n ClockFromMouseY = 0,\n ClockFromMouseX = 100,\n d = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"],\n m = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"],\n date = new Date(),\n day = date.getDate(),\n year = date.getYear() + 1900;\n \n var TodaysDate = \" \" + d[date.getDay()] + \" \" + day + \" \" + m[date.getMonth()] + \" \" + year;\n var D = TodaysDate.split('');\n var H = '...';\n H = H.split('');\n var M = '....';\n M = M.split('');\n var S = '.....';\n S = S.split('');\n var Face = '1 2 3 4 5 6 7 8 9 10 11 12',\n font = 'Helvetica, Arial, sans-serif',\n size = 1,\n speed = 0.6;\n Face = Face.split(' ');\n var n = Face.length;\n var a = size * 10;\n var ymouse = 0,\n xmouse = 0,\n scrll = 0,\n props = '<span style=\"font-family:' + font + ';font-size:' + size + 'em; color:#' + fCol + '\">',\n props2 = '<span style=\"font-family:' + font + ';font-size:' + size + 'em; color:#' + dCol + '\">';\n var Split = 360 / n;\n var Dsplit = 360 / D.length;\n var HandHeight = ClockHeight / 4.5; \n var HandWidth = ClockWidth / 4.5;\n var HandY = -7,\n HandX = -2.5,\n step = 0.06,\n currStep = 0,\n y = [],\n x = [],\n Y = [],\n X = [],\n Dy = [],\n Dx = [],\n DY = [],\n DX = [];\n var i;\n \n for (i = 0; i < n; i++) {\n y[i] = 0;\n x[i] = 0;\n Y[i] = 0;\n X[i] = 0;\n }\n \n for (i = 0; i < D.length; i++) {\n Dy[i] = 0;\n Dx[i] = 0;\n DY[i] = 0;\n DX[i] = 0;\n }\n \n var wrapper = $('clock');\n var html = ''\n \n // Date wrapper\n html = '';\n for (i = 0; i < D.length; i++) {\n html += '<div class=\"Date\" name=\"Date\" style=\"position:absolute;top:0px;left:0;height:' + a + ';width:' + a + ';text-align:center\">' + props2 + D[i] + '</span></div>';\n }\n $('Od').children[0].innerHTML = html;\n \n // Face wrapper\n html = '';\n for (i = 0; i < n; i++) {\n html += '<div class=\"Face\" name=\"Face\" style=\"position:absolute;top:0px;left:0;height:' + a + ';width:' + a + ';text-align:center\">' + props + Face[i] + '</span></div>';\n }\n $('Of').children[0].innerHTML = html;\n \n // Hours wrapper\n html = '';\n for (i = 0; i < H.length; i++) {\n html += '<div class=\"Hours\" name=\"Hours\" style=\"position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:' + hCol + ';text-align:center;font-weight:bold\">' + H[i] + '</div>';\n } \n $('Oh').children[0].innerHTML = html;\n \n // Minute wrapper\n html = '';\n for (i = 0; i < M.length; i++) {\n html += '<div class=\"Minutes\" name=\"Minutes\" style=\"position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:' + mCol + ';text-align:center;font-weight:bold\">' + M[i] + '</div>';\n } \n $('Om').children[0].innerHTML = html;\n \n // Seconds wrapper\n html = '';\n for (i = 0; i < S.length; i++) {\n html += '<div class=\"Seconds\" name=\"Seconds\" style=\"position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:' + sCol + ';text-align:center;font-weight:bold\">' + S[i] + '</div>';\n } \n $('Os').children[0].innerHTML = html;\n \n // Mouse move event handler\n function Mouse(evnt) {\n if (typeof evnt === 'undefined') {\n ymouse = event.Y + ClockFromMouseY;\n xmouse = event.X + ClockFromMouseX;\n } else {\n ymouse = evnt.clientY + ClockFromMouseY;\n xmouse = evnt.clientX + ClockFromMouseX;\n }\n }\n \n document.onmousemove = Mouse;\n \n function ClockAndAssign() {\n var time = new Date();\n var secs = time.getSeconds();\n var sec = -1.57 + Math.PI * secs / 30;\n var mins = time.getMinutes();\n var min = -1.57 + Math.PI * mins / 30;\n var hr = time.getHours();\n var hrs = -1.575 + Math.PI * hr / 6 + Math.PI * parseInt(time.getMinutes(), 10) / 360;\n \n $('Od').style.top = window.document.body.scrollTop;\n $('Of').style.top = window.document.body.scrollTop;\n $('Oh').style.top = window.document.body.scrollTop;\n $('Om').style.top = window.document.body.scrollTop;\n $('Os').style.top = window.document.body.scrollTop;\n \n for (i = 0; i < n; i++) {\n var F = $$('Face')[i];\n F.style.top = y[i] + ClockHeight * Math.sin(-1.0471 + i * Split * Math.PI / 180) + scrll;\n F.style.left = x[i] + ClockWidth * Math.cos(-1.0471 + i * Split * Math.PI / 180);\n }\n \n for (i = 0; i < H.length; i++) {\n var HL = $$('Hours')[i];\n HL.style.top = y[i] + HandY + (i * HandHeight) * Math.sin(hrs) + scrll;\n HL.style.left = x[i] + HandX + (i * HandWidth) * Math.cos(hrs);\n }\n \n for (i = 0; i < M.length; i++) {\n var ML = $$('Minutes')[i].style;\n ML.top = y[i] + HandY + (i * HandHeight) * Math.sin(min) + scrll;\n ML.left = x[i] + HandX + (i * HandWidth) * Math.cos(min);\n }\n \n for (i = 0; i < S.length; i++) {\n var SL = $$('Seconds')[i].style;\n SL.top = y[i] + HandY + (i * HandHeight) * Math.sin(sec) + scrll;\n SL.left = x[i] + HandX + (i * HandWidth) * Math.cos(sec);\n }\n \n for (i = 0; i < D.length; i++) {\n var DL = $$('Date')[i].style;\n DL.top = Dy[i] + ClockHeight * 1.5 * Math.sin(currStep + i * Dsplit * Math.PI / 180) + scrll;\n DL.left = Dx[i] + ClockWidth * 1.5 * Math.cos(currStep + i * Dsplit * Math.PI / 180);\n }\n currStep -= step;\n }\n \n function Delay() {\n scrll = 0;\n Dy[0] = Math.round(DY[0] += ((ymouse) - DY[0]) * speed);\n Dx[0] = Math.round(DX[0] += ((xmouse) - DX[0]) * speed);\n for (i = 1; i < D.length; i++) {\n Dy[i] = Math.round(DY[i] += (Dy[i - 1] - DY[i]) * speed);\n Dx[i] = Math.round(DX[i] += (Dx[i - 1] - DX[i]) * speed);\n }\n y[0] = Math.round(Y[0] += ((ymouse) - Y[0]) * speed);\n x[0] = Math.round(X[0] += ((xmouse) - X[0]) * speed);\n for (i = 1; i < n; i++) {\n y[i] = Math.round(Y[i] += (y[i - 1] - Y[i]) * speed);\n x[i] = Math.round(X[i] += (x[i - 1] - X[i]) * speed);\n }\n ClockAndAssign();\n setTimeout(Delay, 20);\n }\n Delay();\n }());\n \n num = 1;\n function toggle() {\n num ^= 1; \n if(num == 1){\n document.getElementById('clock').style.visibility=\"hidden\";\n document.getElementById('clockCOLOR').disabled=true;\n document.getElementById('color1').disabled=true;\n document.getElementById('color2').disabled=true;\n document.getElementById('color3').disabled=true;\n document.getElementById('color4').disabled=true;\n document.getElementById('color5').disabled=true;\n } else {\n document.getElementById('clock').style.visibility=\"visible\";\n document.getElementById('clockCOLOR').disabled=false;\n document.getElementById('color1').disabled=false;\n document.getElementById('color2').disabled=false;\n document.getElementById('color3').disabled=false;\n document.getElementById('color4').disabled=false;\n document.getElementById('color5').disabled=false;\n }\n document.getElementById(\"tog\").value = num ?\" REVIVE \":\"KILL(切る)\";\n }\n //-->\n </script>\n \n <div style=\"text-align:center;\">\n <INPUT style=\"BORDER-RIGHT: grey 1px solid; BORDER-TOP:grey 1px solid; FONT-SIZE: 8pt; BORDER-LEFT: grey 1px solid; \n COLOR: black; BORDER-BOTTOM: grey 1px solid; FONT-FAMILY: ms gothic; BACKGROUND-COLOR: silver\"\n onclick=\"bg1()\" type=\"button\" value=\" \">\n <INPUT style=\"BORDER-RIGHT: grey 1px solid; BORDER-TOP:grey 1px solid; FONT-SIZE: 8pt; BORDER-LEFT: grey 1px solid; \n COLOR: black; BORDER-BOTTOM: grey 1px solid; FONT-FAMILY: ms gothic; BACKGROUND-COLOR: mediumblue\"\n onclick=\"bg2()\" type=\"button\" value=\" \">\n <INPUT style=\"BORDER-RIGHT: grey 1px solid; BORDER-TOP:grey 1px solid; FONT-SIZE: 8pt; BORDER-LEFT: grey 1px solid; \n COLOR: black; BORDER-BOTTOM: grey 1px solid; FONT-FAMILY: ms gothic; BACKGROUND-COLOR: black\"\n onclick=\"bg3()\" type=\"button\" value=\" \">\n </div>\n <br>\n <div style=\"text-align:center;\">\n <select id=\"clockCOLOR\" disabled>\n <option style=\"background-color:silver;font-weight:bold\" onclick=\"clockCOLOR1()\">C</option>\n <option style=\"background-color:mediumblue;font-weight:bold\" onclick=\"clockCOLOR2()\">C</option>\n <option style=\"background-color:black;font-weight:bold\" onclick=\"clockCOLOR3()\">C</option> \n </select>\n <select id=\"color1\" disabled>\n <option style=\"background-color:silver;font-weight:bold\" onclick=\"Col11()\">D</option>\n <option style=\"background-color:mediumblue;font-weight:bold\" onclick=\"Col12()\">D</option>\n <option style=\"background-color:black;font-weight:bold\" onclick=\"Col13()\">D</option>\n </select>\n <select id=\"color2\" disabled>\n <option style=\"background-color:silver;font-weight:bold\" onclick=\"Col21()\">F</option>\n <option style=\"background-color:mediumblue;font-weight:bold\" onclick=\"Col22()\">F</option>\n <option style=\"background-color:black;font-weight:bold\" onclick=\"Col23()\">F</option>\n </select>\n <select id=\"color3\" disabled>\n <option style=\"background-color:silver;font-weight:bold\" onclick=\"Col31()\">H</option>\n <option style=\"background-color:mediumblue;font-weight:bold\" onclick=\"Col32()\">H</option>\n <option style=\"background-color:black;font-weight:bold\" onclick=\"Col33()\">H</option>\n </select>\n <select id=\"color4\" disabled>\n <option style=\"background-color:silver;font-weight:bold\" onclick=\"Col41()\">M</option>\n <option style=\"background-color:mediumblue;font-weight:bold\" onclick=\"Col42()\">M</option>\n <option style=\"background-color:black;font-weight:bold\" onclick=\"Col43()\">M</option>\n </select>\n <select id=\"color5\" disabled>\n <option style=\"background-color:silver;font-weight:bold\" onclick=\"Col51()\">S</option>\n <option style=\"background-color:mediumblue;font-weight:bold\" onclick=\"Col52()\">S</option>\n <option style=\"background-color:black;font-weight:bold\" onclick=\"Col53()\">S</option>\n </select>\n <input id=\"tog\" class=\"butt\" type=\"button\" value=\"出現\" onclick=\"toggle()\">\n </div>\n </body>\n </html>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T14:03:27.510",
"favorite_count": 0,
"id": "17288",
"last_activity_date": "2015-10-11T14:37:51.147",
"last_edit_date": "2015-10-06T00:20:44.357",
"last_editor_user_id": "3516",
"owner_user_id": "9359",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"html"
],
"title": "アナログ時計を消したら、好みに設定した色を初期の色に戻す方法",
"view_count": 184
}
|
[
{
"body": "もう少しコードを削りシンプルな質問にした方が回答が得られやすいかと思います。 \n時計の機能を削った物をコードスニペットとして付けましたので、参考にして下さい。\n\n書き捨ての物ですので、グーバル変数の多用や、HTML中のコードの記述などよくない点が多いですが、以下の2点は参考になるかと思います。\n\n 1. 色の変更を、`style.color` などで逐次指定するのではなくdata属性やクラスの切り替えで行なっている点 \n今回は `data-theme` という属性を作り、これを切り替えています。 \n`[data-theme=\"テーマ名\"]`という形式のCSSセレクタで選択できますので、これにスタイルを当てます。\n\n 2. 状態の更新を一箇所に集めている点 \n時計のテーマと、select要素の状態(select要素自体のテーマ、選択されているoption要素)の更新は`set_theme`関数にまとめています。 \n指定された時計の各要素にテーマを当てたあと、時計のテーマを各select要素に反映する処理が毎回確実に入ります。\n\n```\n\n \"use strict\";\r\n var clock_parts = [$hour, $minute, $second];\r\n var clock_part_setters = [$hour_setter, $minute_setter, $second_setter];\r\n \r\n function for_each(array, func){ Array.prototype.forEach.call(array, func); }\r\n \r\n function get_theme(event){\r\n return event.target.options[event.target.selectedIndex].dataset.theme;\r\n }\r\n \r\n function select_option(select_elm, theme){\r\n select_elm.dataset.theme = theme;\r\n // IE hack\r\n select_elm.className = select_elm.className;\r\n \r\n for_each(select_elm.options, function(option_elm){\r\n if(option_elm.dataset.theme == theme){\r\n option_elm.selected = true;\r\n }\r\n });\r\n }\r\n \r\n function set_theme(elms, theme){\r\n for_each(elms, function(elm){\r\n elm.dataset.theme = theme;\r\n // IE hack\r\n elm.className = elm.className;\r\n \r\n });\r\n \r\n // update clock_part_setters\r\n for_each(clock_parts, function(part, i){\r\n select_option(clock_part_setters[i], part.dataset.theme);\r\n });\r\n \r\n // update $clock_setter\r\n var is_same_theme = clock_parts.every(function(part){\r\n return part.dataset.theme == clock_parts[0].dataset.theme;\r\n });\r\n if(is_same_theme){\r\n $clock_setter_none.hidden = true;\r\n select_option($clock_setter, clock_parts[0].dataset.theme);\r\n }\r\n else{\r\n $clock_setter_none.hidden = false;\r\n select_option($clock_setter, \"white\");\r\n }\r\n }\r\n \r\n function match_theme(){\r\n var theme_table = {\r\n // back_theme: \"clock_theme\",\r\n silver: \"blue\",\r\n blue: \"black\",\r\n black: \"silver\",\r\n };\r\n set_theme(clock_parts, theme_table[$back.dataset.theme]);\r\n }\n```\n\n```\n\n [data-theme=\"silver\"]{ color: black; background-color: silver; }\r\n [data-theme=\"blue\"]{ color: white; background-color: blue; }\r\n [data-theme=\"black\"]{ color: white; background-color: black; }\r\n [data-theme=\"white\"]{ color: black; background-color: white; }\r\n \r\n #\\$clock{ font-size: xx-large; }\n```\n\n```\n\n <body id=\"$back\" data-theme=\"silver\">\r\n <div id=\"$clock\">\r\n <span id=\"$hour\" data-theme=\"blue\">HH時</span>\r\n <span id=\"$minute\" data-theme=\"blue\">MM分</span>\r\n <span id=\"$second\" data-theme=\"blue\">SS秒</span>\r\n </div>\r\n \r\n <button onclick=\"$clock.hidden = !$clock.hidden; event.target.textContent = $clock.hidden ? 'Show' : 'Hide'; match_theme();\"\r\n data-theme=\"white\">\r\n Hide</button>\r\n <br />\r\n \r\n <button data-theme=\"silver\" onclick=\"set_theme([$back], 'silver'); match_theme();\">\r\n Silver</button>\r\n <button data-theme=\"blue\" onclick=\"set_theme([$back], 'blue'); match_theme();\">\r\n Blue</button>\r\n <button data-theme=\"black\" onclick=\"set_theme([$back], 'black'); match_theme();\">\r\n Black</button>\r\n <br />\r\n \r\n Clock:\r\n <select id=\"$clock_setter\" data-theme=\"blue\" autocomplete=\"off\"\r\n onchange=\"set_theme(clock_parts, get_theme(event));\">\r\n <option data-theme=\"silver\"> Silver</option>\r\n <option data-theme=\"blue\" selected> Blue </option>\r\n <option data-theme=\"black\"> Black </option>\r\n <option id=\"$clock_setter_none\" data-theme=\"white\" hidden> --- </option>\r\n </select>\r\n Hour:\r\n <select id=\"$hour_setter\" data-theme=\"blue\" autocomplete=\"off\"\r\n onchange=\"set_theme([$hour], get_theme(event));\">\r\n <option data-theme=\"silver\"> Silver </option>\r\n <option data-theme=\"blue\" selected> Blue </option>\r\n <option data-theme=\"black\"> Black </option>\r\n </select>\r\n Minute:\r\n <select id=\"$minute_setter\" data-theme=\"blue\" autocomplete=\"off\"\r\n onchange=\"set_theme([$minute], get_theme(event));\">\r\n <option data-theme=\"silver\"> Silver </option>\r\n <option data-theme=\"blue\" selected> Blue </option>\r\n <option data-theme=\"black\"> Black </option>\r\n </select>\r\n Second:\r\n <select id=\"$second_setter\" data-theme=\"blue\" autocomplete=\"off\"\r\n onchange=\"set_theme([$second], get_theme(event));\">\r\n <option data-theme=\"silver\"> Silver </option>\r\n <option data-theme=\"blue\" selected> Blue </option>\r\n <option data-theme=\"black\"> Black </option>\r\n </select>\r\n </body>\n```",
"comment_count": 12,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-10T14:29:41.910",
"id": "17505",
"last_activity_date": "2015-10-11T14:37:51.147",
"last_edit_date": "2015-10-11T14:37:51.147",
"last_editor_user_id": "3054",
"owner_user_id": "3054",
"parent_id": "17288",
"post_type": "answer",
"score": 1
}
] |
17288
|
17505
|
17505
|
{
"accepted_answer_id": "17316",
"answer_count": 2,
"body": "swiftプログラムでQRコードの読み取りには \n.metadataObjectTypes = [AVMetadataObjectTypeQRCode] \nと標準のフレームワークがありますが、QRコード作成の標準フレームワークが見つかりません。\n\nZXingObjCを使えばできるのですが、もし標準のフレームワークがあるのにZXingObjCを使っていても嫌なので、もしあればご教示お願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T14:24:41.663",
"favorite_count": 0,
"id": "17289",
"last_activity_date": "2022-08-10T08:50:06.113",
"last_edit_date": "2022-08-10T08:50:06.113",
"last_editor_user_id": "3060",
"owner_user_id": "8593",
"post_type": "question",
"score": 6,
"tags": [
"swift",
"qr-code"
],
"title": "swiftプログラムでQRコード作成",
"view_count": 2409
}
|
[
{
"body": "QRコードの生成には、Core Image frameworkに含まれている、`CIQRCodeGenerator`を使うことができます。\n\n<https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIQRCodeGenerator>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T16:59:24.047",
"id": "17295",
"last_activity_date": "2015-10-05T16:59:24.047",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5519",
"parent_id": "17289",
"post_type": "answer",
"score": 3
},
{
"body": "[`CIQRCodeGenerator`](https://developer.apple.com/library/prerelease/mac/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIQRCodeGenerator)\nで:\n\n```\n\n import UIKit\n import CoreImage\n \n func createQRCode(message: String, correctionLevel: String = \"M\", moduleSize: CGFloat = 1) -> UIImage {\n \n let dat = message.dataUsingEncoding(NSUTF8StringEncoding)!\n \n let qr = CIFilter(name: \"CIQRCodeGenerator\", withInputParameters: [\n \"inputMessage\": dat,\n \"inputCorrectionLevel\": correctionLevel,\n ])!\n \n // moduleSize でリサイズ\n let sizeTransform = CGAffineTransformMakeScale(moduleSize, moduleSize)\n let ciImg = qr.outputImage!.imageByApplyingTransform(sizeTransform)\n \n return UIImage(CIImage: ciImg, scale: 1, orientation: .Up)\n }\n \n```\n\n[](https://i.stack.imgur.com/EmosV.png)\n\n例では、`CIImage` バックエンドの `UIImage` を生成していますが、使用用途によっては`CGImage`\n取れないと不便かもしれないので、その場合最後の`return`文を:\n\n```\n\n let ciContext = CIContext(options: nil)\n let cgImg = ciContext.createCGImage(ciImg, fromRect: ciImg.extent)\n return UIImage(CGImage: cgImg, scale: 1, orientation: .Up)\n }\n \n```\n\nにすれば良いかと思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T08:38:00.510",
"id": "17316",
"last_activity_date": "2015-10-07T02:22:31.230",
"last_edit_date": "2015-10-07T02:22:31.230",
"last_editor_user_id": "3489",
"owner_user_id": "3489",
"parent_id": "17289",
"post_type": "answer",
"score": 9
}
] |
17289
|
17316
|
17316
|
{
"accepted_answer_id": "17379",
"answer_count": 1,
"body": "swiftプログラムを行っていてSegueの違いがいまいち理解できません。\n\n 1. show … 現在表示されている View Controller の一階層奥に押し出す形で画面遷移\n 2. show detail … 現在表示されている View Controller を新しい View Controller に置き換える形で画面遷移\n 3. present modally … 現在表示されている View Controller の上に積み重なる形で画面遷移\n 4. popover presentation … 現在表示されている View Controller を表示しつつ、新しい View Controller をポップオーバー\n 5. custom … ??\n\n 6. Relationship Segue view controller … Navigation barで使用\n\nというくらいの理解しかしていません。 \n結論として1-5についてはSegueの見え方の違いだけなのでしょうか? \nまた6に関してはNavigation barくらいにしか使ったことがないのですが、その理解であっているのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T14:42:12.517",
"favorite_count": 0,
"id": "17290",
"last_activity_date": "2015-10-07T14:20:45.967",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8593",
"post_type": "question",
"score": 4,
"tags": [
"swift"
],
"title": "swift Segueの種類について",
"view_count": 15156
}
|
[
{
"body": "以下、ざっくりとした説明で、抜けや間違いがあるかもしれません。\n\nStoryboardはアプリを「Scene」と「Segue」によって抽象化しています。\n\n「Scene」は大体画面と考えておけば問題ないです。ひとつの「Scene」は複数の「Scene」から構成されていることもあります。「Scene」同士の関係を表現するのが「Segue」です。\n\n### Adaptive Action Segue\n\nAction Segueは画面遷移を表現するSegueです。これらのSegueは現在のデバイスのSize\nClassや、コンテナビューコントローラの種類に応じて、異なる挙動をします。\n\n * **show** \nコンテナとなるビューコントローラがなければ単に上に積み重ねる形で表示を行います。`UINavigationController`がコンテナの場合は`pushViewController()`の遷移を行います。画面の間に繋がりがあり、「次」の画面を表示する場合に使う基本的なセグエです。\n\n * **show detail** \n`UISplitViewController`がコンテナの場合に、詳細ペインのビューコントローラを置き換える動きをします。画面のサイズによって2ペイン表示でなかった場合は、現在の画面を置き換える挙動をします。呼び出し元・先のSceneが一覧と詳細の関係の意味合いを持つことを示します。\n\n * **present modally** \n現在のコンテナの種類に関係なく、覆いかぶさるように新しいSceneを表示します。このケースでは、呼び出した元のSceneに対して何らかの応答を返すために用いられます。\n\n * **popover presentation** \nSceneをポップオーバーとして表示するものです。ポップオーバーとは、もともとiPadの広い画面ではモーダルウインドウの表示に全画面を使うよりも、画面の一部しか占有しないポップオーバーの方が求められたため登場しましたが、iPhoneの大画面化に伴いiPhoneでも使えるようになりました。\n\n### Non-Adaptive Action Segue\n\nSize\nClassの概念がなかったiOS8以前に存在したSegueです。状況に関わらず、`push`や`modal`の遷移を行います。(適切な状況で使わなかった場合、クラッシュします)\n\nこれらについては、もう推奨されない機能ですので、説明を割愛します。\n\n### Others\n\n * **custom** \n画面遷移の見栄えを自作したい場合に使うSegueです。\n\n * **unwind** \n元のSceneに戻る場合に利用されるSegueです。\n\n## Non-Action Segue\n\n * **relationship** \n複数のSceneに関連があることを示すSegueです。`UINavigationBar`や`UITabBarController`で用いられます。そのSceneがどういったコンテキスト(ナビゲーションなのか、タブなのか)で画面に表示されるのかを示す意味を持ちます。\n\n * **embed** \nあるビューコントローラに別なビューコントローラが埋め込まれている、つまり「ひとつの画面が異なるSceneの組み合わせで表示されている」という意味合いを持ちます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T14:20:45.967",
"id": "17379",
"last_activity_date": "2015-10-07T14:20:45.967",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5337",
"parent_id": "17290",
"post_type": "answer",
"score": 4
}
] |
17290
|
17379
|
17379
|
{
"accepted_answer_id": "17294",
"answer_count": 1,
"body": "myImageAという名前の画像をタッチするとカウント(scoreNum)が下がっていきそれ以外はカウントが上がっていくコードなのですが、画像以外(何もないところ。背景などの真っ白なところ)をタッチするとクラッシュしてしまいます。\n\nその時 `let touchedImageView = touch!.view as!\nUIImageView`の部分にエラーがあるとのことなのですが、自分では解決できず質問いたしました。\n\nどのように書き換えればいいでしょうか? \nコードも直して書いていただけるとありがたいです。\n\n背景は `self.view.backgroundColor = UIColor.whiteColor()`で白くしています。\n\n```\n\n override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {\n let touch = touches.first as UITouch?\n // タッチしたUIImageViewを取得\n let touchedImageView = touch!.view as! UIImageView\n \n if touchedImageView.image == myImageA {\n scoreNum--\n return\n }\n else {\n scoreNum++\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T14:44:30.790",
"favorite_count": 0,
"id": "17291",
"last_activity_date": "2015-10-05T16:19:17.260",
"last_edit_date": "2015-10-05T14:49:35.203",
"last_editor_user_id": "5337",
"owner_user_id": "11019",
"post_type": "question",
"score": -1,
"tags": [
"ios",
"swift"
],
"title": "swift 画像以外をタッチするとエラーが出てしまう。",
"view_count": 157
}
|
[
{
"body": "示されている`let touchedImageView = touch!.view as! UIImageView`では`as!`\nを使って`touch!.view`をUIImageViewへ強制的にキャストしようとしており、そのキャストが出来ない場合(touch!.viewがUIViewの場合など)にクラッシュしているだけだと思います。\n\n`as?`を使いキャストが失敗するとnilを返すようにし、かつ`if let`のOptional\nBindingを使いnilでなければ処理を実行する条件文とすれば、とりあえず期待する動作をするのではないでしょうか?\n\n```\n\n override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {\n let touch = touches.first as UITouch?\n // タッチしたUIImageViewを取得\n if let touchedImageView = touch!.view as? UIImageView {\n \n if touchedImageView.image == myImageA {\n scoreNum--\n return\n } else {\n scoreNum++\n }\n } else {\n scoreNum++\n }\n }\n \n```\n\n(どのようにOptionalを扱うのが最適かについては質問の答えではないと判断するため、とりあえず期待する動作をすることだけを目的としています)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T16:19:17.260",
"id": "17294",
"last_activity_date": "2015-10-05T16:19:17.260",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7374",
"parent_id": "17291",
"post_type": "answer",
"score": 3
}
] |
17291
|
17294
|
17294
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "git merge-base で3個以上コミットを指定すると、2個目以降のコミットがマージされたような、仮想的なマージコミットと、1個目のコミットに対しての\nmerge-base 判定が実行されます。 <https://git-scm.com/docs/git-merge-base>\n\nこの挙動を、実際に利用する場面があるのでしょうか。\n\nというのも、`git merge-base --octopus` を付与すると、指定されたすべてのコミットたちすべてについての best common\nancestor が出力されます。 merge-base\nの用途から考えるとこちらの方が挙動としてシンプルでわかりやすいと考えたのですが、そうではなく、上で記したような動作が(わざわざ)デフォルトになっているのは、何か意味(特定の用途)があるのでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T15:59:10.910",
"favorite_count": 0,
"id": "17293",
"last_activity_date": "2017-07-14T07:56:55.703",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 3,
"tags": [
"git"
],
"title": "git merge-base で3個以上のコミットを指定して、 --octopus を指定しない用途があるのか",
"view_count": 512
}
|
[] |
17293
| null | null |
{
"accepted_answer_id": "17302",
"answer_count": 2,
"body": "以前 tmux で`ctrl + b`の代わりに`caps lock + b`キーをファンクションキーとして使いたいと質問をした者です。 \nそのときは結論としてtmuxではなく、より下のレイヤにあるプログラムに働きかける必要があるとの回答をいただきました。 \nそれで少し、自力で調べては見たのですが、普段何も考えず、特に知識もなく、いわゆる「ターミナル」「端末」あるいは「コンソール」などと呼ばれる黒い画面でコマンドをいじっていただけの私では、そもそも用語の段階でほとんど理解ができませんでした。この上さらに「X」とそうでない場合もあるという情報に接すると、どこからどうしていいのかわかりません。\n\nこういう状態の人が一般的に端末の基本からキーバインディングを理解し、それを変更したいと思った場合、どの情報からあたっていくのが良いのでしょうか。 \n良いチュートリアルになりそうな書籍やリンク等ありましたら教えてください。\n\n利用している環境は、Ubuntu15.04でこちらはデスクトップとして使ってます。もう一つXのないものでCentOS6.7も使っています。ubuntuからCentOSにsshでつなげるときもあって、こういう場合の端末設定は何が優先されるのかなど全く分かっていません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T20:49:27.980",
"favorite_count": 0,
"id": "17296",
"last_activity_date": "2015-10-06T02:27:11.447",
"last_edit_date": "2015-10-06T00:03:19.673",
"last_editor_user_id": "9403",
"owner_user_id": "9403",
"post_type": "question",
"score": 0,
"tags": [
"linux",
"unix",
"console",
"key-binding"
],
"title": "*nixでのキーバインディングに関して基本から分る情報を探したい",
"view_count": 185
}
|
[
{
"body": "まったく何も知らない状態から教えろ・・・となると「範囲が広すぎ」クローズモデ対象なんですが・・・\n\nこういうときは google でも bing でもお好きな検索エンジンに対してキーワード検索しましょう。 \nご自分で既にキーワード抽出できていますよね。 \"unix\" \"キーバインド\" \"変更\" \nオイラの google 検索によると [emacs](/questions/tagged/emacs \"'emacs' のタグが付いた質問を表示\") や\n[bash](/questions/tagged/bash \"'bash' のタグが付いた質問を表示\") のキー機能のマップ変更のほうが多く抽出されたので \nキーワード変更 \"unix\" \"キーボード\" \"設定\" とかに変更してみました。 \nこっちのほうが今回の目的にはより合致しているようです。\n\n今時の [linux](/questions/tagged/linux \"'linux' のタグが付いた質問を表示\")\nディストリビューションをインストールしたような状況だと \nほぼ確実に X Window System と呼ばれるグラフィック画面表示機構が使われています。 \nなのでキー設定は `xmodmap` で行うことになります。 \nまずはその辺から探してみると良いでしょう。\n\nウチの部内サーバのようにコンソールログインすることが無いような機械だと \nメモリ CPU の節約のため X 使わない設定にすることもありますがまあレアです。 \n[linux](/questions/tagged/linux \"'linux' のタグが付いた質問を表示\") ではない\n[unix](/questions/tagged/unix \"'unix' のタグが付いた質問を表示\") マシンである、ということなら \nそのマシン名・OS名をきっちり書くとアドバイスできる人がいるかもしれません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-05T21:45:50.733",
"id": "17297",
"last_activity_date": "2015-10-05T21:45:50.733",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8589",
"parent_id": "17296",
"post_type": "answer",
"score": 1
},
{
"body": "期待されている回答とは異なるかもしれませんが・・・\n\n1.キーボードや画面自体にて変更可能なものは、ブツ自体で設定しましょう。 \nソフトウエア側での設定は不要になります。 \n\\- LCD 画面の明るさとか色合いとか \n\\- Happy Hacking Keyboard とか使えば A の左となりは Ctrl になっています \n\\- 他にも Ctrl/Caps をハードウエア的に入れ替え可能なキーボードとかあったりします。\n\nキーボードや画面は、それが直結している機械で制御されています。 \nリモートマシンには、ローカルマシンが抽象化した結果だけが送られます。\n\n2.機械自体に変更機能があればそれで設定しましょう。 \n\\- ノート系マシンなら BIOS 設定に Ctrl/Fn 入れ替え機能があったりします。\n\n3.機械に入っている OS/デバイスドライバ/設定機能 で設定します。 \n[ssh](/questions/tagged/ssh \"'ssh' のタグが付いた質問を表示\") や telnet\nを使う場合、直接操作している機械の設定が使われます。\n\n3-a. 操作員 --- Windows 7 ---ssh--- Linux(Ubuntu/CentOS) \nWindows 7 側のキー入れ替え機能でキー設定します。 \nこのとき Ubuntu/CentOS の X は使われないので `xmodmap` で設定しても意味ないです。 \n検索キーワード: Windows Caps Ctrl \nオイラんとこではこの運用が主体です。 \nオイラは Windows 側のキー設定を レジストリ で入れ替えています。 \n( [ssh](/questions/tagged/ssh \"'ssh' のタグが付いた質問を表示\") Terminal に限らず全 Windows\n上で動くソフトのキー設定が変わります)\n\n3-b. 操作員 --- Linux (Ubuntu) ---ssh--- Linux(CentOS) \n3-c. Linux (Ubuntu) に直接ログインして Ubuntu を使う場合 \n両者とも Ubuntu の X server が使われますから \nキー設定は X 自体の持っている機能 `xmodmap` で行うのが良いでしょう。 \n検索キーワード: Unix Caps Ctrl \n当該ターミナルに限らず同一 X server 上で動く全てのソフトのキー設定が変わります。 \n\\- ユーザー単位で切り替えるように設定すればログインユーザごとに違うキー設定で、 \n\\- X server 起動時に切り替えるよう設定すれば全ユーザが同じキー設定で、 \n使うことができるでしょう。\n\n4.Linux (CentOS) に直接ログイン (X server を使わないテキストログイン) の場合 \n難度が高いので解説省略 \n検索キーワード: コンソール キーボード 設定\n\n5.特定ソフトが、そのソフト専用のキー設定を可能な場合、それで設定しましょう。 \nゲームなどでは良くありそうです。 \nターミナルソフト等では提供されていない場合がほとんどです。 \n当然、他のソフトとは連動しません。\n\n理解順としては \na.ターミナルソフトは X Window 配下の \"何とかTerm\" であるか? \nYes → `xmodmap` No→b\n\nb.ターミナルを実行している Local マシンは何か? \nWindows → Windows 側でのキー入れ替え \nLinux + 非 X (テキストログイン) → Linux コンソールのキー入れ替え \nでいいんぢゃないかな。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T02:27:11.447",
"id": "17302",
"last_activity_date": "2015-10-06T02:27:11.447",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8589",
"parent_id": "17296",
"post_type": "answer",
"score": 5
}
] |
17296
|
17302
|
17302
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "DDD本を読んでいて、オブジェクトはValue ObjectとEntity Objectに分けられ以下のように理解 \nしました。、 \n・Entity Object \n・不変な識別(IDなど)できるものがあり \n・その他の属性は変更可能 \n・ValueObject \n・生成時のみ値を設定でき変更不可 \n・同じオブジェクトを生成できる。 \n \nこの場合、例えばEntityObjectの属性にValueObjectがあった場合 \nそのValueObjectの変更は不可能だと思うのですが、入れ替えることも \nできず、どうするのが良いのでしょうか?それとも使い方が間違っているのでしょうか? \n+++++++++++++++++++++++++ \n以下思いつきで書いてみたので文法上間違いが多々あるかもわかりませんが、ソースコード書いてみました。\n\n```\n\n public class ValueObject\n {\n private int b;\n ValueObject(int a)\n {\n b=a;\n }\n ValueObject multi(int a)\n {\n return new ValueObject(a*b);\n }\n ValueObject copy()\n {\n return new ValueObject(b);\n }\n }\n public class EntityObject\n {\n private final int id;\n private ValueObject vo;\n EntityObject(int id,int value)\n {\n this.id=id;\n vo = new ValueObject(30);\n \n \n }\n void setValue(int a)\n {\n //ここのやり方がわからない\n }\n ValueObject getValue()\n {\n return vo.copy();\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T00:06:22.147",
"favorite_count": 0,
"id": "17299",
"last_activity_date": "2015-10-06T03:58:39.990",
"last_edit_date": "2015-10-06T02:26:25.963",
"last_editor_user_id": "8000",
"owner_user_id": "12480",
"post_type": "question",
"score": 2,
"tags": [
"ドメイン駆動設計"
],
"title": "value objectについて質問です。",
"view_count": 1603
}
|
[
{
"body": "下のようなイメージとなります。\n\n```\n\n public class EntityObject\n {\n private final int id;\n private ValueObject vo;\n EntityObject(int id,ValueObject value)\n {\n this.id=id;\n vo = value;\n }\n void setValue(int a)\n {\n vo = new ValueObject(a);\n }\n ValueObject getValue()\n {\n return vo.copy();\n }\n }\n \n```\n\n「ValueObjectの変更が不可能」というのは、`ValueObject`オブジェクトの属性`b`の値を変更することができない(ように実装する)、という意味です。\n\n質問文中のコードは、`ValueObject`型属性の参照先を変更しないようにする意図があるように見えますが、そういうわけではありません。\n\n> ・Entity Object \n> ・不変な識別(IDなど)できるものがあり \n> ・その他の属性は変更可能\n\nと書かれている通り、変更は可能です。\n\n* * *\n\n以下、質問からは少し外れるのですが、実際には以下の様な形のsetter/getterになるのが自然かと思います。\n\n```\n\n void setValue(ValueObject value)\n {\n vo = value;\n }\n ValueObject getValue()\n {\n return vo;\n }\n \n```\n\n * setする型とgetする型が揃っている\n * バリューオブジェクトは不変であるため必ずしも新しいインスタンスを生成する必要はない\n\nという理由からです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T03:58:39.990",
"id": "17303",
"last_activity_date": "2015-10-06T03:58:39.990",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2808",
"parent_id": "17299",
"post_type": "answer",
"score": 3
}
] |
17299
| null |
17303
|
{
"accepted_answer_id": "17301",
"answer_count": 1,
"body": "ある解説書で\n\n```\n\n let dataPoint = (2014, 12, 28)\n switch dataPoint {\n case (_, 8, let date) :\n println(\"In summer vacation. remind days: \\(30 - date)\")\n case(_, 12, let date) where 27 < date:\n println(\"In winter vacation\")\n case(_, 1, let date) where 5 > date:\n println(\"In winter vacation\")\n case(year, month, date):\n println(\"\\(year)-\\(month)-\\(date)\")\n }\n \n```\n\nと書かれていて、上の3つのcaseではlet dateとしているところを最後のcaseではdateとしているのはなぜなのでしょうか? \n他の解説書も見て、whereのあるcaseは定数で宣言するのかなと考えたのですが、 この文では最初のcaseでwhereがないのにlet date です。\n\n本に説明がないということは基本的なことなのだとは思うのですが、どなたかご説明いただけないでしょうか…",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T01:41:58.880",
"favorite_count": 0,
"id": "17300",
"last_activity_date": "2015-10-06T02:13:46.283",
"last_edit_date": "2015-10-06T02:10:40.680",
"last_editor_user_id": "7362",
"owner_user_id": "12516",
"post_type": "question",
"score": 0,
"tags": [
"swift"
],
"title": "swiftのswitch文について質問です。",
"view_count": 117
}
|
[
{
"body": "```\n\n case(year, month, date):\n \n```\n\nこれは、\n\n```\n\n case let (year, month, date) :\n \n```\n\nの書き写し間違いではありませんか?\n\n※この回答は、質問者さんからのReplyによって、随時加筆、変更する予定です。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T02:13:46.283",
"id": "17301",
"last_activity_date": "2015-10-06T02:13:46.283",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7362",
"parent_id": "17300",
"post_type": "answer",
"score": 0
}
] |
17300
|
17301
|
17301
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "コンテナ・サービスの課金単位の一つである Static public IP についてご教示下さい。 \n無料枠内としては 2つまでという制限がありますが、これには ip request で一時的に取得したアドレスも含まれるのでしょうか。 \nまた、この一時的に取得した ip を確認する方法はありますでしょうか。`cf ic ip list`コマンドでは、パーマネントに利用している ip\nアドレスしか表示されません。\n\n課金の内容を確認したく、お手数ですが宜しくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T04:31:06.257",
"favorite_count": 0,
"id": "17304",
"last_activity_date": "2016-09-30T08:57:24.283",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12591",
"post_type": "question",
"score": 2,
"tags": [
"bluemix"
],
"title": "Bluemix の IBM Container の static public IP への課金の確認",
"view_count": 387
}
|
[
{
"body": "無料枠のパブリックIPの2つのうち、何個使っているかは、Bluemixのダッシュボードから確認できます。下記の例ですと、1IPをリクエストして、それをコンテナに割り当てた状態で、使用状況は1IPとなっています。その後、cf\nic ip requestでリクエストすると、使用状況が2IPとなっていましたので、リクエストしただけでもカウントされるのですね。\n\nダッシュボード上からパブリックIPの使用状況を確認してみてください。\n\n[](https://i.stack.imgur.com/Dyn1L.png)\n\nまた、Requestしただけの未割り当てのIPを含めてListするには、「cf ic ip list all」コマンドを使用してみてください。\n\n[](https://i.stack.imgur.com/T0BKV.png)",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T10:28:40.510",
"id": "17319",
"last_activity_date": "2015-10-06T10:41:11.857",
"last_edit_date": "2015-10-06T10:41:11.857",
"last_editor_user_id": "10424",
"owner_user_id": "10424",
"parent_id": "17304",
"post_type": "answer",
"score": 1
}
] |
17304
| null |
17319
|
{
"accepted_answer_id": "17310",
"answer_count": 1,
"body": "表題の件でお助けいただけますでしょうか?\n\nWindows10でAll in one Eclipse 4.5 Mars 32bit fulledition\nをダウンロードして新規プロジェクト作成→新規CプロジェクトでHelloWorld ANSI Cプロジェクトを生成しました。\n\nコンパイラはVisualC++を設定、すでにひな形があるのでコンパイルと実行は出来たのですが、デバッグの際にエラーが出ます。\n\n以下がそのエラーメッセージです。\n\n```\n\n No symbol table is loaded. Use the \"file\" command.\n [New Thread 35376.0x950c]\n Error: dll starting at 0xf00000 not found.\n Error: dll starting at 0x753a0000 not found.\n Error: dll starting at 0xf00000 not found.\n Error: dll starting at 0xf00000 not found.\n [New Thread 35376.0x95d8]\n [New Thread 35376.0x95fc]\n Quit (expect signal SIGINT when the program is resumed)\n \n```\n\nデバッグの際のエラーなのでデバッガーか何かの設定なのかと思い設定を色々触っては試行錯誤していますが改善しません。\n\nエラーの意味と対応法をご存知の方おられましたらお助け願えませんでしょうか。\n\nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T05:05:38.273",
"favorite_count": 0,
"id": "17307",
"last_activity_date": "2015-10-06T06:26:33.267",
"last_edit_date": "2015-10-06T05:28:48.083",
"last_editor_user_id": null,
"owner_user_id": "10606",
"post_type": "question",
"score": 2,
"tags": [
"c",
"eclipse"
],
"title": "EclipseでCのデバッグでNo symbol table is loadedエラー",
"view_count": 2318
}
|
[
{
"body": "VisualC++はよくわからないので的を外してるかもしれませんが\n\n> `No symbol table is loaded. Use the \"file\" command.`\n\nこれはgdbが出力するエラーですね。\n\nビルドしたバイナリにデバッグシンボルが含まれてない場合に表示されるものです。 \nコンパイラがgccであれば`-g`をつけてビルドし直すと良いのですが、そもそも Eclipse CDTは VisualC++\nのデバッグ情報は読み込めないのだと思います。\n\n素直にVisualC++を使うか、[Debuging tools for Windows](https://msdn.microsoft.com/ja-\njp/library/ff551063%28v=vs.85%29.aspx) を使うのが良いのではと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T06:26:33.267",
"id": "17310",
"last_activity_date": "2015-10-06T06:26:33.267",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5008",
"parent_id": "17307",
"post_type": "answer",
"score": 1
}
] |
17307
|
17310
|
17310
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "IDEを利用してTwitterサービスを運用しているVPSサーバーに機能をデプロイしたいです。\n\n現在、VPSレンタルサーバーとRubyを利用してTwitterサービスを構築しています。 \nソースは直接Vimを利用して書いています。しかし、IDEで定義を見に行ったり簡単にオブジェクトの依存関係を見たり、コード補完したり、ブレーク張って変数の中身を確認したりなどの、IDEの機能を使いたいのですが、ローカル環境で作成したソースをサーバーにデプロイしたり、ローカルでテストする方法がわかりません。\n\n大雑把な質問で申し訳ないですが、IDEとRubyを利用して、Twitterサービスを構築し、ローカルでもテストする環境の構築方法を教えていただけないでしょうか。\n\nもしくは、書籍など紹介していただけませんでしょうか。\n\n<使用している環境> \n・VPS \n・gem twitter \n・IDE netbeans \n・ruby\n\n* * *\n\ntake88さんからのご指摘を受けまして、以下の通り質問内容を絞って修正させていただきました。\n\nRubyプラグインを導入して、ローカル環境でIDEの機能を使うことは可能です。 \n現状のデプロイ方法は、VPSにリモートで接続し、直接vimでソースを修正してプログラムを手動または自動で実行してサービスを実現しています。\n\nできないこと(やりたいこと)は以下になります。 \n1.ローカル環境のNetbeansで書いたソースをローカル環境でテスト \n2.ローカル環境のNetbeansで書いたソースをVPSにデプロイ\n\n特に優先的に実施したいのは2.の「ローカル環境のNetbeansで書いたソースをVPSにデプロイ」です。\n\n※ヒントなどでも構いませんので、ご教授いただけるとありがたいです。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T05:28:23.180",
"favorite_count": 0,
"id": "17308",
"last_activity_date": "2015-10-06T22:51:20.113",
"last_edit_date": "2015-10-06T22:51:20.113",
"last_editor_user_id": "85",
"owner_user_id": "12603",
"post_type": "question",
"score": 1,
"tags": [
"ruby",
"twitter",
"rubygems",
"netbeans"
],
"title": "VPSにRubyで作ったサービスをデプロイする方法と、NetBeansを使ってRubyを開発するノウハウを知りたい",
"view_count": 157
}
|
[] |
17308
| null | null |
{
"accepted_answer_id": "17441",
"answer_count": 1,
"body": "Android の位置情報取得についてです\n\n<http://techbooster.jpn.org/andriod/application/2525/> \n<http://seesaawiki.jp/w/moonlight_aska/d/%B0%CC%C3%D6%BE%F0%CA%F3%A4%F2%BC%E8%C6%C0%A4%B9%A4%EB>\n\nなどGPS取得のサンプルは多くありますがSDK23に対応したソースサンプルはほとんどありません \ncheckSelfPermission に対応したサンプルコードの記載、またはその例の記載のあるサイトを教えてください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T08:15:25.620",
"favorite_count": 0,
"id": "17313",
"last_activity_date": "2015-10-09T01:12:55.233",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12608",
"post_type": "question",
"score": 1,
"tags": [
"android",
"gps"
],
"title": "Android SDK23におけるGPS取得",
"view_count": 315
}
|
[
{
"body": "Android SDK23のPermissionはRuntimeでリクエストが必要になります。\n\nリクエスト方法の例は:\n\n```\n\n if (ActivityCompat.shouldShowRequestPermissionRationale(this,\n Manifest.permission.ACCESS_COARSE_LOCATION)) {\n //ユーザーになぜ位置情報取得の許可が必要を説明して、リクエストします。\n Snackbar.make(contentView, R.string.access_location_permission_description, Snackbar.LENGTH_INDEFINITE)\n .setAction(android.R.string.ok, new View.OnClickListener() {\n @Override\n public void onClick(View view) {\n ActivityCompat.requestPermissions(KamelioLoginActivity.this,\n new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},\n PERMISSION_REQUEST_ACCESS_COARSE_LOCATION);\n }\n }).show();\n } else {\n //ユーザーにしましたが、まだ許可されてないのでまたリクエストします。\n ActivityCompat.requestPermissions(KamelioLoginActivity.this,\n new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},\n PERMISSION_REQUEST_ACCESS_COARSE_LOCATION);\n }\n \n```\n\nリクエストの結果はonRequestPermissionsResultにでます:\n\n```\n\n @Override\n public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,\n @NonNull int[] grantResults) {\n if (requestCode == PERMISSION_REQUEST_ACCESS_COARSE_LOCATION) {\n if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {\n //許可されました。\n } else {\n //許可されなかったので、メッセージ表示します。\n Snackbar.make(contentView, R.string.access_location_permission_not_granted,\n Snackbar.LENGTH_SHORT).show();\n }\n } else {\n super.onRequestPermissionsResult(requestCode, permissions, grantResults);\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-09T01:12:55.233",
"id": "17441",
"last_activity_date": "2015-10-09T01:12:55.233",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2437",
"parent_id": "17313",
"post_type": "answer",
"score": 1
}
] |
17313
|
17441
|
17441
|
{
"accepted_answer_id": "17317",
"answer_count": 1,
"body": "nginxを使って、リバースプロキシをして2つのWebサーバーをサブドメインでわけたいと考えています。\n\nこの場合データベースはどのように扱えばいいのでしょうか。ちなみに全て1つの物理サーバー内で構築しようと考えています。 \n例えばこの場合データベースのインスタンス(MySQL等)を1つのポートで1台たちあげると、そのインスタンスを利用できるのは1つのWebサーバーのみとなってしまうと考えられます。\n\nこの解決方法として幾つか考えましたがどれがベストなのかわかりません。\n\n①データベースインスタンスを2台立ち上げ、データの保管場所を同じにしてWebサーバごとに1台ずつアクセスする。\n\n②1台のサーバではそもそもデータベースを共有できないので別のデータベースを使わなければならない。\n\n③データベースごとに物理サーバをたてて、スイッチで接続する。\n\nできれば1台のサーバないでできる方法を教えていただきたいです。また、リバースプロキシのベスト・プラクティスや構築パターンなどありましたら教えていただければ幸いです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T08:31:29.887",
"favorite_count": 0,
"id": "17314",
"last_activity_date": "2015-10-31T16:27:45.213",
"last_edit_date": "2015-10-31T16:27:45.213",
"last_editor_user_id": "8000",
"owner_user_id": "7232",
"post_type": "question",
"score": 1,
"tags": [
"mysql",
"nginx",
"database"
],
"title": "リバースプロキシを用いた場合のデータベースの扱い方",
"view_count": 1067
}
|
[
{
"body": ">\n> 例えばこの場合データベースのインスタンス(MySQL等)を1つのポートで1台たちあげると、そのインスタンスを利用できるのは1つのWebサーバーのみとなってしまうと考えられます。\n\nこれがおかしいです。RDBMS(に限らずほとんどのネットワーク越しに利用なサーバソフトウェア)は単一のポートで複数の接続を提供できます。Webサーバが80/tcpで多数のコネクションを同時に提供できるのが良い例です。\n\nなので、何も難しいことは無く、 \n・DBサーバ一台 \n・Web/APサーバ 2 台 (DBの接続先指定はすべて同じ) \n・リバースプロキシ1台\n\n```\n\n +--Web/APサーバ--+\n --リーバースプロキシ--+ +--DBサーバ\n +--Web/APサーバ--+\n \n```\n\nでよいでしょう。\n\nリバースプロキシ、Web、AP、DBの各サーバを多段で構成する場合の考え方は、一概に言えるものでは無くシステム構成や各要素にどれぐらいの負荷がかかるか、どのぐらいのリソースが提供できるか、耐障害性をどのぐらい確保しなければならないかによって大きく変わります。どうやって実現するのかまで含めるとすくなくとも雑誌記事一本レベルのボリュームになるので、ここで聞くには向かない質問です。書籍等で勉強されることをお勧めします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T09:40:16.770",
"id": "17317",
"last_activity_date": "2015-10-06T09:40:16.770",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5793",
"parent_id": "17314",
"post_type": "answer",
"score": 5
}
] |
17314
|
17317
|
17317
|
{
"accepted_answer_id": "17324",
"answer_count": 1,
"body": "Djangoで作ったプロジェクトに外部のmaster.pyからデータベースにデータを入れたい。 \n開発環境ではSQLite 3で本番環境ではMySQLを使用\n\n検索エンジンで調べた結果\n\n```\n\n import os\n os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"lovadeck.settings\")\n \n```\n\nのように記述すればよいとの記述を発見し、試しましたがダメでした。\n\nmaster.py\n\n```\n\n import os\n os.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"lovadeck.settings\")\n import django\n django.setup()\n from cms.models import Servant\n \n -------中略---------\n \n Servant.hpf = servant_divs[1].text #整数の3桁数字が入っています\n Servant.hpf20 = servant_divs[2].text\n Servant.apf = servant_divs[4].text #整数の2-3桁の数字が入っています\n Servant.apf20 = servant_divs[5].text\n \n```\n\nmodels.py\n\n```\n\n from django.db import models\n \n class Servant(models.Model):\n '''使い魔'''\n hpf = models.IntegerField('HP')\n hpf20 = models.IntegerField('HP Lv20')\n apf = models.IntegerField('AP')\n apf20 = models.IntegerField('AP Lv20')\n \n```\n\n. \n├── lovadeck \n│ ├── cms \n│ │ ├── admin.py \n│ │ ├── admin.pyc \n│ │ ├── __init__.py \n│ │ ├── __init__.pyc \n│ │ ├── migrations \n│ │ │ ├── 0001_initial.py \n│ │ │ ├── 0001_initial.pyc \n│ │ │ ├── __init__.py \n│ │ │ └── __init__.pyc \n│ │ ├── models.py \n│ │ ├── models.pyc \n│ │ ├── tests.py \n│ │ └── views.py \n│ ├── lovadeck \n│ │ ├── __init__.py \n│ │ ├── __init__.pyc \n│ │ ├── settings.py \n│ │ ├── settings.pyc \n│ │ ├── urls.py \n│ │ ├── urls.pyc \n│ │ ├── wsgi.py \n│ │ └── wsgi.pyc \n│ ├── db.sqlite3 \n│ ├── manage.py** \n│ └── **master.py** \n└── Vagrantfile\n\n```\n\n pip freeze -l\n \n beautifulsoup4==4.4.0\n distribution==1.0.0\n Django==1.8.3\n lxml==3.4.4\n \n```\n\nディレクトリ構造やインストールされているものは以上のようになります。 \nよろしくお願いします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T12:18:31.013",
"favorite_count": 0,
"id": "17321",
"last_activity_date": "2015-11-04T08:42:55.627",
"last_edit_date": "2015-11-04T08:42:55.627",
"last_editor_user_id": "4787",
"owner_user_id": "12611",
"post_type": "question",
"score": 1,
"tags": [
"python",
"django"
],
"title": "Djangoのデータベースに外部からデータを入れたい",
"view_count": 1608
}
|
[
{
"body": "`os.environ.setdefault`と`django.setup()`は問題ないと思われます。\n\n`Servant`のフィールドに値を代入した後`save()`を行っていないので、データが生成されないのではないでしょうか。\n\n```\n\n s = Servant()\n s.hpf = servant_divs[1].text\n s.hef20 = servant_divs[2].text\n s.apf = servant_divs[4].text\n s.apf20 = servant_divs[5].text\n s.save()\n \n```\n\nもしくは、`create()`を使っても良いかと。\n\n```\n\n s = Servant.objects.create(\n hpf=servant_divs[1].text, hef20=servant_divs[2].text,\n apf=servant_divs[4].text, apf20=servant_divs[5].text\n )\n \n```\n\nもし`servant_divs[n].text`が`str`や`unicode`型なら`int`型に変換してから代入する必要がありますね。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T14:39:14.417",
"id": "17324",
"last_activity_date": "2015-10-06T14:39:14.417",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9044",
"parent_id": "17321",
"post_type": "answer",
"score": 1
}
] |
17321
|
17324
|
17324
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "お世話になります。 \n下記手順でRaspbian wheezyのPython2.7.3を2.7.10にアップデートしました\n\n```\n\n wget -c https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz\n tar -xzvf Python-2.7.10.tgz\n cd Python-2.7.10/\n LDFLAGS=\"-L/usr/lib/x86_64-linux-gnu\" ./configure\n make\n sudo make install\n \n```\n\nアップデート後、2.3.7で正常に動作していた.pyファイルを実行したら、Pythonがsmbusが見つからないとエラーを吐くようになりました。再度\n\n```\n\n sudo apt-get install build-essential libi2c-dev i2c-tools python-dev libffi-dev\n pip install cffi\n pip install smbus-cffi\n \n```\n\n上記手順でsmbusモジュールのインストールを試みましたが、やはりPythonはsmbusが見つからないとエラーを吐きます。 \nどうしたら正常にPythonにsmbusを認識したもらえるようになるでしょうか? \nアドバイスをよろしくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T14:31:47.420",
"favorite_count": 0,
"id": "17323",
"last_activity_date": "2015-11-05T09:02:02.457",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9773",
"post_type": "question",
"score": 3,
"tags": [
"python",
"raspberry-pi",
"raspbian"
],
"title": "Raspbian wheezyでPython2.7.3から2.7.10にアップデートしたらsmbusをimportできなくなった",
"view_count": 1491
}
|
[
{
"body": "`python-smbus` を apt でインストールすると, Raspbian 標準の Python 2.7 から smbus\nを利用できるようになります.\n\napt でインストールした smbus モジュールは `/usr/lib/python2.7/dist-packages/smbus.so`\nにインストールされるため, 別途インストールした Python 2.7.10 からはそのままでは利用できないはずです.\n\napt でインストールした `smbus.so` を 別途インストールした Python から使うには, いくつかの方法が考えられます.\n\n 1. `/usr/lib/python2.7/dist-packages/smbus.so` から `/usr/local/lib/python2.7/site-packages/smbus.so` にシンボリックリンクを貼る.\n 2. `/usr/lib/python2.7/dist-packages/smbus.so` を `/usr/local/lib/python2.7/site-packages/smbus.so` にコピーする.\n 3. `PYTHONPATH` に `/usr/lib/python2.7/dist-packages` を追加する.",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-11-04T07:39:49.490",
"id": "18399",
"last_activity_date": "2015-11-05T09:02:02.457",
"last_edit_date": "2015-11-05T09:02:02.457",
"last_editor_user_id": "4787",
"owner_user_id": "4787",
"parent_id": "17323",
"post_type": "answer",
"score": 1
}
] |
17323
| null |
18399
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "インラインフレーム内部のページでPOSTした場合、親ページを全体をリロードする方法がわかりません。\n\n開発環境 \nPHP 5.2.8 \nCakePHP 2.6.2 \n[](https://i.stack.imgur.com/WZM0n.png)\n\n上図はメインページ/×××/mainの中にiframeで/×××/sampleが表示されいる例になります。 \n①のnameのテキストボックスに名前をセットしてOKを押すとDBに更新されますが \niframe内のページのみが遷移してメインページがリロードをされません。 \nこれをiframe内のページ/×××/sampleでPOSTした結果 \nページ全体が/×××/mainに遷移するか、更新後全体をリロードする方法がないでしょうか \nよろしくお願いします。 \n下記がコードの抜粋になります。\n\nmain.ctp\n\n```\n\n ------------------------------------------------------\n <?php echo $this->Form->create('×××'); ?>\n <?php echo $this->Form->input('id',array('type' => 'hidden')); ?>\n <iframe src=\"/×××/sample\" height=\"300\" ></iframe>\n *iframe内で更新したnameが表示されます\n ------------------------------------------------------\n \n```\n\nsample.ctp\n\n```\n\n ------------------------------------------------------\n <?php echo $this->Form->create('×××'); ?>\n <?php echo $this->Form->input('id',array('type' => 'hidden')); ?>\n <?php echo $this->Form->input('name',array('size' =>'15','label'=>false)); ?>\n <?php echo $this->Form->submit(' OK ',array('div'=>false)); ?>\n ------------------------------------------------------\n \n```\n\nsample.php\n\n```\n\n ------------------------------------------------------\n if($this->×××->save($this->data)) {\n $this->redirect(array('action' => 'main'));\n }else{\n $this->redirect(array('action' => 'logout'));\n }\n ------------------------------------------------------\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T16:36:18.887",
"favorite_count": 0,
"id": "17325",
"last_activity_date": "2016-07-21T00:10:38.837",
"last_edit_date": "2016-07-21T00:10:38.837",
"last_editor_user_id": "8000",
"owner_user_id": "8168",
"post_type": "question",
"score": 2,
"tags": [
"php",
"html",
"cakephp"
],
"title": "iframe内のフォームの送信で、親フレームを遷移・リロードさせたい",
"view_count": 4613
}
|
[
{
"body": "cakephp側では解決できないと思うのでフロント側(Javascript等)でiframe内のイベントを拾って親ページもリロードするという形にすればいいんんじゃないでしょうか。 \n参考にJqueryでのiframeイベントの検知方法とかのURLを貼っておきます。 \n<http://zxcvbnmnbvcxz.com/jquery-iframe-loaded/>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T08:53:37.860",
"id": "17356",
"last_activity_date": "2015-10-07T08:53:37.860",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4262",
"parent_id": "17325",
"post_type": "answer",
"score": 0
},
{
"body": "下記のようにformにtargetを指定して対応しました。\n\n```\n\n <?php echo $this->Form->create('×××',array('target' => '_top')); ?>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T17:37:04.123",
"id": "17386",
"last_activity_date": "2015-10-07T17:45:04.380",
"last_edit_date": "2015-10-07T17:45:04.380",
"last_editor_user_id": "8168",
"owner_user_id": "8168",
"parent_id": "17325",
"post_type": "answer",
"score": 1
}
] |
17325
| null |
17386
|
{
"accepted_answer_id": "17333",
"answer_count": 5,
"body": "**newしなくても、関数はコンストラクタと呼ばれるのでしょうか?** \n・ 関数 / コンストラクタ は同じ意味?\n\n**関数を定義しただけで、Functionオブジェクトになるのでしょうか?** \n・ 関数 / Functionオブジェクト は同じ意味?\n\n```\n\n var Hoge = function(name) {\n this.name = name;\n };\n \n```\n\n* * *\n\n**補足追記**\n\n・下記を読んで、関数定義した時点でconstructor\nプロパティが生成されるのなら、newしなくても、関数はコンストラクタと呼ばれるのかと思ったのですが、そういうわけではないということでしょうか? \n・そもそも何を持ってコンストラクタとするかは解釈が分かれる?\nのかも知れませんが、一般的には、コンストラクタは関数の内の一種で、関数定義しただけではコンストラクタとは呼ばない \n・constructor\nプロパティを持つオブジェクトをコンストラクタと呼んでしまうと、コンストラクタからイメージする内容と乖離してしまう、ということでしょうか? \n・constructor プロパティと、コンストラクタは、意味が全く異なる?\n\n> constructor プロパティが生成されるのは、Function オブジェクトが生成されたとき \n> <http://d.hatena.ne.jp/teramako/20120927/p1>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T23:16:38.203",
"favorite_count": 0,
"id": "17326",
"last_activity_date": "2015-10-07T21:50:58.210",
"last_edit_date": "2015-10-07T21:50:58.210",
"last_editor_user_id": "7886",
"owner_user_id": "7886",
"post_type": "question",
"score": 5,
"tags": [
"javascript"
],
"title": "JavaScriptでは、関数 / コンストラクタ / 関数オブジェクト / Functionオブジェクト は同じ意味でしょうか?",
"view_count": 966
}
|
[
{
"body": "1点目についてですが、コンストラクタは関数の一種です。コンストラクタでない関数としては`alert()`のような組み込み関数があげられます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-06T23:54:05.033",
"id": "17328",
"last_activity_date": "2015-10-06T23:54:05.033",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5750",
"parent_id": "17326",
"post_type": "answer",
"score": 1
},
{
"body": "**関数とコンストラクタ**\n\n例えば、\n\n```\n\n function add(v){\n return v + 4;\n }\n \n```\n\nのような(引数に4プラスした値を返す)関数は、 \n`new add(7);` \nのように呼び出しできますが、(そういう意味ではコンストラクタと言えても) \n一般には関数`add`のことをコンスタラクタとは言いません。\n\nまた、`Date`関数は \n`new Date()`, `Date()` \nどちらの形でも使用できますが、 \n前者はインスタンスを返すのでコンストラクタ、後者は文字列を返すのでコンストラクタとは呼びません。 \n(逆にnew しなくてもインスタンスを返すものはコンストラクタと呼んでもいいかもしれません)\n\n質問にあるコードの`Hoge`に関して言えば、`new`\nを付けずに呼び出された場合、`this`は、`window`を指し大域変数としての`name`に引数をセットします。 \nこのようなインスタンスを返さないようなものは(用法として)コンストラクタとは言えません。 \n(newを付けて呼び出す場合はコンストラクタ)\n\n**関数 と Functionオブジェクト**\n\n関数定義は結局Functionオブジェクトを作ることなので、 \n全ての関数はFunctionオブジェクトであるといっていいと思います。\n\n(狭義には)Function コンストラクタで生成されたもの(`new Function (引数並び,\n関数本体)`の形式、動作は一般定義の関数と異なる部分がある。)を Function オブジェクトとして区別する人もいるかもしれません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T00:22:49.217",
"id": "17329",
"last_activity_date": "2015-10-07T00:22:49.217",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5044",
"parent_id": "17326",
"post_type": "answer",
"score": 0
},
{
"body": "先に後者から。\n\n## 関数とFunctionオブジェクト\n\nJavascript における全ての関数は Function オブジェクトで表されます。Function オブジェクトは `new Function()`\nとして生成するほかに、専用の構文である「function文」「function式」を使うこともできます。\n\n * [ECMA-262 §4.3.24 Terms and definitions > function](http://www.ecma-international.org/ecma-262/5.1/#sec-4.3.24)\n * [ECMA-262 §13 Function Definition](http://www.ecma-international.org/ecma-262/5.1/#sec-13)\n\nネイティブ関数であっても、Function オブジェクトです。\n\n```\n\n document.write(alert instanceof Function);\n```\n\n## コンストラクタ\n\nコンストラクタは関数(もとい Function オブジェクト)であるため、関数の一種と言えるでしょう。\n\nJavascript における「コンストラクタ」の用法としてまっさきに浮かぶのは、`new`\nを付けて関数を呼ぶことを「コンストラクタとして呼ぶ」と表現するといったものです。ここから考えると、ある関数がコンストラクタであるかというのは、その関数をコンストラクタとして(`new`を使って)呼ぶことができるかどうか、だと思います。\n\n例えば Date オブジェクトについて、規格上は以下のような記述が見られます。\n\n> When `Date` is called as part of a `new` expression, it is a constructor: it\n> initialises the newly created object. \n> \\--- <http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.3> より引用\n\nこのように、 `new` を付けて(コンストラクタとして)呼び出される前提のもとで、ある関数のことを「コンストラクタ」と呼ぶのだと思います。\n\nまた `Array()` のように `new` を使わなくても同じように機能するオブジェクトについてですが、\n\n> When Array is called as a function rather than as a constructor, it creates\n> and initialises a new Array object. Thus the function call Array(…) is\n> equivalent to the object creation expression new Array(…) with the same\n> arguments. \n> \\--- <http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.1> より引用\n\nといった書き方になっているので、厳密に言えば「コンストラクタではないが、コンストラクタのようにオブジェクトを生成する関数」というところかと思います。クラスベースの言語で\n`new Hoge()` を内部的に呼び出す静的メソッド `Hoge.create()` が存在したとしても、それをコンストラクタと呼ばないのと同じように。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T02:32:18.323",
"id": "17333",
"last_activity_date": "2015-10-07T02:32:18.323",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "17326",
"post_type": "answer",
"score": 5
},
{
"body": "newしなくても、関数はコンストラクタと呼ばれるのでしょうか? \n・ 関数 / コンストラクタ は同じ意味?\n\nいいえ。コンストラクタは関数の一種です。コンストラクタ=関数は成立しますが、関数=コンストラクタは成立しません。 \nではコンストラクタとはどういう関数かというと、 \n「オブジェクトを初期化して返す関数」全般を「コンストラクタ」とするのならばそういう振る舞いをする関数は全部コンストラクタでしょうが、 \nJavascriptでのコンストラクタ、と限定するのであればオブジェクトのconstructorプロパティに設定されている関数のことです。 \nある関数をnewキーワードをつけて呼び出した場合、その関数内でthisで参照可能なオブジェクトのconstructorプロパティはその関数を指します(Javascriptにより自動で設定されます)。つまり明示的に別のオブジェクトをreturnしたり、constructorプロパティを書き換えない場合は、newして作成されたオブジェクトのconstructorプロパティはnewで呼び出した関数となり、 \nつまりその関数のことをコンストラクタと呼びます。 \nJavascriptはこの辺プロトタイプチェインとか絡んできてややこしいです。この世からなくなればいいのに。\n\n関数を定義しただけで、Functionオブジェクトになるのでしょうか? \n・ 関数 / Functionオブジェクト は同じ意味?\n\nはい。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T02:51:43.607",
"id": "17334",
"last_activity_date": "2015-10-07T02:51:43.607",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12617",
"parent_id": "17326",
"post_type": "answer",
"score": 0
},
{
"body": "同じ意味か?と言われれば言葉に内包している意味合いは違います。 \nですが、同じ動きか?と聞かれれば概ね同じ動きだと思います、 \n順番に説明します。\n\n**※関数について** \n関数については特筆ありません。 \n`function(){}`で宣言された処理の集まりです。 \n上記、無名関数ですが大体は`function foo(){}`と名前を付けることが多いかと思います。\n\n**※コンストラクタについて** \n`var cnst = new foo();` \n上記のように`new`を頭に付けて宣言する関数をコンストラクタと言います。 \n「結局、中身はおんなじなんじゃねーの?」とも思いますが、微妙に異なります。\n\n```\n\n function foo(){\n this = {}//暗黙的追加\n return this;//暗黙的追加\n }\n \n```\n\n関数の始めにオブジェクトを作成して終わりに返却しています。 \n「何の役に立つんだよ」ってことですが……\n\n```\n\n function cnst_test(){\r\n this.n=0;\r\n this.counter=function(){this.n++;alert(this.n);}\r\n }\r\n \r\n var test = new cnst_test();\n```\n\n```\n\n <button onclick=\"test.counter()\">Click</button>\n```\n\nこんなことが出来ます。 \nJavaScriptにはクラスはありませんが、クラスっぽいです。 \n「これだけなら暗黙的にしなくても明示的に出来るんじゃ……」 \nはい、できます。ただしプロトタイプ宣言の紐付けが無くなってしまいます。\n\n**※関数オブジェクト/Functionオブジェクトについて** \nなんとなくここまでみて関数はオブジェクトみたいだなと感じられたかと思いますが、 \nその通りです。FunctionクラスのオブジェクトがJavaScriptでの関数の扱いになっています。 \nですので、JavaScriptで作られる関数は全て関数オブジェクトです。 \nFunctionオブジェクトは\n\n> **function** foo(){} \n> ↑これ\n\nのことなので、[ここ](https://msdn.microsoft.com/ja-\njp/library/x844tc74\\(v=vs.94\\).aspx)に書いてあることが全てですかね……",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T04:10:15.083",
"id": "17335",
"last_activity_date": "2015-10-07T04:10:15.083",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7676",
"parent_id": "17326",
"post_type": "answer",
"score": 0
}
] |
17326
|
17333
|
17333
|
{
"accepted_answer_id": "17331",
"answer_count": 1,
"body": "node.jsとexpressを用いたサーバ構築についてわからないことがあったので質問します。\n\n質問内容は\n\n```\n\n app.use(express.static(__dirname));\n \n```\n\nと\n\n```\n\n app.get('/', function(req, res){});\n \n```\n\nの記述順番によって意図しない結果が返ってくるというものです。\n\n* * *\n\n質問: \nパターン1の位置にexpress.staticを記述し、[http://localhost:3000にアクセスすると](http://localhost:3000%E3%81%AB%E3%82%A2%E3%82%AF%E3%82%BB%E3%82%B9%E3%81%99%E3%82%8B%E3%81%A8)、index.htmlの内容が表示されるのはなぜでしょうか? \nまた、htmlのファイル名がindex.htmlの時にだけこの現象が起こるのですがなぜでしょうか?\n\n想定している動き: \napp.getではtestpage.html(存在しないhtml)を返すと記述しているので、localhost:3000にアクセスするとError:\nENOENTとなるはずでは?\n\n備考: \n普段はパターン2の位置にexperss.staticを記述していました。2の位置にexpress.staticを記述しlocalhost:3000にアクセスするとError:\nENOENTとなります(想定通り)\n\n認識している点:\n\n```\n\n app.use(express.static(__dirname + '/public'));\n \n```\n\n指定したディレクトリ以下の静的ファイルを公開する\n\n```\n\n app.get('/', function(req, res){});\n \n```\n\n引数で指定されたGETリクエストに対して処理を行う。今回の質問の場合指定したhtmlファイルを返す。\n\n* * *\n\n以下サンプルを示します。\n\nディレクトリ構成 \napp \n├package.json \n├app.js \n├node_modules \n│ └express \n└public \n└index.html\n\napp.js\n\n```\n\n var express = require('express');\n var app = express();\n var http = require('http').Server(app);\n \n //パターン1\n app.use(express.static(__dirname + '/public'));\n \n app.get('/', function(req, res){\n res.sendFile(__dirname + '/public/testpage.html');\n });\n \n //パターン2\n //app.use(express.static(__dirname + '/public'));\n \n http.listen(3000, function(){\n console.log('Web Server listening on *:3000');\n });\n \n```\n\nindex.html\n\n```\n\n <!doctype html>\n <html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"> \n <title>testpage</title>\n </head>\n <body>\n <h1>Test Page</h1>\n </body>\n </html>\n \n```\n\n基本的なことで恐縮ですが教えていただけるとありがたいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T00:25:59.633",
"favorite_count": 0,
"id": "17330",
"last_activity_date": "2015-10-07T01:14:34.717",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10728",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"node.js"
],
"title": "node.jsとexpressのexpress.staticについて",
"view_count": 2436
}
|
[
{
"body": "`index.html`は`/`に対しての予約語・エイリアスとして定着している言わば方言で、ディレクトリのエントリポイント(最初にアクセスするべきファイル)を指します。`Apache`や`nginx`,\n`node-static`など、他のサーバーでも頻繁に利用されている設定です。\n\n`express.static`の実態は[`serve-static`モジュール](https://github.com/expressjs/serve-\nstatic#serve-files-with-vanilla-nodejs-http-\nserver)です。第二引数で`/`の振る舞いを変更することが出来ます。\n\n`express()`の`.use`,`.get`,`.post`などは、書いた順番に`url`が一致するかチェックを行いますが、コールバック関数の第三引数(e.g.`function(req,res,next){next()}`)を実行すると、一致している場合でも、次のコールバック関数に処理をそのまま渡すことが出来ます。\n\n```\n\n $ node app.js\n # Web Server listening on *:3000\n \n $ open http://localhost:3000/\n # 1\n # 2\n # 3\n # 4\n \n```\n\n```\n\n var express= require('express');\n var app= express();\n var http= require('http').Server(app);\n \n app.use(function(req,res,next){\n console.log('1');\n next();\n });\n app.use('/',function(req,res,next){\n console.log('2');\n next();\n });\n app.get('/',function(req,res,next){\n console.log('3');\n next();\n });\n \n app.use(function(req,res,next){\n console.log('4');\n res.status(404).end('404 Notfound');\n });\n \n http.listen(3000,function(){\n console.log('Web Server listening on *:3000');\n });\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T01:14:34.717",
"id": "17331",
"last_activity_date": "2015-10-07T01:14:34.717",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9834",
"parent_id": "17330",
"post_type": "answer",
"score": 1
}
] |
17330
|
17331
|
17331
|
{
"accepted_answer_id": "17338",
"answer_count": 1,
"body": "```\n\n // 送られたパスの画像を圧縮する\n private string ImageCoder(string path)\n {\n int fileCount = Directory.GetFiles(path).Count();\n string[] fileTitles = Directory.GetFiles(path);\n Array.Sort(fileTitles, new LogicalStringComparer());\n \n string dirResize = path + @\"\\resize\\\";\n Directory.CreateDirectory(dirResize);\n \n ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);\n System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;\n EncoderParameters myEncoderParameters = new EncoderParameters(1);\n \n for (int i = 0; i < fileCount; i++)\n {\n System.Drawing.Bitmap bmpSrc = new System.Drawing.Bitmap(fileTitles[i]);\n System.Drawing.Bitmap bmpSrcHalf = new System.Drawing.Bitmap\n (bmpSrc, RE_WIDTH, (int)(bmpSrc.Height * ((double)RE_WIDTH) / (double)(bmpSrc.Width)));\n \n EncoderParameter myEncoderParameter =\n new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, RE_COMP);\n \n myEncoderParameters.Param[0] = myEncoderParameter;\n bmpSrcHalf.Save(dirResize + (i + 1) + \".jpg\", jgpEncoder, myEncoderParameters);\n \n FileInfo fileInfo = new FileInfo(dirResize + (i + 1) + \".jpg\");\n long reComp = RE_COMP;\n \n if (fileInfo.Length < 3000)\n {\n ShowBalloon(\"画像は削除されています。処理を中断します。\");\n break;\n }\n \n while (fileInfo.Length > RE_SIZE)\n {\n myEncoderParameter = new EncoderParameter(myEncoder, (reComp = reComp - 3));\n myEncoderParameters.Param[0] = myEncoderParameter;\n bmpSrcHalf.Save(dirResize + (i + 1) + \".jpg\", jgpEncoder, myEncoderParameters);\n fileInfo = new FileInfo(dirResize + (i + 1) + \".jpg\");\n }\n }\n \n // ZIP化\n ZipStream(dirResize, path);\n \n return dirResize;\n }\n private ImageCodecInfo GetEncoder(ImageFormat format)\n {\n ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();\n foreach (ImageCodecInfo codec in codecs)\n if (codec.FormatID == format.Guid)\n return codec;\n return null;\n }\n \n \n // 送られたパスのファイルをソートする\n private string[] FileSort(string path)\n {\n string[] fileNames = Directory.GetFiles(path);\n fileNames = fileNames.OrderBy(n =>\n {\n int v = 0;\n if (int.TryParse(Path.GetFileNameWithoutExtension(n), out v))\n {\n return v;\n }\n return 9999999; // 数字で無いファイル名は一番後ろになる様に\n }).ToArray();\n \n return fileNames;\n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T04:27:46.613",
"favorite_count": 0,
"id": "17336",
"last_activity_date": "2015-10-07T05:45:13.553",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7973",
"post_type": "question",
"score": -1,
"tags": [
"c#"
],
"title": "画像のファイルサイズと大きさを縮小しZIP圧縮するのですが、もう少しコードを短縮できないでしょうか?",
"view_count": 712
}
|
[
{
"body": "`LogicalStringComparer`、`GetEncoder`、`FileSort`の機能は取り込みました。 \nコメントに従い10KBで判定しました。 \n`GetImageDecoders()`でなく`GetImageEncoders()`を使いました。 \nきちんとリソース解放しました。 \n毎回ファイルに書き出さず、メモリ上で処理して最終結果だけをファイルに書き出しました。\n\n```\n\n // 送られたパスの画像を圧縮する\n private string ImageCoder(string path) {\n var fileTitles = Directory.GetFiles(path).OrderBy(n => {\n int v = 0;\n return Int32.TryParse(Path.GetFileNameWithoutExtension(n), out v) ? v : 9999999; // 数字で無いファイル名は一番後ろになる様に\n }).ToArray();\n \n var dirResize = Path.Combine(path, \"resize\");\n Directory.CreateDirectory(dirResize);\n \n var jpegCodec = ImageCodecInfo.GetImageEncoders().FirstOrDefault(codec => codec.FormatID == ImageFormat.Jpeg.Guid);\n \n for (int i = 0; i < fileTitles.Length; i++) {\n // 10kb程の小さい画像になって削除済みと書かれた画像がダウンロードされた場合\n if (new FileInfo(fileTitles[i]).Length < 10240) {\n ShowBalloon(\"画像は削除されています。処理を中断します。\");\n break;\n }\n using (var original = new Bitmap(fileTitles[i]))\n using (var resized = new Bitmap(original, RE_WIDTH, (int)(original.Height * (double)RE_WIDTH / original.Width))) {\n var quality = RE_COMP;\n byte[] bytes;\n do {\n using (var memory = new MemoryStream()) {\n resized.Save(memory, jpegCodec, new EncoderParameters { Param = new[] { new EncoderParameter(Encoder.Quality, quality) } });\n bytes = memory.ToArray();\n }\n quality -= 3;\n } while (bytes.Length > RE_SIZE);\n File.WriteAllBytes(Path.Combine(dirResize, String.Format(\"{0}.jpg\", i + 1)), bytes);\n }\n }\n \n // ZIP化\n ZipStream(dirResize, path);\n \n return dirResize;\n }\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T05:45:13.553",
"id": "17338",
"last_activity_date": "2015-10-07T05:45:13.553",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "17336",
"post_type": "answer",
"score": 2
}
] |
17336
|
17338
|
17338
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "Qiitaに載っていた、こちらの記事を参考に \nMicrosoft Translator APIを入れようと思っています。 \n[参照記事](http://qiita.com/kemayako/items/21fe36005e6e729aff77)\n\n```\n\n 'use strict';\n \n var http = require('http');\n var https = require('https');\n var qs = require('querystring');\n \n getAccessToken(function (token) {\n translate(token, '翻訳したい文章', function (translated) {\n console.log(translated);\n });\n });\n \n function getAccessToken(callback) {\n var body = '';\n var req = https.request({\n host: 'datamarket.accesscontrol.windows.net',\n path: '/v2/OAuth2-13',\n method: 'POST'\n }, function (res) {\n res.setEncoding('utf8');\n res.on('data', function (chunk) {\n body += chunk;\n }).on('end', function () {\n var resData = JSON.parse(body);\n callback(resData.access_token);\n });\n }).on('error', function (err) {\n console.log(err);\n });\n var data = {\n 'client_id': 'クライアントIDに設定した文字列',\n 'client_secret': '顧客の秘密に設定した文字列',\n 'scope': 'http://api.microsofttranslator.com',\n 'grant_type': 'client_credentials'\n };\n \n req.write(qs.stringify(data));\n req.end();\n }\n \n function translate(token, text, callback) {\n var options = 'appId=Bearer ' + token + '&to=en&text=' + text +\n '&oncomplete=translated';\n var body = '';\n var req = http.request({\n host: 'api.microsofttranslator.com',\n path: '/V2/Ajax.svc/Translate?' + qs.escape(options),\n method: 'GET'\n }, function (res) {\n res.setEncoding('utf8');\n res.on('data', function (chunk) {\n body += chunk;\n }).on('end', function () {\n eval(body);\n });\n }).on('error', function (err) {\n console.log(err);\n });\n \n req.end();\n \n function translated(text) {\n callback(text);\n }\n }\n \n```\n\n上記のコードをjsファイルに追記すると、 \nconsoleエラーで\n\n```\n\n require is not defined\n \n```\n\nと表示されます。\n\nこの問題で他のメソッドもconsole.logが反応しない状態になっています。\n\nQiitaの記事ではhtmlファイルまでは載っていなかったのですが、 \n何かあらかじめ宣言しておく必要があるのでしょうか?\n\nよろしくお願いします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T05:31:18.800",
"favorite_count": 0,
"id": "17337",
"last_activity_date": "2015-10-07T08:58:50.293",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8415",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"jquery"
],
"title": "翻訳APIを入れるjsを書くとrequire is not definedが表示され、javascriptが動作しない",
"view_count": 776
}
|
[
{
"body": "ブラウザ上で動くJavascriptではなく、サーバサイドで動くJavaScriptですね。 \nサーバサイドで動くJavaScriptなのでサーバサイドで動作させるための環境が必要です。\n\ncommonJSやnode.jsのキーワードで検索してみてください。いろいろと参考になるサイトがヒットすると思います。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T06:36:55.073",
"id": "17342",
"last_activity_date": "2015-10-07T06:36:55.073",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10724",
"parent_id": "17337",
"post_type": "answer",
"score": 1
},
{
"body": "ブラウザで動かすコードではないので別のサンプルコードを探したほうが早いかもしれません。例えば [第38回 使ってみようMicrosoft\nTranslator:使ってみよう! Windows Live SDK/API|gihyo.jp …\n技術評論社](http://gihyo.jp/dev/serial/01/wl-sdk/0038)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T08:58:50.293",
"id": "17357",
"last_activity_date": "2015-10-07T08:58:50.293",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5008",
"parent_id": "17337",
"post_type": "answer",
"score": 0
}
] |
17337
| null |
17342
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "VIEWの変更権限を持っていないデータベースからコード生成を行おうとしています。 \nドキュメントにはAPIをoverrideするように書いてありましたがやり方がわかりませんでした。\n\n使用ライブラリのバージョン \nscala 2.11.6 \nslick 3.0.3 \nslick-codegen 3.0.3 \nmysql-connector-java 5.1.36\n\nドキュメント \n<http://slick.typesafe.com/doc/3.0.3/code-generation.html#customization>\n\nドキュメントで紹介されているExample \n<https://github.com/slick/slick-codegen-customization-example>\n\nソースコードはこちらになります。\n\n```\n\n def custom = {\n val slickDriver = \"slick.driver.MySQLDriver\"\n val jdbcDriver = \"org.gjt.mm.mysql.Driver\"\n val url = \"jdbc:mysql://localhost/test?characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull\"\n val outputFolder = \"src/main/scala\"\n val pkg = \"gen\"\n val user = \"userName\"\n val pass = \"password\"\n \n val driver: JdbcProfile =\n Class.forName(slickDriver + \"$\").getField(\"MODULE$\").get(null).asInstanceOf[JdbcProfile]\n val dbFactory = driver.api.Database\n val db = dbFactory.forURL(url, driver = jdbcDriver,\n user = Some(user).getOrElse(null), password = Some(pass).getOrElse(null), keepAliveConnection = true)\n \n try {\n val m = Await.result(db.run(driver.createModel(None, false)(ExecutionContext.global).withPinnedSession), Duration.Inf)\n new SourceCodeGenerator(m).writeToFile(slickDriver, outputFolder, pkg)\n } finally db.close\n }\n \n```\n\nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T05:45:35.850",
"favorite_count": 0,
"id": "17339",
"last_activity_date": "2017-01-14T14:26:40.803",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12620",
"post_type": "question",
"score": 1,
"tags": [
"scala"
],
"title": "Slick の Code-generation で View を除外したい",
"view_count": 165
}
|
[
{
"body": "ソースを読んで解決しました。\n\nMTable.getTables の引数に対象とするテーブルをフィルターする条件を指定します。\n\ntypesにはDatabaseMetaData.TableTypeのnameに定義されている値を利用できます。\n\n```\n\n def custom = {\n val slickDriver = \"slick.driver.MySQLDriver\"\n val jdbcDriver = \"org.gjt.mm.mysql.Driver\"\n val url = \"jdbc:mysql://localhost/test?characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull\"\n val outputFolder = \"src/main/scala\"\n val pkg = \"gen\"\n val user = \"userName\"\n val pass = \"password\"\n \n val driver: JdbcProfile =\n Class.forName(slickDriver + \"$\").getField(\"MODULE$\").get(null).asInstanceOf[JdbcProfile]\n val dbFactory = driver.api.Database\n val db = dbFactory.forURL(url, driver = jdbcDriver,\n user = Some(user).getOrElse(null), password = Some(pass).getOrElse(null), keepAliveConnection = true)\n \n val tables = Some(MTable.getTables(Some(\"\"), Some(\"\"), None, Some(Seq(\"TABLE\")))) //ここでフィルターできるようです。\n val modelAction = driver.createModel(tables, false)(ExecutionContext.global).withPinnedSession\n val modelFuture = db.run(modelAction)\n try {\n val m = Await.result(modelFuture, Duration.Inf)\n new SourceCodeGenerator(m).writeToFile(slickDriver, outputFolder, pkg)\n } finally db.close\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T16:03:12.057",
"id": "17383",
"last_activity_date": "2015-10-07T16:03:12.057",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12620",
"parent_id": "17339",
"post_type": "answer",
"score": 1
}
] |
17339
| null |
17383
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "現在、音声録音を行っているのですが以下の書き換えがわかりません。 \nもし教えていただける方がいらっしゃいましたらご指導の程よろしくお願いいたします。\n\n```\n\n // 使用している機種が録音に対応しているか\n if ([audioSession inputIsAvailable]) {\n [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];\n }\n if error {\n NSLog(@\"audioSession: %@ %d %@\", [error domain], [error code], [[error userInfo] description]);\n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T06:00:17.353",
"favorite_count": 0,
"id": "17340",
"last_activity_date": "2015-10-07T13:34:23.063",
"last_edit_date": "2015-10-07T13:34:23.063",
"last_editor_user_id": "5337",
"owner_user_id": "12536",
"post_type": "question",
"score": 0,
"tags": [
"swift"
],
"title": "録音を行う処理のObjective-CからSwiftへの書き換え方法が分からない",
"view_count": 451
}
|
[
{
"body": "こんな感じでどうでしょうか? \n(Xcode 7.0.1で確認)\n\n```\n\n let audioSession = AVAudioSession.sharedInstance()\n \n // inputIsAvailableは廃止になったのでinputAvailableを使用\n if audioSession.inputAvailable {\n \n // Swift2でNSErrorの扱いがdo/try/catchに変更された\n do {\n try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)\n \n } catch let err {\n \n // Swift2ではNSLogではなくprintを使用\n print(\"audioSession: \\(err)\")\n }\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T11:28:43.360",
"id": "17369",
"last_activity_date": "2015-10-07T11:28:43.360",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7459",
"parent_id": "17340",
"post_type": "answer",
"score": 1
}
] |
17340
| null |
17369
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "monacaの実機デバッグで外部から引っ張ってきている画像がいきなり表示されなくなりました。\n\n・iphone6s、xperiaZ4の両方で表示されません。 \n・同じネットワークに接続しております。 \n・ブラウザのプレビューでは表示されています。\n\n原因がお分かりになる方解決方法をご教授いただけますでしょうか。 \n宜しくお願いいたします。\n\n追記 \nご指摘ありがとうございます。 \nソースコードは下記なります。\n\n```\n\n <ons-template id=\"start.html\">\n \n <div class=\"contents\">\n \n <div class=\"box top\"ng-click=\"myNavigator.pushPage('open_page.html', { animation:'lift' })\">\n <div class=\"inner clearfix\">\n <p class=\"toptitle\">タイトル</p>\n </div>\n <img class=\"top_back\" src=\"http://xxxx.com/aaaa.jpg\" height=\"100%\">\n </div>\n \n ・\n ・\n ・\n </div>\n </ons-template>\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T06:13:06.637",
"favorite_count": 0,
"id": "17341",
"last_activity_date": "2015-10-07T06:26:21.993",
"last_edit_date": "2015-10-07T06:26:21.993",
"last_editor_user_id": "12624",
"owner_user_id": "12624",
"post_type": "question",
"score": 1,
"tags": [
"monaca"
],
"title": "monaca 実機デバッグ 外部画像がいきなり表示されなくなった",
"view_count": 232
}
|
[] |
17341
| null | null |
{
"accepted_answer_id": "17393",
"answer_count": 1,
"body": "railsで、modelにforeign_keyを指定した場合に、orderメソッドを使ってソートしたいです。\n\n下記のようにユーザーと部署テーブルがあり、 \nユーザーは部署に2つ所属する場合、\n\n```\n\n class User < ActiveRecord::Base\n belongs_to :unit_first, foreign_key: 'unit_first_id', class_name: 'Unit'\n belongs_to :unit_second, foreign_key: 'unit_second_id', class_name: 'Unit'\n end\n \n class Unit < ActiveRecord::Base\n has_many :first_user, foreign_key: 'unit_first_id', class_name: 'User'\n has_many :second_user, foreign_key: 'unit_second_id', class_name: 'User'\n end\n \n```\n\n一つの部署に所属するのであればこんな感じだと思いますが、\n\n```\n\n User.joins(:unit).order(\"`units`.`name` ASC\")\n \n```\n\n指定の仕方がわかりません。。 \n教えてください!\n\n追記:\n\n複数ソートを実装したくて下記で動きましたが、 \narelでもいいのでSQLを直書きしない方法はありますか?\n\n```\n\n users = User\n .joins!(\"INNER JOIN `units` AS `unit_first` ON `unit_first`.`id` = `users`.`unit_first_id`\")\n .joins!(\"INNER JOIN `units` AS `unit_second` ON `unit_second`.`id` = `users`.`unit_second_id`\")\n .order!(\"`unit_first`.`name` ASC, `unit_second`.`name` ASC\")\n \n```\n\n追記2:\n\n回答を参考にSQLを見てやってみて、下記で動作します\n\n```\n\n User.joins(:unit_first, :unit_second).order(\"users.name ASC\", \"unit_seconds_users.name ASC\")\n \n```\n\n先にmodelでbelongs_toを定義したカラムは通常通りのテーブル名で \n後にmodelでbelongs_toを定義したカラムは\n\n```\n\n #{複数系カラム名}_#{テーブル名}\n \n```\n\nという形でエイリアスになっていました。\n\nただ、unit_second単体でソートする場合も一度unit_firstをjoinさせる必要があるので注意が必要っぽいです。\n\n```\n\n User.joins(:unit_first, :unit_second).order(\"unit_seconds_users.name ASC\")\n \n```\n\nうーん。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T06:36:58.260",
"favorite_count": 0,
"id": "17343",
"last_activity_date": "2015-10-08T04:15:37.350",
"last_edit_date": "2015-10-08T04:15:37.350",
"last_editor_user_id": "9897",
"owner_user_id": "9897",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"sql",
"rails-activerecord"
],
"title": "railsで、modelにforeign_keyを指定した場合のorderはどう書けばいいのでしょうか。",
"view_count": 1107
}
|
[
{
"body": "以下のように書くのはどうでしょうか?\n\n```\n\n User.joins(:unit_first, :unit_second).order(\"users.name\", \"users_unit_second.name\")\n \n```\n\n\"users.name\"や\"users_unit_second.name\"の部分は、発行されるSQLにあわせて変更する必要があるかもしれません。\n\n### 追記\n\n> ただ、unit_second単体でソートする場合も一度unit_firstをjoinさせる必要があるので注意が必要っぽいです。\n> User.joins(:unit_first, :unit_second).order(\"unit_seconds_users.name ASC\")\n\nその場合はこうすれば良い気がします。\n\n```\n\n User.joins(:unit_second).order(\"units.name ASC\")\n \n```\n\nいかがでしょうか?",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T00:57:13.953",
"id": "17393",
"last_activity_date": "2015-10-08T03:53:00.547",
"last_edit_date": "2015-10-08T03:53:00.547",
"last_editor_user_id": "85",
"owner_user_id": "85",
"parent_id": "17343",
"post_type": "answer",
"score": 1
}
] |
17343
|
17393
|
17393
|
{
"accepted_answer_id": "17350",
"answer_count": 1,
"body": "取得したい属性の表示はできたのですが,それらをcsv形式で保存するにはどうすればよいでしょうか? \n以下に,rubyとxmlのファイルを示します.\n\nまた,示したxmlファイルについてですが,要素は2つしかありませんが,この要素の数が増えても問題なく処理が可能でしょうか?\n\n```\n\n <!-- language: lang-xml -->\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n <posts>\n <row Id=\"1\" PostTypeId=\"1\" CreationDate=\"2010-08-17T19:22:37.890\" Score=\"12\" ViewCount=\"14120\" Body=\"<p>What is the hardware and software differences between Intel and PPC Macs?</p>
\" OwnerUserId=\"10\" LastEditorUserId=\"15\" LastEditDate=\"2010-09-08T15:12:04.097\" LastActivityDate=\"2015-07-03T01:23:24.217\" Title=\"What is the difference between Intel and PPC?\" Tags=\"<hardware><mac><powerpc><intel>\" AnswerCount=\"8\" CommentCount=\"0\" FavoriteCount=\"2\" />\n <row Id=\"2\" PostTypeId=\"1\" AcceptedAnswerId=\"130\" CreationDate=\"2010-08-17T19:24:59.630\" Score=\"6\" ViewCount=\"3980\" Body=\"<p>The VPN software I use for work (<a href="http://www.lobotomo.com/products/IPSecuritas/">IPSecuritas</a>) requires me to turn off Back To My Mac to start it's connection, so I frequently turn off Back To My Mac in order to use my VPN connection (the program does this for me). I forget to turn it back on however and I'd love to know if there was something I could run (script, command) to turn it back on.</p>
\" OwnerUserId=\"17\" LastEditorUserId=\"17\" LastEditDate=\"2010-08-28T17:59:50.107\" LastActivityDate=\"2013-07-10T14:19:12.677\" Title=\"Turn on Back To My Mac via a Script or Command Line\" Tags=\"<osx><mobileme><terminal><back-to-my-mac><script>\" AnswerCount=\"1\" CommentCount=\"0\" FavoriteCount=\"4\" />\n <row Id=\"7\" PostTypeId=\"2\" ParentId=\"5\" CreationDate=\"2010-08-17T19:30:45.577\" Score=\"5\" Body=\"<p>I originally wanted to do this with my first Mac a couple years ago as well, since that's how my Linux and Windows environments behave. But I think the driving force preventing this from becoming a reality is in how OS X handles application menus.</p>

<p>What if you want to go to the menu at the top of the screen for an application you're using, but in the process briefly hover over another application? That would become infuriating quickly.</p>

<p>In short, I don't think its doable for that and potentially other reasons.</p>
\" OwnerUserId=\"41\" LastActivityDate=\"2010-08-17T19:30:45.577\" CommentCount=\"4\" />\n </posts>\n \n```\n\nと\n\n```\n\n <!-- language: lang-ruby -->\n require 'rexml/document'\n require 'csv'\n \n doc = REXML::Document.new(open(\"ruby_csv.xml\"))\n \n \n doc.elements.each('posts/row') do |element|\n puts element.attributes[\"Id\"]\n puts element.attributes[\"PostTypeId\"]\n puts element.attributes[\"AcceptedAnswerId\"]\n puts element.attributes[\"Body\"]\n end\n \n```\n\nです.\n\n(追記) \nrubyファイルを以下のように変更してcsv形式の保存を検討しています. \n[\"a\",\"b\",\"c\"]の部分を指定した属性にしたいのですがどうすればよいでしょうか?\n\n```\n\n <!-- language: lang-ruby -->\n require 'rexml/document'\n require 'csv'\n \n doc = REXML::Document.new(open(\"ruby_csv.xml\"))\n \n \n doc.elements.each('posts/row') do |element|\n puts element.attributes[\"Id\"]\n puts element.attributes[\"PostTypeId\"]\n puts element.attributes[\"AcceptedAnswerId\"]\n puts element.attributes[\"Body\"]\n end\n \n #CSVファイルを作成\n CSV.open(\"posts.csv\",\"w\") do |csv|\n csv << [\"a\",\"b\",\"c\"]\n csv << [\"d\",\"e\",\"f\"]\n csv << [\"g\",\"h\",\"i\"]\n end\n \n```\n\nよろしくお願いいたします.",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T06:38:14.643",
"favorite_count": 0,
"id": "17344",
"last_activity_date": "2015-10-09T18:06:57.667",
"last_edit_date": "2015-10-09T18:06:57.667",
"last_editor_user_id": "754",
"owner_user_id": "9505",
"post_type": "question",
"score": 0,
"tags": [
"ruby",
"xml",
"csv"
],
"title": "xmlファイル内の要素の属性をcsv形式で保存したい.使用言語はrubyです.",
"view_count": 1256
}
|
[
{
"body": "指定した属性値を row element ごとに CSV 形式で出力すれば良いのであれば、以下の様になります。\n\n```\n\n CSV.open(\"posts.csv\", \"w\") do |csv|\n doc.elements.each('posts/row') do |element|\n csv << [\"Id\", \"PostTypeId\", \"AcceptedAnswerId\", \"Body\"].map { |attr|\n element.attributes[attr] }\n end\n end\n \n```\n\n追加\n\n\"PostTypeId\" が\"1\" の場合のみを出力するには以下の様にします。\n\n```\n\n CSV.open(\"posts.csv\",\"w\") do |csv|\n doc.elements.each('posts/row') do |element|\n if element.attributes[\"PostTypeId\"] == \"1\"\n csv << [\"Id\", \"PostTypeId\", \"AcceptedAnswerId\", \"Body\"].map { |attr|\n element.attributes[attr] }\n end\n end\n end\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T07:52:06.590",
"id": "17350",
"last_activity_date": "2015-10-07T08:30:33.800",
"last_edit_date": "2015-10-07T08:30:33.800",
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "17344",
"post_type": "answer",
"score": 0
}
] |
17344
|
17350
|
17350
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "ViewControllerのコンテナビューにTableViewControllerを追加(segueのEmbedで接続)した所上部にステータスバーとナビゲーションバー分の空白が生じてしまいます。 \nそういうものかと思いコンテナビューの領域をナビゲーションバーの下の部分までとしていたのをViewControllerのviewを全て覆うように変更しました。 \nしかし、コンテナビューに別のTableViewControllerのviewを表示させると今度は上部に空白ができず下記写真のようにバーと重なってしまいます。 \n[](https://i.stack.imgur.com/k435E.png)\n\nViewControllerをコンテナビューとして2つのTableViewControllerを切り替えるものを作りたいのですがどのように設定を変更すれば上部に隙間ができないでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T06:40:49.530",
"favorite_count": 0,
"id": "17345",
"last_activity_date": "2015-10-07T07:23:24.567",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12232",
"post_type": "question",
"score": 0,
"tags": [
"ios",
"uitableview"
],
"title": "iOS UIViewControllerのコンテナビューに追加したUITableViewControllerのビューの上に空白ができる",
"view_count": 566
}
|
[
{
"body": "[ここ](https://stackoverflow.com/questions/18906919/remove-empty-space-before-\ncells-in-uitableview)の回答を参考にして解決することができました。 \nコンテナビューコントローラのviewDidLoadで \n`self.automaticallyAdjustsScrollViewInsets = NO;`を設定することで空白を解消することができます。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T07:23:24.567",
"id": "17347",
"last_activity_date": "2015-10-07T07:23:24.567",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": "12232",
"parent_id": "17345",
"post_type": "answer",
"score": 1
}
] |
17345
| null |
17347
|
{
"accepted_answer_id": "17454",
"answer_count": 1,
"body": "Javascriptとsvgの勉強として以下のコードを作成してみました。 \n1週間程かけてsvgの仕組み,JavascriptのaddEventListener,jQueryのイベント関連関数など色々試してみましたが一番スムーズに動いたソースを張り付けておきます。\n\n以下のリンクで確認できます。\n\nエラーは出ませんがマウスを動かさないと中央部分がランダムに動かない\n\n```\n\n $(document).ready(function() {\r\n var d = document;\r\n var mysvg = d.getElementById(\"mysvg\");\r\n \r\n var mx, my, random, xmid, ymid, input;\r\n \r\n setInterval(function() {\r\n //svgのサイズ\r\n var svgw = $(\"svg\").width();\r\n var svgh = $(\"svg\").height();\r\n \r\n //画面の中央\r\n xmid = svgw / 2;\r\n ymid = svgh / 2;\r\n \r\n //ランダムな数値\r\n random = {\r\n a: Math.floor(Math.random() * 25),\r\n b: Math.floor(Math.random() * 25),\r\n c: Math.floor(Math.random() * 25)\r\n };\r\n \r\n //svgniにイベントを追加\r\n mysvg.addEventListener(\"mousemove\", function(e) {\r\n //マウスの座標を取得\r\n mx = e.clientX;\r\n my = e.clientY;\r\n \r\n //svgにパスを追加\r\n input = '<path d=\"M ' + xmid + ',' + ymid + ' l ' + 0 + ',' + 0 + ' ' + ((mx - xmid) / 2) + ',' + random.a + ' ' + ((mx - xmid) - ((mx - xmid) / 2)) + ',' + ((my - ymid) - random.a) + ' ' + '\" stroke=\"orange\" stroke-width=\"7\" stroke-linejoin=\"round\" fill=\"none\" />';\r\n });\r\n \r\n //使用出来るデータを表示\r\n $(\"#status1\").html(\"X 座標 : \" + mx + \"<br>Y 座標: \" + my + \"<br><br>画面の中央 X: \" + xmid + \"<br><br>画面の中央 Y: \" + ymid + \"<br><br>画面の横幅: \" + svgw + \"<br>画面の縦幅: \" + svgh + \"<br><br>ランダム値 a: \" + random.a + \"<br>ランダム値 b: \" + random.b + \"<br>ランダム値 c: \" + random.c);\r\n \r\n $(\"#mysvg\").html(input);\r\n }, 10);\r\n });\n```\n\n```\n\n html,\r\n body {\r\n width: 100%;\r\n height: 100%;\r\n padding: 0;\r\n margin: 0;\r\n }\r\n \r\n body {\r\n overflow: hidden;\r\n }\r\n \r\n #wrapper {\r\n width: 100%;\r\n min-height: 100%;\r\n margin: 0 auto;\r\n position: relative;\r\n }\r\n \r\n svg {\r\n position: absolute;\r\n bottom: 0;\r\n left: 0;\r\n right: 0;\r\n margin: 0 auto;\r\n width: 100%;\r\n height: 100%;\r\n outline: 1px solid blue;\r\n }\n```\n\n```\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>\r\n <div id=\"wrapper\">\r\n <p id=\"status1\"></p>\r\n <svg id=\"mysvg\" width=\"300\" height=\"300\"></svg>\r\n </div>\n```\n\n```\n\n $(document).ready(function(){\n var d = document;\n var mysvg = d.getElementById(\"mysvg\");\n \n var mx,my,random,xmid,ymid,input;\n \n setInterval(function() {\n //svgのサイズ\n var svgw = $(\"svg\").width();\n var svgh = $(\"svg\").height();\n \n //画面の中央\n xmid = svgw/2;\n ymid = svgh/2;\n \n //ランダムな数値\n random = {\n a: Math.floor(Math.random()*25),\n b: Math.floor(Math.random()*25),\n c: Math.floor(Math.random()*25)\n };\n \n //svgにイベントを追加\n mysvg.addEventListener(\"mousemove\", function(e) {\n //マウスの座標を取得\n mx = e.clientX;\n my = e.clientY;\n \n //svgにパスを追加\n input = '<path d=\"M ' + xmid + ',' + ymid + ' l ' + 0 + ',' + 0 + ' ' + ((mx-xmid)/2) + ',' + random.a + ' ' + ((mx-xmid)-((mx-xmid)/2)) + ',' + ((my-ymid)-random.a) + ' ' + '\" stroke=\"orange\" stroke-width=\"7\" stroke-linejoin=\"round\" fill=\"none\" />';\n });\n \n //使用出来るデータを表示\n $(\"#status1\").html(\"X 座標 : \" + mx + \"<br>Y 座標: \" + my + \"<br><br>画面の中央 X: \" + xmid + \"<br><br>画面の中央 Y: \" + ymid + \"<br><br>画面の横幅: \" + svgw + \"<br>画面の縦幅: \" + svgh + \"<br><br>ランダム値 a: \" + random.a + \"<br>ランダム値 b: \" + random.b + \"<br>ランダム値 c: \" + random.c);\n \n $(\"#mysvg\").html(input);\n }, 10);\n \n```\n\nやりたいことはマウスの動きに合わせてSVGの \"path\" を使用して蛇のようなアニメーションを再現したい。 \n※Canvasも試してみましたがsvgの方が自由度が高いのでSVGを使用しました。\n\n**問題** \n・マウスを動かさないとランダム値が変化されない \n※ランダム値が動かない理由は \"mousemove\" イベントが発生していないと \"ランダム値\" も変化されないというのは理解しております。\n\n・\"input =\" の部分を addEventListener関数の外に出すこともできますがその場合マウスの座標が取得できない。 \n※ブラウザの開発者モードの \"Console\" タブに行き \"\" の値を確認すると マウスの座標の部分が \"NaN\" になる。 \n※一番下にリンクを張っておきます。\n\n・マウスを止めた場合 \"path\" の中央の値が1秒ごとに動いている理由?\n\n**最終的にやりたいこと** \n・pathに2,3点ほどランダムに値が変化する変数を追加してマウスを動かしていても止めている状態でもランダムに変化させたい\n\nやりたいこととしてはこちらの方が望ましいですが開発者ツールのconsoleメッセージでエラーが出る\n\n```\n\n $(document).ready(function() {\r\n var d = document;\r\n var mysvg = d.getElementById(\"mysvg\");\r\n \r\n var mx, my, random, xmid, ymid, input;\r\n \r\n setInterval(function() {\r\n //svgのサイズ\r\n var svgw = $(\"svg\").width();\r\n var svgh = $(\"svg\").height();\r\n \r\n //画面の中央\r\n xmid = svgw / 2;\r\n ymid = svgh / 2;\r\n \r\n //ランダムな数値\r\n random = {\r\n a: Math.floor(Math.random() * 25),\r\n b: Math.floor(Math.random() * 25),\r\n c: Math.floor(Math.random() * 25)\r\n };\r\n \r\n //svgniにイベントを追加\r\n mysvg.addEventListener(\"mousemove\", function(e) {\r\n //マウスの座標を取得\r\n mx = e.clientX;\r\n my = e.clientY;\r\n });\r\n \r\n //svgにパスを追加\r\n input = '<path d=\"M ' + xmid + ',' + ymid + ' l ' + 0 + ',' + 0 + ' ' + ((mx - xmid) / 2) + ',' + random.a + ' ' + ((mx - xmid) - ((mx - xmid) / 2)) + ',' + ((my - ymid) - random.a) + ' ' + '\" stroke=\"orange\" stroke-width=\"7\" stroke-linejoin=\"round\" fill=\"none\" />';\r\n \r\n //使用出来るデータを表示\r\n $(\"#status1\").html(\"X 座標 : \" + mx + \"<br>Y 座標: \" + my + \"<br><br>画面の中央 X: \" + xmid + \"<br><br>画面の中央 Y: \" + ymid + \"<br><br>画面の横幅: \" + svgw + \"<br>画面の縦幅: \" + svgh + \"<br><br>ランダム値 a: \" + random.a + \"<br>ランダム値 b: \" + random.b + \"<br>ランダム値 c: \" + random.c);\r\n \r\n $(\"#mysvg\").html(input);\r\n }, 10);\r\n });\n```\n\n```\n\n html,\r\n body {\r\n width: 100%;\r\n height: 100%;\r\n padding: 0;\r\n margin: 0;\r\n }\r\n \r\n body {\r\n overflow: hidden;\r\n }\r\n \r\n #wrapper {\r\n width: 100%;\r\n min-height: 100%;\r\n margin: 0 auto;\r\n position: relative;\r\n }\r\n \r\n svg {\r\n position: absolute;\r\n bottom: 0;\r\n left: 0;\r\n right: 0;\r\n margin: 0 auto;\r\n width: 100%;\r\n height: 100%;\r\n outline: 1px solid blue;\r\n }\n```\n\n```\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>\r\n <div id=\"wrapper\">\r\n <p id=\"status1\"></p>\r\n <svg id=\"mysvg\" width=\"300\" height=\"300\"></svg>\r\n </div>\n```\n\n↑のようなやり方でも動くようですが \"NaN\" エラーが出ているのでやり方がおかしいのかもしれません。\n\nJavascriptの経験はまだ浅い方なのでもっといい方法があるのかもしれません。 \n宜しくお願い致します。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2015-10-07T07:35:12.940",
"favorite_count": 0,
"id": "17348",
"last_activity_date": "2019-12-13T17:53:10.453",
"last_edit_date": "2019-12-13T17:52:31.383",
"last_editor_user_id": "32986",
"owner_user_id": "12625",
"post_type": "question",
"score": 3,
"tags": [
"javascript",
"jquery",
"svg"
],
"title": "SVG 要素をJavascriptのmousemoveイベントとsetIntervalとの組み合わせ",
"view_count": 1494
}
|
[
{
"body": "ざっくりですが修正してみました。 \n<http://jsfiddle.net/kamem/x2c5gvb2/2/>\n\n```\n\n $(document).ready(function() {\r\n var svg = document.getElementById(\"svg\");\r\n var $stg = $(\"#mysvg\");\r\n \r\n var mx, my, input;\r\n //svgのサイズ\r\n var svgWidth = $stg.width();\r\n var svgHeight = $stg.height();\r\n \r\n //画面の中央\r\n var xmid = svgWidth / 2;\r\n var ymid = svgHeight / 2;\r\n var random = [];\r\n var randomNum = 20;\r\n \r\n setInterval(function() {\r\n //ランダムな数値\r\n random = [{\r\n x: Math.floor(Math.random() * randomNum),\r\n y: Math.floor(Math.random() * randomNum)\r\n },\r\n {\r\n x: Math.floor(Math.random() * randomNum),\r\n y: Math.floor(Math.random() * randomNum)\r\n },\r\n {\r\n x: Math.floor(Math.random() * randomNum),\r\n y: Math.floor(Math.random() * randomNum)\r\n },\r\n ];\r\n \r\n //使用出来るデータを表示\r\n $(\"#status1\").html(\"X 座標 : \" + mx + \"<br>Y 座標: \" + my + \"<br><br>画面の中央 X: \" + xmid + \"<br><br>画面の中央 Y: \" + ymid + \"<br><br>画面の横幅: \" + svgWidth + \"<br>画面の縦幅: \" + svgHeight + \"<br><br>ランダム値 a: \" + random[0] + \"<br>ランダム値 b: \" + random[1] + \"<br>ランダム値 c: \" + random[2]);\r\n \r\n createPath();\r\n }, 10);\r\n \r\n //svgniにイベントを追加\r\n mysvg.addEventListener(\"mousemove\", function(e) {\r\n //マウスの座標を取得\r\n mx = e.clientX;\r\n my = e.clientY;\r\n createPath();\r\n });\r\n \r\n function createPath() {\r\n var height = my - ymid;\r\n var width = mx - xmid;\r\n var point1 = (xmid + width / 4 + random[0].x) + ' ' + (ymid + height / 4 + random[0].y);\r\n var point2 = (xmid + width / 3 + random[1].x) + ' ' + (ymid + height / 3 + random[1].y);\r\n var point3 = (xmid + width / 1.5 + random[2].x) + ' ' + (ymid + height / 1.5 + random[2].y);\r\n input =\r\n '<path d=\"M ' + xmid + ' ' + ymid + ',' +\r\n ' L ' + point1 +\r\n ' L ' + point2 +\r\n ' L ' + point3 +\r\n ' L ' + mx + ' ' + my +\r\n '\" stroke=\"orange\" stroke-width=\"7\" stroke-linejoin=\"round\" fill=\"none\" />';\r\n $stg.html(input);\r\n }\r\n });\n```\n\n```\n\n html,\r\n body {\r\n width: 100%;\r\n height: 100%;\r\n padding: 0;\r\n margin: 0;\r\n }\r\n \r\n body {\r\n overflow: hidden;\r\n }\r\n \r\n #wrapper {\r\n width: 100%;\r\n min-height: 100%;\r\n margin: 0 auto;\r\n position: relative;\r\n }\r\n \r\n svg {\r\n position: absolute;\r\n bottom: 0;\r\n left: 0;\r\n right: 0;\r\n margin: 0 auto;\r\n width: 100%;\r\n height: 100%;\r\n outline: 1px solid blue;\r\n }\n```\n\n```\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.0/jquery.min.js\"></script>\r\n <div id=\"wrapper\">\r\n <p id=\"status1\"></p>\r\n <svg id=\"mysvg\" width=\"300\" height=\"300\"></svg>\r\n </div>\n```\n\n## やったこと\n\n### setIntervalで毎回実行する必要が無い記述はわける。\n\n毎回実行する必要があるのは下記項目なので、それ以外の記述はそとに移しました。\n\n 1. randomの数字を撮り直す\n 2. 情報の取得・描画\n 3. svgのパスを生成し直す\n\n### パスを作る処理を関数化\n\nマウスを移動した時の処理と \nsetIntervalの場合にパスを生成する処理を \n共通しそれぞれで実行するように修正しました。(`createPath`)\n\nあとは見ていただければなんとくわかるのではないかと思います。 \nPathの生成部分などいまベタで描いてしまっているのですが \nfor文で描いたほうが応用が効きそうかなとは思いました。",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2015-10-09T02:37:23.463",
"id": "17454",
"last_activity_date": "2019-12-13T17:53:10.453",
"last_edit_date": "2019-12-13T17:53:10.453",
"last_editor_user_id": "32986",
"owner_user_id": "7455",
"parent_id": "17348",
"post_type": "answer",
"score": 1
}
] |
17348
|
17454
|
17454
|
{
"accepted_answer_id": "17353",
"answer_count": 1,
"body": "SORACOM Air の SIM には名前を付けて管理することができますが、Web のコンソールで1つずつ変更していくのが手間です。 \nCSV をインポートするなど、一括で変更する方法はありますか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T07:51:42.260",
"favorite_count": 0,
"id": "17349",
"last_activity_date": "2015-10-07T08:14:00.697",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "72",
"post_type": "question",
"score": 0,
"tags": [
"soracom"
],
"title": "SORACOM Air の SIM の名前を一括で変更したい",
"view_count": 83
}
|
[
{
"body": "SORACOM では、SDK が提供されており、これを利用すると比較的容易にインポート、エクスポートが可能です。 \n以下は、CSVではなく、タブ区切りのサンプルです。\n\n### 前提\n\nSORACOM SDK for Ruby と、jq コマンドがインストールされている事\n\n### エクスポート\n\n```\n\n ~/work/simtag$ cat get_sim_name.sh\n #!/bin/bash\n soracom sim list | jq -r '.[] | .imsi+\" \"+.tags.name'\n \n ~/work/simtag$ ./get_sim_name.sh > sim_tag.tsv\n \n```\n\nsim_tag.tsv が出力されます。\n\n### インポート\n\n```\n\n ~/work/simtag$ cat set_sim_name.sh\n #!/bin/bash\n IFS=$'\\t'\n while read LINE; do\n tsv=($(echo \"$LINE\"))\n soracom sim update_tags --imsi ${tsv[0]} --tags=name:\"${tsv[1]}\"\n done\n ~/work/simtag$ ./set_sim_name.sh < sim_tag.tsv\n \n```\n\nsim_tag.tsv からインポート(一括更新)されます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T08:14:00.697",
"id": "17353",
"last_activity_date": "2015-10-07T08:14:00.697",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12626",
"parent_id": "17349",
"post_type": "answer",
"score": 2
}
] |
17349
|
17353
|
17353
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Webサイト(Webシステム)の表示を \nMonacaで行うには、iframeを使用して行うのが一般的なのでしょうか?\n\nその場合は、naitiveでwebviewを使用する場合と同じように \nnative→html、html→nativeのようなやり取りは可能でしょうか?\n\n良し悪しは別にして、 \nNativeで開発予定だったのですが、スマホ用に開発したWebシステムを \nラップしてアプリとして出そうとなりました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T07:57:54.337",
"favorite_count": 0,
"id": "17351",
"last_activity_date": "2016-04-04T17:14:53.370",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12629",
"post_type": "question",
"score": 0,
"tags": [
"android",
"ios",
"monaca"
],
"title": "Monacaで既存のWEBサイトを読み込み表示をしたい",
"view_count": 874
}
|
[
{
"body": "[InAppBrowser](http://docs.monaca.mobi/2.9/ja/reference/phonegap_29/ja/inappbrowser/inappbrowser/)というのがあります。\n\n> native→html、html→nativeのようなやり取りは可能でしょうか?\n\n[addEventListener](http://docs.monaca.mobi/2.9/ja/reference/phonegap_29/ja/inappbrowser/inappbrowser/#addeventlistener-\nja) \n[executeScript](http://docs.monaca.mobi/2.9/ja/reference/phonegap_29/ja/inappbrowser/inappbrowser/#executescript-\nja) \nこの辺りを利用すれば、同じようなことはできると思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T11:38:46.677",
"id": "17371",
"last_activity_date": "2015-10-07T11:38:46.677",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3516",
"parent_id": "17351",
"post_type": "answer",
"score": 1
}
] |
17351
| null |
17371
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "レシーバーで通知受信時にサービスを立ち上げてステータスバーに通知を出す処理を定義しています。 \nただ、実際にステータスバーに通知を出すかどうかは サービス内で SQLite を用いて判断します。\n\n現在は サービスに一応 static で SQLite を保持しており、 \nonStartCommand で null だったらデータベースをインスタンス化しております。 \nまた、 onDestroy にて毎回クローズしています。\n\nとは言え、サービスは毎回終了する度に onDestroy がコールされると思うので \n実質1通知を処理するのに毎回 データベースを読み込んでいるかと思います。\n\nデータベースのレコードはアプリ起動時に毎回最適化しているのでせいぜい平均50程度と殆ど負荷にはならないかと思いますが、それでも効率が悪いのには変わりありません… \nトークアプリのため、通知はたくさん来ます。\n\nSQLiteはネイティブで保持されているとのことで、closeしないことも考えましたが、 \nやはり、closeしなかった場合はメモリリークが発生しますし…\n\n通知を処理するサービスでSQLiteを使用するにはどのように保持・管理・closeするのがベストなのでしょうか?",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T07:58:10.407",
"favorite_count": 0,
"id": "17352",
"last_activity_date": "2016-06-28T13:47:48.047",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10346",
"post_type": "question",
"score": 3,
"tags": [
"android"
],
"title": "Android GCM通知受信時のServiceでSQLiteを効率良く使うには",
"view_count": 104
}
|
[
{
"body": "ちょっと考えてみました。 \n通知設定がApplicationクラスのライフサイクルに合うなら、そのスコープで設定値をキャッシュすればsqliteを都度参照しなくて済みませんかね? \nただ、キャッシュコントロールが必要ですし過度な最適化に思えます。 \n変に延命措置をせず、さくっと終了するほうが全体最適ではないかとも思います。。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-06-28T13:47:48.047",
"id": "27149",
"last_activity_date": "2016-06-28T13:47:48.047",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "15039",
"parent_id": "17352",
"post_type": "answer",
"score": 1
}
] |
17352
| null |
27149
|
{
"accepted_answer_id": "17367",
"answer_count": 1,
"body": "**現在の案** \n・オリジナル画像データは、バッチ処理時に加工やサムネイル作成に使用するだけなので、/public_html/の下には置かない \n・実際の表示に使用する画像データは、/public_html/の中で保存 \n┏/オリジナル画像データ/ \n┗/public_html/ \n├/加工画像データ/ \n└/サムネイル画像データ/\n\n* * *\n\n**問題点** \n・オリジナル画像データは、画像ファイルアップロードで追加する予定だったのですが、public_htmlの上なので、アップロードできない?\n\n* * *\n\n**質問** \n・画像ファイルをアップロードする際、public_htmlディレクトリ階層より上に保存することは可能でしょうか? \n・オリジナル画像データは、普通どこに保存するのでしょうか? \n・public_htmlディレクトリ階層より上に保存したりはしない?\n\n* * *\n\n**補足** \n・オリジナル画像データをpublic_htmlディレクトリ階層より上に保存しようとした理由は、普段使用しないデータなら、ブラウザでアクセスできない箇所に配置した方が安全だと考えたから",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T08:35:52.100",
"favorite_count": 0,
"id": "17354",
"last_activity_date": "2015-10-07T11:16:30.820",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7886",
"post_type": "question",
"score": 1,
"tags": [
"php"
],
"title": "画像ファイルをアップロードする際、public_htmlディレクトリ階層より上に保存することは可能でしょうか?",
"view_count": 1649
}
|
[
{
"body": "> public_htmlディレクトリ階層より上に保存することは可能でしょうか?\n\n「ドキュメントルート内にしか書き込めない」という制約はPHPにはありません。というか、PHPからドキュメントルートを確実に認識する術はないでしょう。\n\n重要なのは保存先のパーミッションです。PHP はWebサーバーと同じ `www-data` や `httpd`\nといったユーザー、もしくはレンタルサーバなどでは各利用者のユーザーで動作していますから、このユーザーから書き込めるようにパーミッションを設定する必要があります。\n\nドキュメントルートより上の階層であろうと書き込みが許可されていれば保存できますし、逆に下の階層であっても書き込みが禁止されていれば保存できません。\n\nなお通常 PHP でファイルアップロードを行う場合、PHP はそのファイルを一旦 `/tmp` などの一時ディレクトリに保存します。これを\n`move_uploaded_file()` などでお好みの場所に移動することになるでしょう。\n\n参考 [PHP: POST メソッドによるアップロード - Manual](http://php.net/manual/ja/features.file-\nupload.post-method.php)\n\n> public_htmlディレクトリ階層より上に保存したりはしない?\n\nユーザーから無条件にアクセスさせたくないファイルは、ドキュメントルートの外側に置くことが多いと思います。Symfony や Laravel\nといったフレームワークでは、フレームワークを起動する `index.php`\nだけをドキュメントルートに置き、残りのスクリプト・設定・ログはその外に置いています。\n\n`.htaccess`\nなどで別途制限をかける方法もありますが、レンタルサーバーなどでドキュメントルートの外側にファイルを置けないといった事情がない限り、選択する理由はないでしょう。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T11:16:30.820",
"id": "17367",
"last_activity_date": "2015-10-07T11:16:30.820",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "17354",
"post_type": "answer",
"score": 2
}
] |
17354
|
17367
|
17367
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "まだmonacaでの開発もしたことがないのですが、monacaでNFCを使用したAndroidアプリ開発をしたいと思っています。 \n標準プランのCordovaプラグインの一覧にはバーコードスキャナのプラグインはありますが、NFCについては見当たりません。\n\nGoldプランではプラグインをインポートすることもできるようですが、標準プランではできないようです。\n\n有料プランへの変更は構わないのですが、実際にmonacaで使用可能なNFCプラグインがなければ意味が無いので、\n\n * monacaで使用可能なNFCプラグインがあるか\n * Goldプランで組み込みは可能か\n * サンプルプログラム等、組み込みの指南\n\nをお聞きできればと思います。\n\nお手数ですが教えていただけないでしょうか。 \nよろしくお願いいたします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T09:11:11.597",
"favorite_count": 0,
"id": "17358",
"last_activity_date": "2015-10-07T10:21:43.933",
"last_edit_date": "2015-10-07T10:21:43.933",
"last_editor_user_id": "7290",
"owner_user_id": "12630",
"post_type": "question",
"score": 1,
"tags": [
"android",
"monaca"
],
"title": "monacaでNFCを使用したAndroidアプリ開発は可能でしょうか",
"view_count": 1032
}
|
[] |
17358
| null | null |
{
"accepted_answer_id": "17372",
"answer_count": 2,
"body": "[Mashup Awards\n10向け提供APIガイド](http://search.nicovideo.jp/docs/api/contest.html)を使用したWebアプリケーションを開発しています。\n\n`XMLHttpRequest`を使用して、生放送をjsonで取得することは出来たのですが、取得できた内容にコミュニティid(`co****`)が存在しません。\n\n```\n\n # 例\n $ curl -X POST -d '{\"issuer\":\"test\",\"reason\":\"ma10\",\"query\":\"初音ミク\",\"from\":0,\"size\":100,\"service\":[\"live\"],\"search\":[\"title\",\"body\",\"caption\",\"tags\"],\"join\":[\"cmsid\",\"title\",\"description\",\"thumbnail_url\",\"start_time\",\"update_time\",\"last_comment_time\",\"view_counter\",\"comment_counter\",\"mylist_counter\",\"tags\",\"channel_id\",\"main_community_id\",\"length_seconds\",\"score_timeshift_reserved\",\"provider_type\",\"channel_id\",\"live_status\",\"member_only\",\"is_official\",\"serial_status\",\"episode_count\",\"is_sample\",\"genre\",\"author\",\"publisher\",\"label\",\"is_free\",\"price\",\"series_id\",\"series_number\",\"series\",\"charticle_ppv_type\",\"is_member_only\",\"thumbnail_key\",\"media_id\",\"media_name\"],\"filters\":[],\"order\":\"desc\",\"sort_by\":\"start_time\",\"timeout\":10000}' http://api.search.nicovideo.jp/api/\n \n```\n\nなお、返ってくる`lv***`の番号とは関連性が無いようでした。\n\n`http://live.nicovideo.jp/watch/lv***`を、代理サーバーでスクレピングし、中の`<img>`からURLを抽出してブラウザへ返す方法を試しましたが、こちらはアクセス制限が厳しく、1秒間隔でアクセスしても拒否されました。\n\nログインセッションキーを代理サーバーへ渡し、[getplayerstatus](http://live.nicovideo.jp/api/getplayerstatus/nsen/hotaru)を代理サーバーから取得して、ブラウザへ返す方法を考えましたが、これはWEBアプリケーションとして操作難易度が高いので、最終手段にしたいです。\n\n> 参考: \n> [ニコニコ動画検索APIのリクエスト発行テスト jsdo.it/59naga](http://jsdo.it/59naga/niconico-api-\n> test)([Internet\n> Archive](https://web.archive.org/web/20191017111206/http://jsdo.it/59naga/niconico-\n> api-test))",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2015-10-07T09:52:13.390",
"favorite_count": 0,
"id": "17360",
"last_activity_date": "2019-10-17T11:13:16.973",
"last_edit_date": "2019-10-17T11:13:16.973",
"last_editor_user_id": "19110",
"owner_user_id": "9834",
"post_type": "question",
"score": 2,
"tags": [
"javascript",
"angularjs"
],
"title": "ニコニコ生放送のコミュニティidをログインせずに取得したい",
"view_count": 568
}
|
[
{
"body": "[Vita\nAPI](http://www59.atwiki.jp/nicoapi/pages/24.html)というものから、ログイン不要で取得が可能でした。\n\n```\n\n $ curl http://api.ce.nicovideo.jp/liveapi/v1/video.array?__format=json&v=lv237697178\n # {\"nicolive_video_response\":{\"video_info\":{\"video\":{\"id\":\"lv237697178\",\"title\":\"\\uff12\\uff14\\u6642\\u9593\\u653e\\u9001 \\uff08MIKUMAX)\",\"open_time\":\"2015-10-07 13:26:49\",\"start_time\":\"2015-10-07 13:26:52\",\"schedule_end_time\":\"\",\"end_time\":\"2015-10-07 13:56:52\",\"provider_type\":\"community\",\"related_channel_id\":\"\",\"hidescore_online\":\"0\",\"hidescore_comment\":\"0\",\"community_only\":\"1\",\"channel_only\":\"0\",\"view_counter\":\"3\",\"comment_count\":\"0\",\"_ts_reserved_count\":\"0\",\"timeshift_enabled\":\"0\",\"is_hq\":\"0\"},\"community\":{\"id\":\"1240226\",\"name\":\"\\uff12\\uff14\\u6642\\u9593\\u653e\\u9001\\u3000\\u521d\\u97f3\\u30df\\u30af\\uff08MIKUMAX)\",\"channel_id\":\"\",\"global_id\":\"co1240226\",\"thumbnail\":\"http:\\/\\/icon.nimg.jp\\/community\\/124\\/co1240226.jpg?1440712338\",\"thumbnail_small\":\"http:\\/\\/icon.nimg.jp\\/community\\/s\\/124\\/co1240226.jpg?1440712338\"}},\"count\":\"1\",\"@status\":\"ok\"}}\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T10:08:06.887",
"id": "17362",
"last_activity_date": "2015-10-07T10:08:06.887",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9834",
"parent_id": "17360",
"post_type": "answer",
"score": 0
},
{
"body": "そのAPIでレスポンスに含まれる項目を制御するのは `join`\nというパラメータですが、質問にも書かれている[APIガイド](http://search.nicovideo.jp/docs/api/contest.html)で生放送の検索クエリ例を見ると、次のように書かれています。\n\n```\n\n ...\n \"join\":[\n \"cmsid\",\n \"title\",\n \"description\",\n \"community_id\",\n \"community_icon\",\n \"open_time\",\n \"start_time\",\n \"end_time\",\n \"score_timeshift_reserved\",\n \"provider_type\",\n \"channel_id\",\n \"live_status\",\n \"member_only\"\n ],\n ...\n \n```\n\n`community_id` というのがありますね。\n\n```\n\n $.ajax({\r\n type: 'post',\r\n url: 'http://api.search.nicovideo.jp/api/',\r\n data: JSON.stringify({\r\n query: \"初音ミク\",\r\n service: [\"live\"],\r\n search: [\"tags\"],\r\n join: [\"cmsid\", \"title\", \"community_id\"],\r\n filters: [{type: \"equal\", field: \"provider_type\", value: \"community\"}],\r\n size: 3,\r\n issuer: \"stackoverflow_sample\",\r\n reason: \"ma10\"\r\n }),\r\n contentType: 'application/json',\r\n dataType: 'text',\r\n success: function(resp) {\r\n $.each(resp.split('\\n'), function (_, chunk) {\r\n if (chunk && (json = JSON.parse(chunk)) &&json.type === 'hits') {\r\n $('pre').text(JSON.stringify(json.values, null, ' '));\r\n }\r\n })\r\n }\r\n });\n```\n\n```\n\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js\"></script>\r\n <pre class=\"prettyprint\"></pre>\n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T12:04:11.823",
"id": "17372",
"last_activity_date": "2015-10-07T12:14:05.930",
"last_edit_date": "2015-10-07T12:14:05.930",
"last_editor_user_id": "8000",
"owner_user_id": "8000",
"parent_id": "17360",
"post_type": "answer",
"score": 2
}
] |
17360
|
17372
|
17372
|
{
"accepted_answer_id": "17364",
"answer_count": 2,
"body": "サーバー起動時にClassNotFoundExceptionが出力され、解決出来ません。 \nエラー内容は以下です。\n\n```\n\n 重大: フィルタ Encoding の起動中の例外です\n java.lang.ClassNotFoundException: net.fnavi.bww.com.filter.EncodingFilter\n at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1313)\n at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1164)\n at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:520)\n at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:501)\n at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:120)\n at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)\n at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)\n at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4574)\n at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5193)\n at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)\n at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)\n at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)\n at java.util.concurrent.FutureTask.run(Unknown Source)\n at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n at java.lang.Thread.run(Unknown Source)\n \n```\n\n確認した内容としては、\n\n * net.test.bww.com.filter内にEncodingFilter.classが存在する\n * web.xml設定\n\n```\n\n <filter>\n <filter-name>Encoding</filter-name>\n <filter-class>net.test.bww.com.filter.EncodingFilter</filter-class>\n <init-param>\n <param-name>encoding</param-name>\n <param-value>Windows-31J</param-value>\n </init-param>\n </filter>\n \n```\n\n * tomcatライブラリー内に、EncodingFilter.javaを含むjarが存在する \n(webライブラリーにも配置)\n\n * クラス名は間違えていません\n\nという感じです。 \n解決方法の分かる方がいましたら、ご教授をお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T10:00:26.787",
"favorite_count": 0,
"id": "17361",
"last_activity_date": "2015-10-08T00:39:37.303",
"last_edit_date": "2015-10-08T00:39:37.303",
"last_editor_user_id": "7626",
"owner_user_id": "7626",
"post_type": "question",
"score": 0,
"tags": [
"java",
"tomcat"
],
"title": "ClassNotFoundException が解決出来ません",
"view_count": 37008
}
|
[
{
"body": "エラーメッセージでは、パッケージ名は、`net.test.bww.com.filter`ではなく、`net.fnavi.gw.com.filter`となっていますが、`import`などでの指定で問題があるのではないでしょうか?",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T10:17:56.727",
"id": "17363",
"last_activity_date": "2015-10-07T10:17:56.727",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7290",
"parent_id": "17361",
"post_type": "answer",
"score": 2
},
{
"body": "tomcatライブラリー(おそらくtomcatのディレクトリ/libのことでしょうか)の中、ないしはWebアプリケーションのwarファイル構成/WEB-\nINF/lib の中に配置したjarファイルに、上記 EncodingFilter.class が含まれているのは間違いないでしょうか。\n\nおそらく記述ミスだと思うのですが、.javaファイルではなく、.classファイルであっていますよね。\n\njarファイルの中身を確認する方法としては、jarファイルはzipで解凍できますので、拡張子をzipに変換して解凍すると確認できます。解凍後、上記EncodingFilterが、/net/test/bww/com/filter/\nディレクトリに存在していることも確認してください。\n\nhata\n様もご指摘のとおり、スタックトレースに出ているパッケージ名が異なっておりますので、jarファイルを作成したときのパッケージ名と、実際にソースをコンパイルしたときのパッケージ名が変わってしまっていないかも確認が必要です。\n\nなお、余談ですが、Tomcatのlibと、WebアプリケーションのWEB-INF/lib\n両方に入れる必要はありません。複数のWebアプリケーションで共通したものを使うのでなければ、Tomcatのlibには含めません。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T10:22:45.117",
"id": "17364",
"last_activity_date": "2015-10-07T10:22:45.117",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5778",
"parent_id": "17361",
"post_type": "answer",
"score": 4
}
] |
17361
|
17364
|
17364
|
{
"accepted_answer_id": "23024",
"answer_count": 3,
"body": "PHP 5.3のWebスクレーパーとして`Goutte 1.0.6`を使っています。\n\n一度訪問したサイトのHTMLをファイルキャッシュなどに格納しておき、2回目からはファイルキャッシュからHTMLを文字列として変数に読み込み、その内容をスクレイピングするような動作をさせています。\n\n```\n\n $client = new Goutte\\Client;\n $is_cached = false;\n if ($cache_data = $cache->get($url)) {\n $crawler = $client->request('GET', '');\n $crawler->clear();\n $crawler->addHtmlContent($cache_data, 'cp932');\n $is_cached = true;\n }\n else {\n $crawler = $client->request('GET', $url);\n $status = $client->getResponse()->getStatus();\n if (($status != 200) && ($status != 304 )) {\n return array(status => $status);\n }\n }\n \n```\n\nのようなコードにしていますが、キャッシュがヒットした場合、空の`GET`をさせることで`Crawler`オブジェクトを得て、いったんスクレイプ対象のHTMLを`$crawler->clear()`で捨ててから改めて`$crawler->addHtmlContent($cache_data,\n'cp932');`でHTMLを食べさせるというアドホックなコードになっています。\n\n実際には無駄なHTTPリクエストが発生しておりますので、改善できないかと考えています。\n\n`Goutte`を使ったスクレイピングで、HTTPリクエストなしでスクレイピングできる`crawler`オブジェクトを生成させる方法をご存知の方は、ご教示いただけないでしょうか。\n\nコード全文: \n<https://github.com/CLCL/akizukidenshi-ogp-\ninjector/blob/8c0869e411ac9898fd8e9cba9bfebb4d93a22314/index.php>\n\n* * *\n\n(投稿後すぐに自己解決したので一時ここに解決法を載せていましたが、回答の方に転記してこちらの記述を削除しました。)",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T11:11:32.387",
"favorite_count": 0,
"id": "17366",
"last_activity_date": "2016-06-06T07:30:02.120",
"last_edit_date": "2015-10-07T11:38:44.427",
"last_editor_user_id": "12633",
"owner_user_id": "12633",
"post_type": "question",
"score": 1,
"tags": [
"php"
],
"title": "GoutteでHTTPリクエストなしに文字列からスクレイプする方法",
"view_count": 2141
}
|
[
{
"body": "自己解決しました。\n\n```\n\n if ($cache_data = $cache->get($url)) {\n //$crawler = $client->request('GET', '');\n //$crawler->clear();\n $crawler = $client->getClient();\n $crawler->addHtmlContent($cache_data, 'cp932');\n $is_cached = true;\n }\n \n```\n\nで解決しました。\n\n解決方法の見つけ方として、\n\nGoutteのGitHub\n\n<https://github.com/FriendsOfPHP/Goutte/blob/master/Goutte/Client.php>\n\nを参照したところ、\n\n```\n\n public function getClient()\n {\n if (!$this->client) {\n $this->client = new GuzzleClient(array('defaults' => array('allow_redirects' => false, 'cookies' => true)));\n }\n return $this->client;\n }\n \n```\n\nという箇所があり、これで空の`Crawler`オブジェクトを生成しているようだったので、試してみたところ、うまく動作しました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T11:34:26.370",
"id": "17370",
"last_activity_date": "2015-10-07T11:34:26.370",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12633",
"parent_id": "17366",
"post_type": "answer",
"score": 1
},
{
"body": "「自己解決した」としましたが、その後、間違っていることがわかり、下記コードに修正しました。\n\n今回は、ちゃんと動かせるテストコードを提示します。\n\n```\n\n <?php\n require_once './vendor/autoload.php';\n \n // モジュールインストール\n // php composer.phar require fabpot/goutte:~1.0 pear/Cache_Lite:~1.7\n \n $cache_dir = __DIR__ . '/cache_cache_lite/';\n @mkdir($cache_dir, 0775);\n \n $cache = new Cache_Lite( array (\n 'cacheDir' => $cache_dir,\n 'lifeTime' => 8,// 8秒間キャッシュ有効\n 'automaticCleaningFactor' => 20, \n 'hashedDirectoryLevel' => 1,\n 'hashedDirectoryUmask' => 02775,\n ));\n \n $url='http://akizukidenshi-ogp-injector.dtpwiki.jp/';\n \n $client = new Goutte\\Client;\n $is_cached = false;\n if ($cache_data = $cache->get($url)) {\n echo \"cache zumi\\n\";\n \n // a. 質問文での手法 無駄なGETリクエストが走るがHTMLをスクレイプできるオブジェクトができる\n //$crawler = $client->request('GET', '');\n //$crawler->clear();\n //$crawler->addHtmlContent($cache_data, 'cp932');\n \n // b. 一度解決したとした時の手法 実際にできるオブジェクトはHTMLをスクレイプできない\n //$crawler = $client->getClient();\n //$crawler->addHtmlContent($cache_data, 'cp932');\n \n // c. 今回の手法 \n $crawler = $client->request('HEAD', null);\n $crawler->clear();\n $crawler->addHtmlContent($cache_data, 'cp932');\n \n $is_cached = true;\n }\n else {\n echo \"torini iku\\n\";\n $crawler = $client->request('GET', $url);\n $status = $client->getResponse()->getStatus();\n if (($status != 200) && ($status != 304 )) {\n return array(status => $status);\n }\n }\n \n if (!$is_cached) {\n $cache->save($client->getResponse()->getContent(), $url);\n }\n \n```\n\n一度「解決した」として提示したb.のコードでは、実際にはオブジェクトに`addHtmlContent`は生えておらず、エラーとなります。\n\n今回のc.のコードでは、どうしてもHTTPリクエストを発生させずにHTMLスクレイピングができる`clawler`オブジェクトの生成はできなかったため、最初質問で提示したものから、GETリクエストをHEADリクエストに変更することで、`localhost`にはアクセスするが最小の負荷になるようにしました。\n\nこの場合、稼働している自サーバのport 80/TCPのドキュメントルートにアクセスが来ることになり、アクセスログには、\n\n```\n\n ::1 - - [11/Mar/2016:15:51:21 +0900] \"HEAD / HTTP/1.1\" 403 - \"-\" \"Symfony2 BrowserKit\"\n \n```\n\nが記録されることになります。\n\nしっくりこない結果ですが、現状のベストとしてこのコードを上げさせていただきます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-11T07:32:05.497",
"id": "23024",
"last_activity_date": "2016-03-11T07:32:05.497",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12633",
"parent_id": "17366",
"post_type": "answer",
"score": 0
},
{
"body": "```\n\n use Symfony\\Component\\DomCrawler\\Crawler;\n $crawler = new Crawler($html);\n \n```\n\nこれでいけると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-06-06T04:29:11.637",
"id": "26494",
"last_activity_date": "2016-06-06T07:30:02.120",
"last_edit_date": "2016-06-06T07:30:02.120",
"last_editor_user_id": "5008",
"owner_user_id": "16770",
"parent_id": "17366",
"post_type": "answer",
"score": -2
}
] |
17366
|
23024
|
17370
|
{
"accepted_answer_id": "17375",
"answer_count": 1,
"body": "githubにリポジトリを作成している状態で、developのブランチを作成しました。 \n`git clone`してから`sudo git checkout -b develop`でdevelopに変更できましたが、 \n`git clone` したものの内容がmasterの中身のままです。 \n他者がdevelopで開発をしていて、開発したものをコピーして確認したいのですが、方法がわからないです。mergeをまだしないでコピーだけしたです。 \nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T12:05:23.560",
"favorite_count": 0,
"id": "17373",
"last_activity_date": "2015-10-07T13:08:30.980",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10980",
"post_type": "question",
"score": 0,
"tags": [
"git"
],
"title": "Githubのbranchからのコピーについて",
"view_count": 3030
}
|
[
{
"body": "`git checkout` は確かにブランチをチェックアウト(切り替える)する時に使うコマンドですが、 `-b` オプションを指定した場合は「\n**現在のコミットを指した新しいブランチを作り** 、そのブランチをチェックアウトする」という意味になります。そのため master\nブランチと同じものが見えてしまったのでしょう。\n\n 1. `git checkout master` で元のブランチに戻り、\n 2. `git branch -d develop` で誤って作成した develop ブランチを削除し、\n 3. `git checkout develop` で `origin/develop` を追跡する develop ブランチを作成\n\nといった感じで Github と同じ develop ブランチをチェックアウトしなおせると思います。\n\nまた `sudo` がついていますが、 Git は作業ディレクトリ上のファイルだけでなく `.git`\n以下の管理ファイルも作成・更新するため、それらのファイルの所有者が root になる可能性があります。こうなると sudo\nなしでの操作に問題が起きることがあるため、極力 sudo の利用を避けることをお勧めします。\n\nが、\n\n> mergeをまだしないでコピーだけしたです。\n\nGit におけるマージというのは、あるブランチに別のブランチの内容を取り込んで合流させることです。つまり master から develop\nに現在のブランチをチェックアウトしただけでは、マージされることはありません。\n\n※`git pull` はリモートでの変更をローカルブランチに取り込むため、マージが発生します。\n\nそのうえで、コピーだけしたいというのがよくわかりません。何を懸念して「merge」を避け、「コピー」にどのような結果を期待されているのでしょうか。\n\n* * *\n\nGithub などに push\nしていない変更はコマンド操作によって消失する可能性もあります。もし心配であればリポジトリを丸ごと別の場所にコピーしておくと安全かと思います。\n\n参考 [サルでもわかるGit入門 〜バージョン管理を使いこなそう〜 |\nどこでもプロジェクト管理バックログ](http://www.backlog.jp/git-guide/stepup/stepup1_1.html)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T13:08:30.980",
"id": "17375",
"last_activity_date": "2015-10-07T13:08:30.980",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "17373",
"post_type": "answer",
"score": 1
}
] |
17373
|
17375
|
17375
|
{
"accepted_answer_id": "17387",
"answer_count": 2,
"body": "```\n\n (with-open-file (s f :direction :input :element-type 'unsigned-byte)\n (let ((x (make-array 4 :element-type 'unsigned-byte)))\n (read-sequence x s)\n x))\n \n```\n\nこのようにファイルから変数xに4byte読みだすことは出来たのですが,それを4byteの整数に変換するにはどうすればよいのでしょうか. \nあるいは4byteの整数として直接読み込むことが出来るのでしょうか?\n\n補足: \nwavファイルをparseするコードを自分で書こうと思って質問しました。 \nwavファイルのヘッダ情報はデータサイズがそれぞれ異なるので、どうしたらそれを分解できるかなと思った次第です。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T12:11:24.413",
"favorite_count": 0,
"id": "17374",
"last_activity_date": "2015-10-09T04:09:10.653",
"last_edit_date": "2015-10-09T04:09:10.653",
"last_editor_user_id": "12467",
"owner_user_id": "12467",
"post_type": "question",
"score": 3,
"tags": [
"common-lisp"
],
"title": "ファイルから4byteの整数を読みだす",
"view_count": 485
}
|
[
{
"body": "ファイルから 4 バイト(32 ビット)単位で読み込む様にして、`read-byte` で読み出せばよろしいかと思います。\n\n```\n\n (with-open-file (s \"file\" :direction :input :element-type '(unsigned-byte 32))\n (read-byte s))\n \n```\n\n`element-type` が `'(unsigned-byte 32)` の場合は `unsigned int`、 `'(signed-byte\n32)` とすれば `signed int` として扱われる事になります。\n\n例えば、以下の様にしてサンプルデータを作成して、\n\n```\n\n $ perl -e \"print pack('L', -10000)\" > int.dat\n \n```\n\nSBCL で読み込んでみます。\n\n```\n\n * (with-open-file (s \"int.dat\" :direction :input :element-type '(signed-byte 32))\n (read-byte s))\n => -10000\n \n * (with-open-file (s \"int.dat\" :direction :input :element-type '(unsigned-byte 32))\n (read-byte s))\n => 4294957296\n \n```\n\n**追記**\n\nQuicklisp に [cl-binary-file](http://quickdocs.org/cl-binary-file/api) という\npackage がありました…。`signed/unsigned`, `little-endian/big-endian`\nの指定ができるので、こちらの方が良いかもしれません。\n\n```\n\n * (ql:quickload :cl-binary-file-0.4)\n * (use-package :binary-file)\n * (read-integer (open-binary-stream \"int.dat\") :bytes 4 :signed t :endianness :little-endian)\n => -10000\n * (read-integer (open-binary-stream \"int.dat\") :bytes 4 :signed nil :endianness :little-endian)\n => 4294957296\n \n```\n\n※ SBCL では `sb-c:*backend-byte-order*` でシステムの byte order を取得できます。\n\n```\n\n * sb-c:*backend-byte-order*\n \n :LITTLE-ENDIAN\n \n```\n\n**追記その2**\n\n> 同じファイルから4byteの整数以外にバイト列(unsigned-byte 8)も取得したい場合、element-\n> typeを切り替えながら読み込むということは可能なのでしょうか?\n\nはい、以下の様に `with-open-file` を2重にします。\n\n```\n\n (with-open-file (s \"int.dat\" :direction :input :element-type 'unsigned-byte)\n (with-open-file (int32 \"int.dat\" :direction :input :element-type '(signed-byte 32))\n (let ((x (make-array 4 :element-type 'unsigned-byte)))\n (read-sequence x s)\n (list x (read-byte int32)))))\n \n => (#(240 216 255 255) -10000)\n \n```",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T18:09:03.657",
"id": "17387",
"last_activity_date": "2015-10-08T05:06:13.503",
"last_edit_date": "2015-10-08T05:06:13.503",
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "17374",
"post_type": "answer",
"score": 1
},
{
"body": "* オクテット(unsigned-byte 8)を読み出す\n * 4オクテット単位でまとめたい(unsigned-byte 32として読む)\n * 途中でub8<=>ub32を切り替える(且つ切り換え場所から読み込み)\n\nとなると [nibbles](http://quickdocs.org/nibbles/) を使うのが簡単かなと思います。 \nライブラリを使わないのならば、オクテットで読み出してエンディアンを考慮しつつ合成するか、ub32で読んでエンディアンを考慮しつつ分解するか、かなと思います。\n\n```\n\n (ql:quickload :nibbles)\n \n ;; ファイル作成\n (with-open-file (out \"/tmp/foo.bin\" \n :element-type '(unsigned-byte 8) \n :direction :output\n :if-does-not-exist :create\n :if-exists :supersede)\n (dotimes (i 32)\n (write-byte 255 out)\n (write-byte 0 out)))\n \n \n ;; 読み出し\n (with-open-file (in \"/tmp/foo.bin\" :element-type '(unsigned-byte 8))\n (let ((ans (list (nibbles:read-ub32/be in) ;unsigned-byte 32/big endian\n (nibbles:read-ub32/le in) ;unsigned-byte 32/little endian\n (read-byte in) ;unsigned-byte 8\n (read-byte in) ;unsigned-byte 8\n (read-byte in) ;unsigned-byte 8\n (read-byte in) ;unsigned-byte 8\n )))\n (format T \"~&~{~12D: ~:*#b~32,'0B~%~}\" ans)))\n ;>> 4278255360: #b11111111000000001111111100000000\n ;>> 16711935: #b00000000111111110000000011111111\n ;>> 255: #b00000000000000000000000011111111\n ;>> 0: #b00000000000000000000000000000000\n ;>> 255: #b00000000000000000000000011111111\n ;>> 0: #b00000000000000000000000000000000\n ;=> nil\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T17:41:07.317",
"id": "17435",
"last_activity_date": "2015-10-08T17:41:07.317",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3510",
"parent_id": "17374",
"post_type": "answer",
"score": 1
}
] |
17374
|
17387
|
17387
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "ffmpegでx264を使いたくて、libx264をいれてmakeしたら`make: *** [ffmpeg_g] Error 1`というエラーがでました。 \n他の方も`ffmpeg_g Error\n1`がでたという人がいてその方の質問には「このライブラリがリンクしようとしているライブラリのバージョンの不一致なのでは?」と答えられていました。 \nもしライブラリのバージョンが不一致の場合どのようにすればエラーはなくなりますか? \nmakeの結果は\n\n```\n\n LD ffmpeg_g\n libavformat/libavformat.a(rtsp.o): In function `ff_rtsp_connect':\n /home/pi/ffmpeg/libavformat/rtsp.c:1659: undefined reference to `ff_log2_tab'\n libavcodec/libavcodec.a(asvdec.o): In function `asv2_get_level':\n /home/pi/ffmpeg/libavcodec/asvdec.c:92: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(asvdec.o): In function `decode_frame':\n /home/pi/ffmpeg/libavcodec/asvdec.c:267: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(asvenc.o): In function `encode_mb':\n /home/pi/ffmpeg/libavcodec/asvenc.c:177: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(asvenc.o): In function `encode_frame':\n /home/pi/ffmpeg/libavcodec/asvenc.c:304: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(dsddec.o): In function `decode_frame':\n /home/pi/ffmpeg/libavcodec/dsddec.c:150: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(ivi.o):/home/pi/ffmpeg/libavcodec/ivi.c:162: more undefined references to `ff_reverse' follow\n libavcodec/libavcodec.a(tiertexseqv.o): In function `seqvideo_decode':\n /home/pi/ffmpeg/libavcodec/tiertexseqv.c:191: undefined reference to `ff_log2_tab'\n libavcodec/libavcodec.a(tiff.o): In function `deinvert_buffer':\n /home/pi/ffmpeg/libavcodec/tiff.c:282: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(webp.o): In function `webp_get_vlc':\n /home/pi/ffmpeg/libavcodec/webp.c:263: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(wnv1.o): In function `decode_frame':\n /home/pi/ffmpeg/libavcodec/wnv1.c:79: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(xsubdec.o): In function `decode_frame':\n /home/pi/ffmpeg/libavcodec/xsubdec.c:102: undefined reference to `ff_log2_tab'\n libavcodec/libavcodec.a(xsubenc.o): In function `put_bits':\n /home/pi/ffmpeg/libavcodec/put_bits.h:182: undefined reference to `ff_log2_tab'\n libavcodec/libavcodec.a(xsubenc.o): In function `xsub_encode_rle':\n /home/pi/ffmpeg/libavcodec/xsubenc.c:91: undefined reference to `ff_log2_tab'\n libavcodec/libavcodec.a(aacps_fixed.o): In function `get_bits':\n /home/pi/ffmpeg/libavcodec/get_bits.h:268: undefined reference to `ff_log2_tab'\n libavcodec/libavcodec.a(aacps_float.o): In function `get_bits':\n /home/pi/ffmpeg/libavcodec/get_bits.h:268: undefined reference to `ff_log2_tab'\n libavformat/libavformat.a(matroskadec.o):/home/pi/ffmpeg/libavformat/matroskadec.c:746: more undefined references to `ff_log2_tab' follow\n libavcodec/libavcodec.a(bitstream.o): In function `alloc_table':\n /home/pi/ffmpeg/libavcodec/bitstream.c:115: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(bitstream.o): In function `ff_init_vlc_sparse':\n /home/pi/ffmpeg/libavcodec/bitstream.c:288: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(dcaenc.o): In function `calc_masking':\n /home/pi/ffmpeg/libavcodec/dcaenc.c:530: undefined reference to `ff_reverse'\n /home/pi/ffmpeg/libavcodec/dcaenc.c:530: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(s302m.o): In function `s302m_decode_frame':\n /home/pi/ffmpeg/libavcodec/s302m.c:190: undefined reference to `ff_reverse'\n libavcodec/libavcodec.a(xbmdec.o):/home/pi/ffmpeg/libavcodec/xbmdec.c:127: more undefined references to `ff_reverse' follow\n collect2: ld returned 1 exit status\n Makefile:126: recipe for target 'ffmpeg_g' failed\n make: *** [ffmpeg_g] Error 1\n \n```\n\nこのようになりました。`undefined references to` という表示が何カ所もでていますが、これはmakeできていないんですよね? \nこの場合の対処法を教えて欲しいです。よろしくお願いします。 \n私が使っているLinuxはRaspbianです。 \n行った処理は \nx264を使いたかったので\n\n```\n\n git clone git://git.videolan.org/x264\n ./configure --enable-shared --prefix=PREFIX\n make & make install\n \n```\n\nこの後に\n\n```\n\n git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg\n ./configure --enable-gpl --enable-nonfree --enable-libx264\n make\n \n```\n\nこの最後のmakeで`make: * [ffmpeg_g] Error 1`がでました。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T13:45:26.140",
"favorite_count": 0,
"id": "17376",
"last_activity_date": "2015-10-09T07:33:06.623",
"last_edit_date": "2015-10-09T07:33:06.623",
"last_editor_user_id": "3271",
"owner_user_id": "9349",
"post_type": "question",
"score": 2,
"tags": [
"ffmpeg",
"raspbian"
],
"title": "ffmpegのmakeでのエラーついて",
"view_count": 1741
}
|
[
{
"body": "ffmpegをRaspbianに入れるにはToolchainが必要で、 \nToolchainを入れるにはcrosstool-ng が必要なようです。\n\n<https://trac.ffmpeg.org/wiki/CompilationGuide/RaspberryPi>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T18:23:32.230",
"id": "17388",
"last_activity_date": "2015-10-07T18:23:32.230",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3271",
"parent_id": "17376",
"post_type": "answer",
"score": 1
}
] |
17376
| null |
17388
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "よくブロックを書かないサンプルに,selectメソッドの引数に&シンボルを指定して, \n`(1..10).select(&:even?)` \nこのように書いてあるサンプルはよくありますが, \nとあるクラスの属性を参照するような条件だとどのように書くのでしょうか\n\n```\n\n Square = Struct.new(:row, :column)\n \n squares = []\n \n squares << Square.new(10, 20)\n squares << Square.new(50, 20)\n squares << Square.new(20, 20)\n \n # ここをselect(...) のようにブロックを書かないようにしたい\n p squares.select{|s| :==.to_proc[20, s.row]} # row が 20 のものを抽出\n # p squares.select{|s| 20 == s.row} 素直にこう書けよという話なんですが...\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T14:13:41.127",
"favorite_count": 0,
"id": "17377",
"last_activity_date": "2015-10-09T22:08:26.480",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8722",
"post_type": "question",
"score": 1,
"tags": [
"ruby"
],
"title": "selectメソッドでto_procを使わないようにプログラムを変えたい",
"view_count": 142
}
|
[
{
"body": "`lambda_driver`というgemを使えばできます。\n\n```\n\n squares.select(&:row >> 20._(:==))\n \n```\n\nご自身で書かれてるように素直に`squares.select{|s| 20 == s.row}`しとくのが一番だと思いますが。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T18:38:42.963",
"id": "17389",
"last_activity_date": "2015-10-07T18:38:42.963",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3271",
"parent_id": "17377",
"post_type": "answer",
"score": 3
},
{
"body": "どうしても`select(...)`を使いたいというのであれば、こんなふうに書くとか。\n\n```\n\n Square = Struct.new(:row, :column)\n \n squares = []\n \n squares << Square.new(10, 20)\n squares << Square.new(50, 20)\n squares << Square.new(20, 20)\n \n f = ->(s){ s.row == 20}\n \n squares.select(&f)\n \n```\n\nもしくは、こうとか。\n\n```\n\n def test((s, v))\n s.row == v\n end\n \n Square = Struct.new(:row, :column)\n \n squares = []\n \n squares << Square.new(10, 20)\n squares << Square.new(50, 20)\n squares << Square.new(20, 20)\n \n squares.product([20]).select(&method(:test)).map(&:first)\n \n```\n\nたぶん、求めている回答とは違うと思いますが。。。\n\nとはいえ、何か特別な理由がなければ、\n\n```\n\n squares.select{|s| s.row == 20}\n \n```\n\nと書くのが一番素直でわかりやすいでしょうね。\n\n### 追記\n\n> test((s, v))てどういう意味ですか?\n\n`def test(s, v)` のように、カッコなしでメソッドを定義してコードを実行すると、次のようなエラーが出ます。\n\n```\n\n ArgumentError: wrong number of arguments (1 for 2)\n from (irb):1:in `test'\n from (irb):13:in `select'\n from (irb):13\n from /Users/jit/.rbenv/versions/2.2.3/bin/irb:11:in `<main>'\n \n```\n\nこれはつまり、testメソッドは引数を二つ受け取るように定義されているのに、selectメソッドで呼ばれたときは引数が一つしか渡されなかった(=1つの配列が渡された)のでエラーが出ています。\n\n`def test((s, v))`と書くと、「引数は1個」と定義したことになります。 \nただし、配列が渡されたら、1番目と2番目の要素はそれぞれ s と v に代入されます。(ややこしいですね)\n\n分かりにくい場合は、次のようなコードを1行で書いたと考えてください。\n\n```\n\n def test(args)\n s = args[0]\n v = args[1]\n # s, v = args でもよい\n s.row == v\n end\n \n Square = Struct.new(:row, :column)\n \n squares = []\n \n squares << Square.new(10, 20)\n squares << Square.new(50, 20)\n squares << Square.new(20, 20)\n \n squares.product([20]).select(&method(:test)).map(&:first)\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T22:29:33.830",
"id": "17437",
"last_activity_date": "2015-10-09T22:08:26.480",
"last_edit_date": "2015-10-09T22:08:26.480",
"last_editor_user_id": "85",
"owner_user_id": "85",
"parent_id": "17377",
"post_type": "answer",
"score": 2
}
] |
17377
| null |
17389
|
{
"accepted_answer_id": "17384",
"answer_count": 1,
"body": "下記サイトを参考にして、deploy scriptを書きましたが下記エラーにより失敗してしまいます。 \n<http://docs.drone.io/ssh.html>\n\ndeploy script\n\n```\n\n sudo rm -rf /var/www/html/[project-name]\n sudo mkdir /var/www/html/[project-name]\n sudo cp -pr /home/[user-name]/temp/* /var/www/html/[project-name]\n \n```\n\nエラー\n\n```\n\n sudo: no tty present and no askpass program specified\n sudo: no tty present and no askpass program specified\n sudo: no tty present and no askpass program specified\n exit status 1\n \n```\n\n`sudo`を取るとpermission deniedが出てしまいます。これはおそらく/var/ディレクトリのアクセス権限のせいですが。 \n本当は、例のようにデプロイする前にnginxをstopしたいのですが、下記のようにrootで起動しているようでできません。\n\n```\n\n root 517 0.0 0.2 15096 2276 ? Ss 21:36 0:00 nginx: master process nginx\n \n```\n\nこの場合はどのように書けばいいのでしょうか。またなぜ例では`sudo`が記入されていないのでしょうか。\n\n追記 \nOSはDebianです",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T14:18:16.153",
"favorite_count": 0,
"id": "17378",
"last_activity_date": "2015-10-07T16:18:08.843",
"last_edit_date": "2015-10-07T15:12:08.580",
"last_editor_user_id": "7232",
"owner_user_id": "7232",
"post_type": "question",
"score": 0,
"tags": [
"デプロイ"
],
"title": "drone.ioのssh deploy scriptが失敗する。",
"view_count": 130
}
|
[
{
"body": "> sudo: no tty present and no askpass program specified\n\nこれは sudo\nがパスワードを要求しようとしたが、端末(tty)が利用できず、他のパスワード入力手段も設定されていない、というエラーです。今回の場合いずれにせよその場でパスワードを入力することはできないでしょうから、パスワードなしで\nsudo を実行できるよう設定することで回避するぐらいでしょうか。\n\nもしこの方法を採るのであれば、一連の処理をまとめたスクリプトを書いた上で、SSH\nに使うユーザーかつそのスクリプトのみをパスワードなしで実行できるようにするとより安全です。\n\n * [特定のコマンドをパスワードなしでsudo する設定 - Slow Dance](http://d.hatena.ne.jp/LukeSilvia/20080716/p1)\n * [How do I sudo a command in a script without being asked for a password? - Ask Ubuntu](https://askubuntu.com/a/155827)\n\nnginx は init スクリプトで起動したのだろうと思います。この場合 `service stop nginx` `service start\nnginx` などとして操作できると思いますが、これも root 権限が必要です。\n\nそしてご想像の通り、drone.io から ssh させるユーザーに適切なアクセス権が与えられていれば、sudo は不要になります。サンプルスクリプトで\nsudo が使われていないのもそのためでしょう。\n\nまとめると、\n\n * デプロイ先のパーミッションを適切に設定し、手動で nginx を起動停止するようにする \n→ sudo 不要。drone.io のドキュメント通りで動くはず\n\n * パーミッションそのまま or 現状通り nginx の起動を init に任せる \n→ sudo が必要なので、NOPASSWD の設定を行う\n\nのどちらかになるかと思います。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T16:18:08.843",
"id": "17384",
"last_activity_date": "2015-10-07T16:18:08.843",
"last_edit_date": "2017-04-13T12:25:24.820",
"last_editor_user_id": "-1",
"owner_user_id": "8000",
"parent_id": "17378",
"post_type": "answer",
"score": 0
}
] |
17378
|
17384
|
17384
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "カリー化した場合に引数が必要な場合とそうじゃない場合の違いがわかりません. \nシンボルからto_procした場合は可変長引数を取るので \nそのため引数が必要になるのでしょうか??\n\n```\n\n head :022 > f = proc { |x,y| x + y }\n => #<Proc:0x007fbb311a0088@(irb):22> \n head :023 > f.curry(2).call(1).call(2)\n => 3 \n head :024 > f.curry.call(1).call(2)\n => 3 \n head :025 > f.curry.call(1,2)\n => 3 \n head :026 > :+.to_proc.curry.call(2, 3)\n => 5 \n head :027 > :+.to_proc.curry(2).call(2).call(3)\n => 5 \n head :028 > :+.to_proc.curry.call(2).call(3) # 指定しないとエラー\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T14:36:07.663",
"favorite_count": 0,
"id": "17380",
"last_activity_date": "2015-10-08T04:16:49.947",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8722",
"post_type": "question",
"score": 5,
"tags": [
"ruby"
],
"title": "rubyのカリー化で引数が必要な場合とそうでない場合の違い",
"view_count": 206
}
|
[
{
"body": "> シンボルからto_procした場合は可変長引数を取るので そのため引数が必要になるのでしょうか??\n\n必ずしも必要なわけではありません。 \nカリー化されたProcは「十分な数の引数が渡されると」評価されます。その十分な数の引数の数をcurry時に引数(arity)として指定するか、call時に自前で判断させるかの違いです。\n\n```\n\n # 次の場合、十分な引数の数は2つと判断される\n f2 = proc { |x, y, *z| x + y + z.inject(:+) }\n f2.curry.call(1, 2, 3, 4)\n => 10\n f2.curry.call(1).call(2, 3, 4)\n => 10\n f2.curry.call(1).call(2).call(3, 4) # 2つ渡した時点で評価される\n TypeError: nil can't be coerced into Fixnum\n \n```\n\nrubyのソース読んだわけではありませんが、挙動から察するにProc#arityの値を見て判断しているように思われます。\n\n```\n\n f = proc { |x,y| x + y }\n f.arity #=> 2 ... 2つの実引数\n \n f2 = proc { |x, y, *z| x + y + z.inject(:+) }\n f2.arity #=> -3 ... 2つの実引数と1つの可変長引数\n \n :+.to_proc.arity #=> -1 ... 0個の実引数と1つの可変長引数\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T04:16:49.947",
"id": "17405",
"last_activity_date": "2015-10-08T04:16:49.947",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9608",
"parent_id": "17380",
"post_type": "answer",
"score": 3
}
] |
17380
| null |
17405
|
{
"accepted_answer_id": "17385",
"answer_count": 1,
"body": "特定のブランチなど(tree-ish なオブジェクト)に存在する、特定のファイルの SHA-1 ハッシュを取得したいと考えています。\n\ngit の原理的に、checkout などによって index や worktree\nに対して変更を加えずとも、これを実現する方法はありそうだと考えているのですが、ご存知の方はいらっしゃいますでしょうか。\n\n例えば:\n\n```\n\n git THECOMMAND HEAD:hoge-dir/fuga-file\n git THECOMMAND origin/develop:README\n \n```\n\nなどで、該当するファイルの SHA-1 ハッシュを取得できたらよいと考えています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T15:53:19.473",
"favorite_count": 0,
"id": "17382",
"last_activity_date": "2015-10-07T17:31:36.327",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 3,
"tags": [
"git"
],
"title": "<tree-ish>:path/to/file で指定されるようなファイルの SHA-1 hash を取得するには?",
"view_count": 129
}
|
[
{
"body": "確かに Git は SHA-1\nハッシュでオブジェクトを識別していますが、これはあくまでオブジェクトのハッシュであり、ファイルなどのデータ本体のハッシュではありません。\n\n具体的には、データ本体の前にオブジェクトの種類や長さを付加したものが Git\nにおけるオブジェクトであり、これをハッシュ関数にかけたものがオブジェクトIDになっています。\n\n * [Git の仕組み (1) - こせきの技術日記](http://koseki.hatenablog.com/entry/2014/04/22/inside-git-1#3)\n * [Git - Git Objects](https://git-scm.com/book/en/v2/Git-Internals-Git-Objects) (もしくは[日本語訳](http://git-scm.herokuapp.com/book/ja/v2/Git%E3%81%AE%E5%86%85%E5%81%B4-Git%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88#%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%82%B9%E3%83%88%E3%83%AC%E3%83%BC%E3%82%B8))\n\n・・・とここまで書いて、「計算済みのハッシュ値を取り出したい」とは書かれていないことに気づきました。\n\n```\n\n git show origin/develop:README\n \n```\n\nで当該オブジェクトの中身を表示できるので、これを sha1sum にでも流して\n\n```\n\n git show origin/develop:README | sha1sum\n \n```\n\nという感じでどうでしょうか。\n\nちなみにファイルパスを `./` から始めると、相対パスとして扱われるようです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T17:26:32.130",
"id": "17385",
"last_activity_date": "2015-10-07T17:31:36.327",
"last_edit_date": "2015-10-07T17:31:36.327",
"last_editor_user_id": "8000",
"owner_user_id": "8000",
"parent_id": "17382",
"post_type": "answer",
"score": 2
}
] |
17382
|
17385
|
17385
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "はじめてこの場を使用させていただきます。\n\n現在、xcode6 objective-c を使用してゲームの開発を行っているのですが\n\nメモリの解放がうまくいきません。\n\nviewcontroller A から viewcontroller B への遷移後\n\ndismissViewControllerAnimatedを B で使用しているのですが\n\nviewcontroller A に戻った後もメモリは変わっていません。\n\nインスタンス宣言したものを全てremoveFromSuperviewしても \n全体の2割程度しか解放されませんでした。\n\ndismissViewControllerAnimatedを使用し、BからAへと戻った後に \n再度AからBへと遷移すると、 \n一部の変数の中身が残っている状態で様々な箇所でbad_accessが出てしまいます。\n\ndismissViewControllerAnimatedを使用したときに \nviewcontroller B の中身を全てを解放し、 \n再度、A から B へと遷移後、1から読み込みをしたいのですが \nなんとかならないでしょうか・・・。\n\n説明不足かもしれませんが、よろしくおねがいします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T23:08:49.433",
"favorite_count": 0,
"id": "17391",
"last_activity_date": "2016-10-24T03:49:04.460",
"last_edit_date": "2016-07-07T00:49:02.383",
"last_editor_user_id": "76",
"owner_user_id": "12635",
"post_type": "question",
"score": 1,
"tags": [
"objective-c"
],
"title": "removeFromParentViewControllerを使っての解放について",
"view_count": 545
}
|
[
{
"body": "View Controllerのメモリ解放のタイミングについて、誤解があるように感じたので、確認させてください。 \nモーダル表示されたView\nControllerは、`dismissViewControllerAnimated:`が完了したときにメモリ解放されます。`removeFromSuperview`しないと解放されないということはありません。 \nこのことを確かめるには、「viewcontroller B」に、`dealloc()`メソッドを記述してみます。\n\n```\n\n - (void)dealloc {\n NSLog(@\"ViewController B instance was released.\");\n }\n \n```\n\nviewcontroller\nBをReceiverとして`dismissViewControllerAnimated:`を実行すると、直後、コンソールに「ViewController B\ninstance was released.」と出力されます。\n\n* * *\n\nモーダル表示を終了させても、メモリが期待どおり解放されていないのは、よくあるケースとして、 **循環参照** が考えられます。「Objective-c\nARC\n循環参照」というようなキーワードでネット検索すると、循環参照に関する日本語の情報を見つけることができるでしょう。もとよりAppleの公式ドキュメントに直接あたられるなら、それに越したことはありません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T07:04:44.533",
"id": "17415",
"last_activity_date": "2015-10-08T07:04:44.533",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7362",
"parent_id": "17391",
"post_type": "answer",
"score": 1
}
] |
17391
| null |
17415
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "button(バックグラウンド)の上にオブジェクト(imageUI)がある場合、オブジェクトが重なっているところも同様にbuttonの効果があるようにする方法はありますか?\n\nバッググラウンド全体にbuttonがあります。buttonを押すと処理が開始されるのですが、 \nオブジェクトと重なっている場所は押せないため重なっていても処理ができるようにする \n方法はありますでしょうか",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-07T23:30:52.150",
"favorite_count": 0,
"id": "17392",
"last_activity_date": "2015-10-09T03:35:43.913",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9268",
"post_type": "question",
"score": 1,
"tags": [
"c#",
"unity3d"
],
"title": "button クリック判定",
"view_count": 814
}
|
[
{
"body": "やりたいことを「画面全域のクリックを検出したい」だと仮定して回答します。\n\nそもそもUIButtonは使わずにクリックを検出すればよいです。\n\n```\n\n void Update() {\n if (Input.GetMouseButtonDown(0)){\n Debug.Log(\"Pressed left click.\");\n }\n }\n \n```\n\n<http://docs.unity3d.com/jp/current/ScriptReference/Input.GetMouseButtonDown.html>\n\n* * *\n\n \nもう少し正確に質問しないと回答つきませんよ。\n\n * buttonとは何ですか?\n * imageUIとは何ですか?",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-09T03:35:43.913",
"id": "17460",
"last_activity_date": "2015-10-09T03:35:43.913",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4850",
"parent_id": "17392",
"post_type": "answer",
"score": 3
}
] |
17392
| null |
17460
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "こんにちは。\n\nMonacaにてiOS用アプリを作成してますが、一度iTunesConnectにリリースビルドしたアプリをアップロードしたあと、秘密鍵とCSR情報を再作成した場合(ディストリビューション証明書は変更なし)、その後ビルドしたものをiTunesConnectにアップロードしても大丈夫なのでしょうか?\n\nご回答よろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T02:13:21.237",
"favorite_count": 0,
"id": "17395",
"last_activity_date": "2016-06-11T02:06:31.130",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12638",
"post_type": "question",
"score": 0,
"tags": [
"ios",
"monaca"
],
"title": "Monaca:iOS用アプリで秘密鍵とCSR情報を再作成した場合",
"view_count": 438
}
|
[
{
"body": "アップデートの申請の話でしょうか? \nAndroidと違いiOSはCSRを再発行してもアップデートの申請はできます。 \n下記の場合にのみアップデート出来ません。 \n(それでも申請する場合は新たなアプリとして申請することになります。) \n・BundleIDが変更される \n・個人の場合は開発アカウントが変更された場合 \n・法人の場合は開発アカウントが属する開発グループから抜けた場合 \n・アプリバージョンが以前より高くない場合 \n・AppleDeveloperProgramの期限が切れた場合\n\n蛇足ですが、Androidの場合はkeystoreファイルが変わるとアップデートできなくなります。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T03:56:24.440",
"id": "17400",
"last_activity_date": "2015-10-08T03:56:24.440",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7676",
"parent_id": "17395",
"post_type": "answer",
"score": 1
}
] |
17395
| null |
17400
|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "<http://qiita.com/atchy@github/items/fb9df9e5865d8c7f7a72>\n\nこちらのサイトでraspbianのクロスコンパイル環境を作り方が説明されているのですが、Ubuntuのbit数はraspbianと合わせた方がいいのでしょうか? \nraspbianは \nLinux raspberrypi 3.18.11+ #781 PREEMPT Tue Apr 21 18:02:18 BST 2015 armv6l\nGNU/Linux \nこれを使用しています。 \narmv6lが何bitなのか分からないのですが、32bitまたは64bitのどちらに合わせた方がいいでしょうか? \nよろしくお願いします。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T02:31:52.103",
"favorite_count": 0,
"id": "17396",
"last_activity_date": "2015-10-08T05:15:15.180",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9349",
"post_type": "question",
"score": 1,
"tags": [
"raspberry-pi"
],
"title": "raspberry piのクロスコンパイル環境",
"view_count": 825
}
|
[
{
"body": "クロスコンパイル環境ですからホストとターゲットのビット数が同じである必然はまったくありません。 \nむしろ 64bit/32bit の両方で問題の生じないソースコードが書けるように \nホストは 64bit のほうが良い、んぢゃないですかね? \nホスト側の 64bit native compiler と \nクロス用の 32bit cross compiler と、 \n両方で [raspberry-pi](/questions/tagged/raspberry-pi \"'raspberry-pi'\nのタグが付いた質問を表示\") の 32bit コードをコンパイルしてみると違う警告が出たりします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T05:15:15.180",
"id": "17407",
"last_activity_date": "2015-10-08T05:15:15.180",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8589",
"parent_id": "17396",
"post_type": "answer",
"score": 1
}
] |
17396
| null |
17407
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "パスの設定をする際、エラーが生じてしまいます。これはどのように書き直すのがよろしいのでしょうか?教えてくださる方がいましたら、どうかよろしくお願いいたします。\n\n質問文の更新ですが、getCacheDirectory()の返り値の型はNSStringです。\n\n```\n\n func getFileURL() -> NSURL{\n let path = getCacheDirectory().stringByAppendingPathComponent(fileName)//ここでエラーが出ます。\n \n let filePath = NSURL(fileURLWithPath: path)\n \n return filePath\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T04:04:08.277",
"favorite_count": 0,
"id": "17401",
"last_activity_date": "2015-10-16T16:10:31.700",
"last_edit_date": "2015-10-16T16:10:31.700",
"last_editor_user_id": "5519",
"owner_user_id": "12536",
"post_type": "question",
"score": 1,
"tags": [
"swift"
],
"title": "stringByAppendingPathComponentのエラーについて",
"view_count": 1339
}
|
[
{
"body": "> エラーのメッセージは、 'stringByAppendingPathComponent' is unavailable: Use \n> URLByAppendingPathComponent on NSURL instead. というものです。\n\nでしたら、関数`getCacheDirectory()`の返値の型は、`String`だと思われます。 \n型(クラス名)を確認するには、`dynamicType`を使います。(以下の確認コードとその結果は、Xcode 7.0.1、Swift\n2.0で実行したものです。旧バージョンだと、おなじ結果にならないかもしれません)\n\n```\n\n print(getCacheDirectory().dynamicType)\n \n```\n\n返値の型が`NSString`であれば、`__NSCFString`と出力するはずです。`__NSCFString`は、`NSString`のクラスクラスタのひとつです。 \n返値の型が`String`であれば、そのまま`String`と出力します。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T07:35:50.383",
"id": "17416",
"last_activity_date": "2015-10-08T09:34:14.007",
"last_edit_date": "2015-10-08T09:34:14.007",
"last_editor_user_id": "7362",
"owner_user_id": "7362",
"parent_id": "17401",
"post_type": "answer",
"score": 1
},
{
"body": "`getCacheDirectory()`の実装が分かりませんが、\n\n```\n\n func getCacheDirectory() -> NSString {\n return NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true).last!\n }\n \n```\n\nのようなものであれば、普通に`stringByAppendingPathComponent`は使えます。\n\n```\n\n let path = (getCacheDirectory() as NSString).stringByAppendingPathComponent(fileName)\n \n```\n\nのようにキャストする方法もありますが、一度`NSURL`に変換する方法が好まれます。\n\n* * *\n\nSwiftは`String`と`NSString`の間に暗黙の変換がありますが、バージョンを経ることに段々と制約が増えていきます。\n\n理由は、Swiftの`String`が値型であることに対して、Objective-Cの`NSString`は参照型であることかと思います。\n\n`NSString`はクラスクラスタなので、複数のサブクラス実装がありますが、それらすべてに対してブリッジしてしまうので、`NSString`のサブクラス実装によってはコピー処理によって予期せぬパフォーマンス性能劣化を引き起こすからです。\n\nSwift\n1.2から2.0で、`stringByAppendingPathComponent`のようなパス文字列を扱うメソッド群(実装が`NSPathStore2`にあると考えられるもの)を使うと、\n\n> 'stringByAppendingPathComponent' is unavailable: Use\n> URLByAppendingPathComponent on NSURL instead.\n\nというコンパイルエラーが出るようになりました。これは上述の問題を回避するために一度`NSURL`に変換して、`URLByAppendingPathComponent`で代替するべきだというメッセージですので、それに従うのが無難かと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T12:02:15.133",
"id": "17428",
"last_activity_date": "2015-10-08T12:02:15.133",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5337",
"parent_id": "17401",
"post_type": "answer",
"score": 1
}
] |
17401
| null |
17416
|
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "音声のフォーマットを設定する際、以下のプログラムでエラーが生じてしまいます。\n\n追記:UIntを加えたのですが、`soundRecorder` の `as [NSObject : AnyObject]` の部分でエラーが出てしまいます。\n\n```\n\n let recordSettings: [String : Any] = [AVFormatIDKey:UInt(kAudioFormatAppleLossless),\n AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue,\n AVEncoderBitRateKey : 160000,\n AVNumberOfChannelsKey : 2,\n AVSampleRateKey : 8000.0 ]\n \n var error : NSError?\n \n soundRecorder = AVAudioRecorder(URL: getFileURL(), settings: recordSettings as [NSObject : AnyObject], error: &error)//ここでエラーが出ます。\n \n```\n\nお気づきの方がいらっしゃいましたら、ご指導のほどよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T04:14:52.713",
"favorite_count": 0,
"id": "17404",
"last_activity_date": "2015-10-16T16:10:23.917",
"last_edit_date": "2015-10-16T16:10:23.917",
"last_editor_user_id": "5519",
"owner_user_id": "12536",
"post_type": "question",
"score": 0,
"tags": [
"ios",
"swift"
],
"title": "録音音声のフォーマット設定時のエラー",
"view_count": 745
}
|
[
{
"body": "コンパイラが型を推論できていないので、例えば型を指定します。`var recordSettings: [String: Any]`の部分です。\n\n```\n\n var recordSettings: [String: Any] = [AVFormatIDKey : kAudioFormatAppleLossless,\n AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue,\n AVEncoderBitRateKey : 160000,\n AVNumberOfChannelsKey : 2,\n AVSampleRateKey : 8000.0 ]\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T09:41:56.843",
"id": "17425",
"last_activity_date": "2015-10-08T09:41:56.843",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5519",
"parent_id": "17404",
"post_type": "answer",
"score": 1
},
{
"body": "編集前の質問のコードは、Xcode6では大丈夫だったのですが、Xcode7/iOS9 SDKになって、 \n`kAudioFormatAppleLossless` が `Int` から `UInt32` になり、`UInt32`\nなどのビット数指定の数値型は、`NSNumber`に自動変換されないため、エラーになります。\n\nなので、Xcode7では明示的に `UInt` 等の `AnyObject`互換の型に変換してあげる必要があります。\n\nそれとそのままだと `recordSettings` が `NSDictionary` になってしまうので `AVAudioRecorder`\nのイニシャライザが要求する `[String:AnyObject]` を明示的に指定します。\n\n```\n\n let recordSettings: [String: AnyObject] = [\n AVFormatIDKey : UInt(kAudioFormatAppleLossless), // <-- これ\n AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue,\n AVEncoderBitRateKey : 160000,\n AVNumberOfChannelsKey : 2,\n AVSampleRateKey : 8000.0\n ]\n \n```\n\n`NSNumber(unsingedInt: kAudioFormatAppleLossless)` でもいいのですが、 \n`UInt` のほうが文字数が少ないので。\n\nあと、 `AVAudioRecorder` イニシャライザは `throw` するようになったので、`try`\nなどしてエラーをハンドルするなり、無視するなりする必要があります。[`Swift` の `throw`\nエラーハンドリング](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html#//apple_ref/doc/uid/TP40014097-CH42-ID508)については、質問の趣旨と違うので、ここでは説明しません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2015-10-08T13:36:14.050",
"id": "17432",
"last_activity_date": "2015-10-08T14:38:48.580",
"last_edit_date": "2015-10-08T14:38:48.580",
"last_editor_user_id": "3489",
"owner_user_id": "3489",
"parent_id": "17404",
"post_type": "answer",
"score": 2
}
] |
17404
| null |
17432
|
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "カスタムセルの中に UIImage を配置し、画像が存在する場合は画像を表示し、画像が存在しない場合は画像を非表示にしたいです。\n\n下記のように Constraint を IBOutlet で繋ぎ、調節しようとしたのですが、うまくいきません。 \nエラー内容としては、一番最後の行の`\"cell.thumImageWidthConstraint.constant = 0.0\"`で Exception\nが発生してしまい、\n\n> fatal error: unexpectedly found nil while unwrapping an Optional value\n\nとなってしまいます。\n\nアドバイス頂けたらうれしいです。\n\n[コード]\n\n```\n\n var cell : BingWebCustomCell! = nil\n cell = tableView.dequeueReusableCellWithIdentifier(\"WebCell\") as! BingWebCustomCell \n \n if self.bingImageArray.isEmpty == false && self.bingImageArray.count > indexPath.row{\n let imageUrlStr: String? = self.bingImageArray[indexPath.row] as? String\n if imageUrlStr != \"\"{\n let imageUrl: NSURL? = NSURL(string: imageUrlStr!)\n cell.thumImage.kf_setImageWithURL(imageUrl!) //download image via \"Kingfisher\" library\n cell.thumImageWidthConstraint!.constant = 128.0\n }else{\n cell.thumImageWidthConstraint.constant = 0.0\n }\n }else {\n cell.thumImageWidthConstraint.constant = 0.0\n }\n \n```\n\n[環境]\n\n * Xcode7.0.1\n * Swift2.0\n * El Capitan (ver10.11)\n * Deployment Target iOS8.2",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2015-10-08T05:17:25.327",
"favorite_count": 0,
"id": "17408",
"last_activity_date": "2019-06-06T20:46:39.993",
"last_edit_date": "2019-06-06T20:46:39.993",
"last_editor_user_id": "32986",
"owner_user_id": "682",
"post_type": "question",
"score": 1,
"tags": [
"ios",
"swift",
"tableview"
],
"title": "UIImageの幅を可変にしたい",
"view_count": 221
}
|
[] |
17408
| null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.