question
dict
answers
list
id
stringlengths
2
5
accepted_answer_id
stringlengths
2
5
popular_answer_id
stringlengths
2
5
{ "accepted_answer_id": "70", "answer_count": 3, "body": "要素として文字列と数字が混在している配列があります。 これをすべて数字順に並べ替えたいのですが、どうしたらよいでしょうか?\n\nたとえば、以下のような配列があったとします。\n\n```\n\n [\"123\", 200, \"12\", 85]\n \n```\n\nこれを次のように並び替えたいです。\n\n```\n\n [\"12\", 85, \"123\", 200]\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-09-29T20:06:18.613", "favorite_count": 0, "id": "69", "last_activity_date": "2015-01-25T20:33:15.580", "last_edit_date": "2014-10-02T01:17:50.717", "last_editor_user_id": "30", "owner_user_id": "85", "post_type": "question", "score": 9, "tags": [ "ruby" ], "title": "Rubyで文字列と数字が混在している配列をソートする方法を教えてください", "view_count": 5960 }
[ { "body": "`sort_by`メソッドを使えばソートできますよ。\n\n```\n\n [\"123\", 200, \"12\", 85].sort_by{|item| item.to_i} #=> [\"12\", 85, \"123\", 200]\n \n```\n\n次のように書いても同じです。\n\n```\n\n [\"123\", 200, \"12\", 85].sort_by(&:to_i) #=> [\"12\", 85, \"123\", 200]\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-09-29T20:10:36.950", "id": "70", "last_activity_date": "2014-09-29T20:10:36.950", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "parent_id": "69", "post_type": "answer", "score": 13 }, { "body": "私は[Kernel#Integer](http://docs.ruby-lang.org/ja/2.1.0/class/Kernel.html#M_-\nINTEGER)を使うのが好きです。\n\n```\n\n [\"123\", 200, \"12\", 85, \"dog\", -5].sort_by{|item| item.to_i}\n #=> [-5, \"dog\", \"12\", 85, \"123\", 200] >_<\n \n [\"123\", 200, \"12\", 85, \"dog\", -5].sort_by{|item| Integer(item)}\n # ArgumentError: invalid value for Integer(): \"dog\"\n \n [\"123\", 200, \"12\", 85, -5].sort_by{|item| Integer(item)}\n #=> [-5, \"12\", 85, \"123\", 200]\n \n```\n\n次のように書いても同じです。\n\n```\n\n [\"123\", 200, \"12\", 85, -5].sort_by(&method(:Integer)) #=> [-5, \"12\", 85, \"123\", 200]\n \n```\n\n([Object#methodのドキュメント](http://docs.ruby-\nlang.org/ja/2.1.0/class/Object.html#I_METHOD))", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T12:40:43.050", "id": "1759", "last_activity_date": "2014-12-16T13:34:19.657", "last_edit_date": "2014-12-16T13:34:19.657", "last_editor_user_id": "30", "owner_user_id": "3873", "parent_id": "69", "post_type": "answer", "score": 6 }, { "body": "数値にマップして比較するのではなく、文字列にマップして比較する方法も考えられます。\n\n```\n\n ary = [\"123\", 'cat', 200, \"12\", 85, nil, 'dog']\n \n p ary.sort {|a, b| format('%10s', \"#{a}\") <=> format('%10s', \"#{b}\")}\n p ary.sort_by {|x| format('%10s', \"#{x}\")}\n \n p ary.sort_by {|x| x.to_i} # 数値にマップ \n \n```\n\n実行結果は次のようになります。\n\n```\n\n [nil, \"12\", 85, \"123\", 200, \"cat\", \"dog\"]\n [nil, \"12\", 85, \"123\", 200, \"cat\", \"dog\"]\n [\"dog\", \"cat\", nil, \"12\", 85, \"123\", 200]\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T14:27:47.313", "id": "1786", "last_activity_date": "2015-01-25T20:33:15.580", "last_edit_date": "2015-01-25T20:33:15.580", "last_editor_user_id": "2987", "owner_user_id": "2987", "parent_id": "69", "post_type": "answer", "score": 4 } ]
69
70
70
{ "accepted_answer_id": "164", "answer_count": 5, "body": "ここ数ヶ月Android Studioのお世話になっており、よくできているなと感心しています。これまでEmacsが長かったのですが、Android\nStudio/IntelliJと同等のことができるほどには使い込んでいません。\n\nAndroid Studioでは以下の操作をよくしています。これをEmacsで実現できるようなIDEパッケージはありますか?\nひとまずJavaが対象ですが、多言語対応でも可です。\n\n 1. 検索: ソースツリー内のファイルをファイル名から検索して開く\n 2. 検索: ソースツリー内のファイルをファイルの内容から検索して開く\n 3. 検索: メソッドや変数の定義に飛ぶ\n 4. 検索: メソッドや変数、クラスを使っている行をソースツリー内から検索する\n 5. リファクタリング: メソッドや変数、クラス名を任意のスコープ内で (メソッド内のみ、クラス内のみなど) 一気に変更する\n 6. リファクタリング: その他リファクタリング全般 (メソッド切り出しなど)\n 7. コード編集支援: クラス名やスコープ内の変数などから変数名を自動補完する\n 8. コード編集支援: カーソルがある行をif文やtry/catch文などで囲う\n 9. コード編集支援: カーソルがあるメソッドの引数名や型、返り値を表示する\n 10. コード編集支援: 静的コード解析で見つかった問題を修正する (インポート文を自動挿入するなど)\n\n更新: 範囲が広すぎたため、質問の方向をピボットして、全部を実現できるようなソリューションがないかを問う質問にしました。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-01T16:30:57.317", "favorite_count": 0, "id": "73", "last_activity_date": "2014-12-29T03:13:02.883", "last_edit_date": "2014-12-29T03:13:02.883", "last_editor_user_id": "30", "owner_user_id": "30", "post_type": "question", "score": 7, "tags": [ "emacs" ], "title": "EmacsをJava用IDEとして使い倒せるパッケージはありますか?", "view_count": 1103 }
[ { "body": "> 1. 検索: ソースツリー内のファイルをファイル名から検索して開く\n> 2. 検索: ソースツリー内のファイルをファイルの内容から検索して開く\n> 3. 検索: メソッドや変数の定義に飛ぶ\n> 4. 検索: メソッドや変数、クラスを使っている行をソースツリー内から検索する\n>\n\nhelm <https://github.com/emacs-helm/helm>\nというパッケージが検索というか絞り込みの操作全般をまかなう定番です。ソースツリー内のファイル検索はさまざまなやり方があると思いますが helm\nと組み合わせるなら helm-ag <https://github.com/syohex/emacs-helm-ag> がいいと思います。\n\nキー操作については、 helm\nのインストール作業の一環として自分で好みのキーバインドを定義することになりますので、短くて打ちやすい(覚えやすい)キーバインドを使えます。\n\n> 5. リファクタリング: メソッドや変数、クラス名を適切なスコープ内で一気に変更する\n>\n\n「適切なスコープ」がよくわかりませんが、リージョンを選択して M-x query-replace でも(原始的ですが)一括置換は可能です。が、\n\n> 6. リファクタリング: その他リファクタリング全般 (メソッド切り出しなど)\n>\n\nこういうのは Emacs Lisp パッケージで実現するのは難しいのではないかと思います(探せばあるのかもしれませんが...)\n\n> 7. コード編集支援: クラス名やスコープ内の変数などから変数名を自動補完する\n>\n\nこれは限定的ではありますが標準機能の動的略語展開 (dabbrev-expand) で補完できます。変数名を途中まで打って M-/ を押してみてください。\n\n> 8. コード編集支援: カーソルがある行をif文やtry/catch文などで囲う\n>\n\n私は使ったことがないのですが yasnippet <https://github.com/capitaomorte/yasnippet>\nなどを駆使すれば似たようなことが実現できるかもしれません。\n\n> 9. コード編集支援: カーソルがあるメソッドの引数名や型、返り値を表示する\n> 10. コード編集支援: 静的コード解析で見つかった問題を修正する (インポート文を自動挿入するなど)\n>\n\n5, 6 のリファクタリングと同様、静的なコード解析まで行う高機能な Emacs Lisp\nは(探せばあるのかもしれませんが)思い当たるものがありません。過去に Ruby のコード解析を行う RSense\n<http://cx4a.org/software/rsense/index.ja.html> というツールを使ったことがありますが、 RSense 自体は\nJava で書かれていました(付属の Emacs Lisp パッケージのインタフェースを通じて Emacs から利用する)\n\n私は Eclipse や Android Studio/IntelliJ などの IDE\nに習熟していないので比較したわけではないですが、静的コード解析や自動リファクタリングのような機能は Emacs のカスタマイズをするよりも素直に IDE\nの機能を利用したほうが良いと思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-12T18:29:59.293", "id": "164", "last_activity_date": "2014-11-12T18:29:59.293", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "82", "parent_id": "73", "post_type": "answer", "score": 9 }, { "body": "CEDET <http://cedet.sourceforge.net/> はどうでしょうか。 1.~4.は実現できると思います。\n(残りもいくつかは実現できると思います)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T07:36:53.147", "id": "1704", "last_activity_date": "2014-12-16T07:36:53.147", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3552", "parent_id": "73", "post_type": "answer", "score": 3 }, { "body": "Android Studio/IntelliJとあるので、Javaを前提としますが、一番メジャーなのはmalabar-modeでしょうか。\n導入はかなり面倒です。\n\nCEDETの拡張でJDEEというのがありますが、開発停止しており・・・と思ってましたが再開されたようです。 こちらを試してみてもいいかもしれません。\n\n<http://mikio.github.io/article/2012/12/23_emacsjdeejava.html>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T08:03:55.730", "id": "1708", "last_activity_date": "2014-12-16T08:03:55.730", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2542", "parent_id": "73", "post_type": "answer", "score": 4 }, { "body": "# 適切なスコープだけ編集\n\n適切なスコープだけ編集したいのであれば、narrowing系コマンドを駆使すればいいと思います。\n\nまず最初にnarrowing系コマンドでパニックにならないように、解除方法である `C-x n w` (`M-x\nwiden`)を覚えてください。このコマンドが最重要です。\n\nnarrowingとはバッファの特定領域だけを編集範囲にするものです。表示もその特定範囲だけになります。基本はリージョンを選択して`C-x n n`\n(`M-x narrow-to-\nregion`)です。そうすると選択範囲以外は消えてしまいます。表示上消えただけです。narrowingを解除すると現れるので大丈夫です。\n\nこのnarrowingの状態ですと表示されている領域しか編集対象になりません。置換なんかもこの範囲内です。編集を終了したら前述の`C-x n\nw`で元に戻してください。\n\nちなみに初めてnarrowing系コマンドを使うときは「本当に大丈夫か?」みたいなことをEmacsが聞いて来ます。これはこのコマンドを知らないとパニックを起こすためです。narrowing系コマンドは他に、\n\n * `narrow-to-defun` (カーソルのある位置の関数・メソッド定義)\n * `narrow-to-page` (`^L`で挟まれた領域。elispはこれでページを分けたりしているようです)\n\nがあります。カーソルのある位置のクラス定義全体を編集範囲にしたいときは\n\n 1. `C-M-u`を何度か押してクラス定義の先頭にカーソルを持って行く\n 2. `C-M-space C-x n n`でnarrowing\n 3. 心ゆくまで編集し\n 4. `C-x n w`でnarrowing解除\n\nという手順になります。`C-M-u` (`M-x backward-up-list`)はブロックを遡る\n(押すたびに一つ上のレベルのブロックにカーソルが移動する)、`C-M-space`(`M-x mark-sexp`)\nはブロックをマークするというもので覚えておくと便利かと思います。\n\nただし、`narrow-to-defun`や`mark-sexp`や`backward-up-\nlist`はメジャーモードが対応していないと使えないかもしれません。lisp-modeとruby-modeで使っていますのでこれらモードでは動きます。\n\nもうひとつ、リファクタリングにはmultiple-cursorsパッケージが有用かと思います。\n\n# メソッドの切り出し\n\nこれは`C-M-k`(`M-x kill-\nsexp`)と前述の`C-M-u`を駆使しましょう。`C-M-u`でメソッドの先頭に持って行って、`C-M-k`です。\n\nあるいは`M-x mark-defun`の後に`C-w`でもよいかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-17T12:41:57.373", "id": "1922", "last_activity_date": "2014-12-17T12:55:56.067", "last_edit_date": "2014-12-17T12:55:56.067", "last_editor_user_id": "3413", "owner_user_id": "3413", "parent_id": "73", "post_type": "answer", "score": 4 }, { "body": "> コード編集支援: クラス名やスコープ内の変数などから変数名を自動補完する\n\nAuto complete mode(<http://cx4a.org/software/auto-complete/index.ja.html>)\nはいかがでしょうか? GNU Global(<http://www.gnu.org/software/global/>)\nのタグを情報源に補完できるので、完璧とはいえませんが、そこそこ快適にコーディングできると思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-28T19:17:36.870", "id": "2760", "last_activity_date": "2014-12-28T19:17:36.870", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5727", "parent_id": "73", "post_type": "answer", "score": 2 } ]
73
164
164
{ "accepted_answer_id": "160", "answer_count": 2, "body": "go言語で以下のようにコマンドを実行すると\"compile and run Go\nprogram\"するとUsageに書かれているが、compileされたバイナリはどこかに保存されますか?\n\n```\n\n $ go run hello.go\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-04T14:56:18.787", "favorite_count": 0, "id": "84", "last_activity_date": "2014-11-11T05:40:19.747", "last_edit_date": "2014-10-23T17:03:12.410", "last_editor_user_id": "10", "owner_user_id": "33", "post_type": "question", "score": 8, "tags": [ "go" ], "title": "go runでコンパイルされるバイナリはどこかに保存される?", "view_count": 2683 }
[ { "body": "コンパイルして実行ファイルを作成する場合、\"go build\"コマンドが使えます\n\n```\n\n go build hello.go\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-11T03:01:42.600", "id": "158", "last_activity_date": "2014-11-11T03:01:42.600", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "63", "parent_id": "84", "post_type": "answer", "score": 1 }, { "body": "[go コマンドのドキュメント](https://golang.org/cmd/go/)によると、-work オプションをつけると go run\nでコンパイルされたバイナリが格納されているテンポラリディレクトリを削除せずに残しておいてくれて、そのディレクトリ名が表示されるそうです。\n\n```\n\n $ go run -work hello.go\n WORK=/tmp/go-build943288373\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-11T05:40:19.747", "id": "160", "last_activity_date": "2014-11-11T05:40:19.747", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "72", "parent_id": "84", "post_type": "answer", "score": 14 } ]
84
160
160
{ "accepted_answer_id": "104", "answer_count": 1, "body": "1. ランチャーアクティビティからAccountManager経由で独自AccountAuthenticatorActivityを起動\n 2. 独自AccountAuthenticatorActivityでバックボタンが押されたら、認証をキャンセル\n 3. AccountManagerのコールバックでfutureがキャンセルされていたら、ランチャーアクティビティをfinish\n 4. アクティビティが消えるトランジションの後、一瞬 (それまでに起動していた) アプリの画面が表示される\n\nという症状です。\n\nAndroidManifest.xml\n\n```\n\n <activity\n android:name=\".activity.LaunchActivity\"\n android:label=\"@string/app_name\"\n android:screenOrientation=\"portrait\"\n android:theme=\"@style/Theme.AppCompat.Translucent.NoTitleBar\" >\n <intent-filter>\n <action android:name=\"android.intent.action.MAIN\" />\n <category android:name=\"android.intent.category.LAUNCHER\" />\n </intent-filter>\n </activity>\n \n```\n\nバックボタンが押された時のコールバック: 認証をキャンセルする\n\n```\n\n public class LoginActivity extends AccountAuthenticatorActivity {\n @Override\n public void onBackPressed() {\n setAccountAuthenticatorResult(null);\n setResult(RESULT_CANCELED);\n finish();\n }\n }\n \n```\n\nAccountManagerのコールバック内でキャンセルを処理\n\n```\n\n mAccountManager.getAuthTokenByFeatures(mAccountType, mAuthTokenType, null, activity, null, null,\n new AccountManagerCallback<Bundle>() {\n @Override\n public void run(AccountManagerFuture<Bundle> future) {\n Bundle bundle;\n try {\n if (future.isCancelled()) {\n eventBus.post(new LoginFailedEvent(true));\n return;\n }\n \n```\n\nランチャーアクティビティを`finish()`\n\n```\n\n public class LaunchActivity extends BaseActivity {\n // EventBus経由で受け取る\n public void onEventMainThread(LoginFailedEvent event) {\n if (event.isCancelled()) {\n finish();\n }\n \n```\n\n終了の仕方がおかしいなどあるでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-09T10:18:10.977", "favorite_count": 0, "id": "103", "last_activity_date": "2014-10-13T14:46:55.037", "last_edit_date": "2014-10-13T14:46:55.037", "last_editor_user_id": "30", "owner_user_id": "30", "post_type": "question", "score": 6, "tags": [ "android" ], "title": "finishする瞬間に他のアプリが一瞬表示されてしまう", "view_count": 1545 }
[ { "body": "これは[Nexus 5 + Android\n4.4.3以降で起きる問題](https://code.google.com/p/android/issues/detail?id=71067)のようです。\n\n回避策として、`moveTaskToBack`で一旦アプリをバックグラウンドに回すようにしたら他のアプリは表示されなくなりました。\n\n```\n\n public class LaunchActivity extends BaseActivity {\n // EventBus経由で受け取る\n public void onEventMainThread(LoginFailedEvent event) {\n if (event.isCancelled()) {\n // workaround for: https://code.google.com/p/android/issues/detail?id=71067\n moveTaskToBack(false);\n finish();\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-09T10:18:10.977", "id": "104", "last_activity_date": "2014-10-13T14:45:06.843", "last_edit_date": "2014-10-13T14:45:06.843", "last_editor_user_id": "30", "owner_user_id": "30", "parent_id": "103", "post_type": "answer", "score": 8 } ]
103
104
104
{ "accepted_answer_id": null, "answer_count": 5, "body": "PHPで文字列がメールアドレスかどうか判定する方法を教えてください。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-09T10:44:29.833", "favorite_count": 0, "id": "106", "last_activity_date": "2015-01-22T08:28:15.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37", "post_type": "question", "score": 13, "tags": [ "php" ], "title": "PHPで文字列がメールアドレスか判定するには?", "view_count": 2793 }
[ { "body": "正規表現を使用した判定方法が以下のページに紹介されています.\n\n * [正規表現:メールアドレスかどうか調べる](http://phpspot.net/php/pg%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE%EF%BC%9A%E3%83%A1%E3%83%BC%E3%83%AB%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9%E3%81%8B%E3%81%A9%E3%81%86%E3%81%8B%E8%AA%BF%E3%81%B9%E3%82%8B.html)\n * [メールアドレスを表す現実的な正規表現](http://qiita.com/sakuro/items/1eaa307609ceaaf51123)", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-11T04:59:20.860", "id": "159", "last_activity_date": "2014-12-05T01:25:51.390", "last_edit_date": "2014-12-05T01:25:51.390", "last_editor_user_id": "30", "owner_user_id": "68", "parent_id": "106", "post_type": "answer", "score": -2 }, { "body": "アドレスっぽいかどうかチェックするだけならfilter_varで。\n\n```\n\n $mail = filter_var($str, FILTER_VALIDATE_EMAIL)\n \n```\n\nただ、RFCに準拠させたりメールヘッダをパースする用途では使うのはNG。\n\nいっそ、試しにメール送ってみればいいんじゃないかな", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-11T14:11:24.887", "id": "161", "last_activity_date": "2014-11-11T14:11:24.887", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "62", "parent_id": "106", "post_type": "answer", "score": 20 }, { "body": "Emailアドレスの検証を行うライブラリは多数存在しているので要件にあったものを選択して組み込むのがよいのではと思います。\n特に日本ではキャリアのメールアドレスのような特殊なフォーマットをどう扱うか、に応じて事情が変わってきます。\n\nPackgistで検索すると下記のライブラリが利用が多いようでした。\n\n<https://packagist.org/packages/egulias/email-validator>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:41:36.063", "id": "235", "last_activity_date": "2014-12-02T05:41:36.063", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "452", "parent_id": "106", "post_type": "answer", "score": 4 }, { "body": "UTF-8\nの文字を認める国際化ドメインを前提にすると、通常の文章と区別がつかなくなるので、セキュリティ対策に議論を絞るとよいのではないかと思います。なお、Postfix\nは 2.12 から [SMTPUTF8](http://www.postfix.org/SMTPUTF8_README.html)\nに対応したので、Ubuntu や Debian であれば、2016年から2017年までには 2.12 を利用できるようになるでしょう。\n\n国際化ドメインを扱う場合、従来の XSS や SQL インジェクション対策に加えて、キリル文字をラテン文字に混在させる\n([偽キリル文字](http://ja.wikipedia.org/wiki/%E5%81%BD%E3%82%AD%E3%83%AA%E3%83%AB%E6%96%87%E5%AD%97))\nなど肉眼では区別できない文字を使ったなりすましドメインを識別する必要があるか、考える必要があります。2005年ごろにさまざまなブラウザーがなりすましドメインの対応に追われました。\n\nなりすまし対策の例として Gmail を挙げます。 \nGmail\nの[仕様](https://support.google.com/mail/answer/81126#format)では、なりすまし対策としてメールアドレスは\nUTS#39 の「[Highly\nRestrictive](http://www.unicode.org/reports/tr39/#Restriction_Level_Detection)」を満たすことを求めています。具体的には、それぞれの文字の\nUnicode スクリプトプロパティが1種類もしくは複数の種類の場合、指定した組み合わせであることを要求します。\n\n日本語のドメインを対象とするのであれば、スクリプトプロパティの組み合わせは Latin、Han、Hiragana、Katakana\nで構成されなければなりません。ほかに認められる複数の組み合わせの例は Latin、Han、Bopomofo (台湾で使われる注音符号) もしくは Latin\n+ Han + Hangul です。\n\nスクリプトの組み合わせのほかの例として、Firefox の[IDN\n表示アルゴリズム](https://wiki.mozilla.org/IDN_Display_Algorithm#Current_Algorithm)は制限レベルに\nModerately Restrictive を採用しています。\n\nUnicode スクリプトプロパティの組み合わせを判定するには PCRE や intl の `Spoofchecker`\nを使います。自分でライブラリを実装するのであれば、unicode.org で配布されている\n[Scripts.txt](http://www.unicode.org/Public/7.0.0/ucd/Scripts.txt) を使います。\n\n次のコードは ICU 51 とそれ以降のバージョンで確認したものです。ICU のバージョンを調べるには `INTL_ICU_VERSION`\nを使います。ただし、この定数が導入されたバージョンは PHP 5.3.7 なので、それ以前のバージョンを利用していてかつ pecl\nのリポジトリからインストールしていない場合、`phpinfo` 関数もしくはコマンドラインで `php -i | grep ICU` を実行します。C\n言語で ICU のバージョン番号で求めるには uvernum.h のマニュアルをご参照ください。`isSuspicious` の実装に使われる\n`uspoof_checkUTF8` は ICU 51 で非推奨になり、最新の ICU 54 でも使えるものの、長期的には intl\nのアップグレードが必要になるでしょう。\n\n```\n\n $spoof = new Spoofchecker;\n $spoof->setChecks(Spoofchecker::SINGLE_SCRIPT);\n \n // Cyrillic\n $str = 'Кириллица';\n // Latin + Han + Hiragana + Katakana\n $str2 = 'latin漢字ひらがなカタカナ';\n // Latin + Han + Hangul\n $str3 = 'latin漢字조선말';\n // Latin + Han + Bopomofo\n $str4 = 'latin漢字ㄅㄆㄇㄈ';\n \n var_dump(\n false === $spoof->isSuspicious($str),\n false === $spoof->isSuspicious($str2),\n false === $spoof->isSuspicious($str3),\n false === $spoof->isSuspicious($str4),\n true === $spoof->isSuspicious($str.$str2)\n );\n \n```\n\nロケールごとで認められるスクリプトの組み合わせを判定することもできます。\n\n```\n\n // Latin + Han + Hiragana + Katakana\n $str = 'latin漢字ひらがなカタカナ';\n $pattern = '/\\A[\\p{Latin}\\p{Han}\\p{Hiragana}\\p{Katakana}]+\\z/u';\n \n $spoof = new Spoofchecker;\n $spoof->setAllowedLocales('en_US,ja_JP');\n \n var_dump(\n false === $spoof->isSuspicious('latin漢字ひらがなカタカナ'),\n 1 === preg_match($pattern, $str)\n );\n \n```\n\nほかに、ドメイン名登録業サービスで登録可能な文字であるかどうかを判定するには準拠する IDNA のバージョンによって異なりますので、IDNA\nの仕様書を調べる必要があります。IDNA2003 であれば参照される Unicode のバージョンは 3.2 です。IANA\nは国際化ドメインに許可される文字のテーブルを配布しています ([Repository of IDN\nPractices](https://www.iana.org/domains/idn-tables))。\n\n濁点つきひらがなのように同じ文字を異なる表現で登録することを認めたくない場合、`normalizer_is_normalized`\nを使ってチェックする必要があります。Nameprep で適用される正規化の形式は KC です。\n\n許可する文字テーブルをもとに判定する方法を採用しているのが ZF2 の `Validator\\EmailAddress` です\n(判定のためのテーブルの[ディレクトリ](https://github.com/zendframework/zf2/tree/master/library/Zend/Validator/Hostname))。ただし、どこのリポジトリから採用したテーブルなのか明記されていないのと、2014年の時点では、ローカルパートは\nUTF-8 に対応していません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-22T07:17:06.803", "id": "2371", "last_activity_date": "2015-01-14T00:35:03.527", "last_edit_date": "2015-01-14T00:35:03.527", "last_editor_user_id": "568", "owner_user_id": "568", "parent_id": "106", "post_type": "answer", "score": 14 }, { "body": "何処まで確認したいかが分からないです。 \n確認方法は上記に出揃っているので省くとして \nドメイン名を取ってDNSで有効か確認(dns_get_record)までするのかな?\n\n一応、配列取得してMXチェックすればメールが有効とか…やりすぎ感はあるけどね\n\n```\n\n $results = dns_get_record(\"i.softbank.jp\");\n $isMailDomain = false;\n foreach($results as $res){\n if($res['type'] == 'MX'){\n $isMailDomain = true;\n break;\n }\n }\n if($isMailDomain){echo \"メールドメインだったよ\";}\n else{echo \"メールドメインじゃないよ\";}\n /**\n Array ( \n [0] => Array ( \n [host] => i.softbank.jp \n [type] => TXT \n [txt] => v=spf1 ip4:101.110.8.0/23 ip4:126.240.66.0/24 ip4:117.46.5.64/27 ip4:117.46.7.32/27 ip4:117.46.9.96/27 ip4:117.46.11.64/27 -all \n [class] => IN [ttl] => 1656 \n ) \n [1] => Array ( \n [host] => i.softbank.jp \n [type] => MX \n [pri] => 10 \n [target] => msv.softbank.jp \n [class] => IN [ttl] => 75 \n ) \n )\n **/\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-01-22T08:28:15.557", "id": "5068", "last_activity_date": "2015-01-22T08:28:15.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7676", "parent_id": "106", "post_type": "answer", "score": 1 } ]
106
null
161
{ "accepted_answer_id": "109", "answer_count": 3, "body": "Flask-Mobility\nを使っているのですが、PCのブラウザでスマホ表示の確認をする方法はないでしょうか?スマホかPCかの判定をライブラリ内で行っていると思うので、それを外部から制御できるとよいと思うのですが", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-09T11:32:52.883", "favorite_count": 0, "id": "107", "last_activity_date": "2014-12-02T18:38:48.967", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37", "post_type": "question", "score": 4, "tags": [ "python" ], "title": "Flask-Mobility でスマホ表示をPCで表示する方法はありませんか?", "view_count": 438 }
[ { "body": "リクエスト前処理の \"before_request\" で \"request.MOBILE = True\"\nとする事で表示をスマホ版に強制的に切り替える事が可能です。\n\n```\n\n @public.before_request\n def before_request():\n request.MOBILE = True\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-09T11:48:12.347", "id": "108", "last_activity_date": "2014-10-09T11:48:12.347", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37", "parent_id": "107", "post_type": "answer", "score": 1 }, { "body": "Flask-Mobilityの[ソース](https://github.com/rehandalal/flask-\nmobility/blob/master/flask_mobility/main.py#L15)を見ると、User-\nAgentヘッダをみてモバイルかどうかを判断しています。\n\nほとんどのブラウザに、カスタムのUser-Agentヘッダを送る機能があると思いますので、それを使ってモバイルブラウザのUser-\nAgentを送るようにすれば、スマホ版の表示を確認できると思います。\n\niPhoneのUser-Agentの例\n\n```\n\n Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53\n \n```\n\nGoogle\nChromeでは、開発者ツールの左上にあるスマホアイコンをクリックすることでモバイルをはじめとしたデバイスの[エミュレーションモードを起動](https://developer.chrome.com/devtools/docs/device-\nmode#enable-device-mode)できます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-09T12:15:55.357", "id": "109", "last_activity_date": "2014-10-09T12:15:55.357", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "107", "post_type": "answer", "score": 2 }, { "body": "Google Chromeだと、F12で表示できるデベロッパーツールから画面サイズの固定やUser-Agentのオーバーライドができます。\n\n## 方法\n\n 1. F12を押す\n\n 2. デベロッパーツール左上の虫眼鏡の右隣にあるスマホのアイコンをクリック\n\n 3. `Device`欄から既存のスマホのプロファイルを選ぶ\n\n 4. (再現したいスマホがない場合は) 画面サイズ・通信帯域・User-Agent(`UA`欄)を入力\n\n 5. F5で更新し反映", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T18:38:48.967", "id": "273", "last_activity_date": "2014-12-02T18:38:48.967", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "197", "parent_id": "107", "post_type": "answer", "score": 1 } ]
107
109
109
{ "accepted_answer_id": null, "answer_count": 3, "body": "iOS開発初心者ですが、無謀にもstoryboardを使わずにiPhoneとiPadで動くuniversalアプリを開発しようとしているところです。シミュレータでiPhoneとiPad2を選択して起動すると問題なく起動しますが、iPad\nretinaとiPad Airを選択すると起動時にエラーが発生します。\n\nこの情報から考えられうるエラー原因はなんでしょうか。 \n個人的には設定関連でケアレスミスをしている気がしているのですが、、、 \n同じような症状がでてこれで解決できたというような方がいたらご回答お願いいたします。\n\n・エラー箇所\n\n```\n\n int main(int argc, char * argv[]) {\n @autoreleasepool {\n return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));ここでストップします(Thread1:signal SIGABRTといわれる)\n }\n }\n \n```\n\n・outputにでてきたログ\n\n```\n\n > (loaded)'\n *** First throw call stack:\n (\n 0 CoreFoundation 0x000000010cedc3f5 __exceptionPreprocess + 165\n 1 libobjc.A.dylib 0x000000010cb75bb7 objc_exception_throw + 45\n 2 UIKit 0x000000010da56cf0 -[UIStoryboard name] + 0\n 3 UIKit 0x000000010d50aca9 -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 40\n 4 UIKit 0x000000010d509d49 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1075\n 5 UIKit 0x000000010d508d22 -[UIApplication workspaceDidEndTransaction:] + 179\n 6 FrontBoardServices 0x0000000110a362a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16\n 7 CoreFoundation 0x000000010ce11abc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12\n 8 CoreFoundation 0x000000010ce07805 __CFRunLoopDoBlocks + 341\n 9 CoreFoundation 0x000000010ce075c5 __CFRunLoopRun + 2389\n 10 CoreFoundation 0x000000010ce06a06 CFRunLoopRunSpecific + 470\n 11 UIKit 0x000000010d508799 -[UIApplication _run] + 413\n 12 UIKit 0x000000010d50b550 UIApplicationMain + 1282\n 13 Add or Sub 0x000000010c645703 main + 115\n 14 libdyld.dylib 0x000000010f71a145 start + 1\n )\n libc++abi.dylib: terminating with uncaught exception of type NSException\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2014-10-16T08:38:37.883", "favorite_count": 0, "id": "143", "last_activity_date": "2021-02-05T00:54:23.940", "last_edit_date": "2021-02-05T00:53:44.923", "last_editor_user_id": "3060", "owner_user_id": "45", "post_type": "question", "score": 8, "tags": [ "xcode", "ios" ], "title": "iPad2シミュレータでは動くがiPad retina、iPad Airでは動かないのはなぜか", "view_count": 1191 }
[ { "body": "細かいところはわかりませんが、ビルド時のアーキテクチャ設定もミスなような気がします。 XCodeのビルド設定の項目に **Valid\nArchitectures** という項目があります。 おそらく`armv7`などが設定されているのではないかと思われます。\n\niPhone5 以降の機種については、`Apple A6 CPU` 以降のCPUが使用されています。これは\n`armv7s`というアーキテクチャに対応しているため、こういうのが原因かなと思っていますが、定かではありません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:20:49.050", "id": "342", "last_activity_date": "2014-12-04T04:20:49.050", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "264", "parent_id": "143", "post_type": "answer", "score": 2 }, { "body": "Xcode6ではStandard Architecturesからarmv7sが外されており、 \niPad Airなどで実行したい場合はBuild Settings->Architecturesに手動で設定値を追加する必要があります。\n\n<https://stackoverflow.com/questions/24040497/xcode-6-standard-architectures-\nexclude-armv7s>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T02:37:29.397", "id": "1637", "last_activity_date": "2014-12-16T02:37:29.397", "last_edit_date": "2017-05-23T12:38:55.307", "last_editor_user_id": "-1", "owner_user_id": "2790", "parent_id": "143", "post_type": "answer", "score": 3 }, { "body": "**対処方法を発見したのでここに記載しておきます**\n\nuniversal ではなくてiPad専用の設定にしてからビルドし、その後 universal\nの設定に戻してビルドしたら動くようになりました。原因はわかりませんが、これで動くようになりました。\n\n* * *\n\n_この投稿は @Kei Minagawa さんが質問文に記載した内容を元に、コミュニティwiki で個別の回答として投稿しました。_", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2021-02-05T00:54:23.940", "id": "73805", "last_activity_date": "2021-02-05T00:54:23.940", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "143", "post_type": "answer", "score": 0 } ]
143
null
1637
{ "accepted_answer_id": "146", "answer_count": 1, "body": "REST APIのテストフレームワークであるFrisby.jsに関する質問。 \nレスポンスのJSONデータの値が「nullか文字列」である事をテストしたい場合、以下のような形でCustom Matcherが使える。\n\n```\n\n frisby.create('Test using a path as the paramater')\n .get('http://localhost:3000/test')\n .expectJSONTypes('member.*', {\n \"name\": String,\n \"hobby\": function(val) { expect(val).toBeTypeOrNull(String); }, // Custom Matcher\n \"rank\": {\n \"name\": string, \n \"point\": Number\n }\n })\n .toss()\n \n```\n\nしかし、JSONがネストしている場合、Custom Matcherがうまく使えない。 \n例えば\"rank\"の\"name\"がnullか文字列というテストをしようとするとエラーとなってしまう。 \n解決方法が分かれば教えて下さい。\n\n```\n\n frisby.create('Test using a path as the paramater')\n .get('http://localhost:3000/test')\n .expectJSONTypes('member.*', {\n \"name\": String,\n \"hobby\": String,\n \"rank\": {\n \"name\": function(val) { expect(val).toBeTypeOrNull(String); }, // エラーになる \n \"point\": Number\n }\n })\n .toss()\n \n```\n\nエラーメッセージは以下。\n\n```\n\n 1) Frisby Test: Test using a path as the paramater \n [ GET http://localhost:3000/test ]\n Message:\n Error: Expected 'string' to be type 'object' on key 'name'\n Stacktrace:\n Error: Expected 'string' to be type 'object' on key 'name'\n at _jsonContainsTypes (/home/vagrant/frisby_test/node_modules/frisby/lib/frisby.js:1283:15)\n at _jsonContainsTypes (/home/vagrant/frisby_test/node_modules/frisby/lib/frisby.js:1271:9)\n at jasmine.Matchers.toContainJsonTypes (/home/vagrant/frisby_test/node_modules/frisby/lib/frisby.js:1156:12)\n at /home/vagrant/frisby_test/node_modules/frisby/lib/frisby.js:573:22\n at Array.forEach (native)\n at Function._.each._.forEach (/home/vagrant/frisby_test/node_modules/frisby/node_modules/underscore/underscore.js:81:11)\n at null.<anonymous> (/home/vagrant/frisby_test/node_modules/frisby/lib/frisby.js:572:9)\n at null.<anonymous> (/home/vagrant/frisby_test/node_modules/frisby/lib/frisby.js:1043:43)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-26T15:28:44.797", "favorite_count": 0, "id": "145", "last_activity_date": "2014-12-20T08:06:21.897", "last_edit_date": "2014-12-20T08:06:21.897", "last_editor_user_id": "33", "owner_user_id": "33", "post_type": "question", "score": 3, "tags": [ "javascript", "rest", "テスト" ], "title": "Frisby.jsでネストしたJSON ResponseのテストにCustom Matcherが使えない", "view_count": 928 }
[ { "body": "[`.expectJsonTypes()`は内部的にはJasmineのカスタムmatcherを呼んでいる](https://github.com/vlucas/frisby/blob/3b5f4146ff919a7687ed83501a2deef06d3f2282/lib/frisby.js#L1186)ので、それを利用して最上位の\n`\"key\": object` に対してCustom Matcherを書くことでわりときれいに回避できます:\n\n```\n\n var frisby = require('frisby');\n beforeEach(function() {\n this.addMatchers(jasmine.Matchers.prototype);\n })\n frisby.create('Test using a path as the paramater')\n .get('http://localhost:3000/test')\n .expectJSONTypes(\"members.*\", {\n \"name\": String,\n \"hobby\": String,\n \"rank\": function(val) {\n expect(val).toContainJsonTypes({\n \"name\": function(val) {\n expect(val).toBeTypeOrNull(String);\n },\n \"point\": Number\n })\n }\n })\n .toss()\n \n```\n\n`beforeEach`\nは、ちょっと処理内容が冗長になりますが、Frisbyが内部で定義しているカスタムmatcherが正しくJasmineに登録されていなかったため追加しました。これを追加しない場合、`expect`の結果を`return`し、Frisbyにテストの成否を判定させる必要があります。\n\nなお、この「ネストされたオブジェクトにカスタムmatcherが使えない」問題に関して[バグ報告](https://github.com/vlucas/frisby/issues/93)が[上がっています](https://github.com/vlucas/frisby/issues/93)。修正されれば不要な回避策になります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-27T03:42:28.397", "id": "146", "last_activity_date": "2014-10-30T07:15:55.460", "last_edit_date": "2014-10-30T07:15:55.460", "last_editor_user_id": "30", "owner_user_id": "30", "parent_id": "145", "post_type": "answer", "score": 2 } ]
145
146
146
{ "accepted_answer_id": "148", "answer_count": 1, "body": "マウスカーソルをのせても、クリックしてもドロップダウンメニューが開きません。やったこと:\n\nプロジェクトを作ってパッケージを追加:\n\n```\n\n $ meteor create dropdown-test\n $ cd dropdown-test\n $ meteor add iron:router ewall:foundation\n \n```\n\n`dropdown-\ntest.html`にFoundationのドロップダウンメニューを[サンプル](http://foundation.zurb.com/docs/components/topbar.html)からコピペ:\n\n```\n\n <template name=\"layout\">\n <nav class=\"top-bar\" data-topbar role=\"navigation\">\n <section class=\"top-bar-section\">\n <ul class=\"right\">\n <li class=\"active\"><a href=\"#\">Right Button Active</a></li>\n <li class=\"has-dropdown\">\n <a href=\"#\">Right Button Dropdown</a>\n <ul class=\"dropdown\">\n <li><a href=\"#\">First link in dropdown</a></li>\n <li class=\"active\"><a href=\"#\">Active link in dropdown</a></li>\n </ul>\n </li>\n </ul>\n </section>\n </nav>\n <div id=\"main\" class=\"row\">\n {{> yield}}\n </div>\n </template>\n \n <template name=\"hello\">\n Hello world!\n </template>\n \n```\n\n`dropdown-test.js`にルーティング情報を追加\n\n```\n\n Router.configure({\n layoutTemplate: 'layout'\n });\n \n Router.route('/', {name: 'hello'});\n \n```\n\nmeteorを実行\n\n```\n\n $ meteor\n \n```\n\n各バージョン:\n\n * meteor: 1.0\n * ewall:foundation: 5.4.6\n * iron:router: 1.0.0", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-31T03:55:40.883", "favorite_count": 0, "id": "147", "last_activity_date": "2014-11-01T09:29:56.613", "last_edit_date": "2014-10-31T21:54:57.847", "last_editor_user_id": "12", "owner_user_id": "30", "post_type": "question", "score": 3, "tags": [ "meteor", "iron-router" ], "title": "MeteorでIron Routerを使うとFoundationのドロップダウンメニューが動かない", "view_count": 192 }
[ { "body": "[別のFoundation用パッケージのReadme](https://github.com/juliancwirko/meteor-\nzf5)に書かれているように、ルーティング後にFoundationを初期化するようにする必要があります。\n\nたとえば`dropdown-test.js`に以下を足します。\n\n```\n\n if (Meteor.isClient) {\n Meteor.startup(function () {\n if (typeof(Router) !== 'undefined' && Router.onAfterAction) {\n Router.onAfterAction(function () {\n Tracker.afterFlush(function () {\n $(document).foundation('reflow');\n });\n });\n } else {\n UI.body.rendered = function () {\n $(document).foundation('reflow');\n };\n }\n });\n }\n \n```\n\nルーティングとは無関係にテンプレートがレンダリングされることがある場合は、そのテンプレートの`rendered`コールバックで初期化を制御できます。\n\n```\n\n Template.alert.rendered = function () {\n // alertプラグインのみ初期化\n $(document).foundation('alert', 'reflow');\n };\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-10-31T03:55:40.883", "id": "148", "last_activity_date": "2014-11-01T09:29:56.613", "last_edit_date": "2014-11-01T09:29:56.613", "last_editor_user_id": "30", "owner_user_id": "30", "parent_id": "147", "post_type": "answer", "score": 2 } ]
147
148
148
{ "accepted_answer_id": "153", "answer_count": 1, "body": "Meteorと[meteor-mocha-web](https://github.com/mad-eye/meteor-mocha-\nweb)でテストを動かそうとしていますが、テストをmochaに見つけてもらえません。\n\n```\n\n $ meteor add mike:mocha@0.4.4 # 別の問題を回避するため現時点での最新版をインストール\n $ mkdir -p tests/server/unit\n \n```\n\n[サンプルのテスト](https://github.com/meteor-velocity/velocity-\nexamples/blob/master/leaderboard-\nmocha/tests/mocha/server/serverTest.js)をコピペして、確実に落ちるように修正:\n\n`tests/server/unit/test.js`\n\n```\n\n if (!(typeof MochaWeb === 'undefined')){\n MochaWeb.testOnly(function(){\n describe(\"Server initialization\", function(){\n it(\"should insert players into the database after server start\", function(){\n chai.assert(0 > 0);\n });\n });\n });\n }\n \n```\n\nmeteorを実行\n\n```\n\n $ meteor\n \n```\n\nアプリの画面をブラウザで開くと右上に青い丸が出て、詳細を見ると \"0 tests passed in 0 ms\" と出ています。\n\n何か手順を間違えているでしょうか。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-06T05:39:18.127", "favorite_count": 0, "id": "152", "last_activity_date": "2014-12-20T11:57:36.693", "last_edit_date": "2014-12-20T11:57:36.693", "last_editor_user_id": "33", "owner_user_id": "30", "post_type": "question", "score": 3, "tags": [ "テスト", "meteor" ], "title": "Meteor+mochaでテストが実行されない", "view_count": 155 }
[ { "body": "[meteor-mocha-webは`tests/mocha/`の下にあるファイルしかロードしない](https://github.com/mad-\neye/meteor-mocha-\nweb/blob/71201992a494a97e5a72d2afc4b805ea979ae982/server.js#L9)ので、テストコードの置き場所を変える必要があります。\n\n```\n\n $ mkdir -p tests/mocha/server/unit\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-06T05:39:18.127", "id": "153", "last_activity_date": "2014-11-06T05:39:18.127", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "152", "post_type": "answer", "score": 2 } ]
152
153
153
{ "accepted_answer_id": "157", "answer_count": 1, "body": "`nodejs` cookbookを自前cookbookで使おうとしているのですが、`include_recipe \"nodejs\"` や\n`nodejs_npm \"bower\" do ... end.run(:install)` などしても、どうも反映されません。\n\n問題を突きとめるために`log`を入れても、出力されません。\n\n`site-cookbooks/my-cookbook/recipes/default.rb`:\n\n```\n\n log \"debug\" do\n message \"hello there\"\n level :error\n end\n \n```\n\n```\n\n $ knife solo cook -i path/to/pem hostename\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-10T11:55:52.127", "favorite_count": 0, "id": "156", "last_activity_date": "2014-11-10T11:55:52.127", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "post_type": "question", "score": 2, "tags": [ "chef" ], "title": "chef solo用の自前cookbookを更新しても反映されない", "view_count": 465 }
[ { "body": "私の場合、`knife` の設定ファイルがバージョン管理されておらず、ワーキングコピーに `.chef/knife.rb` がなかったことが原因でした。\n\n[こちらの記事](http://qiita.com/DQNEO/items/0ade0c3fa9616d33bfbb)にあるように、 `knife solo\ninit .` することで `site-cookbooks` を読み込ませるのに必要な設定を生成することができました。\n\n```\n\n cookbook_path [\"cookbooks\", \"site-cookbooks\"]\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-10T11:55:52.127", "id": "157", "last_activity_date": "2014-11-10T11:55:52.127", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "156", "post_type": "answer", "score": 2 } ]
156
157
157
{ "accepted_answer_id": "163", "answer_count": 2, "body": "標準入力が与えられた場合はそちらを行ごとに、そうでない場合は引数をまるまる1行として扱うスクリプトを作ろうとしています。\n\n```\n\n #!/bin/sh\n \n fetch_input () {\n [ -t 0 ] && echo \"$1\" || cat -\n }\n \n fetch_input \"$*\" | while IFS= read -r line\n do\n echo \"reading: $line\"\n done\n \n```\n\n標準入力が存在するかチェックするのに上のように`[ -t\n0]`を使用すると大抵の場合はうまくいくのですが、インタラクティブシェルで動かすことが前提になるため、sshなどでリモートマシンのスクリプトを動かそうとすると`-t`オプションで仮想端末を用意する必要がでてしまいます。\n\n```\n\n ssh -t remote '/path/to/script.sh foo bar'\n \n```\n\nこの場合、もっと単純に標準入力と引数のどちらにも対応できるスクリプトを書く方法はありますか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-11T14:44:13.173", "favorite_count": 0, "id": "162", "last_activity_date": "2019-11-23T15:05:11.067", "last_edit_date": "2015-07-10T22:28:40.983", "last_editor_user_id": "2349", "owner_user_id": "62", "post_type": "question", "score": 8, "tags": [ "sh" ], "title": "標準入力と引数のどちらにも対応したbourne-shellスクリプト", "view_count": 690 }
[ { "body": "普通※は引数の有無で判定します。(※例:`cat`) `$#` で引数の数が分かるので↓とか\n\n```\n\n { test $# = 0 && cat || echo \"$*\"; }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-12T15:57:17.580", "id": "163", "last_activity_date": "2014-11-12T15:57:17.580", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "81", "parent_id": "162", "post_type": "answer", "score": 3 }, { "body": "別解です。 \n変数の展開機能を利用して、引数がない場合は標準入力(`cat`の実行結果の置換)、あれば引数を使用する。\n\n```\n\n ${@:-\"`cat`\"}\n \n```\n\n`bash`ならば次の例も使えます。\n\n```\n\n ${@:-\"$(cat)\"}\n \n```\n\n【使用例】\n\n```\n\n printf \"%s\" ${@:-\"`cat`\"}\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-11-23T15:05:11.067", "id": "60794", "last_activity_date": "2019-11-23T15:05:11.067", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "35558", "parent_id": "162", "post_type": "answer", "score": 1 } ]
162
163
163
{ "accepted_answer_id": "173", "answer_count": 2, "body": "Markdown で書いた文書にシンタックスハイライトした形でソースコードを掲載したいと考えています。Pygments 等のツールを使って Markdown\n中のコードをハイライトするにはどうすれば良いでしょうか?\n\nコマンドラインで動作する Markdown→HTML 変換ツールでシンタックスハイライトができるようなツールがあれば教えていただきたいです。またできれば\nGitHub-flavored Markdown が扱えればなお嬉しいです。\n\nよろしくおねがいします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-16T12:48:28.427", "favorite_count": 0, "id": "165", "last_activity_date": "2014-12-02T07:36:56.407", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "73", "post_type": "question", "score": 5, "tags": [ "markdown" ], "title": "Markdown に含まれるコードをシンタックスハイライトするには?", "view_count": 1068 }
[ { "body": "[Grip - Github Readme Instant Preview](https://github.com/joeyespo/grip)\nを使ってみるのはどうでしょうか.\n\n以下のコマンドを実行してインストールし,\n\n```\n\n % pip install grip\n \n```\n\n以下のコマンドを実行すると Github-flavored Markdown なファイル (`file.md`) が HTML (`file.html`)\nに変換されます.文章中のソースコードは Pygments によってシンタックスハイライトされます.\n\n```\n\n % grip --export --gfm file.md\n \n```\n\n**補足:**\n\n * `\\--export` オプションを指定しない場合は,`localhost:5000` を Web ブラウザで開くことで変換後の内容を閲覧できます.\n * Grip 3.0.0 と Python 3.4.0 の組み合わせでは `\\--export` オプションによる .md -> .html 変換が正常に実行できませんでした.Python 2.7 では正常に動作しました.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-17T15:04:34.240", "id": "173", "last_activity_date": "2014-11-17T15:04:34.240", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "84", "parent_id": "165", "post_type": "answer", "score": 2 }, { "body": "[Python-\nmarkdown](http://pythonhosted.org/Markdown/)と[Pygments](http://pygments.org/)の組み合わせであれば、こんな感じでしょうか。\n\n```\n\n $ python -m markdown -x cod hoge.md > hoge.html\n $ pygmentize -S default -f html > code.css\n \n```\n\nあとは`hoge.html`に`<link rel=\"stylesheet\" href=\"./code.css\" type=\"text/css\"\nmedia=\"all\" />`を入れれば、カラーで表示されるようになると思います。\n\nまあPygmentsに拘らなければGripか[Pandoc](http://johnmacfarlane.net/pandoc/)の方がラクな気がしますが…。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T07:09:28.000", "id": "242", "last_activity_date": "2014-12-02T07:36:56.407", "last_edit_date": "2014-12-02T07:36:56.407", "last_editor_user_id": "440", "owner_user_id": "521", "parent_id": "165", "post_type": "answer", "score": 1 } ]
165
173
173
{ "accepted_answer_id": "168", "answer_count": 1, "body": "LinearLayoutを使ったAndroidアプリを作るため、Blank\nActivityから作成したプロジェクトでデフォルトに設定されているRelativeLayoutを削除しようとしたところ、なぜか削除出来ませんでした。 \n \n \nなお、Android Studio (Beta)\n0.8.9では削除出来ていたのですが、0.8.14にバージョンアップしたら出来なくなりました(開発環境はOS X 10.10)。 \n \n \n手作業でactivity_main.xmlを編集してLinearLayoutへの変更は出来ましたが、GUIから削除出来ない原因がわかる方がいれば教えて下さい。よろしくお願いします。 \n \n \n![画像の説明をここに入力](https://i.stack.imgur.com/aLIV4.png) \n![画像の説明をここに入力](https://i.stack.imgur.com/0a4PC.png)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-16T14:46:50.043", "favorite_count": 0, "id": "166", "last_activity_date": "2014-11-17T13:33:57.967", "last_edit_date": "2014-11-17T13:33:57.967", "last_editor_user_id": "30", "owner_user_id": "33", "post_type": "question", "score": 5, "tags": [ "android", "android-studio" ], "title": "Android StudioでRelativeLayoutの削除ができない", "view_count": 2778 }
[ { "body": "バグ修正の一環として、レイアウトエディタからは[トップにあるViewGroupを削除できなくなった](https://code.google.com/p/android/issues/detail?id=76942#c2)ようです\n(バージョン0.8.13から)。この修正方法を採用した理由として、トップのViewGroupを削除するとビューツリーが不正な状態になるから、というのが挙げられています。\n\nトップのViewGroupの種類を変更したい場合は「Morphing」メニューを利用せよ、とのことですが、すべての*Layout同士を相互に変換できるわけではないようです。(変換可能なクラスは[views-\nmeta-\nmodel.xml](https://android.googlesource.com/platform/tools/adt/idea/+/master/android/src/com/intellij/android/designer/model/views-\nmeta-model.xml#1370)で定義されている)。\n\nメモ: この変更を見つけた手順:\n\n```\n\n git clone https://android.googlesource.com/platform/tools/adt/idea android-platform-tools-adt-idea\n cd android-platform-tools-adt-idea\n git log --grep layout # 上から順に関係ありそうなログを目視で探した\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-17T06:51:00.543", "id": "168", "last_activity_date": "2014-11-17T06:51:00.543", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "166", "post_type": "answer", "score": 10 } ]
166
168
168
{ "accepted_answer_id": "332", "answer_count": 4, "body": "テキストファイルをエクセルにインポートする時、最初のセルに「�ソ」の文字化けがでてきます。\n\nテキストファイルの例文(Mac OSXのTextEditで見た場合):\n\n```\n\n 0dd6b4f419f3489a580846fb4ebe831b|one: [$numVotes$ more votes needed]\n 0dd6b4f419f3489a580846fb4ebe831b|other: [$numVotes$ more votes needed]\n 89e050644a71fbf8170e280f59fb8940: An error occurred during submission\n a4c510816f6c806507bb528c240ed9a9: [closed]\n 2de9c2314772731359c387be3656bc19: Are you sure you want to award your bounty to this answer? THIS CANNOT BE UNDONE!\n \n```\n\n複数のテキストファイルで同じ文字が現れてきます。手で治すには時間がかかりますので、自動的に方法がありますか?", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-17T06:48:55.830", "favorite_count": 0, "id": "167", "last_activity_date": "2014-12-16T05:56:22.837", "last_edit_date": "2014-11-20T04:39:31.293", "last_editor_user_id": "10", "owner_user_id": "10", "post_type": "question", "score": 4, "tags": [ "テキストファイル", "sed" ], "title": "テキストファイルの最初4文字の文字化け", "view_count": 3179 }
[ { "body": "各行が「�ソ」+「ascii文字列」というパターンであることが確定しているなら、「行の先頭からascii文字列以外を削除する」というパターンで除去することができます:\n\n```\n\n $ sed -i.bak 's/^[^[:alnum:]]*//' weird_*.txt\n \n```\n\nテスト:\n\n```\n\n $ echo -n -e \"\\xef\\xbf\\xbd\\xef\\xbd\\xbf0dd\" | sed '1 s/^[^[:alnum:]]*//' | hexdump -C\n 00000000 30 64 64 0a |0dd.|\n 00000004\n # 一文字増えているのは、sedが改行文字を最後に付加しているせい\n \n```\n\n文字化けしているバイト列をピンポイントで除去したい場合、Mac OS X の場合 gsed (GNU sed) でできます。バイト列をまず確認し:\n\n```\n\n $ echo -n -e \"\\xef\\xbf\\xbd\\xef\\xbd\\xbf0dd\" > weird.txt # テストファイルを作成\n $ head -n1 weird.txt | hexdump -C # バイト列を確認\n 00000000 ef bf bd ef bd bf 30 64 64 |......0dd|\n 00000009\n \n```\n\n置き換える:\n\n```\n\n # homebrewなどでgsedをインストール\n $ gsed -i.bak 's/^\\xef\\xbf\\xbd\\xef\\xbd\\xbf//' weird.txt\n $ cat weird.txt\n 0dd\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-20T15:10:24.143", "id": "176", "last_activity_date": "2014-11-20T15:10:24.143", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "167", "post_type": "answer", "score": 4 }, { "body": "おそらく、バイトオーダーマーク(BOM)のついたエンコーディングになっているのだとおもいます。バイトオーダーマークについて詳しくは以下を参照してください。\n\n[バイトオーダーマーク -\nWikipedia](http://ja.wikipedia.org/wiki/%E3%83%90%E3%82%A4%E3%83%88%E3%82%AA%E3%83%BC%E3%83%80%E3%83%BC%E3%83%9E%E3%83%BC%E3%82%AF)\n\nUTF-16エンコーディングだと、プラットフォームによってエンディアンの違いが問題となるため、ファイルの先頭にエンディアンを識別するためのデータが追加されることがあります。そのデータのことをバイトオーダーマーク(BOM)といいます。\n\nUTF-8エンコーディングはエンディアンの問題がないため、通常はBOMが付いていません。Mac OS\nXなどで普通に「UTF-8」といえば「BOMなしUTF-8」となります。ただし、Unicodeの仕様としてはUTF-8にもBOMをつけることが許されていてその場合は「0xEF\n0xBB 0xBF」が付加されます。\n\n特に、Windows環境ではUTF-8にもBOMをつける傾向が多いようで、Windowsのメモ帳でUTF-8を選択して保存するとBOM付きUTF-8のファイルになります。\n\n<http://www.php-factory.net/trivia/03.php>\n\n今回の問題はMac版の\nExcelがBOMありのUTF-8に対応していないのが原因だとおもいます。Microsoftの製品なんだから対応して欲しいところですが、仕方ないので\nテキストファイルの方を直すしかありません。\n\nUNIXでの文字エンコーディングの変換は通常 iconv を使うのですが、iconvは BOMありのUTF-8に対応していないという問題があります。\n\n<http://yanok.net/2010/02/iconvutf-8bom.html>\n\nちょっと古いツールですが、昔ながらの nkf を使うとBOMの変更操作も可能です。nkfは homebrew等でインストール可能です。\n\n```\n\n >brew install nkf\n \n```\n\nnkfでBOMを削除するには以下のようにします。\n\n```\n\n >nkf --overwrite --oc=UTF-8 test.txt\n \n```\n\n逆に、BOMを追加する場合は、以下のようにします。\n\n```\n\n >nkf --overwrite --oc=UTF-8-BOM test.txt\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T01:07:50.787", "id": "332", "last_activity_date": "2014-12-04T09:10:43.583", "last_edit_date": "2014-12-04T09:10:43.583", "last_editor_user_id": "832", "owner_user_id": "832", "parent_id": "167", "post_type": "answer", "score": 19 }, { "body": "Excel(Mac)がBOM付きUnicodeに対応していないのが問題だと思います。GUIツールだとCotEditor(Mac)でBOMの除去ができます。\n\n 1. CotEditorでファイルを開く\n 2. メニュー -> フォーマット -> エンコーディング -> Unicode (UTF-16) を選択\n 3. ファイルを保存\n\n![画像の説明をここに入力](https://i.stack.imgur.com/e8s2q.jpg)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T09:48:47.487", "id": "354", "last_activity_date": "2014-12-04T09:48:47.487", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37", "parent_id": "167", "post_type": "answer", "score": 2 }, { "body": "BOM が付いているからというのが正解のようですが、何者かを確認できていたら解決が楽だった可能性があるので、それを調べる方法をどうぞ。\n\n```\n\n $ head -n1 target.txt |od -tcx1\n \n```\n\nこんな風にすると、ファイル先頭部分の文字コードを確認できます。`od`(1) の代わりに `hexdump`(1) などを利用してもいいですね。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T05:56:22.837", "id": "1683", "last_activity_date": "2014-12-16T05:56:22.837", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3061", "parent_id": "167", "post_type": "answer", "score": 1 } ]
167
332
332
{ "accepted_answer_id": "171", "answer_count": 1, "body": "複数のテキストファイルがあります:\n\n例:\n\n```\n\n 0dd6b4f419f3489a580846fb4ebe831b|one: [$numVotes$ more votes needed]\n 0dd6b4f419f3489a580846fb4ebe831b|other: [$numVotes$ more votes needed]\n 89e050644a71fbf8170e280f59fb8940: An error occurred during submission\n a4c510816f6c806507bb528c240ed9a9: [closed]\n 2de9c2314772731359c387be3656bc19: Are you sure you want to award your bounty to this answer? THIS CANNOT BE UNDONE!\n \n```\n\n最初はキーで、複数系が単独系に差がある場合、キーの後に「|one:」か「|other:」がでてきます。単独系・複数系に差がない場合、その部分が抜けていますので、キーの直後に「:」しかないです。\n\nエクセルへインポートしたいため、CSVファイルにしたいです。\n\n```\n\n |one: → ,one,\n |other: → ,other,\n : → ,,\n \n```\n\n「:」の後にも「:」がでてくる可能性があるため、最初の「:」だけに適用したいです。\n\n*NIXの「`sed`」を利用できるはずですが、どのように使えばできますか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-17T06:58:35.770", "favorite_count": 0, "id": "169", "last_activity_date": "2014-12-02T10:05:31.783", "last_edit_date": "2014-12-02T10:05:31.783", "last_editor_user_id": "30", "owner_user_id": "10", "post_type": "question", "score": 3, "tags": [ "テキストファイル", "sed", "csv" ], "title": "複数のテキストファイルであるパターンを変換", "view_count": 173 }
[ { "body": "foo.txtからfoo.csvへ変換するのであれば、 このように使ってみてはいかがでしょうか。\n\n```\n\n cat foo.txt | sed -e \"s/|\\(one\\|other\\):\\|:/,\\1,/\" > foo.csv\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-17T10:50:42.013", "id": "171", "last_activity_date": "2014-11-17T10:50:42.013", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "70", "parent_id": "169", "post_type": "answer", "score": 2 } ]
169
171
171
{ "accepted_answer_id": "172", "answer_count": 2, "body": "python34 パッケージがインストールされているらしいのですが、どこにバイナリがあるのか分かりません。\n\n`yum help` でコマンドの一覧を見てもそれらしいコマンドはなく、 `yum info python34 -v`\nでパッケージ情報を見ても、ファイル一覧までは出てきません。\n\nどうすれば yumでインストールしたパッケージに含まれるファイルの一覧を出せるでしょうか。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2014-11-17T07:38:03.727", "favorite_count": 0, "id": "170", "last_activity_date": "2020-08-09T00:46:53.387", "last_edit_date": "2020-08-09T00:46:53.387", "last_editor_user_id": "5793", "owner_user_id": "30", "post_type": "question", "score": 9, "tags": [ "linux", "yum" ], "title": "yumでインストールしたパッケージに含まれるファイルの一覧を表示するには?", "view_count": 17907 }
[ { "body": "repoquery コマンドはどうでしょうか?\n\n```\n\n sudo yum install yum-utils\n repoquery --list python34\n \n```\n\n[yumでインストールされたファイル一覧を表示する方法 repoquery\n--list](http://kaworu.jpn.org/kaworu/2012-05-01-1.php)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2014-11-17T14:52:55.483", "id": "172", "last_activity_date": "2020-08-08T12:29:54.210", "last_edit_date": "2020-08-08T12:29:54.210", "last_editor_user_id": "3060", "owner_user_id": "33", "parent_id": "170", "post_type": "answer", "score": 14 }, { "body": "インストール済みのパッケージであれば、rpmコマンドも使えます:\n\n```\n\n rpm -ql python34\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-19T00:24:01.057", "id": "175", "last_activity_date": "2014-11-19T00:24:01.057", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "170", "post_type": "answer", "score": 9 } ]
170
172
172
{ "accepted_answer_id": "177", "answer_count": 1, "body": "現在、以下の3つのマシンを立てて使っています。\n\n```\n\n $ find . -maxdepth 4\n .\n ./master\n ./master/.vagrant\n ./master/.vagrant/machines\n ./master/.vagrant/machines/default\n ./master/Vagrantfile\n ./slave\n ./slave/.vagrant\n ./slave/.vagrant/machines\n ./slave/.vagrant/machines/default\n ./slave/Vagrantfile\n ./staging\n ./staging/.vagrant\n ./staging/.vagrant/machines\n ./staging/.vagrant/machines/default\n ./staging/Vagrantfile\n \n```\n\nこれを以下のようにmulti-machine構成の単一のVagrantfileで定義するようにしたいと考えています。\n\n```\n\n Vagrant.configure(\"2\") do |config|\n config.vm.define \"master\" do |master|\n end\n \n config.vm.define \"slave\" do |slave|\n end\n \n config.vm.define \"staging\" do |staging|\n end\n end\n \n```\n\n見たところ、以下の作業で何事もなかったようにvagrant upできそうですが、これで必要十分でしょうか。\n\n 1. {machine}/.vagrant/machines/default ディレクトリを ./vagrant/machines/{machine} に移動する\n\n```\n\n ./.vagrant/machines/master # ./master/.vagrant/machines/default\n ./.vagrant/machines/slave # ./slave/.vagrant/machines/default\n ./.vagrant/machines/staging # ./staging/.vagrant/machines/default\n \n```\n\n 2. path/to/machine/virtualbox/synced_folders ファイルにある絶対パスを書き換える\n\n```\n\n {\"virtualbox\":\n {\"/vagrant\":\n {\"guestpath\":\"/vagrant\",\n \"hostpath\":\"/path/to/root\",\n \"disabled\":false}}}\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-18T09:41:39.907", "favorite_count": 0, "id": "174", "last_activity_date": "2014-11-20T15:15:13.877", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "post_type": "question", "score": 4, "tags": [ "vagrant" ], "title": "別々のVagrantfileで定義して運用していたマシンをmulti-machine構成に集約したい", "view_count": 167 }
[ { "body": "結局、1.のディレクトリ移動だけで済みました。(Vagrantfileの`synced_folder`で設定しているパスの調整はしましたが。)\n`virtualbox/synced_folders` ファイルは起動時にVagrantが自動生成するので、ノータッチでよいようです。\n\n 1. `vagrant halt`\n 2. ディレクトリ移動\n 3. Vagrantfileをマージ\n 4. `vagrant up`", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-20T15:15:13.877", "id": "177", "last_activity_date": "2014-11-20T15:15:13.877", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "174", "post_type": "answer", "score": 2 } ]
174
177
177
{ "accepted_answer_id": "182", "answer_count": 1, "body": "Tungsten ReplicatorのJavaScriptフィルタで、[OneRowChange](http://tungsten-\nreplicator.googlecode.com/svn/trunk/replicator/src/java/com/continuent/tungsten/replicator/dbms/OneRowChange.java)クラスの内部クラス、ColumnSpecをnewしようとしています。\n\nColumnSpecクラスはスタティックではないので、Javaなら `oneRowChange.new ColumnSpec()`\nとするところですが、これをRhino経由でJavaScriptで記述するにはどうすればよいでしょうか。\n\n今まで以下を試してみましたが、エラーになるばかりです。\n\n```\n\n $ cat Outer.java\n public class Outer {\n public class Inner {\n public Inner() {\n }\n }\n }\n $ javac Outer.java\n $ java -cp /usr/local/Cellar/rhino/1.7R4/libexec/js.jar:. org.mozilla.javascript.tools.shell.Main\n Rhino 1.7 release 4 2012 06 18\n js> o = new Packages.Outer()\n Outer@12413ffc\n js> new o.Inner()\n js: uncaught JavaScript runtime exception: TypeError: org.mozilla.javascript.Undefined@675dd521 is not a function, it is undefined.\n \n js> new Packages.Outer.Inner()\n js: Java constructor for \"Outer$Inner\" with arguments \"\" not found.\n \n js> o.new Inner()\n js: \"<stdin>\", line 4: missing ; before statement\n js: o.new Inner()\n js: ...........^\n js: \"<stdin>\", line 4: Compilation produced 1 syntax errors.\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-21T16:30:02.623", "favorite_count": 0, "id": "178", "last_activity_date": "2014-11-25T04:27:16.390", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "post_type": "question", "score": 5, "tags": [ "javascript", "tungsten-replicator", "java" ], "title": "Rhinoで内部クラスをnewしたい", "view_count": 386 }
[ { "body": "これで通らないでしょうか。\n\n```\n\n js> o = new Packages.Outer()\n Outer@1b7071b8\n js> new Packages.Outer.Inner(o)\n Outer$Inner@3996a317\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T04:27:16.390", "id": "182", "last_activity_date": "2014-11-25T04:27:16.390", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "70", "parent_id": "178", "post_type": "answer", "score": 3 } ]
178
182
182
{ "accepted_answer_id": null, "answer_count": 5, "body": "普段、Rubyを使い慣れているのでJavaScriptで配列やハッシュ、文字列等を操作するときに、「RubyでいうあのメソッドはJavaScriptにあるのかな?」と探す\nor 実装するのが面倒です。\n\nというわけでベーシックなオブジェクトをRubyっぽく操作できるJSライブラリがあれば教えてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-24T19:40:02.863", "favorite_count": 0, "id": "179", "last_activity_date": "2014-12-16T02:27:44.580", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "post_type": "question", "score": 5, "tags": [ "javascript", "ruby" ], "title": "RubyっぽいAPIを提供してくれるJavaScriptのライブラリはありませんか?", "view_count": 810 }
[ { "body": "Opalという、RubyコードをJavascriptに変換するサイト/ライブラリがあります。\n\n<http://opalrb.org>\n\n主要なRuby関数はライブラリになっていますので、こちらで変換して確認できるかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T01:23:22.830", "id": "180", "last_activity_date": "2014-11-25T01:23:22.830", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "63", "parent_id": "179", "post_type": "answer", "score": 4 }, { "body": "[RubyJS](http://rubyjs.org/) という Ruby の API を模した JS ライブラリがあります。\n\n以下のように `R` で包まなければいけないようです。\n\n```\n\n R(1.2345).round(2) + 1\n // => 2.23\n \n```\n\n参考:<http://rubyjs.org/blog/2012/12/rubyjs-the-post-launch-launch-post/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T01:08:29.023", "id": "211", "last_activity_date": "2014-12-02T01:08:29.023", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "206", "parent_id": "179", "post_type": "answer", "score": 2 }, { "body": "RubyっぽいAPIがmodule\nEnumerableのことを指しているなら[Underscore](http://underscorejs.org/)や、その[文字列拡張ライブラリ](https://github.com/epeli/underscore.string)がメジャーだと思います。functional\nprogramming library for javascriptで検索すると上位に表示されるので。\n\n```\n\n var stooges = [{name: 'curly', age: 25}, {name: 'moe', age: 21}, {name: 'larry', age: 23}];\n var youngest = _.chain(stooges)\n .sortBy(function(stooge){ return stooge.age; })\n .map(function(stooge){ return stooge.name + ' is ' + stooge.age; })\n .first()\n .value();\n => \"moe is 21\"\n \n _.mixin(_.str.exports()); // underscore と統合\n _(' capitalize dash-CamelCase_underscore trim ').humanize()\n => 'Capitalize dash camel case underscore trim'\n ['foo20', 'foo5'].sort(_.naturalCmp)\n => [ 'foo5', 'foo20' ]\n \n```\n\n[fn.js](http://eliperelman.com/fn.js/)はカリー化もできます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T14:54:06.587", "id": "269", "last_activity_date": "2014-12-02T14:54:06.587", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "699", "parent_id": "179", "post_type": "answer", "score": 4 }, { "body": "Tetsuwo OISHIさんも書かれているように、RubyJSというライブラリがあります。\n現在のバージョンは0.8.0-beta1という新しいものです。まだ知名度は低いかもしれませんが、Rubyライクなコーディングが好きな方にはよいかもしれません。\n\n**RubyJS** <http://rubyjs.org/>\n\nドキュメントによると2つの使い方があるようです。\n\n> * RubyJS (Lite) - Functional\n> * RubyJS Classic - Object Oriented\n>\n\n先ずRubyJS (Lite)のほうは、Underscore.jsに似た関数スタイルで実装されているようです。\n\n```\n\n String 関連の関数は、グローバルオブジェクトの '_s' に、\n Array 関連の関数は、グローバルオブジェクトの '_a' に、\n Time 関連の関数は、グローバルオブジェクトの '_t' に、...\n \n```\n\nという具合です。\n\n一方、RubyJS Classic\nの方は、Lite版の機能を'`R`'という名前のラッパーオブジェクトを使って実装しているようです。こちらの関数は、戻り値としてラッパーオブジェクト自身を返すようになっていて、メソッドチェーンを組むことができます。\n\n```\n\n R(\"foo\"); // => {R.String: \"foo\"}\n R(\"foo\").capitalize(); // => {R.String: \"Foo\"}\n R(\"foo\").capitalize().ljust(7, '-'); // => {R.String: \"--Foo--\"}\n \n```\n\n* * *\n\n# JavaScript / Underscore.js / RubyJS の比較\n\nRubyJSの[ドキュメントページ](http://rubyjs.org/reloaded/#overview-\nbenefitsForJsDevelopers)に、純粋なJSとUnderscore.jsと書き方を比較するコードが載っています。その中から2つの部分を選んで以下に補足します。\n\n## 比較1. 配列中の文字列を数値に変換\n\n>\n```\n\n> // JS\n> ['10', '10', '10'].map(parseInt) // => [10, NaN, 2]\n> // underscore\n> _.map(['10', '10', '10'], parseInt) // => [10, NaN, 2]\n> // RubyJS\n> _a.map(['10', '10', '10'], parseInt) // => [10, 10, 10]\n> \n```\n\nこのコードが言わんとしていることは、「JSやunderscoreでは配列中の文字列をまとめてparseIntできないけど、RubyJSなら簡単です。」ということだと思います。確かにそうですが、このままだとJSとunderscoreが言われっ放しで少しかわいそうな気もするので以下に補足してみます。\n\n**純粋なJavascriptの場合**\n\nJavascriptの`Array.map()` を使ってparseIntするときに、以下のように書くと予想外の結果になります。\n\n```\n\n ['10', '10', '10'].map(parseInt); // => [10, NaN, 2]\n \n```\n\nこれは、`parseInt()`関数の引数が1つではないことに起因しています。\n\n>\n```\n\n> var intValue = parseInt(string[, radix]); //第2引数は基数(10進の場合は10)\n> \n```\n\n>\n> [Mozilla Developper\n> Network](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/parseInt)より引用\n\n対処方法はいくつかありますが、そのひとつは`bind()`関数を使うものです。`bind()`の第2引数に基数10(10進数)を指定することができます。\n\n```\n\n ['10', '10', '10'].map(parseInt.bind(null, 10));// => [10, 10, 10]\n \n```\n\nあるいはもっとシンプルに、`parseInt()`の代わりに`Number()`を使う方法もあります。JavaScriptの`Number()`はラッパーオブジェクトですが、`new`演算子をつけないで呼び出すと型変換関数として動作します。\n\n```\n\n ['10', '10', '10'].map(Number); // => [10, 10, 10]\n \n```\n\nこれならばシンプルですし、RubyJSと比べても見劣りしないと思います。\n\n**Underscore.jsの場合**\n\nUnderscoreでは、デフォルトで`_`(アンダースコア)という名前のグローバルオブジェクトが定義されています。その`_`に実装されているmap関数を使って、配列にコールバック関数を関連付けます。上で述べたJSの場合と同様に、以下のどちらかの方法で数値化できます。\n\n```\n\n _.map(['10', '10', '10'],parseInt.bind(null, 10));  // => [10, 10, 10]\n _.map(['10', '10', '10'],Number);  // => [10, 10, 10]\n \n```\n\n**RubyJSの場合**\n\nRubyJSでは、`_a`という名前のグローバルオブジェクトに配列関連のメソッドが定義されています。 以下のどちらの書き方もできます。\n\n```\n\n _a.map(['10', '10', '10'], parseInt); // => [10, 10, 10]\n _a.map(['10', '10', '10'], Number); // => [10, 10, 10]\n \n```\n\n確かにシンプルにコーディングできます。\n\n* * *\n\n## 比較2. 配列のソート\n\nもうひとつの比較を見てみます。ここでは、配列を`sort()`するコードが載っています。\n\n>\n```\n\n> // JS\n> [1, 8, 15].sort() // => [1, 15, 8]\n> // underscore\n> _.sortBy([1, 8, 15]) // => [1, 15, 8]\n> // RubyJS\n> _a.sort([1, 8, 15]) // => [1, 8, 15]\n> \n```\n\nこのコードが言わんとしていることは、「JSやunderscoreでは配列中の文字列を単純にソートきないけど、RubyJSなら簡単だよ」ということだと思います。更に解りやすくするために、数値を書き換えて以下のようにして考えます。\n\n```\n\n // JS\n [33,4,1111,222].sort() // => [1111,222,33,4]\n // underscore\n _.sortBy([33,4,1111,222]) // => [1111,222,33,4]\n // RubyJS\n _a.sort([33,4,1111,222]) // => [4, 33, 222, 1111]\n \n```\n\n**純粋なJavascriptの場合**\n\nJavascriptの`Array.sort()` を使って以下のようにすると、アルファベット順にソートされた結果が返ります。\n\n```\n\n [33,4,1111,222].sort(); // => [1111,222,33,4]\n \n```\n\nアルファベットではなく数値として比較したい場合には、以下のように書けます。\n\n```\n\n [33,4,1111,222].sort(function(a,b){ return a - b;})); // => [4, 33, 222, 1111]\n \n```\n\n**Underscore.jsの場合**\n\nUnderscoreでは、`sortBy()`を使って以下のようにできます。\n\n```\n\n _.sortBy([33,4,1111,222], function(num){ return num; });// => [4, 33, 222, 1111]\n \n```\n\n**RubyJSの場合**\n\n```\n\n _a.sort([33,4,1111,222])// => [4, 33, 222, 1111]\n \n```\n\n確かにシンプルです。\n\n以上です。Rubyライクなコーディングが好きな方にはよいかもしれません。\n\n上述のコードを[JSFiddle](http://jsfiddle.net/naokiota/24ceLxv7/1/)に置きました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T08:18:56.913", "id": "366", "last_activity_date": "2014-12-11T05:19:59.957", "last_edit_date": "2014-12-11T05:19:59.957", "last_editor_user_id": "47", "owner_user_id": "47", "parent_id": "179", "post_type": "answer", "score": 7 }, { "body": "プロトタイプ拡張を許すならRuby風にネイティブオブジェクトを拡張するsugar.jsが便利でした。作者がrubyistなのでだいたいのrubyのメソッドは定義されています。詳しくは以下のドキュメントにて。\n\n[Sugar: A Javascript library for working with native\nobjects.](http://sugarjs.com/ \"Sugar: A Javascript library for working with\nnative objects.\")\n\nプロトタイプ拡張を許さない環境なら underscore.js や lodash.js を使うでしょう。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T02:27:44.580", "id": "1634", "last_activity_date": "2014-12-16T02:27:44.580", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2674", "parent_id": "179", "post_type": "answer", "score": 2 } ]
179
null
366
{ "accepted_answer_id": "183", "answer_count": 1, "body": "数時間かかると予想されるスクリプトをbashから起動しました。これを、ログインセッションが切れても一緒に落ちてしまわないように切り離したいです。\n\n```\n\n $ python insanely_long.py\n \n```\n\nたまたまこのマシンにはscreenも入っていないので、これまではnohupでやっていたのですが今回は忘れてしまいました。どうすればよいでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T04:08:49.010", "favorite_count": 0, "id": "181", "last_activity_date": "2014-11-25T06:55:02.383", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "post_type": "question", "score": 20, "tags": [ "bash" ], "title": "既に実行を開始したプロセスをシェルから切り離すには?", "view_count": 1454 }
[ { "body": "bash/zshでは、disown を利用します。\n\n```\n\n $ perl -e 'sleep 10000'\n ^Z\n [1]+ Stopped perl -e 'sleep 10000'\n $ jobs\n [1]+ Stopped perl -e 'sleep 10000'\n $ bg %1\n [1]+ perl -e 'sleep 10000' &\n $ jobs\n [1]+ Running perl -e 'sleep 10000' &\n $ disown %1\n $ jobs\n $ exit\n exit\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T06:55:02.383", "id": "183", "last_activity_date": "2014-11-25T06:55:02.383", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "76", "parent_id": "181", "post_type": "answer", "score": 38 } ]
181
183
183
{ "accepted_answer_id": "205", "answer_count": 3, "body": "Objective-Cでは以下のように、複数のプロトコルを実装した具体的な型で変数宣言やプロパティ定義など出来ますが、\n\n```\n\n UIView<FooProtocol, BarProtocol>* myView = ...\n \n```\n\nSwiftでは同様の書き方ありませんか?", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T07:08:55.180", "favorite_count": 0, "id": "184", "last_activity_date": "2015-12-30T03:24:02.227", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "55", "post_type": "question", "score": 8, "tags": [ "swift", "objective-c" ], "title": "SwiftでUIView<FooProtocol, BarProtocol>相当の宣言て出来ますか?", "view_count": 962 }
[ { "body": "直接Objective-\nCと同じことはできませんが、型拡張で同じ事はできると思います。型Tがprotocolに適合していればそれはグローバルな状態だとおもうので、これでいいんじゃないでしょうか。\n\n```\n\n protocol FooProtocol {\n var foo: String { get }\n }\n protocol BarProtocol {\n var bar: String { get }\n }\n \n extension UIView: FooProtocol, BarProtocol {\n var foo: String { return \"foo\" }\n var bar: String { return \"bar\" }\n }\n \n let a = UIView()\n a.foo // \"foo\"\n a.bar // \"bar\"\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T00:18:45.480", "id": "205", "last_activity_date": "2014-12-02T00:18:45.480", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "114", "parent_id": "184", "post_type": "answer", "score": 4 }, { "body": "似てますが、以下の方法もありますね。\n\n```\n\n protocol FooProtocol {\n var foo: String { get }\n }\n protocol BarProtocol {\n var bar: String { get }\n }\n \n class CompositeProtocolUIView: UIView, FooProtocol, BarProtocol {\n var foo: String { return \"foo\" }\n var bar: String { return \"bar\" }\n }\n \n let a = CompositeDelegateUIView()\n a.foo // \"foo\"\n a.bar // \"bar\"\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T02:11:26.253", "id": "219", "last_activity_date": "2014-12-02T02:22:00.673", "last_edit_date": "2014-12-02T02:22:00.673", "last_editor_user_id": "55", "owner_user_id": "55", "parent_id": "184", "post_type": "answer", "score": 3 }, { "body": "Genericsを使うことで具体的かつ必要最低限の制約で書くことができます。\n\n```\n\n class MyClass <T:UIView where T:FooProtocol, T:BarProtocol> {\n var fbView:T?\n }\n \n```\n\nちなみに\n\n```\n\n class FooBarButton : UIButton, FooProtocol, BarProtocol {}\n \n```\n\n型を決め打ちするやり方だと今回は UIButton,Foo,Bar → UIView,Foo,Bar\nのキャストをさせてもらえず渡すことができない一方、Genericsなら上のようなクラスもプロパティに代入できます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-19T18:25:55.877", "id": "2171", "last_activity_date": "2014-12-19T18:25:55.877", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5290", "parent_id": "184", "post_type": "answer", "score": 2 } ]
184
205
205
{ "accepted_answer_id": "197", "answer_count": 4, "body": "組込み環境でC言語で開発しています。C言語の規約上、ヌルポインタを代入したい場合\n\n```\n\n int *nullp = 0;\n \n```\n\nと書かなければいけませんが、 私の環境では 0番地に NOR がマッピングされています。(上のコードはコンパイルすると物理的には\n0番地ではなく、0x3FFFFFFFのような番地が代入されます)\n\n0番地にアクセスする(0番地へのポインタを代入する)にはどうすれば良いでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T12:04:07.320", "favorite_count": 0, "id": "185", "last_activity_date": "2017-07-24T12:41:10.450", "last_edit_date": "2014-11-26T03:52:25.063", "last_editor_user_id": "79", "owner_user_id": "79", "post_type": "question", "score": 12, "tags": [ "c", "ポインタ" ], "title": "0番地ポインタの設定方法", "view_count": 2266 }
[ { "body": "コンパイラが割り当てているということでしたら、 stddef.hをインクルードしてNULLを使えば適切なヌルポインタが入ってくれないでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T01:05:43.543", "id": "191", "last_activity_date": "2014-11-26T01:05:43.543", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "70", "parent_id": "185", "post_type": "answer", "score": 1 }, { "body": "そのコンパイラが ANSI (ISO/JIS) C に準拠しているという前提であれば、ポインタの文脈で 0\nを与えると必ずナルポインタを得ることが出来ます。(キャストしていないので、警告は出るかもしれませんが。)\n\nですので、そのコンパイラは 0x3FFFFFFF をナルポインタとして利用する珍しいコンパイラなのだと思います。(値が 0x3FFFFFFF\nであったとしても、nullp == 0 は真になりますし、nullp 自体は偽と見なされます。)\n\nただし、組み込み用のコンパイラは ANSI C に準拠していないことも多いようなので、正確なところはドキュメントを参照するのが良いかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T02:15:13.790", "id": "192", "last_activity_date": "2014-11-26T02:15:13.790", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "76", "parent_id": "185", "post_type": "answer", "score": 5 }, { "body": "いろいろ調べてコーディングが一番シンプルなのは\n\n```\n\n uintptr_t address = 0;\n int *p = (int *) address;\n \n```\n\nでした([Could I ever want to access the address\nzero?](https://stackoverflow.com/questions/2761360/could-i-ever-want-to-\naccess-the-address-zero))。\n\nただコード上わかりにくい気はします。コメントを書いておく位しかないかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T05:26:09.490", "id": "197", "last_activity_date": "2014-11-26T05:26:09.490", "last_edit_date": "2017-05-23T12:38:56.467", "last_editor_user_id": "-1", "owner_user_id": "79", "parent_id": "185", "post_type": "answer", "score": 15 }, { "body": "unionを使うとか。\n\n```\n\n union {\n int *nullp;\n int i;\n } hoge;\n hoge.i = 0;\n \n```\n\nただし、`sizeof(int) == sizeof(int *)`を仮定している悪いコードです。\n\nあるいはmemsetをつかうとか。\n\n```\n\n int *nullp;\n memset((void *)&nullp, 0, sizeof(nullp));\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-17T13:40:47.347", "id": "1930", "last_activity_date": "2014-12-17T13:40:47.347", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3413", "parent_id": "185", "post_type": "answer", "score": 4 } ]
185
197
197
{ "accepted_answer_id": null, "answer_count": 2, "body": "今後はSwiftでiOSアプリケーションを開発していきたいのですが、今まで作成したObjective-\nCのソースコードも活用していきたいと思っています。Objective-\nCのソースコードをSwiftプロジェクトに取り込んで使用するにはどのように設定したらよいでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T12:33:46.070", "favorite_count": 0, "id": "186", "last_activity_date": "2014-12-02T00:25:39.593", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37", "post_type": "question", "score": 7, "tags": [ "xcode", "swift", "objective-c" ], "title": "SwiftプロジェクトでObjective-Cソースファイルを使う方法", "view_count": 1580 }
[ { "body": "まず、`Objective-C` と `Swift` の間を橋渡しする Bridging Header ファイルを作成する必要があります。\n\n[XCode 6.1\n日本語化計画目次](http://www.xcode601.com/Swift/Swift1.0.0/SwFObjC/SwiBaSe7.html#SwiBaSe1005IOCS02)が詳しいです。\n\n他にも相互運用の際の注意点などがまとまっていて、オススメです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-01T06:55:05.977", "id": "204", "last_activity_date": "2014-12-01T06:55:05.977", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "41", "parent_id": "186", "post_type": "answer", "score": 2 }, { "body": "<プロダクト名>-Bridging-Header.hを作成して、SwiftからObjective-Cのクラスを参照できるようにする必要があります。\n\n以下に新規SwiftプロジェクトでObjective-Cのクラスを使うまでの手順を記載します。\n\n 1. 新規Swiftプロジェクトを作成\n 2. Objective-Cで任意のクラスを作成\n``` #import <Foundation/Foundation.h>\n\n \n @interface ObjcClass : NSObject\n -(void)log;\n @end\n @implementation ObjcClass\n -(void)log{\n NSLog(@\"Objc Class Log\") ;\n }\n @end\n \n```\n\n 3. Bridging-Header.hを作成するか聞かれるのでYESを選択\n\n 4. Swiftから使用したいObjective-Cのクラスを-Bridging-Header.hにインポート\n``` #import \"ObjcClass.h\"\n\n \n```\n\n 5. swiftファイルからObjective-Cのクラスを使用するコードを記述\n``` func application(application: UIApplication,\ndidFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {\n\n var objcClass = ObjcClass()\n objcClass.log()\n // Override point for customization after application launch.\n return true\n }\n \n```\n\n[サンプルプロジェクト](https://github.com/sekitaka/SwiftInObjcProj)も載せておきますね。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T00:25:39.593", "id": "207", "last_activity_date": "2014-12-02T00:25:39.593", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "131", "parent_id": "186", "post_type": "answer", "score": 5 } ]
186
null
207
{ "accepted_answer_id": null, "answer_count": 1, "body": "SwiftプロジェクトでCocoaPodsでインストールしたAFNetworkなどを使用したいのですが設定方法を教えてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T12:50:01.790", "favorite_count": 0, "id": "187", "last_activity_date": "2014-12-02T00:58:51.967", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37", "post_type": "question", "score": 8, "tags": [ "xcode", "swift", "cocoapods" ], "title": "SwiftでCocoaPodsを使う方法", "view_count": 444 }
[ { "body": "1. プロジェクトに[ProductName]-Bridging-Header.h というファイルを追加します。\n 2. Build SettingsでObjective-C Bridging Headerにそのファイルパス(たとえばMyProduct/MyProduct-Bridging-Header.h)を設定します。\n 3. そのファイルにAFNetworkingであれば#import \"AFNetworking.h\"と記述することでSwiftでAFNetworkingを利用できるようになります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T00:58:51.967", "id": "210", "last_activity_date": "2014-12-02T00:58:51.967", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "238", "parent_id": "187", "post_type": "answer", "score": 9 } ]
187
null
210
{ "accepted_answer_id": "358", "answer_count": 6, "body": "Ruby on Rails\nで書いたサーバソフトウエアのパッケージがあり、それを用いてチュートリアルをしようとしています。そのために、「Windowsで簡単な設定でRuby on\nRailsをdevelopment実行環境で動かす」ことが必要になっています。\n\n対象者は、コマンドプロンプトでコマンド打ち込むぐらいは出来る人が、sshは知らないかもしれない、ぐらいのスキルのユーザを想定しています。\n\nたとえば、インストーラで一通り開発環境を設定できるようなパッケージがあると思うのですが、WindowsでのRuby開発環境に疎いので、適切な解を見付けられていません。\n\n教えてください。\n\n蛇足ですが、最終的にはHerokuで実験できるようにすることも考えているのですが、恐らく、外のサービスでアカウント作るよりは、手元で動かす方がハードルが低いのではないかと考えています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T21:46:13.960", "favorite_count": 0, "id": "188", "last_activity_date": "2014-12-18T04:29:19.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "44", "post_type": "question", "score": 7, "tags": [ "ruby", "windows", "ruby-on-rails" ], "title": "WindowsでのRuby実験環境構築パッケージについて", "view_count": 972 }
[ { "body": "<http://rubyinstaller.org/>\n\nこれとかいかがでしょう?\n\nVirtualBoxとVagrantが使えるなら\n\n[rails-dev-box - VagrantでRails開発環境を作るならこれ!\nMOONGIFT](http://www.moongift.jp/2014/11/rails-dev-box-\nvagrant%E3%81%A7rails%E9%96%8B%E7%99%BA%E7%92%B0%E5%A2%83%E3%82%92%E4%BD%9C%E3%82%8B%E3%81%AA%E3%82%89%E3%81%93%E3%82%8C%EF%BC%81/)\n\nもあります。こっちのがサーバ環境には近いので外部にホストした際の環境差異は小さいのではないかと。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T00:28:08.660", "id": "208", "last_activity_date": "2014-12-02T00:28:08.660", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "139", "parent_id": "188", "post_type": "answer", "score": 4 }, { "body": "スキルセットを考慮すると\n\n<http://rubyinstaller.org>\n\nをつかってそのままWindowsで環境を構築するのが良さそうに思えます\n\nRailsを動作させるのに必要なgemには、バージョンによってはNative\nextensionを使用するものもあると思うので、devkitもいれる必要があるかもしれません\n\n同一のネットワークに接続できるのであれば↑のRuby環境を共有フォルダに構築して、それぞれの開発端末からはPATH変数などを設定するバッチファイルのみを配布するのありだと思います", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T01:11:53.750", "id": "212", "last_activity_date": "2014-12-02T01:11:53.750", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "265", "parent_id": "188", "post_type": "answer", "score": 3 }, { "body": "小さなツールや使用するgemの依存が少ないならほぼ問題無いのですが、使用するgemにC言語による拡張が含まれる場合は途端にハードルが高くなります。rubyinstaller\nである程度はビルド出来るのですが windows に対応していない gem も多数存在しますし、なかなかのいばらの道です。\n予め大きい依存になる事が想定されるのであれば、vagrant 上で環境を構築し、もしコードの変更がある場合は vagrant の共有フォルダを\nwindows 側から触って貰うのが良いかと思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T03:04:48.453", "id": "225", "last_activity_date": "2014-12-02T03:34:20.903", "last_edit_date": "2014-12-02T03:34:20.903", "last_editor_user_id": "440", "owner_user_id": "440", "parent_id": "188", "post_type": "answer", "score": 8 }, { "body": "<https://www.nitrous.io/> のように、オンライン上でコーディングして実行できる環境を使うとよいかもしれません。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T07:41:59.030", "id": "243", "last_activity_date": "2014-12-02T07:41:59.030", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "205", "parent_id": "188", "post_type": "answer", "score": 3 }, { "body": "その名も [RailsInstaller](http://railsinstaller.org/) というものがあります。能書き:\n\n * Ruby 2.0.0 または 2.1.5\n * Rails 4.1\n * Bundler\n * Git\n * Sqlite\n * TinyTDS\n * SQL Server サポート\n * DevKit\n\nインストールが完了すると、スタートメニューにメニュー項目が追加されており、rails\nコマンドにパスの通ったコマンドプロンプトを起動できる、という使用感のようです。(私は試したことがありません)\n\nもう 1 つ [RailsFTW](http://railsftw.bryanbibat.net/)\nというのもあります。こちらは「やっつけ仕事だが、RailsInstallerに比べてインストール時にインターネット接続しなくてもokという利点がある」ということだそうです。同梱物:\n\n * RubyInstaller 2.1.5 32bit\n * Rails 4.1.8\n * sqlite3 と mysql2 の gem\n * SQLite3 DLL\n * MariaDB の libmysql.dll", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T17:02:19.243", "id": "358", "last_activity_date": "2014-12-04T17:02:19.243", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "188", "post_type": "answer", "score": 4 }, { "body": "まだ紹介されていないので紹介します。実開発では使用したことがありませんが、[Bitnami Ruby\nStack](https://bitnami.com/stack/ruby) が使いやすそうです。(redmine stackで使用中)\n\n以下のアプリケーションが同梱されています。 Ruby(2.0.0), Rails, RVM, MySQL, SQLite, NGINX, Apache,\nMemcache and Varnish, Git and Subersion, Sphinx, PHP and phpMyAdmin\n\nGem関係ではThin, RMagick, Rake, Mongrel, Passenger,\nNokogiriが適用済みで、Msysも入っているのでネイティブビルドでも多少はカバーできそうです。\n\n以下導入に当たっての注意点や検討事項\n\n * railsアプリのサンプルコードが入ってるので参考になるかもしれません\n * 上記プログラムが内包されているので、インターネットから隔離されている環境でも使えます。(gemを追加しない場合に限る)\n * インストール時にMySQLやPostgreSQLはサービスとして起動されるので、既存のインスタンスがある場合は注意が必要です。(インストール時にカスタムを選択してください)\n * railsなので大丈夫だとは思いますが、Windowsのファイルシステムであるが故、大文字小文字と改行文字には注意してください。\n * gitやsubversionもインストール対象ですが、実運用では[TortoiseGit](https://code.google.com/p/tortoisegit/),[TortoiseSVN](http://tortoisesvn.net/downloads.html)等を導入されることを検討したほうがよいかもしれません\n * 環境にサービスをインストールするので、バージョンアップを行う場合は注意が必要です", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-12T14:09:14.920", "id": "1559", "last_activity_date": "2014-12-12T14:09:14.920", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "882", "parent_id": "188", "post_type": "answer", "score": 3 } ]
188
358
225
{ "accepted_answer_id": null, "answer_count": 7, "body": "C#やPerlを使っていた頃はStyleCop, FxCop, Perl::Critic, Perltidy等でコードを自動的にチェックしていました。\n\nRubyやRailsでも同じようなツールはありますか?\n\nGoogleで検索してみましたが、これというツールが見つかりませんでした。\n\n* * *\n\n注:この質問は過去に英語版に投稿した質問を転記したものです。\n<https://stackoverflow.com/questions/9103874/coding-style-checker-or-code-\nformatter-for-ruby-rails>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2014-11-25T22:50:07.980", "favorite_count": 0, "id": "189", "last_activity_date": "2020-05-01T07:53:29.573", "last_edit_date": "2020-05-01T07:53:29.573", "last_editor_user_id": "32986", "owner_user_id": "85", "post_type": "question", "score": 13, "tags": [ "ruby", "ruby-on-rails" ], "title": "RubyやRailsのコーディングチェックツールを探しています", "view_count": 3067 }
[ { "body": "IDEであるIntelliJ(RubyMine)を使えば、コーディングスタイルについての問題をエディタ上で確認できます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T04:20:56.627", "id": "196", "last_activity_date": "2014-11-26T04:20:56.627", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "63", "parent_id": "189", "post_type": "answer", "score": 6 }, { "body": "[RuboCop](https://github.com/bbatsov/rubocop) がオススメです。Rails に特化したチェッカもついています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T00:20:34.183", "id": "206", "last_activity_date": "2014-12-02T00:20:34.183", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "167", "parent_id": "189", "post_type": "answer", "score": 29 }, { "body": "Railsらしいコードかどうかは、[railsbp/rails_best_practices](https://github.com/railsbp/rails_best_practices)というgemを使うとチェックできます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T04:49:34.033", "id": "227", "last_activity_date": "2014-12-02T04:49:34.033", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "511", "parent_id": "189", "post_type": "answer", "score": 7 }, { "body": "オンラインのサービスに登録すると、単純な書式に限らないコードのチェックとレポート作成を自動的に行なってくれるものがあります。\n内部的にはRubocopなども使われていますが、セットアップが要らないので手軽です。\n\n * <https://codeclimate.com/>\n * <https://scrutinizer-ci.com/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T06:34:20.620", "id": "239", "last_activity_date": "2014-12-02T06:34:20.620", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "452", "parent_id": "189", "post_type": "answer", "score": 2 }, { "body": "GitHub 上のプロジェクトであれば、[HoundCI](https://houndci.com/) が手軽です。普通に Pull Request\nを出すと、コーディングスタイル上の問題点を以下のように GitHub 上でコメントとして残してくれます。\n\n![HoundCI のコメント](https://i.stack.imgur.com/0b1E9.png)\n\nHoundCI はスタイルチェッカーとして [RuboCop](https://github.com/bbatsov/rubocop)\nを使っています。ですので、チェック項目は基本的に RuboCop と同じです。\n\n注意点があるとすれば、HoundCI のコーディング規約が RuboCop のデフォルト設定と多少異なることです。たとえば:\n\n * RuboCop: `\"foobar\"` のような式展開のない文字列は `'foobar'` と書かせる。\n * HoundCI: 文字列内にシングルクオートがなければ `\"foobar\"` と書かせる。\n\nこれは、HoundCI を提供する [thoughtbot](http://thoughtbot.com/) のコーディング規約だそうです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T01:38:12.613", "id": "335", "last_activity_date": "2014-12-04T01:38:12.613", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "774", "parent_id": "189", "post_type": "answer", "score": 4 }, { "body": "sideCIというgemが古くなっていないか、セキュリティチェック、Rails-best-practiceをチェックしてくれるサービスが有ります。\nGithub連携してくれるのでPullreqのタイミングで見てくれますね。今のところ無料です。\n\nまたrubocop-gitという修正したところだけRubocopチェックしてくれるgemがお勧めです", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T05:50:17.550", "id": "1681", "last_activity_date": "2014-12-16T05:50:17.550", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2467", "parent_id": "189", "post_type": "answer", "score": 1 }, { "body": "guardとか使うとリアルタイムに実行エラー拾えたりもしますよー。もちろんsyntaxもです。 \nネットで参考にさせていただいた記事を張っておきます。\n\n[Guard gem\nを利用してファイルの変更を検出し、任意のタスクを自動実行する](http://qiita.com/tbpgr/items/f5be21d8e19dd852d9b7)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T08:25:03.817", "id": "1713", "last_activity_date": "2014-12-16T08:25:03.817", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2329", "parent_id": "189", "post_type": "answer", "score": 1 } ]
189
null
206
{ "accepted_answer_id": "202", "answer_count": 5, "body": "gitリポジトリ内の全erbファイルをhamlにリネームしたいです。(例: index.html.erb => index.html.haml)\n\n以下のようなコマンドで一つずつリネームするのは大変です。\n\n```\n\n $ git mv app/views/pages/index.html.erb app/views/pages/index.html.haml\n \n```\n\nまた、こんなコマンドが使えるかなと思ったのですが、無理でした。\n\n```\n\n $ git mv app/views/**/*.erb app/views/**/*.haml\n \n usage: git mv [options] <source>... <destination>\n \n -n, --dry-run dry run\n -f, --force force move/rename even if target exists\n -k skip move/rename errors\n \n```\n\nこういう場合はどうすればよいでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-25T22:54:16.260", "favorite_count": 0, "id": "190", "last_activity_date": "2014-12-19T04:11:00.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "post_type": "question", "score": 10, "tags": [ "git" ], "title": "gitで複数のファイルを一括で移動またはリネームする方法を教えてください", "view_count": 9281 }
[ { "body": "おそらくやりたいことは、単なるリネームでは無くてERBからHAMLへの移行だと思います。\n\n[erb2haml](https://github.com/dhl/erb2haml) を導入した後、\n\n```\n\n rake haml:replace_erbs\n git add --all\n \n```\n\nとすると、ERBからHAMLに変換した後、レポジトリから *.erb を削除、*.haml を追加することができます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T02:24:36.420", "id": "193", "last_activity_date": "2014-11-26T02:24:36.420", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "76", "parent_id": "190", "post_type": "answer", "score": 4 }, { "body": "質問者と同じく[英語版サイトの解答](https://stackoverflow.com/a/9151943/4037)を入れると\n\n```\n\n for i in $(find . -iname \"*.erb\"); do\n git mv \"$i\" \"$(echo $i | rev | cut -d '.' -f 2- | rev).haml\";\n done\n \n```\n\nですが、これだけだと価値を足していないので、解説してみます。\n\n```\n\n $(find . -iname \"*.erb\")\n \n```\n\nで、`.erb` で終わるファイルをすべてリストアップします。それを `for` で1つずつ見ていきます。\n\n次に\n\n```\n\n $(echo $i | rev | cut -d '.' -f 2- | rev)\n \n```\n\nを見ていきます。\n\n```\n\n echo $i | rev\n \n```\n\nでファイルへのパスを逆向きにします(例:`app/views/person/index.html.erb` ->\n`bre.xedni/nosrep/sweiv/ppa`)。\n\n```\n\n cut -d '.' -f 2-\n \n```\n\nで、ファイルをドット `.` で区切り、2番目以降だけ取り出します(つまり、`bre.` だけ消す)。\n\n最後に `rev` で文字を元の正方向に戻します。(例:`xedni/nosrep/sweiv/ppa` ->\n`app/views/person/index`)\n\nこれで\n\n```\n\n git mv \"$i\" \"$(echo $i | rev | cut -d '.' -f 2- | rev).haml\";\n \n```\n\nは元のファイル名から `.erb` だけ削り、`.haml` を加えて、`git mv` に渡すって感じになります。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-27T06:47:13.870", "id": "202", "last_activity_date": "2014-11-27T06:47:13.870", "last_edit_date": "2017-05-23T12:38:55.307", "last_editor_user_id": "-1", "owner_user_id": "41", "parent_id": "190", "post_type": "answer", "score": 13 }, { "body": "(私のように) `for` 文のどこにセミコロンを入れたらいいか覚えられない場合は xargs が使えます。\n\n```\n\n find . -iname \"*.erb\" -not -path './vendor/*' \\\n | rev | cut -d. -f2- | rev | xargs -IF git mv F.erb F.haml\n \n```\n\n実行前に何が起こるか確認するには、最後に -n 引数を入れるか、echo を git mv の前に入れます。\n\n```\n\n find . -iname \"*.erb\" -not -path './vendor/*' \\\n | rev | cut -d. -f2- | rev | xargs -IF echo git mv F.erb F.haml\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-29T04:57:05.473", "id": "203", "last_activity_date": "2014-11-29T04:57:05.473", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "190", "post_type": "answer", "score": 7 }, { "body": "こういう明らかに ruby がインストールされている環境では、 ruby を使うと簡単だと思います。\n\n```\n\n % ruby -e 'Dir.glob(\"app/views/**/*.erb\") { |n| `git mv #{n} #{n.gsub(/erb$/,\"haml\")}` }'\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T01:46:09.040", "id": "216", "last_activity_date": "2014-12-02T01:46:09.040", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "290", "parent_id": "190", "post_type": "answer", "score": 5 }, { "body": "自分の経験からなんですが、ファイル名変更のみの作業で `git mv` は必要ありません。というのは git\nは、パスやファイル名からではなく、ファイルの中身で、ファイルの位置を認識・検知するからです。 ですから、「\n_ファイルの中身を大きく変更せずに、拡張子だけを変更したような場合_ 」には、普通にしていれば、まあ、大抵は、「 **ファイル名を変更したと自動検知**\n」されます。\n\nですので、この質問への答えは、「気軽にファイル名を変更して、`git add . -A` する」かな。\n\n具体的な方法ですが、ファイル名の変更自体はどんなやりかたでもよく、例えば:\n\n```\n\n find app/views -name \"*.erb\" -exec rename .erb .haml \\{\\} \\;\n \n```\n\nもしくはシステムによっては:\n\n```\n\n find app/views -name \"*.erb\" -exec rename 's/.erb$/.haml/g' \\{\\} \\;\n \n```\n\nとして作業を終えた後:\n\n```\n\n git add . -A\n git status\n \n```\n\nとします。名前変更されたファイルは、renamed として認識されるはずです。 (`-A` オプションで add/rm を同時に行なわせるのが重要です )\nファイルの変更があまり大きくない場合は、これで事足りるでしょう。\n\n**補足** : サブディレクトリを対象にせず、そのディレクトリのファイルの名前を変更するだけならば、\n\n```\n\n rename .erb .haml *.erb\n git add . -A\n \n```\n\nもしくは、\n\n```\n\n rename 's/.erb/.haml/g' *.erb\n git add . -A\n \n```\n\nで済みます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-19T04:05:26.643", "id": "2091", "last_activity_date": "2014-12-19T04:11:00.367", "last_edit_date": "2014-12-19T04:11:00.367", "last_editor_user_id": "4978", "owner_user_id": "4978", "parent_id": "190", "post_type": "answer", "score": 2 } ]
190
202
202
{ "accepted_answer_id": null, "answer_count": 1, "body": "[Sphinx](http://sphinx-doc.org/) を用いて文章作成をしています。 Emacs で以下のような\nreStructuredText フォーマットのファイルを編集している際に、 コードブロック (code-block) の中身だけ rst-mode\nとは別のメジャーモードでシンタックスハイライトしたいのですが、どうすれば上手くできるでしょうか。\n\n```\n\n こんにちは世界\n ==============\n \n - ほげほげ\n \n .. code-block:: python\n \n # このブロックは rst-mode ではなく python-mode で\n # シンタックスハイライト + インデントしたいという話です\n \n def hello():\n print(\"Hello, world!\")\n \n hello()\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T04:15:07.940", "favorite_count": 0, "id": "194", "last_activity_date": "2014-12-02T02:08:40.840", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "84", "post_type": "question", "score": 6, "tags": [ "emacs", "sphinx" ], "title": "Emacs で reStructuredText を編集中する際に、コードブロックを別途シンタックスハイライトしたい", "view_count": 400 }
[ { "body": "自分で試せていないのでうまくいくか分からないのですが、mumamoやmmm-\nmodeを使うとひとつのバッファの中で、複数のモードをコードの種類によって切り替えて使うことができます(他にも[EmacsWikiのMultipleModes](http://www.emacswiki.org/emacs/MultipleModes)を参考にしてみてください)。\n\nmmm-\nmodeであれば、やっていることは逆(Pythonコード中のrstを編集する)なのですが、[この回答](https://stackoverflow.com/questions/15493342/have-\nemacs-edit-python-docstrings-using-rst-\nmode)や[このコード](https://github.com/mangalam-research/software-\nstandards/blob/master/emacs/mmm-rst-python.el)が設定の参考になるかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T02:08:40.840", "id": "218", "last_activity_date": "2014-12-02T02:08:40.840", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "308", "parent_id": "194", "post_type": "answer", "score": 2 } ]
194
null
218
{ "accepted_answer_id": "223", "answer_count": 1, "body": "AngularJSでルーティングを行うSPAを作成した場合、戻るボタンを押すと1つ前のページに戻りますが、 ページ自体は再度リロードされます。\n\nそのため、前のページの表示位置に戻らず、またデータのリロードが発生してしいます。\n\nAngularJSで戻るボタンを押した場合に、SPAではない通常のアプリケーションと同様に、\n前のページをリロードせずに、元のスクロール位置に戻るにはどのようにすればよろしいでしょうか?", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T04:18:32.127", "favorite_count": 0, "id": "195", "last_activity_date": "2014-12-02T02:43:51.010", "last_edit_date": "2014-11-26T07:15:34.790", "last_editor_user_id": "10", "owner_user_id": "63", "post_type": "question", "score": 5, "tags": [ "javascript", "angularjs" ], "title": "AngularJSで戻るボタンを押した場合に、ページをリロードせずに元のページの元の場所に戻る方法", "view_count": 5808 }
[ { "body": "scroll位置についてはscrollイベントで位置を記録しておいて戻ったタイミングで復元する方法があります。以下の回答が参考になります。\n\n<https://stackoverflow.com/questions/14107531/retain-scroll-position-on-route-\nchange-in-angularjs#16198496>\n\n$http.getが再度実行される件はcacheを有効にすれば解決すると思われます。\n\n```\n\n $http.get('phones/phones.json', { cache: true })\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T02:43:51.010", "id": "223", "last_activity_date": "2014-12-02T02:43:51.010", "last_edit_date": "2017-05-23T12:38:56.083", "last_editor_user_id": "-1", "owner_user_id": "352", "parent_id": "195", "post_type": "answer", "score": 2 } ]
195
223
223
{ "accepted_answer_id": "201", "answer_count": 2, "body": "Javaでは-Xms256mのように利用可能なメモリを指定できますが、指定しない場合のデフォルトサイズ はどのようになりますでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2014-11-26T07:39:54.657", "favorite_count": 0, "id": "199", "last_activity_date": "2023-06-18T23:05:37.013", "last_edit_date": "2023-06-18T23:05:37.013", "last_editor_user_id": "3060", "owner_user_id": "63", "post_type": "question", "score": 10, "tags": [ "java" ], "title": "Javaで利用可能なメモリサイズのデフォルト値は?", "view_count": 17137 }
[ { "body": "下みたいに Java コマンドで確認できるみたいです。\n\n```\n\n % java -XX:+PrintFlagsFinal -version 2>&1 | grep -i heapsize\n uintx ErgoHeapSizeLimit = 0 {product}\n uintx HeapSizePerGCThread = 87241520 {product}\n uintx InitialHeapSize := 134217728 {product}\n uintx LargePageHeapSizeThreshold = 134217728 {product}\n uintx MaxHeapSize := 2147483648 {product}\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T08:47:32.810", "id": "200", "last_activity_date": "2014-11-26T09:01:47.987", "last_edit_date": "2014-11-26T09:01:47.987", "last_editor_user_id": "41", "owner_user_id": "41", "parent_id": "199", "post_type": "answer", "score": 7 }, { "body": "Java SE 8のドキュメントを直訳すると以下のようです。\n\n-Xms\n\n * Java SE 5.0以前:プラットフォームごとの適切なサイズ\n * Java SE 5.0 ~ Java7:物理メモリの1/64より大きい適切なサイズ\n * Java8以降:Old世代とYoung世代に割り当てられたサイズの合計\n\n-Xmx\n\n * Java SE 5.0以前:64MB\n * Java SE 5.0 ~ Java7:物理メモリの1/4より小さい適切なサイズだが、最大でも1GBまで\n * Java8以降:言及はありませんが、Metaspace領域の特性から考えると可能な限り\n\nJava8ではヒープメモリのPermanent領域が消えて、 \n代わりにネイティブメモリにMetaspace領域が追加されました。 \nこれに合わせてメモリ関連のオプション・ツールが変更されています。\n\n○公式ドキュメント(一部情報が古いので、解説記事と合わせてご確認ください。) \n<https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gc-ergonomics.html> \n<https://docs.oracle.com/javase/jp/8/technotes/guides/vm/gc-ergonomics.html> \n<http://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html> \n<http://docs.oracle.com/javase/jp/8/technotes/tools/windows/java.html>\n\n○解説記事 \n<http://equj65.net/tech/java8hotspot/> \n<http://www.slideshare.net/YaSuenag/metaspace>", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-11-26T08:50:03.623", "id": "201", "last_activity_date": "2015-02-04T01:25:51.263", "last_edit_date": "2015-02-04T01:25:51.263", "last_editor_user_id": "70", "owner_user_id": "70", "parent_id": "199", "post_type": "answer", "score": 9 } ]
199
201
201
{ "accepted_answer_id": "316", "answer_count": 3, "body": "Python のパッケージを配布する際、依存するパッケージを指定するのに `requirements.txt` と、 `setuptools` の\n`install_requires` オプションを利用する方法の二種類があります。 どちらの方法がより一般的で推奨されているのでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T00:28:41.577", "favorite_count": 0, "id": "209", "last_activity_date": "2014-12-16T03:47:45.233", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "141", "post_type": "question", "score": 14, "tags": [ "python" ], "title": "requirements.txt と setuptools の install_requires は、どちらを使うべきですか", "view_count": 6064 }
[ { "body": "これから先、Python2.7あるいは3.4以上で動作すれば良いという状況であればpipの`requirements.txt`を使うべきです。\n\n`requirements.txt`の特徴として、以下の点が挙げられます。\n\n * 公式パッケージ配布サイト[PyPI](https://pypi.python.org/pypi)に登録されていないパッケージへの依存も、URLを書くことにより記述できる\n * そのため、TravisCIなどの近年出てきたサービスは`requirements.txt`を前提としている\n * 標準に取り込まれた 参考: [Python3.4からpipが標準インストーラに!?](http://qiita.com/ksato9700/items/c5a6db9d17ad0770a747)\n * `pip`パッケージを利用すれば、`setup.py`から読みだして使うことができる 参考: [How can I reference requirements.txt for the install_requires kwarg in setuptools' setup.py file?](https://stackoverflow.com/questions/14399534/how-can-i-reference-requirements-txt-for-the-install-requires-kwarg-in-setuptool)\n\nもし古いPythonで`pip`がインストールされていない環境でも利用したい、かつ、PyPIに登録されているパッケージだけで良い、ということであれば、`install_require`を利用するほうが良いでしょう。\n\n追記: pipとsetuptoolsも含めた詳しい比較のページがあります(英語ですが) 参考: [Concepts &\nAnalyses](https://python-packaging-user-\nguide.readthedocs.org/en/latest/technical.html#requirements-files-vs-setup-py)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T03:43:35.643", "id": "226", "last_activity_date": "2014-12-02T03:49:46.547", "last_edit_date": "2017-05-23T12:38:55.307", "last_editor_user_id": "-1", "owner_user_id": "349", "parent_id": "209", "post_type": "answer", "score": 5 }, { "body": "setuptoolsの`install_requires`を使うべきです。\n\n`requirements.txt`と`install_requires`では現時点では目的が異なっています。setup.pyに指定したinstall_requiresはパッケージ化の際にメタデータとしてパッケージに同梱されます。\n`requirements.txt`を同梱してもそのような動作にはなりません。そのため、利用者が`pip install\nhogehoge`としてそのパッケージをインストールしたときに正しく依存パッケージをインストールできるのは\n`install_requires`を設定した場合です。また、メタデータはPythonのPEP345やPEP426でフォーマットと項目が規定されている標準仕様です。\n\n`requirements.txt`は`Requirementsフォーマット`と呼ばれる形式でインストールするパッケージを列挙します。このフォーマットにはpipのオプション(`-f`や`-r`)などを含むことが出来ます。Requirementsフォーマットで記述されたrequirements.txtが将来PEPで標準化される可能性はありますが、現時点では標準化されていません。とはいえ現時点でも、様々なサービスがrequirements.txtをデファクトスタンダードと認めているためか、テスト環境の構築時などにこのファイルを認識して利用してくれます。\n\nパッケージングという観点でいえば、`setuptools`の`install_requires`を利用するべきでしょう。\nそのパッケージ自体の開発環境やテスト環境の構築という観点でいえば、`requirements.txt`を動作保証するバージョン指定付きで(一般的には`pip\nfreeze > requirements.txt`で作成して)リポジトリに同梱することが推奨されます。", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T13:33:41.413", "id": "316", "last_activity_date": "2014-12-03T13:33:41.413", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "806", "parent_id": "209", "post_type": "answer", "score": 13 }, { "body": "パッケージを配布する場合に、 pip freeze が出力する requirements をそのまま利用してはいけません。 理由は以下のとおりです。\n\n * テスト自動化やスタイルチェックなど、開発時に使う、そのパッケージが実際には依存していないパッケージまで含まれてしまう可能性がある。\n * マイクロバージョンまで詳細に指定されてしまい、複数のパッケージが同じパッケージのバージョン違いに依存するという dependency hell を引き起こす。\n\nPython の有名なライブラリは、マイクロバージョンでは互換性を壊さない用に注意されているので、自分が作成したパッケージを配布するときには\nsetup.py の install_requirements でのバージョン指定をしないか、緩くすることで、 dependency hell\nを避ける事ができます。\n\npip freeze は、 Web\nアプリケーションをデプロイするときなど、開発環境で検証された構成と同じ構成をステージング・本番環境で作りたい場合などに有効です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T03:47:45.233", "id": "1656", "last_activity_date": "2014-12-16T03:47:45.233", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3019", "parent_id": "209", "post_type": "answer", "score": 7 } ]
209
316
316
{ "accepted_answer_id": "214", "answer_count": 1, "body": "クライアントPC内に仮想マシンを立ち上げ、FTPでファイルをDLしたのいですが、Filezillaでファイルが開けなくてこまっています。仮想マシン側のファイルのパーミッションは777にしており、cyberduckを使うときちんとダウンロードできたので、Filezilla側の問題だ、というところまで特定できています。\n\nまたFilezillaではファイルのアップロードはできますので、単純にDLのみができません。\n\n```\n\n エラー: 書き込み用に \"xxxxx.html\" を開くのに失敗しました\n エラー: ファイル転送に失敗しました\n \n```\n\nファイルをDLしようとすると上記のようなエラーがでます。\n\n * Filezillaのバージョンは3.9.0.6\n * Macのバージョンは OS X 10.10\n\nです。\n\nどうぞよろしくお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T01:23:53.300", "favorite_count": 0, "id": "213", "last_activity_date": "2015-08-20T13:38:24.857", "last_edit_date": "2015-08-20T13:38:24.857", "last_editor_user_id": "33", "owner_user_id": "288", "post_type": "question", "score": 8, "tags": [ "macos" ], "title": "Filezillaでファイルが開けません", "view_count": 2543 }
[ { "body": "Mac のダウンロード先のディレクトリに書き込み権限が無い、ということはありませんか? ダウンロード先を ~/Desktop\nなどに、試しに変えてみると解消されるかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T01:32:29.823", "id": "214", "last_activity_date": "2014-12-02T01:32:29.823", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "294", "parent_id": "213", "post_type": "answer", "score": 4 } ]
213
214
214
{ "accepted_answer_id": "222", "answer_count": 1, "body": "Xcode6で自作フレームワークを作成しました。 \nフレームワーク用プロジェクト内でxibを使用したコードがあるのですが。 \nデモアプリを作成し、そこに自作したフレームワークを追加して呼び出すと以下のエラーが発生してしまいます。\n\n```\n\n 2014-11-27 19:09:25.323 SampleApp[5709:1563355] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/mobile/Containers/Bundle/Application/6FDD2A14-A4A8-47FC-88B2-5DF48546F72D/SampleApp.app> (loaded)' with name 'SampleView''\n *** First throw call stack:\n (0x1824cde48 0x192c140e4 0x1824cdd88 0x1870874f0 0x1000d7360 0x1000d72dc 0x1000d7fb8 0x100100df0 0x100101cfc 0x1000d7f48 0x1000d80e8 0x10006d130 0x186f0b54c 0x186f0f724 0x186f13a6c 0x186f12f48 0x186f12ea0 0x186f067d4 0x18a729640 0x182486124 0x18248522c 0x182483850 0x1823b11f4 0x18b53f5a4 0x186ce2784 0x10006e504 0x193282a08)\n libc++abi.dylib: terminating with uncaught exception of type NSException\n \n```\n\nおそらく、nibファイルが見つけられないのが原因です。 \nこれを解決する良い方法をご存知の方は居らっしゃいますでしょうか。\n\n今のところ、考えてる解決策は2つあります\n\n * xibを使わないでコードで書く\n * xibをデモプロジェクト自体に追加する (この場合、フレームワークを配布するときにnibファイルも別途配布することになりそう)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T01:41:02.220", "favorite_count": 0, "id": "215", "last_activity_date": "2014-12-02T02:58:06.713", "last_edit_date": "2014-12-02T02:10:11.150", "last_editor_user_id": "104", "owner_user_id": "283", "post_type": "question", "score": 4, "tags": [ "xcode", "xcode6", "framework", "xib" ], "title": "Xcode6自作フレームワーク内でxibを使用すると'Could not load NIB in bundle: 'エラーが発生する", "view_count": 5950 }
[ { "body": "Framework内ではFrameworkのBundleからNIBを見つける必要があります。ですのでFramework内のクラス内ではSwiftであれば以下のようにコーディングします。\n\n```\n\n public class ViewLoader {\n \n public class func myView() -> UIView {\n let nib = UINib(nibName: \"MyView\", bundle: NSBundle(forClass: self))\n let view = nib.instantiateWithOwner(nil, options: nil).first as UIView\n return view\n }\n \n public func myView() -> UIView {\n let nib = UINib(nibName: \"MyView\", bundle: NSBundle(forClass: ViewLoader.self))\n let view = nib.instantiateWithOwner(nil, options: nil).first as UIView\n return view\n }\n \n public init() {\n \n }\n \n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T02:22:34.553", "id": "222", "last_activity_date": "2014-12-02T02:58:06.713", "last_edit_date": "2014-12-02T02:58:06.713", "last_editor_user_id": "238", "owner_user_id": "238", "parent_id": "215", "post_type": "answer", "score": 5 } ]
215
222
222
{ "accepted_answer_id": "220", "answer_count": 6, "body": "TwitterのデータのようにJSON形式で取得されたものは、日本語などマルチバイト文字がすべて\"\\uHHHH\"のようなユニコードの16進表現でエンコードされています。 \nこれをOS Xの標準環境、できればシェルスクリプトで配りたいのですが、この制約の中で出来る良い方法がないか探しています。\n\n当初は、 <http://qiita.com/kumazo@github/items/39500f259500a424800b> \nを参考にして挑戦したのですが、 /usr/bin/printf でもデコードできませんでした。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T01:54:25.307", "favorite_count": 0, "id": "217", "last_activity_date": "2014-12-16T08:08:39.953", "last_edit_date": "2014-12-03T07:36:10.867", "last_editor_user_id": "47", "owner_user_id": "248", "post_type": "question", "score": 6, "tags": [ "bash", "macos", "json", "decode", "unicode" ], "title": "エスケープされた日本語文字列をデコードしたい", "view_count": 19867 }
[ { "body": "<https://stackoverflow.com/questions/6319421/do-all-mac-\nos-x-10-6-installations-have-perl-installed-by-default>\n\nを読むにOSXでは、perlが使えると思いますので、\n\n<https://stackoverflow.com/questions/8795702/how-to-convert-uxxxx-unicode-to-\nutf-8-using-console-tools-in-nix>\n\nの中段にある\n\n```\n\n #!/usr/bin/perl\n \n use strict;\n use warnings;\n \n binmode(STDOUT, ':utf8');\n \n while (<>) {\n s/\\\\u([0-9a-fA-F]{4})/chr(hex($1))/eg;\n print;\n }\n \n```\n\n<https://stackoverflow.com/a/8796595/718426>\n\nが使えるんじゃないかなと思うのですが、いかがでしょう。", "comment_count": 7, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T02:18:10.097", "id": "220", "last_activity_date": "2014-12-02T02:18:10.097", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "351", "parent_id": "217", "post_type": "answer", "score": 9 }, { "body": "こちらもYosemiteでprintfやechoではデコードできませんでした。 私はいつも以下の方法でデコードしています。\n\n`\\uHHHH形式を出力するコマンド | sed -e 's/\\\\\\u\\\\(....\\\\)/\\&#x\\1;/g' | nkf --numchar-\ninput`\n\nまず\"&#xHHHH\"の形式に変換してからnkfコマンドで日本語に直しています。 残念ながらnkfはOS\nX標準にはなく、brewでインストールしたものですが。。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T02:18:22.700", "id": "221", "last_activity_date": "2014-12-02T02:18:22.700", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "371", "parent_id": "217", "post_type": "answer", "score": 2 }, { "body": "Python を使ったワンライナーです。OS X はデフォルトで Python 2.7.x が入ってると思うのでそのまま使えると思います。\n\n```\n\n \\uHHHH形式を出力するコマンド | python -c \"import re; print re.sub(r'\\\\u[0-9(a-f|A-F)]{4}', lambda x: chr(int(u'0x' + x.group(0)[2:], 16)), raw_input())\"\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T10:51:22.717", "id": "256", "last_activity_date": "2014-12-02T10:51:22.717", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "645", "parent_id": "217", "post_type": "answer", "score": 2 }, { "body": "Pythonならhexとらなくても`decode(\"unicode-escape\")`があります。\n\n```\n\n $ echo '\\u30e6\\u30cb\\u30b3\\u30fc\\u30c9' | python -c 'from sys import stdin; print stdin.readline().decode(\"unicode-escape\")'\n ユニコード\n \n```\n\n* * *\n\n### 追記:\n\nちなみにサロゲートペアにも対応\n\n```\n\n $ echo '\\ud842\\udfb7\\u91ce\\u5bb6' | python -c 'from sys import stdin; print stdin.readline().decode(\"unicode-escape\")'\n 野家\n \n```", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T11:37:04.100", "id": "259", "last_activity_date": "2014-12-02T14:32:14.853", "last_edit_date": "2014-12-02T14:32:14.853", "last_editor_user_id": "62", "owner_user_id": "62", "parent_id": "217", "post_type": "answer", "score": 6 }, { "body": "perl、python が回答として既に出ているので別解の意味を込めて。\n\nvim が入っているならばバッファにエスケープされた文字列をペーストして\n\n```\n\n :%s/\\\\u\\([0-9a-f]\\{4}\\)/\\=nr2char(eval(\"0x\".submatch(1)),1)/g\n \n```\n\nとすれば\n\n```\n\n \\u30e6\\u30cb\\u30b3\\u30fc\\u30c9\n \n```\n\nこれが\n\n```\n\n ユニコード\n \n```\n\nに変換されます。もし文字列を打ち込むのが難しい場合は\n\n```\n\n $ echo '\\u30e6\\u30cb\\u30b3\\u30fc\\u30c9' | vim -\n \n```\n\nの様にして標準入力を取り込んでも良いと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T14:57:16.280", "id": "318", "last_activity_date": "2014-12-03T14:57:16.280", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "440", "parent_id": "217", "post_type": "answer", "score": 3 }, { "body": "bash, zsh の組込み echo の -e オプションはどうでしょうか。\n\n```\n\n $ echo -e '\\u30e6\\u30cb\\u30b3\\u30fc\\u30c9 \\ud842\\udfb7\\u91ce\\u5bb6'\n ユニコード 野家\n \n```\n\nサロゲートペアな文字は駄目みたいです。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T05:39:37.817", "id": "1677", "last_activity_date": "2014-12-16T08:08:39.953", "last_edit_date": "2014-12-16T08:08:39.953", "last_editor_user_id": "3061", "owner_user_id": "3061", "parent_id": "217", "post_type": "answer", "score": 1 } ]
217
220
220
{ "accepted_answer_id": "240", "answer_count": 4, "body": "* OSX 10.10.1\n * Timemachine使用\n\nYosemiteにアップデート後からかは不明ですが、 最近ホスト名が勝手に変わってしまいます。\n\n`macbookpro.local`としていたものが、\n\n`macbookpro-2.local`にいつの間にか変わってました。\n\nこれでここ2週間で2度めです。\n\n * Time capsule のWifiを使用\n * WifiはONですが、有線LANも使用\n\nどうやら、Timemachineのバックアップ後に変わっているタイミングに感じます。 同じような現象の方いらっしゃいませんか。\n\n対策を知りたいです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T04:59:56.193", "favorite_count": 0, "id": "228", "last_activity_date": "2014-12-10T05:45:05.110", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "512", "post_type": "question", "score": 8, "tags": [ "macos" ], "title": "MacOSXでホスト名が勝手に(自動で)変わってしまう", "view_count": 10131 }
[ { "body": "OSXのホスト名は3つあり\n\n```\n\n sudo scutil --get ComputerName\n sudo scutil --get HostName\n sudo scutil --get LocalHostName\n \n```\n\nで取得できます。どれかが設定されていないのかもしれません。\n\nそれぞれ設定するには\n\n```\n\n sudo scutil --set ComputerName newName\n sudo scutil --set HostName newName\n sudo scutil --set LocalHostName newName\n \n```\n\nです。私はいつも3つともドメインの含まない同じ名前にしていますが、 試してみてはいかがでしょう。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T06:39:11.697", "id": "240", "last_activity_date": "2014-12-02T06:39:11.697", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "499", "parent_id": "228", "post_type": "answer", "score": 11 }, { "body": "Bonjour名はネットワーク上に同一のものがあると、自動的に末尾に番号をつけて重複を回避する挙動をします。$ arp\n-aしてみて、ARPテーブルに残骸が残っているようであれば $ arp -dしてみると良いかもしれません。\n\n> 質問者です\n\n$ arp -a すると以下のようになりました。 \n(詳しくないので) 192.168.24.1で何か重複しているような雰囲気ですが、ここあたりですかね?\n\n![画像の説明をここに入力](https://i.stack.imgur.com/cTrb9.png)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T09:18:52.637", "id": "248", "last_activity_date": "2014-12-02T10:05:45.403", "last_edit_date": "2014-12-02T10:05:45.403", "last_editor_user_id": "512", "owner_user_id": "248", "parent_id": "228", "post_type": "answer", "score": 2 }, { "body": "私も同じ現象になりましたが、 ~~spindle~~ .sparsebundle ファイルを削除して再バックアップしたところ、発生しなくなりました。\n\n * MacBook Pro (Retina, 13-inch, Early 2013)\n * OS X 10.10.1\n * TimeMachine Wifi 経由で週1回バックアップ", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T10:29:29.923", "id": "255", "last_activity_date": "2014-12-02T14:48:45.303", "last_edit_date": "2014-12-02T14:48:45.303", "last_editor_user_id": "640", "owner_user_id": "640", "parent_id": "228", "post_type": "answer", "score": 2 }, { "body": "私も過去にたようなことがありました。ただ、ずいぶん昔のことだったので詳細は忘れてしまいましたが、その時は Ethernet と Wi-Fi\n両方で同じルータに接続していたことが起因していたと記憶しています。\n\nその時は固定IPで、Ethernet と Wi-Fi 両方同じIPにすることで回避しました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-10T05:45:05.110", "id": "494", "last_activity_date": "2014-12-10T05:45:05.110", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "973", "parent_id": "228", "post_type": "answer", "score": 2 } ]
228
240
240
{ "accepted_answer_id": null, "answer_count": 5, "body": "`gem install bundler`のコマンドを打つと、以下のエラーが出てインストールされません。\n\n```\n\n ERROR: Could not find a valid gem 'bundler' (>= 0), here is why:\n Unable to download data from http://rubygems.org/ - no such name (http://api.rubygems.org/latest_specs.4.8.gz)\n \n```\n\nどうすれば解決するでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:28:26.437", "favorite_count": 0, "id": "229", "last_activity_date": "2018-12-27T08:00:58.537", "last_edit_date": "2014-12-10T06:27:31.443", "last_editor_user_id": "982", "owner_user_id": "534", "post_type": "question", "score": 8, "tags": [ "bundler", "rubygems" ], "title": "bundler のインストールが失敗する", "view_count": 9803 }
[ { "body": "今日はrubygems.orgが不安定なようので、そのせいではないでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:34:29.820", "id": "231", "last_activity_date": "2014-12-02T05:34:29.820", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "188", "parent_id": "229", "post_type": "answer", "score": 3 }, { "body": "DNS障害でrubygems.orgに通信できない状況が発生しています。 復旧次第、成功するようになります。\n\nコンソールからドメイン情報の取得を行うと状況が確認出来ます。\n\n`host rubygems.org`", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:36:19.637", "id": "233", "last_activity_date": "2014-12-02T05:36:19.637", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "452", "parent_id": "229", "post_type": "answer", "score": 10 }, { "body": "自分も同じ件で困ってました。 現在は解決されていますが、次似たようなことが発生した場合、下記サイトを見るとすぐに落ちているかどうか判断できるかと思います。\n\nStatus - RubyGems System Status <https://status.rubygems.org/>\n\nPingdom Public Reports Overview <http://uptime.rubygems.org/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T10:13:49.207", "id": "429", "last_activity_date": "2014-12-07T10:13:49.207", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "291", "parent_id": "229", "post_type": "answer", "score": 4 }, { "body": "ソースの場所を-r(Remove)し、有効な場所を-a(add)する\n\n```\n\n gem sources -r http://rubygems.org/ -a http://production.cf.rubygems.org/\n \n```\n\n戻す\n\n```\n\n gem sources -r http://production.cf.rubygems.org/ -a http://rubygems.org/\n \n```\n\nでいつもとりあえず解決させてます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-01-02T05:43:22.510", "id": "2937", "last_activity_date": "2015-01-02T05:43:22.510", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3884", "parent_id": "229", "post_type": "answer", "score": 2 }, { "body": "-pオプションで、proxyを設定してみてください。\n\n<https://maku77.github.io/ruby/gem/gem-with-proxy.html>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2018-12-27T08:00:58.537", "id": "51552", "last_activity_date": "2018-12-27T08:00:58.537", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "31602", "parent_id": "229", "post_type": "answer", "score": 0 } ]
229
null
233
{ "accepted_answer_id": "236", "answer_count": 10, "body": "ちょっと時間がかかるテストを回しながら開発しています。\n\n```\n\n $ python tests.py\n \n```\n\nテストが走っている間に次のテストを書いたりして時間の埋め合わせをしていますが、テストが終わったら前回変えたところを忘れないうちにすぐにテスト結果を見て対処したいです。\n\nテストを実行するコマンドが終了したらビープ音か何かを鳴らせばいいかと思うのですが、どうすればいいでしょうか。\n\nSSH越しのシェルでも動作するような方法がよいです。\n\nおまけでコマンドの終了コードが 0 かそうでないかによって別の音 (ビープ音の数が違うのでもよい) にできればさらによいです。(補足:\nただし、音は終了コードに関わらず常に鳴らしたい)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:29:17.280", "favorite_count": 0, "id": "230", "last_activity_date": "2014-12-18T00:21:18.377", "last_edit_date": "2014-12-03T01:28:29.170", "last_editor_user_id": "30", "owner_user_id": "30", "post_type": "question", "score": 23, "tags": [ "bash", "macos" ], "title": "コマンドが終了したら音を鳴らしたい", "view_count": 21558 }
[ { "body": "シェクスクリプトで実行してからechoでビープ音文字を出力すればよいと思います。 実行結果は$?に入るのでそれを判定して音を鳴らす回数を変える事も出来ます。\n\n```\n\n #!/bin/sh\n python tests.py\n \n if [ $? -eq 0 ]; then\n echo $'\\a' #戻り値が0なら1回ビープ音\n else\n echo $'\\a\\a\\a' #それ以外では3回ビープ音\n fi\n \n```", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:37:44.127", "id": "234", "last_activity_date": "2014-12-02T06:30:24.903", "last_edit_date": "2014-12-02T06:30:24.903", "last_editor_user_id": "525", "owner_user_id": "525", "parent_id": "230", "post_type": "answer", "score": 5 }, { "body": "一度ビープ音を鳴らしたいのであれば次のようにすればよいかと思います.\n\n```\n\n echo ^G\n \n```\n\n「^G」を入力するのには `C-v C-g` とタイプすればよいかと思います.\nまたはターミナルエミュレータの機能で出力があれば知らせるものもあるようです([Konsole](https://konsole.kde.org/)など).\n\n追記:\n\n```\n\n python test.py && echo ^G || (echo ^G; sleep 1; echo ^G)\n \n```\n\nワンライナーがお好きなら,こう書くと正常終了時には一回,異常終了時には二回ビープが鳴るようにできます.単に成功失敗問わず鳴らしたいということならば\n\n```\n\n python test.py; echo ^G\n \n```\n\nです.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:41:45.443", "id": "236", "last_activity_date": "2014-12-02T09:28:30.930", "last_edit_date": "2014-12-02T09:28:30.930", "last_editor_user_id": "535", "owner_user_id": "535", "parent_id": "230", "post_type": "answer", "score": 22 }, { "body": "テストが失敗した場合に音を鳴らすのであれば\n\n```\n\n python test.py || echo ^G\n \n```\n\nとします。`^G` は `CTRL-V` `CTRL-G` で入力します。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:56:55.313", "id": "237", "last_activity_date": "2014-12-02T05:56:55.313", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "440", "parent_id": "230", "post_type": "answer", "score": 12 }, { "body": "Macの場合、sayコマンドが使用できます。自分は長いmakeビルドなどが終わったことを知らせるのに、sayコマンドを使っています\n\n```\n\n make && say Done\n \n```\n\n日本語の音声もつかえるので、日本語を喋らせても面白いです\n\n```\n\n make && say -v Otoya \"終わったよ!\"\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T00:45:28.763", "id": "281", "last_activity_date": "2014-12-03T00:45:28.763", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "264", "parent_id": "230", "post_type": "answer", "score": 26 }, { "body": "DVDトレイを出し入れするejectコマンドを利用するのはどうでしょうか。\n\nRaspberry Piでのやり方:\n\n```\n\n /usr/bin/eject -T\n \n```\n\n色々な利用例: <http://www.slideshare.net/Akkiesoft/20140927-ejecthandson>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-09T09:02:03.950", "id": "484", "last_activity_date": "2014-12-09T15:28:01.097", "last_edit_date": "2014-12-09T15:28:01.097", "last_editor_user_id": "30", "owner_user_id": "972", "parent_id": "230", "post_type": "answer", "score": 3 }, { "body": "システムで利用されている AIFF を使いリッチな音を再生するという方法もあります。\n\n例\n\n```\n\n afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/burn\\ complete.aif\n \n```\n\n他にも\n`/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds`\nにいくつか使えそうな音があります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-09T09:43:34.123", "id": "485", "last_activity_date": "2014-12-09T09:43:34.123", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "973", "parent_id": "230", "post_type": "answer", "score": 3 }, { "body": "`^G` を出力する例ばかりですが、移植性を考慮するなら tput を用いるべきです。\n\n```\n\n $ python test.py; tput bel\n \n```\n\nベルを鳴らし続ける例:\n\n```\n\n $ python test.py; while :; do tput bel;sleep 1; done\n \n```\n\n`bel` など端末の機能名については Linux や *BSD ならオンラインマニュアル `terminfo`(5) の「Cap-\nname」あたりを見てください。\n\n次のようなエイリアスを作っておくといいかもしれません。\n\n```\n\n $ alias alarm='e=$?; s=2; [ $e -ne 0 ] && { echo exit $e 1>&2; let s--; }; while :; do tput bel; sleep $s; done'\n $ python test.py; alarm\n \n```\n\nこの例のエイリアスコマンド `alarm` は、 直前のコマンドの終了コードが 0\nの場合は2秒おきにベルを鳴らし、それ以外の場合は終了コードを表示して1秒おきにベルを鳴らします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T05:31:05.980", "id": "1674", "last_activity_date": "2014-12-16T10:52:30.777", "last_edit_date": "2014-12-16T10:52:30.777", "last_editor_user_id": "3061", "owner_user_id": "3061", "parent_id": "230", "post_type": "answer", "score": 10 }, { "body": "音を鳴らす方法は他の方にお譲りして、私は別の角度からコメントします。コマンドを実行してしばらくしてから「時間かかるなぁ、これが終わった時に音を鳴らしたいなぁ」と後から思うことがよくあります。でも実行を中断して`;\n[音を鳴らすコマンド]`をつけて実行し直すのは、これまでせっかく計算してきたのに時間が無駄になってしまいます。そういう時は、私は`ps`を使っています。プロセスIDをpsで調べてからそのプロセスがある間はwhileループを回します。\n\n```\n\n python tests.py\n # ...\n # 時間がかかるなぁ...\n # 中断するのもったいないなぁ...\n \n # 別の端末を立ち上げて\n ps # PIDを見る\n while ps PID >/dev/null; do sleep 1; done; echo \"done\" # 音を鳴らしたり、出力ファイルを処理するなど\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T10:24:53.217", "id": "1735", "last_activity_date": "2014-12-16T14:14:44.347", "last_edit_date": "2014-12-16T14:14:44.347", "last_editor_user_id": "3822", "owner_user_id": "3822", "parent_id": "230", "post_type": "answer", "score": 8 }, { "body": "同じように音を鳴らす設定にしていたことがありますが、トイレなどに立つと音を聞き逃すため、OS X の Notification Center\nを使うという方法にしたことがあります。\n\nterminal-notifier というアプリケーションを入れ、 <https://github.com/alloy/terminal-notifier>\n\n```\n\n >>> import os\n >>> os.system('/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -message Done')\n \n```\n\nなどを Python 側から呼べば、Mac の画面に通知が出ます (os-x のタグがついているので、Mac を想定します)。\n\nもし `tests.py` の走っている Mac が他の Mac であれば、SSH を使うことで解決できます。通知を受け取りたい側の Mac に\nterminal-notifier をインストールし、`tests.py` の中から、スクリプト終了時に SSH を呼び出します。\n\n```\n\n import os\n os.system(\"ssh YOUR_USER_NAME@YOUR_HOST /Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -message Done\")\n \n```\n\nSSH を使う場合は、パスワード入力をしなくても良いように設定して下さい。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T15:36:51.013", "id": "1794", "last_activity_date": "2014-12-16T15:36:51.013", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4070", "parent_id": "230", "post_type": "answer", "score": 2 }, { "body": "コマンドラインでいちいち`echo\n^G`をつけるのは忘れてしまいますので、テストを走らせるシェルのプロンプトに`^G`を仕込むのはどうでしょう。あるいは``command``で何かコマンド\n(別の方が書いていらっしゃるように通知コマンドなど) をプロンプトに仕込んでおいて起動することも出来ます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-18T00:21:18.377", "id": "1951", "last_activity_date": "2014-12-18T00:21:18.377", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3413", "parent_id": "230", "post_type": "answer", "score": 2 } ]
230
236
281
{ "accepted_answer_id": null, "answer_count": 1, "body": "CentOS 6のsvnとgitのバージョンを上げた際のgit-svnの問題についてです。\n\nCentOS 6のyumで入るsubversionは1.6系なので、これを下記のサイトの方法で1.8系にアップデート: \n[CentOS\n6でsubversionのバージョンを上げる](http://www.torutk.com/projects/swe/wiki/CentOS_6%E3%81%A7subversion%E3%81%AE%E3%83%90%E3%83%BC%E3%82%B8%E3%83%A7%E3%83%B3%E3%82%92%E4%B8%8A%E3%81%92%E3%82%8B)\n\n同じくCentOS 6のyumで入るgitも古いので下記のサイトの方法でアップデート (そのままやるとこけるのでsubversion-\nperlをwandisco-svnからインストールしてからgitをインストールします): \n[CentOS\n6でgitのバージョンを上げる](http://www.torutk.com/projects/swe/wiki/CentOS_6%E3%81%A7git%E3%81%AE%E3%83%90%E3%83%BC%E3%82%B8%E3%83%A7%E3%83%B3%E3%82%92%E4%B8%8A%E3%81%92%E3%82%8B)\n\n両方ともwandiscoのRPMを使用する方法です。 上記方法と同様にしてgit-svnもインストール\n\n```\n\n yum install --enablerepo=wandisco-git --disablerepo=base,updates,epel git-svn\n \n```\n\nところがこの方法で導入したgit-svnによるチェックアウトが失敗してしまいます。\n\n```\n\n git svn clone https://exapmle.com/repos ./\n Initialized empty Git repository in /home/user/test/.git/\n 不正な URL が RA 層に渡されました: 'https://exapmle.com/repos' 用の URL スキームを認識できません at /usr/share/perl5/vendor_perl/Git/SVN.pm line 148\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T05:34:42.763", "favorite_count": 0, "id": "232", "last_activity_date": "2014-12-03T04:43:13.393", "last_edit_date": "2014-12-03T03:07:33.250", "last_editor_user_id": "30", "owner_user_id": "525", "post_type": "question", "score": 3, "tags": [ "git", "centos", "svn" ], "title": "CentOS 6でsvnおよびgitのバージョンを上げた際のgit-svnの問題", "view_count": 814 }
[ { "body": "CentOS\nのパッケージに詳しくないので、綺麗な(パッケージのインストールだけで)方法がちょっとわからないのですが、[本家SO](https://stackoverflow.com/a/13865154/4037)\nで似た質問がありました。\n\nまず、`svn --version` と打ち込み、`\\- handles 'https' scheme`\nという行が表示されるか確認します。これで、インストールした svn に https 機能があるか確認できます。\n\nインストール方法から類推するに HTTPS 機能はあると思います。\n\nその場合、git-svn が古い svn を使っている可能性があります。 \n原因として挙げられているのは\n\n 1. SVN に Perl のバインディングが入っていない可能性があります。入っていないと、http(s) 機能がないデフォルトバイナリを使ってしまうようです。\n 2. Perl モジュールの設定でで `PATH/LD_LIBRARY_PATH` か `PERL5LIB` が設定できておらず、git-svn が上と同じようにデフォルトバイナリを使ってしまっている。\n\n[この方](http://yano3.hatenablog.jp/entry/2013/01/30/194506)は 1.7\n系ですが、自分でコンパイルする際に neon-devel がないと同じエラーになったようです。ご自身でコンパイルすることにした場合は参考になると思います。\n\nちょっとはっきりした答えにならず、申し訳ないです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T04:43:13.393", "id": "303", "last_activity_date": "2014-12-03T04:43:13.393", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "41", "parent_id": "232", "post_type": "answer", "score": 1 } ]
232
null
303
{ "accepted_answer_id": "261", "answer_count": 2, "body": "androidのイヤホン端子でモータを制御しようとしていて、イヤホン端子からPWMを出力する方法を探しています。\n周波数はある程度高周波であればあまりこだわりません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T06:10:13.003", "favorite_count": 0, "id": "238", "last_activity_date": "2014-12-02T12:58:32.977", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "post_type": "question", "score": 8, "tags": [ "android" ], "title": "androidでイヤホン端子からPWMを出力したい", "view_count": 1489 }
[ { "body": "生成した音声バッファを直接再生できる android.media.AudioTrack はいかがでしょうか。\n\n指定された長さ・周波数・デューティ比で矩形波を生成できるクラスを作成し、AudioTrack.OnPlaybackPositionUpdateListener\n内の AudioTrack.onMarkerReached()が呼び出されるたびに波形を生成して流し込めるようにすればよいでしょう。\n\n## 気をつけるべき事項\n\n * 生成波の理論的最高周波数はサンプリングレートの1/2\n\n例えばCDと同じ44.1[kHz]で波形を出力する場合は、標本化定理から22.05[kHz]での出力が最高の周波数になります。ただ、この周波数に近づくにつれて波は台形に近くなり、最終的に三角波になります。(数kHzで必要十分だとは思いますが)\n\n * 波形バッファの長さは周波数に合わせて変える\n\nブラシレスモーター(特にステッピングモータ)の場合は、周波数が高くなると脱調しやすくなります。波形バッファが波長の整数倍でない場合、Listenerによってバッファを流し込む継ぎ目のところだけデューティ比が変わり、脱調を引き起こすかもしれません。\n\nAndroidでシンセサイザーやシグナルジェネレータを作っている人のサイトが多数存在するので、検索してみることをおすすめします。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T10:08:47.857", "id": "254", "last_activity_date": "2014-12-02T10:08:47.857", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "197", "parent_id": "238", "post_type": "answer", "score": 6 }, { "body": "AudioTrackを使って簡単な矩形波を生成するコードを書いてみました。\n<http://qiita.com/niusounds/items/beb0140117b9d3325ce7>\n上記のOscillatorクラスで波形を生成する部分の\n\n```\n\n double sin = Math.sin(2 * Math.PI * t * frequency);\n buffer[i] = sin > 0 ? 1 : -1;\n \n```\n\nで`sin > 0`を`sin > 0.25`とかにすればデューティ比が変わるんじゃないかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T12:58:32.977", "id": "261", "last_activity_date": "2014-12-02T12:58:32.977", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "450", "parent_id": "238", "post_type": "answer", "score": 4 } ]
238
261
254
{ "accepted_answer_id": "247", "answer_count": 4, "body": "VisualStudio C# .NET Framewok という環境でWindows用のアプリを開発しています。\nこのアプリは外部のサーバーと通信を行っております。 サーバは、devel環境、staging環境、production環境の3つが用意されております。\nそれに伴い、アプリも各環境用に、サーバーの指し先を変えたものをビルドしたいです。\n\n(Android開発で言うところのflavorのような機能を期待しています)\n\nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T06:43:20.927", "favorite_count": 0, "id": "241", "last_activity_date": "2014-12-19T14:04:43.443", "last_edit_date": "2014-12-03T14:35:09.090", "last_editor_user_id": "33", "owner_user_id": "427", "post_type": "question", "score": 7, "tags": [ ".net", "visual-studio", "c#", "build" ], "title": "VisualStudio C# .NET Framewok で、どのように複数環境のビルドをしますか", "view_count": 4359 }
[ { "body": "それぞれの環境用にソリューションの構成を用意すればいいと思います。\n\n## ソリューションの構成を追加する\n\nVisual Studioのメニューから[ビルド]-[構成マネージャー]を開いて、 構成マネージャーのダイアログにある[アクティブ\nソリューション構成]のドロップダウンから [<新規作成...>]を選択します。\n\nそうすると「新しい構成マネージャー」が表示されるので、名前をたとえば「devel」「staging」「production」にしたものを追加します。\n\n別の構成をコピーして新しい構成を作成する場合には「設定のコピー元」を選択します。\n\n### 構成毎にビルドするプロジェクトを切り替える必要がある場合\n\n「新しいプロジェクト構成を作成する」にチェックをつけて新しい構成を作成します。 その後、構成マネージャー画面で[アクティブ\nソリューション構成]を切り替えて、 それぞれの構成においてビルドするものとしないものを設定します。\n\n「新しいプロジェクト構成」を追加した場合には それぞれのプロジェクトのプロパティ画面を開くと\n[ビルド]や[デバッグ]のページにある[構成]のドロップダウンにも項目が追加されているので、\n追加された構成用のビルド設定やデバッグ設定を指定できるようになります。\n\n## 構成によってサーバーの指し先を変える\n\nプロジェクトのプロパティページにある [ビルド]-[全般]-[条件付きコンパイル シンボル]の値をそれぞれの構成で異なる値\n(たとえば「devel」構成では`DEVEL`、「staging」構成では`STAGING`、\n「production」構成では`PRODUCTION`)になるようにして、 コード側では\n\n```\n\n #if DEVEL\n var serverAddress = \"<devel server address>\";\n #elif STAGING\n var serverAddress = \"<staging server address>\";\n #elif PRODUCTION\n var serverAddress = \"<production server address>\";\n #endif\n \n```\n\nというようにしてやればいいのではないでしょうか。\n\n# あるいはもう少しスマートな方法があるかもしれませんが。。。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T08:54:16.377", "id": "247", "last_activity_date": "2014-12-04T17:11:53.040", "last_edit_date": "2014-12-04T17:11:53.040", "last_editor_user_id": "30", "owner_user_id": "295", "parent_id": "241", "post_type": "answer", "score": 5 }, { "body": "アプリケーション設定ファイル機能等の外部設定ファイルに書き出してしまう方法はいかがでしょうか。\n\nビルドしたバイナリは変えずに、設定ファイルを書き換えてしまう。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T14:31:34.793", "id": "264", "last_activity_date": "2014-12-02T14:31:34.793", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "700", "parent_id": "241", "post_type": "answer", "score": 6 }, { "body": "こちらの質問は、実行時にアプリが参照するWebサービスのURIを構成するには、と読み取れます。\n\n.NET Framework でデスクトップアプリ(Windows Forms や WPF)を作成すると、プロジェクトに App.config\nというファイルが生成されます。こちらのファイルに appSetting タグを加え、add タグで URI\nを指定する部分を追加し、アプリ側から読み込めば大丈夫です。\n\nApp.config の例:\n\n```\n\n <?xml version=\"1.0\" encoding=\"utf-8\" ?>\n <configuration>\n <startup> \n <supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.5\" />\n </startup>\n <appSettings>\n <add key=\"serverUri\" value=\"http://hogehoge.com/service1\"/>\n </appSettings>\n </configuration>\n \n```\n\nクライアントアプリから URL の参照\n\n```\n\n var url = System.Configuration.ConfigurationManager.AppSettings[\"serverUri\"];\n \n```\n\n後は、作成したアプリをdev, staging, production用に異なる3つのフォルダに分けてにコピーし、App.config の\nserverUriのvalue部分を、それぞれのサーバー用に変更します。 そうすれば、ビルドは一つで、サーバーURLの変更の際に、再ビルドは不要になります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T05:32:10.963", "id": "1675", "last_activity_date": "2014-12-16T05:32:10.963", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2099", "parent_id": "241", "post_type": "answer", "score": 3 }, { "body": "基本的には他の方の回答と同じで、ソースコード内のロジックではなく接続先だけを変えたいのであれば、\n設定ファイル(App.config)内に切り出して、環境ごとにビルド構成を作成し設定ファイルを編集する前提で、ソースコードからはその設定ファイルを参照する、という方法でいいかと思います。\n\nただ、ビルド構成ごとに設定ファイルを切り替えるという意味では、同じ .NET でもWebアプリ(ASP.NET)であれば、Web.config\n変換という便利なものがありまして、「devel」「staging」「production」というビルド構成であれば、\n\n * Web.devel.config \n * Web.staging.config\n * Web.producion.config\n\nという3つのファイルを用意して、ビルド時にXSLT変換によってWeb.configというファイルに変換してくれます。(もう一つデプロイ先ごとに変換する仕組みもありますが、この先の話に関係なくなるので割愛します)\n\n前置きが長くなりましたが、クライアントアプリでもこのconfig変換と同じ仕組みを取りいれられる[Configuration Transform\nというVisual\nStudio拡張](https://visualstudiogallery.msdn.microsoft.com/579d3a78-3bdd-497c-bc21-aa6e6abbc859)があります。VisualStudio拡張ですが、一度VisualStudio上で適用すると、この拡張がないVisualStudio上でも、あるいはCIサーバーなどVisualStudioがない環境でも\nConfiguration Transform\nが有効になります。[私のブログ](http://tech.tanaka733.net/entry/configuration-transform-\nvisual-studio-extension)になりますが、使い方を解説しております。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-19T14:04:43.443", "id": "2155", "last_activity_date": "2014-12-19T14:04:43.443", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2431", "parent_id": "241", "post_type": "answer", "score": 3 } ]
241
247
264
{ "accepted_answer_id": "249", "answer_count": 2, "body": "目的はBootstrapベースのCSSをカスタマイズして、\n\nフォーム関連のborder-radiusを変更したい(1px)のですが、\n\nBootstrapは、sassの変数で、\n\n```\n\n $border-radius-base: 1px;\n $border-radius-large: 1px;\n $border-radius-small: 1px;\n \n```\n\nで変更できました。\n\n`input:select`については、\n\n```\n\n select {\n border-radius: 1px !important;\n }\n \n```\n\nが必要でした。 \nここまではよいのですが、Chromeに関しては、\n\n`input:select`で上記のCSSでも角が4px程度のスタイルになってしまいます。\n\n`-webkit-appearance: none;`でChromeのスタイルを解除できるのですが、\n\nBootstrapでのinput-smではpaddingがずれて、select要素(option)が正しく表示されません。\n\n![画像の説明をここに入力](https://i.stack.imgur.com/mVxMT.png)\n\nなので、`-webkit-appearance: none;`を使わずに、\n\nChrome特有のスタイル(角の丸み)を解除(上書き)したいのです。\n\n![画像の説明をここに入力](https://i.stack.imgur.com/uqFqe.png)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T08:44:33.983", "favorite_count": 0, "id": "246", "last_activity_date": "2019-12-13T13:32:47.470", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "512", "post_type": "question", "score": 3, "tags": [ "css", "google-chrome" ], "title": "selectフォームのborder-radiusをChromeでも変更するには?", "view_count": 7463 }
[ { "body": "こういうのはいかがでしょうか。\n\n```\n\n select {\n border: 0;\n outline: 1px solid #ccc;\n outline-offset: -1px;\n }\n \n```\n\n```\n\n div {\n padding: 10px;\n }\n select {\n border: 0;\n outline: 1px solid #ccc;\n outline-offset: -1px;\n }\n```\n\n```\n\n <div>\n <select>\n <option>1st</option>\n <option>2nd</option>\n <option>3rd</option>\n </select>\n </div>\n```\n\n* * *\n\n> 質問者です\n>\n> 試してみました。結果、角にサンカクができてしまいます。\n>\n> ![画像の説明をここに入力](https://i.stack.imgur.com/PPK7D.png)\n\nこちらではどうでしょう? 要は必要な select要素のスタイルを上記で上書きすれば良いと思います。\n\n```\n\n .form-control {\n border: 0;\n outline: 1px solid #ccc;\n outline-offset: -1px;\n }\n \n```\n\n```\n\n div {\n padding: 10px;\n }\n .form-control {\n border: 0;\n outline: 1px solid #ccc;\n outline-offset: -1px;\n }\n```\n\n```\n\n <div>\n <select class=\"form-control\">\n <option>1</option>\n <option>2</option>\n <option>3</option>\n <option>4</option>\n <option>5</option>\n </select>\n </div>\n```", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2014-12-02T09:30:54.407", "id": "249", "last_activity_date": "2019-12-13T13:32:47.470", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "621", "parent_id": "246", "post_type": "answer", "score": 2 }, { "body": "divでborderを引いて、selectで消す。 \n(参考) \n<http://jolie.leetheme.com/product-category/dreeses/?no-sidebar>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2018-01-05T17:54:15.457", "id": "40759", "last_activity_date": "2018-01-05T17:54:15.457", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26897", "parent_id": "246", "post_type": "answer", "score": 0 } ]
246
249
249
{ "accepted_answer_id": "252", "answer_count": 3, "body": "bitbucketに公開鍵を設定したのですがpush時にパスワードを求められてしまいます。パスワードを省略するにはどのようにしたら良いでしょうか?鍵にパスフレーズは設定していません。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T09:32:29.773", "favorite_count": 0, "id": "250", "last_activity_date": "2015-07-06T03:05:57.673", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "37", "post_type": "question", "score": 3, "tags": [ "git", "bitbucket", "ssh" ], "title": "bitbucketに公開鍵を設定したのにpush時にパスワードを求められる", "view_count": 8504 }
[ { "body": "`https:` のURLが登録されているのでは? `git@bitbucket.org:` であれば聞かれないと思います。\n\n```\n\n git remote -v\n \n```\n\nでリモートのURLを確認してみてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T09:52:09.573", "id": "251", "last_activity_date": "2014-12-02T09:52:09.573", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "621", "parent_id": "250", "post_type": "answer", "score": 1 }, { "body": "**SSH** ではなく **HTTPS** でクローンしていませんか?`remote`を確認してみてください。\n\n## remoteの確認\n\nremoteの確認:\n\n```\n\n $ cat .git/config\n \n```\n\n例えば、`.git/config`のurlがhttpsから始まっているのであればHTTPSでクローンしています。\n\n```\n\n [remote \"origin\"]\n fetch = +refs/heads/*:refs/remotes/origin/*\n url = https://user@bitbucket.org/USERNAME/therepo.git\n \n```\n\nHTTPSでクローンしている場合は以下の画像のようにHTTPSからSSHに変更してクローンをするためのURLを取得してください。\n\n![画像の説明をここに入力](https://i.stack.imgur.com/iPKD6.png)\n\n## remoteの変更方法\n\n```\n\n $ git remote set-url origin SSL_URL\n \n```\n\n例:\n\n```\n\n $ git remote set-url origin git@github.com:USERNAME/therepo.git\n \n```\n\n### 参照リンク\n\n * [Git on Bitbucket: Always asked for password, even after uploading my public SSH key](https://stackoverflow.com/questions/8600652/git-on-bitbucket-always-asked-for-password-even-after-uploading-my-public-ssh)\n * [Push updates to a repo](https://confluence.atlassian.com/display/BITBUCKET/Push+updates+to+a+repo)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T10:03:20.563", "id": "252", "last_activity_date": "2014-12-02T14:31:36.157", "last_edit_date": "2017-05-23T12:38:55.307", "last_editor_user_id": "-1", "owner_user_id": "556", "parent_id": "250", "post_type": "answer", "score": 7 }, { "body": "もし、上記のような状態であれば、下記のコマンドでURLを変更できます。\n\n```\n\n $ git remote set-url origin [SSH_url]\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T10:08:10.477", "id": "253", "last_activity_date": "2015-07-06T03:05:57.673", "last_edit_date": "2015-07-06T03:05:57.673", "last_editor_user_id": "-1", "owner_user_id": "521", "parent_id": "250", "post_type": "answer", "score": 1 } ]
250
252
252
{ "accepted_answer_id": null, "answer_count": 3, "body": "HTML5で画像を回転させて表示させると、斜めになった画像の縁の部分がギザギザになってしまいます。このジャギを回避する方法はないでしょうか?", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T11:36:25.360", "favorite_count": 0, "id": "257", "last_activity_date": "2020-01-22T19:51:26.640", "last_edit_date": "2014-12-03T01:11:04.520", "last_editor_user_id": "658", "owner_user_id": "658", "post_type": "question", "score": 5, "tags": [ "javascript", "css", "html5" ], "title": "HTML5で画像を回転させると縁にジャギが出てしまう", "view_count": 1854 }
[ { "body": "画像を上下左右1ピクセル大きくして、1ピクセル幅の透明の縁をつけると、回転してもジャギらなくなります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T11:36:25.360", "id": "258", "last_activity_date": "2014-12-02T11:36:25.360", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "658", "parent_id": "257", "post_type": "answer", "score": 1 }, { "body": "ジャギの出るのはどのブラウザでもでしょうか? \nFirefoxであれば下記が参考になるかと思います。\n\n<https://stackoverflow.com/questions/9235342/3d-css-transform-jagged-edges-in-\nfirefox>\n\n```\n\n body {\r\n -moz-perspective: 800px;\r\n }\r\n \r\n div {\r\n -moz-transform: rotateX(45deg);\r\n border: 1px solid white;\r\n }\n```\n\n```\n\n <div style=\"display:inline-block; width:10em; height:10em; background:hotpink;margin-left:8em;\"></div>\n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2014-12-03T02:15:13.433", "id": "286", "last_activity_date": "2019-12-13T13:45:40.200", "last_edit_date": "2019-12-13T13:45:40.200", "last_editor_user_id": "32986", "owner_user_id": "621", "parent_id": "257", "post_type": "answer", "score": 1 }, { "body": "imgへの`transform:\nrotate();`の適用でもcanvasでもそうなのですが、どちらもベクターではなくピクセル操作になるので、計算上端数が出るとジャギが見えると思いますし、ディスプレイのppiでも影響するので完全なコントロールは難しいかもしれませんね。 \n前述の制約があるとして、その中で工夫するのであれば\n\n * borderを使ってnピクセルぶんの縁を作ってベクターラインで囲む\n * `box-shadow`を使ってドロップシャドウを生成してジャギが目立つ部分側に適用する\n * 表示するサイズの2倍のイメージを用意して、サイズ指定で50%表示で使うことでサンプリング数をあげる\n\nあたりを組み合わせて試してみると良いと思います。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2014-12-03T02:48:14.647", "id": "292", "last_activity_date": "2020-01-22T19:51:26.640", "last_edit_date": "2020-01-22T19:51:26.640", "last_editor_user_id": "32986", "owner_user_id": "248", "parent_id": "257", "post_type": "answer", "score": 7 } ]
257
null
292
{ "accepted_answer_id": "270", "answer_count": 2, "body": "例えば、SassやCoffeeScriptのファイル保存時のコンパイルなどを想定していますが、できるだけ特定の実行環境(Nodeとか)に依存せず、導入が簡単なものが望ましいです。 \nOSデフォルトの機能だけで実現できればそれが一番よいです。\n\nWindowsのバージョンはVista(Server\n2008)以降を想定しています。特定のバージョンのみで動作する場合には、その旨記載していただければ有難いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T12:07:42.150", "favorite_count": 0, "id": "260", "last_activity_date": "2014-12-02T17:40:14.670", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "645", "post_type": "question", "score": 8, "tags": [ "windows" ], "title": "Windowsでファイルの変更を監視して何かタスクを実行したい", "view_count": 18072 }
[ { "body": "SassやCoffeeScriptのwatchやコンパイルを行えるWindows対応のソフトだと、以下等があります。 \n<https://prepros.io/> \n<http://koala-app.com/> \nOSバージョンの対応状況まではわかりませんが、最近のOSであれば問題なく動くと思います。\n\n単純に、ファイル変更を監視して何かしたいのであれば、汎用なファイル変更検知ソフトもあります。 \n<http://www.forest.impress.co.jp/library/software/folderkanshi/> \nこの手のソフトの場合、変更検知時に好きなコマンドを実行できるタイプが好ましいのではないでしょうか。batファイルの実行もできますので。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T13:17:56.120", "id": "262", "last_activity_date": "2014-12-02T13:17:56.120", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "589", "parent_id": "260", "post_type": "answer", "score": 3 }, { "body": "確認まではしていませんが、Vista 以降でしたら`System.IO.FileSystemWatcher`を\npowershellから使えるかもしれません。 参考までに同期処理だと以下の様になります。 ( WaitForChanged 中は ctrl-C\nで止まらないので、ウィンドウを閉じるか、ctrl-cを押したのち、監視対象のファイルなどの変更を行ってください )\n\n実際には非同期処理の方がいいかと思います。\n\n```\n\n $w = New-Object System.IO.FileSystemWatcher\n $w.Path = \"c:\\\\path\\\\to\\\\dir\"\n $w.Filter = \"*.*\"\n $w.NotifyFilter = [System.IO.NotifyFilters]::LastWrite\n \n while(1){\n \n $changeResult = $w.WaitForChanged([System.IO.WatcherChangeTypes]::All)\n # $changeResult.TimeOut が trueなら、タイムアウト\n \n # 好みのコマンドを実行する。\n .\\run_something.bat $changeResult.Name\n \n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T17:40:14.670", "id": "270", "last_activity_date": "2014-12-02T17:40:14.670", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "728", "parent_id": "260", "post_type": "answer", "score": 11 } ]
260
270
270
{ "accepted_answer_id": null, "answer_count": 2, "body": ".mlファイルの中のOCamlコードで、以下のようなコードを書いた際、\n\n```\n\n let print_for_print_test str =\n for i = 0 to String.length-1 str do\n print_string(str)\n print_newline()\n done;;\n \n```\n\n3行目に `;` が足りない、という意味のエラーメッセージが出ました。実際に `;` を補えばうまくいったのですが、OCamlでの `;` と `;;`\nの違いがよく分かりません。よろしければご教授お願いします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2014-12-02T13:50:47.863", "favorite_count": 0, "id": "263", "last_activity_date": "2021-03-10T14:59:42.623", "last_edit_date": "2021-03-10T14:59:42.623", "last_editor_user_id": "3060", "owner_user_id": "667", "post_type": "question", "score": 10, "tags": [ "ocaml" ], "title": "OCamlの ; と ;; の違いが分からない", "view_count": 826 }
[ { "body": "[こちら(ocaml.org)](https://ocaml.org/learn/tutorials/structure_of_ocaml_programs.ja.html#_4)\nが参考になると思います。\n\n一部を抜粋します。\n\n> ルール1。;;を使うべきときとは、コードのトップレベルにある文を区切るときだ。関数定義の中のときや、他の文のときは、いらない。\n>\n> ルール3と4は、一重の;についてだ。こいつは、;;とは完全に別物だ。セミコロンひとつの;は、\n> シークエンスポイントということになっている。言ってみれば、これは、C、C++、Java、Perlのセミコロンひとつと全く同じことである。\n\n* * *\n\n3行目のみ必要な点については、 4行目はブロックの最後なので `;`が無くても式の終わりがわかりますが、 3行目はそうではないので 式の区切りを示す `;`\nが必要となります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T17:56:44.847", "id": "271", "last_activity_date": "2014-12-03T13:02:11.443", "last_edit_date": "2014-12-03T13:02:11.443", "last_editor_user_id": "728", "owner_user_id": "728", "parent_id": "263", "post_type": "answer", "score": 9 }, { "body": "仕様を見てみましょう。\n\n<http://caml.inria.fr/pub/docs/manual-ocaml-400/language.html>\n\n<http://caml.inria.fr/pub/docs/manual-ocaml-400/manual020.html>\n\nCompilation unitsとspecification,definitionを抜粋すると以下のように定義されています。\n\n```\n\n unit-interface ::= { specification [;;] } \n unit-implementation ::= { definition [;;] } \n \n specification ::= val value-name : typexpr \n ∣ external value-name : typexpr = external-declaration \n ∣ type-definition \n ∣ exception constr-decl \n ∣ class-specification \n ∣ classtype-definition \n ∣ module module-name : module-type \n ∣ module module-name { ( module-name : module-type ) } : module-type \n ∣ module type modtype-name \n ∣ module type modtype-name = module-type \n ∣ open module-path \n ∣ include module-type \n \n definition ::= let [rec] let-binding { and let-binding } \n ∣ external value-name : typexpr = external-declaration \n ∣ type-definition \n ∣ exception-definition \n ∣ class-definition \n ∣ classtype-definition \n ∣ module module-name { ( module-name : module-type ) } [ : module-type ] = module-expr \n ∣ module type modtype-name = module-type \n ∣ open module-path \n ∣ include module-expr\n \n```\n\nOCamlには定義と仕様(まとめて文と呼ぶ)と式の3つがあり、文の区切りには;;を使い、;は式を連続して記述する事に使うと覚えると良さそうです。;;は省略可能ですが、トップレベルや必要なときに使います。\n\nlet a = 1は定義で、 \nval a:intが仕様で、 \nlet b = 1 in bは式です。\n\n```\n\n let a = ();();();1;;\n \n```\n\nはaに1を定義しています。 \n文として式を書く事も出来るのでトップレベルに式を並べて\n\n```\n\n 1;;\n 2;;\n let b = 1 in b;;\n 3\n \n```\n\nのように書く事も出来ます。 \n式を文として連続して書くような場合は;;を書く必要があります。\n\n```\n\n f\n 1\n \n```\n\nと書くとOCamlでは改行は意味を持たないのでf関数に引数1を適用する意味になります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-01-19T11:54:47.257", "id": "4847", "last_activity_date": "2015-01-19T11:54:47.257", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7532", "parent_id": "263", "post_type": "answer", "score": 3 } ]
263
null
271
{ "accepted_answer_id": "266", "answer_count": 1, "body": "webviewの設定で、\n\n下記のように設定しないとピンチインアウトが出来ないのですが、 Controllerを非表示にできないのでしょうか?\n\n```\n\n WebSettings settings = webview.getSettings();\n settings.setSupportZoom(true);\n settings.setBuiltInZoomControls(true);\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T14:38:29.943", "favorite_count": 0, "id": "265", "last_activity_date": "2014-12-04T13:25:57.833", "last_edit_date": "2014-12-04T13:25:57.833", "last_editor_user_id": "30", "owner_user_id": "299", "post_type": "question", "score": 4, "tags": [ "android", "webview" ], "title": "androidのwebviewでピンチインピンチアウトのコントローラーを非表示", "view_count": 1271 }
[ { "body": "下記を設定したら非表示に出来ました。 APIが11以上で対応しているようです。\n\n```\n\n settings.setDisplayZoomControls(false);\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T14:38:29.943", "id": "266", "last_activity_date": "2014-12-02T14:38:29.943", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "299", "parent_id": "265", "post_type": "answer", "score": 7 } ]
265
266
266
{ "accepted_answer_id": "274", "answer_count": 4, "body": "Python 3.3.5 + Flaskでサーバアプリを作っています。\n\n## 内容\n\nFlaskにHTTPリクエストを送ると即座にレスポンスを返してくれますが、\n\n * 2つ以上のリクエストを同時に送る\n\nもしくは\n\n * 早かった方のリクエストの処理中に続けてリクエストを送る\n\nといった事をすると、遅かった方のリクエストのレスポンスは早かった方へのレスポンスが完了するまで待たされます。\n\n単一スレッドで処理しているだからだと思われますが、これをFlaskで並列処理できる方法はありませんでしょうか。\n\n## テストに使ったコード\n\n```\n\n if __name__ == '__main__':\n app = Flask(__name__)\n app.config.update(PROPAGATE_EXCEPTIONS = True)\n \n @app.route('/')\n def greet():\n n = randrange(1, 10)\n sleep(n)\n return 'Hello world! I slept {0}[s].'.format(str(n))\n \n app.run()\n \n```\n\nこれは、リクエストが飛んできたら乱数を元に1 - 10秒待ち何秒待ったか返すコードです。\n\nブラウザのタブを2つ用意し、両方素早くlocalhost:5000へアクセスすると、先にアクセスした方にレスポンスが返ってきてから後の方の待つフェーズが始まることが待ち時間からわかります。\n\nもしFlaskが並列でレスポンスを返すことができたら、待ち時間の乱数が小さかったほうが先に返ってくるはずです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T18:26:57.763", "favorite_count": 0, "id": "272", "last_activity_date": "2014-12-16T04:33:44.997", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "197", "post_type": "question", "score": 7, "tags": [ "python", "flask" ], "title": "Flaskにおける複数リクエストの並列処理", "view_count": 15457 }
[ { "body": "flask.Flask.runのオプションにprocessesまたはthreadedを指定する事で可能だと思います。\nwindows環境ではforkがないためproessesはエラーとなりました。\n\n```\n\n app.run(processes=3)\n \n```\n\nまたは\n\n```\n\n app.run(threaded=true)\n \n```\n\n別のブラウザから同時アクセスして同時に処理されることを確認しました。\n\nrunのオプションはwerkzeugに渡されるそうなのでoptionsに関してはWerkzeugのドキュメントを参照する必要があります。\n\n> * options – the options to be forwarded to the underlying Werkzeug server.\n> See werkzeug.run_simple() for more information.\n>\n\n[Flask.run\n(bitbucket.org)](http://a2c.bitbucket.org/flask/api.html?highlight=flask#flask.Flask.run) \n[werkzeug parameters (pocoo.org)](http://werkzeug.pocoo.org/docs/0.9/serving/)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T23:22:48.073", "id": "274", "last_activity_date": "2014-12-02T23:29:33.670", "last_edit_date": "2014-12-02T23:29:33.670", "last_editor_user_id": "728", "owner_user_id": "728", "parent_id": "272", "post_type": "answer", "score": 5 }, { "body": "gunicornやwaitress, cherrypyなどのwsgiサーバーを使えばよいでしょう。\nとりあえずflaskのサイトにはcherrypyで実行する例がありました。\n\n<http://flask.pocoo.org/snippets/24/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-12T08:58:39.607", "id": "1542", "last_activity_date": "2014-12-12T08:58:39.607", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2167", "parent_id": "272", "post_type": "answer", "score": 3 }, { "body": "asyncioを使うことでI/Oを多重化する方法があります。\n\nPython3.3上でasyncioを使ったflaskアプリを作成するには、次のことが必要です。\n\n 1. asyncioをインストールする\n\nasyncioは、Python 3.4では標準ライブラリの一つですが、 Python 3.3では、asyncioを別途インストールすることで使用できます。\n\n<https://pypi.python.org/pypi/asyncio>\n\n 2. asyncioに対応したflaskを使う\n\nasyncioを使うように手を入れたflaskがいくつか公開されているようです。 例えば、以下のものが見つかりました。\n\n<https://pypi.python.org/pypi/Flask-Async/0.11-dev-20140215>\n\ngunicornなどのような、preforkを行うwsgiサーバと組み合わせることも可能です。\n\nなお、テストコードにあるようなsleep文は、\n\n```\n\n yield from asyncio.sleep(n)\n \n```\n\nに書き換えます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T01:55:59.180", "id": "1626", "last_activity_date": "2014-12-16T04:33:44.997", "last_edit_date": "2014-12-16T04:33:44.997", "last_editor_user_id": "2430", "owner_user_id": "2430", "parent_id": "272", "post_type": "answer", "score": 3 }, { "body": "Flask.run() は開発用サーバーであり、実際にサービスを提供するために利用するためのものではありません。 一般的な構成には、\n\n * 静的ファイル配信を nginx で行い、 nginx からリバースプロキシして gunicorn か uWSGI で Flask アプリを動かす。\n * Apache と mod_wsgi を使う。\n\nといった選択肢があります。個人的には前者がお勧めです。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T03:39:05.863", "id": "1653", "last_activity_date": "2014-12-16T03:39:05.863", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3019", "parent_id": "272", "post_type": "answer", "score": 10 } ]
272
274
1653
{ "accepted_answer_id": "279", "answer_count": 1, "body": "SQL Serverで下記のクエリーを作りました:\n\n```\n\n SELECT dateadd(hour, datediff(hour, 0, CreationDate), 0), COUNT(*)\n FROM Table\n GROUP BY dateadd(hour, datediff(hour, 0, CreationDate), 0)\n \n```\n\n結果は一時間ごとにその時間の新しいレコードになります:\n\n```\n\n 12/2/14 0:00 174\n 12/2/14 1:00 108\n 12/2/14 2:00 84\n 12/2/14 3:00 48\n 12/2/14 4:00 21\n \n```\n\n累計をしたい場合に、どう変換すればいいですか?\n\n目指している結果は下記です:\n\n```\n\n 12/2/14 0:00 174\n 12/2/14 1:00 282\n 12/2/14 2:00 366\n 12/2/14 3:00 414\n 12/2/14 4:00 435\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T23:36:13.017", "favorite_count": 0, "id": "275", "last_activity_date": "2014-12-03T03:39:52.483", "last_edit_date": "2014-12-03T03:39:52.483", "last_editor_user_id": "85", "owner_user_id": "10", "post_type": "question", "score": 4, "tags": [ "sql", "sql-server" ], "title": "SQL Serverで日時ごとの件数の累積値を出力するSQL", "view_count": 5634 }
[ { "body": "window関数を使うといいと思います。 \nSQL Fiddleにサンプルコードを載せました。\n\n<http://sqlfiddle.com/#!6/e30e7/7>\n\n参考までにコードを転記しておきます。\n\n```\n\n create table some_log (\n CreationDate datetime\n )\n \n insert some_log values ('2014-12-02 00:10')\n insert some_log values ('2014-12-02 00:20')\n insert some_log values ('2014-12-02 00:30')\n insert some_log values ('2014-12-02 01:10')\n insert some_log values ('2014-12-02 02:10')\n insert some_log values ('2014-12-02 02:10')\n \n WITH count_by_hour AS\n (SELECT dateadd(hour, datediff(hour, 0, CreationDate), 0) AS datetime,\n COUNT(*) AS cnt\n FROM some_log\n GROUP BY dateadd(hour, datediff(hour, 0, CreationDate), 0))\n SELECT datetime,\n cnt,\n SUM(cnt) over(ORDER BY datetime) AS cum_cnt\n FROM count_by_hour\n ORDER BY datetime\n \n```\n\n実行結果\n\n![画像の説明をここに入力](https://i.stack.imgur.com/ibAqp.png)\n\nwindow関数の詳しい使い方はこちらです。\n\n<http://msdn.microsoft.com/ja-jp/library/ms189461.aspx>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T00:14:47.637", "id": "279", "last_activity_date": "2014-12-03T00:14:47.637", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "parent_id": "275", "post_type": "answer", "score": 6 } ]
275
279
279
{ "accepted_answer_id": "299", "answer_count": 1, "body": "TestFlight の外部テストでは問題なく Facebook ログインができているのにも関わらず、Apple のレビューでログインができず、何度も\nReject となってしまいます。\n\nApple からの回答は下記の通り。\n\n> We found that your app exhibited one or more bugs, when reviewed on iPad\n> running iOS 8.1.1 and iPhone 5s running iOS 8.1.1, on both Wi-Fi and\n> cellular networks, which is not in compliance with the App Store Review\n> Guidelines.\n>\n> We are still unable to log into your app with Facebook. We are presented\n> with the error message 'ユーザーはこのアプリケーションを見ることを許可されていません。:\n> 開発者の設定により、ユーザーはこのアプリケーションを見ることを許可されていません。'\n\n * バックエンドに Parse を使用。\n * 手元では、TestFlight の内部テスター版、外部テスター版ともに問題なく動作している。\n * Facebook のアプリ設定のステータスは「This app is public and available to all users」となっている。\n * Facebook の Approved Items は email, public_profile, user_friends で、アプリで指定しているものは、public_profile, user_friends のみ。\n * Facebook の Country Restricted は NO(制限なし)に設定されている。\n\n同様の問題を解決された方、解決法やヒントを頂けると助かります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T23:44:02.460", "favorite_count": 0, "id": "276", "last_activity_date": "2014-12-21T22:30:26.163", "last_edit_date": "2014-12-21T22:30:26.163", "last_editor_user_id": "208", "owner_user_id": "435", "post_type": "question", "score": 10, "tags": [ "ios", "facebook", "appstore-approval", "parse.com" ], "title": "Apple のレビューにて iOS アプリの Facebook ログインができない", "view_count": 2593 }
[ { "body": "このエラーメッセージは、英語では以下になるようです1:\n\n> User is not allowed to see the application.: The user is not allowed to see\n> this application per the developer set configuration.\n\nこれで検索するといくつか原因が出てきます:\n\n * Apple側のレビュワーがFacebookのテスト用アカウントでログインしようとしていた2, 3\n * → Appleにテスト用アカウントを使わずにテストするように言う\n * レビュワーのFacebookアカウントがブロックされていた3\n * Facebookアプリの設定でNamespaceを設定していなかった3\n * FacebookアプリのシークレットIDがParseの設定からなぜか消えていた3\n\n外部テスターで問題が出ていないということはレビュワーが使っているアカウントの問題かもしれません。\n\n* * *\n\n1\n[Facebookの公式翻訳アプリ](https://www.facebook.com/help/100117036792266)で、[日本語のエラーメッセージを検索](https://www.facebook.com/help/100117036792266)しました。 \n2 [Error With Facebook Login Using Test\nUsers](http://samwize.com/2014/07/23/error-with-facebook-login-using-test-\nusers/) \n3 [Facebook login error “User is not allowed to see the\napplication.”](https://stackoverflow.com/q/24960053/20226)", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T04:07:57.880", "id": "299", "last_activity_date": "2014-12-03T04:07:57.880", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "30", "parent_id": "276", "post_type": "answer", "score": 8 } ]
276
299
299
{ "accepted_answer_id": "278", "answer_count": 3, "body": "githubでgo言語で書かれたリポジトリをforkして作業するときに、import文がずれるのはどうやって解消するのがいいのでしょうか?\n\n例えば、hogeさんのfoobarリポジトリからforkしてくると、\n\n```\n\n import \"github.com/hoge/foobar/client\"\n \n```\n\nのようにインポートされています。\n\nhogeの部分を自分のユーザ名に書き換えても、pull requestを送るときに戻すのがめんどくさいですし、そもそもちゃんと管理できません。。。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T23:51:30.763", "favorite_count": 0, "id": "277", "last_activity_date": "2014-12-05T05:23:44.787", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "181", "post_type": "question", "score": 8, "tags": [ "git", "go", "github" ], "title": "githubでforkしたgo言語のリポジトリのimport文がずれる", "view_count": 663 }
[ { "body": "こちらの方法が良いと思います: \n[GithubのGo言語プロジェクトにPull Requestを送るときのimport問題 |\nSOTA](http://deeeet.com/writing/2014/07/23/golang-pull-request/)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-02T23:52:36.127", "id": "278", "last_activity_date": "2014-12-02T23:52:36.127", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "55", "parent_id": "277", "post_type": "answer", "score": 3 }, { "body": "手順を書いときます。\n\n 1. オリジナルをGOPATH上の正しい場所に clone する \n`git clone git@github.com:wizard/awesome.git`\n\n 2. github で fork する\n 3. オリジナルと同じワーキングディレクトリの remote に fork を追加する \n`git remote add mine git@github.com:myname/awesome.git`\n\n 4. 作業ブランチを作って修正を行う `git checkout -b newfeature`\n 5. 自分のレポジトリに push する `git push -u mine newfeature`\n 6. pull request を作る\n\nGOPATH上でのディレクトリレイアウトを、オリジナルレポジトリに合わせしまうのです。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T00:18:48.707", "id": "280", "last_activity_date": "2014-12-05T05:23:44.787", "last_edit_date": "2014-12-05T05:23:44.787", "last_editor_user_id": "208", "owner_user_id": "208", "parent_id": "277", "post_type": "answer", "score": 9 }, { "body": "対象のリポジトリが対象ユーザの import 構成になっているので、自分のリポジトリ内で作業するともちろん正しくビルド出来ません。 PR を送る目的ならば\nimport 等は書き換えず対象ユーザのリポジトリ内で作業すべきかと思います。\n\n例えば hoge さんが foo さんのリポジトリ bar に対して PR を送る場合、GOPATH 内で foo/bar を git clone します。\n\n```\n\n mkdir -p /path/to/GOPATH/src/github.com/foo\n cd /path/to/GOPATH/src/github.com/foo\n git clone https://github.com/foo/bar\n cd bar\n \n```\n\nPR 用のブランチを作成\n\n```\n\n git checkout -b feature-branch\n vim kanari-sugoi.go\n git commit -a -m \"Super awesome changes\"\n \n```\n\nhub コマンド等で fork\n\n```\n\n hub fork\n git push hoge feature-branch\n \n```\n\n自分のリポジトリに foo/bar を push します。\n\n後は github.com/foo/bar を見に行けば pull-request ボタンが押せる様になっているはずです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T01:49:22.943", "id": "285", "last_activity_date": "2014-12-03T01:49:22.943", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "440", "parent_id": "277", "post_type": "answer", "score": 7 } ]
277
278
280
{ "accepted_answer_id": null, "answer_count": 1, "body": "OSXプログラミングをしていて、Control-F4\nといったキーボードショートカットのキーシーケンスをアプリで生成したいのですが、`CGEventCreateKeyboardEvent` と\n`CGEventPost` を使ってもうまくいきません。`CGPostKeyboardEvent`\nを使って同様のキーストロークを発生した場合にはうまく動きました。しかしながら、`CGPostKeyboardEvent` は deprecated\nになってしまったので、別の方法をさがしています。\n\n```\n\n CGPostKeyboardEvent((CGCharCode)0, (CGKeyCode)118/*F4*/, true); // worked\n \n CGEventPost(kCGHIDEventTap, CGEventCreateKeyboardEvent(NULL, (CGKeyCode)118/*F4*/, true)); // doesn't work\n \n```\n\nどのようにすれば、`CGPostKeyboardEvent`\nのようにキーボードショートカットのアプリでの実行ができるようになるかお教えいただけると幸いです。こういった、システムにかかわるキーボードショートカットを発行できてしまうことが、`CGPostKeyboardEvent`\nが deprecated になってしまった理由ではないかと思わなくもないのですが…", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T00:55:29.927", "favorite_count": 0, "id": "283", "last_activity_date": "2014-12-03T22:26:29.313", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "658", "post_type": "question", "score": 5, "tags": [ "macos", "objective-c", "quartz" ], "title": "CGEventCreateKeyboardEvent と CGEventPost の組み合わせで CGPostKeyboardEvent でできたことを実現したい", "view_count": 846 }
[ { "body": "たとえば以下のようにすれば良いと思います。\n\n```\n\n #import <Foundation/Foundation.h>\n #import <Carbon/Carbon.h>\n \n int main(int argc, const char * argv[]) {\n @autoreleasepool {\n CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);\n \n CGEventRef f4 = CGEventCreateKeyboardEvent(source, kVK_F4, true);\n CGEventSetFlags(f4, kCGEventFlagMaskControl);\n CGEventTapLocation location = kCGHIDEventTap;\n \n CGEventPost(location, f4);\n \n CFRelease(f4);\n CFRelease(source);\n }\n return 0;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T22:26:29.313", "id": "330", "last_activity_date": "2014-12-03T22:26:29.313", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "238", "parent_id": "283", "post_type": "answer", "score": 4 } ]
283
null
330
{ "accepted_answer_id": null, "answer_count": 1, "body": "processing.js を使っているのですが、その描画でグラデーションを使いたいです。この例\n<http://processingjs.org/learning/basic/lineargradient/>\nのように線を一本づつ描くと効率が悪いように思えます。他に何か良い手はありませんでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T01:04:41.550", "favorite_count": 0, "id": "284", "last_activity_date": "2014-12-03T23:38:33.623", "last_edit_date": "2014-12-03T23:38:33.623", "last_editor_user_id": "46", "owner_user_id": "658", "post_type": "question", "score": 3, "tags": [ "processing" ], "title": "processing.js でグラデーションを使った描画をしたい", "view_count": 830 }
[ { "body": "いろいろ彷徨ってみましたが、processing.jsには効率の良いグラデーションの実装がないようですね...\n\n諦めてHTML5のgradientを使うしかない、という投稿を見ました。\n\n * [Question about gradient fill](https://groups.google.com/forum/#!topic/processingjs/BeryyzkQ31I)\n * [線形グラデーションを指定する](http://www.html5.jp/canvas/how4.html)\n\nそんなわけで、普通にcanvasのcontextとってきてcreateLinearGradient使えばいいのかなと思いますが、いかがでしょうか。\n[Understanding Rendering Modes in\nProcessing.js](http://processingjs.org/articles/RenderingModes.html)のAccessing\nthe Raw Canvas Context -\nAdvanced:という項によれば、externalsキーワードを使うとcanvas/contextにアクセスできるようです。\n\n```\n\n <html>\n <head>\n <script src=\"processing.js\">\n </script>\n <script>\n window.onload = function(){\n var canvas = document.getElementsByTagName('canvas')[0];\n var codeElm = document.getElementById('processing-code');\n var code = codeElm.textContent || codeElm.innerText;\n new Processing(canvas, code);\n };\n </script>\n <script id=\"processing-code\" type=\"application/processing\">\n void setup() {\n size(externals.canvas.width, externals.canvas.height);\n frameRate(60);\n }\n void draw() {\n var currentContext = externals.context;\n currentContext.beginPath();\n var gradient = currentContext.createLinearGradient(0, 0, 0, canvas.height);\n gradient.addColorStop(0, 'white');\n gradient.addColorStop(1, 'blue');\n currentContext.fillStyle = gradient;\n currentContext.rect(0, 0, canvas.width, canvas.height);\n currentContext.fill();\n ellipse(width/2, height/2, 100, 100);\n }\n </script> \n </head>\n <body>\n <canvas id=\"canvas\" width=\"250\" height=\"250\"></canvas>\n </body>\n </html>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T18:14:37.240", "id": "322", "last_activity_date": "2014-12-03T19:00:38.063", "last_edit_date": "2014-12-03T19:00:38.063", "last_editor_user_id": "351", "owner_user_id": "351", "parent_id": "284", "post_type": "answer", "score": 4 } ]
284
null
322
{ "accepted_answer_id": "307", "answer_count": 2, "body": "例えば \n1,[title,description,link,imgUrl]を持ったjsonをURLから取得 \n2,下記のようなtableを作ってクリック時にsequeにlinkを渡す \nというような事がしたいです。\n\n* * *\n\n**title** \n| | description,description \n| img | description,description \n| | description,description \n\n* * *\n\njsonを取って来てtitleを通常テーブルに入れるところまでは下記の実装でできました。\n\n```\n\n - (void)getJSON:(NSURL*)url\n {\n //NSURL *url = [NSURL URLWithString:@\"http://itunes.apple.com/jp/rss/topfreeapplications/limit=10/json\"];\n NSURLRequest *request = [NSURLRequest requestWithURL:url];\n \n [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {\n \n NSLog(@\"json ok\");\n NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];\n \n // データの配列をプロパティに保持\n self.items = [jsonDictionary objectForKey:@\"items\"]\n \n NSLog(@\"%d\",(int)[self.items count]);\n \n // TableView をリロード\n [self.tableView reloadData];\n }];\n }\n \n \n // テーブルセルの内容を設定\n - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath\n {\n static NSString *CellIdentifier = @\"Cell\";\n \n UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];\n if (cell == nil) {\n cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];\n cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;\n }\n \n NSDictionary *item = [self.items objectAtIndex:indexPath.row];\n // titleを設定\n cell.textLabel.text = [item objectForKey:@\"title\"];\n //cellにdescriptionを設定\n //cellにimageを設定\n //cellを押した時に発生するsequeを指定、link要素を渡す\n return cell;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T02:17:57.680", "favorite_count": 0, "id": "287", "last_activity_date": "2014-12-03T18:40:36.243", "last_edit_date": "2014-12-03T05:50:38.347", "last_editor_user_id": "525", "owner_user_id": "525", "post_type": "question", "score": 2, "tags": [ "ios", "json", "uitableview" ], "title": "iOSでjsonを取得してカスタムのtableViewに流し込みたい", "view_count": 914 }
[ { "body": "JSONの取得は実装出来ているとのことなので、以下の2.のみ回答させて頂きます。\n\n> 2,下記のようなtableを作ってクリック時にsequeにlinkを渡す というような事がしたいです。\n\nこちら、実現するためには大きくわけて以下の2つの処理が出来れば恐らく意図していることを実装できるかと思います。\n\n1.UITableViewのCellをカスタマイズ\n\n2.Cellがタップされたイベントを検知し、処理を実装\n\nそれでは、以下個別に詳細となります。\n\n**1.UITableViewのCellをカスタマイズする方法**\n\n単一のテキスト以外の情報をCell上に表示したい場合、必要となる各要素のViewを作成しcellのsubviewとすることで実現できます。下記は受け取ったdescriptionのテキストを出力するUILabelを作成し、cell上に配置する処理の例です。画像の場合も、同様にUIImageをcellにaddSubviewすることで表示することが出来ます。また、下記ではコードで実装していますがStoryboardを利用して実装している場合は、そちらからこれらの要素を配置することも可能です。\n\n```\n\n // テーブルセルの内容を設定\n - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath\n {\n static NSString *CellIdentifier = @\"Cell\";\n \n UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];\n if (cell == nil) {\n cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];\n cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;\n }\n // description用のLabelを作成し配置する例\n NSDictionary *item = [self.items objectAtIndex:indexPath.row];\n UILabel *descriptionLabel = [[UILabel alloc] init];\n descriptionLabel.textColor = [UIColor blackColor];\n descriptionLabel.font = [UIFont fontWithName:@\"AppleGothic\" size:12];\n descriptionLabel.text = [item objectForKey:@\"description\"];\n [descriptionLabel sizeToFit];\n [cell addSubview:descriptionLabel];\n // 上記と同様に必要なViewを作成し、CellにaddSubviewして、座標を調整することで\n // 意図するUIを作れると思います。\n \n // ~ 以下省略 ~\n \n```\n\nなお、分かりやすく表現するために上記ではController上に処理を書いていますが今回の用にCellに複数の要素を配置しカスタマイズする場合は、UITableViewCellを継承したサブクラスを作成することが推奨されます。\n\n参考: <http://ios-practice.readthedocs.org/en/latest/docs/tableview/>\n\nまた、URLから画像から読み込んで表示する方法については下記に参考となりそうな記事があったのでこちらも共有しておきます。\n\n参考 <http://qiita.com/EntreGulss/items/d7d9fb5d0b93eb509d43>\n\n**2.Cellがタップされたイベントを検知する方法**\n\nUITableViewControllerは、Cellのタップを検知したときにdidSelectRowAtIndexPathメソッドをコールします。そこで、現在実装されているControllerのクラス(UITableViewControllerを継承したものなはず)上でこのメソッドをオーバーライドすることで、Cellがタップされたときのイベント処理を実装することが出来ます。\n\n```\n\n // Cellがタップされた時に以下のメソッドがコールされる\n - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath\n {\n NSDictionary *item = [self.items objectAtIndex:indexPath.row];\n NSString *linkURL = NSS[item objectForKey:@\"link\"];\n // 画面遷移処理を実装\n }\n \n```\n\n上記でセルをカスタマイズしてタップ時に遷移、というのは実装できると思いますがいかがでしょうか。。。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T09:29:59.387", "id": "307", "last_activity_date": "2014-12-03T09:29:59.387", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "766", "parent_id": "287", "post_type": "answer", "score": 4 }, { "body": "> クリック時にsequeにlinkを渡す\n\n(sequeってsegueですよね)\n\n他の回答で「UITableViewのCellをカスタマイズする方法」と「`didSelectRowAtIndexPath`でCell選択を検知する方法」は出てますので、この回答では\n**Segueを使って選択されたCellに関する情報を保持しながら遷移する方法** についてのみ説明します。\n\n今回の例ではTableViewControllerの`Custom\nClass`を`SourceTableViewController`、遷移先のViewControllerの`Custom\nClass`を`DestinationViewController`だとします。\n読む際は実際は、2つのクラス名を実際プロジェクトでご利用のファイル名に脳内変換して御覧ください。\n\n## Step1. StoryBoard上でSegueを定義しておく\n\nStoryBoard上で以下の設定を行います。\n\n 1. 「TableViewController」と「遷移先ViewController」をStoryBoard上に設置\n 2. 「TableViewController」の`Custom Class`を`SourceTableViewController`に設定\n 3. 「 遷移先Controller」の`Custom Class`を`DestinationViewController`に設定\n 4. 「TableViewController」から「遷移先ViewController」へ`Segue`を張り、`Segue`の`identifier`を`toDestinationViewController`に設定\n\n## Step2. DestinationViewController.hにlinkをpropertyとして定義しておく\n\nCellをタップしたときの遷移先のDestinationViewControllerはlinkを値として受け取る必要があるので\n外部から受け取れるようにheaderファイルに`link`をproeprtyとして定義しておきます。\n\n```\n\n # DestinationViewController.h( Cellをタップした時に移動する遷移先のControllerクラス)\n @interface DestinationViewController : UIViewController\n \n # 外部から受け取りたいパラメータを定義(今回は文字列のlink情報)\n @property NSString *link;\n \n @end\n \n```\n\n## Step3. SourceTableViewController.mで選択Cellの情報をSegueを経由して遷移先に渡す処理を実装\n\nまずCellが選択された際に遷移が実行されるように`didSelectRowAtIndexPath`の中で`performSegueWithIdentifier`の呼び出しを実装します。\n\n```\n\n # SourceTableViewController.m( JSONを表示するTalebViewControllerのクラス )\n - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath\n {\n # \"toDestinationViewController\"はStoryBoardで設定したSegueのIdentifier\n [self performSegueWithIdentifier:@\"toDestinationViewController\" sender:nil];\n }\n \n```\n\n次にSegueを経由して遷移先のに選択されたCellに表示されている情報をパラメータとして渡す処理を実装します。\n\n`prepareForSegue`が遷移前に呼ばれ、そこでSegueに関する情報を処理できます。\n\nなので、`prepareForSegue`で選択されたCellのlink情報を、遷移先のDestinationViewControllerに渡す処理を実装することで、やりたいことが実現できるはずです。\n\n具体的な実装例は以下のようになります。\n\n```\n\n # SourceTableViewController.m\n - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {\n # 選択されたCellのIndexPathを取得します\n NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];\n \n # indexPathから、選択されたItemを取得します\n NSDictionary *selectedItem = self.items[ selectedIndexPath.row ];\n \n # segueが持っている遷移先のViewControllerのインスタンスを取り出します.\n DestinationViewController *destinationViewController = segue.destinationViewController;\n \n # DestinationViewControllerのインスタンスのプロパティのlinkに選択されたItemのlinkを代入\n destinationViewController.link = [selectedItem objectForKey:@\"link\"];\n }\n \n```\n\n## Step5. DestinationViewController.mで受け取った値を利用する\n\n今までの実装で、DestinationViewControllerが表示された際にはインスタンスはlink値を持ってるはずです。\nviewDidLoad等の中で値が入っていることを確認して利用してください。\n\n```\n\n # DestinationViewController.m\n - (void)viewDidLoad {\n [super viewDidLoad];\n # 選択されたCellのlink値が_linkに入っているはず\n NSLog(@\"link:%@\",_link);\n # _linkを使った処理を実装\n }\n \n```\n\n以上の処理で、Segueを利用してUITableViewControllerで選択されたCellの情報を遷移先のControllerに渡すことができると思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T18:13:14.100", "id": "321", "last_activity_date": "2014-12-03T18:40:36.243", "last_edit_date": "2014-12-03T18:40:36.243", "last_editor_user_id": "813", "owner_user_id": "813", "parent_id": "287", "post_type": "answer", "score": 4 } ]
287
307
307
{ "accepted_answer_id": "291", "answer_count": 2, "body": "jQueryっぽく要素を回転させたい\n\n```\n\n $(\"#elem\").rotate(90); => #elemが90度回転\n $(\"#elem\").rotate() => \"90\"が返る\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T02:43:54.733", "favorite_count": 0, "id": "290", "last_activity_date": "2014-12-27T15:31:17.783", "last_edit_date": "2014-12-10T07:03:29.853", "last_editor_user_id": "525", "owner_user_id": "525", "post_type": "question", "score": 5, "tags": [ "javascript", "html5", "jquery" ], "title": "jQueryを拡張して要素を回転させたい", "view_count": 1555 }
[ { "body": "こんな感じになります。\n\n```\n\n $.fn.rotate = function( deg ) {\n if( deg === undefined ) {\n deg = $(this[0]).data.rotateDeg;\n if ( deg === undefined ) { return 0; }\n else { return deg; }\n }\n \n this.each(function(){ \n var $el = $(this);\n var rotation = 'rotate('+ (deg) +'deg)';\n $el\n .css({ \n 'webkitTransform': rotation ,\n 'mozTransform' : rotation ,\n 'msTransform' : rotation ,\n 'oTransform' : rotation ,\n 'transform' : rotation });\n $el.data.rotateDeg = deg;\n });\n return this;\n };\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T02:43:54.733", "id": "291", "last_activity_date": "2014-12-10T07:05:15.863", "last_edit_date": "2014-12-10T07:05:15.863", "last_editor_user_id": "525", "owner_user_id": "525", "parent_id": "290", "post_type": "answer", "score": 4 }, { "body": "jQuery 1.8以降ならベンダプレフィックスは自動付加なのでこうでしょうか。\n\n```\n\n (function($) {\n $.fn.rotate = function(angle) {\n if(angle == null) {\n return this.data(\"angle\") || 0;\n } else {\n return this.data(\"angle\", angle)\n .css(\"transform\", \"rotate(\" + angle + \"deg)\");\n }\n };\n })(jQuery);\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-27T15:31:17.783", "id": "2705", "last_activity_date": "2014-12-27T15:31:17.783", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4388", "parent_id": "290", "post_type": "answer", "score": 3 } ]
290
291
291
{ "accepted_answer_id": "359", "answer_count": 2, "body": "Shared Elements を動画で実現したいと思っています。\n\n[makeSceneTransitionAnimation](https://developer.android.com/reference/android/app/ActivityOptions.html#makeSceneTransitionAnimation\\(android.app.Activity,%20android.util.Pair%3Candroid.view.View,%20java.lang.String%3E...\\))\nの様に動的に View を共有して Activity の遷移を行いたいのですが、 **API level 21**\n未満の場合はどのように実現すればいいでしょうか。\n\n実装方法として Service 等のライフサイクルを横断するストアに View のインスタンスを保持しておき、そのインスタンスを遷移先の View\nをすげ替える事で実現できるのではないかと思っていますが、どなたかご存じないでしょうか?\n\nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T03:01:04.937", "favorite_count": 0, "id": "293", "last_activity_date": "2014-12-05T08:44:56.047", "last_edit_date": "2014-12-05T08:44:56.047", "last_editor_user_id": "30", "owner_user_id": "745", "post_type": "question", "score": 5, "tags": [ "android" ], "title": "Shared Elements による画面遷移を API level 21 未満でも実現する方法はありますか?", "view_count": 787 }
[ { "body": "推測されている通り、Androidのフレームワークでも一旦Viewを保存しておき、アニメーションを実行しています。\n\n基本的にはActivityOptionsクラスの[makeSceneTransitionAnimation](http://tools.oesf.biz/android-5.0.0_r2.0/xref/frameworks/base/core/java/android/app/ActivityOptions.java#453)をまねるかたちになりそうです。動画の方は、バッファリングなどもあるので難易度が高そうですが...\n\n```\n\n 462 ArrayList<String> names = new ArrayList<String>();\n 463 ArrayList<View> views = new ArrayList<View>();\n 464 \n 465 if (sharedElements != null) {\n 466 for (int i = 0; i < sharedElements.length; i++) {\n // このfor文でsharedElementsからViewを取得\n 467 Pair<View, String> sharedElement = sharedElements[i];\n 468 String sharedElementName = sharedElement.second;\n 469 if (sharedElementName == null) {\n 470 throw new IllegalArgumentException(\"Shared element name must not be null\");\n 471 }\n 472 names.add(sharedElementName);\n 473 View view = sharedElement.first;\n 474 if (view == null) {\n 475 throw new IllegalArgumentException(\"Shared element must not be null\");\n 476 }\n 477 views.add(sharedElement.first);\n 478 }\n 479 }\n 480 // アクティビティ終了時のアニメーション準備\n 481 ExitTransitionCoordinator exit = new ExitTransitionCoordinator(activity, names, names,\n 482 views, false);\n \n```\n\nあわせてサポートライブラリを調査してみましたが、 ActivityOptionsCompat\nv21での[実装](http://tools.oesf.biz/android-5.0.0_r2.0/xref/frameworks/support/v4/java/android/support/v4/app/ActivityOptionsCompat.java#131)では、API\nLevel.21以下でのアニメーションは諦めているようで参考にはなりませんでした。\n\n```\n\n 131 public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity,\n 132 View sharedElement, String sharedElementName) {\n 133 if (Build.VERSION.SDK_INT >= 21) { // 諦めの境地\n 134 return new ActivityOptionsCompat.ActivityOptionsImpl21(\n 135 ActivityOptionsCompat21.makeSceneTransitionAnimation(activity,\n 136 sharedElement, sharedElementName));\n 137 }\n 138 return new ActivityOptionsCompat();\n 139 }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T03:50:50.187", "id": "298", "last_activity_date": "2014-12-03T03:50:50.187", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "395", "parent_id": "293", "post_type": "answer", "score": 3 }, { "body": "英語ですが、DevBytes に実装の仕方を説明した動画があります。\n\n[https://www.youtube.com/watch?v=CPxkoe2MraA&list=PLWz5rJ2EKKc_XOgcRukSoKKjewFJZrKV0&index=75](https://www.youtube.com/watch?v=CPxkoe2MraA&list=PLWz5rJ2EKKc_XOgcRukSoKKjewFJZrKV0&index=75)\n\n基本的な考え方は、標準の遷移アニメーションを無効化した上で遷移先のアニメーション側で 独自のアニメーションを頑張る形になります。\n\n遷移先でアニメーションさせるための情報として、遷移元の画像の位置と大きさを Intent の extra にいれて startActivity します。\n動画の中では以下の様なコードを呼び出し側に記述しています。\n\n```\n\n int[] screenLocation = new int[2];\n v.getLocationOnScreen(screenLocation);\n PictureData info = mPicturesData.get(v);\n Intent subActivity = new Intent(ActivityAnimations.this,\n PictureDetailsActivity.class);\n int orientation = getResources().getConfiguration().orientation;\n subActivity.\n putExtra(PACKAGE + \".orientation\", orientation).\n putExtra(PACKAGE + \".resourceId\", info.resourceId).\n putExtra(PACKAGE + \".left\", screenLocation[0]).\n putExtra(PACKAGE + \".top\", screenLocation[1]).\n putExtra(PACKAGE + \".width\", v.getWidth()).\n putExtra(PACKAGE + \".height\", v.getHeight()).\n putExtra(PACKAGE + \".description\", info.description);\n startActivity(subActivity);\n \n // Windowアニメーションを無効化\n overridePendingTransition(0, 0);\n \n```\n\n呼び出される側では、onCreate で extra を取り出してアニメーションを行うのですが、 ひとつポイントがあります。 onCreate\nの段階ではレイアウトが完了していないので、 ViewTreeObserver を使用して描画の直前に処理を挿入してあげるとうまくいきます。\n\n```\n\n if (savedInstanceState == null) {\n ViewTreeObserver observer = mImageView.getViewTreeObserver();\n observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {\n \n @Override\n public boolean onPreDraw() {\n mImageView.getViewTreeObserver().removeOnPreDrawListener(this);\n \n // ここにアニメーションの処理を記述\n \n return true;\n }\n });\n }\n \n```\n\n動画の中で解説しているコードはこちらからダウンロードできます。\n\n<http://developer.android.com/shareables/devbytes/ActivityAnimations.zip>\n\nコードだけでも参考になるのではないかと思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T17:49:19.813", "id": "359", "last_activity_date": "2014-12-04T18:10:14.310", "last_edit_date": "2014-12-04T18:10:14.310", "last_editor_user_id": "319", "owner_user_id": "319", "parent_id": "293", "post_type": "answer", "score": 7 } ]
293
359
359
{ "accepted_answer_id": "301", "answer_count": 3, "body": "Scavenge GC と Full GC の処理の違いは何か教えて下さい。以下については理解しています。\n\n * Scavenge GC が Eden 領域がいっぱいになった時に実行される\n * MaxTenuringThreshold の回数文、S0 から S1 に移動が発生した場合に、OLD 領域への移動が発生する\n * Old がいっぱいになった時に Full GC が発生する。\n\nつまり、Old に残っているオブジェクトは、どこからか参照されていて、それ故に残っていると考えられます。したがって、Full GC が Scavenge\nGC と同様の処理である場合、Old のオブジェクトは、どこからか参照されていると判定されるので、破棄できないのではないかと思いました。\n\nしかし、実際にはそんなはずは無いので、Full GC と Scavenge GC には、不要なオブジェクトを探索するアルゴリズムに差異があるのでは(Full\nGC のほうが深く探索するなど)、と推測しているのですが裏付けとなる情報が得られていません。\n\nよろしくお願いします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T03:18:59.290", "favorite_count": 0, "id": "295", "last_activity_date": "2014-12-17T02:26:49.627", "last_edit_date": "2014-12-03T03:26:06.043", "last_editor_user_id": "294", "owner_user_id": "294", "post_type": "question", "score": 7, "tags": [ "java", "gc", "アルゴリズム" ], "title": "Java における Scavenge GC と Full GC の違い", "view_count": 22539 }
[ { "body": "Scavenge GC の対象の Eden 領域などを含む NEW\n領域は、直近で生成された短命なオブジェクトが残り、しきい値を超えた寿命を持つオブジェクトが OLD 領域に入るだけなので、OLD\n領域は寿命の長いオブジェクトが入ることになります。ですので、どちらに居ても、他のオブジェクトから参照されているオブジェクトは破棄されません。\n\nGC の方式としては、Scavenge GC はコピー方式で、Full GC\nはマーク・アンド・スイープ方式が採用されている話があります(<http://www.atmarkit.co.jp/ait/articles/0704/24/news136.html>)。が、すこし情報が古いようですね。最近は、特に\nFull GC 時の停止期間を少なくするために、コンカレントな GC を Full GC\nに採用するのが一般的です(<http://d.hatena.ne.jp/wyukawa/20130103/1357211148>)。Java 7\n以降だと、G1GC\nという方式も出てきています(<http://nekop.hatenablog.com/entry/20140407/1396858038>)。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T04:15:50.650", "id": "301", "last_activity_date": "2014-12-03T04:15:50.650", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "484", "parent_id": "295", "post_type": "answer", "score": 4 }, { "body": "HotSpot JVM は、世代別 GC\nと呼ばれる仕組みを提供しています。理解している点として挙げられているNew領域とOld領域に分けてGCをするという仕組みです。 \n生成されたばかりの若いオブジェクトがいるNew領域を対象にしたGCを Minor GC、長命オブジェクトがいるOld領域を対象にしたGCを Major GC\nと呼びます。\n\nまた、HotSpot JVMは主なGCとして次のGCを提供しています。\n\n * Parallel GC\n * Concurrent Mark&Sweep GC\n * Garbage First GC\n\nこのうち、どのGCを利用するかは、Javaを起動する時のオプションによって決定されます。 HotSpot JVM はこれらの GC を世代別 GC\nとして実行しています。\n\nと、ここまでが前提。\n\nScavenge GC、Full GCが何なのかというと、Parallel GCを選択した際のMinor GCとMajor GCです(※1)。\nScavenge GCはNew領域を対象にして、Full GCはOld領域を含む全領域(※2)を対象にしてGCします。 \nなので、Scavenge GC ではOld領域の不要メモリは回収されません。Full GCによって回収されます。\n\n※1:Concurrent Mark&Sweep GCを選択した場合でも実行されますが、質問内容的にParallel GCだと判断しました。\nConcurrent Mark&Sweep GCについては手前味噌ですが以下の資料をどうぞ\n<http://www.slideshare.net/YujiKubota/concurrent-marksweep-garbage-collection>\n\n※2:状況によっては、一部領域が除外されます", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T15:25:48.130", "id": "1792", "last_activity_date": "2014-12-16T15:25:48.130", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2511", "parent_id": "295", "post_type": "answer", "score": 3 }, { "body": "Javaが「世代別GC」を採用しているのはなぜかと言うと、寿命が短いオブジェクトが多いからです。逆に寿命が長いオブジェクトはなかなか不要にならない傾向があります。これが重要なポイントです。そのため、寿命が長いオブジェクトは非効率的なGCで止むを得ないが、寿命が短いオブジェクトは効率的にGCを実行したいという考えから、世代別GCを採用しています。\n\n「[Qiitaの私の投稿](http://qiita.com/sipadan2003/items/a7acf7f0375d818b5045)」を参照してください。\n\nNew領域には、1個のEden領域と、2個のSurvivor領域があります。\n\nまず、オブジェクトを生成したら、New領域内のEden領域に格納されますが、Eden領域が一杯になったら、Scavenge\nGCが実行されます。そのとき不要オブジェクトはメモリから破棄されますが、生存オブジェクト(=参照が切れていないオブジェクト)はSurvivor領域に移動されます。\n\nNew領域(EdenとSurviovor)がまた一杯になったら、再びScavenge\nGCが実行され、もう一つのSurvivor領域に生存オブジェクトが移動されます。New領域が一杯になるたびに、Scavenge\nGCが繰り返されます。Scavenge\nGCは、生存オブジェクトを2個のSurvivor領域の間を移動(コピー)させながらGCを実行するので、コピーGCとも呼ばれています。\n\nScavenge GCが数回実行されても生存しているオブジェクトは、Old領域に移動されます。そして、Old領域が一杯になったときにCMS\nGC/Parallel Old GC/Full GCが実行されます(Parallel Old GCはFull GCのマルチスレッド版のようなものです)。\n\nオプションでCMS GCを選択した場合は、Full GCよりもCMS GCが優先的に実行されますが、CMS\nGCはコンパクション(=ハードディスクに対するデフラグと同じ)を行わないので、Old領域内に小さな空き領域が散らばっている状態を作ります。そのため、CMS\nGCを実行しても、Old領域にオブジェクトを格納できない場合は、フォールバック(回避策)として自動的にFull GCが実行されます。\n\nCMS GCとFull\nGCの相違点は、前者はOld領域だけに対してアプリケーションを止めずにGCを行いますが、コンパクションは行いません。後者はOld領域だけでなくPermanent領域に対してアプリケーションを止めてしまいますが、コンパクションを兼ねています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-17T01:44:27.377", "id": "1832", "last_activity_date": "2014-12-17T02:26:49.627", "last_edit_date": "2014-12-17T02:26:49.627", "last_editor_user_id": "4278", "owner_user_id": "4278", "parent_id": "295", "post_type": "answer", "score": 2 } ]
295
301
301
{ "accepted_answer_id": "302", "answer_count": 1, "body": "ブラウザーでダウンロードリンクを踏んだときのようにJavaScriptからファイルをダウンロードさせたいのですが、どのようにしたら良いでしょうか?\n\n```\n\n $.getJSON('/data.json', function(data) {\n // ファイルダイアログを表示して、指定したファイルへ data を書き込む\n });\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T04:11:00.153", "favorite_count": 0, "id": "300", "last_activity_date": "2014-12-04T01:42:46.010", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "450", "post_type": "question", "score": 18, "tags": [ "javascript" ], "title": "JavaScriptからファイルをダウンロードさせるのはどうしたら良いですか?", "view_count": 42178 }
[ { "body": "`content`を`fileName`でダンロードしたい場合の実装 \n`content`は生の文字列\n\n```\n\n var downloadAsFile = function(fileName, content) {\n var blob = new Blob([content]);\n var url = window.URL || window.webkitURL;\n var blobURL = url.createObjectURL(blob);\n \n var a = document.createElement('a');\n a.download = fileName;\n a.href = blobURL;\n a.click(); \n };\n \n```\n\nコレでも可\n\n```\n\n var downloadAsFile = function(fileName, content) {\n var a = document.createElement('a');\n a.download = fileName;\n a.href = 'data:application/octet-stream,'+encodeURIComponent(content);\n a.click();\n };\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T04:22:33.853", "id": "302", "last_activity_date": "2014-12-04T01:42:46.010", "last_edit_date": "2014-12-04T01:42:46.010", "last_editor_user_id": "525", "owner_user_id": "525", "parent_id": "300", "post_type": "answer", "score": 19 } ]
300
302
302
{ "accepted_answer_id": null, "answer_count": 1, "body": "[EDINET](http://disclosure.edinet-fsa.go.jp/)\nから上場会社の決算データ(XBRL)を取得するプログラムを作成しようとしています。その際、EDINET\nコードではなく証券コードで指定したいので、証券コードから EDINET コードを自動的に求めたいと思います。\n\n例: 7203→E02144 (トヨタ自動車)\n\n将来的に上場する会社も対応したいので、プログラム内部に変換表を持つのではなくて、できれば公開されているリソースから取得したいと思っています。\n\n公開されている情報や、参考となる情報があれば教えてください。\n\nなお、プログラムは Linux上の Ruby で作成する予定ですが。情報源がライブラリ等の場合、OS 言語はなんでも OK です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T06:21:08.743", "favorite_count": 0, "id": "304", "last_activity_date": "2014-12-03T06:33:50.710", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "290", "post_type": "question", "score": 3, "tags": [ "edinet" ], "title": "証券コードからEDINETコードへの変換", "view_count": 834 }
[ { "body": "TDnetの決算短信の財務諸表をみるといいらしいです。<http://d.hatena.ne.jp/xbrl/20090621/1245573739>\n\n<http://www.tse.or.jp/rules/td/xbrl/data/>\n\n実装例がありますね。これを参考にすればいいかと <http://qiita.com/shima_x/items/c1955743cb5784505ac9>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T06:27:46.680", "id": "305", "last_activity_date": "2014-12-03T06:33:50.710", "last_edit_date": "2014-12-03T06:33:50.710", "last_editor_user_id": "525", "owner_user_id": "525", "parent_id": "304", "post_type": "answer", "score": 3 } ]
304
null
305
{ "accepted_answer_id": "317", "answer_count": 2, "body": "UITableViewControllerを使って`cellForRowAtIndexPath`等を定義してtableを表示していましたが、\ntable以外のモノも表示したいためstoryboadでViewControllerの中にtableViewを配置したものに変更しました。\n\nこの場合、`self.tableView`に対して`cellForRowAtIndexPath`や`numberOfSectionsInTableView`はどうやって設定したらいいでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T09:24:17.357", "favorite_count": 0, "id": "306", "last_activity_date": "2014-12-04T10:07:41.507", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "post_type": "question", "score": 3, "tags": [ "ios", "tableview" ], "title": "iOSのUIViewControllerにtableViewを追加する場合", "view_count": 835 }
[ { "body": "対象となるViewControllerで、`UITableViewDelegate`と`UITableViewDataSource`を実装すればいいと思います。\n\n * <https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UITableViewDelegate_Protocol/index.html>\n * <https://developer.apple.com/LIBRARY/IOS/documentation/UIKit/Reference/UITableViewDataSource_Protocol/index.html>\n\nその上で、\n\n```\n\n @interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>\n @property (weak, nonatomic) IBOutlet UITableView *tableView;\n @end\n \n```\n\n![アウトレットを定義](https://i.stack.imgur.com/9O89q.png)\n\nとViewController.hにアウトレットをつなげたうえで、\n\n![dataSourceとdelegateを設定](https://i.stack.imgur.com/7QnUq.png)\n\ndataSourceとdelegateをViewControllerにすればいいと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T14:04:14.203", "id": "317", "last_activity_date": "2014-12-03T14:13:57.100", "last_edit_date": "2014-12-03T14:13:57.100", "last_editor_user_id": "351", "owner_user_id": "351", "parent_id": "306", "post_type": "answer", "score": 6 }, { "body": "上の回答で尽きているが、UITableViewDataSourceというプロトコルが、それらのメソッドを規定している。\nそのプロトコルを必要としているのは、UITableView. UITableViewは、それらのメソッドがどこにあるのか、しるのに、datasource\nというプロパティを持っている\n\nUITableViewControllerをstoryboardに貼りつけた場合や、UiTableViewControllerのサブクラス・ソースをxibつきで生成した場合、storyboardや、xibのなかに、フリーズドライされた形で、UITableViewに、datasource\nの値が、設定されているので、この設定は、やる必要がない。\n\n今回のようなことをやる場合、上の回答にある、datasourceを設定する以外に、\n\nViewController.h で、\n\n```\n\n @interface ViewController: UIViewController <UITableViewDataSource>\n \n```\n\nと、このViewControllerが、UITableViewDataSourceプロトコルを実装していることを明示する必要がある。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T02:45:25.167", "id": "337", "last_activity_date": "2014-12-04T10:07:41.507", "last_edit_date": "2014-12-04T10:07:41.507", "last_editor_user_id": "75", "owner_user_id": "75", "parent_id": "306", "post_type": "answer", "score": 2 } ]
306
317
317
{ "accepted_answer_id": "309", "answer_count": 1, "body": "`Multimap<Hoge, Fuga>` を必要とするメソッドがあるのですが、Multimaps.index\nを使うよりも簡単な初期化方法はありませんか?\n\n```\n\n Multimap<Hoge, Fuga> piyo = Multimaps.初期化();\n \n```\n\nくらい簡単なものがうれしいです。環境はJava6です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T09:41:02.577", "favorite_count": 0, "id": "308", "last_activity_date": "2014-12-05T01:57:44.787", "last_edit_date": "2014-12-05T01:57:44.787", "last_editor_user_id": "30", "owner_user_id": "635", "post_type": "question", "score": 5, "tags": [ "java", "guava" ], "title": "Multimap<Hoge, Fuga> の初期化方法を教えてください", "view_count": 452 }
[ { "body": "空のMapが欲しいという事でしたら `ArrayListMultimap.create()`でどうでしょうか。 \nもしくはMultimapBuilderというモノもあります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T09:50:05.377", "id": "309", "last_activity_date": "2014-12-03T09:50:05.377", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "parent_id": "308", "post_type": "answer", "score": 5 } ]
308
309
309
{ "accepted_answer_id": "320", "answer_count": 3, "body": "やりたいことは、ScrollViewとTableViewの判断です。\n二つともデリゲートでつなげているのですが、TableviewはScrollのデリゲートがつながってしまいます・・・\nなので、どちらのViewでスクロールされているのかが判断できない状態です。\n\n現在\n\n```\n\n - (void)scrollViewDidScroll:(UIScrollView*)scrollView\n \n```\n\nこちらで、スクロールが縦にされた場合TableView横でされた場合ScrollViewと判断させているのですが、もっとよいやり方があるのではないかと考えています。\nどなたかご存知の方がいらっしゃればぜひご教授ください。 現在はこちらで判断しております。\n\n```\n\n CGPoint currentPoint = [scrollView contentOffset];\n if(self.scrollBeginingPoint.y > currentPoint.y){\n //上方向スクロール検知 \n }else if(self.scrollBeginingPoint.y < currentPoint.y){\n //下方向スクロール検知 \n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T10:25:00.060", "favorite_count": 0, "id": "310", "last_activity_date": "2014-12-03T19:24:58.340", "last_edit_date": "2014-12-03T10:49:19.363", "last_editor_user_id": "10", "owner_user_id": "798", "post_type": "question", "score": 3, "tags": [ "ios", "tableview", "iphone", "scrollview", "delegate" ], "title": "UIScrollView UITableView ScrollViewDelegateの判定について", "view_count": 1663 }
[ { "body": "引数で渡ってきた`scrollView`を、プロパティなどで保持している`scrollView`や`tableView`と比較して処理を分けると良いと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T11:56:39.100", "id": "312", "last_activity_date": "2014-12-03T11:56:39.100", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "55", "parent_id": "310", "post_type": "answer", "score": 2 }, { "body": "`tag`でできると思います。\n\n<https://developer.apple.com/library/ios/documentation/Uikit/reference/UIView_Class/index.html#//apple_ref/occ/instp/UIView/tag>\n\ntagに適当な値をセット(ここではtableViewに2、scrollViewに1)して、\n\n```\n\n - (void)scrollViewDidScroll:(UIScrollView *)scrollView{\n if(scrollView.tag == 1){\n //scrollView\n }else if(scrollView.tag == 2){\n //tableView\n }\n }\n \n```\n\nとすれば振り分けられます。\n\nタグはstoryboardからも設定できます。\n\n![タグ](https://i.stack.imgur.com/rrkfw.png)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T16:39:57.290", "id": "320", "last_activity_date": "2014-12-03T16:39:57.290", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "351", "parent_id": "310", "post_type": "answer", "score": 2 }, { "body": "既に回答にでているように、基本的にはインスタンスの`property`や`tag`などに情報を保持しておいて一意な情報を元に比較するのが良いと思います。\n\nただ、もしTableViewやScrollViewが動的に生成され、1つのController内にscrollViewDidScrollのscrollView候補がたくさんあるような場合であれば`isKindOfClass`を使って、クラスの種類によって分岐させるという方法もあります。\n\n```\n\n - (void)scrollViewDidScroll:(UIScrollView *)scrollView{\n if([scrollView isKindOfClass:[UITableView class]] ){\n //scrollViewがUITableViewの場合\n }else{\n //scrollViewがUITableView以外のScrollViewの場合\n }\n }\n \n```\n\n「一意なインスタンス」として分岐させたい(`property`や`tag`で識別)のか、「クラスの種類」で分岐(`isKindOfClass`で識別)させたいのかで要件によって使い分けるのが良いと思います。(後者は少し特殊なケースかもしれませんが。。)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T19:08:30.247", "id": "323", "last_activity_date": "2014-12-03T19:24:58.340", "last_edit_date": "2014-12-03T19:24:58.340", "last_editor_user_id": "813", "owner_user_id": "813", "parent_id": "310", "post_type": "answer", "score": 2 } ]
310
320
312
{ "accepted_answer_id": null, "answer_count": 2, "body": "まれに、Macがフリーズしてマウスもキーボードも受け付けなくなることがあります。SSHでログインしてkillしたりはできるのですが、結局再起動しないと直りません。最悪の場合、電源ボタンでの強制終了しか受け付けてくれません。\n\n今し方起きたフリーズだと、以下を試してもダメでした。\n\n * `top -o -cpu` で見つけた忙しそうなプロセスを `kill`\n * `sudo killall Finder`: 効果なし\n * `sudo killall -HUP WindowServer`: ログアウトされたが、入力は受け付けないまま\n\n結局 `sudo shutdown -r now` で再起動しました。 (これも途中でフリーズすることがある。)\n\nOS の外部入力部分だけをリセットしたりできないのでしょうか。\n\n環境: Mac OS X 10.10.1 / MacBook Pro (Retina, 13-inch, Mid 2014)", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T11:21:09.453", "favorite_count": 0, "id": "311", "last_activity_date": "2014-12-16T10:25:10.467", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "post_type": "question", "score": 4, "tags": [ "macos" ], "title": "入力を受け付けなくなったがSSHログインはできるMacを再起動なしに救いたい", "view_count": 1826 }
[ { "body": "loginwindow プロセスを kill してみてはどうでしょうか。\n\n```\n\n sudo killall loginwindow\n \n```\n\nこの場合、ログアウトして、WindowServer プロセスも終了します。 その後、launchd が loginwindow プロセスを上げ直すはずです。\n\nちなみに loginwindow が起動し直すのは\n/System/Library/LaunchDaemons/com.apple.loginwindow.plist に\n\n```\n\n <key>KeepAlive</key>\n <true/>\n \n```\n\nの記載があるためです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T12:58:11.617", "id": "315", "last_activity_date": "2014-12-03T13:34:56.897", "last_edit_date": "2014-12-03T13:34:56.897", "last_editor_user_id": "804", "owner_user_id": "804", "parent_id": "311", "post_type": "answer", "score": 8 }, { "body": "(コメントできないので、こちらですいません)\n\n原因が違うかもしれませんが、私の環境でも11月21日に OSX 10.10.1 の際に起きています。\n理由は内部キーボードおよび内部トラックパッドが切断されたというものでした。\n切断されたことがわかったのは[hardwaregrowler](https://itunes.apple.com/jp/app/hardwaregrowler/id475260933?mt=12)を入れていたおかげです。\n\nその際はBTキーボードとBTトラックパッドを接続して、セーフブートで事なきを得たのですが、当然予めペアリング済みであることが必要です。\nこちらの環境ではセーフブート後は起きていないので、もしかしたら違うかもしれませんが、参考迄に。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T10:25:10.467", "id": "1736", "last_activity_date": "2014-12-16T10:25:10.467", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2805", "parent_id": "311", "post_type": "answer", "score": 1 } ]
311
null
315
{ "accepted_answer_id": "314", "answer_count": 1, "body": "PHP の `date_sun_info`、`date_sunrise`、`date_sunset` 関数は、どのように計算しているのでしょうか。\n関数によって算出された値の精度を知りたいので、ご存知でしたら教えて下さい。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T12:10:59.820", "favorite_count": 0, "id": "313", "last_activity_date": "2014-12-22T02:33:27.510", "last_edit_date": "2014-12-22T02:32:56.077", "last_editor_user_id": "5444", "owner_user_id": "675", "post_type": "question", "score": 11, "tags": [ "php" ], "title": "PHP の日の出、日の入り関数の計算方法", "view_count": 779 }
[ { "body": "`date_sunrise`と`date_sunset`は[date.c](https://github.com/php/php-\nsrc/blob/php-5.5.5/ext/date/php_date.c#L4601)の`php_do_date_sunrise_sunset`関数を使います。`date.c`は`timelib`ライブラリを使っています。\n\n```\n\n static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_sunset)\n {\n double latitude = 0.0, longitude = 0.0, zenith = 0.0, gmt_offset = 0, altitude;\n double h_rise, h_set, N;\n timelib_sll rise, set, transit;\n long time, retformat = 0;\n int rs;\n timelib_time *t;\n timelib_tzinfo *tzi;\n char *retstr;\n \n if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, \"l|ldddd\", &time, &retformat, &latitude, &longitude, &zenith, &gmt_offset) == FAILURE) {\n RETURN_FALSE;\n }\n \n switch (ZEND_NUM_ARGS()) {\n case 1:\n retformat = SUNFUNCS_RET_STRING;\n case 2:\n latitude = INI_FLT(\"date.default_latitude\");\n case 3:\n longitude = INI_FLT(\"date.default_longitude\");\n case 4:\n if (calc_sunset) {\n zenith = INI_FLT(\"date.sunset_zenith\");\n } else {\n zenith = INI_FLT(\"date.sunrise_zenith\");\n }\n case 5:\n case 6:\n break;\n default:\n php_error_docref(NULL TSRMLS_CC, E_WARNING, \"invalid format\");\n RETURN_FALSE;\n break;\n }\n if (retformat != SUNFUNCS_RET_TIMESTAMP &&\n retformat != SUNFUNCS_RET_STRING &&\n retformat != SUNFUNCS_RET_DOUBLE)\n {\n php_error_docref(NULL TSRMLS_CC, E_WARNING, \"Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE\");\n RETURN_FALSE;\n }\n altitude = 90 - zenith;\n \n /* Initialize time struct */\n t = timelib_time_ctor();\n tzi = get_timezone_info(TSRMLS_C);\n t->tz_info = tzi;\n t->zone_type = TIMELIB_ZONETYPE_ID;\n \n if (ZEND_NUM_ARGS() <= 5) {\n gmt_offset = timelib_get_current_offset(t) / 3600;\n }\n \n timelib_unixtime2local(t, time);\n rs = timelib_astro_rise_set_altitude(t, longitude, latitude, altitude, 1, &h_rise, &h_set, &rise, &set, &transit);\n timelib_time_dtor(t);\n \n if (rs != 0) {\n RETURN_FALSE;\n }\n \n if (retformat == SUNFUNCS_RET_TIMESTAMP) {\n RETURN_LONG(calc_sunset ? set : rise);\n }\n N = (calc_sunset ? h_set : h_rise) + gmt_offset;\n \n if (N > 24 || N < 0) {\n N -= floor(N / 24) * 24;\n }\n \n switch (retformat) {\n case SUNFUNCS_RET_STRING:\n spprintf(&retstr, 0, \"%02d:%02d\", (int) N, (int) (60 * (N - (int) N)));\n RETURN_STRINGL(retstr, 5, 0);\n break;\n case SUNFUNCS_RET_DOUBLE:\n RETURN_DOUBLE(N);\n break;\n }\n }\n \n```\n\n`timelib`の`timelib_astro_rise_set_altitude`関数に英語のコメントがありますが、[ソースを見ると](https://github.com/php/php-\nsrc/blob/php-5.5.5/ext/date/lib/astro.c#L207)下記の計算を利用しているらしいです:\n\n>\n> ![日の出計算](https://upload.wikimedia.org/math/4/9/8/4983e82397dfb7c1b1647184ef59e096.png)\n```\n\n int timelib_astro_rise_set_altitude(timelib_time *t_loc, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit)\n {\n double d, /* Days since 2000 Jan 0.0 (negative before) */\n sr, /* Solar distance, astronomical units */\n sRA, /* Sun's Right Ascension */\n sdec, /* Sun's declination */\n sradius, /* Sun's apparent radius */\n t, /* Diurnal arc */\n tsouth, /* Time when Sun is at south */\n sidtime; /* Local sidereal time */\n timelib_time *t_utc;\n timelib_sll timestamp, old_sse;\n \n int rc = 0; /* Return cde from function - usually 0 */\n \n /* Normalize time */\n old_sse = t_loc->sse;\n t_loc->h = 12;\n t_loc->i = t_loc->s = 0;\n timelib_update_ts(t_loc, NULL);\n \n /* Calculate TS belonging to UTC 00:00 of the current day */\n t_utc = timelib_time_ctor();\n t_utc->y = t_loc->y;\n t_utc->m = t_loc->m;\n t_utc->d = t_loc->d;\n t_utc->h = t_utc->i = t_utc->s = 0;\n timelib_update_ts(t_utc, NULL);\n \n /* Compute d of 12h local mean solar time */\n timestamp = t_loc->sse;\n d = timelib_ts_to_juliandate(timestamp) - lon/360.0;\n \n /* Compute local sidereal time of this moment */\n sidtime = astro_revolution(astro_GMST0(d) + 180.0 + lon);\n \n /* Compute Sun's RA + Decl at this moment */\n astro_sun_RA_dec( d, &sRA, &sdec, &sr );\n \n /* Compute time when Sun is at south - in hours UT */\n tsouth = 12.0 - astro_rev180(sidtime - sRA) / 15.0;\n \n /* Compute the Sun's apparent radius, degrees */\n sradius = 0.2666 / sr;\n \n /* Do correction to upper limb, if necessary */\n if (upper_limb) {\n altit -= sradius;\n }\n \n /* Compute the diurnal arc that the Sun traverses to reach */\n /* the specified altitude altit: */\n {\n double cost;\n cost = (sind(altit) - sind(lat) * sind(sdec)) / (cosd(lat) * cosd(sdec));\n *ts_transit = t_utc->sse + (tsouth * 3600);\n if (cost >= 1.0) {\n rc = -1;\n t = 0.0; /* Sun always below altit */\n \n *ts_rise = *ts_set = t_utc->sse + (tsouth * 3600);\n } else if (cost <= -1.0) {\n rc = +1;\n t = 12.0; /* Sun always above altit */\n \n *ts_rise = t_loc->sse - (12 * 3600);\n *ts_set = t_loc->sse + (12 * 3600);\n } else {\n t = acosd(cost) / 15.0; /* The diurnal arc, hours */\n \n /* Store rise and set times - as Unix Timestamp */\n *ts_rise = ((tsouth - t) * 3600) + t_utc->sse;\n *ts_set = ((tsouth + t) * 3600) + t_utc->sse;\n \n *h_rise = (tsouth - t);\n *h_set = (tsouth + t);\n }\n }\n \n /* Kill temporary time and restore original sse */\n timelib_time_dtor(t_utc);\n t_loc->sse = old_sse;\n \n return rc;\n }\n \n```\n\n`date_sun_info`も`timelib`関数を利用しています。\n\nこの回答は[cmbuckley](https://stackoverflow.com/users/283078/cmbuckley)の[Stack\nOverflow回答](https://stackoverflow.com/a/19574347/1933347)からの情報です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T12:35:28.033", "id": "314", "last_activity_date": "2014-12-22T02:33:27.510", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "10", "parent_id": "313", "post_type": "answer", "score": 16 } ]
313
314
314
{ "accepted_answer_id": "355", "answer_count": 1, "body": "Ubuntu 14.04LT を利用しています。\n\n下記のとおりpandocをインストールしたのですが、 \n出力されたpdfを開くと、slide.md の日本語の部分が表示されていませんでした。 \ntex を使うのは初めてなので、よくわかっていません。 \n対処方法わかれば教えてください。\n\n```\n\n sudo apt-get install pandoc\n sudo apt-get install texlive\n sudo apt-get install texlive-xetex\n \n```\n\nコマンド\n\n```\n\n pandoc slide.md -t beamer -o out.pdf --latex-engine=xelatex\n \n```\n\nslide.md\n\n```\n\n % Slide Sample\n % toshi0383\n % 2014/12/03 Wed.\n \n # hello\n ## さんぷるです\n \n # yellow\n \n```\n\nあと一歩な感じはするんですが、 \nここまでくるのにも結構調べて時間を使ってしまい、 \n結局全部英語で書いてプレゼンしてしまいました。 \ntex の日本語環境がここまで整っていないとは。。 \n次回までに日本語環境を構築できればなあと思っています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T15:11:31.087", "favorite_count": 0, "id": "319", "last_activity_date": "2018-12-05T10:45:35.250", "last_edit_date": "2018-12-05T10:45:35.250", "last_editor_user_id": "19110", "owner_user_id": "257", "post_type": "question", "score": 8, "tags": [ "markdown", "latex", "pandoc" ], "title": "pandoc でmarkdown から PDF形式(日本語)のスライドを作る方法を教えてください", "view_count": 2102 }
[ { "body": "いろいろと試してみました。最適なやり方かどうかはわかりませんが出力する事が出来ました。\n\n結論から言えば言語パック入れた上で\n\n * プリアンブル用意して読み込ませる\n * 出力をtex(`-o tex`)にして、別途用意しているテンプレートにincludeする\n\nのいずれかになると思います(fontthemeではうまくできませんでした)。\n\n「プリアンブル用意して読み込ませる」方の手順を以下に示します。新規インストールしたてのUbuntu 14.04 LTS desktopで試しました。\n多分13.04でも言語パックが入ったので行けると思います。\n\nただし、もっといいやり方があるかもしれません。\n\n* * *\n\n# 質問の状態にするためのインストール\n\n質問に書いてくれいていますが、この回答で手順が完結できるように引用させていただきます。 私はOSを入れた直後にこの 3つをインストールしました。\n\n```\n\n sudo apt-get install pandoc texlive\n sudo apt-get install texlive-xetex\n \n```\n\nこの状態で、質問にある slide.md を beamerテンプレートでスライド形式にできますが日本語はでません。\n\n```\n\n pandoc slide.md -t beamer -o out.pdf --latex-engine=xelatex\n \n```\n\n# beamerを使わない状態で日本語を出力する\n\n> メモ:少なくとも私の環境ではこの状態でテンプレートを指定せずにpdf出力すると以下のエラーになっていました。後述する\n> lualatexだとエラーにはなっていなかったように思います\n```\n\n> $ pandoc slide.md -o out.pdf --latex-engine=xelatex\n> pandoc: Error producing PDF from TeX source.\n> ! LaTeX Error: File `etoolbox.sty' not found.\n> -以下略-\n> \n```\n\n>\n> その後言語パッケージを入れたらいつの間にかでなくなっていました。依存で一緒に入ったのかもしれません。\n\nとりあえず日本語のpdfを出せるようにしましょう。\n\nそのために言語パッケージを入れてみました。1000MBと巨大ですので空き容量にも注意してください。\n\n```\n\n sudo apt-get install texlive-lang-cjk\n \n```\n\nインストールが終わると、テンプレートなしでもエラーはでなくなりました。日本語はまだ出力されません。\n\n```\n\n pandoc slide.md -o out.pdf --latex-engine=xelatex\n \n```\n\n`-V`を使って、(pandocではなく、latexのオプションとして)追加の設定をバイパスします。\n\n```\n\n pandoc slide.md -o out.pdf --latex-engine=xelatex -V mainfont=IPAPGothic\n \n```\n\n※ IPAフォントは`texlive-lang-cjk`によってインストールされます。\n\nこれで日本語も表示可能な普通のpdfが出力できたと思います。 `-V`\nは指定するパラメータ毎に追加します。たとえばfontsize(10pt/11pt/12pt)も指定するなら以下の様にします。\n\n```\n\n pandoc slide.md -o out.pdf --latex-engine=xelatex -V mainfont=IPAPGothic -V fontsize=11pt\n \n```\n\n# beamerを指定する\n\n日本語pdfが作成できたので、beamerテンプレートを指定してみます\n\n```\n\n pandoc slide.md -t beamer -o out.pdf --latex-engine=xelatex -V mainfont=IPAGothic\n \n```\n\n出力されません。\nこのmainfont指定をbeamer(beamerのドキュメントクラス)は無視する様で、fontthemeなども指定してみたりしたんですが、\n結局オプション指定からは今の私では解決できませんでした。\n\n# プリアンブルを用意して適用する。\n\n結局以下の様なプリアンブルを用意してpdf作成時に取り込ませることで日本語で表示されるようになりました。\nプリアンブルは普通にtexを作った時にドキュメントクラスとbeginの間に書くものです。\n\n`-t beamer`の場合は\n`\\documentclass`は多分`[beamer]`になって、pandocで出力するtexは`\\begin`と`\\end`の間の部分です。\npandocが作り出すtexの手前でさまざまな設定を行う事ができ、また、全てではないようですがドキュメントクラスで設定されている内容も変更できます。 \nbeamerにフォント指定無視されるので設定上書きできそうなここ(プリアンブル)で設定してみましょうという事です。\n\nともかく `beamer-preamble-xelatex.tex` を作成しテキストエディタで以下の様にします。\n(ファイル名はわかりやすさのために長くなっていますので、必要なら適宜短くしてください) 大文字小文字にも注意してください。\n\n```\n\n \\setmainfont{IPAPMincho}\n \\setsansfont{IPAPGothic}\n \\setmonofont{IPAGothic}\n \\XeTeXlinebreaklocale \"ja\"\n \n```\n\n作成したプリアンブルをpandocで変換時に取り込ませます。`-V`で指定していたフォントは必要がないので削除しました。\n\n```\n\n pandoc slide.md -t beamer -o out.pdf --latex-engine=xelatex -H beamer-preamble-xelatex.tex\n \n```\n\nこれで私の環境では日本語が出力されたスライド形式のpdfが作成できました。\nなおpreambleのファイルをslide.mdと別の場所に置いた場合は正しくパス指定してください。\n\nこのファイルは使いまわせますので参照しやすい場所の置いておけばよいと思います。\n\n# その他\n\nlualatex (パッケージ名 texlive-luatex )というのもあるようですね。\nこちらを使う場合にはプリアンブルの最後のxelatex用の行を削除すれば作成できます。\n\n(lualatexだと、しおりの日本語が化けてしまいますがそこはちょっと詳しく調べてないのでわかりませんでした)\n\nちょっと説明が細かすぎたかもしれませんが、体系的な説明もみつけられなかったのと自分の備忘もかねて丁寧に書いてみました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T12:27:17.613", "id": "355", "last_activity_date": "2014-12-04T12:38:13.887", "last_edit_date": "2014-12-04T12:38:13.887", "last_editor_user_id": "728", "owner_user_id": "728", "parent_id": "319", "post_type": "answer", "score": 7 } ]
319
355
355
{ "accepted_answer_id": "350", "answer_count": 3, "body": "Sublime Text 2を使っているのですが、長らくβなバージョン3に移行したいななどと考えています。\n\nバージョン3は、2と比べて何か大きく良くなかったところなどありますか? また、3はやはりβということで不安定ですか?それとも十分使用に耐えられますか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-03T23:39:31.153", "favorite_count": 0, "id": "331", "last_activity_date": "2014-12-19T07:09:50.287", "last_edit_date": "2014-12-05T00:45:56.973", "last_editor_user_id": "47", "owner_user_id": "55", "post_type": "question", "score": 7, "tags": [ "sublimetext" ], "title": "Sublime Text 2と3は何が大きく違うんですか?", "view_count": 8652 }
[ { "body": "> 3は2と比べて何か大きく良くなかったところなどありますか?\n\nSublime Text3になってより柔軟にSublimeのUI部分を変更しやすくはなっています。\n\n> 3はやはりβということで不安定ですか? \n> それとも十分使用に耐えられますか?\n\nSublime Text Blogの「[Sublime Text 3 Public Beta\n](http://www.sublimetext.com/blog/articles/sublime-text-3-public-beta)」によると:\n\n> Build 3047 is the fastest, most stable, most polished version of Sublime\n> Text yet.\n\n最新のSublime Text 3は最も早く最も安定的で最も洗練されてSublime Textだそうです。\n\nより詳しいSublime Text2 と3の大きな違いについては、Sublime\nTextの[CAHNGELOG](http://www.sublimetext.com/blog/)を参照していただければと思います\n\n## 参照サイト\n\n * [Sublime Blog](http://www.sublimetext.com/blog/)\n * [Migrate from Sublime text 2 to Sublime text3](https://stackoverflow.com/a/17537817/2248060)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T02:48:01.793", "id": "338", "last_activity_date": "2014-12-04T02:58:51.540", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "556", "parent_id": "331", "post_type": "answer", "score": 5 }, { "body": "あまり使い込んでないですが、個人的な感想としては、\n\n起動(ウィンドウが表示されるまで)は早くなったと思います。これはプラグインの読み込みを起動してから行うようになったからじゃないかと思います。(起動して直ぐにコンソール開くと読み込み中な雰囲気なので)\n\nあとはバンドルしているpythonのバージョンが、Sublime Text 2は2.6なのに対し、Sublime Text(3)はpython\n3系がバンドルされています。手元のものは3.3でしたが今後変わるかもしれません。 \nこれもあって 3用のプラグインがないというケースも考えられますが、ほとんどの場合は両方対応してると思います。\n\n余談ですが、個人的にライセンス買ったものの最近Sublime Textの動きが少ないので Github Atom.io\n(まだアルファ版だが普通に使えているし、SJIS公式対応)や Adobe brackets (UTF8以外まだ未対応ではあるがver\n1リリース済み)に乗り換えようかなとも考えてます。 (どちらもPythonじゃないのが残念ですが)\n\n* * *\n\n## 追記:\n\nバンドルされているバージョンについては上記を修正しました。\n\nそれ以外に思い出した点としては、2では `Default`の設定ファイル( settings, key-bindindings\n)のファイルを直接編集して設定を変更することができたと思いますが、3ではそれはできなくなっていて、user定義ファイルで設定する事が強制されるようになりました。Defaultの方をいじっていると最初戸惑うかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T06:35:46.033", "id": "350", "last_activity_date": "2014-12-04T09:49:49.913", "last_edit_date": "2014-12-04T09:49:49.913", "last_editor_user_id": "728", "owner_user_id": "728", "parent_id": "331", "post_type": "answer", "score": 8 }, { "body": "公式の売り文句も含めて、私が知っている違いは、\n\n * パフォーマンス改善 (起動や置換)\n * シンボルインデックスが強化。プロジェクト単位をスキャンするように\n * プロジェクト内で、複数のワークスペースを作れる (ワークスペース=タブをまとめたもの)\n * HTML のタグを `'/'` を入力で閉じられる\n * タブの部分がスクロールする\n * 画像を開ける\n * サイドバーのアイコンが豊富になった\n * プラグインのAPIが改良された\n * プラグイン毎にユーザ用の設定を作るように推奨\n * ST2 にあるのに、 ST3 ではプラグインが未対応のものがある ([このサイトでチェックできる](http://www.caniswitchtosublimetext3.com/))\n * まだまだまだまだベータ版\n\n私にとって大きいのは以下です。\n\n * Python のバージョンが 2.x 系から 3.x 系に移行した\n * Goto メニューに新機能 \n * Goto Definition [`F12`]\n * Goto Symbol in Project [`Ctrl+Shift+'R'`]\n * Jump Back [`Alt+'-'`]\n * Jump Forward [`Alt+Shift+'-'`]\n * ST2, ST3 を同時にインストール可能。\n\nユーザが普段気にする機能は、シンボルインデックス機能の強化ぐらいではないでしょうか、 `F12` と `Ctrl+Shift+'R'` は便利です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-19T07:01:48.483", "id": "2111", "last_activity_date": "2014-12-19T07:09:50.287", "last_edit_date": "2014-12-19T07:09:50.287", "last_editor_user_id": "4978", "owner_user_id": "4978", "parent_id": "331", "post_type": "answer", "score": 3 } ]
331
350
350
{ "accepted_answer_id": "340", "answer_count": 1, "body": "iOSのUIWebViewで、ロードしたページ内のjavascriptを呼び出し戻り値をiOS側に格納したいです。 どのような方法があるでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T01:11:24.453", "favorite_count": 0, "id": "333", "last_activity_date": "2014-12-04T07:10:29.333", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "post_type": "question", "score": 2, "tags": [ "javascript", "ios" ], "title": "iOSのwebViewでjavascriptを呼び出し、返り値を取得したい", "view_count": 6663 }
[ { "body": "webViewにロードしたhtmlが例えば次のようになっていた場合、\n\n```\n\n <html>\n <head>\n <script>\n function test(value){\n return JSON.stringify({result : value * 2});\n }\n </script>\n </head>\n <body>\n </body>\n </html>\n \n```\n\n次のように[stringByEvaluatingJavaScriptFromString:](https://developer.apple.com/library/ios/documentation/uikit/Reference/UIWebView_Class/index.html#//apple_ref/occ/instm/UIWebView/stringByEvaluatingJavaScriptFromString:)を呼び出すことで、返り値を取得できます。\n\n```\n\n NSString *function = [NSString stringWithFormat: @\"test(%i)\", 1];\n NSString *jsonString = [webView stringByEvaluatingJavaScriptFromString:function];\n NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];\n NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];\n NSLog(@\"json: %@\", json);\n \n```\n\nなお、`stringByEvaluatingJavaScriptFromString:`の戻り値はNSStringなので、シンプルなデータであればJSONで受け渡しする必要はないです。\n\nまた、Objective-C -> JSは以上のように簡潔にできますが、JS -> Objective-\nCについては、`UIWebView`には、C#の`WebBrowser`にある`ObjectForScripting`のような実装がないので簡潔には書けません(OSXであれば、[windowScriptObject](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/index.html#//apple_ref/occ/instm/WebView/windowScriptObject)というのが使えるようです)。C#の`WebBrowser`では、例えば、\n\n```\n\n window.external.CSharpMethod(arg1, arg2);\n \n```\n\nのように書けます。\n\nここでのトピックから外れますので詳細については割愛しますが、 [JavaScriptからObjective-\nCにフック](http://qiita.com/ozw_sei/items/62d9cd1938cf6ea012bd#2-2)や[Calling\nObjective-C code from UIWebView](http://pablin.org/2013/08/31/interfacing-\nwith-a-uiwebview-from-a-uiviewcontroller/)などを参考にして下さい。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:10:35.697", "id": "340", "last_activity_date": "2014-12-04T07:10:29.333", "last_edit_date": "2014-12-04T07:10:29.333", "last_editor_user_id": "351", "owner_user_id": "351", "parent_id": "333", "post_type": "answer", "score": 4 } ]
333
340
340
{ "accepted_answer_id": null, "answer_count": 3, "body": "スマートフォン向けのウェブサービスにおいて、AndroidからのアクセスでGETが連続で来る場合があります。 特徴として、\n\n * 2回目のリクエストはリファラーがない \n * 2回目のリクエストは1回目の数秒後ぐらいに来る\n * 2回目のリクエストはユーザーエージェントがDalvik \n * いくつかの端末で出ている\n\nこの問題により、いくつかの機能で不具合のような動作が出ています。 \nどのように対策すれば良いでしょうか。\n\njavascriptを読み込ませてこれを送信しないようにする等の方法があれば、ありがたいです。\n無ければサーバ側で監視するのでしょうか。サーバ側の環境はphp+Zendです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T01:22:41.570", "favorite_count": 0, "id": "334", "last_activity_date": "2016-12-21T07:00:03.220", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "post_type": "question", "score": 5, "tags": [ "android" ], "title": "androidにおけるリクエストの再送信について", "view_count": 9866 }
[ { "body": "Android端末(特定機種)側の不具合と考えられます。 \nWebブラウザまたはAndroid OSが独自の判断で再送しているようです。\n\n手元で現象を確認していないので検討できていませんが、JavaScript側で制御は難しいでしょう。 \nサーバー側で監視,無視など例外対応が必要です。\n\nAndroid側の挙動については次の通りです(サーバー側の対応方法は、わかりません)。2回目のリクエストのUserAgentは次のようなものでしたか?\n\n```\n\n \"Dalvik/1.6.0 (Linux; U; Android 4.2.2; C2004 Build/15.2.A.2.5)\"\n \n```\n\nこれはAndroidのHttpURLConnectionのUserAgentで、WebブラウザのUAとは異なります。 \nAndroidアプリでの確認方法は次のとおりです。\n\n```\n\n System.getProperty(\"http.agent\");\n \n```\n\n同様の症状がStackOverflowの[Browser sending “Dalvik” as user\nagent](https://stackoverflow.com/questions/23804278/browser-sending-dalvik-as-\nuser-agent)に報告されていました。\n\n初回のリクエストがAndroidのブラウザから行われ、 \n何らかの事情でAndroid\nOSの[HttpURLConnection](http://developer.android.com/reference/java/net/HttpURLConnection.html)を使ったリクエストが再送されているようです。\n\nUserAgentについてはWebブラウザ(WebView)、HttpURLConnection、HttpClientそれぞれで異なります。通常、ブラウザを利用している場合は、ブラウザのUAが入ります。しかし、Androidは機種ごとにカスタマイズして実装されているため、幾つかの機種固有の問題として、異常系/例外処理?に入ったケースで質問の挙動が起きているのだと推測します", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T03:02:08.460", "id": "339", "last_activity_date": "2014-12-04T03:02:08.460", "last_edit_date": "2017-05-23T12:38:55.307", "last_editor_user_id": "-1", "owner_user_id": "395", "parent_id": "334", "post_type": "answer", "score": 4 }, { "body": "Androidではありませんが、以前 Windows向けのWebアプリをリリースした際に、同様の問題が起こりました。その時の原因はセキュリティソフトでした。\n\nそのセキュリティソフトには、ユーザがアクセスしたサイトが詐欺サイトでないかどうかをチェックする仕組みがありました。ユーザがブラウザでGETリクエストを発行すると、セキュリティソフトがそれを検出して同じURLに対して別途\nGETリクエストを発行し、サイトの内容を機械的にチェックするというものです。\n\nHTTP的に「GETリクエストは冪等(idempotent)である」という前提を利用した仕組みですが、実際にはアクセスカウンタなどに影響がでるなど、開発者にとってはあまり嬉しいやり方ではありませんね。\n\nAndroidのセキュリティ対策ソフトについてはあまり知見がありませんが、そのようなソフトがインストールされている可能性はないでしょうか?\n\nmhidaka さんが紹介されている本家Stack Overflowのコメントにも McAfee antivirusを\ndisableにしたら送らなくなったと言っている人がいますね。\n\nなお、私が以前遭遇したセキュリティソフトは、ユーザがアクセスしたサイトのURLを一旦その会社のサーバに送り、サーバからGETリクエストがくるというものでしたのでソースIPアドレスが異なっていましたが、セキュリティソフトによっては、常駐しているプログラム自身がそのようなアクセスを行うものがあるかもしれないです。\n\n今回の問題がセキュリティソフトによるものでなかったとしても、そのようなものが将来出てくる可能性は十分あるので、基本的には「GETリクエストが複数回来ても問題ないようにサーバを作っておく」と良いと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:48:19.227", "id": "348", "last_activity_date": "2014-12-04T04:48:19.227", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "832", "parent_id": "334", "post_type": "answer", "score": 2 }, { "body": "within android 4.2.2 SourceCode\n\n./frameworks/base/core/java/com/android/internal/os/RuntimeInit.java\n\n```\n\n private static String getDefaultUserAgent() {\n \n```\n\nthis private function will form a useragent and set to \"http.agent\"\n\n./libcore/luni/src/main/java/libcore/net/http/HttpEngine.java \nHttpEngine will use it.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-12-21T06:34:26.403", "id": "31287", "last_activity_date": "2016-12-21T07:00:03.220", "last_edit_date": "2016-12-21T07:00:03.220", "last_editor_user_id": "754", "owner_user_id": "19975", "parent_id": "334", "post_type": "answer", "score": -1 } ]
334
null
339
{ "accepted_answer_id": "363", "answer_count": 3, "body": "## RxAndroidをローカルビルドできません\n\nRxAndroidに手を入れてみようと思い\n\n<https://github.com/ReactiveX/RxAndroid>\n\n上記をローカルでgit cloneし、Android\nStudioで開くと数ファイルで下記のように`com.google.auto.value.AutoValue`が見つからないという現象が発生しました。\n\n![AutoValueが認識されない](https://i.stack.imgur.com/UpIX6.png)\n\nこれに関しては、build.gradleの\n\n```\n\n compileOnly \"com.google.auto.value:auto-value:1.0-rc1\"\n \n```\n\nを\n\n```\n\n compile \"com.google.auto.value:auto-value:1.0-rc1\"\n \n```\n\nに変更する事で解消したのですが、今度は `AutoValue_OnClickEvent`が見つからないという問題が発生しています。\n\n![AutoValue_OnClickEventが見つからない](https://i.stack.imgur.com/fGBtM.png)\n\n`@AutoValue` を認識して自動生成されることを期待して数回ビルドやクリーンをしてみましたが状況変わらずです。\n\n正常にビルドが通る方法をご教授いただけないでしょうか? \nよろしくお願い致します。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T02:45:24.713", "favorite_count": 0, "id": "336", "last_activity_date": "2014-12-06T07:11:41.840", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "159", "post_type": "question", "score": 6, "tags": [ "android", "reactive-programming" ], "title": "RxAndroidをローカルビルドできません", "view_count": 271 }
[ { "body": "clone してきたものを以下のようにコマンドラインからビルドしたらビルド自体は問題なく出来ました。\n\n```\n\n ./gradlew build\n \n```\n\nIDE 上でのビルドも通らないと不便ですが、とりあえず。\n\n公式のドキュメントでは、eclipse 使えとなってますね...\n\n<https://github.com/ReactiveX/RxJava/wiki/How-to-Contribute>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T05:33:43.950", "id": "363", "last_activity_date": "2014-12-05T07:25:02.550", "last_edit_date": "2014-12-05T07:25:02.550", "last_editor_user_id": "319", "owner_user_id": "319", "parent_id": "336", "post_type": "answer", "score": 6 }, { "body": "参考までにさっき Cloneしたプロジェクトを、今日ダウンロードしたAndroid Studioの\nImportで開いてみましたが、ビルドは成功しているようでした。\n\nWindows 8.1, Android Studio 0.8.14。 \n途中SDK Platform API 20のインストールを要求されましたがそれ以外は特に気になるところもありませんでした。\n\n`RxAndroid\\rxandroid\\build`配下や`RxAndroid\\rxandroid-\nframework\\build`配下もclassファイルなどが生成されています。\n\n![ImportProject](https://i.stack.imgur.com/MSbiA.jpg)\n\nすでにプロジェクトが開かれている場合はFileメニューからImportを選んでみてください。\n\n![Rubuild Project](https://i.stack.imgur.com/PncED.jpg)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T02:32:15.747", "id": "390", "last_activity_date": "2014-12-06T02:32:15.747", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "728", "parent_id": "336", "post_type": "answer", "score": 2 }, { "body": "`compileOnly`\nのまま、エラー表示を無視してそのままビルドすると通ると思います。クラスが見つからないというエラーは、本当にビルドエラーが起きたのではなく、Android\nStudioが親切で表示している警告のようなものです。\n\n### 何故こういう状態になっているか:\n\nAutoValueは、アノテーションを利用してコンパイル時にクラスを生成するタイプのライブラリです。最終的に利用したいのは生成されたクラスの方で、AutoValueライブラリ自体は生成が終わったらお役御免になります。\n\nbuild.gradleで `compileOnly`\nという書き方をしているのはそのためです。RxAndroidを使う側としてはAutoValueライブラリは必要ないので、標準の `compile`\nグループとは別の、自前の依存グループ\n(`compileOnly`)を使うことで、RxAndroidの依存先にAutoValueライブラリが含まれないようにしています。\n\nところが、副作用として、Android\nStudio側では自前の依存グループの扱い方がわからず、AutoValueがどういうクラスを最終的に生成してくれるかも把握できないので、そんなクラスは存在しないよという警告を出してしまうことになります。\n\nこの問題は、[apt](https://bitbucket.org/hvisser/android-\napt)プラグインが使えるように[プロジェクトの構成を変えてから解消する予定](https://github.com/ReactiveX/RxAndroid/pull/87#discussion_r20920391)のようです。\n\n確認環境:\n\n * Mac OS X\n * Android Studio: 0.8.14\n * RxAndroid: f5edaf1", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T07:11:41.840", "id": "397", "last_activity_date": "2014-12-06T07:11:41.840", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "336", "post_type": "answer", "score": 3 } ]
336
363
363
{ "accepted_answer_id": null, "answer_count": 2, "body": "直リンクで申し訳ないのですが、iPhone等のスマートフォンで下記のサイトにアクセスすると、スマートフォンの傾きに応じて背景画像がゆらゆらと動くようになっています。\n\n<http://ignition.co/104>\n\nこのような効果はjQueryか何かのライブラリで実現しているのでしょうか? そういったライブラリをご存知の方がいれば教えてください。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:15:41.567", "favorite_count": 0, "id": "341", "last_activity_date": "2014-12-12T22:51:37.563", "last_edit_date": "2014-12-12T22:51:37.563", "last_editor_user_id": "30", "owner_user_id": "85", "post_type": "question", "score": 5, "tags": [ "javascript" ], "title": "スマートフォンの傾きに応じて背景画像を動かすJavaScriptライブラリはありますか?", "view_count": 2279 }
[ { "body": "`deviceorientation`イベントを使えば良いと思います。\n\n```\n\n window.addEventListener('deviceorientation', function(e) {\n // e.alpha, e.beta, e.gamma で傾きを取得\n });\n \n```\n\nMDNに詳しい説明があります。\n\n<https://developer.mozilla.org/ja/docs/Detecting_device_orientation>\n<https://developer.mozilla.org/ja/docs/DOM/Orientation_and_motion_data_explained>\n\n質問で挙げられているサイトでは`devicemotion`イベントを使っているようですが、こちらは使ったことがないので詳しいことはわかりません。\n<https://developer.apple.com/library/iad/documentation/SafariDOMAdditions/Reference/DeviceMotionEventClassRef/DeviceMotionEvent/DeviceMotionEvent.html>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T04:56:37.203", "id": "361", "last_activity_date": "2014-12-05T04:56:37.203", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "450", "parent_id": "341", "post_type": "answer", "score": 4 }, { "body": "**parallax.js** \nISHITOYA Kentaroさんがコメントされているように、parallax.jsというライブラリがあります。\n内部的には`DeviceOrientationEvent`を使っているようです。\n[**公式サイト**](http://matthew.wagerfield.com/parallax/)\n\n**html5rocks** \nまた、html5rocksにサンプルが掲載されています。これも`DeviceOrientationEvent`が使われています。\n[**サンプル**](http://www.html5rocks.com/en/tutorials/device/orientation/deviceorientationsample.html)\n\n**ブラウザの互換性** \n`DeviceOrientationEvent`は、FirefoxとChromeで動作が異なるなどブラウザの互換性に注意が必要です。\n[**MDN**](https://developer.mozilla.org/en-\nUS/docs/Web/API/DeviceOrientationEvent)\n\n* * *\n\n**DeviceOrientationに関する補足**\n\nDeviceOrientationEventには、座標軸に応じて3つの値があります。\n\n> x軸 : beta 度 [-180 ~ 180] \n> y軸 : gamma 度 [-90 ~ 90] \n> z軸 : alpha 度 [0 ~ 360] \n>\n\nまた、次のような処理の流れになります。\n\n> (1) DeviceOrientationEventのイベントを拾う \n> (2) X軸、Y軸、Z軸の傾きの値を取得する \n> (3) 座標値を好みの値に調節する \n> (4) 画像の位置を調節する \n>\n\n動作の仕組みを知るために、荒っぽく骨格の部分だけ数行で書くと以下のような感じです。\n\n```\n\n if (window.DeviceOrientationEvent) {\n // (1) DeviceOrientationEventのイベントを拾う\n window.addEventListener(\"deviceorientation\", function () {\n // (2) X軸、Y軸の傾きの値を取得する\n var x = Math.round(event.beta || 0); // [-90, 90)\n var y = Math.round(event.gamma || 0); // [-180, 180)\n \n // (3) 座標値を好みの値に調節する(省略)\n \n // (4) 画像の位置を調節する\n $('#contentarea').css({'background-position-x':x,\n 'background-position-y':y});\n }, true);\n }else{\n // DeviceOrientationEventがサポートされていません\n }\n \n```\n\n[jsfiddle ソースコード](http://jsfiddle.net/naokiota/ysad8cnu/) \n[jsfiddle 動作確認用](http://jsfiddle.net/naokiota/ysad8cnu/embedded/result/)\n\n以上です。参考になれば幸いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T12:28:39.173", "id": "375", "last_activity_date": "2014-12-12T12:54:12.947", "last_edit_date": "2014-12-12T12:54:12.947", "last_editor_user_id": "47", "owner_user_id": "47", "parent_id": "341", "post_type": "answer", "score": 3 } ]
341
null
361
{ "accepted_answer_id": "347", "answer_count": 2, "body": "各種通知をクライアント側に送信したいです。\n\nなるべく **WebサーバーとDBサーバーに負荷をかけない仕様** が望ましい。\n\n※通知サーバーを別途構築することも考えています。\n\n**シンプルかつ安全なサーバーの構成やミドルウェア、通知の仕様** について経験者の意見を聞きたいです。 よろしくおねがい致します。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:22:29.387", "favorite_count": 0, "id": "343", "last_activity_date": "2014-12-05T12:38:20.990", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "841", "post_type": "question", "score": -3, "tags": [ "notification" ], "title": "大容量トラフィックに耐えられるnotification機能はどう実装した方がいいですか。", "view_count": 227 }
[ { "body": "詳細な条件がわからないので \n通知=メッセージ、負荷をかけない=キューがよくできている \nという風に捉えて、回答しておきます。\n\n自前運用なら [RabbitMQ](http://www.rabbitmq.com/) あたりが定番かつ良い評判をよく聞きます。 \nAWS が可なら [AmazonSQS](http://aws.amazon.com/jp/sqs/) とかも選択肢に入るとは思いますが、\n通知条件・方法次第ではニーズに合致しないかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:37:26.773", "id": "347", "last_activity_date": "2014-12-04T04:37:26.773", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "208", "parent_id": "343", "post_type": "answer", "score": 3 }, { "body": "環境が指定されていないので、実際の実装の参考程度に。。。\n\nASP.NETの機能にSignalRがあります。 \n仕組み的にはWebSocket等を利用してサーバー側がクライアント側に設定してあるJavascriptのメソッドをキックするというものです。\n\n[公式のIntroduction(www.asp.net)](http://www.asp.net/signalr/overview/getting-\nstarted/introduction-to-signalr \"Introduction to\nSignalR\")や[実際にチャットアプリを作る記事(gihyo.jp)](http://gihyo.jp/dev/serial/01/realtimeweb/0005)などが参考になるでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T12:38:20.990", "id": "376", "last_activity_date": "2014-12-05T12:38:20.990", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "908", "parent_id": "343", "post_type": "answer", "score": 3 } ]
343
347
347
{ "accepted_answer_id": "346", "answer_count": 3, "body": "viで編集してShift+ZZ -> 権限がありません! \nとなったときにどう対処すればいいですか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:24:33.060", "favorite_count": 0, "id": "344", "last_activity_date": "2014-12-16T11:19:21.657", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "post_type": "question", "score": 7, "tags": [ "vim", "linux" ], "title": "root権限じゃないのにVimで保存したい", "view_count": 1174 }
[ { "body": "`:w !sudo tee % > /dev/null` でOK", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:24:33.060", "id": "345", "last_activity_date": "2014-12-04T04:24:33.060", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "parent_id": "344", "post_type": "answer", "score": 7 }, { "body": "それを支援するプラグイン [sudo.vim](http://www.vim.org/scripts/script.php?script_id=729)\nもあります。\n\n# 個人的には sudo tee のほうが好きですが ;)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T04:32:03.000", "id": "346", "last_activity_date": "2014-12-04T04:32:03.000", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "208", "parent_id": "344", "post_type": "answer", "score": 8 }, { "body": ".vimrcに\n\n`cnoreabbrev w!! w !sudo tee > /dev/null %`\n\nと書けば`:w!!`で保存できますよ。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T08:36:06.153", "id": "1718", "last_activity_date": "2014-12-16T11:19:21.657", "last_edit_date": "2014-12-16T11:19:21.657", "last_editor_user_id": "3822", "owner_user_id": "2713", "parent_id": "344", "post_type": "answer", "score": 6 } ]
344
346
346
{ "accepted_answer_id": null, "answer_count": 1, "body": "Xcode6を使っていますがjs編集時に正規表現で`\\\"`などが入力されていると、以降のインデントが狂ってしまうようです。 \nインデントが狂う原因がよくわからず、特定のjsを開いた時に変だという印象を持ってしまいました。\n\n設定等での回避方法があれば教えていただければと思います。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T06:56:20.477", "favorite_count": 0, "id": "351", "last_activity_date": "2015-01-19T14:23:47.180", "last_edit_date": "2015-01-19T03:22:30.723", "last_editor_user_id": "525", "owner_user_id": "525", "post_type": "question", "score": -1, "tags": [ "macos", "xcode" ], "title": "Xcodeのjavascriptのインデント", "view_count": 498 }
[ { "body": "イケてないというのがどうイケてないのかわかりませんが、 \njsファイルを右クリックしてOpen As > Source Code で開いてるんですよね?\n\n![open as source code](https://i.stack.imgur.com/tXSj7.jpg)\n\n気になるところはありますが、こんなもんかなと思ってます。\n\n> OS Xでおすすめのエディタがあれば教えてください\n\n私はWeb StormとかSublime Textをよく使います。 \nAtom.ioやbrucketsもありますね。 \nあとは使ったことはないですが、CodaやText Mateの名前もよく聞きます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T14:52:46.957", "id": "357", "last_activity_date": "2014-12-04T14:52:46.957", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "728", "parent_id": "351", "post_type": "answer", "score": 1 } ]
351
null
357
{ "accepted_answer_id": "356", "answer_count": 1, "body": "Rubyのバージョンは2.1.2です。\n\nREXMLを使ってXML内の特定のタグ以下のノードにマッチさせたいです。 \nタグが英語であればマッチするのですが、日本語のタグだとルート以下の全体がマッチしてしまいます。 \n例えば、XML解析のRubyコードは以下のようになっています。\n\n```\n\n require 'rexml/document'\n \n doc = nil\n File.open(\"example.xml\") do |file|\n doc = REXML::Document.new(file)\n end\n \n puts REXML::XPath.match(doc, \"/root/a\")\n \n```\n\nこの時、読み込むexample.xmlが以下のような場合は、\n\n```\n\n <?xml version=\"1.0\" ?>\n <root>\n <a>\n <b/>\n </a>\n <a>\n <b>bbb1</b>\n <b>bbb2</b>\n <e>eeee1</e>\n <f>ffff1</f>\n <b>bbb3</b>\n <c>ccc1</c>\n </a>\n <a>\n <b>bbb4</b>\n <b>bbb5</b>\n </a>\n </root>\n \n```\n\n以下のように返ってきますが、\n\n```\n\n #<a>\n # <b/>\n #</a>\n #<a>\n # <b>bbb1</b>\n # <b>bbb2</b>\n # <e>eeee1</e>\n # <f>ffff1</f>\n # <b>bbb3</b>\n # <c>ccc1</c>\n #</a>\n #<a>\n # <b>bbb4</b>\n # <b>bbb5</b>\n #</a>\n \n```\n\nexample.xmlが以下のような場合、\n\n```\n\n <?xml version=\"1.0\" ?>\n <本棚>\n <本>\n <b/>\n </本>\n <本>\n <b>bbb1</b>\n <b>bbb2</b>\n <e>eeee1</e>\n <f>ffff1</f>\n <b>bbb3</b>\n <c>ccc1</c>\n </本>\n <本>\n <b>bbb4</b>\n <b>bbb5</b>\n </本>\n </本棚>\n \n```\n\nRubyのコードを以下のように書き換えても、\n\n```\n\n # coding: utf-8\n require 'rexml/document'\n \n doc = nil\n File.open(\"example.xml\") do |file|\n doc = REXML::Document.new(file)\n end\n \n puts REXML::XPath.match(doc, \"/本棚/本\")\n \n```\n\n以下のように返ってきます。\n\n```\n\n #<本棚>\n # <本>\n # <b/>\n # </本>\n # <本>\n # <b>bbb1</b>\n # <b>bbb2</b>\n # <e>eeee1</e>\n # <f>ffff1</f>\n # <b>bbb3</b>\n # <c>ccc1</c>\n # </本>\n # <本>\n # <b>bbb4</b>\n # <b>bbb5</b>\n # </本>\n #</本棚>\n \n```\n\n理想は以下のように返ってきて欲しいです。\n\n```\n\n #<本>\n # <b/>\n #</本>\n #<本>\n # <b>bbb1</b>\n # <b>bbb2</b>\n # <e>eeee1</e>\n # <f>ffff1</f>\n # <b>bbb3</b>\n # <c>ccc1</c>\n #</本>\n #<本>\n # <b>bbb4</b>\n # <b>bbb5</b>\n #</本>\n \n```\n\nXMLファイル自体の文字コードはUTF-8です。 どのようにしたら希望通りにパースされた結果を得ることができるでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T07:43:08.540", "favorite_count": 0, "id": "352", "last_activity_date": "2014-12-10T06:27:06.527", "last_edit_date": "2014-12-10T06:27:06.527", "last_editor_user_id": "982", "owner_user_id": "192", "post_type": "question", "score": 4, "tags": [ "ruby", "xml", "xpath" ], "title": "XPathでXMLの要素名に日本語が使われている要素をマッチさせたい", "view_count": 1492 }
[ { "body": "nokogiriでもよろしければ\n\n```\n\n require 'nokogiri'\n \n doc = nil\n File.open(\"example.xml\") do |file|\n doc = Nokogiri::XML(file)\n end\n \n puts doc.xpath(\"/本棚/本\")\n \n```\n\nで、以下の様に取得できました。\n\n```\n\n <本>\n <b/>\n </本>\n <本>\n <b>bbb1</b>\n <b>bbb2</b>\n <e>eeee1</e>\n <f>ffff1</f>\n <b>bbb3</b>\n <c>ccc1</c>\n </本>\n <本>\n <b>bbb4</b>\n <b>bbb5</b>\n </本>\n \n```\n\n以下の環境で確認しました\n\n * windows 7 + ruby 2.1.4 + nokogiri 1.6.5\n\n * Ubuntu 14.04 + ruby 2.1.5 + nokogiri 1.6.5 \n( ruby2.1-dev, libxml2, libxml2-dev, libxslt1.1, libxslt1-dev )\n\n* * *\n\n## 補足の追記:\n\nいきなりnokogoriを提案した形になってしまったので少し補足します。 ubuntuやwindows上でもREXMLでは\"/本棚/本\"が \"/本棚\"\nと同じ動きになっていました。\nまた、\"/山/川\"などとしても同様に\"/山\"と同じ様な動作でしたのでnokogiriで試してみたら上手くいったので提案しました。\n\nruby\n1.8をつかって日本語でも正しく区切られるようなページを見かけていたため、先ほど気になって試してみましたが、windows環境でrubyinstallerからruby\n1.8.7を入れて質問のrexmlで\"/本棚/本\"のソースそのままで試したところ以下の様に取得されました。 \n※\n1.8.7でコマンドプロンプト上で実行するとコマンドプロンプトがutf8をプリントできずに`本`が`<譛ャ>`と化けてしまいますが、ファイルにリダイレクトすればutf8の文字コードで以下の内容になっています。\n\n```\n\n <本>\n <b/>\n </本>\n <本>\n <b>bbb1</b>\n <b>bbb2</b>\n <e>eeee1</e>\n <f>ffff1</f>\n <b>bbb3</b>\n <c>ccc1</c>\n </本>\n <本>\n <b>bbb4</b>\n <b>bbb5</b>\n </本>\n \n```\n\n問題は Win/Linuxどちらでも起きているので、rubyかREXMLかどちらかのバージョンの問題と思われます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-04T14:07:45.797", "id": "356", "last_activity_date": "2014-12-05T04:08:52.260", "last_edit_date": "2014-12-05T04:08:52.260", "last_editor_user_id": "728", "owner_user_id": "728", "parent_id": "352", "post_type": "answer", "score": 1 } ]
352
356
356
{ "accepted_answer_id": "362", "answer_count": 2, "body": "[Materialデザインガイドライン](http://www.google.com/design/spec/components/buttons.html)に書いてあるようなFloating\naction button, Raised buttonはどのように実装すれば良いのでしょうか?\n\nFlat buttonはこの二つを入れれば良さそうな気がするのですが…\n\n```\n\n style=\"?android:borderlessButtonStyle\"\n android:textStyle=\"bold\"\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T04:26:35.230", "favorite_count": 0, "id": "360", "last_activity_date": "2014-12-05T23:13:16.127", "last_edit_date": "2014-12-05T23:13:16.127", "last_editor_user_id": "745", "owner_user_id": "450", "post_type": "question", "score": 5, "tags": [ "android", "material-design" ], "title": "Materialデザインのボタンはどうやって実装したらよいでしょう?", "view_count": 7135 }
[ { "body": "Raised buttonは下記で文字と背景色を設定すればいけると思います。\n\n```\n\n style parent=\"android:Widget.Material.Button\"\n \n```\n\nFloating action buttonはライブラリがgithubにありますね \n<https://github.com/shamanland/floating-action-button>\n\n参考:<http://qiita.com/pside/items/b99a978b7b0fdbd52468> \n(ripple effectの解説ですがボタンの作り方が詳しく解説されています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T05:08:29.747", "id": "362", "last_activity_date": "2014-12-05T05:08:29.747", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "parent_id": "360", "post_type": "answer", "score": 6 }, { "body": "私も現在 Material デザインの実装を行っています。\n\n[MaterialDesignLibrary](https://github.com/navasmdc/MaterialDesignLibrary)\nというライブラリは FlatButton から SnackBar まで多様な Material\nデザインをカバーしており、利用や実装方法に非常に参考となります。\n\n簡単な実装ではアイコンを用意し、以下の様なレイアウトを書くだけで可能となります。\n\n**Floating Action Button**\n\n```\n\n <RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:materialdesign=\"http://schemas.android.com/apk/res-auto\"\n android:layout_width=\"match_parent\"\n android:layout_height=\"match_parent\"\n >\n <!-- ... XML CODE -->\n <com.gc.materialdesign.views.ButtonFloat\n android:id=\"@+id/buttonFloat\"\n android:layout_width=\"wrap_content\"\n android:layout_height=\"wrap_content\"\n android:layout_alignParentRight=\"true\"\n android:layout_alignParentBottom=\"true\"\n android:layout_marginRight=\"24dp\"\n android:background=\"#1E88E5\"\n materialdesign:animate=\"true\"\n materialdesign:icon=\"@drawable/ic_action_new\" />\n \n```\n\nただ、現在未だ[ maven\nレポジトリに登録されてない](https://github.com/navasmdc/MaterialDesignLibrary/issues/1)のでプロジェクトに含めなければいけないのが難点です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T18:40:37.490", "id": "385", "last_activity_date": "2014-12-05T18:40:37.490", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "745", "parent_id": "360", "post_type": "answer", "score": 6 } ]
360
362
362
{ "accepted_answer_id": "368", "answer_count": 3, "body": "Gradle ベースの android プロジェクトで APT (annotation processor, JSR 269) を使いたいのですが\nどのように設定するのがお勧めでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T08:40:39.983", "favorite_count": 0, "id": "367", "last_activity_date": "2016-10-29T03:35:55.433", "last_edit_date": "2016-10-29T03:35:55.433", "last_editor_user_id": "8000", "owner_user_id": "319", "post_type": "question", "score": 8, "tags": [ "android", "android-studio", "gradle" ], "title": "Gradle ベースの android プロジェクトで APT を使う設定", "view_count": 3543 }
[ { "body": "いくつか apt 用のプラグインが公開されています。\n\n私は `com.uphyca.gradle:gradle-android-apt-plugin:0.9.4` を使用しています。\n\n以下のように組み込んでください。\n\nトップレベルの build.gradle で次のようにプラグインをクラスパスに追加します。\n\n```\n\n buildscript {\n repositories {\n jcenter()\n // 以下の行を追加して maven central も見るようにする\n mavenCentral()\n }\n dependencies {\n classpath 'com.android.tools.build:gradle:1.0.0-rc1'\n // 次の行を追加\n classpath 'com.uphyca.gradle:gradle-android-apt-plugin:0.9.4'\n \n // NOTE: Do not place your application dependencies here; they belong\n // in the individual module build.gradle files\n }\n }\n \n allprojects {\n repositories {\n jcenter()\n }\n }\n \n```\n\nまた、アプリケーションやライブラリの build.gradle で、apt を使用する設定を行います。\n\n```\n\n apply plugin: 'com.android.application'\n // 以下の行を追加(com.android.application よりも後に追加すること)\n apply plugin: 'android-apt'\n \n android {\n // (略)\n }\n \n dependencies {\n compile fileTree(dir: 'libs', include: ['*.jar'])\n compile 'com.android.support:appcompat-v7:21.0.2'\n \n // アプリに組み込むライブラリは通常通り compile に、プロセッサは apt で指定します。\n compile \"net.vvakame:jsonpullparser-core:1.6.2\"\n apt \"net.vvakame:jsonpullparser-apt:1.6.2\"\n \n }\n \n```\n\nアノテーションプロセッサによっては、-A で追加の情報を要求するものがあります。 たとえば、Android Annotations を使用する場合は\nAndroidManifest.xml のパスを 指定する必要があるので以下の様なコードを build.gradle の末尾に追加してください。\n\n```\n\n // アプリケーションプロジェクトの場合。ライブラリプロジェクトの場合は\n // applicationVariants を libraryVariants に変えてください。\n android.applicationVariants.all { variant ->\n variant.javaCompile.options.compilerArgs += [\n '-AandroidManifestFile=' + variant.outputs.get(0).processManifest.manifestOutputFile\n ]\n }\n \n```\n\nandroid gradle plugin 0.14.2までは\n`variant.outputs.get(0).processManifest.manifestOutputFile` の部分を、\n`variant.processResources.manifestFile` と記述してください。\n\nここで紹介した以外にも同様のプラグインがあるのでリンクだけ載せておきます。\n\n<https://bitbucket.org/hvisser/android-apt>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T08:40:39.983", "id": "368", "last_activity_date": "2014-12-05T08:40:39.983", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "319", "parent_id": "367", "post_type": "answer", "score": 8 }, { "body": "[AndroidAnnotations](http://androidannotations.org/)をAPTで適用するapp/build.gradleの記述が下記になります。\n\n```\n\n apt 'org.androidannotations:androidannotations:3.2'\n compile 'org.androidannotations:androidannotations-api:3.2'\n \n```\n\nのあたりは利用するものに応じて書き換えてください。\n\n```\n\n buildscript {\n repositories {\n mavenCentral()\n }\n dependencies {\n classpath 'com.android.tools.build:gradle:0.14.4'\n classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'\n }\n }\n \n repositories {\n mavenCentral()\n mavenLocal()\n }\n \n apply plugin: \"com.android.application\"\n apply plugin: 'android-apt'\n \n dependencies {\n apt 'org.androidannotations:androidannotations:3.2'\n compile 'org.androidannotations:androidannotations-api:3.2'\n compile fileTree(dir: 'libs', include: ['*.jar'])\n \n // その他のライブラリー\n }\n \n apt {\n arguments {\n androidManifestFile variant.outputs[0].processResources.manifestFile\n resourcePackageName android.defaultConfig.applicationId\n \n // 追加のアノテーションプロセッシングオプションを下記のように指定可能\n // logLevel 'INFO'\n // logFile '/var/log/aa.log'\n }\n }\n \n android {\n compileSdkVersion 21\n buildToolsVersion \"21.1.1\"\n \n defaultConfig {\n applicationId \"アプリケーションID\" // アプリケーションに応じて書き換える\n minSdkVersion 14\n targetSdkVersion 21\n versionCode 1\n versionName \"1.0\"\n }\n \n compileOptions {\n sourceCompatibility JavaVersion.VERSION_1_7\n targetCompatibility JavaVersion.VERSION_1_7\n }\n \n buildTypes {\n release {\n minifyEnabled false\n proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n }\n }\n \n sourceSets {\n main {\n java.srcDirs = ['src/main/java', 'build/generated/source/apt/${variant.dirName}']\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T04:26:49.943", "id": "437", "last_activity_date": "2014-12-08T04:26:49.943", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "450", "parent_id": "367", "post_type": "answer", "score": 1 }, { "body": "「android apt」でぐぐるとこのエントリーが上位にくるので、最近(2016年10月末)の情報を追記しておきます。\n\n`'com.neenbedankt.gradle.plugins:android-apt:1.8'` \nのリポジトリに記載がありますが、gradle\npluginのバージョン2.2で正式にアノテーションプロセッサーが導入され、追加のライブラリを入れることなくaptが使用できるようになりました。\n\napp配下の`build.gradle`に記述するときは、次のように`annotationProcessor`で指定します。\n\n```\n\n dependencies {\n // 中略\n annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-10-29T02:55:46.033", "id": "29971", "last_activity_date": "2016-10-29T02:55:46.033", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "845", "parent_id": "367", "post_type": "answer", "score": 1 } ]
367
368
368
{ "accepted_answer_id": null, "answer_count": 1, "body": "Xamarin Studio 5.6.3 build 3のSketches機能を使っています。\nXamarin.Formsモードでの利用時にXAMLファイルをプレビューできると良いのですが、残念ながらこのような機能は提供されていないようです。\n\n良い方法はありませんか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T09:13:20.580", "favorite_count": 0, "id": "369", "last_activity_date": "2014-12-05T09:13:20.580", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "777", "post_type": "question", "score": 4, "tags": [ "xamarin" ], "title": "Xamarin SketchesでXamarin.FormsのXAMLをプレビューする方法", "view_count": 260 }
[ { "body": "Xamarin.Forms内のメソッドが提供するXAMLローダをリフレクションによって利用することで実現できます。\n以下のコードをSketchesのテキストエリアへ貼り付けてください。\n\n```\n\n using Xamarin.Forms;\n using System.Reflection;\n using System.Runtime.CompilerServices;\n using Xamarin.Forms.Xaml;\n \n var xaml = @\"<?xml version=\"\"1.0\"\" encoding=\"\"utf-8\"\" ?>\n <ContentPage xmlns=\"\"http://xamarin.com/schemas/2014/forms\"\" xmlns:x=\"\"http://schemas.microsoft.com/winfx/2009/xaml\"\" x:Class=\"\"XamlSamples.HelloXamlPage\"\"\n Title=\"\"Hello XAML Page\"\"\n Padding=\"\"10, 40, 10, 10\"\">\n \n <Label Text=\"\"Hello, XAML Sketch!!\"\"\n VerticalOptions=\"\"Start\"\"\n XAlign=\"\"Center\"\"\n Rotation=\"\"15\"\"\n IsVisible=\"\"true\"\"\n Font=\"\"Bold, 80\"\"\n TextColor=\"\"Red\"\" />\n \n </ContentPage>\";\n \n var page = new ContentPage{Padding = new Thickness(0,20,0,0)};\n var s = (((MethodInfo)(((TypeInfo)((Assembly.Load(new AssemblyName(\"Xamarin.Forms.Xaml, Version=1.2.3.0, Culture=neutral, PublicKeyToken=null\"))\n .GetTypes().Where(t => t.FullName == \"Xamarin.Forms.Xaml.Extensions\").First()))).DeclaredMembers\n .Where(t => !((MethodInfo)t).Attributes.HasFlag(System.Reflection.MethodAttributes.Family)).First())).MakeGenericMethod(typeof(ContentPage))).Invoke(null, new object[]{page, xaml}) != null;\n RootPage.Children.Add(page);\n \n```\n\nこれを貼り付けると、Xamarin Android PlayerまたはiOS SimulatorでXAMLの解釈されたビューを表示できます。\n\nその後は、XAML部分を編集した結果が即時更新されていきます。\n\nここでのXAML記述について、`\"`を`\"\"`と表記する必要があることに注意してください。\n\nなお、動作の仕組みは[第五次Xamarin.Forms戦争の記録(XAMLのライブプレビュー編)\n](http://www.muo.jp/2014/12/xamarinformsxaml.html)で紹介されています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T09:13:20.580", "id": "370", "last_activity_date": "2014-12-05T09:13:20.580", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "777", "parent_id": "369", "post_type": "answer", "score": 5 } ]
369
null
370
{ "accepted_answer_id": null, "answer_count": 4, "body": "Ruby on\nRailsでwebアプリを作っているのですが、コントローラーの記述が長くなってしまった場合、どのようにファイルを分割するのがいいのでしょうか?\n\n今は、コマンドから新しくコントローラーを作って\n\n```\n\n class HogeController < ApplicationController\n \n```\n\nという形になっているやつにソースを移しているんですが、\n\n<http://qiita.com/aDaichiOta/items/3fa5bc302565bcd495a8>\n\nここにあるみたいに\n\n```\n\n class HogeController < BaseController\n \n```\n\nとしたほうがいいのでしょうか?\n\nその場合ってコマンドからではなく直接rbを新規作成したほうがいいのですかね?\nコマンドから作るとviewsの下にフォルダ掘られちゃったりしているのですが・・・。\n\n補足として、 MVCの扱いは\n\n<http://at-grandpa.hatenablog.jp/entry/2013/11/01/072636>\n\nここにあるあるやつの「勘違い形式」でお願いします。\nあと、趣味でやっているものなので、厳密な事は求めていません。あくまで一般的に、みんなはどうやっているのかな?というところで回答をお願い致します。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T10:45:05.293", "favorite_count": 0, "id": "371", "last_activity_date": "2014-12-07T01:33:05.410", "last_edit_date": "2014-12-05T14:40:46.490", "last_editor_user_id": "30", "owner_user_id": "705", "post_type": "question", "score": 2, "tags": [ "ruby-on-rails", "mvc" ], "title": "Railsでコントローラーの記述を分割する方法", "view_count": 3338 }
[ { "body": "BaseController を作成してそちらに移動するのは、おそらく良いアイデアではないでしょう。 Hoge の代わりに Base\nが大きくなるオチがチラつきます。一般に継承は Hoge **IS A** Base という関係が成立するときにのみ、行うべきです。\n\n原則は **適切に責務を分割する** です。\n([Railsでサービスとフォームを導入してみる話](http://a-suenami.hatenablog.com/entry/2013/12/06/092146)より引用)\n\nご自身の別の [質問](https://ja.stackoverflow.com/questions/372/ruby-on-\nrails%E3%81%A7%E6%9C%AC%E5%BD%93%E3%81%AEmvc%E3%81%AE%E5%AE%9F%E8%A3%85%E6%96%B9%E6%B3%95)\nにもあるように、移せるものはモデルへ移すか、上記のエントリーにあるサービスやフォームを導入するということを検討してみてはどうでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T13:49:12.370", "id": "380", "last_activity_date": "2014-12-07T01:33:05.410", "last_edit_date": "2017-04-13T12:52:39.113", "last_editor_user_id": "-1", "owner_user_id": "208", "parent_id": "371", "post_type": "answer", "score": 5 }, { "body": "別のアプローチとして、Controllerが肥大化する要因として「複数のRequestに対する処理を1つのController内で行っている」ことも考えられます。例えばRESTfulな設計を適用した場合、あるリソースに対する操作(CRUD)を1つのController内で定義することが一般的です。つまり、最低でもRequestを受け取るためのメソッドがCRUDに対応して4つ存在します。それぞれのメソッド内の処理が大きくなればなるほど、そのControllerは肥大化していくわけです。\n\nもしその状態になっているのであれば、config/routes.rbを書き換えて、CRUDそれぞれに一つずつ別のControllerを作成する、という対応もありだと思います。これであれば、各Controllerの内容が単純計算で4分の1に減らせる可能性が出てきます。\n\nそうではなく、1つのRequestに対する処理が肥大化している場合は、上の回答にあるような対策が必要でしょうね。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T14:36:36.443", "id": "383", "last_activity_date": "2014-12-05T14:36:36.443", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "531", "parent_id": "371", "post_type": "answer", "score": 1 }, { "body": "私も Rails 3.2 系で、BaseController を作り共通の処理を書きましたが、結局肥大化してしまい見通しが悪くなってしまいました。\n\nそこで、Model 等でも利用している\n[Concerns](http://elegantbrew.tumblr.com/post/70990048275/controller-concerns-\nin-rails-4) という部品に分解し、必要な場合に追加を行うようにしました。\n\n例えば、以下の様に JSON 出力が必要な例外のハンドリングを Concerns にして注入しました。\n\n```\n\n module ExceptionHandler\n extend ActiveSupport::Concern\n \n included do\n rescue_from Errors::BadRequest, with: :bad_request\n end\n \n protected\n def bad_request(exception)\n render_exception status: __method__, debug_message: [exception.message, exception.backtrace].join(\"\\n\")\n end\n \n def render_exception(args)\n status = args[:status].to_sym\n \n error_message = {\n status_code: Rack::Utils.status_code(status),\n status: status.to_s.humanize,\n message: args[:message] }\n \n respond_to do |format|\n format.json { render json: error_message, status: status }\n end\n end\n end\n \n```\n\n独自の構造を作るときには基本的に Scaffold や Generator は利用しませんが、`rails generate controller\nMyContoroller`コマンドで生成を行っている場合、いくつかのオプションを付与することで生成物をスキップすることが出来ます。\n\n```\n\n --skip-template-engine (--no-template-engine) # View の生成をスキップする\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T19:31:25.573", "id": "387", "last_activity_date": "2014-12-06T06:00:03.453", "last_edit_date": "2014-12-06T06:00:03.453", "last_editor_user_id": "745", "owner_user_id": "745", "parent_id": "371", "post_type": "answer", "score": 0 }, { "body": "一概にこの方法が良いとは言い切れないと思います。対象の状況依存ではないでしょうか。\n\nかつて、私がやったことがある方法をあげると、以下の二つです:\n\n * コントローラでの共通部分をベースクラスに括りだして、複数のコントローラで共有する\n\n * コントローラで複数のモデルを操作するコードを、データを伴わないモデルとして独立させて、そこに集約し、コントローラから呼ぶ形にし、コントローラのコードを減らす\n\n前者は、操作するモデルが複数で親子関係があり、その親にも子にも、あるいは複数の子に対しての類似した操作の場合、有効なアプローチだと思います。\n\n後者は、複数モデルに跨いだ操作をコントローラで多くしている場合に有効です。\n\n一方、モデルがある程度の大きさを持っていて、ユニークな操作が多い場合は、コントローラの部分に含まれるコードが増えるのは避けがたいと思います。\n\nまた、一つ気をつけたいのは、コントローラは中(当該アプリのモデルモデル)と外(ユーザや外部システム)との仲立ちをするので、制約があり、実装はどうしても縛られるという点です。この手の議論をすると、モデルのデザインが悪い、という意見が出るものですが、コントローラは、UIとは限らず、内部のモデルと外部のモデルとのインターフェースとしての役割もありますから、きれい事ばかり言えないことはあると思います。たとえば、どんなに内部のモデルがシンプルにできていても、ある程度複雑な出力をせざるえないというのはあります。\n\nなので、見やすさと、コードの共有の程度などを勘案しながら、上記のような方法のうちから、選択してゆくしかないのではないでしょうか。\n\nConcerns も上手に使うと良い仕掛けだと思います。ただ、コードの場所が結構離れるので、わりと見通しわるくなってしまいます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T08:57:38.473", "id": "398", "last_activity_date": "2014-12-06T08:57:38.473", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "44", "parent_id": "371", "post_type": "answer", "score": 1 } ]
371
null
380
{ "accepted_answer_id": "377", "answer_count": 1, "body": "<http://at-grandpa.hatenablog.jp/entry/2013/11/01/072636>\n\nここで説明されている\"MVCの本当の姿\"というやつなんですが、これをどうやってRuby on Railsで実装するのかがさっぱり想像がつきません。\n\n例えば\"Modelの持っている加工メソッド\"っていうのはapp/models/***.rbに記述するの?とか、どうやってViewからModelの状態をみて何を元に出力するの?とかなどなどです。\n\nもうとにかく全く想像が出来ていないので、ざっくり教えて頂けたらと思います。\n細かいことや厳密な事はざっくりした理解が出来てから別途質問させて頂こうと思っています。\n\nご回答よろしくお願い致します。", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T10:52:25.973", "favorite_count": 0, "id": "372", "last_activity_date": "2014-12-08T00:51:01.793", "last_edit_date": "2014-12-08T00:51:01.793", "last_editor_user_id": "30", "owner_user_id": "705", "post_type": "question", "score": 2, "tags": [ "ruby-on-rails", "mvc" ], "title": "Ruby on Railsで「MVCの本当の姿」を実装する方法", "view_count": 1075 }
[ { "body": "> \"Modelの持っている加工メソッド\"っていうのはapp/models/***.rbに記述するの?\n\nYesです。Railsで言うMVCのModelに相当するものは、app/models\nの中に配置されている各Modelクラスが担当することになります。RoRの場合は、このModelクラスがActiveRecordによるO/R\nMapperの役割も兼ねているので混乱の元になるのですが、基本的にはこのModelクラスに「Modelの内容を加工する処理を持つメソッド」を追加していきます。その加工処理には、他の依存Modelを生成したり、複数のModelを取得して最適な情報にまとめて返す、なども含まれます。\n\n> どうやってViewからModelの状態をみて何を元に出力するの?\n\nControllerは、Modelが持つ加工処理や取得処理を呼び出した後、何らかのModelや処理結果を受け取ることになります。それらは通常Controllerのインスタンス変数にセットされますが、セットされたModelは、View、つまりRoRでいうテンプレートファイルから参照することが可能になります。つまり、Viewは業務処理結果を表すModelから画面の描画に必要な情報を引っ張ってきて、HTML内に埋めていきます。この処理のことを「Modelの状態を見て情報を出力する」という言い方をします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T13:06:26.657", "id": "377", "last_activity_date": "2014-12-05T13:06:26.657", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "531", "parent_id": "372", "post_type": "answer", "score": 5 } ]
372
377
377
{ "accepted_answer_id": null, "answer_count": 1, "body": "ASP.NET MVC 5(Visual Stodio 2013 Update 4)環境で開発しています。\n\nContent(cssなど)やScript(Javascriptなど)は通常Project直下にフォルダを作成して展開すると思います。 \nこれを各Areaごとに配置することは可能でしょうか。\n\n私が試した環境では、\n\nArea \n-hogehoge \n-Content \n-Style.css \n\nと配置しましたが、\n\n@Url.Content(~/hogehoge/Content/Style.css) も\n@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(~/hogehoge/Content/)\nもファイルが参照できなくエラーとなってしまいました。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T11:37:56.207", "favorite_count": 0, "id": "373", "last_activity_date": "2014-12-06T02:59:35.893", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "908", "post_type": "question", "score": 1, "tags": [ ".net", "c#", "asp.net", "razor" ], "title": "ASP.NET MVCでAreaごとにContentやScriptを設定したい", "view_count": 6855 }
[ { "body": "Areaではなく、Area **s** ではないですか?\n\n* * *\n\n## Url.Contentで参照する\n\n以下の構成で \n![SolutionExplorer](https://i.stack.imgur.com/lO4uk.jpg)\n\n`Style.css`は以下として \n\n```\n\n body {\n background-color: skyblue;\n }\n \n```\n\n@Url.Contentで直接指定する場合、例えば`_Layout.cshtml`でlinkタグを用意するには以下の様に指定できます。 \nLayoutを使わなくても同様に指定できると思います。\n\n```\n\n <link href=\"@Url.Content(\"~/Areas/hogehoge/Content/Style.css\")\" rel=\"stylesheet\" type=\"text/css\" />\n \n```\n\n![AffectedPage](https://i.stack.imgur.com/445Zh.jpg) \n**スタイルが反映されたページ**\n\n## Styles.Render\n\nただ、なるべくバンドルを追加して `@Styles.Render` で追加する方がいいでしょう。 \nそれには以下の様にします。\n\nまず、`App_Start/BundleConfig.cs`を開きます。\n\n![BundleConfig.cs](https://i.stack.imgur.com/YyVqj.jpg)\n\n以下のbundles.Addを追加します。\n\n```\n\n bundles.Add(new StyleBundle(\"~/Areas/hogehoge/Content/css\").Include(\n \"~/Areas/hogehoge/Content/Style.css\"\n ));\n \n```\n\n先ほど追加した `<link href=\"@Url.Content`の行を以下の様に変更します。\n\n```\n\n @Styles.Render(\"~/Areas/hogehoge/Content/css\")\n \n```\n\nスタイルを追加した場合はBundles.AddのIncludeの引数を増やしてください。 \n(すでにあると思われる`bundles.Add(new StyleBundle(\"~/Content/css\").`が参考になると思います)\n\n## 補足\n\nちなみに`BundleTable.Bundles.ResolveBundleUrl(`に関してもたとえば\n\n```\n\n <!--\n @System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(\"~/Areas/hogehoge/Content/css\") \n -->\n \n```\n\nとしておくとHTMLは以下の様に出力されますので\n\n```\n\n <!--\n /Areas/hogehoge/Content/css?v=yhOQn7MXW55kWVM6x07Bf3QlCaPBa716IIGs-NlMwiA1 \n -->\n \n```\n\nきちんと対象のURLが取れると思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T00:54:43.577", "id": "389", "last_activity_date": "2014-12-06T02:59:35.893", "last_edit_date": "2014-12-06T02:59:35.893", "last_editor_user_id": "728", "owner_user_id": "728", "parent_id": "373", "post_type": "answer", "score": 3 } ]
373
null
389
{ "accepted_answer_id": "381", "answer_count": 1, "body": "FacebookのGraph APIで/{user-\nid}/homeを使って投稿を取得すると、Facebook本家のサイトのホームに表示される投稿とずいぶん違いませんか?\n\n投稿されてから取得できるまでタイムラグがあるとか、多少違うのはいいんです。 でも結構前に投稿された物なのに全く取得できないとかで詰みませんか?\n\nFacebookグループに突撃しても英語が酷かったらしくてスルーされてたし、誰か代わりに英訳してくれませんか?\nもしくは解決方法をご存知の方がいましたら教えて下さい。\n\n友達の一覧から一人ずつ投稿を取得するのとかエレガントじゃないですよね。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T11:55:43.693", "favorite_count": 0, "id": "374", "last_activity_date": "2014-12-05T16:21:21.880", "last_edit_date": "2014-12-05T16:21:21.880", "last_editor_user_id": "30", "owner_user_id": "705", "post_type": "question", "score": 4, "tags": [ "facebook", "facebook-graph-api" ], "title": "Facebook Graph API の /user/home で得られる投稿と実際のホームの投稿が違っている", "view_count": 365 }
[ { "body": "リファレンスを見る限りニュースフィードの取得は生のデータ(read_stream)が流れてくるみたいですね。 \n<https://developers.facebook.com/docs/graph-api/reference/v2.2/user/home> \nそれに対してウェブの画面に表示されるデータは「ハイライト」「最新情報」「未読のもの」などの条件付けに加え、ユーザビヘイビアに基づいてかなりフィルタされたものが配信されています。 \nこれに似たような挙動をさせるには FQL stream_filter table を使いなさいと書いてあります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T13:54:00.357", "id": "381", "last_activity_date": "2014-12-05T13:54:00.357", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "248", "parent_id": "374", "post_type": "answer", "score": 3 } ]
374
381
381
{ "accepted_answer_id": "421", "answer_count": 2, "body": "お世話になっております。\n\n現在ListFragmentを使用し、アプリを作っているのですが、\nListFragmentの各リストをタップするとダイアログを出し、ダイアログの値をそのリストに入れたいのですが、\n動的に変更する方法がいまいち思いつきません。\n\nどなたかいい方法をご存知の方はいらっしゃらないでしょうか?\n\nよろしくお願いいたします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T13:14:56.140", "favorite_count": 0, "id": "378", "last_activity_date": "2014-12-09T06:17:54.687", "last_edit_date": "2014-12-05T14:48:05.200", "last_editor_user_id": "30", "owner_user_id": "297", "post_type": "question", "score": 1, "tags": [ "android", "android-listfragment" ], "title": "ListFragmentの各リストの動的な変更について", "view_count": 2033 }
[ { "body": "ダイアログから何かを変更するならカスタムダイアログを作って初期化時にインターフェースを渡します。\n\nインターフェースの例\n\n```\n\n public interface setInterface{\n public void setter( input );\n }\n \n```\n\nダイアログの例\n\n```\n\n public static class TestDialogFragment extends DialogFragment {\n setInterface target;\n \n //コンストラクタでinterfaceをセット\n TestDialogFragment( setInterface target ){\n this.target = target;\n }\n @Override\n public Dialog onCreateDialog(Bundle savedInstanceState) {\n AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());\n builder.setMessage(\"ダイアログ\")\n .setPositiveButton(\"はい\", new DialogInterface.OnClickListener() {\n public void onClick(DialogInterface dialog, int id) {\n target.setter( YES ); 書込み\n }\n }) \n return builder.create();\n }\n }\n \n```\n\nsetterの定義は、フラグメント自体に書いてしまうのが一番楽です。Listの各要素がデータクラスなりViewクラスなりを持っているならそちらに書きましょう。 \n例えばフラグメント自体に書くなら,\n\n```\n\n public class ItemListFragment extends ListFragment implements setInterface {\n @Override\n public void setter( String input ){ \n TextView title = this.targetView.findViewWithTag(\"title\");\n title.setText(input); \n };\n \n @Override\n public void onListItemClick (ListView l, View v, int position, long id){\n this.targetView = l;//イベント元を保持\n DialogFragment newFragment = new TestDialogFragment(this);//インターフェースを渡す\n newFragment.show(mActivity.getFragmentManager(), \"test\");\n }\n //省略\n }\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T19:00:39.140", "id": "386", "last_activity_date": "2014-12-06T14:30:13.387", "last_edit_date": "2014-12-06T14:30:13.387", "last_editor_user_id": "525", "owner_user_id": "525", "parent_id": "378", "post_type": "answer", "score": -1 }, { "body": "ダイアログは DialogFragment を使うという前提とすると、Fragment 間でどのように結果を受け渡すかというのが問題になります。\n\nポイントは以下の通りです。\n\n 1. 通知を受け取りたいフラグメントは、対象のフラグメントに対して `setTargetFragment()` を呼んで呼び出し元を知らせる。\n 2. 通知を送るフラグメントは、`getTargetFragment()` と `getTargetRequestCode()` を使い、 `onActivityResult()` で通知する。\n 3. 通知を受け取ったら、ArrayAdapter の中のデータを更新し、`notifyDataSetChanged()` で更新を反映する(ArrayAdapterの場合)。\n\n以下の様な感じで書きます。上記のポイントと関連する部分に日本語のコメントを入れておきました。\n\n<https://github.com/zaki50/DynamicListItemUpdateSample>\nに、動作するアプリが作れるプロジェクトを置きました。\n\n```\n\n package com.example.dynamiclistitemupdate;\n \n import android.app.Activity;\n import android.app.AlertDialog;\n import android.app.Dialog;\n import android.content.DialogInterface;\n import android.content.Intent;\n import android.os.Bundle;\n import android.support.v4.app.DialogFragment;\n import android.support.v4.app.ListFragment;\n import android.support.v7.app.ActionBarActivity;\n import android.view.View;\n import android.widget.ArrayAdapter;\n import android.widget.ListView;\n \n \n public class MainActivity extends ActionBarActivity {\n \n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n if (savedInstanceState == null) {\n getSupportFragmentManager().beginTransaction()\n .add(R.id.container, new MyListFragment())\n .commit();\n }\n }\n \n public static class MyListFragment extends ListFragment {\n \n private static final int REQ_DIALOG = 1;\n \n private int mItemIndex = -1;\n \n private String[] mItemData = {\"-\", \"-\", \"-\", \"-\", \"-\"};\n \n public MyListFragment() {\n }\n \n @Override\n public void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n \n setListAdapter(new ArrayAdapter<>(getActivity(),\n android.R.layout.simple_list_item_1, mItemData));\n }\n \n @Override\n public void onListItemClick(ListView l, View v, int position, long id) {\n super.onListItemClick(l, v, position, id);\n \n mItemIndex = position - l.getHeaderViewsCount();\n \n DialogFragment newFragment = new MyDialogFragment();\n // ダイアログフラグメントに対して、結果の通知先を指定。結果は onActivityResult を呼び出すことで通知される\n newFragment.setTargetFragment(this, REQ_DIALOG);\n newFragment.show(getChildFragmentManager(), \"dialog\");\n }\n \n @Override\n public void onActivityResult(int requestCode, int resultCode, Intent data) {\n super.onActivityResult(requestCode, resultCode, data);\n \n if (requestCode != REQ_DIALOG || resultCode != RESULT_OK) {\n return;\n }\n \n if (mItemIndex < 0 || data == null\n || data.getStringExtra(MyDialogFragment.RESULT_EXTRA_KEY_TEXT) == null) {\n return;\n }\n \n // ArrayAdapter の中の配列を更新し、notifyDataSetChanged() で更新を通知する\n mItemData[mItemIndex] = data.getStringExtra(MyDialogFragment.RESULT_EXTRA_KEY_TEXT);\n final ArrayAdapter<?> adapter = (ArrayAdapter<?>) getListAdapter();\n adapter.notifyDataSetChanged();\n }\n }\n \n public static class MyDialogFragment extends DialogFragment {\n public static final String RESULT_EXTRA_KEY_TEXT = \"text\";\n \n public MyDialogFragment() {\n }\n \n @Override\n public Dialog onCreateDialog(Bundle savedInstanceState) {\n AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());\n builder.setMessage(\"ダイアログ\")\n .setPositiveButton(\"はい\", new DialogInterface.OnClickListener() {\n public void onClick(DialogInterface dialog, int id) {\n sendResult(Activity.RESULT_OK, \"yes\");\n }\n })\n .setNegativeButton(\"いいえ\", new DialogInterface.OnClickListener() {\n @Override\n public void onClick(DialogInterface dialog, int which) {\n sendResult(Activity.RESULT_OK, \"no\");\n }\n });\n return builder.create();\n }\n \n /**\n * 結果をダイアログ表示元へ通知するためのメソッド。\n *\n * targetFragment に通知元がセットされているので、onActivityResult を呼び出すことで通知を行う。\n */\n private void sendResult(int resultCode, String str) {\n final Intent data = new Intent();\n \n if (str != null) {\n data.putExtra(RESULT_EXTRA_KEY_TEXT, str);\n }\n \n // 結果を通知する\n getTargetFragment().onActivityResult(getTargetRequestCode(), resultCode, data);\n }\n }\n }\n \n```\n\n別解として、event bus 系のライブラリを使うという方法もあります。いくつか有名所を上げておきます。\n\n * [greenrobot EventBus](https://github.com/greenrobot/EventBus)\n * [Otto](http://square.github.io/otto/)\n * [Guava](https://code.google.com/p/guava-libraries/wiki/EventBusExplained)\n\n私は greenrobot EventBus を使うことが多いですが、 Otto もよく使われているようです。event bus\nについてはQiitaにも[エントリ](http://qiita.com/KeithYokoma/items/793aaac6994c9242808f)がありました。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T06:21:01.013", "id": "421", "last_activity_date": "2014-12-09T06:17:54.687", "last_edit_date": "2014-12-09T06:17:54.687", "last_editor_user_id": "319", "owner_user_id": "319", "parent_id": "378", "post_type": "answer", "score": 5 } ]
378
421
421
{ "accepted_answer_id": null, "answer_count": 1, "body": "## Cordovaでandroidの開発をしています。\n\n動画再生について質問です。 \n\n### 【目的】\n\nCordovaで作成したアプリ内でvideoタグを使用してhtml内部で動画を再生させたい。 \nAndroid 5.0では動作したが、Android 4.4.2でWebViewを使用した場合に再生できない。\n\n### 【問題点】\n\n動画が100秒までしか再生できない。 \n\n### 【使ってるライブラリ等々】\n\n 1. Cordova(androidで開発)\n 2. File API(Cordova plugin <https://github.com/apache/cordova-plugin-file>)\n 3. inappbrowser(Cordova plugin <https://github.com/apache/cordova-plugin-inappbrowser>)\n 4. CorHttpd(Cordova plugin <https://github.com/floatinghotpot/cordova-httpd>)\n\n### 【経緯】\n\n動画の再生のため、CordovaプラグインのFile APIを使って \n\n```\n\n /data/data/<app-id>/files/\n \n```\n\n以下にファイルを配置し、そこで動画を再生していたのですが、100秒までしか再生できませんでした。 \n\n動画へのアクセスがfileプロトコルだったので、httpプロトコルでのアクセスにしようとcordova.httpdプラグインを使用して、android内部でwebサーバを立ち上げました。 \n同時にfileプロトコルからhttpプロトコルへのアクセスはできないため、inappbrowserプラグインを使用して、別windowを立ち上げ、その内部で、video再生用HTMLを表示させていました。 \n\n```\n\n http://192.168.2.1:8080/sample/sample.html\n \n```\n\nとして、アクセスできます。\n\nここで問題が出ました。 \nandroid端末がwifiに接続されていた場合(オンライン時)は動画が全て再生されるのですが、 \nwifiに繋がっていない場合は上記のような100秒までしか再生できない現象になります。 \nオフライン時は\n\n```\n\n http://127.0.0.1:8080/sample/sample.html\n \n```\n\nへのアクセスになります。\n\nchromeのadb exentionを使用して、つながっているandroidのWeb\nViewのデバッグができるので、そこでログ追っていると、動画ファイル読み込みが、`(pending)`表示になっていました。 \n\n【目的】が達成できればよいので、手段は問わないのですが、動画を読み込ませる方法、または動画再生方法はないでしょうか?", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T13:19:48.547", "favorite_count": 0, "id": "379", "last_activity_date": "2016-06-22T23:29:39.027", "last_edit_date": "2015-01-05T12:40:14.013", "last_editor_user_id": "724", "owner_user_id": "899", "post_type": "question", "score": 8, "tags": [ "android", "webview", "cordova", "video" ], "title": "Cordova(android)で動画再生のため、端末内部でwebサーバを立ち上げたが、オフラインになると再生できない", "view_count": 2639 }
[ { "body": "[質問者 silvermotto さんのコメント](https://ja.stackoverflow.com/questions/379/cordova-\nandroid-%E3%81%A7%E5%8B%95%E7%94%BB%E5%86%8D%E7%94%9F%E3%81%AE%E3%81%9F%E3%82%81-%E7%AB%AF%E6%9C%AB%E5%86%85%E9%83%A8%E3%81%A7web%E3%82%B5%E3%83%BC%E3%83%90%E3%82%92%E7%AB%8B%E3%81%A1%E4%B8%8A%E3%81%92%E3%81%9F%E3%81%8C-%E3%82%AA%E3%83%95%E3%83%A9%E3%82%A4%E3%83%B3%E3%81%AB%E3%81%AA%E3%82%8B%E3%81%A8%E5%86%8D%E7%94%9F%E3%81%A7%E3%81%8D%E3%81%AA%E3%81%84#comment5803_379)より。\n\n> Crosswalkで別のactivityを立ち上げinappbrowserのかわりとすることで対応できました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-06-22T23:29:39.027", "id": "26963", "last_activity_date": "2016-06-22T23:29:39.027", "last_edit_date": "2017-04-13T12:52:38.920", "last_editor_user_id": "-1", "owner_user_id": "8000", "parent_id": "379", "post_type": "answer", "score": 1 } ]
379
null
26963
{ "accepted_answer_id": "388", "answer_count": 2, "body": "Webアプリケーション開発時など、複数のiOS\nSimulatorで同時にテストしたいケースがあります。1台のMacで、複数のエミュレータを同時に起動する方法はあるでしょうか?\n\n参考まで、手元で試した次の方法はいずれもうまく行きませんでした。2つ目のインスタンスを立ち上げようとすると、「Unable to boot device\nin current state: Booted」というエラーが出て、黒い画面だけが表示されます。\n\n1) `open`コマンドで、`-n`オプションを指定する。\n\n```\n\n $ open -n -a /Applications/Xcode.app/Contents/Developer/Applications/iOS\\ Simulator.app`\n \n```\n\n2) 別ユーザで、`open`コマンドを使う。\n\n```\n\n $ su OtherUser\n $ open -n -a /Applications/Xcode.app/Contents/Developer/Applications/iOS\\ Simulator.app`\n \n```\n\n![2つめのインスタンス](https://i.stack.imgur.com/kAdd1.jpg)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T17:33:39.293", "favorite_count": 0, "id": "384", "last_activity_date": "2014-12-06T04:46:00.773", "last_edit_date": "2014-12-05T23:15:10.770", "last_editor_user_id": "30", "owner_user_id": "390", "post_type": "question", "score": 9, "tags": [ "ios", "macos", "ios-simulator" ], "title": "iOS Simulatorを多重起動する方法", "view_count": 3575 }
[ { "body": "stackoverflow英語版のこの回答 <https://stackoverflow.com/a/3717027/3474143?stw=2>\nが参考になると思います。\n\nこのアプリ\n<http://www.coderebel.com/2010/08/31/iphone_simulator>(実体は単なるシェルスクリプト)を使うと、複数セッションできるよう設定を変更した後、iPhoneSimulator\nを起動してくれ、ユーザ毎に個別の iPhoneSimulator を起動できるようになりました。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-05T19:48:19.267", "id": "388", "last_activity_date": "2014-12-05T21:31:24.687", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "658", "parent_id": "384", "post_type": "answer", "score": 6 }, { "body": "(解決が見つかったので、自己レスです)\n\nopenコマンドだと、別ユーザで起動できませんでした。別ユーザをGUIで作成した後、直接実行ファイルをsudoすることで、複数のiOS\nSimulatorを同時起動できました。\n\n```\n\n $ sudo -u <別ユーザ名> /Applications/Xcode.app/Contents/Developer/Applications/iOS\\ Simulator.app/Contents/MacOS/iOS\\ Simulator\n \n```\n\n![複数起動したiOS Simulator](https://i.stack.imgur.com/Gxkv5.jpg)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T04:46:00.773", "id": "395", "last_activity_date": "2014-12-06T04:46:00.773", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "390", "parent_id": "384", "post_type": "answer", "score": 4 } ]
384
388
388
{ "accepted_answer_id": "394", "answer_count": 1, "body": "Twitter Bootstrapについてです。 \nBootstrapのスタイルは、デフォルトで \nチェックボックスのラベルをクリックすると(画像の「画像を削除する」のラベル)、 \nチェックボックスがtoggleされます。\n\n![画像](https://i.stack.imgur.com/KtASg.png)\n\nしかし、JSで動的にフォームを挿入した後のチェックボックスは、 \nラベルをクリックしてもtoggleされません。\n\npopoverなどの機能であれば、\n\n```\n\n $('[rel=popover]').popover();\n \n```\n\nなどで、再度初期化できるかと思います。\n\nそのようなフォームの動的な作成後に使用できるBootstrap内のJS \n(ラベルクリックがJSでなされているかは不明ですが)はあるのでしょうか?\n\nどのようにラベルのcheckboxのtoggleを有効化させればよいでしょうか?\n\n===== 訂正 ======\n\n同じページ上に同一のIDが存在したためでした。 \nもちろんformタグはそれぞれに分かれてます。\n\n```\n\n <div class=\"checkbox\">\n <label for=\"course_enabled\">\n <input name=\"course[enabled]\" type=\"hidden\" value=\"0\" />\n <input checked=\"checked\" id=\"course_enabled\" name=\"course[enabled]\" type=\"checkbox\" value=\"1\" /> 使用可能\n </label>\n </div>\n \n```\n\nfor attribute をなくせば可能かもしれません。) \nRailsのフォーム生成のgemに依存しているため少し手こずりそうですが・・・ \n(別のラベルを作成してidとforを合わせれば動作しました。\n\n勘違いだったため、別の問題なのでクローズします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T03:09:01.093", "favorite_count": 0, "id": "391", "last_activity_date": "2019-12-13T13:47:16.293", "last_edit_date": "2014-12-06T06:45:59.243", "last_editor_user_id": "512", "owner_user_id": "512", "post_type": "question", "score": 1, "tags": [ "css", "bootstrap" ], "title": "Bootstrapで動的にフォームを作るとチェックボックスのラベルをクリックしても機能しない", "view_count": 3425 }
[ { "body": "jsによってformを生成して、そのチェックボックスのラベルをクリックしてもチェックのオン・オフが起こらない、ということですよね?\n\nためしに作成してみましたが、ラベルをクリックしても動作します(Chromeでのみ確認)\n\n```\n\n addform = function() {\r\n var form = $('#target:first');\r\n form.append('<form><label><input class=\"form-control checkbox\" type=\"checkbox\"/>abc</label></form>')\r\n }\n```\n\n```\n\n <link rel=\"stylesheet\" href=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css\">\r\n <script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script>\r\n <script src=\"http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js\"></script>\r\n <div id=\"target\">\r\n </div>\r\n <button onclick=\"addform()\">add form</button>\n```\n\nなにか違う点があればお知らせください。\n\nそれでも解決しないようでしたら試してはいませんが\n\n * css classを後から設定してみる\n * formを動的に生成ではなく非表示にしておく\n * チェックボックスなどのコントロールの生成を元々HTMLで用意しておいた非表示のチェックボックスのクローンで生成する( `var newCheckbox=$(\"#templateCheckbox\").clone();` )\n\nという方法もなにか変化がおこるかもしれません。\n\n* * *\n\nfiddleに挙げたもののソース\n\n```\n\n <!DOCTYPE html>\n <html>\n <head lang=\"en\">\n <link rel=\"stylesheet\" href=\"bower_components/bootstrap/dist/css/bootstrap.min.css\"/>\n <script src=\"bower_components/jquery/dist/jquery.min.js\"></script>\n <script src=\"bower_components/bootstrap/dist/js/bootstrap.min.js\"></script>\n <meta charset=\"UTF-8\">\n <title></title>\n <script>\n addform = function(){\n var form = $('#target:first');\n form.append('<form><label><input class=\"form-control checkbox\" type=\"checkbox\"/>abc</label></form>')\n }\n </script>\n </head>\n <body>\n <div id=\"target\"></div>\n <button onclick=\"addform()\">add form</button>\n \n </body>\n </html>\n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2014-12-06T04:05:30.907", "id": "394", "last_activity_date": "2019-12-13T13:47:16.293", "last_edit_date": "2019-12-13T13:47:16.293", "last_editor_user_id": "32986", "owner_user_id": "728", "parent_id": "391", "post_type": "answer", "score": 2 } ]
391
394
394
{ "accepted_answer_id": null, "answer_count": 1, "body": "_(指摘を受けて編集しています)_\n\n現在、UINavigationControllerを使ってiOSの開発を行っています。\nややトリッキーな使い方ではありますが、UINavigationControllerで普通に生成されたビューの中に、\nさらに「UINavigationController > UIViewController >\nUITableView」という構造を持ったものを表示しようとしています。\n\n具体的には、UINavigationControllerで表示されたビューに対し、\nUINavigationBar上のボタンを押下された際に以下のように処理しています。\n\n 1. UIViewを継承したカスタムViewを生成(HogePopupView)\n 2. UINavigationControllerを生成\n 3. (2)に表示するカスタムViewControllerを生成\n 4. (3)をrootに`initWithRootViewController:`を呼び出す\n 5. (1)のviewを、生成元のviewControllerのviewにaddSubviewする\n\n※ storyboardは一切使っていません。\n\n**設計の思惑としては、単純にカスタムのUIViewを生成してaddSubviewするだけで使えるようにしたい、というものです。**\n\nカスタムviewの目的としては、現在表示されているビューの上にオーバーレイする形で 画面全体からやや小さい、ポップアップのビューを表示したいと考えています。\n\niOS7, iOS8では特に問題なく表示されているのですが、なぜかiOS6のみ、 上記のUITableViewが20px(おそらくStatus\nbar分)上にずれる、という現象が発生しています。\nビューが表示されたあと(viewWillAppearなど)に位置を変更する処理を入れてもなぜか変更されません。\n(具体的には、UITableViewの引っ張って更新が出てくる上端がUINavigationBarが少し重なっている状態です)\n\nこうして入れ子にした場合に起こる挙動の違いはなにが考えられるでしょうか?\n(個人的にはUINavigationControllerの挙動として、自動的にステータスバーを考慮した補正がかかるのでは、と思っています)\n\nだいぶ抽象的な質問ですみません。\n\n[追記] 実装上の問題としては解決しました。 (UINavigationBar側を逆に上にずらした)\nただ、本質的な改善にはなっていないので、見た目の整合性を取った、という感じです。", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T05:40:01.533", "favorite_count": 0, "id": "396", "last_activity_date": "2014-12-08T05:39:13.987", "last_edit_date": "2014-12-08T01:01:04.880", "last_editor_user_id": "100", "owner_user_id": "100", "post_type": "question", "score": 1, "tags": [ "ios", "objective-c", "ios6", "uinavigationcontroller" ], "title": "iOS6でのみ、UINavigationControllerの入れ子で最初のsub viewの位置がずれる", "view_count": 1024 }
[ { "body": "コードを再現できないので、本当に解決できるかどうかはわかりませんが、 \n親のUIViewControllerにaddSubViewする前に、以下のように[addChildViewController](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/addChildViewController:)を呼び出すとどうなりますか?\n\n```\n\n [self addChildViewController:childVC];\n [childVC didMoveToParentViewController:self];\n [mainView addSubview:childVC.view];\n \n```\n\n英語版でも同じような質問はあって、addChildViewControllerを呼び出すと直った、というようなコメントがありました。\n\n * [UIViewController's view has weird 20px y margin](https://stackoverflow.com/q/11252395/718426)\n\naddChildViewControllerが何をやっているかですが、この質問がわかりやすいかなと思います。\n\n * [What does addChildViewController actually do?](https://stackoverflow.com/q/17192005/718426)\n\n[正解とされている回答](https://stackoverflow.com/a/18453401/718426)によれば、addChildViewControllerがやることはそう多くなくて、あるUIViewControllerの子であると宣言することで、様々なイベントの情報が通知されるようになる、とのことです。\n\n//できれば、github等々にコードを貼ってもらえると追試が楽です。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T05:39:13.987", "id": "442", "last_activity_date": "2014-12-08T05:39:13.987", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "351", "parent_id": "396", "post_type": "answer", "score": 1 } ]
396
null
442
{ "accepted_answer_id": "402", "answer_count": 1, "body": "Rails4(4.2.0.rc1)でコントローラーのPOSTアクションのテストを書こうとしたのですが、ActionController::ParameterMissing\nのエラーでテストできません。\n\n### コントローラー\n\n```\n\n class UsersController < ApplicationController\n \n # ... 省略 ...\n \n def create\n @user = User.new(user_params)\n if @user.save\n flash[:success] = \"Welcome to Sample App!\"\n log_in @user\n redirect_to @user\n else\n render 'new'\n end\n end\n \n # ... 省略 ...\n \n```\n\n### テスト\n\n```\n\n require 'test_helper'\n \n class UsersControllerTest < ActionController::TestCase\n \n test \"should post create\" do\n post :create,\n name: \"abc\",\n email: \"test@example.com\",\n password: \"passwd\",\n password_confirmation: 'passwd'\n assert_response :success\n end\n end\n \n```\n\n### エラー\n\n```\n\n test_should_post_create#UsersControllerTest (0.64s)\n ActionController::ParameterMissing: ActionController::ParameterMissing: param is missing or the value is empty: user\n app/controllers/users_controller.rb:37:in `user_params'\n app/controllers/users_controller.rb:11:in `create'\n test/controllers/users_controller_test.rb:10:in `block in <class:UsersControllerTest>'\n app/controllers/users_controller.rb:37:in `user_params'\n app/controllers/users_controller.rb:11:in `create'\n test/controllers/users_controller_test.rb:10:in `block in <class:UsersControllerTest>'\n \n```\n\nWebブラウザ上のフォームでは実行できていて、POSTパラメータをのぞくと、テストで指定しているのと同じ`name`, `email`,\n`password`, `password_confirmation` が入っていました。 \nどうすればエラーなく実行できますか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T13:23:16.323", "favorite_count": 0, "id": "399", "last_activity_date": "2014-12-20T11:55:25.833", "last_edit_date": "2014-12-20T11:55:25.833", "last_editor_user_id": "33", "owner_user_id": "645", "post_type": "question", "score": 4, "tags": [ "ruby", "ruby-on-rails", "テスト" ], "title": "Rails4でコントローラーのPOSTアクションのテストをしたいが ActionController::ParameterMissing のエラーでテストできない", "view_count": 2363 }
[ { "body": "自己解決してしまいました。\n\n```\n\n post :create,\n user: {\n name: \"abc\",\n email: \"test@example.com\",\n password: \"passwd\",\n password_confirmation: 'passwd'\n }\n \n```\n\nの形のハッシュをパラメータにしないといけませんでした。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T14:42:12.723", "id": "402", "last_activity_date": "2014-12-06T14:42:12.723", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "645", "parent_id": "399", "post_type": "answer", "score": 3 } ]
399
402
402
{ "accepted_answer_id": "495", "answer_count": 3, "body": "Dockerfileで実行できるコマンド数を減らす方法に関して、なにか知ってれば教えて下さい。\n\n自分の場合、下記のようにコマンドまとめたりして頑張ってるのですが、他なにかいい手段ありますか?\n\n```\n\n RUN \\\n yum -y update; \\\n yum install httpd....\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T14:01:28.387", "favorite_count": 0, "id": "400", "last_activity_date": "2017-04-30T09:46:40.420", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "291", "post_type": "question", "score": 6, "tags": [ "docker" ], "title": "Dockerfileのダイエット方法を教えて下さい", "view_count": 4038 }
[ { "body": "Docker Hub\nにある既存のイメージをなるべく多用し、一つのイメージでいろいろ詰め込む代わりに複数のイメージをリンクして使用するような方法で逃げられないでしょうか?\n\nまた、シェルスクリプト等を ADD して、そのファイルを RUN で実行するようにすると RUN の数は抑えられると思いますがどうでしょう?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T06:24:36.410", "id": "422", "last_activity_date": "2014-12-07T06:24:36.410", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "73", "parent_id": "400", "post_type": "answer", "score": 2 }, { "body": "基本的に、[Optimizing Docker Images](http://www.centurylinklabs.com/optimizing-\ndocker-images/)このページでまとめられているのが有力なものです。\n\n以下では、これに加えて私がイメージを作る際に周囲からもらったアドバイスや試してみたことなども含めて書いてみます。\n\n## 可能な限り、必要最小限のサイズのイメージからスタートする\n\n上記ページにも記載があるように、例えばUbuntuよりもDebianを使います。私の場合は趣味的にはUbuntuが好きなのですが、配布用のDockerイメージはDebianのwheezyベースなどで作っています。上記ページにもあるように、これだけで100MBぐらい違ったりします。\n\n## RUNでのコマンドをチェーンさせてステージ数を減らす\n\ntorusさんの回答にあるものです。DockerではRUNの単位でファイルシステムの更新をおこなうので、仮にあるステージで大きなファイルを追加、その後のステージで当該ファイルを削除しても容量は食いっぱなしとなります。\n私が過去に作ったものでは、あるソフトウェアのソースを拾ってきてmake && make\ninstall、その後にソース一式を削除するところまでをひとつにチェーンさせることで容量削減できました。\n\n## 不要な中間ファイルは削除する\n\n私がイメージを作成していた時に指摘をもらったものなのですが、`/usr/local/src`以下にあるソースを拾ってきて、それを`make && make\ninstall`したままソースコードを残していたことがありました。\n\nこれは、ソースを残しておいたほうが何かといじりやすいと考えての対応でした。さらに言うと、あるソースのスナップショットではなく丸ごとgit\ncloneしていました。これは様々な実験をおこなう際には便利ですし開発環境のDockerイメージを提供しようという際には良いのです。しかしバイナリ配布でサクッと導入してもらえるようなイメージの構築においてはただの無駄ということで納得しました。\n\nソースは`make install`が終わったら消しましょう。ソースが本当に必要な人は、Dockerfileをforkして自前でなんとかしてくれます多分。\n\n## GitHubからソースを拾ってくるものについて、なるべく`git clone`しない\n\nもっと言うと、不要ならgitコマンドをインストールしない(いくらgitのない世界が不安で仕方なくても)。\n\nこれも私がとあるイメージを作成していた時にもらった指摘に関するものです。 GitHubで配布されているコードを使ったビルドをおこなうならひとまず`git\nclone`してくるのが普通だろうという開発脳なのですが、Dockerのイメージを作る際には「えっ、ほんとにgitいる?」と疑うのが肝心です。\nDebianでgit-\ncoreパッケージをインストールするだけでも数十MBの追加容量が必要となるので、指定リリースの*.tar.gzファイルを拾ってきて展開すれば十分なケースではgitのインストールすら避けるのが良いでしょう。\n\n繰り返しとなりますが、チーム用などに開発用環境を用意する際は別です。\n\n## 特に事情がなければディストリビューションのバイナリ配布物を利用する\n\nソフトウェアパッケージのビルドには多くの追加パッケージが必要です。gcc、libstdc++6-dev、make、autotools、cmakeなどなど。build-\nessentialをえいやっと追加すると一気にディスク容量が膨らみます。\n\nというわけで、もし特殊な事情がなければ、なるべくディストリビューションの提供するバイナリ配布物を使うようにDockerfileを記述すべきです。\n\nしかし、ディストリビューションの公式パッケージに入っていないものやバージョンが古いもの・互換性のないものなどについては仕方ありません。なるべく追加容量が最小限で済むように留意しつつ、パッケージをインストールしましょう。\n\n## イメージビルド中の多階層ディレクトリに対するchownを避ける\n\n[Dockerfile Golf (or optimizing the Docker build\nprocess)](http://www.davidmkerr.com/2014/08/dockerfile-golf-or-optimizing-\ndocker.html)で紹介されていました。\n\nこれもDockerの構造がステージごとにファイルシステム状態を記録することに関連します。このblogでは、特定ディレクトリへのchownをビルドフェーズでおこなったところ、72MBもの容量増につながったという話が紹介されています。\n\n代替策として、chownを`COMMAND`での起動シーケンスへと移動したということです。なかなか難しいですね。\n\n## `ONBUILD`を利用して一部処理をイメージ実行時へ逃がす\n\n利用できるシーンが一定限られますが、例えば「あるシステムの実行のために大量の静的ファイル(しかもそれなりに頻繁な更新がおこなわれる)を拾ってくる必要がある」といった場合に有効です。\n\nコンテナの一部として頻繁な更新のおこなわれるファイル群を利用する場合、それらが更新される都度Docker\nHubでのビルドをおこなうのはあまり効率的と言えません。\n\nそこで用意されているのが`ONBUILD`コマンドです。`RUN`コマンドがイメージ生成時に実行されるコマンドであるのに対して、`ONBUILD`コマンド([マニュアル](https://docs.docker.com/reference/builder/#onbuild))は当該処理をコンテナ生成時まで後回しするものです。\n\n## 番外編: 既存の巨大イメージをダイエットする\n\n基本的にはDockerfileを編集してイメージ作り工程を改善するお話ですが、仮にDockerfileへアクセスできなくてもとれる策がこれです(これも上記ページで紹介されています)。\n\n実行中のコンテナを指定して\n\n`docker export <container id> | docker import - <new image name>`\n\nで、イメージのビルド時にステージごとに生成されたレイヤがごっそり統合されます。結果として、ベースイメージからの差分保持すらされなくなるため、場合によっては当該イメージ単体のサイズは増えるかもしれません。\n\n他方、パフォーマンス面では実行時にアクセスするfsレイヤを減らせるのでファイルI/O面は多少有利になるかもしれません。\n\nメリットとデメリットを把握して利用する必要のある策です。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-10T08:55:49.830", "id": "495", "last_activity_date": "2014-12-10T08:55:49.830", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "777", "parent_id": "400", "post_type": "answer", "score": 17 }, { "body": "回答というより追加情報のような形になりますが・・・\n\n開発したWebアプリケーションを`git clone`してコンテナに入れる場合は、 \n動作に不要な`.dockerignore`で`node_modules`や`.git`をコンテナ内にコピーしないようにする必要があります。 \n`git clone --depth=1`をしたとしても`.git`にかなりの容量を食われていたりします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-04-30T09:46:40.420", "id": "34390", "last_activity_date": "2017-04-30T09:46:40.420", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "336", "parent_id": "400", "post_type": "answer", "score": 1 } ]
400
495
495
{ "accepted_answer_id": "410", "answer_count": 2, "body": "Linux環境でrubyをビルドして `/usr/local` 以下にインストールしました。 \nその後 [rbenv](https://github.com/sstephenson/rbenv) でrubyをインストールしたため\n`/usr/local/bin` にあるrubyが不要になりました。\n\nまた、gemをインストールしたときに `/usr/local/bin` に置かれたコマンドも削除したいです。 \n`/usr/local` 以下のrubyに関するファイルをすべて削除する方法はありますか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T18:20:01.120", "favorite_count": 0, "id": "405", "last_activity_date": "2014-12-07T04:55:52.307", "last_edit_date": "2014-12-06T18:28:13.867", "last_editor_user_id": "724", "owner_user_id": "724", "post_type": "question", "score": 2, "tags": [ "ruby", "linux" ], "title": "Linuxでビルドしてインストールしたrubyに関するファイルをすべて削除するには", "view_count": 1175 }
[ { "body": "アーカイブを展開してmakeした後のディレクトリに\".installed.list\"という名前のファイルがあると思うので、探してください。その中に、インストールされたファイルのリストが記録されています。各種記録されているファイルの場所が/usr/local下であれば、.install.listに書かれたファイルを消していけば、ご希望のお掃除ができると思います。注意点としては、ディレクトリは消さずに、ファイルのみ削除してください。\n\ngemについては、gemsディレクトリ丸ごとと、gemコマンドを消せば良いと思います。\n\n上記作業によって消してはいけないファイルを消してしまうかも知れないので、削除行為はくれぐれもご注意を・・・(消さずに一旦 ~/tmp\nとかに移動させてしばらく様子見る、とかがオススメです)。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T23:43:46.507", "id": "410", "last_activity_date": "2014-12-06T23:43:46.507", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "531", "parent_id": "405", "post_type": "answer", "score": 6 }, { "body": "StackOverflowに、\"[How to uninstall Ruby from\n/usr/local?](https://stackoverflow.com/questions/2591501/how-to-uninstall-\nruby-from-usr-local)\"\nというタイトルで同じような質問がされてましたのでそれを参照するといいと思います。以下はその方法を日本語で書きました。\n\nrubyがどこにあるか確認:\n\n```\n\n whereis ruby\n \n```\n\nrubyがある場所を教えてくれるのでrubyを削除:\n\n```\n\n rm -rf /usr/local/lib/ruby\n rm -rf /usr/lib/ruby\n rm -f /usr/local/bin/ruby\n rm -f /usr/bin/ruby\n rm -f /usr/local/bin/irb\n rm -f /usr/bin/irb\n rm -f /usr/local/bin/gem\n rm -f /usr/bin/gem\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T04:55:52.307", "id": "418", "last_activity_date": "2014-12-07T04:55:52.307", "last_edit_date": "2017-05-23T12:38:56.083", "last_editor_user_id": "-1", "owner_user_id": "556", "parent_id": "405", "post_type": "answer", "score": 1 } ]
405
410
410
{ "accepted_answer_id": "407", "answer_count": 2, "body": "実行時に、関数からその関数を実行せずに必要な引数の数を知るにはどうすれば良いですか?\n\n```\n\n <?php\n \n function myFunc($a, $b, $c)\n {\n return \"$a, $b and $c!\";\n }\n \n```\n\nこのような関数を定義したとき、`$a, $b, $c` という三つの引数を必要とするので「3」という数が知りたいです。\n\nまた、メソッドについても同じように調べられますか?\n\n```\n\n <?php\n \n class Hoge\n {\n public static function fuga ($a, $b)\n {\n return \"fuga: $a and $b!\";\n }\n \n public function piyo ($a, $b, $c)\n {\n return \"piyo: $a, $b and $c!\";\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T18:35:21.523", "favorite_count": 0, "id": "406", "last_activity_date": "2014-12-11T02:55:33.667", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "938", "post_type": "question", "score": 5, "tags": [ "php" ], "title": "関数やメソッドの引数の数を調べるにはどうすればいい?", "view_count": 2675 }
[ { "body": "PHPの実行時にクラスや函数などの詳細な情報を取得するには[リフレクション](http://php.net/manual/book.reflection.php)といふ仕組を利用します。\n\n今回のように函数の情報を知りたいときには、[ReflectionFunction](http://php.net/manual/class.reflectionfunction.php)を利用することができます。\n\n```\n\n <?php\n \n $func_ref = new ReflectionFunction(\"myFunc\");\n echo $func_ref->getNumberOfParameters() . PHP_EOL;\n // 3\n \n```\n\nこの仕組は、もちろんPHPの標準函数に対しても、[無名関数](http://php.net/manual/functions.anonymous.php)に対しても利用することができます。\n\nメソッドは方法が少し違って、[ReflectionClass](http://php.net/manual/class.reflectionclass.php)から[ReflectionMethod](http://php.net/manual/class.reflectionmethod.php)を取得します。\n\n```\n\n <?php\n \n $c = new ReflectionClass(\"Hoge\");\n echo $c->getMethod(\"fuga\")->getNumberOfParameters() . PHP_EOL;\n // 2\n echo $c->getMethod(\"piyo\")->getNumberOfParameters() . PHP_EOL;\n // 3\n \n $d = new ReflectionClass(new Hoge);\n echo $d->getMethod(\"fuga\")->getNumberOfParameters() . PHP_EOL;\n // 2\n echo $d->getMethod(\"piyo\")->getNumberOfParameters() . PHP_EOL;\n // 3\n \n```\n\n`new ReflectionClass` はクラス名を渡す方法とインスタンスを渡す方法のどちらでも大丈夫です。\n\n詳細については[PHP - 函数・クロージャの引数の個数を調べる -\nQiita](http://qiita.com/tadsan/items/b539eab11fb6902c17f1)も併せて読んでください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T18:35:21.523", "id": "407", "last_activity_date": "2014-12-06T18:35:21.523", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "938", "parent_id": "406", "post_type": "answer", "score": 6 }, { "body": "リフレクションを使わなくても引数を動的に扱える関数があります。\n\n<http://php.net/manual/ja/function.func-get-args.php>\n\n配列で引数が取得できるので数えれば個数も分かりますし、好きな順番で扱うこともできます。\n動的な処理を行うライブラリやフレームワーク的な実装をする際に昔から疲れている関数です。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-11T02:55:33.667", "id": "497", "last_activity_date": "2014-12-11T02:55:33.667", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "452", "parent_id": "406", "post_type": "answer", "score": -1 } ]
406
407
407
{ "accepted_answer_id": null, "answer_count": 2, "body": "[ArrayAccess](http://php.net/manual/class.arrayaccess.php)を実装すれば、自作のクラスのインスタンスオブジェクトを配列のように利用することができそうです!\n\nしかし、`array_map`などの配列系の標準函数には利用できませんでした。\n\n以下のコードでは簡単のために、SPLに含まれる[ArrayIterator](http://php.net/manual/class.arrayiterator.php)を例にとります。\n\n```\n\n <?php\n array_map('gettype', array_map('floatval', [1, 2, 3]));\n // [\"double\", \"double\", \"double\"]\n \n array_map('gettype', array_map('floatval', new ArrayIterator([1, 2, 3])));\n // PHP Warning: array_map(): Argument #2 should be an array in /tmp/array_access.php on line 5\n // PHP Warning: array_map(): Argument #2 should be an array in /tmp/array_access.php on line 5\n \n```\n\n自作のオブジェクトや`ArrayIterator`などの`ArrayAccess`を実装したクラスのインスタンスを配列と区別なく利用したいのですが、何か解決策はありますか?\n\nタイプヒントで`array`を期待する箇所で利用できると、もっと嬉しいです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T19:25:00.650", "favorite_count": 0, "id": "408", "last_activity_date": "2014-12-16T10:40:40.810", "last_edit_date": "2014-12-07T06:25:17.650", "last_editor_user_id": "728", "owner_user_id": "938", "post_type": "question", "score": 2, "tags": [ "php" ], "title": "array_mapにArrayAccessを実装したオブジェクトを利用する方法はありますか?", "view_count": 649 }
[ { "body": "タイトルにある `array_mapにArrayAccessを実装したオブジェクトを利用する方法` \nという意味ですと、`ArrayIterator::getArrayCopy`や`iterator_to_array`を使って配列に変換すれば可能とは思いますが、\n\n```\n\n array_map('gettype', array_map('floatval', (new ArrayIterator([1, 2, 3]))->getArrayCopy()));\n array_map('gettype', array_map('floatval', iterator_to_array(new ArrayIterator([1, 2, 3]))));\n \n```\n\n`配列と区別なく利用したい`という事ですと、「`ArrayIterator`は配列で無くオブジェクトである」、「配列はオブジェクトではない」となりますのでArrayIteratorを配列そのものとして扱うのは残念ながらできないと思います。\n\n```\n\n <?php\n \n $iterator=new ArrayIterator([1, 2, 3]);\n $array=[1,2,3];\n \n var_dump(is_array($array));\n var_dump(is_array($iterator));\n \n var_dump(is_object($array));\n var_dump(is_object($iterator));\n \n```\n\n結果:\n\n```\n\n bool(true)\n bool(false)\n bool(false)\n bool(true)\n \n```\n\n英語版stackoverflowでも[同様の質問](https://stackoverflow.com/questions/8788002/arrayaccess-\nand-native-php-array-functions)がありました。\n\nphpの配列用関数をArrayAccessで使えないかという質問で、 \n同様のメソッドを自分のオブジェクトに実装するしかないという回答になっています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T03:26:57.130", "id": "416", "last_activity_date": "2014-12-07T03:26:57.130", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "728", "parent_id": "408", "post_type": "answer", "score": 3 }, { "body": "まず、`array_map` を適用したくなるのは `ArrayAccess` ではなく `Traversable` じゃないでしょうか。\n`ArrayAccess`\nには要素を走査したり、添え字の一覧を取得するようなインターフェイスは含まれないので、そういった関数を実装すること自体難しいように思います。\n\n`array` でも `Traversable` でも同様に扱えるライブラリを使うのはどうでしょうか。\n\n * <https://github.com/nikic/iter>\n * <https://github.com/yuya-takeyama/F.php>\n\nいずれも遅延評価を用いているので、対象がメモリにおさまりきれない要素数を持っていても、適用可能です。 \n(巨大なファイルの `SplFileObject` 等)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T10:40:40.810", "id": "1740", "last_activity_date": "2014-12-16T10:40:40.810", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3025", "parent_id": "408", "post_type": "answer", "score": 1 } ]
408
null
416
{ "accepted_answer_id": "412", "answer_count": 1, "body": "Rubyだと、例えば`Method.source_location`を利用することによって、そのメソッドが定義されているファイルパスと行数を確認できるかと思います。\n\nしかし、もう少し踏み込んで、定義場所だけではなく、そのメソッドの実際の挙動、つまりソースコード自体もその場で確認したいという場合、`pry`などで実際に定義されたときのソースを閲覧する方法というものはあったりするのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T22:01:31.797", "favorite_count": 0, "id": "409", "last_activity_date": "2014-12-07T02:06:41.313", "last_edit_date": "2014-12-07T02:06:41.313", "last_editor_user_id": "728", "owner_user_id": "939", "post_type": "question", "score": 8, "tags": [ "ruby", "pry" ], "title": "定義されているメソッドのソースコードをpryなどで確認する方法", "view_count": 1420 }
[ { "body": "pryでshow-sourceを利用すれば可能だと思います。\n\n```\n\n [1] pry(main)> show-source Pry\n \n From: /var/lib/gems/1.9.1/gems/pry-0.10.1/lib/pry/pry_instance.rb @ line 24:\n Class name: Pry\n Number of monkeypatches: 6. Use the `-a` option to display all available monkeypatches\n Number of lines: 641\n \n class Pry\n attr_accessor :binding_stack\n \n :q\n \n [2] pry(main)> show-method pry\n \n From: /var/lib/gems/1.9.1/gems/pry-0.10.1/lib/pry/core_extensions.rb @ line 41:\n Owner: Object\n Visibility: public\n Number of lines: 7\n \n def pry(object=nil, hash={})\n if object.nil? || Hash === object\n Pry.start(self, object || {})\n else\n Pry.start(object, hash)\n end\n end\n \n```\n\nまた、`$`が別名として定義されているので、そちらを使う事もできます\n\n```\n\n [3] pry(main)> require 'rexml/document'\n => true\n [4] pry(main)> $ REXML::Document\n \n From: /usr/lib/ruby/1.9.1/rexml/document.rb @ line 20:\n Class name: REXML::Document\n Number of lines: 226\n \n class Document < Element\n # A convenient default XML declaration. If you want an XML declaration,\n # the easiest way to add one is mydoc << Document::DECLARATION\n # +DEPRECATED+\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T01:47:37.733", "id": "412", "last_activity_date": "2014-12-07T01:47:37.733", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "728", "parent_id": "409", "post_type": "answer", "score": 11 } ]
409
412
412
{ "accepted_answer_id": "413", "answer_count": 3, "body": "iOS8でアプリケーションがバックグラウンドモードに移行したあとも、周期的にタスクを動かしたいと思い、ドキュメントを見ながら以下のようなコードを書いてみました。しかし、思い通り動いてくれません。なにか見落としがあるのでしょうか。\n\n以下、AppDelegate.swiftより抜粋。\n\n```\n\n let backgroundQueue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND,0)\n \n func applicationDidEnterBackground(application: UIApplication) {\n println(\"did enter background\")\n dispatch_async(self.backgroundQueue, myBackgroundTask)\n }\n \n func myBackgroundTask() {\n NSThread.sleepForTimeInterval(0.5)\n println(\"this is back ground task\")\n dispatch_async(self.backgroundQueue, myBackgroundTask)\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-06T23:52:48.910", "favorite_count": 0, "id": "411", "last_activity_date": "2014-12-27T06:38:28.423", "last_edit_date": "2014-12-07T06:22:57.697", "last_editor_user_id": "55", "owner_user_id": "271", "post_type": "question", "score": 6, "tags": [ "ios", "swift" ], "title": "バックグラウンドにあるとき周期的にタスクを動かす方法について", "view_count": 4257 }
[ { "body": "iOS7以上であればBackground Fetchを使うのがいいのではないかと思います。 \n参考:<http://www.gaprot.jp/pickup/ios7/vol1/>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T01:50:12.023", "id": "413", "last_activity_date": "2014-12-07T02:54:14.603", "last_edit_date": "2014-12-07T02:54:14.603", "last_editor_user_id": "525", "owner_user_id": "525", "parent_id": "411", "post_type": "answer", "score": 2 }, { "body": "`beginBackgroundTaskWithExpirationHandler`を使う必要があります。\n\n参考: [Cocoaの日々: [iOS] バックグラウンド実行見本(Task\nCompletion)](http://cocoadays.blogspot.jp/2011/04/ios-task-completion.html)", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T02:40:21.460", "id": "414", "last_activity_date": "2014-12-07T02:40:21.460", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "55", "parent_id": "411", "post_type": "answer", "score": 3 }, { "body": "下記のコードでバックグラウンドで周期的動作をするようになりました。\nただし180秒までが限界です(iOS8の場合)。expirationHandlerは限界に達する6秒ほど前に呼び出されました。またexpirationHandlerで終了処理を行わないと、アプリケーション全体が終了してしまいます。\n\n```\n\n func applicationDidEnterBackground(application: UIApplication) {\n println(\"did enter background\")\n application.beginBackgroundTaskWithName(\"myBgTask\", expirationHandler: myExpiratonHandler)\n dispatch_async(self.backgroundQueue, myBackgroundTask)\n }\n \n func myBackgroundTask() {\n NSThread.sleepForTimeInterval(0.5)\n println(\"this is back ground task\")\n dispatch_async(self.backgroundQueue, myBackgroundTask)\n }\n \n func myExpiratonHandler(){\n let application:UIApplication = UIApplication.sharedApplication()\n println(\"Expiration handler called: \\(self.bgTaskId)\")\n application.endBackgroundTask(self.bgTaskId)\n self.bgTaskId = UIBackgroundTaskInvalid\n }\n }\n \n```", "comment_count": 9, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-09T00:25:13.753", "id": "469", "last_activity_date": "2014-12-27T06:38:28.423", "last_edit_date": "2014-12-27T06:38:28.423", "last_editor_user_id": "271", "owner_user_id": "271", "parent_id": "411", "post_type": "answer", "score": 3 } ]
411
413
414
{ "accepted_answer_id": "417", "answer_count": 1, "body": "フルスクリーン(`Immersive Mode`)でコンテンツを表示し、動的にナビゲーションバーの表示・非表示を行うアプリケーションを制作しています。\n\n`View.SYSTEM_UI_FLAG_VISIBLE`と`View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION`でフルスクリーンのままナビゲーションバーをコンテンツ上に出すことはできたのですが、その際にナビゲーションバーの分のパディングを取得する方法がわかりません。\n\n`fitSystemWindows(Rect insets)`を利用する方法を試したところ、取得できる場合と取得できない場合がありました。\n\n```\n\n @Override\n protected boolean fitSystemWindows(Rect insets) {\n Log.d(getClass().getSimpleName(), \"insets=\"+insets.toShortString());\n return super.fitSystemWindows(insets);\n }\n \n```\n\n * アプリ起動時は取得できる:`insets=[0,75][0,144]`\n * 画面回転・ナビゲーションバー表示切替時は取得できない:`insets=[0,0][0,0]`\n\nこの`fitSystemWindows`というメソッドの挙動がいまいちわかりません。 メソッドの使い方が良くないのでしょうか?\n\nまた、他に有効な手段をご存じの方がいらっしゃいましたら教えて下さい。\n\nサンプルのコードを添付します。\n\n```\n\n public class MainActivity extends ActionBarActivity {\n \n private boolean mOverlayMode = false;\n \n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setOverlayMode(true);\n setContentView(R.layout.activity_main);\n ButterKnife.inject(this);\n }\n \n @OnClick(R.id.button_overlay)\n void switchOverlayMode() {\n setOverlayMode(!mOverlayMode);\n }\n \n /**\n * ステータスバー・ナビゲーションバーの表示・非表示\n * @param mode\n */\n private void setOverlayMode(boolean mode) {\n mOverlayMode = mode;\n \n Window window = getWindow();\n if (mode) {\n window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);\n window.addFlags(\n WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN \n | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);\n if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {\n int systemUiVisibility = \n View.SYSTEM_UI_FLAG_VISIBLE\n | View.SYSTEM_UI_FLAG_LAYOUT_STABLE\n | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;\n if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {\n systemUiVisibility |= \n View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;\n }\n window.getDecorView().setSystemUiVisibility(systemUiVisibility);\n }\n } else {\n window.addFlags(\n WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN \n | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS\n | WindowManager.LayoutParams.FLAG_FULLSCREEN);\n if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {\n int systemUiVisibility =\n View.SYSTEM_UI_FLAG_LAYOUT_STABLE\n | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN\n | View.SYSTEM_UI_FLAG_LOW_PROFILE\n | View.SYSTEM_UI_FLAG_FULLSCREEN;\n if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {\n systemUiVisibility |= \n View.SYSTEM_UI_FLAG_HIDE_NAVIGATION\n | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION\n | View.SYSTEM_UI_FLAG_IMMERSIVE;\n }\n window.getDecorView().setSystemUiVisibility(systemUiVisibility);\n }\n }\n }\n \n```\n\n## ■追記\n\nご回答いただいた方法でうまくいきましたので最終的なコードを載せておきます。\n\n```\n\n /**\n * フルスクリーン表示時のシステム表示分のパディングを取得する.\n */\n @SuppressLint(\"NewApi\")\n public static Rect getSystemWindowPadding(Activity activity) {\n if (activity == null) { \n return new Rect();\n }\n final int statusBarHeight = getStatusBarHeight(activity); // ステータスバーの高さを取得。ここでは割愛\n if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {\n final Display display = activity.getWindowManager().getDefaultDisplay();\n final Point screenSize = new Point(0, 0);\n final Point windowSize = new Point(0, 0);\n display.getRealSize(screenSize);\n display.getSize(windowSize);\n \n final int paddingBottom = screenSize.y-windowSize.y; // ナビゲーションバーが下に表示される場合\n final int paddingRight = screenSize.x-windowSize.x; // ナビゲーションバーが右に表示される場合\n return new Rect(0, statusBarHeight, paddingRight, paddingBottom);\n } else {\n return new Rect(0, statusBarHeight, 0, 0);\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T03:09:30.420", "favorite_count": 0, "id": "415", "last_activity_date": "2019-02-17T01:17:57.963", "last_edit_date": "2014-12-07T14:16:23.200", "last_editor_user_id": "915", "owner_user_id": "915", "post_type": "question", "score": 11, "tags": [ "android" ], "title": "Android KitKatでナビゲーションバーやステータスバーの分のpaddingを取得したい", "view_count": 6360 }
[ { "body": "こちらの手法はいかがでしょうか。\n\n直接ナビゲーションバーを取得する方法ではありませんが、[画面サイズの計算方法](http://techbooster.org/android/hacks/16066/)をまとめたことがあります。 \nたとえばナビゲーションバーの高さは、液晶ディスプレイのサイズ(高さ)から表示可能なディスプレイサイズを引くと計算できます(ナビゲーションバーの高さは、機種ごとに異なる可能性があります)。\n\n[![ナビゲーションバーのサイズ計算](https://i.stack.imgur.com/HPlBc.png)](https://i.stack.imgur.com/HPlBc.png) \n(source: [techbooster.org](http://techbooster.org/wp-\ncontent/uploads/2013/02/screensize2.png))\n\n実際にはDisplayクラスのgetRealSize() - getSize() = ナビゲーションバーの高さとして計算しているので、\n\ngetRealSizeメソッドで液晶ディスプレイの高さを取得して\n\n```\n\n Display display = getWindowManager().getDefaultDisplay();\n Point real = new Point(0, 0);\n if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {\n // Android 4.2以上で対応\n display.getRealSize(real);\n }\n \n```\n\ngetSizeメソッドで表示領域(Androidアプリとして描画可能な領域)\n\n```\n\n Display display = getWindowManager().getDefaultDisplay();\n Point p = new Point();\n display.getSize(p);\n \n```\n\nこれを引き算すると、1280px – 1184px = 96px のようなかたちでナビゲーションバーの高さが取得できます。", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2014-12-07T04:32:56.677", "id": "417", "last_activity_date": "2019-02-17T01:17:57.963", "last_edit_date": "2019-02-17T01:17:57.963", "last_editor_user_id": "19769", "owner_user_id": "395", "parent_id": "415", "post_type": "answer", "score": 9 } ]
415
417
417
{ "accepted_answer_id": null, "answer_count": 6, "body": "Rubyを紹介する必要があって、和文で一通り書いてある文書を探しています。\n\n他のオブジェクト指向言語を知っていると仮定して、短時間でざっと読める簡潔なものが良いのです。入門書は沢山あるのですが、そういうものでなく、ざっと味見が出来るような文書が望ましいのです。\n\n私の知っている範囲だと、英文なら、定番中の定番である、Agile Web Programming with\nRailsのAppendixがまさにそういう文書なのですが、残念ながら一番新しいものの和訳がまだ無いので、紹介しにくい感じです。\n\nもしご存じでしたら教えてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T08:08:30.173", "favorite_count": 0, "id": "423", "last_activity_date": "2014-12-17T07:29:57.710", "last_edit_date": "2014-12-17T04:13:13.690", "last_editor_user_id": "44", "owner_user_id": "44", "post_type": "question", "score": 5, "tags": [ "ruby" ], "title": "他のオブジェクト指向言語に経験のあるプログラマがRubyを覚えるための簡潔な日本語の説明", "view_count": 1111 }
[ { "body": "[Ruby リファレンスマニュアル](http://docs.ruby-lang.org/ja/2.1.0/doc/index.html)\nはどうでしょうか。もともとはリファレンスですが、序章にRubyとは何かということから言語仕様まで載っています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T08:58:44.197", "id": "424", "last_activity_date": "2014-12-07T14:38:25.420", "last_edit_date": "2014-12-07T14:38:25.420", "last_editor_user_id": "724", "owner_user_id": "724", "parent_id": "423", "post_type": "answer", "score": 2 }, { "body": "Ruby on Rails チュートリアルの第4章のこのあたりから眺めてみるのはいかがでしょう?\n\n<http://railstutorial.jp/chapters/rails-flavored-ruby?version=4.0#sec-\nstrings_and_methods>\n\nもちろん、Ruby on\nRailsのチュートリアルの一部なので、Railsの経験やWebアプリケーション開発の知識を前提としている部分も多いですが、オブジェクト指向言語である程度経験がある人であれば、わからないところは飛ばしたり勘で想像しながらでも、短時間でRubyの特徴的なエッセンスに触れることができるように思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-07T14:03:36.007", "id": "432", "last_activity_date": "2014-12-07T14:03:36.007", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "645", "parent_id": "423", "post_type": "answer", "score": 4 }, { "body": "初めての Ruby という書籍がオススメです。\n\n<http://www.amazon.co.jp/dp/4873113679>\n\n書評はこちらが参考になると思います。\n\n<http://blog.livedoor.jp/dankogai/archives/51077051.html>", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-10T05:42:32.270", "id": "493", "last_activity_date": "2014-12-10T05:42:32.270", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "982", "parent_id": "423", "post_type": "answer", "score": 4 }, { "body": "さっくりと味見したいという要望ですと、[やわらかRuby](https://gist.github.com/udzura/7548163)\nという文章があります。\n\nあえてRubyの特徴らしいところにスポットライトを当てているため、おそらく「他のオブジェクト指向言語に経験のあるプログラマ」なら、Rubyらしいところがわかるような作りになっているかと思われます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-16T22:08:16.873", "id": "1820", "last_activity_date": "2014-12-16T22:08:16.873", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "939", "parent_id": "423", "post_type": "answer", "score": 3 }, { "body": "Railsですが、これどうでしょう。Railsのチュートリアルをかなり簡潔にした感じなので紹介レベルだといいかもです。ハンズオンでツイッターみたいなアプリだとすぐ作れるよ!的な内容です。 \n[小学生でもわかるRuby on Rails入門](http://openbook4.me/projects/92)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-17T07:01:57.157", "id": "1885", "last_activity_date": "2014-12-17T07:01:57.157", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2329", "parent_id": "423", "post_type": "answer", "score": 2 }, { "body": "他のオブジェクト指向に親しんでいて、ざっと味見ということですが「[7つの言語\n7つの世界](http://shop.ohmsha.co.jp/shop/shopdetail.html?brandcode=000000001902&search=978-4-274-06857-7&sort=)」(オーム社)はいかがでしょうか。1つの言語に1週間(実際は3日分の内容)かけて取り組んでみようという本です。(元はpragprogの本)\n\n`Ruby`以外の言語も含まれていますが、インタプリタでのHello\nWorldから始まって、最終的にメタプログラミングの基礎の基礎あたりまで触れることが出来、`Ruby`のパワフルな側面を知るのにも良い内容かと思います。\n\n* * *\n\nまた、`Appendix`についてですが古い版(Second\nEditionでは確認できました)にはきちんとしたチュートリアルがあるものの、最新版ではRubyの説明に第4章が割かれているなど本の構成が版によって異なります。ですので、いつの版の`Appendix`かも明記されたほうが良い気がします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-17T07:20:13.310", "id": "1888", "last_activity_date": "2014-12-17T07:29:57.710", "last_edit_date": "2014-12-17T07:29:57.710", "last_editor_user_id": "3313", "owner_user_id": "3313", "parent_id": "423", "post_type": "answer", "score": 2 } ]
423
null
432
{ "accepted_answer_id": "453", "answer_count": 2, "body": "ロードバランサで複数のWEBサーバに処理を分散していて、WEBサーバは一つのDBサーバを参照しているrailsアプリがあります。\n\n運用している中で、テーブルのカラムを削除する必要がある場合、マイグレーションファイルでremove_columnをすると思うのですが、\ncapistranoで全てのWEBサーバにデプロイする中で、デプロイ対象のWEBサーバが多いとWEBサーバでは削除したカラムを参照しますが、\nDB側はrake db:migrateが実行されたためにカラムが削除されているという状況が発生するような気がしています。\n\nこのような事象が発生しないように複数サーバへのデプロイを行うにはどうすればよいでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T03:28:47.973", "favorite_count": 0, "id": "435", "last_activity_date": "2014-12-09T15:00:12.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "189", "post_type": "question", "score": 10, "tags": [ "ruby", "ruby-on-rails", "デプロイ" ], "title": "DBスキーマの変更で発生するソースコードとDBスキーマの不整合をデプロイ時にどうやって解決するか?", "view_count": 830 }
[ { "body": "すぐには消さない、という戦略が考えられます。\n\nリリースを2回に分け、 \n1回めのリリースで、すべてのアプリケーションサーバを、そのカラムにアクセスしない版に更新します。 \n次のリリースで、要らなくなったカラムをDBから実際に消す、という寸法です。\n\nカラム名の変更についても、基本的には同じ考え方が適用できるかと思います。\n\n# いっぺんにやってひどい目にあったことが何度か (´・ω・`)", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T08:14:16.953", "id": "453", "last_activity_date": "2014-12-08T08:19:42.723", "last_edit_date": "2014-12-08T08:19:42.723", "last_editor_user_id": "208", "owner_user_id": "208", "parent_id": "435", "post_type": "answer", "score": 9 }, { "body": "単純なカラム削除や追加であれば、KoRoNさんの回答の通り、アプリ側とDB側のリリースを分けたり、自動マイグレーションであれば2回に分けて段階的にリリースするのがセオリーですね。\n\n追加情報として、カラム名の変更や、より複雑なスキーマ変更に関しては、ちょうどそういったDBの変更技法を扱った「データベース・リファクタリング」という書籍があり、一冊丸ごと様々な手法が紹介されています。\n\n<http://amzn.to/131cVYy> (AA)\n\n以前にこの本の読書会が何回か開かれたようで、日本語の情報もあります。\n\n * [読書会の参加記録と講演メモ](http://makopi23.blog.fc2.com/blog-entry-11.html)\n * [トリガー (上記の本で紹介されている手法) を使わずにカラム名を変更する例](http://dqn.sakusakutto.jp/2012/03/database_refactoring.html)\n * [読書会で使われたスライド](http://www.slideshare.net/daisuke_m/20120830-db)", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-09T06:32:52.313", "id": "479", "last_activity_date": "2014-12-09T15:00:12.367", "last_edit_date": "2014-12-09T15:00:12.367", "last_editor_user_id": "30", "owner_user_id": "972", "parent_id": "435", "post_type": "answer", "score": 5 } ]
435
453
453
{ "accepted_answer_id": "468", "answer_count": 2, "body": "VS2013 .NetFramework4.0環境で、\nHtmlAgilityPackを使用して煩雑なHTMLをパーズし、整形したHTMLに変換するプログラムを作成しています。\n\nしかし、HtmlAgilityPackにはHTMLテキストをインデントする機能はないようでした。\nXMLを自動インデントする方法はあるのですが、変換処理が必要になってしまう・preタグの中にインデント文字が入ってしまうなど少し面倒です。\nC#でHTMLテキストをインデントする簡単な方法はありますでしょうか。HTML5のタグに対応しているものだとなお良いです。\n\nよろしくお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T04:00:11.330", "favorite_count": 0, "id": "436", "last_activity_date": "2014-12-09T11:34:43.947", "last_edit_date": "2014-12-09T11:34:43.947", "last_editor_user_id": "438", "owner_user_id": "438", "post_type": "question", "score": 4, "tags": [ ".net", "c#", "html5", "html-agility-pack" ], "title": "C#でHTMLテキストをインデントする方法はありませんか?", "view_count": 1443 }
[ { "body": "Html Agility Packでは出来ないらしいので、HtmlTidyPackを使うらしいです。 \n<https://stackoverflow.com/questions/2593147/html-agility-pack-make-code-look-\nneat>\n\n```\n\n using System;\n using System.IO;\n using System.Net;\n using Mark.Tidy;\n \n namespace CleanupHtml{\n /// <summary>\n /// http://markbeaton.com/SoftwareInfo.aspx?ID=81a0ecd0-c41c-48da-8a39-f10c8aa3f931\n /// </summary>\n internal class Program\n {\n private static void Main(string[] args)\n {\n string html =\n new WebClient().DownloadString(\n \"https://stackoverflow.com/questions/2593147/html-agility-pack-make-code-look-neat/2610903#2610903\");\n \n using (Document doc = new Document(html))\n {\n doc.ShowWarnings = false;\n doc.Quiet = true;\n doc.OutputXhtml = true;\n doc.OutputXml = true;\n doc.IndentBlockElements = AutoBool.Yes;\n doc.IndentAttributes = false;\n doc.IndentCdata = true;\n doc.AddVerticalSpace = false;\n doc.WrapAt = 120;\n \n doc.CleanAndRepair();\n \n string output = doc.Save();\n Console.WriteLine(output);\n File.WriteAllText(\"output.htm\", output);\n }\n }\n }\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T05:35:59.923", "id": "441", "last_activity_date": "2014-12-08T05:35:59.923", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "525", "parent_id": "436", "post_type": "answer", "score": 2 }, { "body": "# HtmlTidyPackについて\n\n[別の回答に含まれる英語版SOの回答](https://stackoverflow.com/a/2610903/718426)に書かれていたHtmlTidyPackのURLを開くと、\n\n> This site is no longer being maintained. If you've arrived here via wherever\n> and you're looking for some software, maybe these links will help: \n> (このサイトはメンテナンスされていません。ソフトウェアなどをお探しでしたら、以下のリンクが参考になると思います(意訳))\n\nとあり、当該githubのURLは[TidyManaged](https://github.com/markbeaton/TidyManaged)ですが5年以上メンテナンスされていないようです。 \n(そもそも本家のtidyが2008年から更新されていないですので仕方ないですね)\n\n# NuGet Package\n\nそこで、[HtmlTidy](http://tidy.sourceforge.net/)のラッパである[HTML Tidy Library\nProject](https://www.nuget.org/packages/libtidy/)または[TidyNetPortable](https://www.nuget.org/packages/TidyNetPortable/)を以下のように、NuGet経由でインストールするのがいいかなとおもいテストしてみました。\n\n```\n\n Install-Package TidyNetPortable \n \n```\n\n結果、VS2013環境では両方使えませんでした... \nTidyNetPortableはそもそも実装が足りないのか、実装しても動かず、ドキュメントもありません。また、HTML Tidy Library\nProjectは.Net Framework 4.0環境にはNuGetでインストールできませんでした。\n\n# tidy wrapperを探してビルド\n\nNuGetで提供されているパッケージがつかえないので、比較的新しめのプロジェクトを探してdllをビルドして使うしかないようです。さがしてみると[EfTidyNet:\n.NET Wrapper for Tidy\nlibrary](http://www.codeproject.com/Articles/24105/EfTidyNet-NET-Wrapper-for-\nTidy-library)というのを発見しました。\n\n * Download EfTidy 1.0.2.0.source\n\nとあるのをダウンロードし、Buildしてdllを生成します。このときx64環境であれば、構成がデフォルトでWin32になっていますので、環境に合わせて修正してbuildしてください。\n\ndllを生成したら、ソリューションエクスプローラーのReferences(参照)上で右クリックして、Add\nReferences(参照の追加)をしてください。\n\n![参照の追加](https://i.stack.imgur.com/6yEHA.png)\n\n次のようなダイアログが表示されますので、Browse(日本語版だと参照?)をクリックして、前の手順でビルドしたdllを選択します。 \n![参照の追加ダイアログ](https://i.stack.imgur.com/MxQbh.png)\n\nそして、次のようなプログラムを書きます。 \n(ここでは、html5にtidy処理しています)\n\n```\n\n ...\n using EfTidyNet;\n using System.Text.RegularExpressions;\n \n ...\n String text = File.ReadAllText(\"test.html\"); \n \n TidyNet objTidyNet = new TidyNet();\n objTidyNet.Option.OutputType(EfTidyNet.EfTidyOpt.EOutputType.HtmlOut);\n objTidyNet.Option.NewBlockLevelTags(\"article aside audio details dialog figcaption figure footer header hgroup menutidy nav section source summary track video\");\n objTidyNet.Option.NewInlineTags(\"command embed keygen source track wbr\");\n objTidyNet.Option.NewEmptyTags(\"canvas command data datalist embed keygen mark meter output progress time wbr\");\n objTidyNet.Option.Indent(EfTidyNet.EfTidyOpt.EIndentScheme.AUTOINDENT);\n objTidyNet.Option.IndentSpace(2);\n objTidyNet.Option.WrapLen(0);\n objTidyNet.Option.DropEmptyParas(true);\n objTidyNet.Option.TidyMark(false);\n objTidyNet.Option.Clean(true);\n \n String result = null;\n objTidyNet.TidyMemToMem(text, ref result);\n result = Regex.Replace(result, @\"(\\r\\n){2}\", \"\\r\\n\"); //tidyのオプションでどうしても消せず...\n this.textBox1.Text = result;\n \n```\n\ntest.htmlは次のような内容です。\n\n```\n\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge\">\n <title>xxxxxxxxxx</title>\n <!--[if IE]>\n <script src=\"http://html5shiv.googlecode.com/svn/trunk/html5.js\"></script>\n <![endif]-->\n <style>\n article, aside, dialog, figure, footer, header,\n hgroup, menu, nav, section {\n display: block;\n }\n </style>\n </head>\n <body>\n <article><h1>xxxxxxxxxx</h1><p>xxxx</p><aside><h3>xxx</h3><ul class=\"referenceLinks\"><li><a href=\"http://xx.html\" target=\"_blank\">http://xxx.html</a></li><li><a href=\"http://xxxxx.html\" target=\"_blank\">http://xx.html</a></li></ul></aside><section><h2>yyyyyy</h2><p>Pyyyyy</p></section><section><h2>zzzzzzz</h2><p>Pzzzzzzz<strong>ssss</strong><strong>aaaaa</strong><strong>ssss</strong>zzzzzz</p><figure><figcaption>zzzzzz</figcaption><img src=\"aaa.png\" alt=\"aaaaa\"></figure><p>bbbbb</p></section></article>\n </body>\n </html>\n \n```\n\n上記プログラムに食わせると、以下のような出力を得られます。\n\n```\n\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge\">\n <title>xxxxxxxxxx</title><!--[if IE]>\n <script src=\"http://html5shiv.googlecode.com/svn/trunk/html5.js\"></script>\n <![endif]-->\n <style type=\"text/css\">\n article, aside, dialog, figure, footer, header,\n hgroup, menu, nav, section {\n display: block;\n }\n </style>\n </head>\n <body>\n <article>\n <h1>xxxxxxxxxx</h1>\n <p>xxxx</p>\n <aside>\n <h3>xxx</h3>\n <ul class=\"referenceLinks\">\n <li><a href=\"http://xx.html\" target=\"_blank\">http://xxx.html</a></li>\n <li><a href=\"http://xxxxx.html\" target=\"_blank\">http://xx.html</a></li>\n </ul>\n </aside>\n <section>\n <h2>yyyyyy</h2>\n <p>Pyyyyy</p>\n </section>\n <section>\n <h2>zzzzzzz</h2>\n <p>Pzzzzzzz<strong>ssss</strong><strong>aaaaa</strong><strong>ssss</strong>zzzzzz</p>\n <figure>\n <figcaption>zzzzzz</figcaption><img src=\"aaa.png\" alt=\"aaaaa\">\n </figure>\n <p>bbbbb</p>\n </section>\n </article>\n </body>\n </html>\n \n```\n\nというわけで無事beautifyされました。 \ntidyのオプションの詳細については、[HTML Tidy Configuration\nOptions](http://tidy.sourceforge.net/docs/quickref.html)を確認して下さい。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T19:24:21.720", "id": "468", "last_activity_date": "2014-12-08T20:24:49.000", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "351", "parent_id": "436", "post_type": "answer", "score": 5 } ]
436
468
468
{ "accepted_answer_id": "443", "answer_count": 3, "body": "[本家SOより](https://stackoverflow.com/questions/2928584/how-to-grep-search-\ncommitted-code-in-the-git-history)\n\n`Git`で`git log\n-p`を使うと、コミットログと一緒に、コードの差分が表示されると思うのですが、このコードのコミット履歴を使って、検索するにはどうしたらいいですか?\n\n```\n\n git log -p | grep <pattern>\n \n```\n\nをやってみましたが、コミットのハッシュかもすぐに分からず、あまり使えません。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T04:38:27.463", "favorite_count": 0, "id": "438", "last_activity_date": "2014-12-08T07:07:44.750", "last_edit_date": "2017-05-23T12:38:56.467", "last_editor_user_id": "-1", "owner_user_id": "41", "post_type": "question", "score": 6, "tags": [ "git", "grep" ], "title": "Gitでソースコードのコミット履歴を検索する方法", "view_count": 7964 }
[ { "body": "```\n\n git log --grep keyword\n \n```\n\nでコミットログに\"keyword\"を含むものを抽出できます。\n\nコミットメッセージにRedmineなどのチケット番号を入れるルールで開発している場合は、\n\n```\n\n git log --grep #1111\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T05:18:29.813", "id": "439", "last_activity_date": "2014-12-08T05:18:29.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "525", "parent_id": "438", "post_type": "answer", "score": 1 }, { "body": "消してしまった履歴をコミットしたかどうかにもよりますが…\n\nファイルシステム上で rm しただけならば、git はワークツリーでの作業としてそれを記録するため、unstaged な履歴があることを git\nstatus で検知できます。\n\ngit rm した場合は、git は staged な履歴としてファイルの消去を扱うので、これもコミットしなければstaged な履歴があることを git\nstatus で検知できます。\n\nもしファイルの消去をコミットしてしまった場合はいくつかパターンがありますが、最新のコミットでなおかつ push していない場合は、git reset\nHEAD^ で最新のコミットを取り消すことができます。これで、間違えて消したものを戻すことができます。\n\nもしファイルのパスがはっきりしているのであれば、git log --stat\nで、コミットごとにどのファイルにどの程度の差分ができたかを閲覧できるので、この中から探せますね。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T05:20:01.320", "id": "440", "last_activity_date": "2014-12-08T05:20:01.320", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "484", "parent_id": "438", "post_type": "answer", "score": 0 }, { "body": "質問同様 [本家SOについた回答](https://stackoverflow.com/questions/2928584/how-to-grep-\nsearch-committed-code-in-the-git-\nhistory#)よりコミットされた物(例えば実際のソースの行や、コミットメッセージなど)を検索する方法を説明します。\n\n## すべてのコミットテキストを正規表現でgrepする検索方法\n\n```\n\n git grep <regexp> $(git rev-list --all)\n \n```\n\n(追記: もし \"`Argument list too long`\"(引数リストが長すぎます)というエラーが発生する場合は \n`git rev-list --all | xargs git grep expression` を使えば上手いくと思います)\n\n \n\n## コードを検索する上でその他の便利な方法\n\nワーキングツリーを正規表現 `<regexp>` でテキストマッチ検索:\n\n```\n\n git grep <regexp>\n \n```\n\nワーキングツリーを正規表現 `<regexp1>` または `<regexp2>` がマッチする行のテキストマッチ検索:\n\n```\n\n git grep -e <regexp1> [--or] -e <regexp2>\n \n```\n\nワーキングツリーを正規表現 `<regexp1>` も `<regexp2>` もマッチする行のテキストマッチ検索:\n\n```\n\n git grep -e <regexp1> --and -e <regexp2>\n \n```\n\nワーキングツリーの中で正規表現`<regexp1>`にテキストマッチする行と正規表現`<regexp2>`にテキストマッチする行を持つファイルを検索し、ファイルパスのみ報告:\n\n```\n\n git grep -l --all-match -e <regexp1> -e <regexp2>\n \n```\n\n全てのリビジョンを正規表現`<regexp>`でテキストマッチ検索:\n\n```\n\n git grep <regexp> $(git rev-list --all)\n \n```\n\n`<rev1>` から `<rev2>` の間の全てのリビジョンを正規表現`<regexp>`でテキストマッチ検索:\n\n```\n\n git grep <regexp> $(git rev-list <rev1>..<rev2>)\n \n```\n\n* * *\n\n[jeet](https://stackoverflow.com/users/268330/jeet)による[stackoverflow.comの回答](https://stackoverflow.com/questions/2928584/how-\nto-grep-search-committed-code-in-the-git-history#)より。 \nxargs を用いる更新部分は[Casebash](https://stackoverflow.com/users/268330/jeet)による補足。\n\nファイルパスのみ報告するのは `git grep -l --all-match -e <regexp1> -e <regexp2>`\nの事だと思われるのでそれについてはこちらで修正しています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T05:50:22.957", "id": "443", "last_activity_date": "2014-12-08T07:07:44.750", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "728", "parent_id": "438", "post_type": "answer", "score": 2 } ]
438
443
443
{ "accepted_answer_id": "451", "answer_count": 1, "body": "Tungsten\nReplicatorで、OracleデータベースからMySQLデータベースにデータを流し込もうとしています。各種初期化は終わり、[ドキュメントにあるParallel\nextractorを使う方法](http://docs.continuent.com/tungsten-replicator-3.0/deployment-\noracle-provision.html)で既にOracle側にあるデータをMySQLに入れようとしているところです。\n\nところが、エラーで途中で止まってしまいます。幸いオープンソースなのでログを仕込んでみたところ、CDCで変更を記録するためのテーブルのデータも抽出しようとしているらしいことがわかりました。\n\n`java.sql.Types.VARBINARY` という型 (-3) の `SOURCE_COLMAP$` という名前のカラムを処理しようとしている:\n\n> 2014-12-08 14:59:37,077 [cookbook - prov-q-to-thl-0] WARN\n> thl.serializer.ProtobufSerializer Unimplemented type -3 for SOURCE_COLMAP$\n\nテーブルは `MYSCHEMA.CT_USER`:\n\n> 2014-12-08 14:59:37,428 [cookbook - prov-q-to-thl-0] ERROR\n> thl.serializer.ProtobufSerializer Failure while storing MYSCHEMA_PUB.CT_USER\n\nどうすればCDC用テーブルは無視するように設定できるでしょうか。\n\nバージョン: Tungsten Replicator 3.0.0-524", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T06:37:15.490", "favorite_count": 0, "id": "446", "last_activity_date": "2014-12-08T08:07:44.853", "last_edit_date": "2014-12-08T08:07:44.853", "last_editor_user_id": "30", "owner_user_id": "30", "post_type": "question", "score": 2, "tags": [ "tungsten-replicator", "oracle-cdc" ], "title": "Parallel extractorがCDC用のテーブルも抽出しようとしてしまう", "view_count": 62 }
[ { "body": "その後ソースコードを眺めていたら、抽出用の設定ファイルを指定できるようになっていることに気付きました。\n\n```\n\n スキーマ名,テーブル名,一度に抽出する行数\n \n```\n\nという形式でchunks.csvなどに保存してレプリケーターから読める場所に置き、\n\n```\n\n ./tools/tpm update service_name \\\n --property=replicator.extractor.parallel-extractor.ChunkDefinitionFile=/path/to/chunks.csv\n \n```\n\nで設定を更新すれば使ってくれるようになります。CDC用のテーブルは *_PUB\nという形式のスキーマに保存するように初期化スクリプトがセットアップしているので、抽出したいスキーマのみを含めるようにすればCDC用テーブルを除外できます。\n\nテーブル名以降は省略可です。\n\n設定を読み込んでいるあたりの[ソースコード](https://code.google.com/p/tungsten-\nreplicator/source/browse/branches/3.0.0-maintenance/replicator/src/java/com/continuent/tungsten/replicator/extractor/parallel/ChunksGeneratorThread.java#194):\n\n```\n\n logger.info(\"Using definition from file \" + chunkDefFile);\n chunkDefinition = new ChunkDefinitions(chunkDefFile);\n \n```\n\n設定すべきプロパティの見つけ方:\n\n```\n\n # ChunkDefinitionsというのが設定ファイル用クラスなので、chunkでレプリケーターの設定ファイルをgrepしてみる\n $ grep chunk conf/static-service_name.properties\n # Path to the chunk definition file. If the file is not provided or is not\n replicator.extractor.parallel-extractor.ChunkDefinitionFile=/path/to/chunks.csv\n # How many rows should be handle in one chunk\n replicator.extractor.parallel-extractor.chunk_size=2000\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T07:54:00.757", "id": "451", "last_activity_date": "2014-12-08T07:54:00.757", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "30", "parent_id": "446", "post_type": "answer", "score": 0 } ]
446
451
451
{ "accepted_answer_id": "450", "answer_count": 1, "body": "連絡先アプリのように定期的にサーバーのデータをチェックして端末のデータを更新する機能を作りたいです。 \n場合によって通知領域にメッセージを出したりします。\n\nサーバーからのプッシュ型ではなくクライアントからのプル型で実装したいです。皆さんどのように実装されているのでしょう?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T07:12:44.910", "favorite_count": 0, "id": "449", "last_activity_date": "2014-12-08T07:43:22.663", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "450", "post_type": "question", "score": 6, "tags": [ "android" ], "title": "Androidで定期的にサーバーのデータをチェックする方法", "view_count": 1404 }
[ { "body": "大きく分けて 2 つの方法があります。\n\n1 つは SyncAdapter を使う方法。もう 1 つは AlarmManager を使う方法です。\n\nSyncAdapter は、ContentProvider や AccountManager\nと密な連携を取るもので、定期的にデータベースのデータを同期するための仕組みです。\n\nAlarmManager は、特定のタイミングや間隔で Intent を飛ばすための仕組みで、その Intent\nを受け取った時に、データの更新をする処理を走らせることで、SyncAdapter と同じ機能を実現できます。\n\n以下のページを参考にしてみてください。\n\n参考:<http://developer.android.com/training/sync-adapters/creating-sync-\nadapter.html>, <http://developer.android.com/training/sync-adapters/running-\nsync-adapter.html>, <https://github.com/mixi-\ninc/AndroidTraining/wiki/2.15.-ContentProvider-%E3%81%AE%E7%99%BA%E5%B1%95>,\n<http://qiita.com/KeithYokoma/items/17d9bee6612e16393353>,\n<http://developer.android.com/reference/android/app/AlarmManager.html>", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2014-12-08T07:43:22.663", "id": "450", "last_activity_date": "2014-12-08T07:43:22.663", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "484", "parent_id": "449", "post_type": "answer", "score": 10 } ]
449
450
450