question
dict | answers
list | id
stringlengths 2
5
| accepted_answer_id
stringlengths 2
5
⌀ | popular_answer_id
stringlengths 2
5
⌀ |
---|---|---|---|---|
{
"accepted_answer_id": "23268",
"answer_count": 1,
"body": "Unityで作成したゲームにランキングを導入しようと、面白法人カヤックさんが公開しているLobiを導入してみたのですが、iOSにコンパイルした場合のみBGMが割れたような音?すごくピッチが遅くなったような音になりました。\n\n現在導入しているプラグインをひとつずつ追加していき、確認したのでLobi導入による問題だとは特定したのですが、導入の仕方に問題があって起こった症状なのか、Lobiのバグなのかどちらかわからない状況です。\n\n新しいプロジェクト作ってただBGM流してるだけの最小構成のアプリでもなったので、 \nLobiのバグだと思いたいんですが。。。 \nこれ以上どうしたらいいかわからなかったので、質問させていただきました。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-18T10:57:38.360",
"favorite_count": 0,
"id": "23255",
"last_activity_date": "2016-04-18T01:38:11.247",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13901",
"post_type": "question",
"score": 2,
"tags": [
"ios",
"unity3d"
],
"title": "Unityで面白法人カヤックさんのLobiを使用するとBGMが割れる",
"view_count": 372
} | [
{
"body": "改めて回答として投稿しておきます。\n\nGithub上のLobiSDKのWikiに、各環境ごとの導入手順書が載っています。で、[iOS+Unity](https://github.com/kayac/Lobi/wiki/iOS-\nImplement-LobiRecSDK-Unity)の手順の中に、「Unity\n5での導入に関しては~」という記述があり、その[リンク先](https://github.com/kayac/Lobi/wiki/LobiSDK-\nUnity5)にこのように書かれています。\n\n> ## Unityプロジェクトの設定\n>\n> * (省略)\n> * `[Edit]-[Project Settings]-[Audio]` の `[Sample Rate]` に `44100`\n> を設定して下さい(※お手数ですが、Android向けにビルドするときは、設定を空欄に戻してください)\n>\n\nサンプリングレートの設定が原因でピッチや再生速度がおかしくなるというのは、iOSやUnityに限らず、PC上での音楽制作などでも耳にする話ですね。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T00:40:00.953",
"id": "23268",
"last_activity_date": "2016-03-19T00:40:00.953",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "23255",
"post_type": "answer",
"score": 2
}
]
| 23255 | 23268 | 23268 |
{
"accepted_answer_id": "23260",
"answer_count": 1,
"body": "javaの場合、下記のような感じでOSのコマンドを実行可能なのですが、 \niosから実行する方法はあるのでしょうか。 \n#NSTaskで!と思ったのですがiosでは無理なようで…。\n\n```\n\n Runtime runtime = Runtime.getRuntime();\n Process proc = null;\n try{\n proc = runtime.exec(\"ping -c 5 www.google.com\");\n proc.waitFor();\n }catch(Exception e){}\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-18T11:19:46.357",
"favorite_count": 0,
"id": "23256",
"last_activity_date": "2016-03-18T12:58:43.257",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12842",
"post_type": "question",
"score": 0,
"tags": [
"ios"
],
"title": "iosでOSのコマンドを実行することは可能なのでしょうか",
"view_count": 1150
} | [
{
"body": "できません。\n\n * shellを含む多くのOSコマンドがiOSには搭載されていません\n * 数少ない「OSコマンド」の存在するディレクトリにはアプリからアクセス出来ません\n * 何らかの実行ファイルをアプリとは別のプロセスとして起動することもできません\n\nUnix/Linux用のOSコマンドはほとんどオープンソースですから、使いたいコマンドのソースコードを入手して、ご自身のアプリの一部としてビルドし、その機能をアプリの一部として実行させる、と言うことでOSコマンドの実行内容と同じ処理をさせられるかも知れませんが、大変な手間がかかりますし、「OSのコマンドを実行」と言う言葉で語られているのとは全く異なるイメージなのではないかと思います。と言うわけで結論は最初に書いた通り「できません」です。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-18T12:58:43.257",
"id": "23260",
"last_activity_date": "2016-03-18T12:58:43.257",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "23256",
"post_type": "answer",
"score": 2
}
]
| 23256 | 23260 | 23260 |
{
"accepted_answer_id": "23264",
"answer_count": 1,
"body": "ReactJSとjQueryと[materialize](http://materializecss.com/)というjQueryを使ったフレームワークを使ったサイトを作成しています。\n\nそこで質問です。Reactにより生成されるgridにmaterializeによるgridレイアウトを使用していますが、スマホで観た時にグリッドが1カラムになってくれません。しかし、PCのブラウザ(クローム、サファリで確認)では画面幅を小さくした時に1カラム表示となります。画面が大きい場合は3カラムのグリッドです。\n\nこのようになってしまう原因としては何が考えられるでしょうか。また、ReactとjQuery(Bootstrapのようなフレームワーク)の共存は不可能なのでしょうか。react-\nbootstrapなどを使用しなければならないのでしょうか。\n\n以下にReactのコードを示します。一応jQueryがロードされた後にこのコードを実行するようにしましたが、効果ありませんでした。\n\n```\n\n (function($){\n var GridBox = React.createClass({\n loadData: function(){\n $.ajaxSetup({\n cache: false\n });\n $.getJSON(this.props.url, function(json){\n this.setState({data: json});\n }.bind(this));\n },\n getInitialState: function(){\n return {data: {\n \"items\": []\n }};\n },\n componentDidMount: function(){\n this.loadData();\n },\n render: function(){\n var rows = this.state.data.items.map(function(row){\n return (\n <Row data={row}/>\n );\n });\n return (\n <div>\n <h5>{this.state.data.title}</h5>\n {rows}\n </div>\n );\n }\n });\n \n var Row = React.createClass({\n render: function(item){\n var items = this.props.data.map(function(item){\n return (\n <Col item={item}/>\n );\n });\n return (\n <div className=\"row\">\n {items}\n </div>\n );\n }\n });\n \n var Col = React.createClass({\n render: function(){\n var imageURL = \"dist/images/\" + this.props.item.thumbnail;\n return (\n <div className=\"col s12 m4\">\n <div className=\"card\">\n <div className=\"card-image waves-effect waves-block waves-teal\">\n <a href={this.props.item.url} target=\"_blank\">\n <img src={imageURL} className=\"lazy\"/>\n </a>\n </div>\n <div className=\"card-content\">\n <p>{this.props.item.name}</p>\n </div>\n </div>\n </div>\n );\n }\n });\n \n \n ReactDOM.render(\n <GridBox url=\"data/item.json\"/>,\n document.getElementById('item')\n );\n \n \n })(jQuery);\n \n```\n\nまたこのコードはjsxでコンパイルしたあとでgulpにより、他のJavaScriptファイルと一緒にminify,uglifyして1つのJavaScriptにしてロードしています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-18T14:52:40.730",
"favorite_count": 0,
"id": "23263",
"last_activity_date": "2016-03-18T18:47:28.877",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7232",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"jquery",
"reactjs"
],
"title": "ReactjsとjQueryフレームワークを同時に使うには",
"view_count": 825
} | [
{
"body": "[このスレではtaylorさんが述べているように](https://stackoverflow.com/a/33044103/1167750)、この問題は[`viewport`](https://developer.mozilla.org/ja/docs/Mobile/Viewport_meta_tag)のことに関連していると私は思います。`meta`タグの`viewport`が使用されていない時は、スマホのブラウザはPCのブラウザのように振る舞うのです。\n\n下記のコード例のように、`viewport`を[使用すると](https://developer.mozilla.org/ja/docs/Mobile/Viewport_meta_tag#.E3.83.93.E3.83.A5.E3.83.BC.E3.83.9D.E3.83.BC.E3.83.88.E3.81.AE.E5.9F.BA.E6.9C.AC)、スマホを使う場合は`Materialize`のスマホへの[レスポンシブ`CSS`](http://materializecss.com/grid.html#grid-\nresponsive)が期待される効果を発揮すると思います。\n\n```\n\n <html>\n <head>\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n </head>\n <body>\n <!-- 自分のコンテンツ -->\n </body>\n </html>\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-18T16:38:11.073",
"id": "23264",
"last_activity_date": "2016-03-18T18:47:28.877",
"last_edit_date": "2017-05-23T12:38:55.250",
"last_editor_user_id": "-1",
"owner_user_id": "4129",
"parent_id": "23263",
"post_type": "answer",
"score": 0
}
]
| 23263 | 23264 | 23264 |
{
"accepted_answer_id": "24798",
"answer_count": 1,
"body": "iOSアプリ側 [ViewController.swift]\n\n```\n\n override func viewDidLoad() {\n super.viewDidLoad()\n \n let udForWatch = NSUserDefaults(suiteName: SuiteName)!\n let ary = [\"テスト\",\"テスト\"]\n \n udForWatch.setObject(ary, forKey: \"ary\")\n }\n \n```\n\nWatch Extension側 [InterfaceController.swift]\n\n```\n\n class InterfaceController: WKInterfaceController {\n \n \n override func awakeWithContext(context: AnyObject?) {\n super.awakeWithContext(context)\n \n let ud = NSUserDefaults(suiteName: SuiteName)!\n print(ud.objectForKey(\"ary\")) //nilになる。\n \n }\n }\n \n```\n\nとしているのですが、Watch Extension側のデータがnilになってしまいます。 \n何がおかしいのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-18T18:18:23.100",
"favorite_count": 0,
"id": "23266",
"last_activity_date": "2016-05-12T12:33:07.223",
"last_edit_date": "2016-03-19T03:55:40.770",
"last_editor_user_id": "12297",
"owner_user_id": "12297",
"post_type": "question",
"score": 0,
"tags": [
"swift"
],
"title": "watchOS2で、Watch Extension側に、iOSアプリ側からNSUserDefaults経由で、データが渡ってこない。",
"view_count": 131
} | [
{
"body": "watchOS2ではWatchConnectivityを使用する必要があります。上記のコードはいわゆるwatchOS1でしか使うことができません。\n\nこちらでその原因が述べられていますが、watchOS1ではiPhoneでExtensionが動作していましたが、watchOS2からはApple\nWatchで動作するようになったためです。 \n<http://qiita.com/koogawa/items/432b9c65035b6ba17c8b#3-app-\ngroups%E3%81%A7%E3%83%87%E3%83%BC%E3%82%BF%E3%82%92%E5%85%B1%E6%9C%89%E3%81%A7%E3%81%8D%E3%81%AA%E3%81%84%E5%95%8F%E9%A1%8C>\n\niPhone内に保存したUserDefaultsのデータはWatchConnectivityフレームワークの`sendMessage`など、用途に応じて適切な方法で送信する必要があります。 \n<http://qiita.com/koogawa/items/b39e1419cbbcda8efc07>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-05-12T12:33:07.223",
"id": "24798",
"last_activity_date": "2016-05-12T12:33:07.223",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10926",
"parent_id": "23266",
"post_type": "answer",
"score": 3
}
]
| 23266 | 24798 | 24798 |
{
"accepted_answer_id": "23870",
"answer_count": 1,
"body": "Babelで特定の機能だけ有効にすることはできるのでしょうか?\n\narrow\nfunctionはすでに実装されているのでそちらを使い、classはまだ実装されていないのでbabelで変換する、というふうにESの機能ごとにbabelのon,\noffを切り替えることはできるのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T07:22:12.237",
"favorite_count": 0,
"id": "23271",
"last_activity_date": "2018-09-28T22:33:54.707",
"last_edit_date": "2018-09-28T22:33:54.707",
"last_editor_user_id": "19110",
"owner_user_id": "5246",
"post_type": "question",
"score": 2,
"tags": [
"javascript",
"babeljs"
],
"title": "JavaScriptのBabelで特定の機能だけ有効にする",
"view_count": 185
} | [
{
"body": "最新のBabel(6.7.5\nで確認)ではプロジェクトのディレクトリに作成する`.babelrc`で設定する方法が[推奨されています](https://github.com/thejameskyle/babel-\nhandbook/blob/master/translations/en/user-handbook.md#toc-babelrc)。 \n必要な物だけ`presets`や`plugins`に指定します。 \n\n```\n\n {\n \"presets\": [\n ],\n \"plugins\": [\n \"transform-es2015-classes\",\n \"transform-strict-mode\"\n ]\n }\n \n```\n\n`.babelrc`がなくともツール毎に実行時に指定する方法はあります。 \n例えばコマンドラインツールだと、オプションで指定出来ます。 \n\n```\n\n babel --plugins transform-strict-mode,transform-es2015-classes hello.js\n \n```\n\nしかし、`.babelrc`を作っておけばツール毎に指定する手間がない、という事のようです。\n\nプリセットやプラグインの一覧は <http://babeljs.io/docs/plugins/> にあります。 \n[プリセットに`es2015`](http://babeljs.io/docs/plugins/preset-\nes2015/)を指定するとES6をES5に変換する為のプラグインが全て読み込まれるようです。\n\n```\n\n {\n \"presets\": [\"es2015\"]\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-04-09T09:43:49.390",
"id": "23870",
"last_activity_date": "2016-04-09T09:43:49.390",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23271",
"post_type": "answer",
"score": 4
}
]
| 23271 | 23870 | 23870 |
{
"accepted_answer_id": "23277",
"answer_count": 2,
"body": "BEMでのクラス名のつけ方を確認して頂きたいのですが、下記でクラス名のつけ方全般に問題はないでしょうか?\n\n(簡易なBEMなので、すべては引き継がずという形を目指しています。) \nタグも間違ってなさそうでしょうか? \nいろいろな方の意見が聞きたいです。\n\n・ソース\n\n```\n\n <div class=\"wrap-skew1 first-section-skew1\">\n <div class=\"wrap-skew2 first-section-skew2\">\n <div class=\"wrap-inner\">\n <section class=section multicolumn \">\n <div class=\"content-wrap translate3d-to-upper-left \">\n <h2 id=\"js-about-me \" class=\"heading-primary \">ABOUT ME</h2>\n <p class=\"paragraph-oneline \">あああああああああああああああああああああああああああああああああああ</p>\n <p>いいいいいいいいいいいいいいいいいいいいいいいいいい。</p>\n </div><!-- /.contents-wrap -->\n <div class=\"img-wrap translate3d-lower-right \">\n <img class=\"my-image \" src=\"img/index/myimage.png \" alt=\"自身の写真 \">\n </div>\n </section><!-- /#about -->\n </div>\n </div>\n </div>\n \n```\n\n```\n\n 下記はinnerにするべきなのでしょうか?\n innerは中身ということですがいまいちはっきりしません。\n <section class=section-wrap multicolumn\">\n <div class=\"content-wrap translate3d-to-upper-left\">\n \n```\n\n・下記が実際の見た目です。 \n<https://jsfiddle.net/80od313c/24/>\n\n```\n\n $(function(){\r\n // 下記をクリックすると実行される\r\n $('#drawermenu, .overlay-haikeikurokari, .link-block, .showMenue, .modal-button-wrap').on('click', function() {\r\n // 下記の要素のセレクタにactiveクラスが足される。.modal-button-wrap__button.activeとなるので、.modal-button-wrap__buttonのみで良い。\r\n $('.modal-button-wrap__button').toggleClass('active');\r\n }); \r\n });\r\n \r\n $('.modal-button-wrap__button,.link-block').click(function(){\r\n //ulをクリックすると、メニューが出たり戻ったりする\r\n $('#drawermenu').toggleClass('showMenue');//モーダルのクラスを削除して、モーダルボディーを戻す\r\n });\r\n $('#drawermenu li').click(function(){\r\n //ulをクリックすると、メニューが出たり戻ったりする\r\n $('#drawermenu').toggleClass('showMenue');//モーダルのクラスを削除して、モーダルボディーを戻す\r\n });\r\n $(document).on('click', '.overlay-haikeikurokari, #js-drwar-action ,.showMenue', function(){ \r\n //.メニューが出る必要はなく、戻る動きだけ必要な場合\r\n $('#drawermenu').removeClass('showMenue');//モーダルのクラスを削除して、モーダルボディーを戻す\r\n });\r\n \r\n <!-- drawermenu-blackbackground -->\r\n $('.modal-button-wrap').click(function(){\r\n //透明の背景、オーバーレイのhtmlを作る\r\n $('body').append('<div class=\"overlay-haikeikurokari\"></div>');\r\n //透明の背景、オーバーレイをフェードイン\r\n $('.overlay-haikeikurokari').fadeIn('slow');\r\n //ここをクリックすると黒い背景がフェードアウト\r\n $('.overlay-haikeikurokari, .close, #drawermenu, .link-block ,.showMenue, .modal-button-wrap__button').click(function(){\r\n //透明の背景をフェードアウト\r\n $('.overlay-haikeikurokari').fadeOut('slow');\r\n // 透明の背景オーバーレイはフェードアウトしてから削除\r\n $('.overlay-haikeikurokari').fadeOut('slow', function(){\r\n $('.overlay-haikeikurokari').remove();\r\n });\r\n });\r\n });\n```\n\n```\n\n /* ---------------------------------------------------------\r\n MainContent-First\r\n ----------------------------------------------------------*/\r\n /* メインコンテンツの背景共通 */\r\n main {\r\n font-size: 1.6rem;\r\n }\r\n \r\n .wrap-skew1 {\r\n transform: skewY(-6deg);\r\n margin: 0px auto 10%;\r\n padding: 0px;\r\n background: rgba( 229, 228, 255, 0.9 );\r\n /*other-pattern*/\r\n /*background: rgba( 229, 228, 255, 0.7 );*/\r\n /*background: linear-gradient(to left bottom, rgba(0, 255, 255, 0.6), rgba(0, 0, 255, 0.6) 15%, rgba(0, 255, 255, 0.6) 33%, rgba(0, 0, 255, 0.6) 49%, rgba(0, 255, 255, 0.6) 67%, rgba(0, 0, 255, 0.6) 84%, rgba(0, 255, 255, 0.6));*/\r\n text-align: left;\r\n }\r\n \r\n @media (min-width: 640px) { \r\n .wrap-skew1 {\r\n transform: skewY(-5deg);\r\n } \r\n }\r\n \r\n @media (min-width: 960px) { \r\n .wrap-skew1 {\r\n transform: skewY(-3.5deg);\r\n margin: 0px auto 5%;\r\n } \r\n }\r\n \r\n .wrap-skew2 {\r\n transform: skewY(6deg);\r\n width: 100%;\r\n margin: 0px auto;\r\n padding: 0px;\r\n background: rgba( 190, 250, 255, 0.6 );\r\n /*background: linear-gradient(to left bottom, rgba(0, 255, 255, 0.1), rgba(0, 0, 255, 0.1) 15%, rgba(0, 255, 255, 0.1) 33%, rgba(0, 0, 255, 0.1) 49%, rgba(0, 255, 255, 0.1) 67%, rgba(0, 0, 255, 0.1) 84%, rgba(0, 255, 255, 0.1));*/\r\n }\r\n \r\n @media (min-width: 640px) { \r\n .wrap-skew2 {\r\n transform: skewY(5deg);\r\n } \r\n }\r\n \r\n @media (min-width: 960px) { \r\n .wrap-skew2 {\r\n transform: skewY(3.5deg);\r\n } \r\n }\r\n \r\n /* メインコンテンツのパッディング */\r\n .wrap-content {\r\n padding: 15% 8%;\r\n transform: skewY(0deg);\r\n }\r\n \r\n @media (min-width: 640px) { \r\n .wrap-content {\r\n padding: 11% 11%;\r\n } \r\n }\r\n \r\n @media (min-width: 960px) { \r\n .wrap-content {\r\n padding: 9% 11%;\r\n } \r\n }\r\n /* /メインコンテンツのパッディング */\r\n \r\n /* メインコンテンツの背景 */\r\n .first-section-skew1 {\r\n margin-top: 5%;\r\n padding: 0px;\r\n }\r\n \r\n /* 見出しの共通クラス */\r\n .common-heading {\r\n font-size: 2.8rem;\r\n text-shadow: \r\n 1px 1px rgba(0, 0, 0, .2),\r\n 2px 2px rgba(0, 0, 0, .1),\r\n 3px 3px rgba(0, 0, 0, .1),\r\n 4px 4px rgba(0, 0, 0, .05),\r\n 5px 5px rgba(0, 0, 0, .05),\r\n 6px 6px rgba(0, 0, 0, .05);\r\n }\r\n \r\n \r\n \r\n /* ---------------------------------------------------------\r\n Inquery\r\n ----------------------------------------------------------*/\r\n .inquiry {\r\n position: relative;\r\n padding: 34rem 0 35.5rem 0;\r\n width : 100%;\r\n background: url(../img/common-img/inquery-back.png) no-repeat;\r\n background-position: center center;\r\n background-size: cover;\r\n }\r\n \r\n @media (min-width: 960px) { \r\n .inquiry {\r\n padding: 53rem 0 28rem 0;\r\n } \r\n }\r\n \r\n /*入力フォーム一覧の位地*/\r\n .inquiry-wrap {\r\n position: absolute;\r\n top: 7.6%;\r\n left: 8%;\r\n }\r\n \r\n @media (min-width: 640px) { \r\n .inquiry-wrap {\r\n top: 7.6%;\r\n left: 11%;\r\n } \r\n }\r\n \r\n @media (min-width: 960px) { \r\n .inquiry-wrap {\r\n position: absolute;\r\n top: 10.3%;\r\n left: 11%;\r\n } \r\n }\r\n \r\n .inquiry__heading {\r\n text-shadow: \r\n 1px 1px rgba(0, 0, 0, .2),\r\n 2px 2px rgba(0, 0, 0, .1),\r\n 3px 3px rgba(0, 0, 0, .1),\r\n 4px 4px rgba(0, 0, 0, .05),\r\n 5px 5px rgba(0, 0, 0, .05),\r\n 6px 6px rgba(0, 0, 0, .05)\r\n ;\r\n }\r\n \r\n .inquiry__heading,.inquiry-form dt {\r\n color: white;\r\n }\r\n \r\n .inquiry-form dt {\r\n text-shadow:\r\n 0px 0px 10px #fff,\r\n 0px 0px 10px #fff,\r\n 0px 0px 10px #fff,\r\n 0px 0px 10px #fff,\r\n 0px 0px 10px #fff,\r\n 0px 0px 10px #fff,\r\n 0px 0px 10px #fff,\r\n 0px 0px 10px #fff,\r\n 0px 0px 10px #fff,\r\n 2px 2px 2px rgba(0,0,0,.9);\r\n color: #000;\r\n font-weight: bold;\r\n }\r\n \r\n /*フォーム~ボタンまでの横幅、行間一括指定、個人情報ボックス以外*/\r\n .inquiry-form__input-box input,#inquiry-form_body,.inquiry__submit-btn {\r\n width: 90%;\r\n line-height: 2;\r\n border-style: none;/*選択時の枠線を無くす*/\r\n }\r\n \r\n @media (min-width: 960px) { \r\n .inquiry-form__input-box input,#inquiry-form_body,.inquiry__submit-btn {\r\n width: 40%;\r\n } \r\n }\r\n \r\n .inquiry-form__input-box,.inquiry-form__input-box_kind_textarea {\r\n opacity: 0.7;\r\n }\r\n \r\n .inquiry-form__input-box {\r\n margin-bottom: 1rem;\r\n }\r\n \r\n .inquiry-form__input-box_kind_textarea #inquiry-form_body {\r\n margin-bottom: 2rem;\r\n resize: horizontal;/*横のみリサイズ可能*/\r\n }\r\n \r\n #inquiry-form_body {\r\n height: 5rem;\r\n }\r\n \r\n @media (min-width: 960px) { \r\n #inquiry-form_body {\r\n height: 10rem;\r\n } \r\n }\r\n \r\n .privacy {\r\n border: 0.1rem solid #03AFFF;\r\n width: 78%;\r\n padding: 2.3rem 3rem 0 3rem;\r\n height: 12rem;\r\n line-height: 2;\r\n overflow-y: scroll;\r\n background: #fff;\r\n opacity: 0.7;\r\n }\r\n \r\n @media (min-width: 960px) { \r\n .privacy {\r\n width: 37%;\r\n } \r\n }\r\n \r\n .inquiry__submit-btn {\r\n display: block;\r\n margin-top: 4rem;\r\n height: 5.5rem;\r\n background: rgb(0, 239, 123);\r\n color: #fff;\r\n font-size: 2.7rem;\r\n font-weight: bold;\r\n letter-spacing: 2px;\r\n line-height: 5.5rem;\r\n text-align: center;\r\n text-shadow: 1px 1px 0px #000,\r\n -1px 1px 0px #000,\r\n 1px -1px 0px #000,\r\n -1px -1px 0px #000;\r\n box-shadow: 2px 2px 2px rgba(0,0,0,.9);\r\n }\r\n \r\n \r\n \r\n /* ---------------------------------------------------------\r\n Footer\r\n ----------------------------------------------------------*/\r\n .footer-common {\r\n padding: 8% 10%;\r\n box-shadow: 0rem 0.6rem 0.6rem -0.6rem rgba(0,0,0,0.9) inset; \r\n text-align: center;\r\n font-size: 1.6rem;\r\n behavior: url(./plugin/PIE.htc);\r\n /*background: transparent linear-gradient(to right bottom, rgba(0, 255, 255, 0.2), rgba(0, 0, 255, 0.2) 15%, rgba(0, 255, 255, 0.2) 33%, rgba(0, 0, 255, 0.2) 49%, rgba(0, 255, 255, 0.2) 67%, rgba(0, 0, 255, 0.2) 84%, rgba(0, 255, 255, 0.2)) repeat scroll 0% 0%;*/\r\n background: transparent linear-gradient(to right bottom, rgba(0, 255, 255, 0.4), rgba(0, 0, 255, 0.4) 15%, rgba(0, 255, 255, 0.4) 33%, rgba(0, 0, 255, 0.4) 49%, rgba(0, 255, 255, 0.4) 67%, rgba(0, 0, 255, 0.4) 84%, rgba(0, 255, 255, 0.4)) repeat scroll 0% 0%; \r\n /*background: transparent linear-gradient(to right bottom, rgba(0, 255, 255, 1), rgba(0, 0, 255, 1) 15%, rgba(0, 255, 255, 1) 33%, rgba(0, 0, 255, 1) 49%, rgba(0, 255, 255, 1) 67%, rgba(0, 0, 255, 1) 84%, rgba(0, 255, 255, 1)) repeat scroll 0% 0%;*/\r\n /*background-image: linear-gradient(to right, rgb(52, 152, 219) 25%, rgb(41, 128, 185) 100%);*/\r\n /*-pie-background: linear-gradient(#8Fd537, #6Fb517);*/\r\n }\r\n \r\n @media (min-width: 960px) {\r\n .footer-common {\r\n padding: 6% 10%;\r\n box-shadow: 0rem 0.6rem 0.6rem -0.6rem rgba(0,0,0,0.9) inset; \r\n }\r\n }\r\n \r\n @media (min-width: 960px) {\r\n .footer-common {\r\n padding: 3.5% 10%;\r\n box-shadow: 0rem 0.6rem 0.6rem -0.6rem rgba(0,0,0,0.9) inset; \r\n }\r\n }\r\n \r\n /* address */\r\n .address {\r\n display: inline;\r\n font-size: 1.8rem;\r\n text-shadow: 1px 1px 1px rgba(0,0,0,.9);\r\n line-height: 1.5;/* Social-buttonとアドレスの間の隙間 */\r\n }\r\n \r\n @media (min-width: 640px) {\r\n .address {\r\n font-size: 2.5rem;\r\n }\r\n }\r\n \r\n @media (min-width: 960px) {\r\n .address {\r\n font-size: 2.7rem;\r\n }\r\n }\r\n \r\n /* ボタンやアドレスの色-はヘッダーと共通なのでヘッダーにある */\r\n .address__tel,.address__mail {\r\n color: #00ff8a;\r\n }\r\n /* address */\r\n \r\n /* Social-buttonのWEBfontの共通CSSはheaderにある */\r\n \r\n .social-btn {\r\n display: inline; \r\n line-height: .9;/* Social-buttonとアドレスの間の隙間 */\r\n text-shadow: .1rem .1rem .2rem rgba(0,0,0,.9);\r\n }\r\n /* /Social-button */\r\n \r\n /* gototop-footer */\r\n [id=\"gototop\"] i,[id=\"gototop\"] a:visited {\r\n font-size: 7rem!important;\r\n text-shadow: .1rem .1rem .2rem rgba(0,0,0,.9);\r\n color: #00bbff;\r\n }\r\n \r\n @media (min-width: 960px) {\r\n [id=\"gototop\"] {\r\n width: 9rem;\r\n margin: auto;\r\n }\r\n }\r\n \r\n [id=\"gototop\"] i,[id=\"gototop\"] a:visited {\r\n font-size: 7rem!important;\r\n text-shadow: .1rem .1rem .2rem rgba(0,0,0,.9);\r\n color: #00bbff;\r\n }\r\n \r\n @media (min-width: 960px) {\r\n [id=\"gototop\"] i,[id=\"gototop\"] a:visited {\r\n font-size: 9rem!important;\r\n text-shadow: .1rem .1rem .2rem rgba(0,0,0,.9);\r\n }\r\n }\r\n \r\n \r\n \r\n \r\n /* 左から出てくるdrawer-menu */\r\n [id=\"drawermenu\"] {\r\n z-index: 300;\r\n width: 100%;\r\n height: 100%;\r\n position: fixed;\r\n top: 0;\r\n overflow-y: hidden;\r\n padding-top: 0rem;\r\n text-align: center;\r\n cursor: pointer;\r\n margin-left: -100%;\r\n transition-propety:all;\r\n transition-duration:1s;\r\n }\r\n \r\n @media (min-width: 960px) {\r\n [id=\"drawermenu\"] {\r\n padding-top: 2.8rem;\r\n } \r\n }\r\n \r\n [id=\"drawermenu\"] ul {\r\n overflow-y: scroll;\r\n overflow-x: scroll;\r\n width: 105%;/* 横のスクロールバーをはみ出して、上記のhiddenで隠す */\r\n height: 101%;/* 下のスクロールバー */\r\n }\r\n \r\n [id=\"drawermenu\"] li {\r\n margin-bottom: 0.2rem;\r\n background: rgba( 229, 228, 255, 0.3 ); \r\n }\r\n \r\n [id=\"drawermenu\"] li a {\r\n height: 6rem;\r\n line-height: 6rem;\r\n margin: 0 auto;\r\n color: #fff;\r\n font-size: 2rem;\r\n text-decoration: none;\r\n text-shadow: 1px 1px 1px rgba(0,0,0,.9);\r\n }\r\n \r\n @media (min-width: 960px) {\r\n [id=\"drawermenu\"] li a {\r\n font-size: 2.5rem;\r\n }\r\n }\r\n \r\n .link-block {\r\n display: block;\r\n z-index: 99999;\r\n }\r\n \r\n /* .modal-button-wrap__buttonをクリックした際に加えられる */\r\n .showMenue {\r\n margin-left: 0%;\r\n }\r\n /* /.modal-button-wrap__buttonをクリックした際に加えられる */\r\n /* 左から出てくるdrawer-menu */\r\n \r\n /* modalwindow-button-white-threeborder */\r\n /*モーダルウィンドウのボタンの囲い*/\r\n .modal-button-wrap {\r\n position: fixed;\r\n top: 2%;\r\n right: 3%;\r\n z-index: 9999;\r\n }\r\n \r\n @media (min-width: 960px) {\r\n .modal-button-wrap {\r\n top: 5%;\r\n right: 5%;\r\n } \r\n }\r\n \r\n /*モーダルウィンドウのボタン*/\r\n /* shadow */\r\n .modal-button-wrap__border {\r\n box-shadow: 0 0.2rem 0.2rem rgba(0,0,0,.9);\r\n }\r\n /* /shadow */\r\n \r\n .modal-button-wrap__button,\r\n .modal-button-wrap__button span,.overlay-haikeikurokari {\r\n display: inline-block;\r\n transition: all .4s;\r\n box-sizing: border-box;\r\n }\r\n \r\n /*button-size*/\r\n .modal-button-wrap__button,.overlay-haikeikurokari {\r\n position: relative;\r\n width: 5rem;\r\n height: 4.4rem;\r\n }\r\n /* /button-size */\r\n \r\n .modal-button-wrap__button span,.overlay-haikeikurokari span {\r\n position: absolute;\r\n left: 0;\r\n width: 100%;\r\n height: 4px;\r\n background-color: #fff;\r\n border-radius: 4px;\r\n }\r\n \r\n /* threewhiteline */\r\n .modal-button-wrap__button span:nth-of-type(1) {\r\n top: 0;\r\n }\r\n .modal-button-wrap__button span:nth-of-type(2) {\r\n top: 20px;\r\n }\r\n .modal-button-wrap__button span:nth-of-type(3) {\r\n bottom: 0;\r\n }\r\n /* /threewhiteline */\r\n \r\n /*drawermenuのボタンのアニメーション*/\r\n .modal-button-wrap__button.active span:nth-of-type(1) {\r\n -webkit-transform: translateY(20px) rotate(-315deg);\r\n transform: translateY(20px) rotate(-315deg);\r\n }\r\n \r\n .modal-button-wrap__button.active span:nth-of-type(2) {\r\n opacity: 0;\r\n }\r\n \r\n .modal-button-wrap__button.active span:nth-of-type(3) {\r\n -webkit-transform: translateY(-20px) rotate(315deg);\r\n transform: translateY(-20px) rotate(315deg);\r\n }\r\n \r\n /* drawermenu-overlay-半透明のグレーバック */\r\n /* lightbox-overlay-半透明のグレーバックは別のcss(.overlay) */ \r\n .overlay-haikeikurokari {\r\n z-index: 100;\r\n display:none;\r\n position:fixed;\r\n top:0;\r\n left:0;\r\n width:100%;\r\n height:100%;\r\n background-color:rgba(0,0,0,.4);\r\n transition: all 3.3s;\r\n }\r\n \r\n .drawermenu__social-btn {\r\n font-size: 6.5rem!important; \r\n }\r\n \r\n .drawermenu__material-icons {\r\n font-size: 7rem; \r\n }\r\n \r\n .material-icons_large {\r\n font-size: 8rem;\r\n line-height: 0.75;\r\n }\r\n /* /drawermenu */\r\n \r\n /*Reset Stylesheet*/\r\n /* \r\n html5doctor.com Reset Stylesheet\r\n v1.6.1\r\n Last Updated: 2010-09-17\r\n Author: Richard Clark - http://richclarkdesign.com \r\n Twitter: @rich_clark\r\n */\r\n \r\n html, body, div, span, object, iframe,\r\n h1, h2, h3, h4, h5, h6, p, blockquote, pre,\r\n abbr, address, cite, code,\r\n del, dfn, em, img, ins, kbd, q, samp,\r\n small, strong, sub, sup, var,\r\n b, i,\r\n dl, dt, dd, ol, ul, li,\r\n fieldset, form, label, legend,\r\n table, caption, tbody, tfoot, thead, tr, th, td,\r\n article, aside, canvas, details, figcaption, figure, \r\n footer, header, hgroup, menu, nav, section, summary,\r\n time, mark, audio, video {\r\n margin:0;\r\n padding:0;\r\n border:0;\r\n outline:0;\r\n font-size:100%;\r\n vertical-align:baseline;\r\n background:transparent;\r\n }\r\n \r\n body {\r\n line-height:1;\r\n }\r\n \r\n article,aside,details,figcaption,figure,\r\n footer,header,hgroup,menu,nav,section { \r\n display:block;\r\n }\r\n \r\n ul {\r\n list-style:none;\r\n }\r\n \r\n blockquote, q {\r\n quotes:none;\r\n }\r\n \r\n blockquote:before, blockquote:after,\r\n q:before, q:after {\r\n content:'';\r\n content:none;\r\n }\r\n \r\n a {\r\n margin:0;\r\n padding:0;\r\n font-size:100%;\r\n vertical-align:baseline;\r\n background:transparent;\r\n text-decoration: none;\r\n }\r\n \r\n /* change colours to suit your needs */\r\n ins {\r\n background-color:#ff9;\r\n color:#000;\r\n text-decoration:none;\r\n }\r\n \r\n /* change colours to suit your needs */\r\n mark {\r\n background-color:#ff9;\r\n color:#000; \r\n font-style:italic;\r\n font-weight:bold;\r\n }\r\n \r\n del {\r\n text-decoration: line-through;\r\n }\r\n \r\n abbr[title], dfn[title] {\r\n border-bottom:1px dotted;\r\n cursor:help;\r\n }\r\n \r\n table {\r\n border-collapse:collapse;\r\n border-spacing:0;\r\n }\r\n \r\n /* change border colour to suit your needs */\r\n hr {\r\n display:block;\r\n height:1px;\r\n border:0; \r\n border-top:1px solid #cccccc;\r\n margin:1em 0;\r\n padding:0;\r\n }\r\n \r\n input, select {\r\n vertical-align:middle;\r\n }\n```\n\n```\n\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js\"></script>\r\n <div class=\"wrap-skew1 first-section-skew1\">\r\n <div class=\"wrap-skew2 first-section-skew2\">\r\n <div class=\"wrap-content\"> \r\n <section class=\"section-wrap multicolumn\">\r\n <div class=\"content-wrap translate3d-to-upper-left\">\r\n <h2 id=\"js-about-me\" class=\"heading-primary\">ABOUT ME</h2>\r\n <p class=\"paragraph-oneline\">あああああああああああああああああああああああああああああああああああ</p>\r\n <p>いいいいいいいいいいいいいいいいいいいいいいいいいい。</p>\r\n </div><!-- /.contents-wrap -->\r\n <div class=\"img-wrap translate3d-lower-right\">\r\n <img class=\"my-image\" src=\"img/index/myimage.png\" alt=\"自身の写真\">\r\n </div>\r\n </section><!-- /#about -->\r\n </div>\r\n </div>\r\n </div>\r\n \r\n \r\n \r\n \r\n <!-- drawermenu -->\r\n <nav>\r\n <div id=\"drawermenu\">\r\n <ul>\r\n <li class=\"link-block\">\r\n <a class='header__social-btn drawermenu__social-btn symbol animation-hover action-hover' href=\"https://plus.google.com/share?url=\" onclick=\"window.open(this.href, 'Gwindow', 'width=650, height=450, menubar=no, toolbar=no, scrollbars=yes'); return false;\" title=''></a>\r\n \r\n <a class='header__social-btn drawermenu__social-btn symbol animation-hover action-hover' href=\"http://www.facebook.com/share.php?u=\" onclick=\"window.open(this.href, 'FBwindow', 'width=650, height=450, menubar=no, toolbar=no, scrollbars=yes'); return false;\" title=''></a>\r\n \r\n <a class='header__social-btn drawermenu__social-btn symbol animation-hover action-hover' href=\"http://twitter.com/share?url=\" title=''></a> \r\n </li>\r\n <li><a class=\"link-block action-hover animation-hover\" href=\"#js-about-me\">ABOUTME</a></li>\r\n <li><a class=\"link-block action-hover animation-hover\" href=\"#js-gallary\">GALLARY</a></li>\r\n <li><a class=\"link-block action-hover animation-hover\" href=\"#js-gmap\">MAP</a></li>\r\n <li><a class=\"link-block action-hover animation-hover\" href=\"#js-inquiry\">CONTACT</a></li>\r\n <li id=\"js-drwar-action\"><a class=\"link-block drawermenu__gototop action-hover animation-hover\" href=\"#top\"><i class=\"material-icons material-icons_large action-hover animation-hover\"></i></a></li>\r\n <li><a class=\"link-block action-hover animation-hover\" href=\"\">TOPPAGE</a></li>\r\n <li><a class=\"link-block action-hover animation-hover\" href=\"\">BLOG</a></li>\r\n </ul>\r\n </div>\r\n </nav>\r\n <!-- /drawermenu -->\r\n \r\n \r\n \r\n <!-- drawermenu-button -->\r\n <div class=\"modal-button-wrap\">\r\n <a class=\"animation-hover action-hover modal-button-wrap__button kuruttosuru\">\r\n <span class=\"modal-button-wrap__border\"></span><!-- border -->\r\n <span class=\"modal-button-wrap__border\"></span><!-- border -->\r\n <span class=\"modal-button-wrap__border\"></span><!-- border -->\r\n </a>\r\n </div>\n```\n\nまた、BEMのclass名は「Block_key_value」で表します。とあるのですが、 \nkeyがvalue=色が赤=color_redということでしょうか? \n主語と目的語ということでしょうか? \nよくわかりません。\n\n<https://app.codegrid.net/entry/bem-basic-1>",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2016-03-19T07:43:12.830",
"favorite_count": 0,
"id": "23273",
"last_activity_date": "2019-12-13T19:28:55.703",
"last_edit_date": "2019-12-13T19:28:55.703",
"last_editor_user_id": "32986",
"owner_user_id": "14320",
"post_type": "question",
"score": 0,
"tags": [
"css"
],
"title": "BEMでのクラス名のつけ方を確認して頂きたいのですが、下記でクラス名のつけ方全般に問題はないでしょうか?",
"view_count": 1588
} | [
{
"body": "コメントする前にサンプルコードを修正しておきますね。\n\n```\n\n <div class=\"wrap-skew1 first-section-skew1\">\n <div class=\"wrap-skew2 first-section-skew2\">\n <div class=\"wrap-inner\">\n <section class=\"section multicolumn\">\n <div class=\"content-wrap translate3d-to-upper-left\">\n <h2 id=\"js-about-me\" class=\"heading-primary\">ABOUT ME</h2>\n <p class=\"paragraph-oneline\">あああああああああああああああああああああああああああああああああああ</p>\n <p>いいいいいいいいいいいいいいいいいいいいいいいいいい。</p>\n </div>\n <div class=\"img-wrap translate3d-lower-right\">\n <img class=\"my-image\" src=\"img/index/myimage.png\" alt=\"自身の写真\">\n </div>\n </section>\n </div>\n </div>\n </div>\n \n```\n\nサンプルコードがOOCSS(後述)ぽく見えるので、BEMについて誤解があるように感じられたので補足します。\n\nまず、BEMは「Block(親要素)」「Element(子要素)」「Modifier(状態)」の頭文字を取った記法のことです。class名はBlockとElementとの間は__で繋げ、Modifierは\n--で繋げます。\n\nなのでclass名は`.親要素__子要素__孫要素__…`と続いていきます。どこかの要素が少し変わる場合は`.親要素--\n状態変化__子要素`という書き方になります。\n\nなお、このModifierについて、提示されたURLでは_で繋げて表記されていますが、一般的には--で繋げて、長くなる場合は_で区切ります。\n\n例えば「エラーを表示するボックス」はボックスを使い回すために`.box`とでもしておきましょう。エラーであるを主張したいので`.box--\nerror`にします。あとは中にある要素次第ですが、アイコンがあるのであれば`.box--error__icon`\n\nついで言えばModifierは必ずしもBlockにつける必要はないので`.box__icon--cat_…`のようにElementにつけることができます。\n\n> また、BEMのclass名は「Block_key_value」で表します。とあるのですが、 \n> keyがvalue=色が赤=color_redということでしょうか?\n\nその認識で間違いではありませんが、red自体が赤い色を示しているのでcolor_redは少し冗長的に感じます。強いて言うなら_redでしょうか。先の説明で書き換えるなら\n--redかなと。\n\nだんだん書いてて説明が面倒になってきたので「[BEMという命名規則とSass\n3.3の新しい記法](http://blog.ruedap.com/2013/10/29/block-element-\nmodifier)」も参考にすると理解が進むと思います。\n\n(ここから先は少し自己流が混ざっているのと、先のコードを読むのが大変なのである程度無視して解説しています。)\n\nそれを踏まえた上で内側の要素を整理すると、\n\n```\n\n <section class=\"profile\">\n <h2 class=\"profile__title\">ABOUT ME</h2>\n <p class=\"profile__paragraph--lead\">「あ」が並ぶ段落</p>\n <p class=\"profile__paragraph\">「い」が並ぶ段落</p>\n <img class=\"profile__image\">\n </section>\n \n```\n\nこのようになります。ただ、これだと少し.profile__paragraphが冗長的なので、\n\n```\n\n <section class=\"profile\">\n <h2 class=\"profile__title\">ABOUT ME</h2>\n <p class=\"profile__lead\">「あ」が並ぶ段落</p>\n <p>「い」が並ぶ段落</p>\n <img class=\"profile__image\">\n </section>\n \n```\n\nという書き方もできます。人によるところがあるので好みでいいでしょう。\n\nそして、外側に装飾があるようなので使いまわせることを前提で書き換えると、\n\n```\n\n <div class=\"frame\">\n <div class=\"frame__inframe\">\n <div class=\"frame__inframe__content\">\n </div>\n </div>\n </div>\n \n```\n\nこうでしょうか。ちょっといいclass名が思いつきませんでしたが概ねこんな感じでしょう。\n\n合わせると、\n\n```\n\n <div class=\"frame\">\n <div class=\"frame__inframe\">\n <div class=\"frame__inframe__content\">\n <section class=\"profile\">\n <h2 class=\"profile__title\">ABOUT ME</h2>\n <p class=\"profile__lead\">「あ」が並ぶ段落</p>\n <p>「い」が並ぶ段落</p>\n <img class=\"profile__image\">\n </section>\n </div>\n </div>\n </div>\n \n```\n\nこんな感じ。\n\nただ、投稿主が望むCSSの書き方がよくわからないので「[OOCSSとSass](http://takazudo.github.io/blog/entry/2012-12-10-oocsssass.html)」や「[SMACSS\n読んだ \n](http://chroma.hatenablog.com/entry/2013/07/22/120818)」の2つを読んでみることをおすすめします。その上で己が目指すCSSを書くと良いでしょう。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T11:21:34.880",
"id": "23277",
"last_activity_date": "2016-03-19T11:21:34.880",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4960",
"parent_id": "23273",
"post_type": "answer",
"score": 1
},
{
"body": "前半何言ってるのかよくわからないので後半だけコメントしますね。\n\n> frameというクラス名を採用されていますが、wrapよりそちらの方が現場では多いのですか?\n\n特に意味はありません。つけるとしたらwrapやwrapperが多いですが、制作するところによるでしょう。\n\n> `<section class=\"profile\">` とされていますが、\n> sectionタグは絶対に章節に使われるので、下記で常に良いと考えられないのでしょうか?\n\nsectionはマークアップするためのタグとしてHTML5で登場しました。レイアウトするタグとしてsectionではなくdivを推奨されますが、レイアウト目的でなければ問題ありません。\n\nあとその.section作る意味がわからないです。意味的には同じかと。\n\n> またなぜprofileというクラス名を使われているのでしょうか?\n\n.profileは内側のスタイリングです。もし.frameに記事を入れたい場合は代わりに.articleで括れば可読性が上がります。\n\n.profileの命名について言っているのであれば、h2タグに「ABOUT ME」があったから連想しただけです。\n\nもし、BEM特有のclassの冗長化が気になるようであればわざわざBEMで書かずOOCSSで書くべきだと思われます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T06:05:12.037",
"id": "23293",
"last_activity_date": "2016-03-20T06:05:12.037",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4960",
"parent_id": "23273",
"post_type": "answer",
"score": 1
}
]
| 23273 | 23277 | 23277 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "swift2で日記アプリを作っています。\n\nアプリにApp ExtensionsのShare Extensionを追加したのですが、勘違いしていてやりたいことと違ったので削除したいです。\n\nこの場合、Targetのところと、追加されたフォルダを普通に削除するだけで良いのでしょうか。 \n何か他の部分で削除しないといけないものや、何かの設定を戻す等の操作が必要でしたら教えていただきたいです。\n\nよろしくお願いします。\n\n補足 \n他の質問サービスでも質問させていただきましたが、解決できなかったので質問させていただきます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T10:15:39.240",
"favorite_count": 0,
"id": "23274",
"last_activity_date": "2016-04-19T04:02:12.680",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10791",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"xcode"
],
"title": "shareExtensionの削除の仕方",
"view_count": 105
} | [
{
"body": "他サイトで教えていただき解決しました。 \n普通に消すだけで問題ありませんでした。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T03:06:47.150",
"id": "23289",
"last_activity_date": "2016-03-20T03:06:47.150",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10791",
"parent_id": "23274",
"post_type": "answer",
"score": 1
}
]
| 23274 | null | 23289 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "まず以下のようにして、 \nベクトルxとベクトルyの角度を計算する関数を書きます。\n\n```\n\n import numpy as np\n \n def angle(x, y):\n \n dot_xy = np.dot(x, y)\n norm_x = np.linalg.norm(x)\n norm_y = np.linalg.norm(y)\n cos = dot_xy / (norm_x*norm_y)\n rad = np.arccos(cos)\n theta = rad * 180 / np.pi\n \n return theta\n \n```\n\n次にこの関数を用いて、 \n以下のベクトルxとベクトルyの角度を計算します。\n\n```\n\n x = np.array([1, 0, 1])\n y = np.array([1, 1, 1])\n print angle(x, y)\n \n```\n\nこの結果はもちろん、45.0となります。\n\nここで、上記のベクトルxと以下のベクトルzの角度を計算します。\n\n```\n\n z = np.array([1, -1, 1])\n print angle(x, z)\n \n```\n\nこの場合ももちろん、上記と同じ角度である45.0が出力されます。\n\nしかしここで、 \nxとyで計算した時を「正の方向」とした上で、 \nxとzの角度は45.0ではなく、315.0と出力したいです。\n\nnumpyではどのようにすれば、 \nベクトルの向きを固定して角度を計算することができるでしょうか?\n\nよろしくお願いします。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T10:25:29.407",
"favorite_count": 0,
"id": "23275",
"last_activity_date": "2016-04-18T13:46:17.893",
"last_edit_date": "2016-03-19T11:12:06.470",
"last_editor_user_id": "12874",
"owner_user_id": "12874",
"post_type": "question",
"score": 3,
"tags": [
"python",
"numpy"
],
"title": "numpyでベクトルの向きを考慮して2つのベクトル間の角度を計算したい",
"view_count": 11307
} | [
{
"body": "コメントを頂いた通り、符号の判定で解決できる問題でした。 \nお手数をおかけしました。ありがとうございます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T11:14:40.157",
"id": "23276",
"last_activity_date": "2016-03-19T11:14:40.157",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12874",
"parent_id": "23275",
"post_type": "answer",
"score": 2
}
]
| 23275 | null | 23276 |
{
"accepted_answer_id": "23287",
"answer_count": 2,
"body": "PythonでのPyMySQLに関してですが、テーブルからユーザー名を取得する関数を作ったのですが、そのユーザーをmysqlから消しても、関数が返す値が同じです。何がいけないのでしょうか?\n\n以下が作った関数です\n\n```\n\n import sys\n import time\n import pymysql\n \n conn = pymysql.connect(host='localhost',\n user='user',\n password='password',\n db='database',\n charset='utf8')\n \n def get_user():\n cursor = conn.cursor()\n query = \"\"\"SELECT username FROM users WHERE username=testuser\"\"\"\n cursor.execute(query)\n result = cursor.fetchone()[0]\n cursor.close()\n return result\n \n \n def worker():\n try:\n while True:\n time.sleep(1)\n print(get_user())\n except KeyboardInterrupt:\n print(\"Stopeed\")\n \n \n if __name__ == '__main__':\n worker()\n \n```\n\ntestuserを消した後、get_user()を実行すると、テーブルには存在しないのに返ってきてます。なぜでしょうか?\n\nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T12:07:57.310",
"favorite_count": 0,
"id": "23278",
"last_activity_date": "2016-03-22T23:34:42.080",
"last_edit_date": "2016-03-21T10:29:20.943",
"last_editor_user_id": "3054",
"owner_user_id": "14857",
"post_type": "question",
"score": 5,
"tags": [
"python",
"mysql"
],
"title": "PyMySQLでの問合せ結果がテーブルデータ変更後も変化しない",
"view_count": 2234
} | [
{
"body": "コードを一目で見ると、一つの問題は`'`のマークのことにあると思います。特に、この行:\n\n```\n\n >>> testuser = \"me\"\n >>> query = 'SELECT username FROM users WHERE username='testuser''\n \n```\n\nこの関数を実行すると、`SyntaxError`が発生するでしょう。例えば:\n\n```\n\n >>> query = 'SELECT username FROM users WHERE username='testuser''\n File \"<stdin>\", line 1\n query = 'SELECT username FROM users WHERE username='testuser''\n ^\n SyntaxError: invalid syntax\n \n```\n\nそしたら、`SELECT`の`query`が正確に実行されていないと思いますので、他に問題が発生する可能性もあると思います。\n\nそのために、下記の方はどうですか。\n\n```\n\n query = \"\"\"SELECT username FROM users WHERE username='%s'\"\"\", (testuser)\n \n```\n\n出力の例:\n\n```\n\n >>> testuser = \"me\"\n >>> query = \"\"\"SELECT username FROM users WHERE username='%s'\"\"\", (testuser)\n >>> query\n (\"SELECT username FROM users WHERE username='%s'\", 'me')\n \n```\n\n* * *\n\n### 更新\n\nもっと調べてみると、これは「キャッシュ」のことにつながっている問題ではないでしょうか。特に、「`autocommit`」という設定に[関係があるかもしれません](https://github.com/PyMySQL/PyMySQL/issues/76)。しかし、[suzukis](https://ja.stackoverflow.com/users/5793/suzukis)さんの回答のように、`commit`のことはやはり[`MySQL\nQuery Cache`](http://dev.mysql.com/doc/refman/5.6/ja/query-\ncache.html)に関係がないようですが。\n\nそれにしても、下記のメソードを呼び出すと、「キャッシュっぽい効果」を避けることが出来るようです。\n\n`conn.autocommit(True)`\n\n[このスレでは、martaaayさんの説明](https://github.com/PyMySQL/PyMySQL/issues/76#issuecomment-10236696)のように、`autocommit(False)`という設定は最新のチェンジを無視して、次の`commit`を実行する前に、前のデータを使用する状態になってしまうのです。他方では、`autocommit(True)`という設定は自動的に最新のトランザクションを`commit`して、これからは最新の`commit`されたデータを使用することが出来ます。\n\n将来の参照のために、`autocommit`のこと自体については[suzukisさんの説明](https://ja.stackoverflow.com/a/23328/4129)と共に、MySQLのトランザクションについての[リファレンス](http://dev.mysql.com/doc/refman/5.6/ja/commit.html)もあると思います。トランザクションということ自体は大切な概念で、特に[ACID](https://ja.wikipedia.org/wiki/ACID_\\(%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF%E7%A7%91%E5%AD%A6\\))には[役に立ちます](https://stackoverflow.com/a/3740307)。",
"comment_count": 13,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T00:51:47.393",
"id": "23287",
"last_activity_date": "2016-03-22T17:26:05.550",
"last_edit_date": "2017-05-23T12:38:56.467",
"last_editor_user_id": "-1",
"owner_user_id": "4129",
"parent_id": "23278",
"post_type": "answer",
"score": 1
},
{
"body": "autocommitを有効にしたら期待したとおりの動作になったということで、それはトランザクションによるものです。\n\nトランザクションというのはデータベースにおける一連の処理の塊のことで、「コミット」という操作をすることでDBに反映が永続化されます。また、「ロールバック」という操作で処理を取り消すことも出来ます。\n\nautocommit(自動コミット)が無効の場合、明示的にcommitないしはrollbackするまではトランザクションの内部にいることになります。ここで、他のトランザクションによりDBが変更されたとしても、その変更を読み取ることは出来ません。(細かいことを言うとトランザクション分離レベルにもよる)\n\nautocommitを有効にすると、1つクエリを発行した時点でトランザクションが完結します。他のトランザクションによる変更後に発行されたクエリではその変更を読み取ることが出来ます。\n\nキャッシュとは全く違う概念です。\n\nデータベース理論の入門的な内容ですがデータベースのACID特性について学んでもらえば、これがデータベースの信頼性に関わる根本的な部分に関連していて、キャッシュとは全く違うものであることが理解できると思います。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T00:53:37.353",
"id": "23328",
"last_activity_date": "2016-03-22T23:34:42.080",
"last_edit_date": "2016-03-22T23:34:42.080",
"last_editor_user_id": "5793",
"owner_user_id": "5793",
"parent_id": "23278",
"post_type": "answer",
"score": 3
}
]
| 23278 | 23287 | 23328 |
{
"accepted_answer_id": "23283",
"answer_count": 2,
"body": "```\n\n ary1 = [[2, 5, 9], [5, 5, 6], [2, 6, 8], [2, 5, 7]]\n ary2 = [[2, 9, 5], [5, 6, 5], [8, 6, 2], [7, 2, 5]]\n \n # 最大値の小さい順\n p ary1.sort{|a, b| a.max <=> b.max}\n p ary2.sort{|a, b| a.max <=> b.max}\n p ''\n # 最大値の大きい順\n p ary1.sort{|a, b| b.max <=> a.max}\n p ary2.sort{|a, b| b.max <=> a.max}\n p ''\n # 最小値の小さい順\n p ary1.sort{|a, b| a.min <=> b.min}\n p ary2.sort{|a, b| a.min <=> b.min}\n p ''\n # 最小値の大きい順\n p ary1.sort{|a, b| b.min <=> a.min}\n p ary2.sort{|a, b| b.min <=> a.min}\n \n```\n\n出力結果 \n[[5, 5, 6], [2, 5, 7], [2, 6, 8], [2, 5, 9]] \n[[5, 6, 5], [7, 2, 5], [8, 6, 2], [2, 9, 5]] \n\"\" \n[[2, 5, 9], [2, 6, 8], [2, 5, 7], [5, 5, 6]] \n[[2, 9, 5], [8, 6, 2], [7, 2, 5], [5, 6, 5]] \n\"\" \n[[2, 5, 9], [2, 5, 7], [2, 6, 8], [5, 5, 6]] \n[[2, 9, 5], [7, 2, 5], [8, 6, 2], [5, 6, 5]] \n\"\" \n[[5, 5, 6], [2, 6, 8], [2, 5, 9], [2, 5, 7]] \n[[5, 6, 5], [8, 6, 2], [2, 9, 5], [7, 2, 5]]\n\n四つ目が(たまたまかもしれませんが)[2, 6, 8], [2, 5, 9], [2, 5, 7]の順となっているのに、 \n三つめが[2, 5, 9], [2, 5, 7], [2, 6, 8]の順となっています。\n\nそこで質問なのですが、 \nブロックの部分を \na.min <=> b.min \nから \nb.min <=> a.min \nと逆にしても得られる結果は \nちょうど逆の並びにならない理由を教えてください。 \nまた、三つめの例で \n**最小値が同じ場合は、次に小さいもの同士を比べ、小さい順に並べ \nさらに同じ場合は、その次に小さいもの同士を比べ、小さい順に並べる** \nようにするにはどうすればいいですか?\n\n(追記) \n三つめの例を \n**最小値が同じ場合は、次に小さいもの同士を比べ、小さい順に並べ \nさらに同じ場合は、その次に小さいもの同士を比べ、小さい順に並べる** \nようにする簡単な方法はあるようですが、 \n一つ目の例を \n**最大値が同じ場合は、次に大きいもの同士を比べ、小さい順に並べ \nさらに同じ場合は、その次に大きいもの同士を比べ、小さい順に並べる** \nまた二つ目の例を \n**最大値が同じ場合は、次に大きいもの同士を比べ、大きい順に並べ \nさらに同じ場合は、その次に大きいもの同士を比べ、大きい順に並べる** \nさらに四つ目の例を \n**最小値が同じ場合は、次に小さいもの同士を比べ、大きい順に並べ \nさらに同じ場合は、その次に小さいもの同士を比べ、大きい順に並べる** \nようにする簡単な方法はあるのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T13:50:57.350",
"favorite_count": 0,
"id": "23279",
"last_activity_date": "2016-03-20T15:49:56.267",
"last_edit_date": "2016-03-19T17:33:35.300",
"last_editor_user_id": "5363",
"owner_user_id": "5363",
"post_type": "question",
"score": 1,
"tags": [
"ruby"
],
"title": "配列を最大値の小さい順、大きい順や最小値の小さい順、大きい順に並べ変えたときの結果について",
"view_count": 971
} | [
{
"body": "_ちょうど逆の並びにならない理由を教えてください。_ \nsortに用いられるアルゴリズムによってはキーに用いる値が同点と判定された場合の結果の並びが元の順序からは容易に判定できないものがあります。 \n(Wikipediaの[ソート](https://ja.wikipedia.org/wiki/%E3%82%BD%E3%83%BC%E3%83%88)や[安定ソート](https://ja.wikipedia.org/wiki/%E5%AE%89%E5%AE%9A%E3%82%BD%E3%83%BC%E3%83%88)などを参照してください。) \nrubyのsortメソッドでは、非安定ソートアルゴリズムの代表格であるクイックソートが使われているようですので、キーが同じ場合の結果は不定(正確には「容易には判定できない順序」であって、同じ入力に対しては通常必ず同じ結果になると思われます)となります。\n\nまた、あなたが与えているブロック`a.min <=> b.min`では、キーに使う値が同点であれば(`[2, 6, 8], [2, 5, 9], [2,\n5,\n7]`の場合、キーとして比較に使われる値は全部2)それらはソートアルゴリズム上は区別できませんので、不定(上記の意味)または元の順序を保存、と言うことになり、(たとえクイックソート以外のアルゴリズムでソートしたとしても)逆順にはなりません。\n\n**_最小値が同じ場合は、次に小さいもの同士を比べ、小さい順に並べ \nさらに同じ場合は、その次に小さいもの同士を比べ、小さい順に並べる** \nとするにはどうすればいいですか?_ \n「次に小さいもの」をどう定義するか(同点の値がある場合)にもよりますが、内側の配列の順序を変えても良いなら、「内側の配列を小さいもの順に並び替えて、その結果を(配列の辞書式比較で)さらに並べ替える」なんてことで実現できそうです。\n\n```\n\n ary1.map{|arr|arr.sort}.sort\n => [[2, 5, 7], [2, 5, 9], [2, 6, 8], [5, 5, 6]] \n ary2.map{|arr|arr.sort}.sort\n => [[2, 5, 7], [2, 5, 9], [2, 6, 8], [5, 5, 6]]\n \n```\n\n内側の配列の順序を変更したくないというのであれば、「元の配列と並べ換えに使う値をペアにしてソートした後、『並べ換えに使う値』だけを剥ぎ取ってしまう」と言う形で実装するとこんな感じになりますね。\n\n```\n\n ary1.map{|arr|[arr,arr.sort]}.sort{|p1,p2|p1[1]<=>p2[1]}.map{|p|p[0]}\n => [[2, 5, 7], [2, 5, 9], [2, 6, 8], [5, 5, 6]]\n ary2.map{|arr|[arr,arr.sort]}.sort{|p1,p2|p1[1]<=>p2[1]}.map{|p|p[0]}\n => [[7, 2, 5], [2, 9, 5], [8, 6, 2], [5, 6, 5]] \n \n```\n\n少しわかりにくければ、メソッドチェーンにせずに途中経過を表示させながら試してみてください。\n\n他にもっと良いやり方がありそうですが、一つの例としてお読みください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T14:43:25.757",
"id": "23280",
"last_activity_date": "2016-03-19T14:43:25.757",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "23279",
"post_type": "answer",
"score": 4
},
{
"body": "1つ目の質問はLe Pere d'OOさんの回答のとおりで、2つ目の質問について。\n\n> 最小値が同じ場合は、次に小さいもの同士を比べ、小さい順に並べ \n> さらに同じ場合は、その次に小さいもの同士を比べ、小さい順に並べる\n\n要素をsortした結果を[Array#<=>](http://docs.ruby-\nlang.org/ja/2.3.0/method/Array/i/=3c=3d=3e.html)に丸投げするのが楽かと思います。\n\n```\n\n ary1.sort_by(&:sort)\n # => [[2, 5, 7], [2, 5, 9], [2, 6, 8], [5, 5, 6]] \n ary2.sort_by(&:sort)\n # => [[7, 2, 5], [2, 9, 5], [8, 6, 2], [5, 6, 5]] \n \n```\n\n**追記**\n\n質問の追記分について。いずれも単なる組み合わせです。\n\n> 一つ目の例を \n> 最大値が同じ場合は、次に大きいもの同士を比べ、小さい順に並べ \n> さらに同じ場合は、その次に大きいもの同士を比べ、小さい順に並べる\n\n→要素を降順ソートした値で、昇順ソート\n\n```\n\n ary1.sort_by {|x| x.sort {|a, b| b <=> a} }\n \n```\n\n> また二つ目の例を \n> 最大値が同じ場合は、次に大きいもの同士を比べ、大きい順に並べ \n> さらに同じ場合は、その次に大きいもの同士を比べ、大きい順に並べる\n\n→要素を降順ソートした値で、降順ソート\n\n```\n\n ary1.sort_by {|x| x.sort {|a, b| b <=> a} }.reverse\n \n```\n\n> さらに四つ目の例を \n> 最小値が同じ場合は、次に小さいもの同士を比べ、大きい順に並べ \n> さらに同じ場合は、その次に小さいもの同士を比べ、大きい順に並べる\n\n→要素を昇順ソートした値で、降順ソート\n\n```\n\n ary1.sort_by(&:sort).reverse\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T16:40:17.080",
"id": "23283",
"last_activity_date": "2016-03-20T15:49:56.267",
"last_edit_date": "2016-03-20T15:49:56.267",
"last_editor_user_id": "4010",
"owner_user_id": "4010",
"parent_id": "23279",
"post_type": "answer",
"score": 2
}
]
| 23279 | 23283 | 23280 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "数年前に組んだCのコンパイルが通らなくなってしまい困っています。 \nどうやら、\n\n```\n\n #include \"mbctype.h\"\n #include \"stdafx.h\"\n \n```\n\nのコンパイルが通らないようです。\n\nこちらの2つは使うのに何か条件があるのでしょうか?\n\nよろしくおねがいします。\n\n* * *\n\nコメントによるとエラーメッセージは\n\n```\n\n $ gcc a.c\n a.c:3:10: fatal error: 'mbctype.h' file not found\n #include <mbctype.h>\n ^\n 1 error generated.\n \n```\n\nとのこと。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T16:10:02.883",
"favorite_count": 0,
"id": "23281",
"last_activity_date": "2016-03-21T00:58:33.770",
"last_edit_date": "2016-03-21T00:58:33.770",
"last_editor_user_id": "4236",
"owner_user_id": "8823",
"post_type": "question",
"score": -3,
"tags": [
"c"
],
"title": "\"mbctype.h\", \"stdafx.h\" のコンパイルが通らない",
"view_count": 1754
} | [
{
"body": "> コンパイルが通らない\n\nであれば質問文にエラーメッセージを加えるべきですし、そのエラーメッセージで検索し原因を探るべきです。\n\n以下は質問文から読み取れる問題について言及しますが、真の問題が何であるかはこの回答ではなくエラーメッセージを確認してください。\n\n* * *\n\n[`#include`ディレクティブ](https://msdn.microsoft.com/ja-\njp/library/36k2cdd4\\(v=vs.120\\).aspx)には`引用符形式`と`山かっこ形式`があり意味が異なります。その上で[`<mbctype.h>`は`_mbbtype`関数](https://msdn.microsoft.com/ja-\njp/library/xc8tc6c1\\(v=vs.120\\).aspx)などで使いますがドキュメントにあるように`山かっこ形式`を使用しなければなりません。\n\n`stdafx.h`というファイル名はVisual\nC++においてプリコンパイル済みヘッダーに用いられる既定の名称です。仮にプリコンパイル済みヘッダーに絡む問題によりコンパイルが通らないのであれば正しく構成する必要があります。 \n少なくともプリコンパイル済みヘッダー行`#include \"stdafx.h\"`より前に`#include`ディレクティブなどを記述してはいけません。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T21:02:05.620",
"id": "23285",
"last_activity_date": "2016-03-19T21:02:05.620",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4236",
"parent_id": "23281",
"post_type": "answer",
"score": 2
}
]
| 23281 | null | 23285 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "**実行環境**\n\n```\n\n $ ruby -v\n ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]\n \n $ rails -v\n Rails 4.2.6\n \n```\n\n環境変数を定義する Gem として有名な [config](https://github.com/railsconfig/config) を使用しています\n\n`bundle install` で config をインストールして\n\n```\n\n $ rails g config:install\n create config/initializers/rails_config.rb\n create config/settings.yml\n create config/settings.local.yml\n create config/settings\n create config/settings/development.yml\n create config/settings/production.yml\n create config/settings/test.yml\n append .gitignore\n \n```\n\nを実行し環境変数を書いておく yml ファイルを作成しました \nしかし\n\n```\n\n $ vi config/settings.yml\n twitter:\n follow_target_name: 'mossmoss'\n text: 'mossmossmossmossmoss'\n url : 'http://mossmossmossmossmoss.com/'\n \n```\n\nとして環境変数を取得しようとすると `nil` となっていまいます\n\n```\n\n $ rails c\n > Settings.twitter\n => nil\n > Settings\n => #<Config::Options> \n \n```\n\nドキュメント通りにやったのですがなぜ どこかで環境変数の取得方法が間違っているのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-19T23:00:19.933",
"favorite_count": 0,
"id": "23286",
"last_activity_date": "2016-11-02T17:15:10.667",
"last_edit_date": "2016-03-19T23:06:05.803",
"last_editor_user_id": "5505",
"owner_user_id": "5505",
"post_type": "question",
"score": 2,
"tags": [
"ruby-on-rails"
],
"title": "rails_config の環境変数が反映されない",
"view_count": 3826
} | [
{
"body": "直接の質問の回答ではないのですが、[dotenv](https://github.com/bkeepers/dotenv)というgemもありまして、私はいつもそれを使っているのですが、環境変数をrails内に設定するということであればそちらを使ってもできると思います。 \n`.env`という名前のファイルを使って、シェル変数のように環境変数にしたい情報を設定するだけです。\n\n```\n\n S3_BUCKET=YOURS3BUCKET\n SECRET_KEY=YOURSECRETKEYGOESHERE\n \n```\n\nこの設定が済むと、railsプロジェクトのどこでも(多分)以下のように記述して環境変数を取ってこれるようになると思います。\n\n```\n\n s3 = ENV['S3_BUCKET']\n \n```\n\nconfigをお使いとのことですので、そちらを使うのでも一向に問題ないと思いますが、もしどうしても行き詰まってしまうようなら(そういうことはないでしょうが)、こちらを試してみるのも悪くないと思います。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T22:17:13.623",
"id": "23309",
"last_activity_date": "2016-03-20T22:17:13.623",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9403",
"parent_id": "23286",
"post_type": "answer",
"score": 2
},
{
"body": "spring使ってませんか? (Rails4以降ならデフォルトで使用します) \nconfig/initializers/以下にファイルを追加・変更したあとはbundle exec spring stop しましょう。\n\n```\n\n % bundle exec spring status\n Spring is running:\n \n 71694 spring server | myapp | started 8 secs ago\n 71697 spring app | myapp | started 8 secs ago | development mode\n % vi Gemfile\n % bundle\n % vi config/settings.yml\n % bin/rails c\n Running via Spring preloader in process 72273\n Loading development environment (Rails 4.2.6)\n >> Settings\n => #<Config::Options>\n >> Settings.twitter\n => nil\n >> ^D\n % bundle exec spring stop\n Spring stopped.\n % bin/rails c\n Running via Spring preloader in process 72436\n Loading development environment (Rails 4.2.6)\n >> Settings.twitter\n => #<Config::Options follow_target_name=\"mossmoss\">\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-11-02T07:00:55.383",
"id": "30050",
"last_activity_date": "2016-11-02T17:15:10.667",
"last_edit_date": "2016-11-02T17:15:10.667",
"last_editor_user_id": "17037",
"owner_user_id": "17037",
"parent_id": "23286",
"post_type": "answer",
"score": 1
}
]
| 23286 | null | 23309 |
{
"accepted_answer_id": null,
"answer_count": 3,
"body": "AdMobを導入するためにGoogleMobileAdsフレームワークをプロジェクトに追加しViewControllerに\n\n```\n\n @import GoogleMobileAds;\n \n```\n\nと記述したところ Use of '@import' when modules are disabled というエラーが出てしまいます。\n\n調べてみたところ Enable Modules(C and C-Objective-C) を NO から YES\nにすればエラーが消えると書いてあったので試してみましたがエラーは消えず。\n\n他に考えられる原因は何でしょうか?アドバイスいただけると助かります。",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T02:34:06.417",
"favorite_count": 0,
"id": "23288",
"last_activity_date": "2023-02-27T08:31:16.240",
"last_edit_date": "2016-03-20T04:58:29.960",
"last_editor_user_id": "76",
"owner_user_id": "14860",
"post_type": "question",
"score": 0,
"tags": [
"objective-c",
"admob"
],
"title": "エラー Use of '@import' when modules are disabled",
"view_count": 2453
} | [
{
"body": "Objctive-Cなら、 \n`@import <GoogleMobileAds>`または`@import\n\"GoogleMobileAds\"`なのではないでしょうか?投稿時の記述ミスでしたら済みません。\n\nそれ以外には、左側のファイルインスペクターでプロジェクトを選択、メインビューのビルドセッティングで、Build Phasesをクリック、Link\nBinary With Librariesに該当フレームワークが含まれているか確認してみてください。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T16:34:35.813",
"id": "23305",
"last_activity_date": "2016-03-20T16:34:35.813",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14745",
"parent_id": "23288",
"post_type": "answer",
"score": -1
},
{
"body": "コメントに示したように現在のObjective-C++では、`@import`でのModuleのimportはサポートされていないようです。\n\nframework中から適切な.hファイルを探し出して、旧来の`#import`でimportしてやれば大丈夫のはずです。[こちらの記事](https://stackoverflow.com/questions/28572343/admob-\nsdk-ios-file-not-found)によれば、\n\n```\n\n #import <GoogleMobileAds/GoogleMobileAds.h>\n \n```\n\nでimportできるように書かれています。お試しください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T12:27:32.553",
"id": "23319",
"last_activity_date": "2016-03-21T12:27:32.553",
"last_edit_date": "2017-05-23T12:38:56.467",
"last_editor_user_id": "-1",
"owner_user_id": "13972",
"parent_id": "23288",
"post_type": "answer",
"score": 1
},
{
"body": "こちらより引用: \n[STEP3: SDKの初期化コードを追加する | KARTE Developer\nPortal](https://developers.karte.io/docs/setup-react-native-\nsdk-v2#step3-sdk%E3%81%AE%E5%88%9D%E6%9C%9F%E5%8C%96%E3%82%B3%E3%83%BC%E3%83%89%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B)\n\nAppDelegate クラスが Objective-C++ (.mm) に書かれている場合に `Use of '@import' when C++\nmodules are disabled, consider using -fmodules and -fcxx-modules`\nのエラーが出る場合があります。 \nその場合はアプリケーションの Targets -> Build Settings -> Apple Clang - Custom Compiler\nFlags > Other C++ Flags に -fcxx-modules フラグを追加してビルドすることでエラーを消すことができます。\n\n設定画面については、以下のスクリーンショットを参照してください。\n\n[](https://i.stack.imgur.com/tLFSS.png)",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2023-02-25T10:23:54.297",
"id": "94001",
"last_activity_date": "2023-02-27T08:31:16.240",
"last_edit_date": "2023-02-27T08:31:16.240",
"last_editor_user_id": "3060",
"owner_user_id": "57268",
"parent_id": "23288",
"post_type": "answer",
"score": 0
}
]
| 23288 | null | 23319 |
{
"accepted_answer_id": "23296",
"answer_count": 1,
"body": "# 前提・実現したいこと\n\nrails+capybara(+Poltergeist)でスクレイピングをしようとしています。 \naタグをクリックして次のページに移動する動きしようとしているのですがうまく動きません。\n\n# 発生している問題・エラーメッセージ\n\n```\n\n Failures:\n \n 1) test next20\n Failure/Error: click_on \"次の20件\"\n \n Capybara::ElementNotFound:\n Unable to find link or button \"次の20件\"\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/finders.rb:43:in `block in find'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/base.rb:84:in `synchronize'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/finders.rb:32:in `find'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/actions.rb:13:in `click_link_or_button'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:686:in `block (2 levels) in <class:Session>'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'\n # ./test3.rb:30:in `block (3 levels) in <top (required)>'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:290:in `within'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'\n # ./test3.rb:28:in `block (2 levels) in <top (required)>'\n \n Finished in 7.06 seconds (files took 0.4783 seconds to load)\n 1 example, 1 failure\n \n Failed examples:\n \n```\n\n# ソースコード(test3.rb)\n\n```\n\n require 'capybara/rspec' \n require 'capybara/poltergeist' \n require 'capybara/dsl'\n \n Capybara.javascript_driver = :poltergeist \n Capybara.register_driver :poltergeist do |app| \n Capybara::Poltergeist::Driver.new(app, { \n js_errors: false, \n timeout: 1000, \n debug: true, \n phantomjs_options: [ \n '--load-images=no', \n '--ignore-ssl-errors=yes', \n '--ssl-protocol=any']}) \n end\n \n Capybara.configure do |config| \n config.run_server = false \n config.default_driver = :poltergeist \n config.app_host = 'http://www.mansion-review.jp/prefecture/20.html' \n end\n \n describe \"test\", :type => :feature do \n subject{ page } \n before { visit('/') }\n \n it \"next20\", js: true do \n within ('#saleHistorySoubaBlock') do \n have_text \"次の20件\" \n click_on \"次の20件\" \n end \n end \n end\n \n```\n\n# 補足情報\n\n * capybara (2.6.2)\n * globalid (0.3.6)\n * rails (4.2.6)\n * rspec-rails (3.4.2)\n\n# 追記\n\n広く意見を求めたい為,Stack Overflowとteratailにて同様の質問をしております。 \n解決しましたら、両方にて共有したいと思いますので、ご容赦ください。\n\n* * *\n\nコメントは改行できないのですね、教えていただきありがとうございます。 \nエラーメッセージが若干違うようですので、貼っておきます。\n\n# エラーメッセージ\n\n```\n\n Failures:\n \n 1) test next20\n Failure/Error: click_on \"次の20件\"\n \n Capybara::ElementNotFound:\n Unable to find link or button \"次の20件\"\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/finders.rb:43:in `block in find'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/base.rb:84:in `synchronize'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/finders.rb:32:in `find'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/node/actions.rb:13:in `click_link_or_button'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:686:in `block (2 levels) in <class:Session>'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'\n # ./test3.rb:31:in `block (4 levels) in <top (required)>'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:290:in `within'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'\n # ./test3.rb:29:in `block (3 levels) in <top (required)>'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/session.rb:290:in `within'\n # ~/vendor/bundler/ruby/2.3.0/gems/capybara-2.6.2/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'\n # ./test3.rb:28:in `block (2 levels) in <top (required)>'\n \n Finished in 7.67 seconds (files took 1.44 seconds to load)\n 1 example, 1 failure\n \n Failed examples:\n \n```\n\n# 修正部分\n\n```\n\n describe \"test\", :type => :feature do\n subject{ page }\n before { visit('/') }\n \n it \"next20\", js: true do\n within first('#resultBlock div p') do\n within all('a').last do\n should have_text '次の20件'\n click_on \"次の20件\"\n end\n end\n end\n end\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T03:47:12.763",
"favorite_count": 0,
"id": "23290",
"last_activity_date": "2016-03-22T05:15:12.873",
"last_edit_date": "2016-03-22T04:42:07.757",
"last_editor_user_id": "8000",
"owner_user_id": "14858",
"post_type": "question",
"score": 1,
"tags": [
"ruby-on-rails",
"ruby",
"capybara",
"phantomjs",
"poltergeist"
],
"title": "capybara(+ Poltergeist)でaタグがclick_on出来ない",
"view_count": 2498
} | [
{
"body": "そのページをブラウザで見てみましたが、エラーメッセージの通り、 `#saleHistorySoubaBlock` の中に `次の20件`\nはありません。というか、`#saleHistorySoubaBlock` は空っぽの `<div>` ですね。\n\nそれなら `click_on` じゃなくて `have_text`\nでエラーになりそうですが、これは「対象が指定した文字列を含むかどうかを検査するMatcher」を返すメソッドで、呼びだしただけでは何も起きません。RSpecの\n`should` や `expect(...).to` に渡して初めて実際の検査が行われます。\n\n例えば次のようにすると、`should have_text` の時点でFailureになります。\n\n```\n\n describe \"test\", :type => :feature do \n subject{ page } \n before { visit('/') }\n \n it \"next20\", js: true do \n within ('#saleHistorySoubaBlock') do \n should have_text \"次の20件\" \n click_on \"次の20件\" \n end \n end \n end\n \n```\n\n* * *\n\n例えば `<a id=\"hoge\">link text</a>` というリンクがあり、ここで `within('#hoge')` とすると、\n\n * `should have_text 'link text'`: **そのリンクの中に** `link text` という文字列を含む \n⇒ OK\n\n * `click_on 'link text'`: **そのリンクの中で** `link text` と書かれたリンク・ボタンをクリック \n⇒ `<a id=\"hoge\">link text</a>` の中にリンク・ボタンは存在しないのでエラー\n\nとなります。それ自身をクリックするという意味にはなりません。\n\nwithinで選択した要素自体をクリックする方法はちょっとわからなかったので、have_textも省略してこんな感じでいかがでしょう。\n\n```\n\n describe \"test\", :type => :feature do \n subject{ page } \n before { visit('/') }\n \n it \"next20\", js: true do \n within ('#resultBlock div p') do \n first(:link, \"次の20件\").click\n # あるいは\n # click_on \"次の20件\", :match => :first\n end \n end \n end\n \n```\n\n一応firstと指定していますが、capybara2.6.2で試す限りでは単にclick_onとだけ書いても最初にマッチしたものをクリックしてくれるようですね。\n\n参考\n\n * [Capybaraでクリックできない場合の対処法 - harublog](http://hrt0kmt.hatenablog.com/entry/2015/11/17/210904)\n * [How to click first link in list of items after upgrading to Capybara 2.0? - Stack Overflow](https://stackoverflow.com/questions/14513377/how-to-click-first-link-in-list-of-items-after-upgrading-to-capybara-2-0)",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T07:47:03.470",
"id": "23296",
"last_activity_date": "2016-03-22T05:15:12.873",
"last_edit_date": "2017-05-23T12:38:55.250",
"last_editor_user_id": "-1",
"owner_user_id": "8000",
"parent_id": "23290",
"post_type": "answer",
"score": 1
}
]
| 23290 | 23296 | 23296 |
{
"accepted_answer_id": "23362",
"answer_count": 3,
"body": "下記のソースコードは、marqueeで動いている文字の方向に応じて、その『方向指示ボタン』の \n矢印を\"赤\"に,反対側の矢印を\"白\"になるように設定したものです。 \nこの動いている方向の矢印を\"赤\"で示すのでなく、\"点滅\"で示すようにするには、どのように \n書き換えればいいでしょうか。ご教示ください。\n\n```\n\n <SCRIPT>\n \n function marLeft(){\n document.getElementById(\"blinkL\").style.color=\"red\";\n document.getElementById(\"blinkR\").style.color=\"white\";\n }\n function marRight(){\n document.getElementById(\"blinkR\").style.color=\"red\";\n document.getElementById(\"blinkL\").style.color=\"white\";\n }\n \n \n flg=false;\n function Stop_Start(){\n flg = !flg;\n document.myForm.stopStart.value=flg?\"START\":\"STOP\";\n if(flg) {\n document.getElementById(\"myMarquee\").stop();\n } else {\n document.getElementById(\"myMarquee\").start();\n }\n }\n </script>\n \n \n <marquee id=\"myMarquee\">TTTTT</marquee>\n <br><br>\n <form id=\"marFunction\" name=\"myForm\" style=\"text-align:center;\">\n <INPUT id=\"blinkL\" type=\"button\" style=\"color:red; background: black;\" onclick=\"myMarquee.direction='left'; marLeft();\" value=\"←\"> \n ☆\n <input type=\"button\" name=\"stopStart\" value=\" STOP \" onClick=\"Stop_Start()\">\n ☆\n <INPUT id=\"blinkR\" type=\"button\" style=\"color:white; background: black;\" onclick=\"myMarquee.direction='right'; marRight();\" value=\"→\"> \n </form>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T05:03:43.507",
"favorite_count": 0,
"id": "23291",
"last_activity_date": "2019-12-13T19:27:05.827",
"last_edit_date": "2016-03-20T14:42:38.410",
"last_editor_user_id": "9359",
"owner_user_id": "9359",
"post_type": "question",
"score": -2,
"tags": [
"javascript",
"html"
],
"title": "marqueeで動いている文字の方向に応じて、その『方向指示ボタン』の矢印を、\"点滅\"で示すようにするには",
"view_count": 235
} | [
{
"body": "専門的には分かりませんが、一応以下のようにすれば機能します。 \nただ、\"stop\"と\"start\"を切り替える『トグルボタン』ではうまくいきませんので、 \n普通の『ストップ』ボタンにしました。 \nまた、矢印のボタンを連打すると、その連打した回数だけ反対側の矢印のボタンを \n押さないと、正常な状態に戻らない点が難点です。\n\n```\n\n <html>\n <head>\n <title>ボタンのラベルを点滅させます</title>\n \n <script language=\"JavaScript\">\n <!--\n \n msgA = new Array();\n msgA[0] = \"←\";\n msgA[1] = \"\\u0020\\u0020\\u0020\";\n numA = 0;\n var tmr1ID;\n \n function blinkmsg1(){ //ボタンのラベル(文字)を点滅させます。\n document.getElementById(\"mybotan2\").value =\"→\";\n clearTimeout(tmr2ID);\n document.getElementById(\"mybotan1\").value = msgA[numA];\n numA ^= 1;\n tmr1ID = setTimeout('blinkmsg1()',1000);\n document.getElementById(\"mybotan1\").style.color=\"red\";\n document.getElementById(\"mybotan2\").style.color=\"white\";\n myMarquee.direction='left'; \n document.getElementById(\"myMarquee\").start();\n }\n \n msgB = new Array();\n msgB[0] = \"→\";\n msgB[1] = \"\\u0020\\u0020\\u0020\";\n numB = 0;\n var tmr2ID;\n \n function blinkmsg2(){ //ボタンのラベル(文字)を点滅させます。\n document.getElementById(\"mybotan1\").value =\"←\";\n clearTimeout(tmr1ID);\n document.getElementById(\"mybotan2\").value = msgB[numB];\n numB ^= 1;\n tmr2ID = setTimeout('blinkmsg2()',1000);\n document.getElementById(\"mybotan1\").style.color=\"white\";\n document.getElementById(\"mybotan2\").style.color=\"red\";\n myMarquee.direction='right';\n document.getElementById(\"myMarquee\").start();\n }\n \n function stopMarquee(){\n document.getElementById(\"mybotan1\").disabled=false;\n document.getElementById(\"mybotan2\").disabled=false;\n clearTimeout(tmr1ID);\n clearTimeout(tmr2ID);\n document.getElementById(\"mybotan1\").value =\"←\";\n document.getElementById(\"mybotan2\").value =\"→\";\n document.getElementById(\"mybotan1\").style.color=\"white\";\n document.getElementById(\"mybotan2\").style.color=\"white\";\n document.getElementById(\"myMarquee\").stop();\n }\n //-->\n </script>\n </head>\n \n <body>\n <marquee id=\"myMarquee\">ttttt</marquee>\n \n <form name=\"myForm\" style=\"text-align:center;\">\n <input name=\"blinkA\" type=\"button\" id=\"mybotan1\" value=\"←\" onclick=\"blinkmsg1();\"\n style=\"color:white; font-weight:bold; background:black; text-align : center;\">\n <input type=\"button\" name=\"stop\" value=\" STOP \" onClick=\"stopMarquee()\">\n <input name=\"blinkB\" type=\"button\" id=\"mybotan2\" value=\"→\" onclick=\"blinkmsg2();\"\n style=\"color:white; font-weight:bold; background:black; text-align : center;\">\n </form>\n \n <script language=\"JavaScript\">\n <!--\n setTimeout('blinkmsg1()',1000);\n //-->\n </script>\n \n </body>\n </html>\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T02:44:51.167",
"id": "23312",
"last_activity_date": "2016-03-22T15:04:09.167",
"last_edit_date": "2016-03-22T15:04:09.167",
"last_editor_user_id": "9359",
"owner_user_id": "9359",
"parent_id": "23291",
"post_type": "answer",
"score": 0
},
{
"body": "要は、質問は「文字を点滅させるにはどうしたらよいか」になると思います。いろいろと方法があり、user9359\nさん自身の回答「JavaScriptのタイマーで何とかする」はその一つです。\n\n別解は、\n\n * 画像ボタンにしてアニメーション GIF で点滅させる\n * CSS Animation を使う\n\nなどあると思います。後者の例です: <https://jsfiddle.net/68zfn8t1/>\n\n```\n\n function marLeft() {\r\n document.getElementById(\"blinkL\").classList.add(\"BLINK\");\r\n document.getElementById(\"blinkR\").classList.remove(\"BLINK\");\r\n }\r\n \r\n function marRight() {\r\n document.getElementById(\"blinkR\").classList.add(\"BLINK\");\r\n document.getElementById(\"blinkL\").classList.remove(\"BLINK\");\r\n }\r\n \r\n var flg = false;\r\n \r\n function Stop_Start() {\r\n flg = !flg;\r\n document.myForm.stopStart.value = flg ? \"START\" : \"STOP\";\r\n if (flg) {\r\n document.getElementById(\"myMarquee\").stop();\r\n } else {\r\n document.getElementById(\"myMarquee\").start();\r\n }\r\n }\n```\n\n```\n\n .DIRECTION {\r\n color: white;\r\n background: black;\r\n }\r\n \r\n .BLINK {\r\n animation: blink 1s step-end infinite normal;\r\n }\r\n \r\n @keyframes blink {\r\n 0% {\r\n color: red;\r\n }\r\n 50% {\r\n color: transparent;\r\n }\r\n }\n```\n\n```\n\n <marquee id=\"myMarquee\">TTTTT</marquee>\r\n <br><br>\r\n <form id=\"marFunction\" name=\"myForm\" style=\"text-align:center;\">\r\n <input id=\"blinkL\" type=\"button\" class=\"DIRECTION BLINK\" onclick=\"myMarquee.direction='left'; marLeft();\" value=\"←\"> ☆\r\n <input type=\"button\" name=\"stopStart\" value=\" STOP \" onClick=\"Stop_Start()\"> ☆\r\n <input id=\"blinkR\" type=\"button\" class=\"DIRECTION\" onclick=\"myMarquee.direction='right'; marRight();\" value=\"→\">\r\n </form>\n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2016-03-23T01:57:20.390",
"id": "23362",
"last_activity_date": "2019-12-13T19:27:05.827",
"last_edit_date": "2019-12-13T19:27:05.827",
"last_editor_user_id": "32986",
"owner_user_id": "3475",
"parent_id": "23291",
"post_type": "answer",
"score": 0
},
{
"body": "\"stop\"と\"start\"を切り替える『トグルボタン』でも、うまく行きました。 \nなお、スタートさせるには、『方向指示ボタン』で方向を決めて点滅させてから \n『START』を押さないと、機能しません。\n\n```\n\n <html>\n <head>\n <title>ボタンのラベルを点滅させます</title>\n \n <script language=\"JavaScript\">\n <!--\n \n msgA = new Array();\n msgA[0] = \"←\";\n msgA[1] = \"\\u0020\\u0020\\u0020\";\n numA = 0;\n var tmr1ID;\n \n function blinkmsg1(){ //ボタンのラベル(文字)を点滅させます。\n document.getElementById(\"stop_start\").disabled=false;\n document.getElementById(\"mybotan1\").disabled=true;\n document.getElementById(\"mybotan2\").disabled=false;\n document.getElementById(\"mybotan2\").value =\"→\";\n clearTimeout(tmr2ID);\n document.getElementById(\"mybotan1\").value = msgA[numA];\n numA ^= 1;\n tmr1ID = setTimeout('blinkmsg1()',1000);\n document.getElementById(\"mybotan1\").style.color=\"red\";\n document.getElementById(\"mybotan2\").style.color=\"white\";\n myMarquee.direction='left';\n }\n msgB = new Array();\n msgB[0] = \"→\";\n msgB[1] = \"\\u0020\\u0020\\u0020\";\n numB = 0;\n var tmr2ID;\n \n function blinkmsg2(){ //ボタンのラベル(文字)を点滅させます。\n document.getElementById(\"stop_start\").disabled=false;\n document.getElementById(\"mybotan1\").disabled=false;\n document.getElementById(\"mybotan2\").disabled=true;\n document.getElementById(\"mybotan1\").value =\"←\";\n clearTimeout(tmr1ID);\n document.getElementById(\"mybotan2\").value = msgB[numB];\n numB ^= 1;\n tmr2ID = setTimeout('blinkmsg2()',1000);\n document.getElementById(\"mybotan1\").style.color=\"white\";\n document.getElementById(\"mybotan2\").style.color=\"red\";\n myMarquee.direction='right';\n }\n \n flg=false;\n function stopMarquee(){\n flg = !flg;\n if(flg){\n document.getElementById(\"mybotan1\").value =\"←\";\n clearTimeout(tmr1ID);\n document.getElementById(\"mybotan1\").style.color=\"white\";\n document.getElementById(\"mybotan2\").value =\"→\";\n clearTimeout(tmr2ID);\n document.getElementById(\"mybotan2\").style.color=\"white\";\n document.getElementById(\"mybotan1\").disabled=false;\n document.getElementById(\"mybotan2\").disabled=false;\n document.getElementById(\"stop_start\").disabled=true;\n document.getElementById(\"myMarquee\").stop();\n flg=true;\n }else{\n document.getElementById(\"stop_start\").disabled=false;\n document.getElementById(\"myMarquee\").start();\n flg=false;\n }\n document.getElementById(\"stop_start\").value=flg?\"START\":\"STOP\";\n }\n //-->\n </script>\n </head>\n \n <body>\n <marquee id=\"myMarquee\">ttttt</marquee>\n <br><br>\n <form name=\"myForm\" style=\"text-align:center;\">\n <input name=\"blinkA\" type=\"button\" id=\"mybotan1\" value=\"←\" onclick=\"blinkmsg1();\"\n style=\"color:white; font-weight:bold; background:black; text-align : center;\">\n <input type=\"button\" id=\"stop_start\" name=\"\" value=\" STOP \" onClick=\"stopMarquee()\">\n <input name=\"blinkB\" type=\"button\" id=\"mybotan2\" value=\"→\" onclick=\"blinkmsg2();\"\n style=\"color:white; font-weight:bold; background:black; text-align : center;\">\n </form>\n \n <script language=\"JavaScript\">\n <!--\n setTimeout('blinkmsg1()',1000);\n //-->\n </script>\n \n </body>\n </html>\n \n```\n\nここで新たな疑問が生じました。 \nスタートさせるには、『方向指示ボタン』で方向を決めて\"点滅\"させてから \n『START』を押さないと、機能しませんが、この停止している状態では\"点滅\" \nではなくて\"赤色\"にし、スタートさせたら\"点滅\"するようにしたいのです。 \n分かる方は、教えていただけませんか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T09:10:34.747",
"id": "23381",
"last_activity_date": "2016-03-24T11:56:00.927",
"last_edit_date": "2016-03-24T11:56:00.927",
"last_editor_user_id": "9359",
"owner_user_id": "9359",
"parent_id": "23291",
"post_type": "answer",
"score": 0
}
]
| 23291 | 23362 | 23312 |
{
"accepted_answer_id": "23300",
"answer_count": 1,
"body": "現在MYSQLをソースからインストールしており、 \n今回、MYSQLにSSLで接続する必要が出てきたためmysqlを以下の手順で再インストールしようと考えております。 \nこの場合現在あるデータベースのデータに影響はありますでしょうか?\n\n```\n\n cd /usr/loca/src/mysql-5.7.11\n ; -DWITH_SSL=yesを追加\n cmake . -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_SSL=bundled -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/src/boost_1_60_0/boost -DWITH_SSL=yes\n make\n porg -lD \"make install\"\n```\n\nmy.cnfに以下を追加※httpdで使用しているssl証明書を使用する\n\n```\n\n [mysqld]\n ssl-ca = /opt/httpd/httpd-2.4.18/conf/ssl.crt/server-ca.crt\n ssl-cert = /opt/httpd/httpd-2.4.18/conf/ssl.crt/server.crt\n ssl-key = /opt/httpd/httpd-2.4.18/conf/ssl.key/server.key\n```\n\n```\n\n service mysqld restart\n```\n\nssl適応確認 \n\n```\n\n mysql -u root -p -e \"show variables like '%ssl%'\"\n```\n\n```\n\n cat /proc/version\n Linux version 2.6.32-573.12.1.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) ) #1 SMP Tue Dec 15 21:19:08 UTC 2015\n mysql --version\n mysql Ver 14.14 Distrib 5.7.11, for Linux (x86_64) using EditLine wrapper\n \n```\n\n宜しくお願い致します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T05:50:09.037",
"favorite_count": 0,
"id": "23292",
"last_activity_date": "2016-03-20T12:43:10.937",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14864",
"post_type": "question",
"score": 0,
"tags": [
"mysql"
],
"title": "MYSQLの再インストール",
"view_count": 270
} | [
{
"body": "SSL関連以外に全く変更がないのであれば、影響はありません。\n\nただし、自分でソースコードからビルドしているとその「全く変更がない」事を保証できるかという話になってきますので、念のためデータベースのフルバックアップを取得しておくこと、作業前後のデータの整合性の確認方法、バックアップからのリカバリ方法を検討しておくことをお勧めします。\n\nまた、どうしても必要が無い限りソースコードからのビルドではなく、MySQL公式かディストリビュータが提供しているバイナリパッケージを利用されることも検討した方がよいでしょう。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T12:43:10.937",
"id": "23300",
"last_activity_date": "2016-03-20T12:43:10.937",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5793",
"parent_id": "23292",
"post_type": "answer",
"score": 1
}
]
| 23292 | 23300 | 23300 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "こんにちは。\n\n早速質問ですが、Macで「IntelliJ、バージョン15」にウェブサーバ(Tomcat 8.0) \n設定の際、1099ポートが使えません。\n\nコンソールに出力されるメッセージは下記のようです。\n\n> ”Application Server was not connected before run configuration \n> stop,reason: Unable to ping server at localhost:1099”\n\nちなみにStack Overflowから少し調べ、試したのが下記のようです。\n\n①/etc/hostsでホスト名を設定。 \n②自分のMacでホスト名を設定する。\n\n追記します。 \netc/hosts \n127.0.0.1 localhost\n\nマックに設定されているホスト名 : localhost \nJAVAはバージョン8です。\n\n上記処理を行った後、ウェブサーバーを再起動してみましたが結果はダメでした。\n\n宜しくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T06:32:54.903",
"favorite_count": 0,
"id": "23294",
"last_activity_date": "2016-05-10T09:11:19.567",
"last_edit_date": "2016-03-23T17:01:23.487",
"last_editor_user_id": "14882",
"owner_user_id": "14865",
"post_type": "question",
"score": 0,
"tags": [
"macos",
"tomcat",
"intellij-idea"
],
"title": "IntelliJにTomcat設定の際、ポート1099エラー",
"view_count": 496
} | [
{
"body": "自分で解決した履歴です。\n\nIntelliJのjava設定にて、システムのJVMとして \nロードされるように変更して解決しました。\n\nIDE全体的な設定とproject設定を両方変更。\n\n(既存設定はIntelliJ基本のJVMでした。 \nおそらく、JVMのpath問題だったと思います。)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-04-09T05:57:51.953",
"id": "23867",
"last_activity_date": "2016-04-09T05:57:51.953",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14882",
"parent_id": "23294",
"post_type": "answer",
"score": 1
}
]
| 23294 | null | 23867 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Unity5.3を使って、AdMobを実装しようと思っています。 \niOSデバイスでは上手く機能しているのですが、Androidではコンパイルエラーになってしまいます。\n\nやったことは、 \n(1) AdMob管理画面からAndroid用のユニットIDを取得して広告を表示したいソースにコピー \n(2) AdMob Unityプラグインをプロジェクトにインポート \n(3) Android SDKにインストールされているgoogle-play-\nservices_libをAssets/Plugins/Android/配下にコピー\n\nCommandInvokationFailure: Failed to re-package resources. See the Console for\ndetails.\n\n似たようなエラーについての質問とその回答は幾つか見つけることができましたが、解決には至りませんでした(情報が古いためかもしれません)。\n\nAndroid上でAdMobを実装するためには、上記の手順以外にも何か必要な点があるのでしょうか? \nご教示いただけると幸いです。\n\nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T07:23:25.840",
"favorite_count": 0,
"id": "23295",
"last_activity_date": "2016-09-11T12:27:09.473",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13138",
"post_type": "question",
"score": 0,
"tags": [
"unity3d",
"admob"
],
"title": "UnityでのAdMob実装について",
"view_count": 728
} | [
{
"body": "Assets\\PlayServicesResolver\\Editor にある AdMobDependencies.cs の中に\n\nsvcSupport.DependOn(\"com.android.support\", \"appcompat-v7\", \"23.1.0+\");\n\nと記述されている箇所を\n\nsvcSupport.DependOn(\"com.android.support\", \"appcompat-v7\", \"LATEST\");\n\nと書き替えたら、私の場合はうまくいきました。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T07:49:15.583",
"id": "23377",
"last_activity_date": "2016-03-23T07:49:15.583",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14902",
"parent_id": "23295",
"post_type": "answer",
"score": 1
}
]
| 23295 | null | 23377 |
{
"accepted_answer_id": "23428",
"answer_count": 1,
"body": "現在、monacaとniftymbaasを使用してプッシュ通知が使えるアプリを作成しています。 \nプログラムは作成済みなのですが、デバッグビルドをする際のiosビルド設定で困っております。 \niOS dev centerでprovisioning\nfile、証明書の取得をして秘密鍵とCSRのインポートまではうまくいったんですが、証明書のアップロードでこれはデペロッパーの証明書ではないですよと言うようなエラーが出てしまい先に進めません。何度も証明書を取得し試しているのですが同じエラーが出てしまいます。 \nmonacaの設定の問題でしょうか? \nそれとも証明書の取得がうまくいってないんでしょうか?\n\nどなたかわかる方ご教授お願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T08:32:30.717",
"favorite_count": 0,
"id": "23297",
"last_activity_date": "2016-03-24T15:41:51.980",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13685",
"post_type": "question",
"score": 3,
"tags": [
"ios",
"monaca"
],
"title": "monacaとniftymbaasを使用して、iOS でプッシュ通知を実装したい。",
"view_count": 500
} | [
{
"body": "wakuさん、こんにちは。 \n恐らく自分がはまったのと同じ個所かと思われますのでお助けになれば。。。\n\nデバッグビルドをする際の、[iOSのビルド設定]でアップロードする証明書は、 \nApple developerログイン \n→Member Center \n→Certificates, Identifiers & Profiles \n→Certificates \n→Development \n→iOS App Development \nこれです。\n\n自分は、「プッシュ通知をするんだから…」と思い込み \nCertificates \n→Development \n→Apple Push Notification service SSL (Sandbox) \nこのプッシュ通知のための証明書を何度も何度も作っては消し…で半月くらい費やしたでしょうか…\n\nちなみにプッシュ通知を実装したアプリには、全部で4つ証明書が必要になります。 \n●デバッグビルド用 \n・Certificates→Development→iOS App Development \nアプリの証明書。Monacaにアップロードする「デベロッパー証明書」はこれ。 \nアップロードする「秘密鍵」もこの証明書から書き出したもの。 \n・Certificates→Development→Apple Push Notification service SSL (Sandbox) \nプッシュ通知のための証明書。プッシュを実装しなければ不要。 \nNCMBにアップロードするp12ファイルはこの証明書から書き出したもの。 \n●リリースビルド用 \n・Certificates→Production→App Store and Ad Hoc \nMonacaにアップロードする「ディストリビューション証明書」はこれ。 \nアップロードする「秘密鍵」もこの証明書から書き出したもの。 \n・Certificates→Production→Apple Push Notification service SSL (Sandbox &\nProduction) \nプッシュ通知のための証明書。プッシュを実装しなければ不要。 \nNCMBにアップロードするp12ファイルはこの証明書から書き出したもの。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T15:41:51.980",
"id": "23428",
"last_activity_date": "2016-03-24T15:41:51.980",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13592",
"parent_id": "23297",
"post_type": "answer",
"score": 2
}
]
| 23297 | 23428 | 23428 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "生徒の教育のため `Github` で サイトのレポジトリを公開し、サーバーサイドのソースコードが生徒や第三者に見えるようにしたいです。 \n`Ruby on Rails`\n実装したウェブサイトのレポジトリを公開していて、実際にブラウザでアクセスできるサイトは検索などでもみつからなかったのですが、そもそもウェブサイトのサーバーサイドのソースコードを公開することは一般的にはあるんでしょうか?\n\nそしてサーバーサイドのソースコードを公開して全世界からのアクセスを許可した場合、どのような危険が考えられるのでしょうか?\n\nサーバーサイドの実装が丸見えになるので攻撃者などにも格好の餌食になるのではないかと思っていますが、サーバーサイド・エンジニアリングの教育のため広く第三者にみえるようにしたいんです。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T09:39:33.917",
"favorite_count": 0,
"id": "23299",
"last_activity_date": "2016-03-21T00:03:14.407",
"last_edit_date": "2016-03-20T13:19:50.997",
"last_editor_user_id": "5505",
"owner_user_id": "5505",
"post_type": "question",
"score": -1,
"tags": [
"security"
],
"title": "オープンソースでサーバーサイドのソースコードを公開することはどのような危険があるんでしょうか?",
"view_count": 823
} | [
{
"body": "> そもそもウェブサイトのサーバーサイドのソースコードを公開することは一般的にはあるんでしょうか?\n\nあります。複数人でそのウェブサイトを開発し運用していく上で、ソースコードを共有することは重要になります。その共有場所としてソースコードがオープンな状況になってしまう場所を選択することも多いです。GithubのPublicリポジトリが代表例ですね。また、WordPressなどのインストールして使うようなソフトウェアも同様です。\n\n> サーバーサイドのソースコードを公開して全世界からのアクセスを許可した場合、どのような危険が考えられるのでしょうか?\n\n結局のところ、「守りたいことは何か?」という点に尽きます。危険性の排除を最大限優先するのであれば、全て隠せば良いし、危険性が全くないのであれば、全て晒してしまって良いわけです。「守りたいことが何なのか?」の程度によって、隠すもの、晒すもの、それらの割合が自然と変わってきます。\n\nWordPressの例であれば、データベースのパスワードなど、サイトごとに隠さなければならない情報がありますので、WordPressで公開されているソースコードの中には、もちろん「隠さなければならない情報」は一切含まれていません。サイトのサーバにインストールした後、隠さなければならない情報を追記することになります。そして、それを隠す責務は、WordPressの作者側ではなく、そのサイトの運営者側です。wp-\nconfig.phpファイルが閲覧可能であれば、もう何でもありの危険きわまりない状況になります。\n\nWordPressのデータベースの構造は、WordPressのソースコードに含まれるものですので、公開情報です。世界中の誰でもその構造を知ることができます。ではそれが直ちに危険かというと、構造を知っても、データベースに直接アクセスできなければ、直ちに危険な状況ではありません。サイトの運営者側が適切にサイトを守ることができれば良く、それよりも構造を公開して皆で共有することで、WordPressの開発スピードを高められます。\n\nただし、世界中にいるクラッカーは日々様々なソフトウェアの脆弱性を突いて侵入を試みています。そういった人達にできるだけ情報を渡さない、という考え方もあります。この場合、WordPressを使ってることがバレれば、データベースの構造などが簡単にわかるため、侵入されるリスク、侵入された後の被害が拡大するリスクは高まります。この考え方であれば、WordPressを選択しない、またはWordPressを利用していることを完全に隠す、といった対処が必要になります。\n\nまとめると、\n\n * 守りたいこと/ものは何か?(守れなかった場合の被害を検討)\n * それを守るためには何が必要か?(隠すための手段を検討)\n * 公開したときのメリットは何か?(共同開発が必要、第3者によるレビュー/改善を受けたい、など)\n\nといった要因がそれぞれどの程度あるのかによって、答えは変わってきます。\n\n> 生徒の教育のため Github で サイトのレポジトリを公開し、サーバーサイドのソースコードが生徒や第三者に見えるようにしたいです。\n\nお持ちのそのリポジトリにあるソースコードについて、上記3つのポイントをそれぞれ検討し、危険性を洗い出してみてはいかがでしょうか?",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T00:03:14.407",
"id": "23311",
"last_activity_date": "2016-03-21T00:03:14.407",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "531",
"parent_id": "23299",
"post_type": "answer",
"score": 5
}
]
| 23299 | null | 23311 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "Swift 2.1 \nRealm 0.98\n\nイメージとしては、クイズアプリの様に複数の質問と回答がDBに格納されて、 \n質問一覧から選択すると、質問文が表示され、回答を出す。\n\nたった今Realmを導入したばかりで、全体の流れもあまり理解できておりません。\n\n更新ドキュメントを見ましたが、モデルを作成してそこでデータに関する処理ができます。 \nという形でしか理解できませんでした。\n\nイメージのものを作成する流れを教えて頂けますでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T18:19:26.620",
"favorite_count": 0,
"id": "23306",
"last_activity_date": "2016-09-16T06:18:19.503",
"last_edit_date": "2016-03-21T02:25:13.990",
"last_editor_user_id": "5519",
"owner_user_id": "14872",
"post_type": "question",
"score": 1,
"tags": [
"ios",
"swift",
"realm"
],
"title": "Realmで初期データを作成をしたいのですが、やり方がわかりません。",
"view_count": 2999
} | [
{
"body": "まずデータとなる質問と回答の構造を考えます。 \n最低限必要なのは問題文と回答のテキストですね。アプリの性質によっては順番や難易度などが必要かもしれません。必要なデータ項目を洗い出して、それを元にクラスを設計します。\n\nRealmではクラスがそのまま一般のデータベースでいうテーブルになります。\n\nクラスを作るところまでできれば、実際の問題文と回答のデータをRealmに保存していきます。\n\nこれが初期データとなります。初期データの作成は適当なプロジェクトを作ってシミュレータでやるのが簡単です。\n\n初期データの作成が完了したら、できたファイルを本当のアプリケーションのプロジェクトにコピーして組み込みます。 \n実際のアプリケーションでは組み込んだファイルを読み込んで使用します。\n\n大まかな流れは上記のようになります。\n\n現在の様子ですと、より詳しくは、Realmのチャットサポート(日本語で質問できます) <http://slack.realm.io/>\nを使って聞かれるのが良いと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-20T23:56:32.337",
"id": "23310",
"last_activity_date": "2016-03-20T23:56:32.337",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5519",
"parent_id": "23306",
"post_type": "answer",
"score": 0
},
{
"body": "私は初期データ(=シードデータ)の投入にあたっては、初回起動処理用のフラグを設けて、初回起動時にだけ流し込みを行っています。 \n具体的にはAppDelegateで処理をしていますので、具体的なコードをみてください(文量の関係上、一部メソッドを省略してます)。 \n`insertSeedData`メソッドで、kishikawa katsumiさんがご回答された準備の上で、書き込み処理を追加してください。\n\n```\n\n import UIKit\n import RealmSwift\n \n @UIApplicationMain\n class AppDelegate: UIResponder, UIApplicationDelegate {\n \n var window: UIWindow?\n let defaults = NSUserDefaults()\n \n func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {\n \n // 初回起動処理\n let dic = [\"initialLaunch\": true]\n defaults.registerDefaults(dic)\n defaults.synchronize()\n \n if defaults.boolForKey(\"initialLaunch\") == true {\n print(\"initial setup start\")\n self.initialSetUp()\n }\n \n return true\n }\n \n func initialSetUp() {\n // 初回マイグレーション\n self.realmMigration()\n // シードデータ投入\n self.insertSeedData()\n // 初回起動済みのフラグを立てる\n self.defaults.setBool(false, forKey: \"initialLaunch\")\n self.defaults.synchronize()\n }\n \n func realmMigration() {\n let config = Realm.Configuration(\n // 新しいスキーマバージョンを設定します。以前のバージョンより大きくなければなりません。\n // (スキーマバージョンを設定したことがなければ、最初は0が設定されています)\n schemaVersion: 1,\n \n // マイグレーション処理を記述します。古いスキーマバージョンのRealmを開こうとすると\n // 自動的にマイグレーションが実行されます。\n migrationBlock: { migration, oldSchemaVersion in\n if (oldSchemaVersion < 1) {\n // 何もする必要はありません!\n // Realmは自動的に新しく追加されたプロパティと、削除されたプロパティを認識します。\n // そしてディスク上のスキーマを自動的にアップデートします。\n }\n })\n \n // デフォルトRealmに新しい設定を適用します\n Realm.Configuration.defaultConfiguration = config\n \n // Realmファイルを開こうとしたときスキーマバージョンが異なれば、\n // 自動的にマイグレーションが実行されます\n let realm = try! Realm()\n }\n \n func insertSeedData() {\n // realm\n let realm = try! Realm()\n // 空のアプリユーザーを作成\n let appUser = User()\n appUser.id = 1\n // 書き込み処理\n try! realm.write {\n realm.add(appUser, update: true)\n }\n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T05:50:02.220",
"id": "23499",
"last_activity_date": "2016-03-27T05:50:02.220",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "303",
"parent_id": "23306",
"post_type": "answer",
"score": 1
}
]
| 23306 | null | 23499 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "Windows8上のAndroidStudioでアプリ開発をしていたのですが、 \n先日パソコンのファイル整理をして以来、 \nAndroidStudioのエミュレーターでアプリを実行できなくなってしまいました。\n\n状況としては、 \nエミュレーターを立ち上げる(普通に立ち上がりますし、アイコン一覧からアプリのプロジェクトをクリックすればそのアプリが実行されます) \n→AndroidStudioの実行ボタン(◀)を押すが、何も起こらず、 \n実行ボタンは押されたまま\n\nという感じです。エラーも出ていません。\n\nAndroidSDKやJDK等はProjectStructureで示されている場所にありました。 \nまた、SDK Managerを確認しましたが、必要と思われるものはすべて入っていました。\n\nどうすれば、◀ボタンを押したときにAndroidStudioで開いているプロジェクトのアプリが \n実行されるでしょうか? \n何か解決策等ありましたら教えていただきたいです。\n\n* * *\n\n追記\n\nTarget Deviceを確認したところ、 \nエミュレーターの名前が赤文字になっていたので、これも関係しているかもしれません。\n\n[](https://i.stack.imgur.com/BgPtd.png)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T05:09:21.737",
"favorite_count": 0,
"id": "23313",
"last_activity_date": "2023-05-07T02:01:15.357",
"last_edit_date": "2017-03-18T08:54:00.447",
"last_editor_user_id": "8000",
"owner_user_id": "12330",
"post_type": "question",
"score": 0,
"tags": [
"android",
"android-studio"
],
"title": "AndroidStudioのエミュレーターでアプリを実行できない",
"view_count": 5112
} | [
{
"body": "windows/linux/Macよっても変わってくると思うので、それだけではなんとも。 \nファイル整理をしたとの事なので、AndroidSDKなどのフォルダを移動していないか確認してみては?",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T06:49:11.200",
"id": "23314",
"last_activity_date": "2016-03-21T06:49:11.200",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "525",
"parent_id": "23313",
"post_type": "answer",
"score": 0
},
{
"body": "windows 8のPro?でよいですか?またCPUのアーキテクチャわかりますか? \n一部の仮想端末使うためにはHyper Vが必須で、いわゆるHomeではHyper V使えないとかいろいろ制約あります。またIntel\n系のプロセッサならまだ楽ですが、AMD系を使っている場合、最悪、純粋エミュレータ(激遅)を使わなくてはいけないという。。。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2020-03-09T13:58:41.857",
"id": "63702",
"last_activity_date": "2020-03-09T13:58:41.857",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10174",
"parent_id": "23313",
"post_type": "answer",
"score": 0
}
]
| 23313 | null | 23314 |
{
"accepted_answer_id": "23394",
"answer_count": 1,
"body": "BCrypt::Errors::InvalidHash in Devise::SessionsController#createとエラーが表示されました。 \nまたinvalid\nhashとも表示されました。これは、SessionsControllerのcreateアクションのhashが無効である、という意味かなと思いましたが、SessionsControllerなるものをつくっていないです。解釈が間違っているのでしょうか?\n\napplication_controller.rb\n\n```\n\n class ApplicationController < ActionController::Base\n \n before_action :configure_permitted_parameters, if: :devise_controller? \n # Prevent CSRF attacks by raising an exception. \n # For APIs, you may want to use :null_session instead. \n protect_from_forgery with: :exception\n \n # privateメソッドを定義し、deviseの新規登録フォームでnameを受け取れるようにしてください \n include ApplicationHelper\n \n private\n \n def configure_permitted_parameters \n devise_parameter_sanitizer.for(:sign_up) << [:name,:email,:username,:password] \n devise_parameter_sanitizer.for(:sign_in) << [:login,:username,:remember_me] \n end \n end \n \n```\n\nhome_controller.rb\n\n```\n\n class HomeController < ApplicationController \n def top \n if user_signed_in? \n # 変数@noteにNoteクラスのインスタンスを代入してください \n @note = Note.new \n # 変数@notesにNoteクラスのインスタンスの配列を降順で代入してください \n @notes = Note.all.order(created_at: :desc) \n else \n @message = \"ようこそKotoritterへ!\" \n end \n end\n \n def about \n end \n end \n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T07:54:03.810",
"favorite_count": 0,
"id": "23315",
"last_activity_date": "2016-03-23T13:23:43.677",
"last_edit_date": "2016-03-21T08:35:02.417",
"last_editor_user_id": "8000",
"owner_user_id": "14754",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "BCrypt::Errors::InvalidHash in Devise::SessionsController#createの意味",
"view_count": 2820
} | [
{
"body": "`Devise::SessionsController`はDeviseで実際に認証などの処理をしているControllerです。\n\nDeviseを使ってユーザー認証をする場合、ユーザー登録時、パスワードは元の文字列そのままではなく、元の文字列に戻せないよう変換した形でDBに保存されます。この処理をやっているのがBCryptというライブラリです。\n\nこの変換処理を施した後の文字列は、`$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW`こんな感じになっているのですが、一定の書式がある文字列になっています。\n\n`BCrypt::Errors::InvalidHash`は、BCryptが上記の文字列を読み込んだ時に適切なフォーマットになっていないと発生する例外です。\n\nDBの`users`テーブル(Deviseのセットアップ時に変更した場合は適宜読み替えてください)の`ecrypted_password`に保存されている値が不正な値になっていると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T13:23:43.677",
"id": "23394",
"last_activity_date": "2016-03-23T13:23:43.677",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5793",
"parent_id": "23315",
"post_type": "answer",
"score": 0
}
]
| 23315 | 23394 | 23394 |
{
"accepted_answer_id": "23318",
"answer_count": 1,
"body": "いまTwitterのようなサイトを作っています。 \nつぶやきの投稿画面に文字を入力し保存ボタンを押したら、1件のエラー: \nUser can't be blankと表示されます。 \nユーザーの新規登録画面を作成し、そこにユーザー情報を入力し、正常ログインしたあとのエラーで、Userが空である訳がないのですが。。。 \nnotes_controller.rbのどこかに異常があるということなのでしょうか? \n(tweetをnoteと読んでいます) \nnotes_controller.rb\n\n```\n\n class NotesController < ApplicationController \n before_action :authenticate_user! \n before_action :correct_user, only: [:edit, :update] \n before_action :set_note,only:[:show,:edit,:update,:destroy]\n \n def create \n @note = Note.new(note_params) \n if @note.save \n redirect_to @note,notice:'投稿が保存されました' \n else \n @notes = Note.all.order(created_at: :desc) \n render 'home/top' \n end \n end\n \n def show \n @notes = Note.find(params[:id]) \n end\n def edit \n @notes = Note.find(params[:id]) \n end\n \n def update \n if @note.update(note_params) \n redirect_to @note, notice: \"投稿が更新されました\" \n else \n render :edit \n end \n end\n \n def destroy \n @note.destroy \n redirect_to notes_path \n end\n \n def liking_users \n @users = @note.liking_users \n end\n \n private\n \n def set_note \n @note = Note.find(params[:id]) \n end\n \n def note_params \n params.require(:note).permit(:content) \n end\n \n def correct_user \n note = Note.find(params[:id]) \n # noteを投稿したユーザーを取得し、current_user?メソッドの引数に渡してください \n if !current_user?(note.user) \n redirect_to root_path, alert: '許可されていないページです' \n end \n end\n \n end \n \n```\n\nnotes_controller.rb\n\n```\n\n class NotesController < ApplicationController \n before_action :authenticate_user! \n before_action :correct_user, only: [:edit, :update] \n before_action :set_note,only:[:show,:edit,:update,:destroy]\n def create \n @note = Note.new(note_params) \n if @note.save \n redirect_to @note,notice:'投稿が保存されました' \n else \n @notes = Note.all.order(created_at: :desc) \n render 'home/top' \n end \n end\n \n def show \n @notes = Note.find(params[:id]) \n end\n \n def edit \n @notes = Note.find(params[:id]) \n end\n \n def update \n if @note.update(note_params) \n redirect_to @note, notice: \"投稿が更新されました\" \n else \n render :edit \n end \n end\n \n def destroy \n @note.destroy \n redirect_to notes_path \n end\n \n def liking_users \n @users = @note.liking_users \n end\n \n private\n \n def set_note \n @note = Note.find(params[:id]) \n end\n \n def note_params \n params.require(:note).permit(:content) \n end\n \n def correct_user \n note = Note.find(params[:id]) \n # noteを投稿したユーザーを取得し、current_user?メソッドの引数に渡してください \n if !current_user?(note.user) \n redirect_to root_path, alert: '許可されていないページです' \n end \n end\n \n end \n \n```\n\nnoteのmodelのnote.rb\n\n```\n\n class Note < ActiveRecord::Base \n belongs_to :user \n has_many :likes, dependent: :destroy \n has_many :liking_users, through: :likes, source: :user\n \n validates :content, presence: true, length: { maximum: 140 } \n validates :user_id, presence: true \n end\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T08:00:54.530",
"favorite_count": 0,
"id": "23316",
"last_activity_date": "2016-03-21T10:18:07.073",
"last_edit_date": "2016-03-21T08:41:18.790",
"last_editor_user_id": "8000",
"owner_user_id": "14754",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "User can't be blankの解消方法",
"view_count": 3137
} | [
{
"body": "`user_id` (`user`) に代入している部分が見当たりません。おそらく Devise\nを使っていると思いますが、無関係のモデルに自動的に代入する機能はありません。\n\n`@note = Note.new(note_params)` の直後で、その値を確認してみると `user_id` は `nil`\nになっているはずです。その直後に次のようなコードを入れれば期待通りに動作するはずです。\n\n```\n\n @note.user = current_user\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T10:18:07.073",
"id": "23318",
"last_activity_date": "2016-03-21T10:18:07.073",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "76",
"parent_id": "23316",
"post_type": "answer",
"score": 0
}
]
| 23316 | 23318 | 23318 |
{
"accepted_answer_id": "23321",
"answer_count": 1,
"body": "Railsで `rake foo` というタスクがあり、同一サーバー上に定期的にファイルを更新してる\n`/var/foo/data.yml`がある状態なのですが、この `data.yml`が更新された時に `rake foo`を走らせたく思っています。\n\n方法としては\n\n * `data.yml`を生成するスクリプトの最後の`rake foo`を外部から呼び出す方法\n * Railsで`data.yml`のファイルスタンプを常に見ておいて更新されたら`rake foo`を呼び出す方法\n\nの2通りが思いついたのですが、外部からRails内部を触りに行くよりは、Railsが外部ファイルを触りに行くほうが自然な気がするのでRailsで特定のファイルの更新を監視する方法があれば知りたいです。\n\n`data.yml`取得のスクリプト部分をRailsプロジェクト内に入れることも考えたのですが、下手に入れると複雑に絡み込んでしまいそうで全く別の物として使っています。\n\nこのような場合どうすれば`data.yml`の更新を検知してすぐにRakeタスクを走らせることができますか?\n\nRakeタスクの管理には`Whenever`を使い、外部スクリプトの定期実行には別ユーザーでの`cron`を使っています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T09:22:58.090",
"favorite_count": 0,
"id": "23317",
"last_activity_date": "2016-03-21T13:18:20.537",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3271",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"rake"
],
"title": "Railsのプロジェクト外の同一サーバー上のファイルの更新を検出してrakeタスクを走らせる",
"view_count": 162
} | [
{
"body": "Whenever から1分ごとに適当なスクリプトを呼び出し、その中でファイルが変更されたことをチェックしてはいかがでしょうか? (もしくは、`rake\nfoo` で呼び出される処理中で判定する。) ファイルの更新時刻やダイジェスト値などを保存しておき、現在のものと比較することで変更を検出できます。\n\n1分ごとのチェックでは粗すぎるのであれば、`inotify` (Linuxの場合) などのツールを使って検知するのが良い思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T13:18:20.537",
"id": "23321",
"last_activity_date": "2016-03-21T13:18:20.537",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "76",
"parent_id": "23317",
"post_type": "answer",
"score": 0
}
]
| 23317 | 23321 | 23321 |
{
"accepted_answer_id": "23324",
"answer_count": 1,
"body": "Unityのデフォルト状態ではウィンドウの色は灰色になっています。\n\nしかし、[この前unityのチュートリアル動画](https://www.youtube.com/watch?v=RFlh8pTf4DU)で、黒っぽい色に変更して\n\nいるのをみました。プレイモード時の色を変更するのは、\n\nPreferencesから設定することを知っていますが、\n\nウィンドウの色を変更するにはどうするのでしょうか?\n\n回答よろしくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T12:51:13.597",
"favorite_count": 0,
"id": "23320",
"last_activity_date": "2016-03-21T16:08:39.960",
"last_edit_date": "2016-03-21T15:39:33.093",
"last_editor_user_id": "4129",
"owner_user_id": "14879",
"post_type": "question",
"score": 0,
"tags": [
"unity3d"
],
"title": "Unityウィンドウの色の変更について",
"view_count": 8686
} | [
{
"body": "残念ながら、Unityの`Preferences`の設定で少し色を変更することが出来るのに、ウインドウの色などを変更することにはUnityプロ・エディションが必要だと思います。私のUnityのバージョン(`4.3.2`)はちょっと古いのに、設定で、「ダーク・スキン」のそばで「Pro\nOnly」という注意がやはりありますよね。\n\nまた、[このUnityのページ](https://unity3d.com/get-\nunity)をご覧になると、プロ・エディションには「Professional editor skin」同梱の状態ようですが。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T15:57:44.667",
"id": "23324",
"last_activity_date": "2016-03-21T16:08:39.960",
"last_edit_date": "2016-03-21T16:08:39.960",
"last_editor_user_id": "4129",
"owner_user_id": "4129",
"parent_id": "23320",
"post_type": "answer",
"score": 0
}
]
| 23320 | 23324 | 23324 |
{
"accepted_answer_id": "23331",
"answer_count": 1,
"body": "googleplayの以下のサイトのhtmlをpythonで取得したところ、アプリのランキングが60位までしかのっていないものでした。\n\n<https://play.google.com/store/apps/collection/topselling_free?hl=ja> \nでソースコードを表示すると同じく60位までしか表示されません。\n\n調べたところ、Javascriptか何かでレンダリングされているとのことだったのですが、どのようにしたら60以降のアプリの情報ものったhtmlが取得できるか知りたいです。\n\nhtmlを取得したい理由は個々のアプリの詳細ページへのリンクを取得したいからです。 \n個々のアプリの詳細ページのリンクさえ取得できれば、手段は問いません。\n\nseleniumなどを利用することも考えましたが、ド素人なのでうまい対策が分かりませんでした。\n\n回答の程、よろしくお願い致します。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-21T15:24:57.163",
"favorite_count": 0,
"id": "23322",
"last_activity_date": "2016-03-22T08:52:38.607",
"last_edit_date": "2016-03-22T07:42:06.963",
"last_editor_user_id": "3054",
"owner_user_id": "10111",
"post_type": "question",
"score": 3,
"tags": [
"python",
"ajax"
],
"title": "無限スクロールでページの内容が随時読み込まれる場合のスクレイピング",
"view_count": 3576
} | [
{
"body": "例えば、このようなURLでアクセスすると \n[https://play.google.com/store/apps/collection/topselling_free?hl=ja&start=60&num=30](https://play.google.com/store/apps/collection/topselling_free?hl=ja&start=60&num=30) \n60位から90位が取得出来ます。\n\nこういったリクエストのパラメータを探すには、Webブラウザのデベロッパーツールなどで該当ページの挙動を観察すればよいです。 \nしかし、これからは多くのWebページが「Webアプリケーション」化していくので、難易度は上っていくでしょう。 \nやはり、seleniumやPhantomJSなどのようにブラウザをまるごと内蔵(操作)しているクライアントでクロールするのが楽だと思います。\n\n* * *\n\n追記:\n\n> ソースコードのどこをみればよいか\n\nですが、Webアプリケーションのソースをただ読んで追っていくのは普通の人には厳しいと思います。既にそういう時代です。 \n挙動を観察するのが基本かと思います。\n\n下にスクロールすると続きが読み込まれる「無限スクロール」の場合、観察するのは \n\\- スクロールイベント周辺 \n\\- ネットワークのリクエスト \nのどちらかです。\n\nこのページに関していうと、下までスクロールした際にXHR(XMLHttpRequests)による \n`https://play.google.com/store/apps/collection/topselling_free?hl=ja&authuser=0`\nに対するPOST要求が観察出来ます。 \nPOSTデータはこんな感じです。 \n\n```\n\n start=60\n num=60\n numChildren=0\n cctcss=square-cover\n cllayout=NORMAL\n ipf=1\n xhr=1\n token= ...\n hl=ja\n \n```\n\nこの中から必要な物を使う事になります。今回はstartとnumだけでよかったです。試してみるとGETも受け付けたので、上記URLが作れたわけです。 \n観察には[Firefoxの開発ツール](https://developer.mozilla.org/ja/docs/Tools/Network_Monitor)を使いました。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T03:02:37.747",
"id": "23331",
"last_activity_date": "2016-03-22T07:36:59.873",
"last_edit_date": "2016-03-22T07:36:59.873",
"last_editor_user_id": "3054",
"owner_user_id": "3054",
"parent_id": "23322",
"post_type": "answer",
"score": 2
}
]
| 23322 | 23331 | 23331 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "cakePHP 2.4.9を使用しています。 \n以下2つのテーブルをhasManyモデルを使用して結合し、追加、編集、更新を想定。\n\neventsテーブル\n\n```\n\n CREATE TABLE `events` (\n `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n `name` varchar(256) DEFAULT NULL,\n `latitude` decimal(18,15) DEFAULT NULL,\n `longitude` decimal(18,15) DEFAULT NULL,\n `adult_price` int(11) DEFAULT NULL,\n `adult_age` int(11) DEFAULT NULL,\n `child_price` int(11) DEFAULT NULL,\n `child_age` int(11) DEFAULT NULL,\n `access` text,\n `description` text,\n `minimun_participants_number` int(11) DEFAULT NULL,\n `child_policy_flag` int(11) DEFAULT NULL,\n `meals_flug` int(11) DEFAULT NULL,\n `time_of_day` int(11) DEFAULT NULL,\n `pickup_flag` int(11) DEFAULT NULL,\n `duration_hour` int(11) DEFAULT NULL,\n `pv` int(11) DEFAULT NULL,\n `rating` int(11) DEFAULT NULL,\n `created` timestamp NULL DEFAULT NULL,\n `modified` timestamp NULL DEFAULT NULL,\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n \n```\n\nevents_schedulesテーブル\n\n```\n\n CREATE TABLE `events_schedules` (\n `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n `event_id` int(10) DEFAULT NULL,\n `title` varchar(50) DEFAULT NULL,\n `description` text,\n `start_hour` int(11) DEFAULT NULL,\n `start_min` int(11) DEFAULT NULL,\n `end_hour` int(11) DEFAULT NULL,\n `end_min` int(11) DEFAULT NULL,\n `created` datetime DEFAULT NULL,\n `modified` datetime DEFAULT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n \n```\n\nModel/Event.php\n\n```\n\n <?php \n class EventController extends AppModel\n {\n public $hasMany = array(\n 'Event' => array(\n 'className' => 'Event',\n 'foreignKey' => 'event_id',\n 'dependent' => true,\n 'conditions' => '',\n 'fields' => '',\n 'order' => '',\n 'limit' => '',\n 'offset' => '',\n 'exclusive' => '',\n 'finderQuery' => '',\n 'counterQuery' => '',\n ),\n );\n }\n \n```\n\nとなっており、一つのイベントIDにつき複数のスケジュールを追加できるようにしています。 \nコントローラー側の処理です。 \nController/EventController.php\n\n```\n\n <?php\n App::uses('AppController', 'Controller');\n App::uses('HttpSocket', 'Network/Http');\n \n class EventsController extends AppController\n {\n \n public $uses = array('Event', 'EventSchedule');\n \n public function edit($id = null)\n {\n if ($this->request->is('Event') || $this->request->is('post')) {\n if ($id == null) {\n $id = $this->Event->getLastInsertID();\n } else {\n $this->EventSchedule->deleteAll(array('EventSchedule.event_id' => $id));\n }\n $this->Event->id = $id;\n \n if ($this->Event->save($this->request->data)) {\n if ($this->request->data('EventsSchedule')) {\n $this->EventsSchedule->saveAll($this->request->data['EventsSchedule'], array('deep' => true));\n }\n {\n $this->Flash->success(__('登録が完了しました'));\n }\n \n $this->redirect(array('action' => 'edit', $this->Event->id));\n } else {\n $this->Flash->error(__('失敗しました'));\n }\n }\n \n $options = array('conditions' => array('Event.id' => $id));\n $this->request->data = $this->Event->find('first', $options);\n $this->set('event', $this->request->data);\n }\n \n```\n\nView側では複数のインプットを保存できるように用意 \nView/Events/edit.ctp\n\n```\n\n <?php echo $this->Form->create('Event', array('type' => 'button', 'action' => 'edit','div' => false)); ?>\n (中略)\n .\n .\n .\n <?php \n $count = 0; \n foreach($this->data['EventsSchedule'] as $Eventschedule): ?> \n <tr>\n <th rowspan=\"8\">スケジュール</th>\n <td>\n <div class=\"form-inline\">\n <div class=\"ui two fields\">\n <div class=\"form-group\">\n <label>日本語</label>\n <?php echo $this->Form->input('EventsSchedule.'. $count . '.title', array('type' => 'text', 'placeholder' => 'スケジュールタイトル(日本語)', 'div' => false, 'label' => false, 'class' => 'form-control', 'required' => false)) ;?>\n </div>\n <div class=\"form-group\">\n <label>詳細</label>\n <?php echo $this->Form->input('EventsSchedule.'. $count . '.description', array('type' => 'text', 'placeholder' => 'スケジュール詳細(日本語)', 'div' => false, 'label' => false, 'class' => 'form-control', 'required' => false)) ;?>\n </div>\n </div>\n </div>\n </td>\n </tr>\n <tr>\n <td>\n <div class=\"form-inline\">\n <div class=\"ui fields\">\n <div class=\"form-group\">\n <label>開始時間</label>\n <?php echo $this->Form->input('EventsSchedule.'.$count. '.start_hour',array('type' => 'select','options' => Configure::read('Hour.codes'),'class' => 'select', 'div' => false, 'label' => false, 'class' => 'form-control', 'required' => false)); ?>:\n <?php echo $this->Form->input('EventsSchedule.'.$count. '.start_min', array('type' => 'select','options' => Configure::read('Minute.codes'),'class' => 'select', 'div' => false, 'label' => false, 'class' => 'form-control', 'required' => false)); ?> 〜 \n </div>\n <div class=\"form-group\">\n <label>終了時間</label> \n <?php echo $this->Form->input('EventsSchedule.'.$count. '.end_hour',array('type' => 'select','options' => Configure::read('Hour.codes'),'class' => 'select', 'div' => false, 'label' => false, 'class' => 'form-control', 'required' => false)); ?>:\n <?php echo $this->Form->input('EventsSchedule.'.$count. '.end_min', array('type' => 'select','options' => Configure::read('Minute.codes'),'class' => 'select', 'div' => false, 'label' => false, 'class' => 'form-control', 'required' => false)); ?>\n </div>\n </div>\n </div>\n </td>\n </tr>\n <?php $count++; ?>\n <?php endforeach; ?>\n <?php echo $this->Form->end(array('label' => '登録・編集', 'class' => 'btn btn-primary')); ?>\n \n```\n\nここまではなんとかで用意でき、以下のことが実現できません。 \n・更新を押した際にEvents_scheduleテーブルにevent_idが保存されない \n・スケジュールの入力欄を動的に追加できるようにしたい\n\nどなたかご教示いただけると幸いです。 \n宜しくお願い致します。",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T02:31:59.297",
"favorite_count": 0,
"id": "23330",
"last_activity_date": "2016-04-24T01:30:52.403",
"last_edit_date": "2016-03-23T04:03:13.903",
"last_editor_user_id": "8500",
"owner_user_id": "8500",
"post_type": "question",
"score": 0,
"tags": [
"cakephp"
],
"title": "CakePHPでhasManyを使った更新が上手くいかない",
"view_count": 1686
} | [
{
"body": "いろいろと例示コード上におかしな点がありますが、保存部分だけに絞って回答します。\n\n`EventsController::edit()`において`$this->Event->save()`の後に`$this->EventSchedule->saveAll()`を実行していますが、これはまとめて`saveAssociated`を使いましょう。\n\n<http://book.cakephp.org/2.0/ja/models/saving-your-data.html#model-\nsaveassociated-array-data-null-array-options-array>\n\n```\n\n if ($this->Event->saveAssociated($this->request->data)) {\n // 保存成功時の処理\n } else {\n // 保存失敗時の処理\n }\n \n```\n\nまた、View側でEvendScheduleのidが指定されていないため、このままではEventScheduleレコードが毎回新規作成されてしまいます。\n\nそこで、View側で\n\n```\n\n <?php\n foreach($this->request->data['EventsSchedule'] as $count => $Eventschedule): ?> \n <tr>\n <th rowspan=\"8\">スケジュール</th>\n <td>\n <?php echo $this->Form->hidden(\"EventsSchedule.$count.id\"); ?>\n \n```\n\nのようにして、EventsSchedule.idをhiddenでセットしておきます。\n\n(foreachループで$countをインクリメントしていますが、このようにforeachでキーとして取得すればインクリメントは不要ですよね。)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T01:03:12.407",
"id": "23435",
"last_activity_date": "2016-03-25T01:03:12.407",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2668",
"parent_id": "23330",
"post_type": "answer",
"score": 2
}
]
| 23330 | null | 23435 |
{
"accepted_answer_id": "23333",
"answer_count": 3,
"body": "割と量のある二次元配列に対して\n\n```\n\n print data\n \n```\n\nとした時に下記のように省略されるのですが、ファイルに書き出したいので全部出して欲しい時はどうすればよいですか?\n\n```\n\n [[a,b,c ..., x,y,z]\n [a,b,c ..., x,y,z]\n ....,\n [a,b,c ..., x,y,z]\n [a,b,c ..., x,y,z]]\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 4.0",
"creation_date": "2016-03-22T03:24:06.453",
"favorite_count": 0,
"id": "23332",
"last_activity_date": "2021-07-10T08:03:17.990",
"last_edit_date": "2021-07-10T08:03:17.990",
"last_editor_user_id": "3060",
"owner_user_id": "525",
"post_type": "question",
"score": 4,
"tags": [
"python"
],
"title": "Python で 二次元配列を print すると結果が省略されるが、全て表示させたい",
"view_count": 63718
} | [
{
"body": "`print <python-object>`\nとしたときにPythonのリストオブジェクトや辞書オブジェクトのプログラムコードのように出力されているのは、「たまたま」です。人間が見やすいように整形しているので、長い場合は途中で省略されます。\n\nデータを完全な状態でファイルに保存する、つまりシリアライズする方法はいくつかあります。このとき、どのようなフォーマットでファイルに書き出したいかによって実装方法は異なります。単に、人間が見るだけれあれば(再利用しないのであれば)、シリアライズをちゃんと考えるよりも楽に解決できそうです。\n\n人間が見やすければOKな出力(画面の横幅はきっと広い):\n\n```\n\n lines = []\n for r in data:\n lines.append(', '.join(r))\n print '\\n'.join(lines)\n \n```\n\nprint風味でprintを使って出力(Pythonのリストの文法と一致させる):\n\n```\n\n lines = []\n for r in data:\n lines.append('[' + ', '.join(r) + ']')\n print '[' + ',\\n'.join(lines) + ']'\n \n```\n\ncsvで出力(一般的に再利用しやすい方法):\n\n```\n\n import csv\n with open('file.csv', 'wt') as f:\n writer = csv.writer(f)\n writer.writerows(data)\n \n # csv.reader を使えば読み込みが出来ます\n \n```\n\npickleで出力(Pythonで再利用しやすい方法):\n\n```\n\n import pickle\n # write\n with open('file.p', 'wb') as f:\n pickle.dump(data, f)\n \n # read\n with open('file.p', 'rb') as f:\n d2 = pickle.load(f)\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T03:55:41.627",
"id": "23333",
"last_activity_date": "2016-03-22T03:55:41.627",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "806",
"parent_id": "23332",
"post_type": "answer",
"score": 7
},
{
"body": "これはnumpyですか?だとしたら\n\n```\n\n import numpy as np\n np.set_printoptions(threshold=np.inf)\n \n```\n\nと先頭でやれば全部表示されます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T04:51:40.413",
"id": "23336",
"last_activity_date": "2016-03-22T04:51:40.413",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7837",
"parent_id": "23332",
"post_type": "answer",
"score": 6
},
{
"body": "pandasなら\n\n```\n\n import pandas as pd\n pd.set_option('display.max_rows', 最大表示列数)\n pd.set_option('display.max_columns', 最大表示行数)\n \n```\n\nなのでこの最大値を10000000くらいにしたら、表示が可能です",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2020-06-09T19:02:13.877",
"id": "67471",
"last_activity_date": "2020-06-09T22:03:20.897",
"last_edit_date": "2020-06-09T22:03:20.897",
"last_editor_user_id": "19110",
"owner_user_id": "40556",
"parent_id": "23332",
"post_type": "answer",
"score": 1
}
]
| 23332 | 23333 | 23333 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "HTML+JavaScriptで出来ることって何ですか? \nAndroidアプリ、iOSアプリ等は作れるんですか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T06:07:55.750",
"favorite_count": 0,
"id": "23338",
"last_activity_date": "2016-03-22T06:30:44.250",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14888",
"post_type": "question",
"score": 0,
"tags": [
"javascript"
],
"title": "JavaScript+HTMLで開発",
"view_count": 147
} | [
{
"body": "HTMLはWebページを記述する言語です。それだけでは文章や画像、リンクを表示するといったことしかできませんが、Javascriptを組み合わせることで「ボタンを押したらメッセージを表示する」とか「別のサーバーから取得した情報を同じページに展開する」とか、Webページに動きを持たせることができます。\n\n基本的にはWebサーバーにブラウザからアクセスして表示・実行させるものですが、最近ではPC上やスマートフォン上で動くアプリを作るためにも使われるようになってきました。この場合、ブラウザの代わりに「HTMLを表示しJavascriptを実行する」土台が用意されているので、そこで動くように開発し、その土台とセットにして配布することになります。\n\n具体的には、PC向けだとElectronやNW.js、スマートフォン向けにはApache\nCordovaやMonacaといったものが存在します。ブラウザを埋め込んだアプリを自分で作ることもあります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T06:30:44.250",
"id": "23339",
"last_activity_date": "2016-03-22T06:30:44.250",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "23338",
"post_type": "answer",
"score": 2
}
]
| 23338 | null | 23339 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "MonacaからリリースビルドしたiOSアプリで \nApp Storeの情報で互換性の「iOS *.*以降。」のバージョンを変更したいのですが \nどのような設定をすれば変更する事が出来るのでしょうか。\n\nCordovaはバージョン5.2です。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T07:05:09.140",
"favorite_count": 0,
"id": "23342",
"last_activity_date": "2016-04-21T02:55:44.633",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14889",
"post_type": "question",
"score": 0,
"tags": [
"monaca"
],
"title": "iOS互換性表記の指定方法",
"view_count": 547
} | [
{
"body": "`MonacaApp-Info.plist`を編集しましょう \n下記のように記載すれば最小の対応OSを指定できます。\n\n```\n\n <key>MinimumOSVersion</key>\n <string>4.1</string>\n \n```\n\n[参考](http://docs.monaca.mobi/3.5/ja/reference/config/ios_configuration/)",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T10:18:05.063",
"id": "23347",
"last_activity_date": "2016-03-22T10:18:05.063",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "23342",
"post_type": "answer",
"score": 1
},
{
"body": "config.xmlに以下のようにdeployment-targetを指定してください。\n\n対応OS8.0以上の場合 \n`<preference name=\"deployment-target\" value=\"8.0\" />`",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-04-21T02:55:44.633",
"id": "24198",
"last_activity_date": "2016-04-21T02:55:44.633",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8532",
"parent_id": "23342",
"post_type": "answer",
"score": 0
}
]
| 23342 | null | 23347 |
{
"accepted_answer_id": "23345",
"answer_count": 2,
"body": "```\n\n <input type=\"text\" class=\"input\">\n <input type=\"text\" class=\"input\"> \n <input type=\"text\" class=\"input\">\n <input type=\"text\" class=\"input\">\n <input type=\"text\" class=\"input\">\n \n```\n\n上記のようなHTMLにて、 \n入力されているinputタグに処理をしたいのですが、\n\n```\n\n $('.input').each(function() {\n if ($(this).val()) {\n $(this).hogehoge;\n }\n });\n \n```\n\n↑のようにループ等使わずに、\n\n```\n\n $('xxxxxx').hogehoge;\n \n```\n\nと、1行で書く事はできないでしょうか。 \nよろしくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T07:14:07.763",
"favorite_count": 0,
"id": "23343",
"last_activity_date": "2016-03-22T08:34:49.130",
"last_edit_date": "2016-03-22T07:35:49.097",
"last_editor_user_id": "14688",
"owner_user_id": "14688",
"post_type": "question",
"score": 2,
"tags": [
"jquery"
],
"title": "jQuery 同classのinputタグから入力済みのものだけへの処理をループを使わずに書く方法",
"view_count": 1666
} | [
{
"body": "input等の要素が入力済みであるか、あるいはvalueプロパティを検査できるようなセレクタはjQueryにもないと思います。処理の部分をループの外に追い出したいということであれば\n[`.filter()`](https://api.jquery.com/filter/)\nを使う手はありますが、判定の部分はやはり無名関数を使うことになります。\n\n```\n\n $('button').on('click', function() {\r\n $('.input')\r\n .css('background', '') //reset\r\n .filter(function(){ return $(this).val() !== ''; })\r\n .css('background', 'gray');\r\n });\n```\n\n```\n\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\r\n <input type=\"text\" class=\"input\">\r\n <input type=\"text\" class=\"input\">\r\n <input type=\"text\" class=\"input\">\r\n <input type=\"text\" class=\"input\">\r\n <input type=\"text\" class=\"input\">\r\n <button>Check</button>\n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T07:54:33.953",
"id": "23344",
"last_activity_date": "2016-03-22T07:54:33.953",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "23343",
"post_type": "answer",
"score": 0
},
{
"body": "やりたい事によっては、input要素を`required=\"required`にしておき、:invalid擬似クラスを使う方法でもよさそうですね。 \n(jQueryの独自機能では無いですし、この手の事で単純な事は大抵CSSだけで出来ますが)\n\n```\n\n $('button').on('click', function() {\r\n $('input:invalid').css('background-color', 'orange');\r\n $('input:valid').css('background-color', 'lightgreen');\r\n });\n```\n\n```\n\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\r\n \r\n <input type=\"text\" required=\"required\"/>\r\n <button>Run</button>\n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T08:34:49.130",
"id": "23345",
"last_activity_date": "2016-03-22T08:34:49.130",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23343",
"post_type": "answer",
"score": 1
}
]
| 23343 | 23345 | 23345 |
{
"accepted_answer_id": "23349",
"answer_count": 1,
"body": "windows7でnpm installするとエラーが発生します \n`C:\\Users\\username\\package.json`が存在していないというエラーのようです \nどうすれば解決できるのでしょうか?\n\nnode5.9.0 \nnpm3.7.3 \nを使っています\n\n```\n\n \n npm WARN enoent ENOENT: no such file or directory, open 'C:\\Users\\username\\package.json'\n npm WARN username No description\n npm WARN username No repository field.\n npm WARN username No README data\n npm WARN username No license field.\n \n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T11:39:44.323",
"favorite_count": 0,
"id": "23348",
"last_activity_date": "2016-03-22T12:09:12.650",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5246",
"post_type": "question",
"score": 1,
"tags": [
"node.js",
"npm"
],
"title": "Windows7でnpm installするとエラーになる",
"view_count": 7423
} | [
{
"body": "`npm install` は、カレントディレクトリにある package.json に書かれた全パッケージを、同カレントディレクトリの\nnode_modules/ ディレクトリにインスールするコマンドです。よって package.json\nが存在しない場合には、動作の前提条件を満たせないためそのようなエラーになります。もしも本当に `npm install`\nを実行したいのであれば、package.json が存在するディレクトリに `cd` で移動した上で `npm install` してください。\n\n特定のパッケージをカレントディレクトリの node_modules/ ディレクトリへインストールしたいのであれば、 `npm install foobar`\nのようにパッケージ名を指定して実行する必要があります。またカレントディレクトリではなくグローバルにインストールしたい場合 `npm install -g\nfoobar` のように、`-g` オプションを付けて実行してください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T12:09:12.650",
"id": "23349",
"last_activity_date": "2016-03-22T12:09:12.650",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "208",
"parent_id": "23348",
"post_type": "answer",
"score": 4
}
]
| 23348 | 23349 | 23349 |
{
"accepted_answer_id": "37992",
"answer_count": 3,
"body": "プログラミングの問題ではないのかもしれませんが…質問させていただければと思います。\n\nHomebrew で Vim をインストールしようとすると \n下記のようなエラーが出て、インストールする事が出来ません。\n\n```\n\n $ brew install vim --with-lua\n ==> Downloading https://github.com/vim/vim/archive/v7.4.1589.tar.gz\n Already downloaded: /Library/Caches/Homebrew/vim-7.4.1589.tar.gz\n ==> ./configure --prefix=/usr/local --mandir=/usr/local/Cellar/vim/7.4.1589/share/man --enable-multibyte --with-tlib=ncurses --enable-cscope --with-compiledby=Homebrew --enable-luai\n ==> make\n Last 15 lines from /Users/akihiroyajima/Library/Logs/Homebrew/vim/02.make:\n /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -o objects/term.o term.c\n /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -o objects/ui.o ui.c\n /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -o objects/undo.o undo.c\n /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -o objects/window.o window.c\n /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -I/usr/local/include -o objects/if_lua.o if_lua.c\n /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -g -DPERL_DARWIN -fno-strict-aliasing -fstack-protector -I/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -o objects/if_perl.o auto/if_perl.c\n /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -g -DPERL_DARWIN -fno-strict-aliasing -fstack-protector -I/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -o objects/if_perlsfio.o if_perlsfio.c\n /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -I/Applications/MAMP/Library/include/python2.7 -DPYTHON_HOME='\"/Applications/MAMP/Library\"' -fPIE -o objects/if_python.o if_python.c\n if_python.c:67:10: fatal error: 'Python.h' file not found\n #include <Python.h>\n ^\n 1 error generated.\n make[1]: *** [objects/if_python.o] Error 1\n make[1]: *** Waiting for unfinished jobs....\n make: *** [first] Error 2\n \n READ THIS: https://git.io/brew-troubleshooting\n \n These open issues may also help:\n Make Install fails for Vim 7.4.1525 https://github.com/Homebrew/homebrew/issues/50197\n vim 7.4.488 build fails if Homebrew ruby is installed but /usr/bin/ruby comes first in PATH https://github.com/Homebrew/homebrew/issues/33705\n \n```\n\nエラー文に表示されている issue なども見ながら改善しようと思いましたが、 \n中々決定打が見つからず…といった感じです。\n\nよろしくお願いします。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T12:14:54.897",
"favorite_count": 0,
"id": "23350",
"last_activity_date": "2017-09-16T13:35:29.613",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9617",
"post_type": "question",
"score": 2,
"tags": [
"vim",
"homebrew"
],
"title": "Homebrew で Vim がインストールできない",
"view_count": 1853
} | [
{
"body": "`brew install python` で Python をインストールすると、Vim もインストールできるようになりました! \nご回答いただきありがとうございました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T09:06:53.230",
"id": "23450",
"last_activity_date": "2016-03-25T09:06:53.230",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9617",
"parent_id": "23350",
"post_type": "answer",
"score": 4
},
{
"body": "自分はbrew install vim --with-luaの時に同じ問題に遭遇しました。\n\n上記内容だけではできなかったので追加します。 \npyenvやcondaなどを利用している場合、pythonのパスが変更されることでこのエラーがおきる可能性があるようです。\n\n**自分の解決方法** \n1\\. .bashrcでのPATH変更の部分をコメントアウトし、terminalを再起動 \n2\\. brew install vim --with-lua実行 --> 成功 \n3\\. .bashrcのコメントアウトを外す",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-06-13T21:37:36.760",
"id": "35547",
"last_activity_date": "2017-06-17T01:09:29.060",
"last_edit_date": "2017-06-17T01:09:29.060",
"last_editor_user_id": "23772",
"owner_user_id": "23772",
"parent_id": "23350",
"post_type": "answer",
"score": 2
},
{
"body": "私はanyenvでpyenvを使用しており、同様のエラーに遭遇しました。\n\n以下のコマンドを実行したら成功しました。\n\n```\n\n $ pyenv local system\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-09-16T13:35:29.613",
"id": "37992",
"last_activity_date": "2017-09-16T13:35:29.613",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "25423",
"parent_id": "23350",
"post_type": "answer",
"score": 2
}
]
| 23350 | 37992 | 23450 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "カレンダー予約システムで、セッションに入ってる予約数を、在庫管理に組み込みたいのですがうまくいきません。 \nこちらの良いやり方があればアドバイスいただきたいです。\n\n【できているところ】 \nデータベースから商品番号を参照して、予約データの予約が入っている日の予約数を、在庫数$maxに参照して在庫の有る無しを判定\n\n在庫を調べるためのデータ \n$room_id 商品ID \n$reservday 日時 \n$max 在庫総数 ※ $max < $m で在庫無し\n\n1.予約データを取り出して、予約数を数える\n\n```\n\n $m =0;\n mysql_select_db($DBNAME, $connect);\n mysql_query(\"SET NAMES utf8\");\n $query = \"SELECT * FROM reserve_table WHERE type='$room_id' AND reserve_day='$reservday'\";\n $result = mysql_query($query) or die(mysql_error());\n while ($row = mysql_fetch_array($result)) {\n $m++;\n }\n \n```\n\n2.セッション$_SESSION[item]の中身\n\n```\n\n Array ( \n // [key]1商品×日程ごとの固有KEY [reserve_day]予約開始日 [renpaku]連泊数\n [0] => Array ( [key] => 1458583223 [type] => 5 [reserve_day] => 20160322 [renpaku] => 1 ) \n [1] => Array ( [key] => 1458583836 [type] => 5 [reserve_day] => 20160327 [renpaku] => 1 ) \n [2] => Array ( [key] => 1458584148 [type] => 1 [reserve_day] => 20160321 [renpaku] => 1 ) \n )\n \n```\n\n【やりたいこと】 \n1の$mに、セッション変数に入っている$mを予約数にプラスしたい。 \n下の書き方では正常な動作になりませんでした。こちらをどのように修正すればいいかアドバイスをいただけるとありがたいです。\n\n3.セッションの予約数をデータベースの予約数にプラスする\n\n```\n\n foreach ($_SESSION['item'] as $od => $val) {\n $type = $val[ room_id ];\n $reserve_day = $val[ reserve_Day ];\n $renpaku = $val[ renpaku ]; //連泊日数\n $ren = 0;\n \n if($type == $row[type]) {\n \n //連日予約用にreserve_dayを分断、月またぎの予約に対応\n $year = substr($reserve_day, 0, 4);\n $mon = substr($reserve_day, 4, 2);\n $day = substr($reserve_day, 6, 2);\n \n //連日予約の、全ての日が予約数に追加されるようにする\n for ($i = 1; $i <= $renpaku; $i++) {\n if ($renpaku >= 2) {\n $tomorrow = mktime(0, 0, 0, $mon, $day + $ren, $year);\n $reserve_day = date(Ymd, $tomorrow);\n }\n $ren++;\n }\n $m++; //ここが合っていない?\n }\n \n```",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T13:00:46.303",
"favorite_count": 0,
"id": "23351",
"last_activity_date": "2016-03-23T02:03:51.667",
"last_edit_date": "2016-03-22T14:15:18.707",
"last_editor_user_id": "13755",
"owner_user_id": "13755",
"post_type": "question",
"score": 0,
"tags": [
"php",
"session"
],
"title": "宿泊予約で、セッションに入ってる予約数を在庫管理に組込みたい",
"view_count": 295
} | [
{
"body": "明らかな間違いや良くないところが多数あり、基本的な部分から勉強された方が良いように思います。\n\n * `mysql_*`系の関数は古すぎて非推奨です\n * `SET NAMES utf-8`で文字エンコーディングを指定してはいけません\n * SQLに変数が直接埋め込まれており、事前にエスケープしていない場合はSQLインジェクションが可能になります。プレースホルダを使いましょう。(勧められませんが)エスケープする場合は漏れを防ぐため組み立てと同時やるのがセオリーです。\n * コメントでも指摘があるとおり、行数が必要なら取得した結果をループで回すのではなく`COUNT`を使いましょう。\n * 連想配列のキーが`'`や`\"`で括られておらず文字列リテラルになっていませんがいいんでしたっけ?\n * 連想配列から`room_id`をキーとする値を取得しようとしていますが、提示されたデータには含まれていません。(`type`の誤り?)\n * 同様に`reserve_Day`も。(`reserve_day`の誤り?)\n * 「連日予約」を処理しているループは、`$renpaku`の値を加算するだけでよいので不要\n\n宿泊予約ということですが、トランザクションを適切に扱わないとダブルブッキングのようなことがおきます(参考:[嵐のコンサートがあるとダブルブッキングしてしまうホテル予約システムを作ってみた\n| 徳丸浩の日記](http://blog.tokumaru.org/2015/05/blog-post.html)。\n\nwebアプリケーションは注意しないと簡単にセキュリティホールを作り込んでしまいます。少なくともIPAの[安全なwebサイトの作り方](http://www.ipa.go.jp/security/vuln/websecurity.html)は読んだ方がよいでしょう。「体系的に学ぶ\n安全なWebアプリケーションの作り方」(ISBN 4797361190)など信頼できる書籍で勉強されることをお勧めします。\n\nPHPそのものの入門書についてはおすすめ出来るものを知りません(読んだことないので)が、\"[「いちばんやさしいPHPの教本」のレビューを担当しました |\n徳丸浩の日記](http://blog.tokumaru.org/2015/05/php_8.html)\"の書評は参考になると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T00:40:02.760",
"id": "23360",
"last_activity_date": "2016-03-23T02:03:51.667",
"last_edit_date": "2016-03-23T02:03:51.667",
"last_editor_user_id": "5793",
"owner_user_id": "5793",
"parent_id": "23351",
"post_type": "answer",
"score": 2
}
]
| 23351 | null | 23360 |
{
"accepted_answer_id": "23378",
"answer_count": 1,
"body": "行列をパディングするコードをGoで書きました。 \nそこで下記のように並列化するものとしないものを用いてベンチマークを実行しました。しかしgoroutineを使ったほうが使わかなった方よりも時間がかかりメモリも多く使うという結果になりました。\n\ngoroutineを使ったほうが速くなると考えましたがなぜこのようなことが起こったのでしょうか。 \n下記に作成したコード、ベンチマークのコード、コマンド、結果を記述します。\n\n**コード**\n\n```\n\n import (\n \"errors\"\n \"fmt\"\n \"sync\"\n )\n \n // Matrix is object for matrix.\n type Matrix struct {\n Rows uint\n Cols uint\n M [][]float64\n }\n \n const (\n Zero = iota + 1\n Edge\n )\n \n // NewMatrix is constructor of Matrix.\n func NewMatrix(m [][]float64) *Matrix {\n return &Matrix{\n M: m,\n Rows: uint(len(m)),\n Cols: uint(len(m[0])),\n }\n }\n \n func (m *Matrix) edgePad(rows, cols uint, newMatrix [][]float64, w uint, y int, wg *sync.WaitGroup) {\n col := make([]float64, m.Cols)\n for x := 0; x < int(m.Cols); x++ {\n if y < int(w) && x < int(w) {\n col[x] = m.M[0][0]\n } else if y < int(w) && x > int(w)-1 && x < int(cols+w) {\n col[x] = m.M[0][x-int(w)]\n } else if y < int(w) && x > int(cols+w)-1 {\n col[x] = m.M[0][cols-1]\n } else if y > int(w)-1 && y < int(rows+w) && x < int(w) {\n col[x] = m.M[y-int(w)][0]\n } else if y > int(w)-1 && y < int(rows+w) && x > int(cols+w)-1 {\n col[x] = m.M[y-int(w)][cols-1]\n } else if y > int(rows+w)-1 && x < int(w) {\n col[x] = m.M[rows-1][0]\n } else if y > int(rows+w)-1 && x > int(w)-1 && x < int(cols+w) {\n col[x] = m.M[rows-1][x-int(w)]\n } else if y > int(rows+w)-1 && x > int(cols+w)-1 {\n col[x] = m.M[rows-1][cols-1]\n } else {\n col[x] = m.M[y-int(w)][x-int(w)]\n }\n }\n newMatrix[y] = col\n wg.Done()\n }\n \n // Pad pads the Matrix.\n func (m *Matrix) Pad(w uint, mode int) error {\n newMatrix := make([][]float64, m.Rows+w*2)\n rows, cols := m.GetSize()\n m.Cols = m.Cols + w*2\n m.Rows = m.Rows + w*2\n var wg sync.WaitGroup\n for y := 0; y < int(m.Rows); y++ {\n wg.Add(1)\n switch mode {\n case Zero:\n //go m.zero(...)この部分をかえました。\n m.zeroPad(rows, cols, newMatrix, w, y, &wg)\n case Edge:\n //go m.Edge(...)\n m.edgePad(rows, cols, newMatrix, w, y, &wg)\n }\n }\n wg.Wait()\n m.M = newMatrix\n return nil\n }\n \n```\n\n**ベンチマーク**\n\n```\n\n func BenchmarkEdge(b *testing.B) {\n m := GetMatrix(480, 360)\n for i := 0; i < b.N; i++ {\n err := m.Pad(7, Edge)\n if err != nil {\n b.Fatal(err)\n }\n }\n }\n \n func GetMatrix(rows, cols int) *Matrix {\n rand.Seed(time.Now().UnixNano())\n s := make([][]float64, rows)\n for y := 0; y < rows; y++ {\n col := make([]float64, cols)\n for x := 0; x < cols; x++ {\n col[x] = rand.Float64()\n }\n s[y] = col\n }\n return NewMatrix(s)\n }\n \n```\n\n**コマンド**\n\n```\n\n go test -cpu 4 -bench . -benchmem\n \n```\n\n**結果**\n\n**goroutineなし**\n\n```\n\n BenchmarkEdge-4 100 11697971 ns/op 12066503 B/op 1198 allocs/op\n \n```\n\n**goroutineあり**\n\n```\n\n BenchmarkEdge-4 200 18919942 ns/op 33900980 B/op 1901 allocs/op\n \n```\n\n**実行時間**\n\n**goroutineなし** : 1.193s \n**goroutineあり** : 4.581s\n\n**動作環境** \nMBA Intel Core i7 2.2 GHz \nコア数: 2 \nメモリ:8GB\n\n**追記**\n\nちなみにzeroPadはパディング部をEdgeの値でなく0で埋めます。goroutineのコストがこの計算よりも負荷が高いのではと想像しています。もし実装を変える事でgoroutineを有効活用できる方法があれば知りたいです。あとgoroutineを使わなかった時の処理速度(np/op)が遅いのに、繰り返し回数は大きくなっているのはなぜなんでしょうか",
"comment_count": 9,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T14:49:32.467",
"favorite_count": 0,
"id": "23353",
"last_activity_date": "2016-03-23T09:14:15.650",
"last_edit_date": "2016-03-23T07:04:06.543",
"last_editor_user_id": "7232",
"owner_user_id": "7232",
"post_type": "question",
"score": 3,
"tags": [
"go"
],
"title": "Goroutineを使うと性能が落ちるのはなぜか",
"view_count": 543
} | [
{
"body": "ベンチマークを取る場合、実行回数(`b.N`)を直接には指定できない様で、`-benchtime` オプションで調整するしかない様です。\n\n**動作環境**\n\nIntel Xeon E5-2640 2.6GHz \nコア数: 16 \nメモリ: 32GB \nGolang: 1.6\n\n**goroutineあり**\n\n```\n\n $ go test -cpu 4 -bench . -benchmem -benchtime=100ms\n testing: warning: no tests to run\n BenchmarkEdge-4 100 4283143 ns/op 12070650 B/op 1210 allocs/op\n PASS\n ok _/home/nemo 0.489s\n \n```\n\n**goroutineなし**\n\n```\n\n $ go test -cpu 4 -bench . -benchmem -benchtime=200ms\n testing: warning: no tests to run\n BenchmarkEdge-4 100 9670161 ns/op 12066484 B/op 1198 allocs/op\n PASS\n ok _/home/nemo 1.101s\n \n```\n\n**追記**\n\n```\n\n func BenchmarkEdge(b *testing.B) {\n m := GetMatrix(480, 360)\n for i := 0; i < b.N; i++ {\n err := m.Pad(7, Edge)\n \n```\n\n`m.Pad(7, Edge)` となっていますが、\n\n```\n\n // Pad pads the Matrix.\n func (m *Matrix) Pad(w uint, mode int) error {\n newMatrix := make([][]float64, m.Rows+w*2)\n rows, cols := m.GetSize()\n m.Cols = m.Cols + w*2\n m.Rows = m.Rows + w*2\n \n```\n\n1\nループ毎に行列のサイズが増大していくのですね(`+14`)…。なので、ベンチマークにおける実行回数が増えると実行時間が線形時間(`O(n)`)以上に増大していくことになります。\n\nそこで、`err := m.Pad(7, Edge)` を `err := m.Pad(0, Edge)`\nとしてベンチマークを実行してみました(意味のないことかも知れませんが)。\n\n**goroutineあり**\n\n```\n\n $ go test -cpu 4 -bench . -benchmem\n BenchmarkEdge-4 2000 937189 ns/op 1487671 B/op 486 allocs/op\n ok _/home/nemo 2.000s\n \n```\n\n**goroutineなし**\n\n```\n\n $ go test -cpu 4 -bench . -benchmem\n BenchmarkEdge-4 1000 1232650 ns/op 1488394 B/op 486 allocs/op\n ok _/home/nemo 1.389s\n \n```",
"comment_count": 7,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T07:56:55.087",
"id": "23378",
"last_activity_date": "2016-03-23T09:14:15.650",
"last_edit_date": "2016-03-23T09:14:15.650",
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "23353",
"post_type": "answer",
"score": 0
}
]
| 23353 | 23378 | 23378 |
{
"accepted_answer_id": "23355",
"answer_count": 1,
"body": "unix のシェルスクリプトであれば、 [posix](http://pubs.opengroup.org/onlinepubs/9699919799/)\nなどを参照すれば、どのような仕様になっているかがわかります。\n\nWindows でのバッチファイルについて、このような仕様についてまとまっているサイト・資料はありますか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T14:51:40.527",
"favorite_count": 0,
"id": "23354",
"last_activity_date": "2016-03-22T15:30:13.560",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 3,
"tags": [
"windows",
"batch-file"
],
"title": "バッチファイルの仕様がまとまっているサイト(資料?)はありますか。",
"view_count": 1255
} | [
{
"body": "私が知っているものとして、コマンドラインリファレンスがあります。\n\nコマンド ライン リファレンス \n<https://msdn.microsoft.com/ja-jp/library/cc778084(v=ws.10).aspx>\n\nこのページに各種解説へのリンクがあり、例えば下記のようなページへ芋づる式にたどっていけます。\n\nコマンド シェルの概要 \n<https://msdn.microsoft.com/ja-jp/library/cc737438(v=ws.10).aspx>\n\nバッチ ファイルを使用する \n<https://msdn.microsoft.com/ja-jp/library/cc758944(v=ws.10).aspx>\n\nバッチ パラメータを使用する \n<https://msdn.microsoft.com/ja-jp/library/cc755880(v=ws.10).aspx>\n\n日本語版にはリンクがない項目(`Setlocal`など)もありますので、そちらは英語版で見ることになるかと思います。\n\nCommand-line reference A-Z \n<https://technet.microsoft.com/library/bb490890.aspx>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T15:30:13.560",
"id": "23355",
"last_activity_date": "2016-03-22T15:30:13.560",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3068",
"parent_id": "23354",
"post_type": "answer",
"score": 8
}
]
| 23354 | 23355 | 23355 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "Xcodeでpython3.5の実行をしようとしています. \nとりあえずインストールは終え,ターミナル\"which\npython3\"と入力すると,\"/Library/Frameworks/Python.framework/Versions/3.5/bin/python3\"と出力されています. \nインストール自体は数ヶ月前に行い,そのときは正しくXcodeでpython3.5を実行することができました.\n\nしかし現在,Xcodeでの設定がうまくいかなくなってしまいました. \n(おそらくEl Capitanに更新したためではないかと思われます.) \n具体的に言いますと,Xcodeで\"Product - Scheme - Edit\nScheme\"で上記,\"/Library/Frameworks/Python.framework/Versions/3.5/bin/python3\"のpython3.5を指定する必要があります. \nしかし,python3.5がExecutableではなく書類のファイルになっていて,指定することができません. \nどうやら\".5\"という拡張子だと判断されているようです.\n\nどうすればよいでしょうか? \n何か解決法があればお願いします.",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-22T21:51:12.167",
"favorite_count": 0,
"id": "23357",
"last_activity_date": "2019-02-15T12:25:00.257",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13125",
"post_type": "question",
"score": 3,
"tags": [
"xcode",
"python",
"macos"
],
"title": "Mac(Xcode)でのpython3.5の設定について.",
"view_count": 847
} | [
{
"body": "右クリック→クイックルックで強引な気もしますが一応選択できましたよ",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-06-19T07:29:08.240",
"id": "26856",
"last_activity_date": "2016-06-19T07:29:08.240",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "16884",
"parent_id": "23357",
"post_type": "answer",
"score": 1
},
{
"body": "古い質問ですが私の場合Python3.6.8を使う必要がありまして \n`/Library/Frameworks/Python.framework/Versions/3.6/bin/python3` \nをコピーして \n`/Library/Frameworks/Python.framework/Versions/3.6/bin/python` \nにするとクリックして指定できました \n動作保証は...",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2019-02-15T12:25:00.257",
"id": "52798",
"last_activity_date": "2019-02-15T12:25:00.257",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "31797",
"parent_id": "23357",
"post_type": "answer",
"score": 0
}
]
| 23357 | null | 26856 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "お世話になります。\n\nmonacaで、Crosswalkプラグインを入れた状態で、 \nサーバと通信すると、下記エラーが出てしまいました。\n\n(できれば)サーバ側で何も設定すること無く、 \n正常に通信をする方法はありますでしょうか。\n\n===[エラー内容]=== \nXMLHttpRequest cannot load <http://xxxx.xxx.jp/xxxx.php/xxxxx> . No 'Access-\nControl-Allow-Origin' header is present on the requested resource. Origin\n'file://' is therefore not allowed access.",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T01:27:27.260",
"favorite_count": 0,
"id": "23361",
"last_activity_date": "2016-07-07T10:00:52.760",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13702",
"post_type": "question",
"score": 0,
"tags": [
"monaca",
"cordova"
],
"title": "Crosswalkプラグイン利用時、サーバ通信ができない",
"view_count": 233
} | [
{
"body": "残念ながら、Crosswalkプラグインの仕様上、サーバー側に\n\n```\n\n Access-Control-Allow-Origin: file://\n \n```\n\nや\n\n```\n\n Access-Control-Allow-Origin: *\n \n```\n\nの設定がないと、このエラーが出てしまうと思います。 \nビルドしたアプリでは、アプリのコード領域にindex.htmlがあるのでこのエラーが出ない \nのですが、Monacaデバッガーでは書き換え可能なファイル領域にindex.htmlがあるため、 \nこのエラーを避けられません。\n\nこの問題を解決するには、Crosswalkプラグイン側を改修する必要があります。試しに改修 \nしたものを \n<https://github.com/knight9999/cordova-plugin-crosswalk-webview> \nに用意しました。標準のCrosswalkプラグインを外して、こちらのプラグインを組み込み、 \nカスタムビルド版デバッガーを作成すれば、カスタムビルド版デバッガー上ではエラーが出ず \nにサーバー通信を行うことが出来るようになります。\n\nまた、この改修は何らかの形で、次期Monacaデバッガー(6.0.x系)に取り込む予定です。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-07-07T10:00:52.760",
"id": "27421",
"last_activity_date": "2016-07-07T10:00:52.760",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8848",
"parent_id": "23361",
"post_type": "answer",
"score": 1
}
]
| 23361 | null | 27421 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "仮定: \n・ユーザA \n・ユーザAのフォロワーにユーザB \n・ユーザBのフォロワーにユーザC\n\nユーザAがツイートしたとき,そのツイートをユーザBがRT(リツイート)して,さらにそのツイートをユーザCがRTしたとき,この流れをTwitter REST\nAPI を利用して取得する方法はありますか?\n\nつまり,以下のような波及する様子を取得したいです. \nツイート -> ユーザBがRT -> ユーザCがRT",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T02:18:53.507",
"favorite_count": 0,
"id": "23363",
"last_activity_date": "2016-07-02T12:08:06.973",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "11142",
"post_type": "question",
"score": 0,
"tags": [
"twitter"
],
"title": "Twitter REST API を用いてRTのRTをした流れを取得",
"view_count": 374
} | [
{
"body": "現実的では無いかも知れませんが、可能かも知れません。 \nRTは\"RT @id\"という文字列で始まる別のツイートIDで管理されます。\n\n 1. `statuses/retweets/:id`にオリジナルのツイートのIDを指定してレスポンスを取得\n 2. 1で取得したレスポンスの各RTのIDを`statuses/retweets/:id`に設定して再びRTを取得\n\nこれを繰り返せば取れるだろうと思います。 \nただし`statuses/retweets/:id`は15回/15分しか使えませんし、一度に100ツイートしか取得できないので、取得できる限界は15回RTされたところまで、また一度に100RT分の所在しか分かりません。これ以上取得するには15分ごとに時間を空けるしかなさそうです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-07-02T12:08:06.973",
"id": "27271",
"last_activity_date": "2016-07-02T12:08:06.973",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7966",
"parent_id": "23363",
"post_type": "answer",
"score": 1
}
]
| 23363 | null | 27271 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "> sudo mount -t cifs -o username=name,sec=ntlm //pass/共有したフォルダ /mnt/samba\n\nというコマンドを打ったのですがうまくいきませんでした。 \nWindowsから共有した場合はうまくいきました。 \nマウントできている方教えていただけると助かります。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T04:00:27.790",
"favorite_count": 0,
"id": "23367",
"last_activity_date": "2016-03-24T06:24:26.243",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14899",
"post_type": "question",
"score": 1,
"tags": [
"ubuntu"
],
"title": "Macで共有したフォルダをUbuntu でマウントするにはどうすればいいですか",
"view_count": 1354
} | [
{
"body": "[Apple Support\nCommunitiesのスレッド](https://discussions.apple.com/thread/3196311?start=30&tstart=0)\nによると `nounix,sec=ntlmssp` オプションが必用だそうです。試してみてください。\n\n(例) \n`mount.cifs //192.168.xxx.xxx/test /mnt/test/ -o\nuser=******,password=******,nounix,sec=ntlmssp`",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T06:24:26.243",
"id": "23409",
"last_activity_date": "2016-03-24T06:24:26.243",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5008",
"parent_id": "23367",
"post_type": "answer",
"score": 2
}
]
| 23367 | null | 23409 |
{
"accepted_answer_id": "23370",
"answer_count": 2,
"body": "Go言語で2次元配列を作成し、そこから部分的に取り出した配列を作りたい時にスライスを用いて下記のように記述しましたが、行は切り出せましたが列は切り出せませんでした。\n\n<https://play.golang.org/p/QSzCo8ffBw>\n\nつまり上の例では[5,5]を[3,3]になってほしいところが[3,5]になってしまっています。 \n列も含めスライスするにはどのようにすれば良いのでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T04:09:46.237",
"favorite_count": 0,
"id": "23368",
"last_activity_date": "2016-03-23T05:04:35.817",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7232",
"post_type": "question",
"score": 0,
"tags": [
"go"
],
"title": "Goで2次元配列の部分配列を得たい",
"view_count": 1075
} | [
{
"body": "残念ながらこのプログラムですと\n\n```\n\n m := [][]float64{\n {1, 1, 1, 0, 0},\n {0, 1, 1, 1, 0},\n {0, 0, 1, 1, 1},\n {0, 0, 1, 1, 0},\n {0, 1, 1, 0, 0},\n }\n \n```\n\nに対して、 `m[0:3][0:3]` は\n\n```\n\n n := m[0:3]\n n[0:3]\n \n```\n\nの処理をしたことと同じになってしまいます。行と列が同じ数だとわかりにくいので `n[0:2]` としたものが次のコードです。\n\n<https://play.golang.org/p/wUylO3DLyR>\n\n期待通りの動作をさせるには行ごとに必要な列を抜き出す処理を書いてあげないといけません。(次のコード参照)\n\n<https://play.golang.org/p/0YaZMQiA6o>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T04:44:39.263",
"id": "23370",
"last_activity_date": "2016-03-23T05:04:35.817",
"last_edit_date": "2016-03-23T05:04:35.817",
"last_editor_user_id": "216",
"owner_user_id": "216",
"parent_id": "23368",
"post_type": "answer",
"score": 0
},
{
"body": "この場合、`m[0:3][0:3]` は、\n\n```\n\n n = m[0:3]\n fmt.Println(n[0:3])\n \n```\n\nと同じなので、結果的に行単位でスライスする事になります(`m[0:3][0:3][0:3][0:3]...` の様に何度繰り返しても同じ)。\n\nですので、例えば以下の様にして部分行と部分列を切り出します。\n\n<https://play.golang.org/p/TtFNyNSnCs>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T04:56:17.997",
"id": "23371",
"last_activity_date": "2016-03-23T04:56:17.997",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "23368",
"post_type": "answer",
"score": 0
}
]
| 23368 | 23370 | 23370 |
{
"accepted_answer_id": "23670",
"answer_count": 1,
"body": "webフレームワークのbottleをインストールして、\n\n```\n\n from bottle import route, run\n \n @route('/')\n def home():\n return \"it is not fancy, but it is my home page\"\n \n run(host='localhost', port=9999)\n \n```\n\nを実行すると、\n\n```\n\n UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 0: invalid start byte\n \n```\n\nというエラーが出てしまいます。 \n調べてみると、socket.pyというスクリプトの\n\n```\n\n def getfqdn(name=''):\n \"\"\"Get fully qualified domain name from name.\n \n An empty argument is interpreted as meaning the local host.\n \n First the hostname returned by gethostbyaddr() is checked, then\n possibly existing aliases. In case no FQDN is available, hostname\n from gethostname() is returned.\n \"\"\"\n name = name.strip()\n if not name or name == '0.0.0.0':\n name = gethostname()\n try:\n hostname, aliases, ipaddrs = gethostbyaddr(name)\n except error:\n pass\n else:\n aliases.insert(0, hostname)\n for name in aliases:\n if '.' in name:\n break\n else:\n name = hostname\n return name\n \n```\n\nという箇所の\n\n```\n\n try:\n hostname, aliases, ipaddrs = gethostbyaddr(name)\n \n```\n\nという部分にエラーが出ているようです。 \nこのエラーを出なくするためにはどのようにすればいいのでしょうか? \nよろしくお願いします。",
"comment_count": 10,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T07:22:55.650",
"favorite_count": 0,
"id": "23375",
"last_activity_date": "2016-04-01T14:53:24.587",
"last_edit_date": "2016-03-23T07:49:31.273",
"last_editor_user_id": "216",
"owner_user_id": "9597",
"post_type": "question",
"score": 3,
"tags": [
"python",
"bottle"
],
"title": "PythonのフレームワークBottleを使用するとUnicodeDecodeErrorが出てしまいます。解決策を教えてください。",
"view_count": 429
} | [
{
"body": "マシン名(ホスト名)に日本語を使うのを止めると解決します。 \n現在のマシン名の確認は \n\n```\n\n import socket;\n print(socket.getfqdn())\n \n```\n\nで確認出来ます。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-04-01T14:53:24.587",
"id": "23670",
"last_activity_date": "2016-04-01T14:53:24.587",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23375",
"post_type": "answer",
"score": 1
}
]
| 23375 | 23670 | 23670 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "以下のオンクリックの時に、バリデーションアラートを作動させたいのですが、どのようにすればうまくいきますでしょうか。詳しい方、ご教示ください。宜しくお願い致します。\n\n```\n\n <a href=\"#\" onclick=\"document.insert.submit()\" id=\"senddiv\">保存する</a> \n \n \n <form id=\"form\" method=\"post\" name=\"insert\" action=\"\" enctype=\"multipart/form-data\">\n <input type=\"text\" name=\"tags\" id=\"tags\">\n </form>\n \n \n <script>\n $(function(){\n \n \n $('#form').submit(function() {\n \n if($('[name=\"tags\"]').val() == ''){\n alert(\"タグを記入してください。\");\n return false;\n }\n \n return true;\n \n });\n \n });\n </script>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T07:29:46.670",
"favorite_count": 0,
"id": "23376",
"last_activity_date": "2016-04-22T11:47:22.137",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8619",
"post_type": "question",
"score": -1,
"tags": [
"javascript"
],
"title": "javascriptでアラート表示",
"view_count": 218
} | [
{
"body": "aタグのonclick属性値を以下にすると良いと思います。\n\n```\n\n <a href=\"#\" onclick=\"$('#form').submit()\" id=\"senddiv\">保存する</a>\n \n```\n\nこれでJavaScript内で仕掛けているイベントハンドラが呼び出されるようになると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T09:22:54.130",
"id": "23382",
"last_activity_date": "2016-03-23T09:22:54.130",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "531",
"parent_id": "23376",
"post_type": "answer",
"score": 1
},
{
"body": "Safariで動かなくてもよければ、\n\n```\n\n <form method=\"post\" action=\"\" enctype=\"multipart/form-data\">\n <input type=submit value=\"保存する\"><br>\n <label>タグ: <input name=\"tags\" required></label>\n </form>\n \n```\n\nこれだけでほぼ目的は達せられると思います。JavaScriptは不要です。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T10:24:32.117",
"id": "23388",
"last_activity_date": "2016-03-23T10:24:32.117",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3475",
"parent_id": "23376",
"post_type": "answer",
"score": 0
}
]
| 23376 | null | 23382 |
{
"accepted_answer_id": "23380",
"answer_count": 1,
"body": "VBで特定の関数名を作成しようとするとVisual Studioがエラーも出ずに終了してしまいます。\n\n具体的には、Visual Studio\n2015上のVBでフォームアプリケーションを作成し、ボタン(Button1)を配置します。次にソースコードで以下のような関数を作成しようとすると\nset_Button1 まで入力したところでVisual Studioが終了してしまいます。\n\n```\n\n Private Sub set_Button1()\n \n End Sub\n \n```\n\n調べた限りでは set_ のほかに get_ でも落ちることからプロパティが関係しているのかとも思いますがよく分かりません。\n\nこの問題は関数名を入力するときに気をつけるしかないのでしょうか? \nあるいはなんらかの設定をすることでエラーを出すなどの対策が可能なのでしょうか? \nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T08:26:49.930",
"favorite_count": 0,
"id": "23379",
"last_activity_date": "2016-03-23T09:13:37.140",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14903",
"post_type": "question",
"score": 5,
"tags": [
"visual-studio",
"vb.net"
],
"title": "VB.NET で特定の関数名を作成しようとするとVisual Studio が落ちる",
"view_count": 641
} | [
{
"body": "Visual Studioの不具合だと思われるので、[Microsoft\nConnect](https://connect.microsoft.com/VisualStudio/Feedback)かWindowsフィードバックに報告のうえ、修正されるまでは自分で回避するしかないと思います。\n\n* * *\n\n原因を説明するとフォーム上に`Button1`を配置すると、`.designer.vb`に以下のようなコードが生成されます。\n\n```\n\n Friend WithEvents Button1 As System.Windows.Forms.Button\n \n```\n\nこの`WithEvents`フィールドはVB文法上はフィールド扱いですが、値の代入時にイベントハンドラーの設定が行われるため、内部的にはプロパティとなります。この`Button1`プロパティに対して生成される予約メソッド`set_Button1`の存在を想定していないため、エディターが異常終了しているのだと思われます。\n\n確認したところ、この問題は`WithEvents`に限らずプロパティ一般で発生するようです。\n\n```\n\n Class Hoge\n \n Property Fuga As String\n \n Sub set_Fuga()\n End Sub\n \n End Sub\n \n```\n\nもともと.NETではメソッド名にアンダーバーを使うことがあまり推奨されていないので、`SetButton1`等で代替するのが良いのではないでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T08:58:01.237",
"id": "23380",
"last_activity_date": "2016-03-23T09:13:37.140",
"last_edit_date": "2016-03-23T09:13:37.140",
"last_editor_user_id": "5750",
"owner_user_id": "5750",
"parent_id": "23379",
"post_type": "answer",
"score": 10
}
]
| 23379 | 23380 | 23380 |
{
"accepted_answer_id": "23390",
"answer_count": 2,
"body": "`clojure`初心者です。 \n非常に初歩的な質問ですみませんが、`clojure`といえども、`var`に対する再束縛は問題なくできると考えてよいのでしょうか?\n\n```\n\n user => (def a 100)\n user => a\n ; 100と表示\n user => (def a 200)\n user => a\n ; 200と表示\n \n```\n\n`clojure`が変数(`var`のこと)の参照先オブジェクトを変更できないイミュータブルな性質を持つことは`java`等の経験から理解できます。\n\nその一方で、関数型言語では「再代入」はできない、なんていう言葉も何度もそれとなく聞いておりまして、それはなんとなくそういうものなのかと思っていました。それゆえ、本日思わぬ形で上記の例に出会ってしまい、今までも似たようなものは見てたのでしょうが、はたと気がついて混乱しております。\n\n私の拙い理解では、これだと再代入は「できている」、`clojure`流の言葉では「再束縛」が起きているとでも言えばいいのでしょうか、とにかく同じ`var`に別の値を結びつけることができています。\n\n```\n\n user=> (defn xyz [] \n (let [abc 100] \n (let [abc 200] (+ abc 100))))\n user=> (xyz)\n 300\n \n```\n\n`let` を使っても同じことです。\n\n変数の値の再代入は他の言語でも普通にありますし、この動作がおかしいなどと言うつもりは毛頭ないのですが、いわゆる「関数型言語に再代入はない」的な言説が何を言わんとしているのかがわからなくなりました。再代入ができないのではなく、再代入を避けやすい、という意味で使われることが多いのでしょうか。\n\n「プログラミングclojure」という本を読みながら学習しているのですが、このことについては特に記述がないか、見つけられません。なので、しょーもない質問とは思いますが、おかしな理解をするのも良くないので、どなたか教えてくださると嬉しいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T09:42:01.687",
"favorite_count": 0,
"id": "23384",
"last_activity_date": "2018-04-29T02:53:02.010",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9403",
"post_type": "question",
"score": 1,
"tags": [
"clojure"
],
"title": "clojureで「再代入できない」と言われる意図は何なのか",
"view_count": 717
} | [
{
"body": "`def`は、その名前空間のトップレベルのvar(≒グローバル変数)を新しく作ります。まあこれは例外ですね。現代的なプログラミング言語では、グローバル変数の変更はあまり重要ではありませんし。\n\n`let`の入れ子の場合、「同じ名前だけど別の変数」を定義しているだけです。内側の`let`で`abc`に別の値を束縛しても、外側の`let`の`abc`は別の変数なので、影響を与えません。別の関数の仮引数の変数名が呼び出し元の変数名とカブっている場合(以下のコード片参照)とまったく同じです。\n\n```\n\n (defn foo [abc] (+ abc 100))\n (defn xyz [] (let [abc 100] (foo 200)))\n (xyz) ;;=> 300\n \n```\n\n変数を再代入できるというのは、同じ名前というだけではなく、同じ変数の値を変更できることです。たとえば以下のRubyコード片のような書き方は、Clojureだとそのままではできません(やるにはrefなどを使う)。\n\n```\n\n x = 3\n 3.times { x *= 2 }\n x #=> 24\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T11:12:18.347",
"id": "23390",
"last_activity_date": "2016-03-23T11:12:18.347",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4010",
"parent_id": "23384",
"post_type": "answer",
"score": 2
},
{
"body": "再束縛と再代入の違いは関数型を始めたころに僕も悩みました。どちらも同じじゃないかと \nしかし背景で起こっていることはかなり違います。 \n何を可変性(mutable)と呼び、何を不変性(immutable)と呼んでいるのかを理解するには下記の例が参考になるかもしれません。 \nCの例で申し訳ないのですが、以下のような記述は再代入です。\n\n```\n\n #include <stdio.h>\n int main(void) {\n char str[] = {'h','e','l','l','o','\\0'};\n printf(\"before value: %s\\n\",str);\n printf(\"before address: %x\\n\", &str);\n str[4] = ' ';\n printf(\"after value: %s\\n\", str);\n printf(\"after address: %x\\n\", &str);\n scanf(\"%c\\n\", &str); // to keep displaying the console window\n return 0;\n }\n \n```\n\n上記を実行してもらえばわかりますが、文字配列型変数strはstr[4]='\n'という変更(破壊的代入とも言います)を行った後でもメモリアドレスを共有しています。つまり再代入というのは、変数に紐づけられたメモリアドレスが格納している値を直接変更することをいいます。 \nここで'o'という文字は値として完全に上書きされており、メモリのどこを探しても'o'は出てきません。 \n一方でJavaやClojureなどの現代的な言語では文字列はimmutableとして実装されており、文字列への再代入は認められておりません。ではどのようにして上記のような変更を実現するのかというと、文字列型値\"hello\"とは別に文字列型値\"hell\n\"を生成し、文字列型変数strが指し示すメモリアドレスを\"hello\"から\"hell\n\"にすり替えるのです。ここでは変更前後でもはやメモリアドレスは同一のものを指しません。Javaが文字列をimmutableとして設計した理由については、おそらく下記URLのほうが詳しいので割愛いたします。 \n<https://stackoverflow.com/questions/22397861/why-is-string-immutable-in-java> \nまた、Javaはリストやマップなどのデータ構造をmutableとして設計しました。常識的に考えるとリストを変更するたびにオブジェクトをコピーする必要が出てきて著しく効率が悪いので、Javaはリストをimmutableとして設計しなかったのです。 \n一方でclojureは、haskellなどを参考にしimmutableの要件(つまり値を上書きしないこと)を満たしながら効率的にリストの入れ替えができるようにデータ構造を設計しました。ここでいう入れ替えとは再束縛のことで、再束縛を行っても過去の値(前述の例では'o')は消滅しないのです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2018-04-29T02:53:02.010",
"id": "43645",
"last_activity_date": "2018-04-29T02:53:02.010",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "25980",
"parent_id": "23384",
"post_type": "answer",
"score": 0
}
]
| 23384 | 23390 | 23390 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "依存が少なく(単体で動く)メール送信ライブラリはありますか? \nJavaMailなどではなく、通知用なのでとにかく送信だけのシンプルなものがいいです。 \n(メールサーバーを作らない、経由しない) \nCentOSでの`sendmail`コマンドのようなものが理想です。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T10:54:35.010",
"favorite_count": 0,
"id": "23389",
"last_activity_date": "2016-09-29T16:07:43.093",
"last_edit_date": "2016-09-29T16:07:43.093",
"last_editor_user_id": "5519",
"owner_user_id": "10346",
"post_type": "question",
"score": 6,
"tags": [
"java"
],
"title": "送信に特化したメール送信ライブラリ",
"view_count": 1277
} | [
{
"body": "Java で SMTP を扱うという観点なら [Apache Commons\nNet](http://commons.apache.org/proper/commons-net/) もあります。\n\nFTP や NNTP などのプロトコルも含まれていますので、jar は小さくはないですが。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-06-05T00:24:59.273",
"id": "25463",
"last_activity_date": "2016-06-05T00:24:59.273",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "15325",
"parent_id": "23389",
"post_type": "answer",
"score": 1
}
]
| 23389 | null | 25463 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "拡張子wavやm4aの複数ファイルからmp4に一括変換したいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T11:12:28.153",
"favorite_count": 0,
"id": "23391",
"last_activity_date": "2017-02-16T03:41:25.123",
"last_edit_date": "2017-02-16T03:41:25.123",
"last_editor_user_id": "49",
"owner_user_id": "525",
"post_type": "question",
"score": -1,
"tags": [
"ffmpeg"
],
"title": "複数ファイルをffmpegで一括変換したい",
"view_count": 9973
} | [
{
"body": "```\n\n for f in *.wmv ; do ffmpeg -i $f $f.mp4; done\n \n```\n\nワンライナーでこのように書けると思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T11:12:28.153",
"id": "23392",
"last_activity_date": "2016-03-23T11:12:28.153",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "525",
"parent_id": "23391",
"post_type": "answer",
"score": 0
}
]
| 23391 | null | 23392 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "UnityでRigidBodyを使用せずに壁ずりを再現したいと考えているのですが、 \n2点わからないことがあり困っています。壁ずりについて調べたところ \n「進行方向ベクトル」と「衝突点の法線」を使用すれば、 \n「壁ずりベクトル」が出せるといことは理解できたのですが、 \n・衝突点の法線ベクトルの出し方 \n・実際に壁ずりベクトルを出した後にどのように使用すればいいのか \nが分かりません。出来れば計算式をコードで見せていただけるとすごく助かります…",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T11:37:43.560",
"favorite_count": 0,
"id": "23393",
"last_activity_date": "2016-03-24T02:22:57.907",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14907",
"post_type": "question",
"score": 0,
"tags": [
"unity3d"
],
"title": "Unityでの壁ずり実装について質問させていただきます。",
"view_count": 2368
} | [
{
"body": "まず、衝突判定という面倒な計算を Unity や RigidBody(やCollider)\nコンポーネントなどが行っていることをご理解ください。それを使わないということは、同じことを自前で行うことになります。\n\n> ・衝突点の法線ベクトルの出し方\n\n壁と自分との衝突点を算出して、衝突した壁の法線を使います。 \nRigidbodyを使わないとなると Collider や Raycast\nも使わないとして、自前で壁の形状(メッシュの頂点や法線データ)を確認しつつ、自分の位置と移動ベクトルから衝突点を検索することになります。衝突判定にはポリゴンと線分の衝突か、2Dであれば線分同士の衝突判定でできると思います。\n\n> ・実際に壁ずりベクトルを出した後にどのように使用すればいいのか\n\nそもそも移動はどうしてるのでしょうか?壁ずりベクトルが算出できたら、その方向に移動すればいいだけです。他に摩擦とかあれば仕様に合わせて計算を追加していきます。\n\n> 出来れば計算式をコードで見せていただけるとすごく助かります\n\n計算式だけを示すことはできません。衝突判定には壁データ(頂点や法線など)へのアクセスが必須であり、まずは壁の形状が把握できなければ衝突判定はできません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T02:22:57.907",
"id": "23405",
"last_activity_date": "2016-03-24T02:22:57.907",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2079",
"parent_id": "23393",
"post_type": "answer",
"score": 2
}
]
| 23393 | null | 23405 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "```\n\n <select class=\"form-control\" style=\"border-radius: 0!important;\">\n \n```\n\nを指定しました。\n\nMacのFirefoxでは四角になりましたが、MacのChromeでは角丸のままで変化がありませんでした。\n\n知ってらっしゃる方、方法など教えてください。 \nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T13:40:08.300",
"favorite_count": 0,
"id": "23395",
"last_activity_date": "2016-03-23T14:29:18.983",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14910",
"post_type": "question",
"score": 0,
"tags": [
"html",
"css",
"bootstrap"
],
"title": "Bootstrapテンプレートで、<select class=\"form-control\"> の角丸を四角にしたい",
"view_count": 1850
} | [
{
"body": "`-webkit-appearance:none;` を指定してください。\n\n```\n\n <select class=\"form-control\" style=\"border-radius: 0!important; -webkit-appearance:none;\">\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T14:29:18.983",
"id": "23397",
"last_activity_date": "2016-03-23T14:29:18.983",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3475",
"parent_id": "23395",
"post_type": "answer",
"score": 1
}
]
| 23395 | null | 23397 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "<http://wisdom.sakura.ne.jp/system/winapi/win32/win85.html> \n上記のサンプルで二番目のリソースがエラーになる。\n\n```\n\n /*リソーススクリプト*/\n KITTY DIALOG 10 , 10 , 100 , 50\n FONT 12 , \"MS ゴシック\"\n CAPTION \"Magical nyan nyan TARUTO\" {\n LTEXT \"終了します\\nよろしいですか?\" , -1 , 5 , 5 , 90 , 20\n PUSHBUTTON \"OK\" , IDOK , 40 , 35 , 20 , 10\n PUSHBUTTON \"Cancel\" , IDCANCEL , 65 , 35 , 30 , 10\n }\n \n```\n\n上記の6行目のPUSHBUTTONでsynatx errorになります。また、これに付いては、`#include \"resource.h\"`で\n`#define IDOK 1001` の様にすると取り敢えずは動きますが。今度は、OKボタンを押してもIDOKを認識して来れません。\n\nなお、これに関しては7行目の\"Cancel\"に付いてもsyntax errorになります。何が悪いのでしょうか。\n\n済みません。悪い個所と正しい記述を回答願います。 \n宜しくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T13:55:36.887",
"favorite_count": 0,
"id": "23396",
"last_activity_date": "2016-03-24T07:42:10.643",
"last_edit_date": "2016-03-24T07:42:10.643",
"last_editor_user_id": "49",
"owner_user_id": "14909",
"post_type": "question",
"score": -1,
"tags": [
"windows",
"gcc"
],
"title": "windows7 mingw windresでsyntax errorになる、修正個所を教えて下さい。",
"view_count": 353
} | [
{
"body": "> `#include \"resource.h\"`で `#define IDOK 1001`の様にすると取り敢えずは動きますが。\n\nWindows\nSDKでは`IDOK`は`1`に、`IDCANCEL`は`2`に予約されています。これらの定数を手動で`#define`しても誤りではありませんが、SDKが提供するヘッダファイル`winres.h`を`#include`した方がよいです。\n\n> 今度は、OKボタンを押してもIDOKを認識して来れません。\n\nリソース上でOKボタンに割り当てたID(あなたのコードでは`1001`)と、WindowsがOKボタンに期待するID(前述した`1`)が不一致になっているためです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T07:40:16.430",
"id": "23413",
"last_activity_date": "2016-03-24T07:40:16.430",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "49",
"parent_id": "23396",
"post_type": "answer",
"score": 1
}
]
| 23396 | null | 23413 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Rを使って、図を作成する時に、 \nx-y座標のサイズを設定する方法について質問させていただいております。\n\n先に使用するサンプルデータ及び問題があるコードを書かせていただきます。\n\n以下のデータをsample.dataとして使用しています。\n\n```\n\n 1247211284201945,A-vector-1,0.028382835,0.327685692,0.288425494\n 1247211284201945,A-vector-10,-0.012618369,0.158331365,0.18369201\n 1247211284201945,A-vector-11,0.059614712,0.210239257,0.138845855\n 1247211284201945,A-vector-13,-0.07040885,-0.00684115,0.071109223\n 1247211284201945,A-vector-14,-0.043941759,0.166591033,0.223211813\n 1247211284201945,A-vector-15,0.026459552,-0.001095527,-0.023953769\n 1247211284201945,A-vector-16,0.054251654,-0.069467257,-0.11831891\n 1247211284201945,A-vector-17,0.058789968,0.021960568,-0.035599055\n 1247211284201945,A-vector-18,-0.035810968,0.029101298,0.05980141\n 1247211284201945,A-vector-19,-0.005040805,-0.020944664,-0.008700876\n \n```\n\nこのデータの3列目と4列目を使用する仮定してください。 \nそのときに使用したコードは、\n\n```\n\n library(hexbin)\n read.table(\"sample.data\", sep=',')->DATA\n bin<-hexbin(DATA[[3]], DATA[[4]], xbins=10, xbnds=range(-0.8,0.1), ybnds=range(-1,2))\n plot(bin, main=\"Hexagonal Binning\")\n \n```\n\nここでは、x座標を-0.8から0.1まで、y座標を-1から2までを想定しています。 \nしかし実際にplotしてみますと、 \nx座標は、-0.1から0.15、 \ny座標を、-0.4から0.4 \nになってしまっています。\n\nxbndsやc(),\nxlimなどいろいろなものを試したのですが、x-yのサイズを自分がほしいレンジに設定することができませした。webでも探してみましたが、設定の方法がわかりませんでした。\n\nもしhexbinを使用して図を作成するときに、x-yサイズを設定する方法をお知りの方は、ご教授をお願いします。よろしくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T20:37:38.760",
"favorite_count": 0,
"id": "23398",
"last_activity_date": "2016-03-23T20:37:38.760",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "11048",
"post_type": "question",
"score": 4,
"tags": [
"r"
],
"title": "R {hexbin} libraryを使用してplotする時のx-y rangeの設定について",
"view_count": 399
} | []
| 23398 | null | null |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "制御が出来ません。何がいけないのですか?\n\n```\n\n package com.company;\n \n \n import java.io.*;\n import java.util.*;\n import java.util.concurrent.TimeUnit;\n \n \n public class Main {\n static boolean b = true;\n static Thread stdRun = null;\n public static void main(String[] args) {\n \n Runnable inputStreamThread = new Runnable(){\n public void run(){\n \n while(b){\n try{\n //System.out.println(\"Thread stdRun start\");\n TimerTask task = new TimerTask() {\n public void run() {\n b=false;\n }\n };\n Timer timer = new java.util.Timer();\n timer.schedule(task, TimeUnit.SECONDS.toMillis(1));\n while(true){\n System.out.println(\"テスト\");\n Thread.sleep(200);\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n b=false;\n }\n \n }\n \n };\n \n stdRun = new Thread(inputStreamThread);\n /* スレッドを開始します。 */\n stdRun.start();\n \n /* スレッドが終了するのを待機 */\n try {\n stdRun.join();\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n \n System.out.println(\"スレッドは正常に終了\");\n \n }\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T21:14:38.670",
"favorite_count": 0,
"id": "23399",
"last_activity_date": "2016-03-30T03:07:11.307",
"last_edit_date": "2016-03-23T21:16:57.970",
"last_editor_user_id": "3605",
"owner_user_id": "14913",
"post_type": "question",
"score": -1,
"tags": [
"java"
],
"title": "スレッドをタイムスケジュールで終了させるプログラム",
"view_count": 805
} | [
{
"body": "もう少しやりたいことを明確にしていただけると助かるのですが、こういうことでしょうか?\n\n```\n\n import java.io.*;\n import java.util.*;\n import java.util.concurrent.TimeUnit;\n \n public class test {\n static boolean b = true;\n static Thread stdRun = null;\n public static void main(String[] args) {\n \n Runnable inputStreamThread = new Runnable(){\n public void run(){\n \n try{\n //System.out.println(\"Thread stdRun start\");\n TimerTask task = new TimerTask() {\n public void run() {\n System.out.println(\"run\");\n stdRun.interrupt();\n }\n };\n Timer timer = new java.util.Timer();\n timer.schedule(task, TimeUnit.SECONDS.toMillis(1));\n \n while (true) {\n System.out.println(\"テスト\");\n Thread.sleep(200);\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n \n };\n \n stdRun = new Thread(inputStreamThread);\n /* スレッドを開始します。 */\n stdRun.start();\n \n /* スレッドが終了するのを待機 */\n try {\n stdRun.join();\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n \n System.out.println(\"スレッドは正常に終了\");\n \n }\n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-23T22:25:26.000",
"id": "23400",
"last_activity_date": "2016-03-24T11:33:21.760",
"last_edit_date": "2016-03-24T11:33:21.760",
"last_editor_user_id": "5288",
"owner_user_id": "5288",
"parent_id": "23399",
"post_type": "answer",
"score": 1
},
{
"body": "ん…それでは無限ループしますよ?\n\ntimer.schedule() のあとの while で無限ループしているので \nタイマーが作動しても while(b) は一生実行されません。\n\nタイマータスクでスレッドを強制終了(kill)などしているなら話は別ですが、 \n今回はフラグを変えているだけなので一定時間にフラグを見る処理すなわち\n\ntimer.schedule() の下の while(true) は while(b) とすべきです。\n\nそれだと最初の行の while(b) の存在意味がよくわからなくなりますが、なにか事情があるのでしょう",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-30T03:02:03.573",
"id": "23605",
"last_activity_date": "2016-03-30T03:07:11.307",
"last_edit_date": "2016-03-30T03:07:11.307",
"last_editor_user_id": "10346",
"owner_user_id": "10346",
"parent_id": "23399",
"post_type": "answer",
"score": 1
}
]
| 23399 | null | 23400 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "vmstat -a 5 で取得した、数日分のファイルがあります。 \nメモリ使用率の平均を算出するために、Freeの使用量平均を知りたいのですが、awkで加算すると桁溢れしてしまい、上手くいきません。\n\nシェルスクリプトの中で以下のように \nしています。\n\n```\n\n VAR=`awk '{m+=$4} END{print m/NR;}' ${myfile}`\n \n```\n\n良い方法がありましたら教えていただけないでしょうか。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T00:51:35.147",
"favorite_count": 0,
"id": "23401",
"last_activity_date": "2016-03-24T07:47:03.250",
"last_edit_date": "2016-03-24T03:59:29.767",
"last_editor_user_id": "3054",
"owner_user_id": "9807",
"post_type": "question",
"score": 4,
"tags": [
"shellscript",
"awk"
],
"title": "awkで大きい数の平均を出そうとすると桁溢れしてしまう",
"view_count": 2248
} | [
{
"body": "### 表記の問題\n\n表示が指数表記(科学表記)になるのを避けるには、`printf`を使いフォーマットを指定する方法があります。\n\n```\n\n printf \"%d\\n\", m;\n \n```\n\n`OFMT`であらかじめ`print`(\"f\"が付かない方)が使うフォーマットを決めておく方法もあります。\n\n```\n\n BEGIN{OFMT=\"%d\"}\n \n```\n\n### データが巨大な場合\n\n今回の質問者さんのケースは違っていましたが、 \n巨大なデータの平均などを出す場合、一つの浮動小数点数に集積していく計算方法だとどうしても精度の問題があります。計算方法を工夫しても、後半のデータが反映されない等の気付きづらい問題が発生しがちです。\n\nこの場合は他の方のコメントのように、任意精度演算(多倍長演算)が行なえる物を使うのが簡単です。 \n一定期間毎に平均を出しておいて、後でそれらの平均を求める方法もありますね。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T03:51:53.993",
"id": "23406",
"last_activity_date": "2016-03-24T07:47:03.250",
"last_edit_date": "2016-03-24T07:47:03.250",
"last_editor_user_id": "3054",
"owner_user_id": "3054",
"parent_id": "23401",
"post_type": "answer",
"score": 1
},
{
"body": "```\n\n awk '{ a+=($4-a)/NR } END{ print a }'\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T05:18:52.997",
"id": "23408",
"last_activity_date": "2016-03-24T05:18:52.997",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "4010",
"parent_id": "23401",
"post_type": "answer",
"score": 3
}
]
| 23401 | null | 23408 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "php→mysqlへ接続ができず非常に困っています。 \nPHPのコードは以下になります。\n\n```\n\n <?php\n $mysqli=new mysqli('localhost','ユーザ名','ホスト名');\n \n if($mysqli->connect_error){\n die('Connect Error('.$mysqli->connect_errno.')'.$mysqli->connect_error);\n }else{\n echo \"接続成功\";\n }\n ?>\n \n```\n\n上記コードで試すとWarning: mysqli::mysqli(): (HY000/1045): Access denied for user\n'ユーザ名'@'localhost' (using password: YES) というエラーが発生します。 \n調べるとユーザ名かエラー名が間違っている際にこのエラーが発生すると記載があったので、DBからユーザ名、パスワードまで全て作り直して再度トライしたのですが、このエラーから抜け出せません。\n\nちなみに、パスワード名を空にすると接続成功になります。 \nもう長い間解決策を探し続けているのですが見つからず、、、どなたか教えていただければ大変助かります。\n\n宜しくお願いします。\n\n※※※ \nコメント有難うございました! \n先ほどphpmyadminをいじっていたら、PW有りで接続できました。 \n恐らく、ターミナル内ではなくphpmyadmin内でユーザ名、PW名を作成していなかったことが原因だと思います。\n\nただ、データベースへの接続はできたのですが、DBの選択ができません。 \nphpmyadmin内でDBを作成したのですが、php外部ファイルから指定するとエラーが起こります。 \nすみません、初心者なのでうまく説明できませんが、、、",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T01:14:34.447",
"favorite_count": 0,
"id": "23403",
"last_activity_date": "2016-03-24T05:40:32.787",
"last_edit_date": "2016-03-24T05:40:32.787",
"last_editor_user_id": "14914",
"owner_user_id": "14914",
"post_type": "question",
"score": 0,
"tags": [
"php",
"mysql"
],
"title": "phpからmysqlへの接続",
"view_count": 7016
} | []
| 23403 | null | null |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "以前の質問の意図を簡略化するために改めて書いたコードですTimerTaskを使い制御するのでbreakなどの制御文は使えないです。何故Lをfalseにしてるのに終わらないのですか?\n\n```\n\n public class Main {\n \n public static void main(String[] args) {\n boolean K = true;\n boolean L = true;\n \n while(and(K,L)){\n System.out.println(\"test\");\n L = false;\n }\n }\n \n public static boolean and(boolean a, boolean b){\n if(a = true){\n if(b = true){\n return true;\n }\n }\n return false;\n }\n \n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T06:53:20.313",
"favorite_count": 0,
"id": "23410",
"last_activity_date": "2016-05-14T04:53:51.683",
"last_edit_date": "2016-03-24T07:25:22.837",
"last_editor_user_id": "14913",
"owner_user_id": "14913",
"post_type": "question",
"score": 4,
"tags": [
"java"
],
"title": "= での比較がうまくいかない",
"view_count": 424
} | [
{
"body": "`=`だと代入になります。比較演算子の `==` を使うと動くはずです。\n\n```\n\n if(a == true){\n \n```\n\nもしくは、\n\n```\n\n if(a){\n \n```\n\nだけでもいいですね。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T07:07:20.997",
"id": "23411",
"last_activity_date": "2016-03-24T07:07:20.997",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23410",
"post_type": "answer",
"score": 10
},
{
"body": "Javaに限らず、殆どのプログラミング言語での = は代入です。 \nあなたのコードは aの値をtrueにしてからaの中身を見てif判定 していることになります。 \n(bも同じです)\n\n```\n\n if(a = true){//判定結果は絶対にtrueにしかならない\n // aは絶対true(当たり前)\n if(b = true){//判定結果は絶対にtrueにしかならない\n //bは絶対にtrue(当たり前)\n return true;\n } else {\n // ここでもbは絶対にtrue\n }\n } else {\n // ここでもaは絶対true\n }\n \n \n \n //正しい例\n if(a == true){\n if(b == true){\n return true;\n }\n }\n \n```\n\n要するに、あなたの書いたコードは分解すると下になります\n\n```\n\n a = true;\n if (a == true) {\n b = true;\n if (b == true) {\n }\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T10:56:51.737",
"id": "23546",
"last_activity_date": "2016-03-29T01:45:38.380",
"last_edit_date": "2016-03-29T01:45:38.380",
"last_editor_user_id": "10346",
"owner_user_id": "10346",
"parent_id": "23410",
"post_type": "answer",
"score": 2
}
]
| 23410 | null | 23411 |
{
"accepted_answer_id": "23417",
"answer_count": 1,
"body": "以下のサイトの記事の右下にplusoneのカウント数が表示されていますが、この数字を取得したいです。 \n[https://play.google.com/store/apps/details?id=com.nintendo.zaaa&hl=ja](https://play.google.com/store/apps/details?id=com.nintendo.zaaa&hl=ja)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T07:28:35.763",
"favorite_count": 0,
"id": "23412",
"last_activity_date": "2016-03-24T09:13:49.160",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10111",
"post_type": "question",
"score": 1,
"tags": [
"python"
],
"title": "Pythonでplusoneのカウント数取得する方法",
"view_count": 88
} | [
{
"body": "まず目的の要素をブラウザの開発ツールで調査します。 \nすると、G+のボタンは生成された`iframe`の中に入っている事が分かります。 \n`iframe`の`src`を見ると、パラメータがいろいろありますが、必要そうなのは`url`だけです。 \n`url`だけ残すとこの様になります。 \n<https://apis.google.com/u/0/_/+1/fastbutton?url=https%3A%2F%2Fmarket.android.com%2Fdetails%3Fid%3Dcom.nintendo.zaaa>\n\n後はこれをGETしてスクレイピングすればよいです。 \n数字の部分は`id=\"aggregateCount\"`ですね。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T09:13:49.160",
"id": "23417",
"last_activity_date": "2016-03-24T09:13:49.160",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23412",
"post_type": "answer",
"score": 0
}
]
| 23412 | 23417 | 23417 |
{
"accepted_answer_id": "23467",
"answer_count": 1,
"body": "UITextFieldのテキストを省略表示させずにフォントサイズを小さくして、すべてのテキストを枠の中に表示させようとしています。 \nこのとき、minimumFontSizeとadjustsFontSizeToFitWidthを設定し、xibでも同様の設定を行いましたが、画像のようにUITextFieldの文字のフォントが変わらず省略表示されてしまいます。下記に添付したコードは、すべてviewDidLoadに書かれており、その他のライフサイクルのメソッドにはコードを書いておりません。\n\nUIButton,UILabelについてもadjustsFontSizeToFitWidthの設定を行い、比較すると、これら2つはフォントサイズが可変となり、枠内にすべて収まりました。 \n \n環境はiOS9.2, Xcode7.2.1となります。\n\nどなたか原因の分かる方いらっしゃいますでしょうか。\n\n```\n\n self.textField.minimumFontSize = 1.0f;\n self.textField.adjustsFontSizeToFitWidth = YES;\n [self.textField setText:@\"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\"];\n self.textField.backgroundColor = [UIColor colorWithRed:241.0f/255.0f green:247.0f/255.0f blue:210.0f/255.0f alpha:1.0f];\n \n```\n\n[](https://i.stack.imgur.com/CN7fP.png)\n\n[](https://i.stack.imgur.com/N4urW.png)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T09:00:26.420",
"favorite_count": 0,
"id": "23415",
"last_activity_date": "2016-03-26T00:42:29.597",
"last_edit_date": "2016-03-25T00:48:18.670",
"last_editor_user_id": "14923",
"owner_user_id": "14923",
"post_type": "question",
"score": 1,
"tags": [
"ios",
"objective-c"
],
"title": "UITextFieldですべてのテキストを枠に表示させたい",
"view_count": 1705
} | [
{
"body": "以下の質問は同様の現象ではないでしょうか。 \nこのページでの解決方法は、テキストをセットした、もしくはテキストが変化した時に適切なフォントを計算してフォントをセットし直しているようです。 \n[iphone - Can't get UITextField to autoshrink text - Stack\nOverflow](https://stackoverflow.com/questions/16350045/cant-get-uitextfield-\nto-autoshrink-text#comment35588809_16356147)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T00:42:29.597",
"id": "23467",
"last_activity_date": "2016-03-26T00:42:29.597",
"last_edit_date": "2017-05-23T12:38:55.307",
"last_editor_user_id": "-1",
"owner_user_id": "238",
"parent_id": "23415",
"post_type": "answer",
"score": 0
}
]
| 23415 | 23467 | 23467 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "以下のリレーションのmodelがあります。\n\n```\n\n class Question\n has_many :answeres\n accepts_nested_attributes_for :answeres\n end\n \n \n class Answere\n belongs_to :question\n end\n \n \n```\n\nそのような前提の中、controller内で、 \[email protected] \nとしようとすると、\n\nNoMethodError: undefined method `attributes' for\n#Answere::ActiveRecord_Associations_CollectionProxy\n\nというエラーが出ます。\n\n```\n\n ※ ApplicationControllerは継承しております。記号をつけると、うまく表示されないため、省略\n \n class QuestionsController\n @question.answeres.attributes = answere_params\n \n private\n \n def answere_params\n xxxxxx\n end\n end\n \n \n```\n\n1対1のリレーションの時では、attributesメソッドは使用できるのですが、今回のような1対多の関係では、どのように実装するのが一般的なのでしょうか?\n\nなお、answere_paramsの実装は、デバッグ中に確認しており、動作は問題ありません。 \n期待する値が入っているのですが、それを、最終的に、answere内につめこみ保存したいです。\n\n不足点がございましたら補足致します。\n\n宜しくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T09:02:53.130",
"favorite_count": 0,
"id": "23416",
"last_activity_date": "2016-04-23T11:09:39.683",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13175",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails",
"ruby"
],
"title": "1対多の関係の際に、attributesメソッドがつかえず、次のエラーがでます。NoMethodError: undefined method `attributes' for #Answere::ActiveRecord_Associations_CollectionProxy",
"view_count": 2366
} | [
{
"body": "`@question.answers`は `answer`のコレクションになるので、`answer`\nの`attributes`を取得したい場合は以下のように呼び出せば良いと思います。\n\n```\n\n @question.answers.first.attributes\n \n```\n\nまた`@questions`に新しい`answer`を追加するには幾つかの方法がありますが、`build`を利用してみるはいかがでしょうか。\n\n```\n\n @anwser = @question.answers.build(answer_params)\n if @anwser.save\n …\n else\n …\n end \n \n```\n\n参考: [Railsガイド 4.3.1.14 collection.build(attributes = {},\n...)](http://railsguides.jp/association_basics.html#has-\nmany%E3%81%A7%E8%BF%BD%E5%8A%A0%E3%81%95%E3%82%8C%E3%82%8B%E3%83%A1%E3%82%BD%E3%83%83%E3%83%89-collection-\nbuild-attributes)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T09:52:49.613",
"id": "23418",
"last_activity_date": "2016-03-24T09:52:49.613",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2646",
"parent_id": "23416",
"post_type": "answer",
"score": 1
}
]
| 23416 | null | 23418 |
{
"accepted_answer_id": "23466",
"answer_count": 2,
"body": "ActiveRecord::RecordNotFound in NotesController#showと表示されました。 \nCouldn't find Note with 'id'=showとさらに表示されました。 \nnotes_controller.rbのprivateメソット以下のset_noteメソットがおかしいようで \ndef set_note \n@note = Note.find(params[:id])←ここの部分がおかしい \nend \nと表示されました。 \nidがshowメソットに記されていないという認識で間違いないですよね? \nSequelProを見ても、notesテーブルにきちんと投稿したカラムにidが書かれています。 \n何かコマンドを打ち忘れ、データが反映されていないのでしょうか? \n回答お願いします。 \nroutes.rbは \nRails.application.routes.draw do\n\ndevise_for :users \nresources :users, only: [:index, :show, :edit, :update] \nresources :notes, only: [:show, :create, :edit, :update, :destroy]\n\nget'/top' => 'home#top'\n\nget'/connection' => 'home#connection' \nget'/notes/new' => 'notes#new' \npost'/notes' =>'notes#create' \nget'/notes' =>'notes#index' \nget'/show' =>\"notes#show\" \nget'/edit' =>'notes#edit' \npatch'/notes/:id' =>\"notes#update\",as:'update_note' \ndelete'/notes/:id' =>\"notes#destroy\",as:'destroy_note'\n\npost '/like/:note_id' => 'likes#like', as: 'like' \ndelete '/unlike/:note_id' => 'likes#unlike', as: 'unlike'\n\nroot 'home#top' \nget'/about' => 'home#about' \nend \nのようになっています。 \nidはshowである、のように記述していないのでは?と思って困っています。 \nお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T12:11:17.410",
"favorite_count": 0,
"id": "23420",
"last_activity_date": "2016-03-25T23:57:34.960",
"last_edit_date": "2016-03-25T01:56:12.323",
"last_editor_user_id": "14754",
"owner_user_id": "14754",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "ActiveRecord::RecordNotFound in NotesController#showの意味",
"view_count": 3770
} | [
{
"body": "`params[:id]`が\"show\"になっているようです。 \nこれは`http://server/notes/show`か`http://server/notes/show/1`のようなURLでnoteを表示(show)しようとしている、ということだと思います。実際は`http://server/notes/1`とか、`/notes/[id]`の形式で表示(show)します。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T21:00:30.650",
"id": "23432",
"last_activity_date": "2016-03-24T21:00:30.650",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14928",
"parent_id": "23420",
"post_type": "answer",
"score": 0
},
{
"body": "_idがshowメソットに記されていないという認識で間違いないですよね? \nidはshowである、のように記述していないのでは?_\n\n間違いです。\n\n`Couldn't find Note with\n'id'=show`は「Noteクラスで表されるデータの中には'id'フィールドの値が\"show\"であるものは見つかりませんでした」と言っています。「idはshowである」のような記述が必要だと言っているのではありません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T23:57:34.960",
"id": "23466",
"last_activity_date": "2016-03-25T23:57:34.960",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "23420",
"post_type": "answer",
"score": 0
}
]
| 23420 | 23466 | 23432 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "adb shellで使える実行可能なネイティブバイナリを作ったのですが、それをadb\nshellに入るコマンドと別に実行するとうまくいくのですが、一続きで実行するとうまくいきません。 \n解決策がお分かりの方是非教えていただけませんでしょうか。\n\nうまくいくコマンド\n\n```\n\n (C:\\user~)$ adb shell\n (adb shell上)$ /data/local/tmp/makeaction < /mnt/sdcard/testtap.txt\n \n```\n\nうまくいかないコマンド(これをうまくいかせたい)\n\n```\n\n (C:\\user~)$ adb shell /data/local/tmp/makeaction < /mnt/sdcard/testtap.txt\n 指定されたパスが見つかりません。\n \n```\n\nちなみに、どこまでうまくいっているか調べるために以下のように実行したところmakeactionが実行されているのは確認できました。\n\n```\n\n (C:\\user~)$ adb shell /data/local/tmp/makeaction\n \n```\n\nさらに以下のように実行するとエラーは出ないものの先程のmakeactionのみで実行したときと同じ実行結果となりました。\n\n```\n\n adb -s HT36MS908593 shell /data/local/tmp/makeaction < C:\\testtap.txt\n \n```\n\nこれらより「<」の右の指定先には何らかの制限があるのかと思うのですがここでつまずいております。 \nどうかよろしくお願いします。\n\nちなみに、こちらのサイトを参考にさせていただきました。 \n<http://techblog.qoncept.jp/?p=397>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T12:53:50.227",
"favorite_count": 0,
"id": "23421",
"last_activity_date": "2016-03-24T14:04:44.963",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14924",
"post_type": "question",
"score": 1,
"tags": [
"adb"
],
"title": "adb shell で「<」がうまくいかない",
"view_count": 1563
} | [
{
"body": "```\n\n adb shell ”/data/local/tmp/makeaction < /mnt/sdcard/testtap.txt”\n \n```\n\nのようにコマンド全体を「\"」や「'」でクォートしてみて下さい。\n\n`<`はリダイレクト記号で、これを解釈してファイルをコマンドの標準出力に繋げるのはシェルの役目です。 \n問題は「どちらの」シェルがこの記号を解釈して、リダイレクトを実行しているかです。\n\n```\n\n adb shell /data/local/tmp/makeaction < /mnt/sdcard/testtap.txt\n \n```\n\nとした場合、リダイレクトを解釈するのは開発(ローカル)環境のシェルです。 \n`adb` コマンドの標準入力に開発マシンの`/mnt/sdcard/testtap.txt`を繋げようとします。 \n`adb`の(デバッグ対象マシンの中で動く)シェルにリダイレクトを処理させなければいけません。\n\n「\"」等でクォートすると `<` も開発マシンのシェルにとってはただの文字列になり、そのままadbのシェルに伝わります。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T14:04:44.963",
"id": "23423",
"last_activity_date": "2016-03-24T14:04:44.963",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23421",
"post_type": "answer",
"score": 3
}
]
| 23421 | null | 23423 |
{
"accepted_answer_id": "23434",
"answer_count": 1,
"body": "プログラミングの技術文章を書いているのですが、書いた文章のライセンスについて質問させてください。 \nプログラミングの技術文章には、ソースコードとソースコードに対する解説文章や図表などが含まれますが、それぞれに別々のライセンスをつけたいと考えています。\n\nソースコード: CC0(Public domain) \n解説文章や図表: CC-BY\n\nソースコードにはGPLやMITなどのライセンスがありますが、ここでは再配布時に著作権を表示不要なCC0(Public\nDomain)をつけたいと考えています。 \n一方文章や図表には、著作権表示が必要なCC-BYライセンスをつけたいと考えています。\n\nこの場合、ライセンスはどのように記載したらよいのでしょうか? \nそもそもこのようなライセンスのつけ方は認めてられないのでしょうか? \nライセンスに関して最近学び始めたばかりであまり詳しいことが分かっていないので、ご教授いただけると助かります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T13:53:48.480",
"favorite_count": 0,
"id": "23422",
"last_activity_date": "2016-03-25T04:20:56.613",
"last_edit_date": "2016-03-24T15:37:31.377",
"last_editor_user_id": "8000",
"owner_user_id": "14114",
"post_type": "question",
"score": 4,
"tags": [
"ライセンス"
],
"title": "複数のクリエイティブ・コモンズ・ライセンスの併用について",
"view_count": 317
} | [
{
"body": "その技術文書、およびソースコードに適切なライセンスを明記すれば良いと思います。次はGo言語の例ですが、ウェブサイトの内容(文章と図表)はCC3.0、ソースコードはBSDライセンスであることが明記されています。\n\n> Except as noted, the content of this page is licensed under the \n> Creative Commons Attribution 3.0 License, and code is licensed under a \n> BSD license.\n\n<https://golang.org/> (フッターに記述があります) \n<https://go.googlesource.com/go/+/master/LICENSE> (ソースコードレポジトリ内のLICENSEファイル)",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T00:12:19.773",
"id": "23434",
"last_activity_date": "2016-03-25T04:20:56.613",
"last_edit_date": "2016-03-25T04:20:56.613",
"last_editor_user_id": "216",
"owner_user_id": "216",
"parent_id": "23422",
"post_type": "answer",
"score": 8
}
]
| 23422 | 23434 | 23434 |
{
"accepted_answer_id": "23427",
"answer_count": 2,
"body": "Go の初心者です。\n\nGolang で、正しく動いている次のコードがあります。\n\n```\n\n package main\n \n import \"os/exec\"\n import fmt \"fmt\"\n \n func main() {\n \n c, _ := exec.Command(\"git\", \"log\", \"--first-parent\", \"--merges\").Output()\n s := string(c[:])\n fmt.Printf(s)\n }\n \n```\n\n* * *\n\nこれの、コマンド実行部分を関数に切り出そうとして、次のように変更を行いました。\n\n```\n\n package main\n \n import \"os/exec\"\n import fmt \"fmt\"\n \n func executeCommand(command ...string) string {\n c, _ := exec.Command(command...).Output()\n return string(c[:])\n }\n \n func main() {\n \n s := executeCommand(\"git\", \"log\", \"--first-parent\", \"--merges\")\n fmt.Printf(s)\n }\n \n```\n\nすると、次のエラーが発生します。\n\n```\n\n # command-line-arguments\n ./calc.go:7:27: error: argument 1 has incompatible type\n c, _ := exec.Command(command...).Output()\n ^\n ./calc.go:7: confused by earlier errors, bailing out\n \n```\n\n`command...` で、受け取った配列を展開して、 `exec.Command()`\nに引き渡せるものだと思っていたのですが、上記の通りそうはなっていないです。\n\n* * *\n\n質問:\n\n * 私は、何を間違えているのでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T14:54:57.740",
"favorite_count": 0,
"id": "23426",
"last_activity_date": "2016-03-24T16:27:39.610",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 2,
"tags": [
"go"
],
"title": "golang で受け取った可変長引数を他の可変長引数に渡したい",
"view_count": 2297
} | [
{
"body": "エラーメッセージにあるとおりです。 `exec.Command` は第1引数は `string` なので、スライスではなく `string`\nを渡す必要があります。\n\n<https://golang.org/pkg/os/exec/#Command>\n\n```\n\n package main\n \n \n import (\n \"fmt\"\n \"os/exec\"\n )\n \n func executeCommand(command ...string) string {\n c, _ := exec.Command(command[0], command[1:]...).Output()\n return string(c[:])\n }\n \n func main() {\n s := executeCommand(\"git\", \"log\", \"--first-parent\", \"--merges\")\n fmt.Println(s)\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T15:07:31.253",
"id": "23427",
"last_activity_date": "2016-03-24T15:07:31.253",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "216",
"parent_id": "23426",
"post_type": "answer",
"score": 1
},
{
"body": "本題からは外れるのですが、`exec.Command()` の signature が\n\n```\n\n func Command(name string, arg ...string)\n \n```\n\nとなっていますので、`executeCommand()` もこれに合わせる方が良いかと思います。\n\n可変長引数だけにすると引数がない場合でも compile error にならずに `executeCommand()` が実行されてしまい、その結果\nruntime error が発生してしまいます。\n\n```\n\n s := executeCommand()\n \n panic: runtime error: slice bounds out of range\n \n```\n\nどうしても可変長引数だけにしたい場合は可変長引数(`command`)の length check などをしておくべきかと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T16:27:39.610",
"id": "23429",
"last_activity_date": "2016-03-24T16:27:39.610",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "23426",
"post_type": "answer",
"score": 0
}
]
| 23426 | 23427 | 23427 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "現在作成中のアプリにて、解像度 1280 * 720 (16:9) で画面を設計しました。 \n解像度2560 * 1440 のアンドロイド端末で問題なく見ることができていました。 \n本日、ナビゲーションバーが出ていないことに気づいて、ナビゲーションバーを出すように設定したところ、表示がおかしくなりました。(縮小された) \n※ Unityのcanvasの設定で解像度設定をしているため、全体が入るように縮小されたと思われます。\n\nここで質問なのですが、 \n1\\.\n端末スペックなどで言われている解像度は、ナビゲーションバーを含んだ解像度であって、実際のアプリで使える範囲の解像度は、それより小さくなるということでしょうか? \n2.ナビゲーションバーを表示するアプリ(表示されているアプリが多いと思いますが)は、ナビゲーションバーの高さを考慮して作成されているのでしょうか? \n3\\. ナビゲーションバーの高さの取得仕方を調べたところ、Unityでは取得できないようなのですが、対処法はありますでしょうか?\n\n開発終盤で解像度が変わる自体になりそうで、大変困ってます。 \nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T17:32:37.817",
"favorite_count": 0,
"id": "23430",
"last_activity_date": "2016-03-24T17:32:37.817",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13198",
"post_type": "question",
"score": 1,
"tags": [
"android"
],
"title": "Android のナビゲーションバーと解像度の関係について",
"view_count": 360
} | []
| 23430 | null | null |
{
"accepted_answer_id": "23436",
"answer_count": 1,
"body": "monacaでスライディングメニュー機能が付いたアプリを作成しております。 \nそこにbxsliderをのせているのですが、bxsliderを操作しようとスワイプするとスライディングメニューが一緒に出てきてしまいます。 \nbxsliderのオプション等いろいろ試してみたのですが、うまくいきません。\n\nスライディングメニューを生かしたままでbxslider上のスワイプ操作だけはスライディングメニューが反応しないようにするにはどうしたらいいでしょうか?\n\nどなたかわかる方ご教授お願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-24T23:06:30.103",
"favorite_count": 0,
"id": "23433",
"last_activity_date": "2016-03-25T01:20:57.530",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13685",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"monaca"
],
"title": "monacaでスライディングメニューとbxsliderのスワイプ操作が干渉してしまう。",
"view_count": 190
} | [
{
"body": "`bxslider`の仕組みだけじゃ厳しいんじゃないかなぁ \n…と言うのもスワイプ操作時に親のドキュメントごと動いちゃうので \n親のドキュメント(`ons-page`)が動くとスライディングメニューが反応します。 \n対策は2つほどパッと思いつく感じですが、、、\n\n1.スワイプ判定を自分で行う \nこちらはややハードルが高いかもしれませんが \nタッチイベントを取得するとタッチされたエレメントを取得できます。 \nそのエレメントの親要素に`bxslider`が存在しなければスライド方向を認識して \n`sideMenu.open()`で開いてやれば良いんでないかな?\n\n2.親にスワイプが影響しないライブラリを使用する \n例えば`owl-carousel`だと指定要素の配下が動くので親は動きません。 \nそういうライブラリを使用するか、作るかですね。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T01:20:57.530",
"id": "23436",
"last_activity_date": "2016-03-25T01:20:57.530",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "23433",
"post_type": "answer",
"score": 0
}
]
| 23433 | 23436 | 23436 |
{
"accepted_answer_id": "23511",
"answer_count": 1,
"body": "Ruby で画像URLをスクレイピングしたいです。\n\n```\n\n <div> \n <a href=\"URL\" titile=\"xxx\"> \n <img alt=\"yyy\" src=\"ここのURLをクスレイピングしたいです> \n </a>\n \n```\n\n以下のように記述しました。\n\n```\n\n require 'mechanize'\n \n agent= Mechanize.new \n page = agent.get(\"取得したいサイトURL\") \n elements = page.search('a img')\n \n elements.each do |ele| \n puts ele.get_attribute('src') \n end \n \n```\n\nそして、`ruby\nscraping_image.rb`をターミナルに記載しENZTERキーを押したのですが、ターミナルにただ大きな空欄が出来るだけで、何も欲しい情報が得られませんでした。 \nエラーメッセージ等は表示されませんでした。\n\n違うタグを取得するように記述するべきだったでしょうか? \nお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T01:58:19.420",
"favorite_count": 0,
"id": "23437",
"last_activity_date": "2016-03-27T14:07:17.790",
"last_edit_date": "2016-03-27T13:35:55.567",
"last_editor_user_id": "3054",
"owner_user_id": "14754",
"post_type": "question",
"score": 2,
"tags": [
"ruby"
],
"title": "画像URLスクレイピング",
"view_count": 640
} | [
{
"body": "質問のコードは私の手元でも動きました。間違いは無さそうです。 \n下記のように`src`属性だけでなく、要素ごと出力して様子を見るとよいでしょう。 \n\n```\n\n puts ele\n puts ele.get_attribute('src') \n \n```\n\n問題があるとすれば、取得しているWebページの構造です。 \n「`a`タグの下に`img`タグがあり、それが`src`属性を持っている」というのが想定する構造ですが、そうはなっていないのでしょう。 \n「空欄」が出力されたという事は`img`タグは発見されているが、それに`src`属性が無いか`src`の値が空文字やスペースなのだろうと推測します。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T14:07:17.790",
"id": "23511",
"last_activity_date": "2016-03-27T14:07:17.790",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23437",
"post_type": "answer",
"score": 3
}
]
| 23437 | 23511 | 23511 |
{
"accepted_answer_id": "23497",
"answer_count": 2,
"body": "Monacaのonsen uiを使用しています。 \nons-list-itemタグのmodifierの内容を動的に変更したいのですが、可能なのでしょうか?\n\npageinitで、$('#ons-list-item').attr('modifier',\n'chevron')をしても、console.log上は変更されていますが、画面は\">\"マークが出てこなく、クリックしても反応しません。\n\nどなたかご存知の方いましたら、ご教示ください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T02:16:38.093",
"favorite_count": 0,
"id": "23439",
"last_activity_date": "2016-03-27T03:02:34.637",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14931",
"post_type": "question",
"score": 0,
"tags": [
"monaca",
"onsen-ui"
],
"title": "onsen uiのons-list-itemタグのmodifierに関して",
"view_count": 1544
} | [
{
"body": "jQueryのattr('modifier', 'chevron')で追加できますよ。 \n他のコードに誤りはありませんか? \n$('#ons-list-item')とありますが、#はIDを指定するセレクタなので、ここが間違っているのではないでしょうか。\n\n```\n\n <ons-list-item class=\"hoge\">\n \n```\n\nのようにしておいて、\n\n```\n\n $('.hoge').attr('modifier', 'chevron');\n \n```\n\nで出来ると思います。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T10:34:10.800",
"id": "23457",
"last_activity_date": "2016-03-25T10:34:10.800",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14940",
"parent_id": "23439",
"post_type": "answer",
"score": 0
},
{
"body": "OnsenUIは(少なくとも1系は)modifierの動的な変更に対応していませんのでmodifier属性を書き換えるだけでは機能しません。代わりに`<ons-\nlist-item>`のclassを手動で付加/除去することで実現できます。下記のスニペットを実行してみてください。\n\n```\n\n ons.bootstrap()\r\n .controller('appCtrl', function($scope, $timeout, $element){\r\n setInterval(function(){\r\n $element.find('ons-list-item').toggleClass('list__item--chevron');\r\n $element.find('ons-list-item').toggleClass('list__item--tappable');\r\n }, 1000);\r\n });\n```\n\n```\n\n <link href=\"https://cdn.rawgit.com/OnsenUI/OnsenUI/1.3.15/build/css/onsen-css-components.css\" rel=\"stylesheet\"/>\r\n <link href=\"https://cdn.rawgit.com/OnsenUI/OnsenUI/1.3.15/build/css/onsenui.css\" rel=\"stylesheet\"/>\r\n <script src=\"https://cdn.rawgit.com/OnsenUI/OnsenUI/1.3.15/build/js/angular/angular.min.js\"></script>\r\n <script src=\"https://cdn.rawgit.com/OnsenUI/OnsenUI/1.3.15/build/js/onsenui.min.js\"></script>\r\n \r\n <ons-page ng-controller=\"appCtrl\">\r\n <ons-list>\r\n <ons-list-header></ons-list-header>\r\n <ons-list-item>item1</ons-list-item>\r\n <ons-list-item>item2</ons-list-item>\r\n <ons-list-item>item3</ons-list-item>\r\n <ons-list-item>itme4</ons-list-item>\r\n <ons-list-item>item5</ons-list-item>\r\n </ons-list>\r\n </ons-page>\n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T03:02:34.637",
"id": "23497",
"last_activity_date": "2016-03-27T03:02:34.637",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8532",
"parent_id": "23439",
"post_type": "answer",
"score": 0
}
]
| 23439 | 23497 | 23457 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "【環境】: CentOS or Ubuntu\n\n高トラフィック時にどこから攻撃が来ているか等をiptablesのハッシュリミットを用いて対策しています。 \nこちらで決めた閾値を超えたsrcipはログを取るようにしています。\n\n似たようなことになるかと思いますが、tcpdumpだけでリアルタイムにどこからアクセス(攻撃元)が来ているかどうかを判別することは可能でしょうか?\n\n普通にtcpdump -i IF名 オプションで実行しても、どれが攻撃元かを判別するのは難しいと思います。\n\n1分間(特に時間指定はいりませんが)に異常なアクセス(他のsrcipに比べて大量のアクセス)があるようなホストだけをしぼってtcpdumpさせるような技(オプションまたは手法)をご存じの方がいらっしゃいましたら、ご教示頂けませんでしょうか?\n\n不可能であるようならば、一言ムリと教えて頂くだけでも幸いです。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T02:35:19.530",
"favorite_count": 0,
"id": "23440",
"last_activity_date": "2016-10-01T19:51:29.057",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14384",
"post_type": "question",
"score": -1,
"tags": [
"linux",
"tcpdump"
],
"title": "高トラフィック時における tcpdump の使い方について",
"view_count": 289
} | [
{
"body": "Linuxでサクッと確認したいなら、 \ntcptrackやiftopなど。\n\nちゃんとやるならnetflowとかsflowとかですね。 \n<http://labs.gree.jp/blog/2015/12/15515/>\n\nあとはIDSですかね。\n\n>\n> 1分間(特に時間指定はいりませんが)に異常なアクセス(他のsrcipに比べて大量のアクセス)があるようなホストだけをしぼってtcpdumpさせるような技(オプションまたは手法)をご存じの方がいらっしゃいましたら、ご教示頂けませんでしょうか?\n\nありません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-10-01T19:51:29.057",
"id": "29290",
"last_activity_date": "2016-10-01T19:51:29.057",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "23440",
"post_type": "answer",
"score": 1
}
]
| 23440 | null | 29290 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Ruby on Railsで管理画面を作っています。 \nリストページで全ての行の前にCheckBoxを置いて、Checkされた行を全部削除したいんです。\n\n下記は自分のコードです。\n\n```\n\n table.table.table-bordered.table-striped\n thead\n tr\n th\n th #\n th 会社コード\n tbody\n - @companies.each do |company|\n tr\n td.text-right = company.Id\n td = company.CompanyCode\n td.text-center = link_to '詳細', company, class: 'badge bg-green'\n td.text-center = link_to '修正', edit_company_path(company), class: 'badge bg-light-blue'\n td.text-center = link_to '削除', company, data: {:confirm => '本当に削除してもよろしいでしょうか?'}, :method => :delete, class: 'badge bg-red'\n \n```\n\ncontroller\n\n```\n\n before_action :set_company, only: [:show, :edit, :update, :destroy]\n \n # GET /company\n def index\n @companies = Company.all\n end\n \n # GET /company/1\n def show\n end\n \n # GET /company/new\n def new\n @company = Company.new\n end\n \n # GET /company/1/edit\n def edit\n end\n \n # POST /companies\n def create\n @company = Company.new(company_params)\n \n if @company.save\n redirect_to @company, notice: 'company was successfully created.'\n else\n render :new\n end\n end\n \n # PATCH/PUT /companies/1\n def update\n if @coupon2_type.update(coupon2_type_params)\n redirect_to @coupon2_type, notice: 'Coupon2 type was successfully updated.'\n else\n render :edit\n end\n end\n \n # DELETE /companies/1\n def destroy\n @company.destroy\n redirect_to companies_url, notice: 'Company was successfully destroyed.'\n end\n \n private\n \n # Use callbacks to share common setup or constraints between actions.\n def set_company\n @company = Company.find(params[:id])\n end\n \n # Only allow a trusted parameter \"white list\" through.\n def company_params\n params.require(:company).permit(:CompanyCode)\n end\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T02:55:46.243",
"favorite_count": 0,
"id": "23441",
"last_activity_date": "2023-05-01T04:03:10.320",
"last_edit_date": "2016-03-25T03:01:37.617",
"last_editor_user_id": "10710",
"owner_user_id": "10710",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "Railsでリストから複数の行を削除する方法",
"view_count": 924
} | [
{
"body": "`check_box_tag`の中に配列を置き、それを用いてコントローラ側で削除すればうまくいくと思います。 \n`<%= check_box_tag \"words_info[]\",word.id %>` \nこんな感じです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-01-25T07:30:52.710",
"id": "32145",
"last_activity_date": "2017-01-25T07:30:52.710",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19915",
"parent_id": "23441",
"post_type": "answer",
"score": 0
}
]
| 23441 | null | 32145 |
{
"accepted_answer_id": "23491",
"answer_count": 1,
"body": "`docker-machine create` コマンドで作成した VM に保存した `~/.ssh/my_id_rsa` ファイルが、VM\nの再起動時に消えてしまいます。ドキュメントを読んでもこの現象に該当する記述が見当たらず、どうしたものかと悩んでいます。\n\nホストマシンは Mac OS (El Capitan) で、docker-machine のバージョンは次の通りです。\n\n```\n\n $ docker-machine version\n docker-machine version 0.6.0, build e27fb87\n \n```\n\nまた、VM は次のオプションで作成しました。\n\n```\n\n $ docker-machine create --driver virtualbox dev\n \n```\n\nもし何か思い当たることがあれば、教えていただけると助かります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T05:10:47.267",
"favorite_count": 0,
"id": "23443",
"last_activity_date": "2016-03-26T14:10:23.940",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13623",
"post_type": "question",
"score": 1,
"tags": [
"docker"
],
"title": "Docker Machine で ~/.ssh/MY_KEY を正しく保存する方法",
"view_count": 124
} | [
{
"body": "一日待って回答を得られなかったので、[本家](https://stackoverflow.com/questions/36232018/how-can-i-\nsave-my-rsa-key-in-my-docker-machine)の方で質問してみました。\n\nこれによると、`boot2docker`は `/var/lib/boot2docker` ディレクトリにあるデータをのぞいて、起動時に\n`boot2docker.iso` の内容で初期化されるから次の二つの方法のいずれかで回避するといい、とのことでした。\n\n * 鍵をホストの `/Users/any/path/you/want` に保存する (`/Users` は `boot2docker`でマウントされるから)\n * 鍵を `/var/lib/boot2docker` に保存する",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T14:10:23.940",
"id": "23491",
"last_activity_date": "2016-03-26T14:10:23.940",
"last_edit_date": "2017-05-23T12:38:56.467",
"last_editor_user_id": "-1",
"owner_user_id": "13623",
"parent_id": "23443",
"post_type": "answer",
"score": 1
}
]
| 23443 | 23491 | 23491 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "以下の様な問題を考えます。\n\nxy平面上でまず、原点Oからx軸に沿って、長さr_1移動します(この時、角度θ_1=0)。 \n次に、角度θ_2で長さr_2移動し、さらに角度θ_3で長さr_3移動し、 \nその後も同様に続けていきます。 \n以下の図の青い線で、上記の移動を示しています。\n\n[](https://i.stack.imgur.com/qVLDK.jpg) \nここで例えば、 \n図の赤い点線の長さであるs_3やs_4、 \n赤い点線とx軸との角度であるφ_3やφ_4は、 \nrとθを用いてどのように計算できるでしょうか?\n\nまた、s_nやφ_nは、rとθを用いてどのような一般式で計算できるでしょうか?\n\n最終的には、三次元極座標系において一般化したいと思っています。\n\nよろしくお願いします。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T08:04:56.937",
"favorite_count": 0,
"id": "23447",
"last_activity_date": "2016-03-25T10:39:07.640",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12874",
"post_type": "question",
"score": -1,
"tags": [
"数学"
],
"title": "極座標における点の移動を計算したい",
"view_count": 1300
} | [
{
"body": "iステップ後の位置を`p_i`としてベクトル表示をすると`p_i=(sum(r_i*cos(D_i),sum(r_i*sin(D_i)))`とかけます.\nここで`D_i`はiステップめの進行方向のx軸からみた角度でとします. `D_i`は`sum(pi-theta_i)` とかけます.\nこの`p_i`を使えばベクトルの長さ `s_i` は `s_i=sqrt(p_i_x**2+p_i_y**2)`とかけます.\n角度は`phi_i=arctan(p_i_y/p_i_x)`です.",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T10:06:49.207",
"id": "23454",
"last_activity_date": "2016-03-25T10:39:07.640",
"last_edit_date": "2016-03-25T10:39:07.640",
"last_editor_user_id": "14418",
"owner_user_id": "14418",
"parent_id": "23447",
"post_type": "answer",
"score": 2
}
]
| 23447 | null | 23454 |
{
"accepted_answer_id": "23474",
"answer_count": 1,
"body": "お世話になります。タイトルで書いたことをやりたいのですがエラーが発生します。 \n最初から順に書きますので漏れなどあればご教示ください。\n\nMonacaを使用しています。\n\n1.新規プロジェクトから「Onsen UI最小限のテンプレート(ユニバーサルアプリ対応版)」を選択 \n2.「ファイル」-「Cordavaプラグインの管理」から「Cordovaプラグインのインポート」をクリック \n3.「ZIP形式のプラグイン」を選んで、[配布元](https://github.com/ch000/cordova-\nimagePicker)から落としたZipをインポート \nインポート結果が下記画像になります。 \n[](https://i.stack.imgur.com/BhERD.png)\n\n4.index.htmlのscript内を下記に変更\n\n```\n\n <script>\n ons.bootstrap();\n if(typeof device === 'undefined'){\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n }else{\n onDeviceReady();\n }\n \n function onDeviceReady() {\n try{\n window.imagePicker.getPictures(\n function(results) {\n for (var i = 0; i < results.length; i++) {\n console.log('Image URI: ' + results[i]);\n }\n }, function (error) {\n console.log('Error: ' + error);\n }\n );\n } catch(e){\n alert(e);\n \n }\n }\n </script>\n \n```\n\nIOS9.3でMonacaデバッガーから起動すると下記エラーが発生 \n「TypeError: Cannot read property 'getPictures' of undefined」 \nカメラプラグインを有効にすると \n「TypeError: undefined is not an object (evaluating\n'window.imagePicker.getPictures')」となります。\n\n追記: \nDeviceプラグインとinAppBrowserプラグインも追加しております。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T08:06:51.877",
"favorite_count": 0,
"id": "23448",
"last_activity_date": "2016-03-27T02:31:55.363",
"last_edit_date": "2016-03-27T02:31:55.363",
"last_editor_user_id": "13177",
"owner_user_id": "13177",
"post_type": "question",
"score": 0,
"tags": [
"monaca",
"cordova"
],
"title": "cordova-imagePickerで画像を表示・選択する方法",
"view_count": 747
} | [
{
"body": "冒頭のif文でdevicereadyが発火済みかどうかチェックしているのだと推測しますが、window.deviceが存在することはdevicereadyが完了していることを保証しません。したがってdevicereadyイベントの発火前にonDeviceReady()関数が呼ばれたためにエラーになっているのでしょう。 \nまた、\n\n```\n\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n \n```\n\nで登録された関数はdevicereadyが既に発火済みの場合は即時実行されますので\n\n```\n\n if(typeof device === 'undefined'){\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n }else{\n onDeviceReady();\n }\n \n```\n\nこの部分は\n\n```\n\n document.addEventListener(\"deviceready\", onDeviceReady, false);\n \n```\n\nこれで十分です。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T05:40:17.167",
"id": "23474",
"last_activity_date": "2016-03-26T05:40:17.167",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8532",
"parent_id": "23448",
"post_type": "answer",
"score": 0
}
]
| 23448 | 23474 | 23474 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "netbeans8.1でエラーでもない文が強調表示されます。 \nコンパイルすると普通に実行できます。 \nどうしたらいいですか \nウブンツ15.10\n\n[](https://i.stack.imgur.com/wJcKg.png)",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T08:34:25.180",
"favorite_count": 0,
"id": "23449",
"last_activity_date": "2016-03-26T12:31:41.297",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14937",
"post_type": "question",
"score": 0,
"tags": [
"netbeans"
],
"title": "エラーでもない文が強調表示される",
"view_count": 605
} | [
{
"body": "最近などコンパイラ周辺への変更を行った経験がある場合は\n\n```\n\n sudo apt-get autoremove\n \n```\n\nたいてい、複数のバージョンが存在します \n私は、アセンブラ命令のコンパイルでエラーが出た\n\nそれ以外の方はディレクトリの記述を確認してください(ほんとに記述されていないのならコンパイルはできないはずですが。。。)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T10:40:38.307",
"id": "23484",
"last_activity_date": "2016-03-26T10:40:38.307",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14937",
"parent_id": "23449",
"post_type": "answer",
"score": 1
},
{
"body": "画像を見た限りinclude文が全角になっているように見えますがどうでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T12:31:41.297",
"id": "23487",
"last_activity_date": "2016-03-26T12:31:41.297",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8215",
"parent_id": "23449",
"post_type": "answer",
"score": -1
}
]
| 23449 | null | 23484 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "画面入力値の西暦を、和暦に変換する必要があり、質問します。 \n以下スースの通り作成したのですが、入力値の「月」が+1されてしまいます。 \n解決法を教えてください。\n\n入力値(以下ソースのcalender.set(2016, 3, 24);部分) → 2016, 3, 24 \n実行結果 → 平成28年4月30日\n\nとなり3月となってほしいのに4月となってしまいます。\n\n```\n\n import java.text.*;\n import java.util.*;\n \n public class MyTest {\n public static void main(String[] args) {\n Locale defaultLocale = new Locale(\"ja\", \"JP\", \"JP\");\n DateFormat japaneseFormat = new SimpleDateFormat(\"GGGGy年M月d日\",\n defaultLocale);\n \n Calendar calender = Calendar.getInstance();\n calender.set(2016, 3, 24);\n \n System.out.println(japaneseFormat.format(calender.getTime()));\n }\n }\n \n```\n\nポイントは、システム日付ではなく、外部から与えられた引数で西暦→和暦に変換したいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T10:19:12.190",
"favorite_count": 0,
"id": "23455",
"last_activity_date": "2016-03-28T02:09:23.557",
"last_edit_date": "2016-03-25T10:42:34.240",
"last_editor_user_id": "46",
"owner_user_id": "14939",
"post_type": "question",
"score": 1,
"tags": [
"java"
],
"title": "javaで西暦→和暦変換がうまくいかない",
"view_count": 8085
} | [
{
"body": "Javadocにもひっそり書いてあるのですが、月は0始まりのためですね。\n\n[Calendar#set(int, int, int) (Java Platform SE 8\n)](https://docs.oracle.com/javase/jp/8/docs/api/java/util/Calendar.html#set-\nint-int-int-)\n\n> month - MONTH カレンダフィールドの設定に使用する値。Month 値は 0 から始まる (1 月は 0 になる)。\n\n3月にするためには、\n\n```\n\n calender.set(2016, 2, 24);\n \n```\n\nとする必要があります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T10:26:14.343",
"id": "23456",
"last_activity_date": "2016-03-25T10:48:15.727",
"last_edit_date": "2016-03-25T10:48:15.727",
"last_editor_user_id": "46",
"owner_user_id": "476",
"parent_id": "23455",
"post_type": "answer",
"score": 7
},
{
"body": "JDK8以降であれば、java.time.chrono.JapaneseDateを使って和暦を取得することもできます。こちらはそのままの月を設定できる感じです。 \n[java.time.chrono.JapaneseDate](https://docs.oracle.com/javase/jp/8/docs/api/java/time/chrono/JapaneseDate.html)\n\n```\n\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"Gyy年M月d日\");\n JapaneseDate japaneseDate = JapaneseDate.of(2016, 3, 24);\n System.out.println(japaneseDate.format(formatter));\n // 平成28年3月24日\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T02:09:23.557",
"id": "23524",
"last_activity_date": "2016-03-28T02:09:23.557",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14890",
"parent_id": "23455",
"post_type": "answer",
"score": 6
}
]
| 23455 | null | 23456 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "最近, プログラミング言語を勉強し始めまして, pythonとrubyに興味を持ちました。\n\nその言語自体のソースコードを見てみると, C言語で記述されているのが分かったのですが, 多くのファイルから成っていることが分かり,\n途端に複雑さが増して混乱しています。\n\nこういった大きなプロジェクトのソースコードリーディングのやり方を教えてください。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T12:12:30.693",
"favorite_count": 0,
"id": "23458",
"last_activity_date": "2016-03-26T13:59:19.733",
"last_edit_date": "2016-03-25T17:02:02.563",
"last_editor_user_id": "754",
"owner_user_id": "14941",
"post_type": "question",
"score": 1,
"tags": [
"c"
],
"title": "ソースコードリーディングについて",
"view_count": 520
} | [
{
"body": "プログラムにはいろいろな種類がありますが、その中でもコンパイラやインタプリタといった言語処理系は特に複雑な部類に入りますので、そのソースコードを読むのも難易度が高くなります。処理する側(例えばC)と処理される側(RubyやPython)両方の知識が必要な上、構文解析などコンピュータ科学の幅広い知識も必要です。\n\nRubyやPythonで(または言語は問わずに)プログラムを書くのが目的なのであれば処理系自身のソースコードが読めることは必須ではありません。それぞれの言語の入門書やなどで勉強されるとよいでしょう。\n\nRubyやPythonがどのように動いているかという言語処理系としての仕組みが知りたいということであれば、まずCと対象の言語をしっかり習得する必要があります。さらに言語処理の仕組みについては専門書で学習する事になるでしょう。\n\nCを勉強するためにソースリーディングをやっているのであれば、言語処理系は難易度が高すぎる題材だと思います。もっと小規模なものから挑戦した方がよいでしょう。それにしても、そのプログラムが何をしているのかの知識は必要になります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T13:15:04.117",
"id": "23489",
"last_activity_date": "2016-03-26T13:15:04.117",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5793",
"parent_id": "23458",
"post_type": "answer",
"score": 1
}
]
| 23458 | null | 23489 |
{
"accepted_answer_id": "23465",
"answer_count": 2,
"body": "Routing Errorを解決したいです。`No route matches [POST]\n\"/like/4\"`とさらに表示されました。POSTが合わないということですよね?\n\nroutes.rbには下記のように記述しました。\n\n```\n\n Rails.application.routes.draw do\n \n devise_for :users\n resources :users, only: [:index, :show, :edit, :update,:like]\n resources :notes, only: [:show, :create, :edit, :update, :destroy,:like]\n \n get'/top' => 'home#top'\n \n get'/connection' => 'home#connection'\n get'/notes/new' => 'notes#new'\n post'/notes' =>'notes#create'\n get'/notes' =>'notes#index'\n patch'/notes/:id' =>\"notes#update\",as:'update_note'\n delete'/notes/:id' =>\"notes#destroy\",as:'destroy_note'\n \n post '/like/notes/:id' => 'likes#like', as: 'like' # ←←\n delete '/unlike/notes/:id' => 'likes#unlike', as: 'unlike'\n \n root 'home#top'\n get'/about' => 'home#about'\n end\n \n```\n\n`←←`で示したところにpost のコードを記載し、rake routesを確認したところ、\n\n```\n\n like_path POST /like/notes/:id(.:format) likes#like \n unlike_path DELETE /unlike/notes/:id(.:format) likes#unlike \n \n```\n\nのようになっており、post と記載すべきなのになぜエラーが出るのか?と思いました。 \nどのように記述すべきなのでしょうか? \nお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T13:06:35.073",
"favorite_count": 0,
"id": "23459",
"last_activity_date": "2016-03-25T23:45:14.613",
"last_edit_date": "2016-03-25T16:09:37.703",
"last_editor_user_id": "3068",
"owner_user_id": "14754",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "Routing Error No route matches [POST] \"/like/4\"",
"view_count": 1119
} | [
{
"body": "routesに`post '/like/notes/:id'`で指定しているのですが、エラーに`/like/4`でアクセスしようとしていると書いてあります。 \n`post '/like/notes/:id'`を`post\n'/like/:id'`に変えるか、または`/like/4`でアクセスしようとしているコードを変えるかのどちらかで解決できます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T14:05:12.317",
"id": "23460",
"last_activity_date": "2016-03-25T14:05:12.317",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14928",
"parent_id": "23459",
"post_type": "answer",
"score": 0
},
{
"body": "「どのように記述すべきなのでしょうか?」については的確な回答が出ていますからこちらの部分。 \n_POSTが合わないということですよね?_ \n`No route matches [POST] \"/like/4\"`は「`[POST]\n\"/like/4\"`にマッチするようなルートが存在しない」と言う意味です。POSTだけがダメと言っているのではありません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T23:45:14.613",
"id": "23465",
"last_activity_date": "2016-03-25T23:45:14.613",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "23459",
"post_type": "answer",
"score": 0
}
]
| 23459 | 23465 | 23460 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "こんにちは。python3で作ったこちらの再帰関数が上手く機能しません。\n\n```\n\n def func(teleports_string):\n strings = [{n[0],n[1]} for n in teleports_string.split(',')]\n start = {'1'}\n \n def search(strings,point,totalpoint):\n for string in strings:\n \n if point <= string and not string.difference(point) <= totalpoint:\n \n if len(totalpoint.union(point)) >= 7:\n \n print(totalpoint)\n return totalpoint\n \n search(strings,string.difference(point),totalpoint.union(string))\n return search(strings,start,set())\n \n func(\"12,23,34,45,56,67,78,81\")\n \n```\n\n上記のコードの \n`return totalpoint` \nの行で`totalpoint`を戻り値として処理を終了させたいのですが、 \n残りの処理を始めてしまいます。 \nどのようにすれば、`return totalpoint`で処理を終わらせられるでしょうか。 \nご教授下さい。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T15:42:15.057",
"favorite_count": 0,
"id": "23461",
"last_activity_date": "2016-03-25T17:00:36.723",
"last_edit_date": "2016-03-25T16:14:40.247",
"last_editor_user_id": "3605",
"owner_user_id": "14943",
"post_type": "question",
"score": 0,
"tags": [
"python",
"アルゴリズム"
],
"title": "python3で深さ優先探索の再帰関数が上手く機能しない",
"view_count": 742
} | [
{
"body": "`search` 関数の最後で自分自身を再帰的に呼び出していますが、\n\n```\n\n search(strings,string.difference(point),totalpoint.union(string))\n \n```\n\nここに `return` がないので、再帰から戻ってきた後も、外側の `for string in strings:`\nを続けて実行しています。しかも、最終的には return なしで関数が終了しているので、何も戻り値を返していません(厳密には `None`\nを返していますが)。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T17:00:36.723",
"id": "23462",
"last_activity_date": "2016-03-25T17:00:36.723",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3605",
"parent_id": "23461",
"post_type": "answer",
"score": 1
}
]
| 23461 | null | 23462 |
{
"accepted_answer_id": "23477",
"answer_count": 1,
"body": "git 上で、あるコミット A から別のコミット B までの間で、削除・追加・変更されたファイルについて、それぞれの一覧が取得したいです。\n\nこれを実現する方法はありますでしょうか。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T17:22:02.683",
"favorite_count": 0,
"id": "23463",
"last_activity_date": "2016-03-26T06:57:37.327",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 5,
"tags": [
"git"
],
"title": "git で、削除・追加・変更されたファイル一覧を取得するには?",
"view_count": 11011
} | [
{
"body": "`git diff --name-status A..B` で一覧が表示されます。\n\n```\n\n A file1\n M file2\n D file3\n \n```\n\n行頭の A, M, D は、それぞれ追加, 変更, 削除されたことを意味します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T06:57:37.327",
"id": "23477",
"last_activity_date": "2016-03-26T06:57:37.327",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3249",
"parent_id": "23463",
"post_type": "answer",
"score": 7
}
]
| 23463 | 23477 | 23477 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "anacondaをpyenv経由でインストールしようとしたら以下のエラーがでました。環境は Debian (jessie) です。\n\n```\n\n /tmp/python-build.20160326063823.3417 ~\n curl: (60) SSL certificate problem: unable to get local issuer certificate\n More details here: http://curl.haxx.se/docs/sslcerts.html\n \n curl performs SSL certificate verification by default, using a \"bundle\"\n of Certificate Authority (CA) public keys (CA certs). If the default\n bundle file isn't adequate, you can specify an alternate file\n using the --cacert option.\n If this HTTPS server uses a certificate signed by a CA represented in\n the bundle, the certificate verification probably failed due to a\n problem with the certificate (it might be expired, or the name might\n not match the domain name in the URL).\n If you'd like to turn off curl's verification of the certificate, use\n the -k (or --insecure) option.\n```\n\n調べてみたところ、ルート証明書が古いため出るエラーだそうですね。 \nそこで <https://curl.haxx.se/ca/cacert.pem>\nから、新しいルート証明書を引っぱり、以下に示したサイトの方法で解決を試みました。\n\n> 1. 使ってる認証局(globalsignとかverisign)のルート証明書を手に入れる。拡張子は.crtに。\n> 2. /usr/share/ca-certificates以下に、1のxxxx.crt を置く。\n> 3. /etc/ca-certificates.confに、2のpathを書\n> 4. update-ca-certificatesを実行して、更新 \n> (<http://kamatari.github.io/blog/2015/03/12/how-to-install-root-\n> certificate-on-debian/> より引用)\n>\n\nしかし結果は変わらず・・・解決手段を教えていただきたいです。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-25T22:34:01.727",
"favorite_count": 0,
"id": "23464",
"last_activity_date": "2016-04-04T10:15:42.920",
"last_edit_date": "2016-04-04T10:15:11.837",
"last_editor_user_id": "10666",
"owner_user_id": "10666",
"post_type": "question",
"score": 0,
"tags": [
"ssl",
"debian"
],
"title": "Debian (jessie) 環境での curl エラー: (60)",
"view_count": 1956
} | [
{
"body": "`export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt`\n\nで通るようになりました。とりあえずよかった。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-04-04T10:06:22.883",
"id": "23736",
"last_activity_date": "2016-04-04T10:15:42.920",
"last_edit_date": "2016-04-04T10:15:42.920",
"last_editor_user_id": "10666",
"owner_user_id": "10666",
"parent_id": "23464",
"post_type": "answer",
"score": 1
}
]
| 23464 | null | 23736 |
{
"accepted_answer_id": "23471",
"answer_count": 2,
"body": "Railsで`whenever`を使い下記のように`time`で実行にかかった記録を残しながら定期処理を行っています。\n\n```\n\n path = 'PATH=\"/opt/rbenv/bin:$PATH\";'\n env = 'eval \"$(rbenv init -)\"; cd :path && :environment_variable=:environment nice -n 10 time'\n job_type :rbenv_rake, %Q{#{path} #{env} :bundle_command rake :task --silent :output}\n \n set :output, {error: 'log/error_foo.log', standard: 'log/foo.log'}\n every '0 8 * * *' do\n rbenv_rake 'foo:update'\n end\n \n```\n\nただ、`time`コマンドの出力が標準出力ではなく標準エラーに行われるため正常終了した時は`log/foo.log`に処理時刻を残しておきたいのに常に`error_foo.log`側に保存されてしまいます。\n\n`time`の結果を標準出力に飛ばす方法、もしくは`time`相当の処理を行い結果を標準出力に行うプログラムなどありますか?",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T01:26:57.380",
"favorite_count": 0,
"id": "23469",
"last_activity_date": "2016-03-26T03:38:25.787",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3271",
"post_type": "question",
"score": 3,
"tags": [
"ruby-on-rails",
"linux"
],
"title": "timeコマンドの出力を標準エラーではなく標準出力に行う方法",
"view_count": 1733
} | [
{
"body": "> `time` の結果を標準出力に飛ばす方法\n\n`time 2>&1` \nとすると、標準エラー出力が標準出力として出力されます。 \nRailsは詳しくないのですが、 \n`env = 'eval \"$(rbenv init -)\"; cd :path && :environment_variable=:environment\nnice -n 10 time 2>&1'` \nとすればできると思います。\n\n・[cmd > /dev/null 2>&1」の話](http://qiita.com/sue71/items/cef17fabd180f4121f9e) \n・[標準エラー出力をファイルへ出力 - リダイレクトとパイプ -\nコマンドプロンプトの使い方](http://www.adminweb.jp/command/redirect/index3.html) \n・[[Bash]標準出力・標準エラー出力の全て(1>&2とか)まとめ | Coffee Breakにプログラミング備忘録](http://to-\ndeveloper.com/blog/?p=1001)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T03:03:17.703",
"id": "23470",
"last_activity_date": "2016-03-26T03:03:17.703",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8621",
"parent_id": "23469",
"post_type": "answer",
"score": 0
},
{
"body": "Rubyからどういったシェルが起動されるか知りませんが、`sh`や`bash`の話として書きます。\n\n### 一般の話\n\n標準エラー出力(FD: 2)を標準出力(FD: 1)に接続するにはリダイレクトで`2>&1`とします。 \nパイプで繋げるのが目的ならば短縮記法の`|&`も使えます。\n\n```\n\n # timeの(標準エラー)出力もnlに渡り行番号が付く\n nice -n 10 time ls 2>&1 |nl\n # パイプに繋げるなら短縮記法もある\n nice -n 10 time ls |& nl\n \n```\n\n### (Bash内部コマンドでない)timeの機能\n\n質問者さんが使っている`time`は`nice`から起動される物なので、外部コマンドの`time`です。 \nargusさんのコメントのように多分`-o`オプションがあります。\n\n```\n\n # 出力先に/dev/stdoutを指定\n nice -n 10 time -o /dev/stdout ls |nl\n \n```\n\n### Bash内部コマンドのtimeの場合\n\n`Bash`を使っている場合、niceに起動させずに普通に`time`を実行すると`bash`の内部コマンドの`time`が実行されます。 \nしかし、上記の方法は内部コマンドの`time`には使えません。\n\n```\n\n # timeの出力には行番号が付かない\n time ls 2>&1 |nl\n \n```\n\nとした場合、標準出力に接続されるのは`ls`のエラーだけです。 \n通常はこの方が便利だからです。 \nこれは`time`が`bash`の組込みコマンドであるからこそ実現できる機能です。\n\n`time`を含んだ全体のリダイレクトを指定する場合は、コマンド列をサブシェルで起動するよう明示する必要があります。 \nそれら全体にリダイレクトを指定します。\n\n```\n\n # 全てに行番号が付く\n (time ls) 2>&1 |nl\n \n```\n\nサブシェルでなく普通にシェルのプロセスを起動してもよいです。\n\n```\n\n bash -c 'time ls' 2>&1 |nl\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T03:38:25.787",
"id": "23471",
"last_activity_date": "2016-03-26T03:38:25.787",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23469",
"post_type": "answer",
"score": 3
}
]
| 23469 | 23471 | 23471 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "サンプルの RSSリーダーをそのまま起動しても loading.gif が表示され続けるか、 \nFailed to load RSS みたいなのが表示されるだけです。\n\n該当のサンプルは 現在使用できないのでしょうか? \nれとも 私の環境 利用の仕方が間違っていおるのでしょうか?\n\nご回答をお待ちしております。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T05:05:42.283",
"favorite_count": 0,
"id": "23473",
"last_activity_date": "2016-12-09T20:12:33.943",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14948",
"post_type": "question",
"score": -1,
"tags": [
"monaca"
],
"title": "MONACA RSSリーダーがRSSを読み込まない",
"view_count": 314
} | [
{
"body": "monaca開発画面のpreviewではloading.gifが表示されるのみですが、デバッガーではちゃんと表示されましたよ。お試しくださいませ。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T07:49:31.387",
"id": "23479",
"last_activity_date": "2016-03-26T07:49:31.387",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14300",
"parent_id": "23473",
"post_type": "answer",
"score": 0
},
{
"body": "私も同じ現象だったので以下のURLを参考に機能を付けたしていったところ、ある場所で同じ現象になりました。 \n<http://mb.cloud.nifty.com/doc/current/tutorial/monaca_rssreader.html#/JavaScript>\n\nためしにURLを元に戻したら正常に表示されました。\n\n```\n\n // CHANGE YOUR URL HERE!\n var feedUrl = \"http://feeds.bbci.co.uk/news/technology/rss.xml\";\n // フィードのURLを変更してください\n //var feedUrl = \"http://blog.mb.cloud.nifty.com/?feed=rss2\";\n \n```\n\n理由はわかりませんがrssの形式が意図されないものだったのでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-10-26T08:56:46.507",
"id": "29913",
"last_activity_date": "2016-10-26T08:56:46.507",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19323",
"parent_id": "23473",
"post_type": "answer",
"score": 0
}
]
| 23473 | null | 23479 |
{
"accepted_answer_id": "23481",
"answer_count": 1,
"body": "```\n\n remote: Permission to AAA/abc.git denied to BBB.\n fatal: unable to access 'https://github.com/AAA/abc.git/': The requested URL returned error: 403\n \n```\n\n`git add .` `git commit` した後に`git push`した結果上記のようなエラーがでてきました。 \nどこの設定を変更すれば解決しますか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T06:21:36.450",
"favorite_count": 0,
"id": "23475",
"last_activity_date": "2016-03-30T05:54:14.640",
"last_edit_date": "2016-03-26T07:44:15.607",
"last_editor_user_id": "2808",
"owner_user_id": "10088",
"post_type": "question",
"score": 1,
"tags": [
"git",
"github"
],
"title": "githubへgit pushしようとすると403エラーとなる",
"view_count": 15464
} | [
{
"body": "そのリポジトリ(AAA/abc)にpushする権限を持たないユーザー(BBB)でログインしているようです。\n\nHTTPSをお使いのようですから、push時に入力したユーザー名・パスワードがそのリポジトリで使っているものかどうか、確認してみてください。\n\n* * *\n\nリモートリポジトリにhttp(s)で接続していて認証が必要な場合には、基本的には毎回ログインを求められます。ただそれでは面倒なので、資格情報を記憶する\ncredential helperという仕組みがあります。\n\nこれはURLごとに記憶するわけですが、デフォルトではパスを無視するため、前回 `https://github.com/`\nにログインした際のユーザー名・パスワードでログインしてしまったようです。\n\n対策としては、`https://[email protected]/`としてURLにユーザー名を含めてしまうのが一番簡単だとは思いますが、一応他の方法も載せておきます。\n\n * 全く記憶しないようにする: configから`credential.helper`を消す\n * 記憶している情報を消す: `git credential reject` コマンドを使う\n * 記憶する際にパスも考慮するようにする: `credential.useHttpPath`をtrueにする\n\ncredential helper\nによってはGit側から伝えられたpathやusernameを無視する可能性もあります。その場合はこれらの方法が役立つかもしれません。\n\n参考\n\n * [Git - 認証情報の保存](https://git-scm.com/book/ja/v2/Git-%E3%81%AE%E3%81%95%E3%81%BE%E3%81%96%E3%81%BE%E3%81%AA%E3%83%84%E3%83%BC%E3%83%AB-%E8%AA%8D%E8%A8%BC%E6%83%85%E5%A0%B1%E3%81%AE%E4%BF%9D%E5%AD%98)\n * [How can I store keychain credentials for multiple Github accounts? - Stack Overflow](https://stackoverflow.com/a/24277934/2818869)",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T08:21:37.583",
"id": "23481",
"last_activity_date": "2016-03-30T05:54:14.640",
"last_edit_date": "2017-05-23T12:38:55.250",
"last_editor_user_id": "-1",
"owner_user_id": "8000",
"parent_id": "23475",
"post_type": "answer",
"score": 2
}
]
| 23475 | 23481 | 23481 |
{
"accepted_answer_id": null,
"answer_count": 3,
"body": "Rubyのスクリプトが一度でも巨大なメモリを確保してしまうと、ずっとメモリを保持し続けてしまう現象に悩んでいます。\n\n```\n\n require 'objspace'\n \n array = []\n (1..20).each_with_index do |i|\n array << 'a'*1000000\n puts \"memsize: #{ObjectSpace.memsize_of_all / 1024} KB, rss: #{`ps -o rss= #{Process.pid}`.chomp} KB\"\n \n if i % 5 == 0\n array = []\n GC.start\n puts \"memsize: #{ObjectSpace.memsize_of_all / 1024} KB, rss: #{`ps -o rss= #{Process.pid}`.chomp} KB\"\n end\n end\n \n```\n\nこんな感じのコードを書くと、実行結果は以下のようになります。\n\n```\n\n memsize: 4125 KB, rss: 8016 KB\n memsize: 5113 KB, rss: 9000 KB\n memsize: 6092 KB, rss: 10000 KB\n memsize: 7071 KB, rss: 11000 KB\n memsize: 8050 KB, rss: 11984 KB\n memsize: 2473 KB, rss: 11988 KB\n memsize: 3452 KB, rss: 11988 KB\n memsize: 4431 KB, rss: 11988 KB\n memsize: 5410 KB, rss: 11988 KB\n memsize: 6389 KB, rss: 11988 KB\n memsize: 7368 KB, rss: 11988 KB\n memsize: 2473 KB, rss: 11988 KB\n memsize: 3452 KB, rss: 11988 KB\n memsize: 4431 KB, rss: 11988 KB\n memsize: 5410 KB, rss: 11988 KB\n memsize: 6389 KB, rss: 11988 KB\n memsize: 7368 KB, rss: 11988 KB\n memsize: 2473 KB, rss: 11988 KB\n memsize: 3452 KB, rss: 11988 KB\n memsize: 4431 KB, rss: 11988 KB\n memsize: 5410 KB, rss: 11988 KB\n memsize: 6389 KB, rss: 11988 KB\n memsize: 7368 KB, rss: 11988 KB\n memsize: 2473 KB, rss: 11988 KB\n \n```\n\n時間を伸ばしたり、外からpsコマンドを実行したりしましたが、どうやってもRSSが減りません。 \nRubyオブジェクトに割り当てられたメモリは解放されているのに、せっかく開放したメモリをOSには返却してくれないようです。 \nこのプロセスに限れば確保したメモリを再利用できるからいいのですが、サーバー上には他のプロセスも動いてるわけでやはり使わなくなったメモリはOSに戻したいです。 \nRubyの仕様上、難しいことでしょうか?",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T07:36:19.417",
"favorite_count": 0,
"id": "23478",
"last_activity_date": "2019-01-09T10:23:48.830",
"last_edit_date": "2016-03-26T08:17:42.780",
"last_editor_user_id": "14950",
"owner_user_id": "14950",
"post_type": "question",
"score": 3,
"tags": [
"ruby",
"linux",
"c",
"memory-leaks"
],
"title": "Rubyのプロセスが掴んでいる実メモリを解放する手段はありますか?",
"view_count": 6924
} | [
{
"body": "Ruby ではオブジェクトを破棄しても free されにくい実装と記憶しています。(結構前の話なので今は変わっているかも?)\nまたCレベルの話をすると、free を呼んでもOSにメモリを返さず、次に malloc した際に再割当するような実装も多く存在します。\n\nということで、一般的にはメモリの解放によっても占有メモリが減らない前提でプログラミングすることになろうかと思います。\n\nどうしてもということであれば、メモリが解放されるようなRubyのバージョン (もし存在すれば)\nとmalloc/freeの実装の組み合わせを固定して開発する必要があるでしょう。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T14:26:46.867",
"id": "23492",
"last_activity_date": "2016-03-27T13:08:37.780",
"last_edit_date": "2016-03-27T13:08:37.780",
"last_editor_user_id": "76",
"owner_user_id": "76",
"parent_id": "23478",
"post_type": "answer",
"score": 5
},
{
"body": "### TL; DR\n\nruby では最大利用メモリ量まで rss が増えたあとなかなか減らないので、メモリ増設するなり、スワップを積むなりしましょう。\n\n### 本文\n\nMRI の ruby についての話をします。\n\nruby はその他プロセスと同じように、静的領域、プログラム領域(ruby本体とか native\nビルドのライブラリとか)に加えて、ヒープとスタックを持ちます。 ruby のプロセスの rss\nが増大する場合、だいたいはこのうちヒープが肥大化することによるものです。\n\nruby プログラムがヒープ上に保持するデータは、大きく分けて次の二つがあります。\n\n 1. オブジェクト(RVALUE)を保持するためのページ。 GC モジュールとかで取得できるデータの大体は、このページについてのお話\n 2. そこそこ大きいオブジェクトの中身(例: そこそこ大きい配列の実体)\n\nそれぞれのヒープ上のデータのメモリ確保の方法は、大体以下のようになっています。\n\n 1. オブジェクト(RVALUE)のページ: ページの中の空きが足りないときに、新しいページをヒープ上で確保(malloc)する\n 2. そこそこ大きいオブジェクトの中身: 直接メモリをヒープ上で確保(malloc)する。(オブジェクトの外側は 1 のページ上にある)\n\nまた、それぞれのメモリ解放のロジックは以下です。\n\n 1. オブジェクト(RVALUE)のページ: すべてのオブジェクトが GC で解放処理がなされたされたページに対して、 free が呼ばれうる(おそらく、そのようなページが増えてくると)\n 2. オブジェクトの中身: GC でオブジェクトの解放処理が実行される際に、 free される\n\nそして、つまり、最終的に重要になるのは malloc と free がどのように振る舞うか、になります。そして、 ruby がデフォルトで採用する\nglibc の malloc/free では、 free されたメモリを OS に返却するには、次の条件が必要になります。\n\n * (メイン)ヒープは、その先頭のメモリが解放済みである場合のみに、先頭を切り詰める形でヒープを縮める処理が実行されうる。\n\nこの挙動があるので、 ruby (というより、大体の動的に malloc/free する系の長期実行プログラム)\nでは、長く実行していると、最大利用メモリ量ぐらいまではメモリが確保されて、そのままなかなか小さくならない、といったような挙動になります。\n\nたまにしかメモリをたくさん使わない、長期実行のプログラムがある場合、個人的には swap を積んで、うまく swap in/out\nしてくれるのを期待する、が現実解なのではなかろうか、と思っています。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2019-01-08T00:11:51.513",
"id": "51809",
"last_activity_date": "2019-01-09T10:23:48.830",
"last_edit_date": "2019-01-09T10:23:48.830",
"last_editor_user_id": "754",
"owner_user_id": "754",
"parent_id": "23478",
"post_type": "answer",
"score": 3
},
{
"body": "Ubuntu 18.04 LTS on Windows Subsystem for Linux on Windows 10 Pro 1809 (64bit)\n環境で1.9~2.6のRubyについて傾向を調べました。Rubyはrbenv-installでインストールしています。\n\n結論から言うと各バージョンともrssの減少は確認できました。しかし、増減パターンやメモリ量はbバージョンによってバラバラで傾向は掴めませんでした。\n\n * 1.9.3-p551 \n1回目は増えて減る山を描くが、2回目以降は増えたままで、最後だけ少し減る。 \n最終値は初期値よりは多い。\n\n * 2.0.0-p648 \n山が4つになるパターンを描き、最終値は初期値とほぼ同じ。 \n初期値は1.9.3-p551よりも多いが、最大値や最終値は1.9.3-p551よりも少ない。\n\n * 2.1.10 \n2.0.0-p648とほぼ同じ。\n\n * 2.2.10 \n2.1.10とほぼ同じだが、消費量が約1.1倍ぐらいに増加。\n\n * 2.3.8 \n1.9.3-p551とほぼ同じパターンで増減する。 \n全体として、消費量は2.2.10の約1.7倍ぐらいに増加。\n\n * 2.4.5 \n2.3.8とほぼ同じだが、2.3.8の0.7倍ぐらいに減少。2.2.10よりはちょっと多い。\n\n * 2.5.3 \n2.4.5とほぼ同じだが、2.4.5の1.3倍ぐらいに増加。2.3.8よりはちょっと少ない。\n\n * 2.6.0 \n山が4つになるパターンを描き、最終値は初期値とほぼ同じ。 \nただし、初期値は2.5.3の最終値と同じぐらいと一番大きい。 \n最大値は2.5.3とほぼ同じ。 \n`--jit`付きの場合も同じ波形になる。\n\n各バージョンのリリースノートを見るとGCやメモリ周りのパフォーマンス改善は度々行われており、mallocの取り方、freeの取り方なども変わっていると思われます。なお、jemallocを有効にすると、また違った結果になるバージョンがありましたので、断片化のされやすさなども影響があると思います。\n\nということで、今回は単純に質問者さんの環境だとOS側がメモリを回収しなかっただけと思われます。より大きな容量(数百MB単位)でも本当に全くメモリが解放されないのかを確認してみてください。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2019-01-08T12:38:34.830",
"id": "51824",
"last_activity_date": "2019-01-08T12:38:34.830",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7347",
"parent_id": "23478",
"post_type": "answer",
"score": 2
}
]
| 23478 | null | 23492 |
{
"accepted_answer_id": "23500",
"answer_count": 2,
"body": "以下のC++11のコードについて\n\n```\n\n #include <iostream>\n #include <tuple>\n #include <utility>\n #include <cxxabi.h>\n #include <typeinfo>\n \n class foo\n {\n public:\n template<typename... types_>\n void method1(types_&&... args) {\n int status;\n \n auto method2_args = std::make_tuple(\n std::forward<types_>(args)...\n );\n auto fp = &foo::method2<int, int, decltype(method2_args)>;\n std::cout << abi::__cxa_demangle(typeid(method2_args).name(), 0, 0, &status) << std::endl;\n std::cout << abi::__cxa_demangle(typeid(fp).name(), 0, 0, &status) << std::endl;\n // (this ->*fp)(1, 2, method2_args); // error: invalid initialization of reference of type ‘std::tuple<int, int, std::tuple<float, double> >&’ from expression of type ‘std::tuple<float, double>’\n }\n \n template<typename... types_>\n void method2(int a, int b, std::tuple<types_...> &args )\n {\n }\n };\n \n int main()\n {\n foo f;\n f.method1(1.0f, 2.0);\n }\n \n```\n\n(this ->*fp)(1, 2, method2_args);がエラーとなってコンパイルできません。 \nコンパイラはg++-4.8です。g++-5.0, clang++-3.4でもエラーでした。\n\n不思議に思い、エラー箇所をコメントアウトして、method2_argsとfpのtype_info::name()を表示させたところ\n\n```\n\n std::tuple<float;, double>\n void (foo::*)(int, int, std::tuple<int;, int, std::tuple<float;, double> >&)\n \n```\n\nでした。最初のがmethod2_argsで次がfpのtype_info::name()です。 \nmethod2_argsは期待どおりでした。 \nしかしfpは実に奇妙で期待していたものと違いました。\n\n```\n\n void (foo::*)(int, int, std::tuple<float;, double> >&)\n \n```\n\nを期待していました。\n\n * 質問1. \nfpはなぜこのような結果になるのでしょうか?\n\n * 質問2. \nfpを私が期待したものにするにはどうしたらよいでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T08:05:55.453",
"favorite_count": 0,
"id": "23480",
"last_activity_date": "2016-03-27T06:21:32.927",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7844",
"post_type": "question",
"score": 0,
"tags": [
"c++",
"c++11"
],
"title": "可変長引数テンプレートメンバ関数へのポインタ。その引数が期待通りにならない。",
"view_count": 1030
} | [
{
"body": "_fpはなぜこのような結果になるのでしょうか?_\n\n * method2の引数`int a, int b,`は、型パラメータ`types_`を使用していませんから`auto fp = &foo::method2<int, int, decltype(method2_args)>;`のようにそれらに対応する`int, int,`を実型引数に与えてはいけません。\n * `method2_args`のデータ型はすでに`std::tuple<float, double>`なのですから、そのデータ型を(method2の)`types_`に渡せば`std::tuple<types_...>`は当然tupleのtupleになります。\n\n_fpを私が期待したものにするにはどうしたらよいでしょうか?_ \ngccは手元にないので、Clangで確認しただけですが、次のように`fp`だけでなく`method2`も書き換える必要があるでしょう。\n\n```\n\n template<typename... types_>\n void method1(types_&&... args) {\n int status;\n \n auto method2_args = std::make_tuple(\n std::forward<types_>(args)...\n );\n auto fp = &foo::method2<decltype(method2_args)>;\n std::cout << abi::__cxa_demangle(typeid(method2_args).name(), 0, 0, &status) << std::endl;\n std::cout << abi::__cxa_demangle(typeid(fp).name(), 0, 0, &status) << std::endl;\n (this ->*fp)(1, 2, method2_args);\n }\n \n template<typename arg_type>\n void method2(int a, int b, arg_type &args )\n {\n }\n \n```\n\n(追記) \n`method2_args`の作り方を間違えると型の不整合が起こりますが、こうすればmethod2の書き換えは不要になりますね。\n\n```\n\n auto fp = &foo::method2<types_...>;\n \n```\n\n(他は質問者さんのコードのまま。)",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T08:40:02.673",
"id": "23482",
"last_activity_date": "2016-03-26T09:02:29.480",
"last_edit_date": "2016-03-26T09:02:29.480",
"last_editor_user_id": "13972",
"owner_user_id": "13972",
"parent_id": "23480",
"post_type": "answer",
"score": 1
},
{
"body": "自己回答です。 \nfpを\n\n```\n\n void (foo::*fp)(int, int, decltype(method2_args)&) = &foo::method2;\n \n```\n\nとすることで、期待通りになりました。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T06:21:32.927",
"id": "23500",
"last_activity_date": "2016-03-27T06:21:32.927",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7844",
"parent_id": "23480",
"post_type": "answer",
"score": 1
}
]
| 23480 | 23500 | 23482 |
{
"accepted_answer_id": "23486",
"answer_count": 1,
"body": "windowsなどでプログラムが応答しないという記述が表示されることがありますが、 \nこのような応答の応答がないプログラムを検出するプログラムはどのようになっているのですか? \n毎回毎回プログラム以前の無知な質問ですみません\n\n【追記】 \n「イベントが一定時間以上の間処理されない」 \nC++/cliかC#の入門で一番最初にウインドウだけを作るプログラム(いわゆるhello\nworldプログラム)を作った経験があるのですが、あれにもイベントがあるのですか。 \nイベントはクリックしたりキーボード入力などの時に呼び出されることは知っていますが、あれ単体では何かしらのイベントがあるのか疑問です。 \nその回答がPeekMessageだとわかりました。 \nPeekMessageとはなんですか?プロセス間通信か何かの用語ですか?(非常に完結でかまいません残りは自力でどうにかします。というより調べたら関数だということがわかりました。)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T11:09:04.613",
"favorite_count": 0,
"id": "23485",
"last_activity_date": "2016-03-27T09:09:05.297",
"last_edit_date": "2016-03-26T12:07:46.330",
"last_editor_user_id": "10455",
"owner_user_id": "10455",
"post_type": "question",
"score": 4,
"tags": [
"アルゴリズム"
],
"title": "無限ループはどのようにして検出しているのですか?",
"view_count": 2153
} | [
{
"body": "一般的にアプリが何らかの無限ループにはまっていることを検出することはできず、単に「プログラムが応答しない」ことを検出しているにすぎません。 \nWindowsなどのGUI系アプリの場合、イベントキューを用いたイベントドリブンな書き方をするのが一般的ですから、「イベントが一定時間以上の間処理されない」ことで「応答がない」と判定できます。\n\nWindowsの場合[superuser](http://superuser.com)(本家stackoverflowのファミリーサイト)に[似た質問のスレッド](https://superuser.com/questions/961843/how-\ndoes-windows-know-if-a-program-is-not-responding)がありました。 \nその中に紹介されているWindowsの[IsHungAppWindow function](https://msdn.microsoft.com/ja-\njp/library/windows/desktop/ms633526\\(v=vs.85\\).aspx)には次のような記載があります。\n\n> An application is considered to be not responding if it is not waiting \n> for input, is not in startup processing, and has not called \n> PeekMessage within the internal timeout period of 5 seconds.\n\n「入力待ちでも起動時処理をしているのでもない場合に5秒間PeekMessageを呼んでいなければ、応答がないと考えられる。」\n\n【追記】\n\n> C++/cliかC#の入門で一番最初にウインドウだけを作るプログラム(いわゆるhello\n> worldプログラム)を作った経験があるのですが、あれにもイベントがあるのですか。\n\nはい。イベントキューを監視する部分は、システム側で記述されており、常にイベントキューに新しいイベントが入ってきていないかをチェックしています。(あなたが書いたコードにイベント処理の部分があるかないかは関係ありません。)\n\n> PeekMessageとはなんですか?\n\nWindows APIの用語です。Windows\nAPIではイベントキューに入るイベントを一般化して「Message」と呼んでいるので、そのような名前になっています。要はイベントキューに新しいイベントが入っていないかどうか覗いてみるための関数ですね。先に書いたように、システム側で処理しているので、普通のアプリの中には現れません。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T11:48:46.687",
"id": "23486",
"last_activity_date": "2016-03-27T09:09:05.297",
"last_edit_date": "2017-03-20T10:18:03.377",
"last_editor_user_id": "-1",
"owner_user_id": "13972",
"parent_id": "23485",
"post_type": "answer",
"score": 5
}
]
| 23485 | 23486 | 23486 |
{
"accepted_answer_id": "23509",
"answer_count": 1,
"body": "ajaxを使って書いたいいね(likeと定義)リンクがおささりません。リンクは画面上に表示されているのですが。 \nコードに問題があるのでしょうか?それともPCに必要なアプリケーションが導入されていないのでしょうか? \nコードは、 \nlikes_controller.rbが\n\n```\n\n class LikesController < ApplicationController\n \n before_action :authenticate_user!\n \n def like\n @note = Note.find(params[:note_id])\n like = current_user.likes.build(note_id: @note.id)\n like.save \n end\n \n def unlike\n @note = Note.find(params[:id])\n like = current_user.likes.find_by(note_id: @note.id)\n like.destroy\n end\n end\n \n```\n\n_like_links.html.erbが\n\n```\n\n <% if current_user.likes.find_by(note_id: @note.id) %>\n <%= link_to 'いいね!を取り消す', unlike_path(@note.id), method: :delete, remote: true %>\n <% else %>\n <%= link_to 'いいね!', like_path(@note.id), method: :post, remote: true %>\n <% end %>\n \n```\n\nlike.js.erbが\n\n```\n\n $('#like-link').html('<%= escape_javascript(render(\"likes/like_links\", note: @note)) %>');\n $('#like-count').html('<%= @note.likes.count %>');\n \n```\n\nunlike.js.erbが\n\n```\n\n $('#like-link').html('<%= escape_javascript(render(\"likes/like_links\", note: @note)) %>');\n $('#like-count').html('<%= @note.likes.count %>');\n \n```\n\nusersフォルダのshow.html.erが\n\n```\n\n <p id=\"notice\" class=\"alert-success\"><%= notice %></p>\n \n <aside class=\"sidebar\">\n <section>\n <span class=\"label\">プロフィール画像</span>\n <h3 class=\"user-info\">\n <%= image_for(@user) %>\n </h3>\n </section>\n \n <section>\n <span class=\"label\">Name:</span>\n <h3 class=\"user-info\"><%= @user.name %></h3>\n </section>\n \n <section>\n <span class=\"label\">Email:</span>\n <h3 class=\"user-info\"><%= @user.email %></h3>\n </section>\n \n <%= link_to @user.likes.count, like_notes_user_path(@user.id) %>個の投稿にいいね!しています\n \n \n <% if current_user?(@user) %>\n <section>\n <small><%= link_to \"プロフィールを編集\",edit_user_path(@user) %></small>\n </section>\n <% end %>\n \n </aside>\n \n <ul class=\"notes\">\n <h2><%= @title %></h2>\n <%= render @notes %>\n </ul>\n \n```\n\nnotesフォルダのshow.html.erが\n\n```\n\n <p id=\"notice\" class=\"alert alert-success\">\n <%= notice %>\n </p>\n \n <h2>今何してる?</h2>\n <p><%= @note.content %></p>\n \n <div id=\"like-link\">\n <!-- 送信先とmethodを指定してください -->\n <%= render \"likes/like_links\", note: @note %>\n </div>\n \n <div>\n <small>\n <%= link_to @note.likes.count, liking_users_note_path(@note.id), id: \"like-count\" %>人がいいね!といっています\n </small>\n </div>\n \n <% if current_user?(@note.user) %>\n <%= link_to \"つぶやく\", edit_note_path(@note.id),class:\"edit\" %>\n <%= link_to \"削除\", destroy_note_path(@note.id), method: \"delete\", class: \"destroy\", \"data-confirm\" => \"本当に削除しますか?\" %>\n <% end %>\n \n```\n\nliking_users.html.erbが\n\n```\n\n <ul class='show-note'>\n <%= render @note %>\n </ul>\n \n <h2 class=\"heading\">いいねしているユーザー一覧 </h2>\n <ul class='user-list'>\n <!-- ここでパーシャルファイルを呼び出してください -->\n <%= render @users %> \n </ul>\n \n```\n\nです。\n\n追加です。 \nいいね!ボタンが正常におささると、 \n「いいね! \n0人がいいね!といっています」(いいね!と0人の所は押すことができます) \nと表示されているところが、 \n「いいね!を取り消す \n1人がいいね!といっています」(いいね!を取り消すと1人の所は押すことができます) \nと変化します。\n\nroutes.rbには\n\n```\n\n Rails.application.routes.draw do\n \n devise_for :users\n \n resources :users, only: [:index, :show, :edit, :update,:like] do\n member do\n get :like_notes\n end\n end ←ここ\n \n resources :notes, only: [:show, :create, :edit, :update, :destroy] do\n member do\n get :liking_users\n end\n end ←ここ\n \n \n get'/top' => 'home#top'\n \n get'/connection' => 'home#connection'\n get'/notes/new' => 'notes#new'\n post'/notes' =>'notes#create'\n get'/notes' =>'notes#index'\n get'/show/:id' => 'notes#show'\n patch'/notes/:id' =>\"notes#update\",as:'update_note'\n delete'/notes/:id' =>\"notes#destroy\",as:'destroy_note'\n \n \n post '/like/notes/:id' => 'likes#like', as: 'like'\n delete '/unlike/notes/:id' => 'likes#unlike', as: 'unlike'\n \n root 'home#top'\n get'/about' => 'home#about'\n end\n \n```\n\nで←ここでしめした所が該当するルーターです。 \nお願いいたします。",
"comment_count": 7,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T12:53:22.257",
"favorite_count": 0,
"id": "23488",
"last_activity_date": "2016-03-27T13:57:15.540",
"last_edit_date": "2016-03-27T12:49:01.393",
"last_editor_user_id": "14754",
"owner_user_id": "14754",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "ajaxを使って書いたリンクがおささりません",
"view_count": 271
} | [
{
"body": "とりあえずこの部分に不整合がありますね。 \nlikes_controller.rb:\n\n```\n\n @note = Note.find(params[:note_id])\n \n```\n\n・`:note_id`でパラメータを取得している。\n\nroutes.rb:\n\n```\n\n post '/like/notes/:id' => 'likes#like', as: 'like'\n \n```\n\n・`:id`としてパラメータを定義している。\n\nこの両者は一致させておかないと正しくパラメータが取得できていないはずです。`unlike`側ではroutes.rbでもlikes_controller.rbでも`:id`で参照していますが、`like`側も`params[:id]`として参照すべきでしょう。\n\nかなりややこしい処理なので、他にも何かあるかもしれません。この修正を施してもまだダメな時は、(その時のコードで)一体どんな動作になっているか(ログが取れるならログも含めて)できるだけ詳しい情報をお知らせください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T13:57:15.540",
"id": "23509",
"last_activity_date": "2016-03-27T13:57:15.540",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "23488",
"post_type": "answer",
"score": 2
}
]
| 23488 | 23509 | 23509 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "OutlookのVBAを使って、会議開催通知の予約をキャンセルを受信したら予定表から予定を自動的に削除するコードを書いてみています。 \nしかし、★印のところからエラーに成って動かないようです。\n\nVBAの超初心者ですが教えて頂けませんでしょうか?\n\n```\n\n Set tmpItem = Application.Session.GetItemFromID(buf(i))\n If tmpItem.MessageClass = \"IPM.Schedule.Meeting.Request\" Then\n Set tmpAppoint = tmpItem.GetAssociatedAppointment(True)\n Set tmpMeeting = tmpAppoint.Respond(olResponseAccepted, True)\n tmpMeeting.Send\n ElseIf tmpItem.MessageClass = \"IPM.Schedule.Meeting.Canceled\" Then\n Dim meetItem As MeetingItem\n Dim apptItem As AppointmentItem\n Set meetItem = objItem\n Set apptItem = meetItem.GetAssociatedAppointment(False)★\n apptItem.MeetingStatus = olMeetingCanceled\n apptItem.Send\n apptItem.Delete\n End If\n \n```",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T15:03:34.977",
"favorite_count": 0,
"id": "23493",
"last_activity_date": "2016-03-26T17:01:38.607",
"last_edit_date": "2016-03-26T17:01:38.607",
"last_editor_user_id": "6092",
"owner_user_id": "14953",
"post_type": "question",
"score": 0,
"tags": [
"vba"
],
"title": "OutlookのVBAで予定表削除がされない",
"view_count": 1425
} | []
| 23493 | null | null |
{
"accepted_answer_id": "23587",
"answer_count": 1,
"body": "現在、monacaでタグでonclickを使用して遷移したい考えております。 \nonclickはタグで遷移させようとすると動作をしないことがわかりました. \nreturn falseを付け加えることで遷移させずに、onclickは起動しております。 \n自分の作成したい内容はonclickが動いて違うページに遷移させたいのでが、 \nこうするためにはどのようなプログラムにすればよろしいですか? \n以下にプログラム内容を載せます\n\nご教授よろしくお願いします。\n\nonclick.js\n\n```\n\n function onRegisterBtn(id){\n ncmb.Installation.fetchById(id).then(function(installation){\n var seibetu = $(\"#reg_seibetu option:selected\").val(); \n installation.set(\"seibetu\", seibetu);\n return installation.update();\n })\n .then(function(installation){\n alert('登録完了しました');\n })\n .catch(function(err){\n alert('登録完了できませんでした');\n });\n }\n \n```\n\nindex.html\n\n```\n\n <p>年齢<br>\n <select id=\"reg_nenrei\">\n <option value=\"10\">10代</option>\n <option value=\"20\">20代</option>\n <option value=\"30\">30代</option>\n <option value=\"40\">40代</option>\n <option value=\"50\">50代</option>\n <option value=\"60\">60代</option>\n <option value=\"その他\">その他</option>\n </select>\n </p> \n <a href=\"index.html\" onclick=\"onRegisterBtn('id')\">登録する</a>\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T15:19:05.017",
"favorite_count": 0,
"id": "23494",
"last_activity_date": "2016-03-29T05:25:28.603",
"last_edit_date": "2016-03-27T13:49:02.917",
"last_editor_user_id": "13367",
"owner_user_id": "13367",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"monaca",
"html"
],
"title": "onclickを使用して遷移したい",
"view_count": 2370
} | [
{
"body": "### onClick属性のイベントハンドラでデフォルト動作を抑止する\n\nリンクがクリックされた時には、ブラウザのデフォルト動作として自動で遷移が行なわれます。 \nこれを防ぐにはonClick属性の場合、返り値に`false`を指定します。\n\n```\n\n <a href=\"index.html\" onclick=\"onRegisterBtn('id'); return false;\">登録する</a>\n \n```\n\n### addEventListener等で登録したイベントハンドラでデフォルト動作を抑止する\n\nCordova・Monacaでは通常onClick属性などは使わず、JavaScriptは別ファイルにして`addEventListener`などを使うと思います。\n\n```\n\n <a id=\"regist\" href=\"index.html\" >登録する</a>\n \n```\n\nこの場合イベントハンドラへは引数でイベントオブジェクトが渡されます。このイベントオブジェクトの`preventDefault`メソッドを呼び出すとデフォルト動作が抑止出来ます。\n\n```\n\n document.getElementById(\"regist\").addEventListener(\"click\", function(event){\n event.preventDefault();\n onRegisterBtn('id');\n }, false);\n \n```\n\n(質問の例の`onRegisterBtn`はイベントオブジェクトを受け取るように出来ていません。よって上記のコードではイベントハンドラに無名関数を指定し、その無名関数から`onRegisterBtn`を呼ぶようにしています)\n\n### JavaScriptで遷移する\n\nブラウザのデフォルト動作を抑止すると、リンクをクリックしてもイベントハンドラが実行された後に何も起こりません。 \nJavaScriptで遷移させる必要があります。`location.assign`を使います。\n\n```\n\n alert('登録完了しました');\n location.assign(\"index.html\");\n \n```\n\n### 現URLの履歴を消して遷移させる(置き換える)\n\nユーザーに遷移を意識させたくなかったり、現在のURLが遷移後は無効になるような場合は`location.replace`を使い現URLに戻れなくします。\n\n```\n\n alert('登録完了しました');\n location.replace(\"index.html\");\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-29T05:25:28.603",
"id": "23587",
"last_activity_date": "2016-03-29T05:25:28.603",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3054",
"parent_id": "23494",
"post_type": "answer",
"score": 1
}
]
| 23494 | 23587 | 23587 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "現在、OnsenUIでTwitterクライアントの制作に挑戦しております。参考としてhttp://docs.monaca.mobi/cur/ja/sampleapp/samples/twitter/のサンプルを基に制作しておりました。サンプルにはindex.htmlのページにConnect\nto Twitterを設置していました。このConnect to\nTwitterのボタンをアプリの起動時に開かれるログイン画面ページとしておきたいです。認証後にタイムラインが表示されたタブバー付きのページへと遷移するという形を作りたいのですがどうにもうまくいきません。ご教授お願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-26T17:50:17.497",
"favorite_count": 0,
"id": "23495",
"last_activity_date": "2016-11-02T07:33:05.790",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13526",
"post_type": "question",
"score": 0,
"tags": [
"monaca",
"onsen-ui"
],
"title": "ログイン画面とタブバー付きのホーム画面を分けたい",
"view_count": 1334
} | [
{
"body": "**4/11修正版** \nログイン画面を表示する場合、`ons-tabbar`の`ng-show`を`false`にしてタブバーを非表示にします。 \n認証後、`ng-show`を`true`にしてタブバーを表示させます。 \nとりあえず、サンプルコードをベースにそれらしく動作するようにコードを修正しました。 \nGapDebugなどを利用すれば、どの行で何が行われているか把握できるはずです。\n\n※`AngularJS`を使用。\n\n```\n\n <!DOCTYPE HTML>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'\">\n <script src=\"components/loader.js\"></script>\n <script src=\"js/jsoauth.js\"></script>\n <link rel=\"stylesheet\" href=\"components/loader.css\">\n <link rel=\"stylesheet\" href=\"css/app.css\">\n <script>\n var app = ons.bootstrap(\"myApp\", [\"onsen\"]);\n app.controller(\"indexController\", [\"$scope\", function($scope) {\n var callbackUrl = \"http://example.com\";\n $scope.oauth = OAuth({\n consumerKey: \"eFszoQFkofI8BQegCOBdw\", // REPLACE HERE TO YOUR CONSUMER KEY or API KEY\n consumerSecret: \"8g3zp7n2x3XVx7qUAXyFChgXoksKubn6J4XP57FWy4g\", // REPLACE HERE TO YOUR CONSUMER SECRET OR API SECRET\n callbackUrl: callbackUrl,\n requestTokenUrl: \"https://api.twitter.com/oauth/request_token\",\n authorizationUrl: \"https://api.twitter.com/oauth/authorize\",\n accessTokenUrl: \"https://api.twitter.com/oauth/access_token\"\n });\n $scope.isConnect = false;\n $scope.jsonData = [];\n $scope.connect = function() {\n $scope.oauth.fetchRequestToken(function(url) {\n console.log(\"Opening Request Token URL: \" + url);\n showAuthWindow(url);\n }, function(data) {\n console.log(JSON.stringify(data));\n });\n };\n function showAuthWindow(url) {\n var browser = window.open(url, '_blank', 'location=yes');\n browser.addEventListener('loadstart', function(event) {\n if (event.url.indexOf(callbackUrl) >= 0) {\n event.url.match(/oauth_verifier=([a-zA-Z0-9]+)/);\n $scope.oauth.setVerifier(RegExp.$1);\n $scope.oauth.fetchAccessToken(function(data) {\n $scope.isConnect = true;\n $scope.$apply();\n getTwits();\n browser.close();\n }, function(data) {\n console.log(JSON.stringify(data));\n });\n }\n });\n }\n function getTwits() {\n $scope.oauth.getJSON('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=monaca_io&count=20', \n function(data) {\n $scope.jsonData = data;\n $scope.$apply();\n }, function(data){\n console.log(JSON.stringify(data));\n });\n }\n }]);\n app.controller(\"timelineController\", [\"$scope\", function($scope) {\n $scope.timelineTable = [];\n ons.ready(function() {\n });\n $scope.$watchCollection(\"jsonData\", function(newVal, oldVal) {\n if (newVal.length > 0) {\n $scope.timelineTable = angular.copy(newVal);\n }\n })\n }]);\n </script>\n </head>\n <body ng-controller=\"indexController\">\n <ons-page>\n <ons-toolbar>\n <div class=\"center\">Connect to Twitter</div>\n </ons-toolbar>\n <div style=\"text-align: center;\">\n <br>\n <ons-button ng-click=\"connect()\">Connect to Twitter</ons-button>\n </div>\n </ons-page>\n <ons-tabbar var=\"tabbar\" ng-show=\"isConnect\">\n <ons-tab\n icon=\"home\"\n label=\"Home\"\n page=\"timeline.html\"\n active=\"true\"></ons-tab>\n <ons-tab\n icon=\"comment\"\n label=\"Comments\"\n page=\"page2.html\"></ons-tab>\n <ons-tab\n icon=\"gear\"\n label=\"Settings\"\n page=\"page3.html\"></ons-tab>\n </ons-tabbar>\n <ons-template id=\"timeline.html\">\n <ons-page ng-controller=\"timelineController\">\n <ons-toolbar>\n <div class=\"center\">Twitter Timeline</div>\n </ons-toolbar>\n <ons-list>\n <ons-list-item ng-repeat=\"item in timelineTable\">\n <div class=\"list-item-main\">\n <div class=\"list-item-left\">\n <img src=\"{{item.user.profile_image_url}}\" class=\"list-item-face\">\n </div>\n <div class=\"list-item-right\">\n <span class=\"list-item-name\">\n {{item.user.name}}<span class=\"lucent\">@{{item.user.screen_name}}</span>\n </span>\n <br />\n <span class=\"list-item-text\">\"{{item.text}}</span>\n </div>\n </div>\n </ons-list-item>\n </ons-list>\n </ons-page>\n </ons-template>\n </body>\n </html>\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-04-08T09:09:19.073",
"id": "23845",
"last_activity_date": "2016-04-10T23:51:51.367",
"last_edit_date": "2016-04-10T23:51:51.367",
"last_editor_user_id": "9566",
"owner_user_id": "9566",
"parent_id": "23495",
"post_type": "answer",
"score": 1
}
]
| 23495 | null | 23845 |
{
"accepted_answer_id": "23501",
"answer_count": 1,
"body": "```\n\n $ cat pseudo-yes.sh\n #!/bin/sh\n \n while true; do\n printf \"y\\n\"\n done\n $ \n \n```\n\n上記のような、 `pseudo-yes.sh`を記述しました。これを、例えば次のように使うと、問題無く `yes` コマンドのような動きをしてくれます。\n\n```\n\n $ ./pseudo-yes.sh | head -n 1\n y\n $ \n \n```\n\n* * *\n\nこの挙動を見る限り、 `printf` コマンドの実行に際して発生する`SIGPIPE`シグナルは、 `pseudo-\nyes.sh`が受信・処理しているはずだと理解できます。(でないと、 `while`文から抜け出せるはずがない)\n\n自分の理解ですと、`SIGPIPE` シグナルは、 `write`システムコールを行ったプロセスに対して発行されるものはずだと思っています。\n\n質問:\n\n * どうして、書き込みを行う主体のプロセスは `printf` なのに、`pseudo-yes.sh` が `SIGPIPE`を正しく処理できているのでしょうか?\n\n補足:\n\n * この挙動は、 ubuntu と mac-os-x の両方で観測されました。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T05:46:12.983",
"favorite_count": 0,
"id": "23498",
"last_activity_date": "2017-05-08T16:41:22.667",
"last_edit_date": "2016-03-27T05:58:07.553",
"last_editor_user_id": "754",
"owner_user_id": "754",
"post_type": "question",
"score": 14,
"tags": [
"sh",
"unix"
],
"title": "擬似 yes コマンドを書いたのですが、 SIGPIPE がどうしてよろしく処理されるのかがわからない",
"view_count": 910
} | [
{
"body": "Ubuntu の `/bin/sh` (bash, dash または posh)、Mac OS X の `/bin/sh` (bash) どちらも\n`printf` はシェル組込みコマンドです。\n\n```\n\n $ /bin/sh -c 'type printf'\n printf is a shell builtin\n \n```\n\nまた `SIGPIPE` のデフォルトのシグナルハンドラーはプロセスの終了です。よって、件のコードを実行すると `/bin/sh` プロセスが\n`SIGPIPE` シグナルを受け、終了します。\n\nUbuntu であれば次のように実行すれば `/bin/sh` が外部コマンドを起動していないこと \n(システムコール `fork`(2)、`clone`(2)、`execve`(2) を実行していない)、 \n`SIGPIPE` を受け取っていることを観測できます。\n\n```\n\n $ strace -f /bin/sh -c 'while true; do printf \"y\\n\"; done' |head -n 1\n \n```\n\nよって、想定通りの動作ですね。\n\n`printf` が組込みでない `/bin/sh` も想定するなら、次のように `printf` の終了コードが 0\n以外なら終了するようにしましょう。`printf`(1) プロセスが `SIGPIPE` を受けて終了したなら、終了コードは 128 + `SIGPIPE`\nの整数値(一般的には 13) = 141 になります。\n\n```\n\n #!/bin/sh\n \n while true; do\n printf \"y\\n\" || exit $?\n done\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T06:29:02.640",
"id": "23501",
"last_activity_date": "2017-05-08T16:41:22.667",
"last_edit_date": "2017-05-08T16:41:22.667",
"last_editor_user_id": "3061",
"owner_user_id": "3061",
"parent_id": "23498",
"post_type": "answer",
"score": 15
}
]
| 23498 | 23501 | 23501 |
{
"accepted_answer_id": "23512",
"answer_count": 1,
"body": "タイトル通りなんですが、iOSのミュージックアプリの曲タイトルなどのように自動で横スクロールさせる方法を教えていただきたいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T09:19:06.603",
"favorite_count": 0,
"id": "23502",
"last_activity_date": "2016-04-02T04:59:55.033",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13963",
"post_type": "question",
"score": 0,
"tags": [
"ios",
"objective-c"
],
"title": "テキストをオートスクロールさせたい",
"view_count": 1289
} | [
{
"body": "残念ながらiOSには、テキストを「自動で横スクロールさせる」ようなUI部品はないようです。\n\niOSのミュージックアプリでどのような方法がとられているかはわかりませんが、ご質問に書かれたようなことをやるために思いつくところを書いておきます。\n\n(1) 「自動で」は諦めて、あなたのコードで全てコントロールする\n\nコードでメインViewに貼り付けた子Viewの位置を変更するのは簡単ですし、UIScrollViewなんてものを使うこともできそうです。…と思ってコードを書きかけたのですが、思っていたより大変で、回答としては長すぎるのと、Swiftで書いてしまったので、掲載は控えておきます。\n\nうまく探せばフリーのライブラリーなど見つかるかもしれません。\n\n(2) WebViewを使ってmarquee系のタグを流し込む\n\nUIWebViewを横に細長く貼り付けてIBOutletにしておいて、\n\n```\n\n @IBOutlet weak var webView: UIWebView!\n \n```\n\nそれにmarquee系のタグを流し込めば、\n\n```\n\n webView.loadHTMLString(\"<marquee>iOSのミュージックアプリの曲タイトルなどのように自動で横スクロールさせる方法を教えていただきたいです</marquee>\", baseURL: nil)\n \n```\n\n(とりあえずSwiftで動作確認したんで、Swiftのコード例で我慢してください。) \n簡単という意味ではこれが一番簡単でしょうか。`<marquee>`タグはHTML5だと非推奨だとか(iOS9.3のUIWebViewでもちゃんと横スクロールはしますが)、フォントや背景色などをいじろうと思うと流し込むHTML+CSSがやたらでかくなるとかはありますが。\n\n(3) SKScene中にテキストスプライトを置いて流れるように移動させる\n\n手間がかかる割にメリットが見当たらないですね。SKSceneの中だけで展開するゲームならやっているアプリもあるかもしれませんが、普通のアプリではやらないでしょう。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T14:38:19.427",
"id": "23512",
"last_activity_date": "2016-03-27T21:38:25.927",
"last_edit_date": "2016-03-27T21:38:25.927",
"last_editor_user_id": "13972",
"owner_user_id": "13972",
"parent_id": "23502",
"post_type": "answer",
"score": 1
}
]
| 23502 | 23512 | 23512 |
{
"accepted_answer_id": "23505",
"answer_count": 2,
"body": "Segmentation Faultとはなんですか?スタックオーバーフローと違いはありますか?\n\n<https://stackoverflow.com/questions/2346806/what-is-segmentation-fault> \n(あと↑これ普通にコピペしただけでここのリンクと同じように扱われないの?(メタ的内容))\n\n英語版では \nSegmentation Faultとはなんですか?C/C++でのその定義はどうなっていますか?Dangling pointer都の関係性はありますか? \nといったところでしょう。\n\n最後に、 \nSegmentation Fault←これカタカナでどう書いたらいいですか \nDangling pointer←これカタカナでどう書いたらいいですか\n\n【追記】 \n自分で調べたこと \nSegmentation Faultはメモリアクセスによて起こされるエラーの一種です。\n\n<https://stackoverflow.com/questions/17997228/what-is-a-dangling-pointer>\n\nDangling pointerはデータが無効またはポインタそのものが無効なポインタのことといっている気がします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T10:22:01.537",
"favorite_count": 0,
"id": "23503",
"last_activity_date": "2016-03-27T20:26:34.340",
"last_edit_date": "2017-05-23T12:38:56.083",
"last_editor_user_id": "-1",
"owner_user_id": "10455",
"post_type": "question",
"score": 3,
"tags": [
"c++",
"c"
],
"title": "Segmentation Faultとはなんですか?",
"view_count": 66588
} | [
{
"body": "> Segmentation Faultとはなんですか?\n\n使用しているシステム(主にCPUと言うか、そのCPUの採用するメモリ管理機構)により細部には違いがありますが、メモリの特定の領域に対するアクセス違反が検出された時に発生する例外(割り込みと言ったほうがいいかもしれません)をSegmentation\nFaultと総称して(元はUnix用語でしょう)いて、次のような場合に発生します。\n\n * メモリが割り当てられていない領域にアクセスしようとした(*)\n * 書き込みが禁止されている領域に書き込もうとした\n * 実行が禁止されている領域のコードを実行しようとした\n\n(* デマンドページングとかは一旦無視しておきます。) \n言葉自体は、メモリ管理方式上の([ページング方式](https://ja.wikipedia.org/wiki/%E3%83%9A%E3%83%BC%E3%82%B8%E3%83%B3%E3%82%B0%E6%96%B9%E5%BC%8F)に対しての)[セグメント方式](https://ja.wikipedia.org/wiki/%E3%82%BB%E3%82%B0%E3%83%A1%E3%83%B3%E3%83%88%E6%96%B9%E5%BC%8F)から来ていると思われるのですが、segmentという言葉自体は「(細分化された後の個々の)部分」と言う意味があるので、ページング主流の時代になっても生き残っているのでしょう。\n\n> スタックオーバーフローと違いはありますか?\n\n両者は異なる概念です。スタックオーバーフローはSegmentation Faultの原因の大きな一つですが、Segmentation\nFaultはそれとは独立した概念です。メモリ保護機構がないシステムの場合、スタックオーバーフローが発生してもSegmentation\nFaultが発生しないまま(いろいろな領域を壊して)実行が続くこともありますし、スタックオーバーフロー以外の様々な要因によってもSegmentation\nFaultは発生します。\n\n「最後に」はこちらのサイトで扱うトピックとは言い難いように思いますので、パスしておきます。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T11:29:34.997",
"id": "23505",
"last_activity_date": "2016-03-27T13:26:48.730",
"last_edit_date": "2016-03-27T13:26:48.730",
"last_editor_user_id": "5793",
"owner_user_id": "13972",
"parent_id": "23503",
"post_type": "answer",
"score": 4
},
{
"body": "Dangling pointer というのは、「元々は有効だったが、参照しているオブジェクトがなくなってしまったので無効になったポインタ」のことです。\n\n最初のリンク先の例をそのまま借りますが、\n\n```\n\n char *p = NULL;\n {\n char c;\n p = &c;\n }\n // Now p is dangling\n *p = 'a'; // dangling pointer へのアクセス\n \n```\n\n中のブロックで `p = &c;` は問題ありません。`c` は、まだ有効で、したがって、そのアドレスも当然有効だからです。しかし、ブロックの外の `*p\n= 'a';` では、既に `c` はなくなっており、したがって、`p` が持っている `c` へのアドレスは無効になっています。これが dangling\npointer です。\n\nイメージとしては、もともと二つのもの (ポインタ変数とオブジェクト) をつないでいたロープが、片方 (オブジェクト) が外れてしまったために、もう一方\n(ポインタ変数) だけで、ぶらぶら、ぶら下がっている (= dangling) 状態です。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T20:26:34.340",
"id": "23517",
"last_activity_date": "2016-03-27T20:26:34.340",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3605",
"parent_id": "23503",
"post_type": "answer",
"score": 4
}
]
| 23503 | 23505 | 23505 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "`appinventor`というweb上で、好きなパーツをはめていくだけで \n手軽にAndroidアプリが作れるものがあります。\n\n<http://www.atmarkit.co.jp/ait/articles/1103/15/news087.html>\n\n手軽でびっくりしたのですが、 \nandroidアプリとして動く(apkファイルを作成する)までの流れが理解しきれず困っております。\n\n```\n\n GUIで操作及び、ブロックのロジックを設定する\n ↓\n ブラウザベースのサービスなので、\n そのロジックをもとに、javascriptでjavaのスクリプトに変換(翻訳?)する\n ↓\n GUIの部分はどういうプロセスを踏んでかは不明だが、xmlファイルに変換し、ボタンなどの位置を記憶する\n ↓\n apkファイル生成\n \n```\n\nといった漠然としたイメージは持っております。\n\n特にわからないのは、どうして、ブラウザ上で作成したロジックがandroidアプリで動くようになているのかという点です。\n\n前述のとおり、何かしらの方法で翻訳しているのだと思うのですが、 \nただ翻訳するだけでなく、javaのファイルとして生成しなければいけないと思います。\n\nその部分が私の今の理解度では追いついておらず、ブラックボックス化しております。\n\nソースコードを呼んだり、ググったりしていたのですが、よくわからず、質問させていただきました。 \n<https://github.com/mit-cml/appinventor-sources>\n\n興味本位の質問ではありますが、すごく面白いないようなので、車輪の開発にはなりますが、 \n自分でも同じようなことができるようになりたいと思っております。\n\nそのために何が必要なのかも差支えがなければ教えていただけると幸いです。\n\n拙い知識ではありますが\n\n * 構文解析器\n * コンパイル\n\nなどが肝になるのかなと思っております。\n\nまた、少し話がそれますが、 \n`rubymotion`という、rubyの文法で、iOS と Android のモバイルアプリが開発できる言語? \nがあります。\n\nこういうのも今回の質問内容に類似しており、気になるところではあります。\n\nrubyの文法で書いたロジックを何かしらの形で翻訳し、javaやobjective-\ncに変換するのだと思うのですが、ここでいうところのその変換方法が何なのかがわかりませんでした。\n\n不足事項などは都度追記させていただきます。 \n何卒よろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T13:30:33.293",
"favorite_count": 0,
"id": "23506",
"last_activity_date": "2016-03-28T16:07:22.470",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13175",
"post_type": "question",
"score": 3,
"tags": [
"android",
"java",
"ruby",
"objective-c",
"xcode"
],
"title": "GUIでの操作だけでアプリが開発できるサービスがあるのですが、その理由がわかりません。(構文解析などが関係しうるのかもしれませんが)",
"view_count": 407
} | [
{
"body": "RubyMotion の場合は、JavaやObjective Cへの変換は行わずに直接バイナリ (より正確に言えば、LLVMのバイトコード)\nを出力します。つまり、Rubyコンパイラとして動作します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T13:47:12.177",
"id": "23508",
"last_activity_date": "2016-03-27T13:47:12.177",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "76",
"parent_id": "23506",
"post_type": "answer",
"score": 1
},
{
"body": "まず、ブラウザ上のJavascriptではUIのレイアウトとブロックの配置を行うエディタ、そしてXMLや後述するYAIL言語への変換を行います。このスクリプトは単純なJavascriptの他に、Javaで書かれたプログラムを[GWT](https://ja.wikipedia.org/wiki/Google_Web_Toolkit)というツールで変換したものも含まれています。\n\nプロジェクトをエクスポートする際はXMLを固めたzipになっていますが、デバッグやビルドの際に使われるのはもうひとつの[YAIL](https://github.com/mit-\ncml/appinventor-\nsources/blob/master/appinventor/blocklyeditor/src/generators/yail.js)(Young\nAndroid Intermediate\nLanguage)という言語です。これはAppInventor独自の[Scheme](https://ja.wikipedia.org/wiki/Scheme)風のプログラミング言語で、UIもブロックもこの言語に変換され、Android端末で動かしたYAILインタプリタで動作します。このインタプリタは、Java上のScheme実装である[Kawa](https://ja.wikipedia.org/wiki/Kawa)で実装されています。\n\napkファイルをダウンロードする時には、YAILコードとリソースをビルドサーバーに送り、それらとYAILインタプリタを合体してapkにします。ビルド処理の実装は[このあたりに](https://github.com/mit-\ncml/appinventor-\nsources/blob/master/appinventor/buildserver/src/com/google/appinventor/buildserver/Compiler.java)。\n\nというわけで、Javaのソースコードやバイトコードを自ら生成しているわけではありません。\n\n一般にAndroid向けにコンパイルするというとJavaバイトコードを生成するわけですが、Java以外の言語でAndroidアプリを作る方法を考えると、\n\n * Javaでインタプリタを実装する\n * Javaのソースコードに変換する\n * Javaバイトコードへのコンパイラを実装する(Kawaとか)\n * Javaバイトコードへのコンパイルができる、別の言語を経由する(Kawaを経由するYAIL)\n * バイトコードではなく、ネイティブコードを生成する(Rubymotionなど) \nといってもLLVM使えば機械語を直接がりがり書く必要はないとかそういう\n\nと、結構色んなパターンがあります。できることやパフォーマンス、難易度に大きく差があります。\n\nちなみにこれはどう出力するかの話です。変換元となるプログラムを読み取る処理は別途考える必要がありますが、そこで出てくるのか構文解析などのプロセスです。\n\n参考\n\n * [App Inventor Developer Overview](https://docs.google.com/a/6lab.org/document/d/1hIvAtbNx-eiIJcTA2LLPQOawctiGIpnnt0AvfgnKBok/pub)\n * [what computer programming language is the app builder? - Google グループ](https://groups.google.com/forum/#!topic/mitappinventortest/cMkhyGqvFFA)",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T16:56:38.330",
"id": "23516",
"last_activity_date": "2016-03-27T16:56:38.330",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "23506",
"post_type": "answer",
"score": 4
}
]
| 23506 | null | 23516 |
{
"accepted_answer_id": "23527",
"answer_count": 1,
"body": "タイトルの通りでどちらが一般的でどういった使い分けを本当はするのかを教えてください。 \n下のfooとbarのイベントは自由で勝手なタイミングに起きるものとします。\n\n 1. fooイベントが発生すると処理Aを行う。このときCを作成する。\n 2. barイベントが発生すると処理Bを行う。このときCを使う。\n\nCが存在しないと処理BがおかしくなってしまうのでCの存在を保証したいです。そこで次の二つのどちらかを自分は今まで気まぐれで使っていました。\n\n * 処理AでCを作成するまで、barイベントに処理Bを登録せずにおく\n * 処理Bの最初でCがあるかどうかを確認し、なければ処理を行わない\n\n前者は無駄な確認処理がありません。後者は可読性が高いような気がします。 \nどちらを使うのが一般的なのでしょうか?それとも別の解決法があるのでしょうか?",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T13:38:37.473",
"favorite_count": 0,
"id": "23507",
"last_activity_date": "2016-03-28T15:30:48.543",
"last_edit_date": "2016-03-27T14:03:55.263",
"last_editor_user_id": "8000",
"owner_user_id": "14222",
"post_type": "question",
"score": 3,
"tags": [
"javascript",
"可読性",
"デザインパターン"
],
"title": "イベントリスナーの登録の入れ子か存在チェック",
"view_count": 301
} | [
{
"body": "一般的にどうなのかは分かりませんが・・・\n\n先に、もう一つの選択肢として、NullObjectパターンを提示しておきます。 \n例えばCが関数ならば、最初の時点では「何もしない関数」(=NullObject)をCに入れておいて、処理Aで正規の関数を入れ直す、という感じです。 \n『無駄な確認処理』が不要になるのが利点です。\n\n以降は、私ならどうするか、ですが:\n\n> 処理AでCを作成するまで、barイベントに処理Bを登録せずにおく\n\n処理Aにおける興味の中心が「処理Bのリスナ登録」であるなら、この方法を採ります。 \n逆に「Cの作成」であるなら、これは避けます。\n\n私が前者の典型だと考えているのは、ドラッグ処理のイベントハンドリングです。 \nmousedownのイベントリスナでmousemove/mouseupのイベントリスナを登録、mouseupのイベントリスナでmousemove/mouseupのイベントリスナを解除、というコードはよく書きます。 \nこの時、例えば「mousedownしたxy座標」のような、Cに相当するオブジェクトを作りますが、あくまで焦点はドラッグイベントの実現のためのイベント管理(登録/解除)であると考えます。\n\n後者は、Cが処理B以外からも使用される場合などが該当します。 \nこの場合は、\n\n> 処理Bの最初でCがあるかどうかを確認し、なければ処理を行わない\n\nつまりnullチェックか、もしくはNullObjectパターンのどちらかを選択します。 \nこの判断は微妙なのですが、プログラムの規模が大きいほど、NullObjectを使うことが多いです。 \nnullチェックをあちこちに書くと冗長ですし、チェックを忘れそうで怖いので。 \nすぐに全体を把握できるぐらい小さなプログラムで、チェックが一箇所しか無いなら、nullチェックで済ませると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T02:59:16.267",
"id": "23527",
"last_activity_date": "2016-03-28T02:59:16.267",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8078",
"parent_id": "23507",
"post_type": "answer",
"score": 2
}
]
| 23507 | 23527 | 23527 |
{
"accepted_answer_id": "40452",
"answer_count": 1,
"body": "TimelineMaxやTweenLiteは使えているのですが、同じようにしてもTweenMaxが使えません。\n\nwebpack.config.jsではresolveのaliasで以下のように設定しています。\n\n```\n\n alias: {\n TweenLite: 'gsap/src/uncompressed/TweenLite.js',\n TweenMax: 'gsap/src/uncompressed/TweenMax.js',\n TimelineLite: 'gsap/src/uncompressed/TimelineLite.js',\n TimelineMax: 'gsap/src/uncompressed/TimelineMax.js',\n EasePack: 'gsap/src/uncompressed/easing/EasePack.js',\n ScrollToPlugin: 'gsap/src/uncompressed/plugins/ScrollToPlugin.js'\n },\n \n```\n\ntsファイルでは以下のようにimportしています。\n\n```\n\n import TweenMax = require('TweenMax');\n \n```\n\nただ、`console.log(TweenMax)`としても空のobjectが返ってきており、 \n当然`TweenMax.to()`などはそんなfunctionは存在しないとerrorがでます。\n\n<https://github.com/greensock/GreenSock-JS/issues/91#issuecomment-148332900> \nこの人と同じように以下のようにしても空のobjectが返ってくることに変化なく。。\n\n```\n\n plugins: [ \n new webpack.ProvidePlugin({TweenMax: \"TweenMax\"})\n ]\n \n```\n\n読み込んでいるGSAPのnpm packageは 1.18.2です。 \nwebpackは1.12.14 \ntypescriptは1.8.7\n\nwebpackでのTweenMaxの使用方法ご教示いただければ幸いです。\n\nあわせて、 \nEasePackはTweenMaxがimportできれば使えると思っていますがまちがいないでしょうか? \nまた、ScrollToPluginも使用したいのですが、これはどのようにimportすればいいでしょうか。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T14:05:40.167",
"favorite_count": 0,
"id": "23510",
"last_activity_date": "2017-12-21T13:52:29.947",
"last_edit_date": "2016-03-27T15:27:33.273",
"last_editor_user_id": "3131",
"owner_user_id": "3131",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"typescript",
"webpack"
],
"title": "webpackでのTweenMax、EasePackの使い方(typescriptを使用)",
"view_count": 1417
} | [
{
"body": "自己解決した内容ですが、gsapがwebpackに対応したためです \nこちらを参照してください。 \n[Best way to use GSAP with\nWebpack](https://greensock.com/forums/topic/16676-best-way-to-use-gsap-with-\nwebpack/?tab=comments#comment-73795)\n\n私の方法が悪いのかもしれませんがScrollToPluginのみimportができないのでこのコメントのようにaliasを設定しています。 \n[GSAP & NPM/Webpack `import` for ScrollToPlugin \n](https://greensock.com/forums/topic/14873-gsap-npmwebpack-import-for-\nscrolltoplugin/?tab=comments#comment-63993)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-21T13:52:29.947",
"id": "40452",
"last_activity_date": "2017-12-21T13:52:29.947",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3131",
"parent_id": "23510",
"post_type": "answer",
"score": 1
}
]
| 23510 | 40452 | 40452 |
{
"accepted_answer_id": "23515",
"answer_count": 1,
"body": "メールを立ち上げることはできたのですが、閉じることができません。 \nswitch result.value のところにエラーメッセージが出ています。 \n調べてみても分からなかったので質問させていただきました。\n\nよろしくお願いします。\n\nfunc mailComposeController(controller: MFMailComposeViewController,\ndidFinishWithResult result: MFMailComposeResult, error: NSError?) {\n\n```\n\n switch result.value {\n case MFMailComposeResultCancelled.value:\n break\n case MFMailComposeResultSaved.value:\n break\n case MFMailComposeResultSent.value:\n break\n case MFMailComposeResultFailed.value:\n break\n default:\n break\n }\n \n self.dismissViewControllerAnimated(true, completion: nil)\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T14:42:04.457",
"favorite_count": 0,
"id": "23513",
"last_activity_date": "2016-03-27T16:42:44.510",
"last_edit_date": "2016-03-27T16:42:44.510",
"last_editor_user_id": "11019",
"owner_user_id": "11019",
"post_type": "question",
"score": 0,
"tags": [
"ios",
"swift",
"iphone",
"swift2"
],
"title": "swift メール画面を閉じたい。",
"view_count": 524
} | [
{
"body": "どこで見つけられたコードか知りませんが、ずいぶん古い書き方をしていますね。Swift1.xのかなり初期の書き方になっています。\n\n現在の`MFMailComposeResult`型はSwiftに以下のようにimportされています。\n\n```\n\n public struct MFMailComposeResult : RawRepresentable, Equatable {\n public init(_ rawValue: UInt32)\n public init(rawValue: UInt32)\n public var rawValue: UInt32\n }\n public var MFMailComposeResultCancelled: MFMailComposeResult { get }\n public var MFMailComposeResultSaved: MFMailComposeResult { get }\n public var MFMailComposeResultSent: MFMailComposeResult { get }\n public var MFMailComposeResultFailed: MFMailComposeResult { get }\n \n```\n\nご覧になればわかると思いますが`MFMailComposeResult`には、`value`という名前のプロパティはありませんから、そのせいでエラーになっています。\n**あなたのコードから全ての`.value`を削除してしまってください。**\n\n```\n\n func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {\n \n switch result {\n case MFMailComposeResultCancelled:\n break\n case MFMailComposeResultSaved:\n break\n case MFMailComposeResultSent:\n break\n case MFMailComposeResultFailed:\n break\n default:\n break\n }\n \n self.dismissViewControllerAnimated(true, completion: nil)\n }\n \n```\n\n初期のSwiftでは、Objective-Cからimportしたenum型の定数では`==`による比較もできなければswitch-\ncaseにも使えないという、今から考えるとかなりひどい制約があったので`enum`内部の整数値(これも`value`から現在では`rawValue`に変更されています)を取り出して比較する必要があったのですが、現在のSwiftにはそのような制約はありませんので値(`result`)も比較する定数値(`MFMailComposeResultCancelled`等)も共に同じ型(今回は`MFMailComposeResult`)であれば、全てに`.value`をつけるような面倒はしなくても良くなっています。\n\nXcodeのエディター上で`MFMailComposeResult`をCommand-\nclickすれば上記の型定義のヘッダーは見ることができます。何もかも全て読み取れる必要はありませんが、「`MFMailComposeResult`型には`value`なんてプロパティがない」ことくらいは(そのような意味のエラーメッセージも出ていたはずです)理解できるようにしてください。\n\nなお表題の「Swiftのメーラー」ですが、通常「メーラー」と言うと「メールの送受信機能を持った独立したアプリ」のことを言いますから、大変誤解を招きやすいタイトルになっています。正確な技術用語はわからなくても、`MFMailComposeViewController`を表示させているというのはコードを書かれたのだから分かっているはずです。タイトルにもそのクラス名を含めたほうが良いでしょう。(私は最初「メーラーのことなんて知らねぇよ」と思ってスルーしていました。)\n\nまた今回は自明な誤りがあったので回答が書けましたが、「エラーが出ています」と言う場合には必ず「ビルド時のエラーなのか実行時のエラーなのか」と「エラーメッセージの内容」をエラーが出た場所に加えて質問中に記載するようにしてください。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T16:24:35.220",
"id": "23515",
"last_activity_date": "2016-03-27T16:24:35.220",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "23513",
"post_type": "answer",
"score": 1
}
]
| 23513 | 23515 | 23515 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "`OLYCameraLiveViewListener`\nの以下のメソッドでライブビュー画像を処理する際に、同時に取得できるmetadataに格納されている情報について記載されているドキュメントはありませんでしょうか? \n常にOrientation情報しか入っていないようなのですが、これで正常なのでしょうか?\n\n```\n\n void onUpdateLiveView (OLYCamera camera, byte[] data, Map< String, Object > metadata)\n \n```\n\nOlympus Camera Kit ver 1.1.1\n\n宜しくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-27T14:50:46.227",
"favorite_count": 0,
"id": "23514",
"last_activity_date": "2016-04-01T05:51:02.290",
"last_edit_date": "2016-03-28T17:20:28.560",
"last_editor_user_id": "8000",
"owner_user_id": "14960",
"post_type": "question",
"score": 1,
"tags": [
"olympus-camerakit"
],
"title": "ライブビュー受信時のmetadataの内容について",
"view_count": 89
} | [
{
"body": "OPCサポートです。\n\nご質問ありがとうございます。 \n現在のところ`metadata`に格納されている情報は回転情報のみです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-04-01T05:51:02.290",
"id": "23661",
"last_activity_date": "2016-04-01T05:51:02.290",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8370",
"parent_id": "23514",
"post_type": "answer",
"score": 1
}
]
| 23514 | null | 23661 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "AWSののdynamoDBを用いて、`loadUser()`データベースに上がってある画像のURLを持ってきて、`downloadImage()`で画像をダウンロードして、`addImage()`で`scrollView`に追加するようなことをしています。 \nしかし、`downloadImage()`内でダウンロードされた順番(loadCounter)を出力してみると \n0 \n2 \n1 \nなどのように出力されて、順番通りに出力されませんでした。 \n非同期処理で順番通りにダウンロードするにはどこを変更したらいいでしょうか。お願いします。\n\n```\n\n import UIKit\n import AWSCore\n import AWSS3\n import AWSDynamoDB\n \n class LoadViewController: UIViewController, UINavigationControllerDelegate,UIScrollViewDelegate {\n \n \n var loadImages:[UIImage] = []\n var loadItems:[DDBTableRow] = []\n \n var userId:String?\n var userName:String?\n var pagniatedOutput: AWSDynamoDBPaginatedOutput?\n \n @IBOutlet weak var scrollView: UIScrollView!\n \n let defaults = NSUserDefaults.standardUserDefaults()\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n self.scrollView.delegate = self\n \n self.userName = defaults.stringForKey(\"userName\")\n self.userId = defaults.stringForKey(\"userId\")\n \n \n loadUser()\n \n }\n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n // Dispose of any resources that can be recreated.\n }\n \n \n func addImage(image:UIImage)\n {\n let sheight = self.scrollView.frame.height\n let swidth = self.scrollView.frame.width\n \n loadImages.append(image)\n let myImageView = UIImageView()\n myImageView.frame = CGRectMake(swidth * CGFloat(loadImages.count-1), 0, swidth, sheight)\n myImageView.image = image\n myImageView.contentMode = .ScaleAspectFit\n scrollView.addSubview(myImageView)\n scrollView.contentSize = CGSizeMake(swidth * CGFloat(loadImages.count), sheight)\n \n }\n \n \n \n func loadUser()\n {\n let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()\n \n let queryExpression = AWSDynamoDBQueryExpression()\n queryExpression.hashKeyValues = userId\n queryExpression.scanIndexForward = false\n var loadCounter:Int = 0\n dynamoDBObjectMapper .query(DDBTableRow.self, expression: queryExpression) .continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task:AWSTask!) -> AnyObject! in\n if (task.error != nil) {\n print(\"Error: \\(task.error)\")\n \n } else {\n if (task.result != nil) {\n self.pagniatedOutput = task.result as? AWSDynamoDBPaginatedOutput\n \n for item in (self.pagniatedOutput?.items)!\n {\n let tableRow = item as! DDBTableRow\n \n print(tableRow.Date)\n self.downloadImage(tableRow.ImageURL!,loadCounter: loadCounter)\n self.loadItems.append(tableRow)\n loadCounter += 1\n \n }\n }\n self.performSegueWithIdentifier(\"unwindToMainSegue\", sender: self)\n }\n return nil\n })\n }\n \n func downloadImage(S3DownloadKeyName: String,loadCounter:Int){\n \n var completionHandler: AWSS3TransferUtilityDownloadCompletionHandlerBlock?\n \n let queue:dispatch_queue_t = dispatch_queue_create(\"com.gologo13.gcd\", DISPATCH_QUEUE_SERIAL)\n \n let expression = AWSS3TransferUtilityDownloadExpression()\n expression.downloadProgress = {(task: AWSS3TransferUtilityTask, bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) in\n dispatch_async(dispatch_get_main_queue(), {\n let progress = Float(totalBytesSent) / Float(totalBytesExpectedToSend)\n NSLog(\"Progress is: %f\",progress)\n })\n }\n \n \n completionHandler = { (task, location, data, error) -> Void in\n dispatch_async(dispatch_get_main_queue(), {\n if ((error) != nil){\n NSLog(\"Failed with error\")\n NSLog(\"Error: %@\",error!)\n }\n else{\n print(Success)\n self.addImage(UIImage(data: data!)!)\n //loadCounterのデバック\n print(loadCounter)\n //loadCounterの出力される値が順番通りにならない\n }\n })\n }\n \n let transferUtility = AWSS3TransferUtility.defaultS3TransferUtility()\n \n transferUtility.downloadToURL(nil, bucket: S3BucketName, key: S3DownloadKeyName, expression: expression, completionHander: completionHandler).continueWithBlock { (task) -> AnyObject! in\n if let error = task.error {\n NSLog(\"Error: %@\",error.localizedDescription);\n // self.statusLabel.text = \"Failed\"\n }\n if let exception = task.exception {\n NSLog(\"Exception: %@\",exception.description);\n // self.statusLabel.text = \"Failed\"\n }\n if let _ = task.result {\n // self.statusLabel.text = \"Starting Download\"\n NSLog(\"Download Starting!\")\n // Do something with uploadTask.\n }\n return nil;\n }\n }\n \n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T00:49:20.107",
"favorite_count": 0,
"id": "23519",
"last_activity_date": "2016-09-01T09:15:27.483",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"post_type": "question",
"score": 1,
"tags": [
"ios",
"swift",
"objective-c",
"xcode",
"swift2"
],
"title": "非同期処理での実行される順番について",
"view_count": 1003
} | [
{
"body": "取得したデータの\n\n> for(var i=0; i < image_list.length; i++){ \n> image.src=url[i]; \n> } \n> のiを \n> sortしてみてはどうですか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T15:41:26.923",
"id": "23563",
"last_activity_date": "2016-03-28T15:46:48.970",
"last_edit_date": "2016-03-28T15:46:48.970",
"last_editor_user_id": "14967",
"owner_user_id": "14967",
"parent_id": "23519",
"post_type": "answer",
"score": 1
},
{
"body": "`.addImage`の中で配列の最後にイメージを追加していくのではなく、配列に`insert:image,\natIndex:loadCounter`にして再描画する仕組みにしてみてはいかがでしょうか",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-04-04T13:54:17.570",
"id": "23742",
"last_activity_date": "2016-04-04T13:54:17.570",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14745",
"parent_id": "23519",
"post_type": "answer",
"score": 0
}
]
| 23519 | null | 23563 |
{
"accepted_answer_id": "23526",
"answer_count": 1,
"body": "```\n\n where(\"id not in (?) AND id != ?\", current_user.friend_ids, current_user)\n \n```\n\nと書かれたコードがありまして、コードの記述の意味がわかりません。 \nこのコードはツイッターのようなサイトの”友達を探す”ページのコントローラーの一部です。 \nまず、`\"id not in (?) AND id != ?\"`の部分の意味がわかりません。なぜANDを使っているのか 、(?) はどのような意味なのかid\n!= ?がどんなことを意味しているのかさっぱりわかりません。どなたかこのコードの記述の仕方とその意味を教えてください。\n\nちなみにコントローラーのコードの全体は \nfind_friends_controller.rb\n\n```\n\n class FindFriendsController < ApplicationController\n \n before_action :authenticate_user!\n \n def index\n @users = User.where(\"id not in (?) AND id != ?\", current_user.friend_ids, current_user).paginate(page: params[:page])\n respond_to do |format|\n format.js\n format.html\n end\n end\n end\n \n```\n\nのようになっています。\n\nどうしてあんな複雑で難解なコードで友達が探せるのか疑問です。。。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T02:04:09.857",
"favorite_count": 0,
"id": "23523",
"last_activity_date": "2016-03-28T02:30:51.037",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "14754",
"post_type": "question",
"score": -1,
"tags": [
"ruby-on-rails"
],
"title": "where(\"id not in (?) AND id != ?\", current_user.friend_ids, current_user)のコードの意味",
"view_count": 635
} | [
{
"body": "```\n\n where(\"id not in (?) AND id != ?\", current_user.friend_ids, current_user)\n \n```\n\nこの `?` の部分には、後続のパラメータが順番に埋め込まれます。コメントとして埋め込んでみると、\n\n```\n\n id not in (/*friend_ids*/) AND id != /*current_user*/\n \n```\n\nといった形になります。このクエリはUserモデルに対して投げていますから、\n\n * `id not in (/*friend_ids*/)` 現在の友達のIDリストに含まれない=まだ友達でない\n * `AND` かつ\n * `id != /*current_user*/` 自分自身でもない\n\nという条件を満たすユーザーを列挙していることになります。\n\n実際にはこの `where()` 呼び出しは `WHERE id not in (1,2,3,...) AND id != 8`\nといった形に変換され、SQLに埋め込まれることになります。ですから `where()`\nで使う式がどのような構造になっていて、何が書けるのかは、SQLのWHERE句について調べるとよいでしょう。\n\n例えば: [SELECT構文:WHEREで検索条件を設定する | Smart](http://rfs.jp/sb/sql/s03/03_2-2.html)",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T02:30:51.037",
"id": "23526",
"last_activity_date": "2016-03-28T02:30:51.037",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8000",
"parent_id": "23523",
"post_type": "answer",
"score": 1
}
]
| 23523 | 23526 | 23526 |
{
"accepted_answer_id": "23542",
"answer_count": 2,
"body": "phpでmysqlデータベースに \ntest_id, test_title, test_contents,\ntest_date.test_imageのデータを保存しています。このデータのid毎に静的htmlに生成して書き出したいです。WordPressやMovable\nTypeの静的ファイルの書き出すとかに似ているイメージです。\n\n[](https://i.stack.imgur.com/ejhzH.png)\n\n[](https://i.stack.imgur.com/cy1lb.png)\n\n例えば:上記添付した画像(CMS.png)の書き出すボタンを押すと添付した画像(database.png)から、/Applications/MAMP/htdocs/test/のディレクトリーの下に静的htmlファイにて生成して書き出したいです \n/Applications/MAMP/htdocs/test/1.html \n/Applications/MAMP/htdocs/test/2.html\n\n1.htmlと2.htmlにはデータベースに保存されているtest_id, test_title, test_contents,\ntest_date.test_imageのデータ内容がそれぞれのhtmlに全部表示されるようにしたいです\n\nこれはphpや何かをして書き出すことは可能でしょうか? ご教授お願い致します。\n\n* * *\n\[email protected] さん \nsync.phpファイルは下記です。\n\n```\n\n <?php\n //require_once(\"db.php\");\n // 取得するIDをURLパラメータから取得\n if (!isset($_GET['test_id'])) {\n echo '{$test_id} param not found. please set param [id] to url params.';\n return;\n }\n $test_id = $_GET['test_id'];\n \n // データベースに接続\n //$db = new mysqli(\"localhost\", \"root\", \"root\", \"product\");\n $db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);\n if ($db->connect_error) {\n echo 'database connect failed.';\n return;\n }\n if ($db->set_charset('utf8') === false) {\n echo 'database connect failed. can not using utf-8.';\n return;\n }\n \n // データ取得とhtmlに変換\n $html = \"<!DOCTYPE html><html><head><meta charset=\\\"UTF-8\\\"><title>{$id} </title></head><body>\";\n //データベース名前はproductです, 今回の想定はいくつからのテーブルあって、その中のtestテーブルです\n $result = $db->query(\"select * from test where test_id = {$test_id};\"); // 本当はidのエスケープを考慮しないといけない でもselectなのでべつにこのままでも危険な事にはならない。\n $rows = array();\n for ($i=0; ($row=$result->fetch_assoc()) != null; $i++) { // 一応一致した全行出力する\n if ($i > 0) {\n $html .= '<br />';\n }\n $html .= 'test_id = ' . $row['test_id'] . ', ';\n $html .= 'test_title = ' . $row['test_title'] . ', ';\n $html .= 'test_contents = ' . $row['test_contents'] . ', ';\n $html .= 'test_date = ' . $row['test_date'] . ', ';\n $html .= 'test_image = ' . $row['test_image'];\n }\n $html .= \"</body></html>\";\n \n // ファイルに書き出し\n if (file_put_contents(\"/Applications/MAMP/htdocs/test/{$test_id}.html\", $html) === false) {\n echo 'write to file failed.';\n } else {\n echo 'write to file succeed.';\n }\n \n```\n\n* * *\n\[email protected]さんこちらが全ファイルです。 \nsync.phpとadmin.phpとdb.phpは同じディレクトリ下にあります。\n\nsync.phpこちらは@D.Tさんのファイル \n\n```\n\n // 取得するIDを取得\n if (!isset($_GET['test_id']) && !isset($_POST['test_id'])) {\n print '[test_id] param not found. please set param [test_id] to url params or post values.';\n return;\n }\n $id = isset($_GET['test_id'])? $_GET['test_id']:$_POST['test_id'];\n \n // データベースに接続\n $db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);\n //$db = new mysqli(\"localhost\", \"root\", \"root\", \"product\");//ここだけを自分の環境に合わせてみました。\n if ($db->connect_error) {\n print 'database connect failed.';\n return;\n }\n if ($db->set_charset('utf8') === false) {\n print 'database connect failed. can not using utf-8.';\n return;\n }\n \n // データ取得とhtmlに変換\n $html = \"<!DOCTYPE html><html><head><meta charset=\\\"UTF-8\\\" /><title>{$id} </title></head><body>\";\n $result = $db->query(\"select * from test where test_id = {$id};\"); // 本当 はidのエスケープを考慮しないといけない でもselectなのでべつにこのままでも危険な事にはならない。\n for ($i=0; ($row=$result->fetch_assoc()) != null; $i++) { // 一応一致した全行出力する\n if ($i > 0) {\n $html .= '<br />';\n }\n $html .= 'test_id = ' . $row['test_id'] . ', ';\n $html .= 'test_title = ' . $row['test_title'] . ', ';\n $html .= 'test_contents = ' . $row['test_contents'] . ', ';\n $html .= 'test_date = ' . $row['test_date'] . ', ';\n $html .= 'test_image = ' . $row['test_image'];\n }\n $html .= \"</body></html>\";\n \n // ファイルに書き出し\n if (file_put_contents(\"/Applications/MAMP/htdocs/test/{$id}.html\", $html) === false) {\n print 'write to file failed.';\n } else {\n print 'write to file succeed.';\n ?>\n \n```\n\nadmin.php \n\n```\n\n $query = \"SELECT * FROM test ORDER BY test_id DESC\";\n $select = mysqli_query($db, $query);\n while($row = mysqli_fetch_assoc($select)){\n $test_id =$row['test_id'];\n $test_title = $row['test_title'];\n $test_contents =$row['test_contents'];\n $test_date =$row['test_date'];\n $test_image =$row['test_image'];\n echo \"<tr>\";\n ?>\n <?php \n echo \"<td>$test_id</td>\";\n echo \"<td>$test_title</td>\";\n echo \"<td>$test_contents</td>\";\n echo \"<td>$test_date</td>\";\n echo \"<td>$test_image</td>\";\n echo \"<td><a href=''>編集</td>\";\n echo \"<td><a rel=''>削除</td>\";\n echo \"<td><form action='sync.php' method='post'><div class='form-group'>\n <input type='hidden' name='test_id' value='\".$test_id.\"'>\n <input type='submit' class='btn' name='submit' value='書き出す'>\n </div></form></td>\";\n echo \"</tr>\";\n \n```\n\n}\n\ndb.php\n\n```\n\n <?php\n $db['db_host'] = \"localhost\";\n $db['db_user'] = \"root\";\n $db['db_pass'] = \"root\";\n $db['db_name'] = \"product\";\n \n foreach($db as $key => $value){\n define(strtoupper($key), $value);\n \n }\n $db = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);\n mysqli_set_charset($db,\"utf8\");\n ?>\n \n```",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T02:29:00.323",
"favorite_count": 0,
"id": "23525",
"last_activity_date": "2016-04-01T02:52:27.217",
"last_edit_date": "2016-04-01T02:52:27.217",
"last_editor_user_id": "30",
"owner_user_id": "9013",
"post_type": "question",
"score": -2,
"tags": [
"php",
"mysql"
],
"title": "phpでmysqlにデータを保存しているデータをid毎に静的フアィルhtmlに生成して書き出したいです",
"view_count": 1093
} | [
{
"body": "お待たせしました \nsync.phpの中身を下にまるまる書き換えて下さい。 \nまた、今回はエスケープを行うなどしてそのまま実用できるようにしました。\n\n```\n\n <?php\n // 取得するIDを取得(GET or POST name is test_id type:number)\n if (!isset($_GET['test_id']) && !isset($_POST['test_id'])) {\n print '[test_id] param not found. please set [test_id] param to url params or post values.';\n return;\n }\n $id = isset($_GET['test_id'])? $_GET['test_id']:$_POST['test_id'];\n \n // パラメータが10進数の数値かチェック\n if (!ctype_digit($id) || strlen($id)==0) {\n print '[test_id] is invalid param type. need number.';\n return;\n }\n \n // データベースに接続(現存のコードを利用)\n require_once('db.php');\n \n // データベースからデータ取得\n $result = mysqli_query($db, \"select * from test where test_id={$id} order by test_id desc;\");\n \n // データ取得と同時にhtmlに変換\n $html = \"<!DOCTYPE html><html><head><meta charset=\\\"UTF-8\\\" /><title>{$id}</title></head><body><table><tbody>\";\n $found = false;\n for ($i=0; ($row=mysqli_fetch_assoc($result)) != null; $i++) { // 一致したレコード分だけ繰り返す\n $found = true;\n \n // ヘッダの出力\n if ($i == 0) {\n $html .= '<tr>';\n foreach ($row as $name => $value) {\n $html .= '<th>' . htmlspecialchars($name) . '</th>';\n }\n $html .= '</tr>';\n }\n \n // 値の出力\n $html .= '<tr>';\n foreach ($row as $name => $value) {\n $html .= '<td>' . htmlspecialchars(str_replace(\"\\n\", \"<br />\", $value)) . '</td>';\n }\n $html .= '</tr>';\n }\n if (!$found) {\n $html .= '<tr><td>1つも一致するデータはありません。</td></tr>';\n }\n $html .= \"</tbody></table></body></html>\";\n \n // ファイルに書き出し\n if (file_put_contents(\"/Applications/MAMP/htdocs/test/{$id}.html\", $html) === false) {\n print 'write to file failed.';\n } else {\n print $html;\n }\n \n```\n\n?>",
"comment_count": 9,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T09:22:27.290",
"id": "23542",
"last_activity_date": "2016-03-28T09:29:06.753",
"last_edit_date": "2016-03-28T09:29:06.753",
"last_editor_user_id": "10346",
"owner_user_id": "10346",
"parent_id": "23525",
"post_type": "answer",
"score": 0
},
{
"body": "ごちゃごちゃなりましたが、これは \nhtmlの書き出しはできたけど、他のIDだとできないものがあるにたいしての回答です。\n\n```\n\n echo \"<td><form action='sync.php' method='post'><div class='form-group'>\n <input type='hidden' name='test_id' value='\".$test_id.\"'>\n <input type='submit' class='btn' name='submit' value='書き出す'>\n </div></form></td>\";\n \n```\n\n試しに↓に書き換えてください。\n\n```\n\n echo \"<td><form action='sync.php' method='post'>\n <input type='hidden' name='test_id' value='{$test_id}'>\n <input type='submit' class='btn' name='submit' value='書き出す'>\n </form></td>\";\n \n```\n\nやっぱりこっちに書き換えて下さい \ninputを閉じていないのが原因…!???\n\n```\n\n echo \"<td><form action='sync.php' method='post'><div class='form-group'>\n <input type='hidden' name='test_id' value='{$test_id}' />\n <input type='submit' class='btn' name='submit' value='書き出す' />\n </div></form></td>\";\n \n```",
"comment_count": 14,
"content_license": "CC BY-SA 3.0",
"creation_date": "2016-03-28T11:15:13.583",
"id": "23548",
"last_activity_date": "2016-03-28T11:15:13.583",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "10346",
"parent_id": "23525",
"post_type": "answer",
"score": -2
}
]
| 23525 | 23542 | 23542 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.