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": 1, "body": "失礼します。 \n本日Xcodeの7.0をインストールし、利用しています。\n\n実機テストが無料で可能とのことでApple IDを登録して実際にHelloWorldをBuildしてみました。 \n(実機にはプロファイルから自分のApple IDをあらかじめ信頼させてあります。)\n\nするとXcodeでは\n\n```\n\n Could not launch “Hello World”\n process launch failed: Security\n \n```\n\nと表示されました。 \niPhoneのプロファイルの画面では、\n\n```\n\n HelloWorld   未検証\n \n```\n\nとなっており、何度「Appを検証」ボタンを押しても検証されません。\n\nこの前にXcode7.1のbeta3で検証したのですが、その際はうまくいきました。なぜXcode7.0ではこのようなエラーが出るのでしょうか?\n\n同じようなエラーが出る方、いらっしゃいますでしょうか。 \nまた、解決方法をご存知の方いらっしゃいましたら、ご教授お願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-15T15:09:00.020", "favorite_count": 0, "id": "17692", "last_activity_date": "2015-10-15T21:51:03.117", "last_edit_date": "2015-10-15T19:26:34.860", "last_editor_user_id": "7290", "owner_user_id": "12799", "post_type": "question", "score": 1, "tags": [ "swift", "xcode", "xcode7" ], "title": "実機テストで「未検証」が「検証済み」にならない問題", "view_count": 9822 }
[ { "body": "iPhone/iPadの実機をMacに接続したとき、「このコンピュータを信頼するか」というアラートが出たと思います。このとき「信頼する」を選択したにもかかわらず、信頼になっていないようです。つまりXcode\n7.0.xにバグがあるんじゃないかという印象があります。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/j8ilL.png)](https://i.stack.imgur.com/j8ilL.png)\n\nこのダイアログが出たら、実機の「設定」>「一般」を開きます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/Mv5Lq.png)](https://i.stack.imgur.com/Mv5Lq.png)\n\n「プロファイル」をタップして、「デベロッパAPP」を「信頼する」にします。 \nこの項目「プロファイル」は、実機を、Xcodeが起動しているMacに接続しないと現れません。 \n私の場合は、これでプロジェクトを実機に転送することができました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-15T21:51:03.117", "id": "17698", "last_activity_date": "2015-10-15T21:51:03.117", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7362", "parent_id": "17692", "post_type": "answer", "score": 1 } ]
17692
null
17698
{ "accepted_answer_id": null, "answer_count": 1, "body": "サーバサイドから送られてきた16進数の画像データをSwiftで表示する機能を実装しようとしています。 \nしかし、現状その16進数表記の画像データをどうやって処理し、画像として表示すればよいのかがわかっていません。 \n今はサーバサイドからの画像データをJSONで受け取るところまでできています。\n\n```\n\n func downloadBtn(sender :UIButton){\n \n //create url request\n //set URL\n let urlstr = \"http://192.168.33.10/test_app/images/recieveImage\"\n let request = NSMutableURLRequest(URL: NSURL(string: urlstr)!)\n \n //set method\n request.HTTPMethod = \"GET\"\n \n //タスクの生成\n let task = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler:{ data, response, error in\n //succeed post\n if(error == nil){\n let result = NSString(data:data!, encoding: NSUTF8StringEncoding)\n //結果を出力\n \n        //サーバからのデータをJSONで受け取る\n let json = JSON(data: data!)\n let resp = json[\"resp\"].string\n print(resp)\n         /*\n         出力結果が16進数データになっていることを確認\n         */\n \n //(1)スペースを削除\n let deleteTarget = NSCharacterSet.whitespaceCharacterSet\n let img_data = resp!.stringByTrimmingCharactersInSet(deleteTarget())\n //print(\"resp = \\(img_data)\")\n \n }else{\n print(error) \n }\n })\n task.resume()\n }\n \n```\n\n(1)では取得したデータが先頭と末尾にスペースがあるので取り除いています。\n\n`img_data`はString型になっていると思うのですが、それをどう処理して画像を表示すればよいのかがわかりません。\n\nなにかありましたら、随時補足いたします。 \nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-15T17:58:10.700", "favorite_count": 0, "id": "17695", "last_activity_date": "2015-10-16T13:36:41.413", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12470", "post_type": "question", "score": -1, "tags": [ "swift", "php", "json" ], "title": "Swiftでの画像処理について", "view_count": 356 }
[ { "body": "64進数での例ですが参考にできると思います。 \n<http://blog.sarabande.jp/post/92097422168>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T13:36:41.413", "id": "17732", "last_activity_date": "2015-10-16T13:36:41.413", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12233", "parent_id": "17695", "post_type": "answer", "score": 1 } ]
17695
null
17732
{ "accepted_answer_id": "17725", "answer_count": 1, "body": "[カスタムキーボードエクステンションからファイルが読み込めない](https://ja.stackoverflow.com/questions/14476/%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%E3%82%AD%E3%83%BC%E3%83%9C%E3%83%BC%E3%83%89%E3%82%A8%E3%82%AF%E3%82%B9%E3%83%86%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%8B%E3%82%89%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%8C%E8%AA%AD%E3%81%BF%E8%BE%BC%E3%82%81%E3%81%AA%E3%81%84) \n上記を参考にしていますが・・・\n\n```\n\n print(realmPath)\n \n```\n\nでは\n\n```\n\n /private/var/mobile/Containers/Shared/AppGroup/****-****--****/test.realm \n \n```\n\nとなりますが・・・\n\n```\n\n let realm = try! Realm(path: realmPath)\n \n```\n\nのところで、\n\n```\n\n 2015-10-16 08:58:46.720 Test-Keyboard[8880:557651] ***storageTaskManagerExistsWithIdentifier:withIdentifier failed: Error Domain=NSCocoaErrorDomain Code=4099 \"The connection to service named com.apple.nsurlstorage-cache was invalidated.\" UserInfo={NSDebugDescription=The connection to service named com.apple.nsurlstorage-cache was invalidated.}; {\n NSDebugDescription = \"The connection to service named com.apple.nsurlstorage-cache was invalidated.\";}\n fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm Code=1 \"open() failed: Operation not permitted\" UserInfo={NSLocalizedDescription=open() failed: Operation not permitted, Error Code=1}: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.59/src/swift/stdlib/public/core/ErrorType.swift, line 50\n (lldb) \n \n```\n\nというエラーが出てしまいます。\n\nデータベースファイルを共有エリアにコピーとかが必要なのか? \nでも、それもgoogleで探していますが、方法がわかりません。\n\nソースは下記の通りです。\n\nどうか改善策を、教えていただけないでしょうか? \nよろしくお願いいたします。\n\n```\n\n import UIKit\n import RealmSwift\n import Foundation\n \n class dic: Object {\n dynamic var ID = 0\n dynamic var yomi = \"\"\n dynamic var emoji = \"\"\n dynamic var date = NSDate(timeIntervalSince1970: 1)\n \n override static func primaryKey() -> String? {\n return \"ID\"\n }\n }\n \n \n \n class KeyboardViewController: UIInputViewController {\n \n @IBOutlet var nextKeyboardButton: UIButton!\n var button11: UIButton!\n var button12: UIButton!\n var fFastBoot = true\n var fPri = CGFloat(20)\n var ifontSize = 18.0\n var RPath = \"\"\n \n // Portrait表示におけるキーボードの高さ\n private var portraitHeight: CGFloat = 190.0\n private var portraitWidth: CGFloat!\n \n // Landscape表示におけるキーボードの高さ\n private var landscapeHeight: CGFloat = 100.0\n private var landscapeWidth: CGFloat!\n \n override func updateViewConstraints() {\n super.updateViewConstraints()\n \n }\n \n \n var realmPath: String {\n let containerURL = NSFileManager().containerURLForSecurityApplicationGroupIdentifier(\"group.AppGrouptestKeybora\")\n return containerURL!.URLByAppendingPathComponent(\"test.realm\").path!\n }\n \n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // Perform custom UI setup here\n \n ・・・\n \n let inputText = \"か\"\n print(\"test1\") \n print(realmPath)\n realm = try! Realm(path: realmPath) //ここでエラー\n print(\"test1.5\")\n let results = realm.objects(dic)\n .filter(\"yomi BEGINSWITH %@\", inputText)\n .sorted(\"date\", ascending: false)\n print(\"test2\")\n \n \n for result in results {\n print(result)\n }\n print(\"test3\")\n }\n ・・・\n \n```\n\nこんなのも、関係あるでしょうか?\n\n```\n\n func createPath() -> String {\n \n let docsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory , NSSearchPathDomainMask.UserDomainMask, true)[0]\n let databaseStr = \"test.realm\"\n let dbPath = docsPath.stringByAppendingString(databaseStr)\n \n // BEGING MODIFICATION\n let fileMan = NSFileManager.defaultManager()\n if !(fileMan.fileExistsAtPath(dbPath)) { // The database does not already exist in Documents directory\n if let source = NSBundle.mainBundle().resourcePath?.stringByAppendingString(databaseStr) {\n if !(fileMan.fileExistsAtPath(source)) {\n print(\"RealmDB - file \\(databaseStr) not found in bundle\")\n } else {\n do {\n try fileMan.copyItemAtPath(source, toPath: dbPath)\n } catch let error as NSError {\n print(\"RealmDB - failed to copy writable version of DB!\")\n print(\"Error - \\(error.localizedDescription)\")\n }\n }\n }\n }\n // END MODIFICATION\n \n return dbPath\n }\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T00:06:46.663", "favorite_count": 0, "id": "17703", "last_activity_date": "2015-10-16T16:04:56.953", "last_edit_date": "2017-04-13T12:52:38.920", "last_editor_user_id": "-1", "owner_user_id": "10845", "post_type": "question", "score": 0, "tags": [ "swift", "ios8", "realm" ], "title": "iOSでRealmデータベースを開こうとするとエラーになる(AppGroupの使用)", "view_count": 1298 }
[ { "body": "下記にありますように、共有コンテナでファイルを読み書きするには、フルアクセスの許可が必要です。\n\n<https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW3>\n\nまず、キーボードエクステンションのInfo.plistの`NSExtensionAttributes`の`RequestOpenAccess`を`YES`にします。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/y0jVy.png)](https://i.stack.imgur.com/y0jVy.png)\n\nそうすると、設定.appの自分のキーボードのところが先に進めるようになっているはずなので、「フルアクセスを許可」をオンにします。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/Eur7a.png)](https://i.stack.imgur.com/Eur7a.png)", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T10:59:55.277", "id": "17725", "last_activity_date": "2015-10-16T10:59:55.277", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "17703", "post_type": "answer", "score": 1 } ]
17703
17725
17725
{ "accepted_answer_id": "17705", "answer_count": 1, "body": "API リファレンスには、指定されたSubscriberが存在しないときにHTTP Status Code が 404 と記載されているのですが、HTTP\nStatus Code で 400 が返ってきます。 \nエラーコードは、400が正しいのでしょうか?それとも404が正しいのでしょうか?\n\nResponse Body:\n\n```\n\n {\n \"code\": \"SEM0001\",\n \"message\": \"No such resource found\"\n }\n \n```\n\n以下のAPIも同様でした\n\n * /subscribers/{imsi}/update_speed_class\n * /subscribers/{imsi}/activate\n * /subscribers/{imsi}/deactivate", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T01:01:56.587", "favorite_count": 0, "id": "17704", "last_activity_date": "2015-10-16T02:28:52.017", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7266", "post_type": "question", "score": 0, "tags": [ "soracom" ], "title": "/subscribers/{imsi} のリターンコードについて", "view_count": 90 }
[ { "body": "ご指摘ありがとうございます。\n\nご報告いただいた API 全てにつきまして、Subscriber が存在しない場合には API Reference にありますとおりステータスコード 404\nを返却するのが正しい動作です。\n\n修正させていただきます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T02:28:52.017", "id": "17705", "last_activity_date": "2015-10-16T02:28:52.017", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12626", "parent_id": "17704", "post_type": "answer", "score": 1 } ]
17704
17705
17705
{ "accepted_answer_id": "18028", "answer_count": 1, "body": "開発環境 \n・OSX EI Capitan 10.11 \n・Scala 2.11.7 \n・ScalaIDE Build id: 4.2.0-vfinal-2015-09-25T11:10:29Z-Typesafe \n・Play 2.4.3\n\n下記サイトを見ながらScala+Playを勉強しているのですが、\n\nScala+Play 2.0でWebアプリ開発入門(4) \n<http://www.atmarkit.co.jp/ait/articles/1302/21/news016_2.html>\n\n下記コードで\n\n```\n\n def sample1 = Action { \n SimpleResult(\n header = ResponseHeader(200, Map(CONTENT_TYPE -> \"text/html\")), \n body = Enumerator(views.html.index(\"Sample Controller#sample1\"))\n )\n }\n \n```\n\n\"not found: value SimpleResult\"\n\n\"type mismatch; found : play.twirl.api.HtmlFormat.Appendable (which expands\nto) play.twirl.api.Html required: Array[Byte]\"\n\n2つエラーが出ます。\n\n\"not found: 〜”の場合、SimpleResult → Resultに変更したらエラーが無くなりました。 \n”type mismatch; found : 〜”も解決しましたが、\n\n```\n\n def sample1 = Action {\n //SimpleResultが使えなかったのでResultを使う。\n Result( \n header = ResponseHeader(200, Map(CONTENT_TYPE -> \"text/html\")),\n body = Enumerator(\"Sample Controlle#sample1\".getBytes) //.getBytesの型指定が必要\n )\n }\n \n```\n\nこのままSimpleResultの代わりにResultを使っても良いのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T02:33:28.957", "favorite_count": 0, "id": "17706", "last_activity_date": "2015-10-24T17:06:20.697", "last_edit_date": "2015-10-16T02:41:13.460", "last_editor_user_id": "12729", "owner_user_id": "12729", "post_type": "question", "score": 1, "tags": [ "scala", "eclipse", "playframework" ], "title": "Scala + Play2.0 → Play2.4 SimpleResultについて", "view_count": 315 }
[ { "body": "`SimpleResult` は Play 2.3 から `Result` に改名されました。 [Play 2.3 Migration\nGuide](https://www.playframework.com/documentation/ja/2.3.x/Migration23#Scala-\nresults) を参照。従って `SimpleResult` の代わりに `Result` を使い続けて問題ありません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-24T17:06:20.697", "id": "18028", "last_activity_date": "2015-10-24T17:06:20.697", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "455", "parent_id": "17706", "post_type": "answer", "score": 1 } ]
17706
18028
18028
{ "accepted_answer_id": "17715", "answer_count": 1, "body": "/subscribers/{imsi}/enable_termination(または、disable_termination)を実行したときに登録済みのSIMのIMSIを指定して実行するとResponse\nCode 400で処理に失敗してしまいます。パラメータが足りないのでしょうか? \n※コマンドの実行は、<https://dev.soracom.io/jp/docs/api/#/> から行っております。\n\nResponse Body:\n\n```\n\n {\n \"code\": \"SEM0003\",\n \"message\": \"Bad request: Invalid Json\"\n }\n \n```\n\nまた、登録されていないIMSIを指定しても同じ結果が返ってきました。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T03:47:57.220", "favorite_count": 0, "id": "17707", "last_activity_date": "2015-10-16T05:53:24.263", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7266", "post_type": "question", "score": 0, "tags": [ "soracom" ], "title": "/subscribers/{imsi}/enable_termination(disable_termination)の動作について", "view_count": 58 }
[ { "body": "ご指摘ありがとうございます。\n\nこちら、API リファレンスの Swagger の設定が誤っておりました。 \nすでに修正してデプロイ済みですので再度お試しいただけますでしょうか。\n\n(ブラウザのキャッシュが残っている場合がありますので、もし動作しないようであればブラウザのキャッシュのクリアもお試しください)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T05:53:24.263", "id": "17715", "last_activity_date": "2015-10-16T05:53:24.263", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12626", "parent_id": "17707", "post_type": "answer", "score": 0 } ]
17707
17715
17715
{ "accepted_answer_id": "17948", "answer_count": 1, "body": "お世話になっております。 \n現在Monacaで開発を進めており、 \nCordovaプラグインを利用してHealthKitから歩数を取得しようと考えました。 \n[こちらのプラグイン](http://plugins.telerik.com/cordova/plugin/healthkit)を拝借し、 \nMonacaへ下記のように組み込み実際に歩数を取得するところまで出来ました。 \nそこで問題なのですが、この歩数…ヘルスケアアプリを開くまで更新されません。 \nヘルスケアアプリを開かなくても、アプリから命令を送り更新することはできないでしょうか? \nよろしくお願いいたします。\n\n```\n\n var hk = null;\n var isHK = false;\n document.addEventListener(\"deviceready\", function(){hk_init();}, false);\n \n /**\n * HealthKit Initialized and Support Check.\n **/\n function hk_init(){\n //モジュールが存在しない\n if(typeof window.plugins.healthkit === 'undefined' || window.plugins.healthkit == null){return false;}\n if(typeof hk === 'undefined' || hk == null){hk=window.plugins.healthkit;}\n \n hk.available(\n function(res){ if(res){ isHK=true; console.log(\"healthkit ready.\"); } },\n function(e){ console.log(e); }\n );\n return true;\n }\n \n /**\n * HealthKitへ歩数取得の権限を要求する\n **/\n function requestHealthKit(callback){\n window.plugins.healthkit.requestAuthorization(\n {'readTypes' : ['HKQuantityTypeIdentifierStepCount']},\n callback,\n hk_error\n );\n }\n \n /**\n * 歩数を取得\n * @param start Date 計測開始日\n * @param end Date 計測終了日\n * @param callback function 戻り値を受け取る関数\n **/\n function call_stepcount(start,end,callback){\n if(!isHK){ hk_noinit(); }\n if(typeof start === 'undefined'){ return false; }\n if(typeof end === 'undefined'){ end=new Date(); }\n if(typeof callback === 'undefined'){ callback=function(res){console.log(res);}; }\n \n window.plugins.healthkit.querySampleType(\n {\n 'startDate' : start,\n 'endDate' : end,\n 'sampleType': 'HKQuantityTypeIdentifierStepCount',\n 'unit' : 'count' // make sure this is compatible with the sampleType\n },\n callback,\n hk_error\n );\n }\n \n /**\n * HealthKitの返却値から歩数を累計する\n * @param Array 返却値\n * @return Integer 総歩数\n **/\n function analyze_step(res){\n var steps = 0;\n try{\n //分布分配列探査\n for(var n=0,len=res.length;n<len;n++){\n steps += res[n][\"quantity\"];\n }\n return steps;\n }catch(e){\n return 0;\n }\n }\n \n /**\n * 特定の1日の歩数を取得する\n * @param specific Date or String 指定日(Date型もしくは\"yyyy/mm/dd\"の文字列)\n * @param callback function 第一引数に歩数(INT)\n **/\n function oneday_steps(specific,callback){\n var start=null;\n if(typeof specific === 'object'){start=new Date(specific.getFullYear()+\"/\"+(specific.getMonth()+1)+\"/\"+specific.getDate());}\n else if(typeof specific === 'string'){start=new Date(specific);}\n else{callback(0);return;}\n //開始から24時間後を指定する\n var end=new Date(((start*1)+(24*60*60*1000)));\n call_stepcount(start,end,function(res){callback(analyze_step(res));});\n }\n \n /**\n * 本日の累計歩数を取得する\n * @param callback function 第一引数に歩数(INT)\n **/\n function today_steps(callback){\n var now=new Date();\n var start = new Date(now.getFullYear()+\"/\"+(now.getMonth()+1)+\"/\"+now.getDate());\n call_stepcount(start,now,function(res){callback(analyze_step(res));});\n }\n \n /**\n * 日曜日を週の始めとした今週の累計歩数を取得する\n * @param callback function 第一引数に歩数(INT)\n **/\n function week_steps(callback){\n var now=new Date();\n var start = new Date((new Date(now.getFullYear()+\"/\"+(now.getMonth()+1)+\"/\"+now.getDate())) - (now.getDay() * (24*60*60*1000)));\n call_stepcount(start,now,function(res){callback(analyze_step(res));});\n }\n \n /**\n * 今月の累計歩数を取得する\n * @param callback function 第一引数に歩数(INT)\n **/\n function month_steps(callback){\n var now=new Date();\n var start = new Date(now.getFullYear()+\"/\"+(now.getMonth()+1)+\"/01\");\n call_stepcount(start,now,function(res){callback(analyze_step(res));});\n }\n \n /**\n * 今年の累計歩数を取得する\n * @param callback function 第一引数に歩数(INT)\n **/\n function year_steps(callback){\n var now=new Date();\n var start = new Date(now.getFullYear()+\"/01/01\");\n call_stepcount(start,now,function(res){callback(analyze_step(res));});\n }\n \n /**\n * 全ての累計歩数を取得する\n * @param callback function 第一引数に歩数(INT)\n **/\n function all_steps(callback){\n var now=new Date();\n var start = new Date(\"1900/01/01\");\n call_stepcount(start,now,function(res){callback(analyze_step(res));});\n }\n \n /**\n * HealthKitのエラーが発生した。\n * @param result Object エラーコールバックへ渡される引数\n **/\n function hk_error(result) {\n console.log(\"Error: \\n\" + JSON.stringify(result));\n requestHealthKit(function(ev){console.log(ev);});\n alert(\"HealthKitへのアクセスに失敗しました。\\nこのアプリからのアクセスを許可されていない可能性があります。\");\n };\n \n /**\n * HealthKit未初期化なので初期化しなおす\n **/\n function hk_noinit(){\n //再度、初期化かけて通知を表示\n hk_init();\n alert(\"HealthKitからの応答がありません。\\n時間をおいて再度お試しください。\");\n }\n \n /**\n * デバッグ関数\n **/\n function debug_hk(no){\n switch (no){\n case 0://昨日の歩数\n oneday_steps((new Date()-(24*60*60*1000)),hk_success);\n break;\n case 1://今日の歩数\n today_steps(hk_success);\n break;\n case 2://今週の歩数\n week_steps(hk_success);\n break;\n case 3://今月の歩数\n month_steps(hk_success);\n break;\n case 4://今年の歩数\n year_steps(hk_success);\n break;\n case 5://全ての歩数\n all_steps(hk_success);\n break;\n }\n }\n \n /**\n * デバッグ用、結果出力\n **/\n function hk_success(result) {\n console.log(\"success : \" + result);\n };\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T04:12:18.227", "favorite_count": 0, "id": "17709", "last_activity_date": "2020-09-04T14:25:13.727", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": 1, "tags": [ "ios", "monaca", "cordova", "health-kit" ], "title": "HealthKitから歩数を取得したい", "view_count": 2053 }
[ { "body": "自己解決いたしました。 \n更新時にモニタリングする関数があり、 \nモニタリング中の更新が発生した場合のコールバックにて呼び出すと更新できました。 \nモニタリングを行わない場合、初回の呼び出しの値を保持し続けるので注意ですね。\n\n```\n\n window.plugins.healthkit.monitorSampleType(\n {'sampleType': 'HKQuantityTypeIdentifierStepCount'},\n function(res){\n window.plugins.healthkit.querySampleType(\n {\n 'startDate' : start,\n 'endDate' : end,\n 'sampleType': 'HKQuantityTypeIdentifierStepCount',\n 'unit' : 'count'\n },\n callback,\n hk_error\n );\n },\n hk_error\n );\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:58:48.940", "id": "17948", "last_activity_date": "2015-10-22T08:58:48.940", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "17709", "post_type": "answer", "score": 1 } ]
17709
17948
17948
{ "accepted_answer_id": "19086", "answer_count": 2, "body": "FuelPHPのtaskでバッチ処理を行っていたのですが、処理時間がだいぶかかるようになったため、マルチスレッド化して並列処理を行うように改修しているのですが、不可解な挙動をするので、相談させて下さい。\n\nテストスクリプトとして以下を記述しました。\n\nfuel/app/tasks/test.php\n\n```\n\n <?php\n namespace Fuel\\Tasks;\n \n class Test\n {\n public static function run()\n {\n // 動く(10がインサートされる)\n \\Foo_Bar::insert(10);\n \n $bar = new \\Foo_Bar();\n \n // 動く(20がインサートされる)\n $bar->run();\n \n // 動かない(Class 'DB' not found)\n $bar->start();\n }\n }\n \n```\n\nfuel/app/classes/foo/bar.php\n\n```\n\n <?php\n class Foo_Bar extends Thread\n {\n public static function insert($i)\n {\n DB::insert('test')->set(array(\n 'i' => $i,\n ))->execute();\n }\n \n public function run()\n {\n $this->insert(20);\n }\n }\n \n```\n\n挙動は、test.phpのコメントの通りとなります。 \nスタティックメソッド呼び出しの際は問題なくテーブルに10がインサートされます。 \nまた、Foo_Barクラスをインスタンス化して、直接run()メソッドを呼び出しても問題ありません。 \nところが、別スレッドとしてrun()メソッドが呼ばれると、Class 'DB' not foundエラーが発生します。 \nself::insert(20); としてみたり、run()メソッド内で直接 DB::insert()を呼び出しても同様のエラーが発生します。\n\nDBアクセス以外の処理(外部クラスを利用しない)は問題なく、マルチスレッドで動くことは確認できています。 \nなぜ、マルチスレッドにした場合、外部クラスが見つからなくなるのか、また、どうすれば利用できるのかご教示いただけると幸いです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T05:19:33.487", "favorite_count": 0, "id": "17710", "last_activity_date": "2015-11-20T20:25:48.407", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10298", "post_type": "question", "score": 2, "tags": [ "php", "fuelphp" ], "title": "FuelPHPのtaskでマルチスレッドを使用すると外部クラスが見つからない", "view_count": 2371 }
[ { "body": "<http://blog.madewithlove.be/post/thread-carefully/> \nオートローダで読み込んだクラスは生成したスレッドに引き継がれないので、スレッド内部でオートローダの読み込みのような初期化を別途行う必要があります\n\n追記:「オートローダで読み込んだクラスは生成したスレッドに引き継がれない」は間違いでした。くわしくはunaristさんの回答を参照。「初期化を別途行う」で動くというのは間違ってもいないので、サンプルを追記しときます。静的プロパティの初期化は必要なのでそこそこ面倒くさいです\n\n```\n\n <?php\n namespace Fuel\\Tasks;\n \n class Threadtest\n {\n public static function run()\n {\n for($i=0;$i<5;$i++){\n $pool[] = new ThreadSample(); \n }\n foreach($pool as $key => $worker){\n echo ($key+1).' started'.\"\\n\";\n $worker->start();\n }\n foreach($pool as $worker){\n $worker->join();\n }\n }\n }\n \n class ThreadSample extends \\Thread{\n function run(){\n require APPPATH.'bootstrap_thread.php';\n $array = [];\n var_dump(\\DB::select()->from('test_table')->execute()->current());\n }\n }\n \n```\n\nbootstrap_thread.php はたとえばこんなの↓\n\n```\n\n <?php\n class Autoloader_Threaded extends Fuel\\Core\\Autoloader{\n protected static $classes = array();\n protected static $namespaces = array();\n protected static $psr_namespaces = array();\n protected static $core_namespaces = array(\n 'Fuel\\\\Core',\n );\n protected static $default_path = null;\n protected static $auto_initialize = null;\n }\n class Config_Threaded extends Fuel\\Core\\Config {\n public static $loaded_files = array();\n public static $items = array();\n public static $default_check_value;\n protected static $itemcache = array();\n }\n class_alias('Autoloader_Threaded', 'Autoloader');\n class_alias('Config_Threaded', 'Config');\n setup_autoloader();\n require VENDORPATH.'autoload.php';\n \\Autoloader::register();\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-11-20T10:34:11.533", "id": "19086", "last_activity_date": "2015-11-20T20:25:48.407", "last_edit_date": "2015-11-20T20:25:48.407", "last_editor_user_id": "13349", "owner_user_id": "13349", "parent_id": "17710", "post_type": "answer", "score": 1 }, { "body": "## 要約\n\n * pthreads拡張で作ったスレッドでは、クラスの別名やオートローダがリセットされます\n * それとは別に、FuelPHPはpthreads拡張に対応していません\n\n* * *\n\n`DB` クラスの実体は `Fuel\\Core\\DB` なのですが、FuelPHP の起動時に別名登録を行うことで `DB`\nで使えるようになっています。で、これを **新しいスレッドに引き継げない**\nために、クラスが見つからないというエラーになっているようです。クラス定義自体は引き継がれています。\n\nFuelPHP の内部でもこの別名を使っていますから、他のコアクラスも含め、別名を定義しなおす必要があります。幸いこの別名は規則的ですから、Thread か\nWorker の `run()` の最初に以下のコードを書けば一括処理できそうです。\n\n```\n\n foreach (get_declared_classes() as $fullname) {\n if (substr($fullname, 0, 10) === 'Fuel\\\\Core\\\\') {\n class_alias($fullname, substr($fullname, 10));\n }\n }\n \n```\n\nところが `\\Foo_Bar::insert()` や `$bar->run()` を取り除くとやはりエラーになります。\n**オートローダ関数のリストも新しいスレッドには引き継がれない**\nようで、オートローディングが使えないのです。そのため、あらかじめクラスを読み込んでおく必要があります。\n\nこれに関してはpthreads拡張のIssueにも書かれていました。\n<https://github.com/krakjoe/pthreads/issues/68>\n\n・・・というのが「Class xxx not found」の話ですが、(holywise\nさんが書かれたように)クラスが新しいスレッドに引き継がれる際、静的プロパティに設定された配列が軒並みnullになります。FuelPHP\n内部でもこのような個所が多数あるようで、結局ろくに動きませんでした。\n\npthreads拡張のオプションでクラスを引き継がないようにして、再度読み込みなおすという手があるにはありますが、`oil`\nファイルに書かれている分も含めFuelPHPの初期化をし直す必要があるので・・・。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-11-20T17:55:14.687", "id": "19101", "last_activity_date": "2015-11-20T17:55:14.687", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "parent_id": "17710", "post_type": "answer", "score": 1 } ]
17710
19086
19086
{ "accepted_answer_id": "17714", "answer_count": 1, "body": "golang公式Documentにある[Writing Web\nApplications](https://golang.org/doc/articles/wiki/)の序盤で以下のコードが出てきました.\n\n```\n\n type Page struct {\n Title string\n Body []byte\n }\n \n func (p *Page) save() error {\n filename := p.Title + \".txt\"\n return ioutil.WriteFile(filename, p.Body, 0600)\n }\n \n```\n\n`p.Title`でPage構造体のTitle変数にアクセスしていますが,ここでは \n`*p.Title`としないとアクセスできないように見えてしまいます. \n何故`p.Title`でアクセスできてしまうのでしょうか.", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T05:42:55.840", "favorite_count": 0, "id": "17713", "last_activity_date": "2015-10-16T05:55:55.107", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7797", "post_type": "question", "score": 0, "tags": [ "go" ], "title": "Go言語における構造体のメンバへのアクセス(ポインタ)", "view_count": 1495 }
[ { "body": "Go言語の仕様です(という回答しかできない気が。。。\n\n仕様は[ここ](https://golang.org/ref/spec#Selectors)にあります。\n\n// 本家でも同様の質問をされた方がいるようです", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T05:45:18.520", "id": "17714", "last_activity_date": "2015-10-16T05:55:55.107", "last_edit_date": "2015-10-16T05:55:55.107", "last_editor_user_id": "845", "owner_user_id": "845", "parent_id": "17713", "post_type": "answer", "score": 2 } ]
17713
17714
17714
{ "accepted_answer_id": "17717", "answer_count": 1, "body": "<https://dev.soracom.io/jp/docs/api/> から\n/stats/air/operators/{operator_id}/export を実行したときにResponse Code: 500 が返ってきました。\n\nResponse Body:\n\n```\n\n {\n \"code\": \"COM0003\",\n \"message\": \"Internal server error. message:400 Bad Request\"\n }\n \n```\n\n**実行時のパラメータ** \nURL: <https://api.soracom.io/v1/stats/air/operators/>{自分のOperatorID}/export \nbody:\n\n```\n\n {\n \"from\": 1443657600, // 2015年10月01日0時0分\n \"period\": \"month\", \n \"to\": 1446335940 // 2015年10月31日23時59分\n }\n \n```\n\n**利用状況** \n\\- 指定したOperatorIDに関連するSIMカードは1枚 \n\\- SIMカードは登録のみ(データ通信は1度も行ったことがない)の状態\n\n**質問**\n\n 1. Response Code: 500 になるのは正しい動きなのでしょうか?\n 2. Response Code: 500 が間違っている場合は、どのような動作になるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T06:35:49.527", "favorite_count": 0, "id": "17716", "last_activity_date": "2015-10-16T07:19:50.607", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7266", "post_type": "question", "score": 0, "tags": [ "soracom" ], "title": "/stats/air/operators/{operator_id}/export の動作について", "view_count": 61 }
[ { "body": "subscriber の groupId に実在しない ID が設定されている場合に /stats API\nが同様のエラーを返す場合があるようです。こちらはその問題に該当するかもしれません。\n\n本来は /subscriber/set_group API が実在しない ID\nを受け付けないようになっている必要があるのですが、そのチェック処理が抜けており、実在しない ID\nも受け付けるようになってしまっているためにこの問題が起こってしまうようです。\n\nこの件はおって修正させていただきますが、バックエンドの修正となるため少々時間を要します。\n\nそれまでの回避策としましては、いったん unset_group API にて groupId を null としていただくことで /stats API\nのエラーが起きなくなるものと思われます。\n\nこちらをお試しいただくことはできますでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T07:19:50.607", "id": "17717", "last_activity_date": "2015-10-16T07:19:50.607", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12626", "parent_id": "17716", "post_type": "answer", "score": 0 } ]
17716
17717
17717
{ "accepted_answer_id": null, "answer_count": 2, "body": "Monacaアプリ初回起動時に、 \nデバイストークン、登録IDを取得し、 \nAmazon SNSにエンドポイントを作成し、 \nphpなどを使用し別のサーバーからpush依頼を投げ、 \nMonacaのアプリでpush通知を受信したい \nのですが、情報がほとんど有りません。\n\nNaitiveだとAWSからSDKが提供されていますので、出来ましたが、 \nMonacaで実装したいので、ご存知の方いらっしゃいましたらアドバイス下さい。\n\nCordvaプラグインを自作して行うのかなと思うのですが、なんとも。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2015-10-16T08:47:14.493", "favorite_count": 0, "id": "17718", "last_activity_date": "2021-06-15T11:06:56.577", "last_edit_date": "2021-06-15T11:06:16.943", "last_editor_user_id": "3060", "owner_user_id": "12629", "post_type": "question", "score": 0, "tags": [ "monaca", "amazon-sns" ], "title": "Amazon SNSを使用したpush通知をMonacaで行いたい", "view_count": 1199 }
[ { "body": "よく分かってないので間違ってるかもしれませんが \nAWS SDK for JavaScript in the Browser は SNS に対応してるようですので使えませんか?\n\n<http://aws.typepad.com/aws_japan/2013/11/developer-preview-aws-sdk-for-\njavascript.html>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T11:24:20.557", "id": "17726", "last_activity_date": "2015-10-16T11:24:20.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "17718", "post_type": "answer", "score": 1 }, { "body": "[Amazon SNSとAdobe PhoneGap\nBuildを利用したプッシュ通知アプリの作成](https://www.infoscoop.org/blogjp/2014/08/22/amazon-\nsns-adobe-phonegap-build-push-notification/)\n\nこちらの記事がほぼそのままの内容かなと思います。\n\nPushPluginがdeprecatedになっているので、代わりに、\n\n<https://github.com/phonegap/phonegap-plugin-push>\n\nこのプラグインをMonacaにインストールし、あとは記事の通りに設定すればできそうな気がしますが...", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2016-09-27T02:55:18.360", "id": "29167", "last_activity_date": "2021-06-15T11:06:56.577", "last_edit_date": "2021-06-15T11:06:56.577", "last_editor_user_id": "3060", "owner_user_id": "18920", "parent_id": "17718", "post_type": "answer", "score": 1 } ]
17718
null
17726
{ "accepted_answer_id": null, "answer_count": 1, "body": "エラー内容 \n`cannot assign a value of type \"NSDateFormatter\" to a value of type` \"NSDate\" \nエラー箇所 \n`notification.fireDate = myDateFormatter`\n\n```\n\n let myDateFormatter = NSDateFormatter()\n myDateFormatter.locale = NSLocale(localeIdentifier: \"ja_JP\")\n myDateFormatter.dateFormat = \"yyyy/MM/dd hh:mm\"\n \n let mySelectedDate: NSString = myDateFormatter.stringFromDate(sender.date)\n dateField.text = mySelectedDate as String\n \n \n UIApplication.sharedApplication().cancelAllLocalNotifications();\n let setting = UIUserNotificationSettings(forTypes: [.Sound, .Alert], categories: nil)\n UIApplication.sharedApplication().registerUserNotificationSettings(setting)\n let notification = UILocalNotification()\n notification.fireDate = myDateFormatter\n notification.timeZone = NSTimeZone.defaultTimeZone()\n notification.alertBody = \"通知だよ\"\n notification.alertAction = \"OK\"\n notification.soundName = UILocalNotificationDefaultSoundName\n UIApplication.sharedApplication().scheduleLocalNotification(notification);\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T09:05:57.870", "favorite_count": 0, "id": "17720", "last_activity_date": "2016-02-13T21:32:01.110", "last_edit_date": "2015-10-16T09:59:12.247", "last_editor_user_id": "5519", "owner_user_id": "12807", "post_type": "question", "score": 0, "tags": [ "ios", "swift", "iphone" ], "title": "Swift LocalNotificationで通知時間を指定したい", "view_count": 476 }
[ { "body": "エラーメッセージの通りで、`myDateFormatter`は`NSDateFormatter`のインスタンスなので、`NSDate`ではないからですね。\n\n`fireDate`に代入したいのは`sender.date`なのではありませんか?", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T10:01:01.630", "id": "17722", "last_activity_date": "2015-10-16T10:01:01.630", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "17720", "post_type": "answer", "score": 1 } ]
17720
null
17722
{ "accepted_answer_id": null, "answer_count": 0, "body": "現在バックグラウンドで端末のWifiをOnまたはOffにする機能を持ったアイフォンアプリをSwiftを使って作成しようとしています。 \nそこで質問です。iOSでは端末の設定をコードから変更するということは可能なのでしょうか。 \nできるのであれば、方法を教えて下さい。よろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T10:12:03.307", "favorite_count": 0, "id": "17723", "last_activity_date": "2015-10-16T10:12:03.307", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7232", "post_type": "question", "score": 1, "tags": [ "ios", "swift" ], "title": "iOSでコードからWifiのon/offをコントロールできますか", "view_count": 301 }
[]
17723
null
null
{ "accepted_answer_id": "17729", "answer_count": 1, "body": "下記のコードでエラーが生じ,解決策が思いつかないため、お知恵をお借りできればと思います。 \nよろしくお願い申し上げます。\n\nNSJSONSerialization.JSONObjectWithDataの部分でbuildエラーが生じるため、下記のそのエラーを修正するコードを書きましたが、うまくいきませんでした。\n\n解決したいこと\n\n定数 jsonの行で生じるエラーを改善したい。\n\n```\n\n 問題のあるコード\n \n private func showSongs() {\n let urlString = \"https://itunes.apple.com/search?term=Ryuichi+Sakamoto&entity=musicTrack&limit=3&lang=ja_jp&country=JP\"\n let url = NSURL(string: urlString)\n let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())\n let dataTask = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in\n if (error == nil){\n //ここから\n let json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: nil) as! [String:AnyObject]\n //ここまでがExtra argument 'error' in call、つまりエラーになります。\n let results = json[\"results\"] as! [[String:AnyObject]]\n for song in results {\n let trackName = song[\"trackName\"] as! String\n println(trackName)\n }\n }\n })\n dataTask.resume()\n }\n \n```\n\n \n \nネットで解決策を探し、書いてみたコード(より多くのエラーが生じました。)\n\n```\n\n private func showSongs(){\n let urlString = \"https://itunes.apple.com/search?term=Ryuichi+Sakamoto&entity=musicTrack&limit=3&lang=ja_jp&country=JP\"\n let url = NSURL(string: urlString)\n let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())\n let dataTask = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in\n do{\n let json = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments) as! [String:AnyObject]\n let results = json[\"results\"] as! [String:anyObjects]\n for song in results {\n let trackName = song[\"trackName\"] as! String\n print(trackName)\n }\n }\n })\n dataTask.resume()\n \n```\n\n}", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T11:26:55.823", "favorite_count": 0, "id": "17727", "last_activity_date": "2015-10-16T11:44:26.713", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10491", "post_type": "question", "score": -1, "tags": [ "swift" ], "title": "swiftにて、extra argument 'error' in callのエラーを改善したい。", "view_count": 5103 }
[ { "body": "Swift\n2では新しいエラーハンドリングの仕組みとして`do〜try〜catch`構文が導入され、`NSError`のダブルポインタはSwiftから使う場合は自動的に上記のAPIに沿うように変換されるようになりました。\n\nなのでメソッドの定義から`NSError`の引数はなくなっているにもかかわらず、以前と同じ形式で呼び出しているので引数が多いというコンパイルエラーになっています。\n\n該当の部分を`do〜try〜catch`を使って書き直すと、下記のようになります。\n\n```\n\n do {\n let json = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as! [String: AnyObject]\n ...\n } catch let error as NSError {\n // エラー処理をする\n }\n \n```\n\nバリエーションとして、エラーを単に無視する`try?`や、エラーがあった時にクラッシュする、`try!`という書き方があります。`try?`あるいは`try!`を使うと`do~catch`ブロックは不要になります。\n\n詳しくは \n<https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html>\n\n^ こちらをご覧ください。\n\n他にもいくつかSwift 2ではエラーになる箇所がありましたので、全部修正したのは下記になります。\n\n```\n\n private func showSongs() {\n let urlString = \"https://itunes.apple.com/search?term=Ryuichi+Sakamoto&entity=musicTrack&limit=3&lang=ja_jp&country=JP\"\n let url = NSURL(string: urlString)\n let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())\n let dataTask = session.dataTaskWithURL(url!, completionHandler: { (data, response, error) -> Void in\n if let data = data where error == nil {\n do {\n let json = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as! [String: AnyObject]\n let results = json[\"results\"] as! [[String:AnyObject]]\n for song in results {\n let trackName = song[\"trackName\"] as! String\n print(trackName)\n }\n } catch let error as NSError {\n // エラー処理をする\n }\n }\n })\n dataTask.resume()\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T11:44:26.713", "id": "17729", "last_activity_date": "2015-10-16T11:44:26.713", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "17727", "post_type": "answer", "score": 2 } ]
17727
17729
17729
{ "accepted_answer_id": "17734", "answer_count": 1, "body": "共用エリアに作っておいたデータベースファイルを、インストール時に移動するか、できなければ、なんらかの方法でコピーする方法がわかりません。\n\nどうしたらいいのか、教えていただければ幸いです。\n\nよろしくお願いいたします。\n\n下記はテストで使っていますが、うまく動きません。\n\n```\n\n var realmPath: String {\n let containerURL = NSFileManager().containerURLForSecurityApplicationGroupIdentifier(\"group.AppGroupKeybora\")\n let docsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.LibraryDirectory , NSSearchPathDomainMask.UserDomainMask, true)[0]\n let databaseStr = \"Dictionary.realm\"\n let dbPath = docsPath.stringByAppendingString(\"/\" + databaseStr)\n var TodbPath = containerURL!.URLByAppendingPathComponent(databaseStr).path!\n \n \n // BEGING MODIFICATION\n let fileMan = NSFileManager.defaultManager()\n if !(fileMan.fileExistsAtPath(dbPath)) { // The database does not already exist in Documents directory\n if let source = NSBundle.mainBundle().resourcePath?.stringByAppendingString(databaseStr) {\n if !(fileMan.fileExistsAtPath(source)) {\n print(\"RealmDB - file \\(databaseStr) not found in bundle\")\n \n } else {\n do {\n try fileMan.copyItemAtPath(source, toPath: TodbPath)\n } catch let error as NSError {\n print(\"RealmDB - failed to copy writable version of DB!\")\n print(\"Error - \\(error.localizedDescription)\")\n }\n }\n }\n }\n // END MODIFICATION\n \n return TodbPath\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T11:41:17.423", "favorite_count": 0, "id": "17728", "last_activity_date": "2015-10-16T16:04:20.810", "last_edit_date": "2015-10-16T16:04:20.810", "last_editor_user_id": "5519", "owner_user_id": "10845", "post_type": "question", "score": -1, "tags": [ "swift", "ios8" ], "title": "iOSでAppGroupを利用したいのですが、初期設定で共用エリアにデータベースファイルを移動しておく方法を知りたい", "view_count": 210 }
[ { "body": "あなたのコードはドキュメントディレクトリに`\"Dictionary.realm\"`というファイルがあるかどうをチェックして、無ければ何もしないという処理になっているので(当然ドキュメントディレクトリにファイルは無いので)、期待した通りに動かないのはそういう理由だと思います。\n\n「共有コンテナ」にファイルがあるかどうかをチェックして、無ければ「バンドル」からファイルを「共有コンテナ」にコピーする、というのが期待している処理だと思いますので、そのように書く必要があります。\n\nラフに修正したのが下記になります。\n\n```\n\n let containerURL = NSFileManager().containerURLForSecurityApplicationGroupIdentifier(\"group.io.realm.RealmAppCom\")\n let databaseStr = \"Dictionary.realm\"\n let TodbPath = containerURL!.URLByAppendingPathComponent(databaseStr).path!\n \n let fileMan = NSFileManager.defaultManager()\n if !(fileMan.fileExistsAtPath(TodbPath)) { // The database does not already exist in Documents directory\n if let source = NSBundle.mainBundle().pathForResource(databaseStr, ofType: nil) {\n if !(fileMan.fileExistsAtPath(source)) {\n print(\"RealmDB - file \\(databaseStr) not found in bundle\")\n \n } else {\n do {\n try fileMan.copyItemAtPath(source, toPath: TodbPath)\n } catch let error as NSError {\n print(\"RealmDB - failed to copy writable version of DB!\")\n print(\"Error - \\(error.localizedDescription)\")\n }\n }\n }\n }\n \n return TodbPath\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T16:04:06.520", "id": "17734", "last_activity_date": "2015-10-16T16:04:06.520", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "17728", "post_type": "answer", "score": 1 } ]
17728
17734
17734
{ "accepted_answer_id": null, "answer_count": 1, "body": "初めまして。 \n前回の質問でたくさんのコメントを頂き、SQLiteを使用するための設定をするところまで行いました。 \nしかし、本当にSQLiteを触れるのかを確かめようとDB作成の仕方を調べてみたものの、System.Data.SQlite.dllを追加するやりかたしか見つかりませんでした。\n\nSQLite for Windows Runtimeをインストールし、 \nSQLite for Windows Runtimeとc++2013を追加して、 \nsqlite-netをインストールすることろまでは終わっています。\n\nxamlでボタンを作りました。MainPage.xaml.csにクリックイベントの処理を書き込むprivate void から始まる記述もあります。\n\n```\n\n private void conect_bt(object sender, RoutedEventArgs e)\n {\n \n }\n \n```\n\nこの中にSQLiteでDBに接続する、もしくはDBを作成する記述を書くのでしょうか、 \n情報が見つからずDB接続が上手くいくかの確認ができずにいて困っています。\n\nc#でSQliteを使い、ストアアプリで使用するDBを作成する記述とはどのようなものなのでしょうか?\n\n参考になるサイトでも構いませんので教えていただきたいです。 \nよろしくお願いします。", "comment_count": 10, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T12:48:14.987", "favorite_count": 0, "id": "17730", "last_activity_date": "2015-10-17T13:37:43.113", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12797", "post_type": "question", "score": -1, "tags": [ "c#", "visual-studio", "sqlite", "database" ], "title": "c#でストアアプリで使用するSQLiteのDBを作りたい", "view_count": 1021 }
[ { "body": "実装することができましたので、ここにソースコードを置きたいとと思います。\n\n```\n\n public sealed partial class MainPage : Page\n {\n public MainPage()\n {\n this.InitializeComponent();\n Loaded += MainPage_Loaded;\n }\n \n void MainPage_Loaded(object sender, RoutedEventArgs e)\n {\n // データベース保存先と,データベースファイルの名前を決める\n var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, \"Food.db\");\n // dbpathで指定したデータベースファイルに,接続する\n using (var db = new SQLite.SQLiteConnection(dbpath))\n {\n // テーブルを作成\n db.CreateTable<Food>();\n // トランザクション処理\n db.RunInTransaction(() =>\n {\n // レコードの作成\n db.Insert(new Food() { Name = \"醤油ラーメン\", Price = 500, Calorie = 700 });\n db.Insert(new Food() { Name = \"きつねうどん\", Price = 350, Calorie = 500 });\n db.Insert(new Food() { Name = \"カレーライス\", Price = 450, Calorie = 1000 });\n db.Insert(new Food() { Name = \"ポテトチップス\", Price = 200, Calorie = 600 });\n });\n \n // ListViewのソースに設定する\n Food_listview.ItemsSource = db.Table<Food>();\n }\n }\n \n }\n \n public class Food\n {\n // 主キー,自動連番\n [AutoIncrement, PrimaryKey]\n public int Id { get; set; }\n \n // カラムの型と名前\n public string Name { get; set; }\n public int Price { get; set; }\n public int Calorie { get; set; }\n \n // 出力形式\n public override string ToString()\n {\n return string.Format(\"ID : {0}\\t商品名:{1}\\t価格:{2}円\\tカロリー:{3}kcal\",Id, Name, Price, Calorie);\n }\n }\n \n```\n\nコメントを下さった皆様、ありがとうございました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T13:37:43.113", "id": "17756", "last_activity_date": "2015-10-17T13:37:43.113", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12797", "parent_id": "17730", "post_type": "answer", "score": 1 } ]
17730
null
17756
{ "accepted_answer_id": "17735", "answer_count": 1, "body": "下記のソースコードは、data-theme属性によりスタイルを切り替えている物です。 \n時計と、それに色を付けるためのボタンがあるのですが、 \n\"ボタンの背景色=時計の色\"のため`<style>`の[data-theme]の\"color\"を \n\"background-color\"と同じにしました。 \nしかし、そうすると今度はボタンの中の文字色も同じになるため、その文字が \n消えてしまいます。 \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 charset=\"utf-8\" />\n <title></title>\n \n \n <style>\n [data-theme=\"black\"]{ color: black; background-color:black;}\n [data-theme=\"blue\"]{ color: blue; background-color:blue;}\n [data-theme=\"silver\"]{ color: silver; background-color:silver;}\n [data-theme=\"white\"]{ color: white; background-color:white;}\n \n </style>\n </head>\n \n <body id=\"back\" data-theme=\"silver\">\n \n <button onclick=\"clock.hidden = !clock.hidden; event.target.textContent = clock.hidden ? 'Show' : 'Hide'; match_theme();\" data-theme=\"white\">Hide</button>\n <br>\n <button data-theme=\"black\" onclick=\"set_theme([back], 'black'); match_theme();\">Black</button>\n <button data-theme=\"blue\" onclick=\"set_theme([back], 'blue'); match_theme();\">Blue</button>\n <button data-theme=\"silver\" onclick=\"set_theme([back], 'silver'); match_theme();\">Silver</button>\n <br>\n \n Clock:\n <select id=\"clock_setter\" data-theme=\"blue\" autocomplete=\"off\"\n onchange=\"set_theme(clock_parts, get_theme(event));\">\n <option data-theme=\"black\">Clock</option>\n <option data-theme=\"blue\" selected> Blue </option>\n <option data-theme=\"silver\"> Silver</option> \n <option id=\"clock_setter_none\" data-theme=\"white\" hidden>--C--</option>\n </select>\n Date:\n <select id=\"date_setter\" data-theme=\"blue\" autocomplete=\"off\"\n onchange=\"set_theme([Od],get_theme(event));\">\n <option data-theme=\"black\"> Black </option>\n <option data-theme=\"blue\" selected> Blue </option>\n <option data-theme=\"silver\"> Silver </option>\n </select>\n Face:\n <select id=\"face_setter\" data-theme=\"blue\" autocomplete=\"off\"\n onchange=\"set_theme([Of],get_theme(event));\">\n <option data-theme=\"black\"> Black </option>\n <option data-theme=\"blue\" selected> Blue </option>\n <option data-theme=\"silver\"> Silver </option>\n </select>\n Hours:\n <select id=\"hour_setter\" data-theme=\"blue\" autocomplete=\"off\"\n onchange=\"set_theme([Oh],get_theme(event));\">\n <option data-theme=\"black\"> Black </option>\n <option data-theme=\"blue\" selected> Blue </option>\n <option data-theme=\"silver\"> Silver </option>\n </select>\n Minutes:\n <select id=\"minute_setter\" data-theme=\"blue\" autocomplete=\"off\"\n onchange=\"set_theme([Om],get_theme(event));\">\n <option data-theme=\"black\"> Black </option>\n <option data-theme=\"blue\" selected> Blue </option>\n <option data-theme=\"silver\"> Silver </option>\n </select>\n Seconds:\n <select id=\"second_setter\" data-theme=\"blue\" autocomplete=\"off\"\n onchange=\"set_theme([Os],get_theme(event));\">\n <option data-theme=\"black\"> Black </option>\n <option data-theme=\"blue\" selected> Blue </option>\n <option data-theme=\"silver\"> Silver </option>\n </select>\n </body>\n \n <div id=\"clock\">\n <div id=\"Od\" data-theme=\"blue\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n <div id=\"Of\" data-theme=\"blue\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n <div id=\"Oh\" data-theme=\"blue\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n <div id=\"Om\" data-theme=\"blue\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n <div id=\"Os\" data-theme=\"blue\" style=\"position:absolute;top:0px;left:0px\">\n <div style=\"position:relative\">\n </div>\n </div>\n </div>\n \n <script type=\"text/javascript\">\n \n \n (function(){\n \"use strict\";\n \n function $(sel)\n {\n return document.getElementById(sel);\n } \n \n function $$(sel)\n {\n if (typeof document.getElementsByClassName === 'undefined')\n {\n return document.getElementsByName(sel);\n }\n return document.getElementsByClassName(sel);\n }\n \n var dCol = '', //date colour.\n sCol = '', //seconds colour.\n mCol = '', //minutes colour.\n hCol = '', //hours colour.\n fCol = '', //face color\n ClockHeight = 40,\n ClockWidth = 40,\n ClockFromMouseY = 0,\n ClockFromMouseX = 100,\n d = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"],\n m = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"],\n date = new Date(),\n day = date.getDate(),\n year = date.getYear() + 1900;\n \n var TodaysDate = \" \" + d[date.getDay()] + \" \" + day + \" \" + m[date.getMonth()] + \" \" + year;\n var D = TodaysDate.split('');\n var H = '...';\n H = H.split('');\n var M = '....';\n M = M.split('');\n var S = '.....';\n S = S.split('');\n var Face = '1 2 3 4 5 6 7 8 9 10 11 12',\n font = 'Helvetica, Arial, sans-serif',\n size = 1,\n speed = 0.6;\n Face = Face.split(' ');\n var n = Face.length;\n var a = size * 10;\n var ymouse = 0,\n xmouse = 0,\n scrll = 0,\n props = '<span style=\"font-family:' + font + ';font-size:' + size + 'em; color:#' + fCol + '\">',\n props2 = '<span style=\"font-family:' + font + ';font-size:' + size + 'em; color:#' + dCol + '\">';\n var Split = 360 / n;\n var Dsplit = 360 / D.length;\n var HandHeight = ClockHeight / 4.5; \n var HandWidth = ClockWidth / 4.5;\n var HandY = -7,\n HandX = -2.5,\n step = 0.06,\n currStep = 0,\n y = [],\n x = [],\n Y = [],\n X = [],\n Dy = [],\n Dx = [],\n DY = [],\n DX = [];\n var i;\n \n for (i = 0; i < n; i++) \n {\n y[i] = 0;\n x[i] = 0;\n Y[i] = 0;\n X[i] = 0;\n }\n \n for (i = 0; i < D.length; i++) \n {\n Dy[i] = 0;\n Dx[i] = 0;\n DY[i] = 0;\n DX[i] = 0;\n }\n \n var wrapper = $('clock');\n var html = ''\n // Date wrapper\n \n html = '';\n \n for (i = 0; i < D.length; i++)\n {\n html += '<div class=\"Date\" name=\"Date\" style=\"position:absolute;top:0px;left:0;height:' + a + ';width:' + a + ';text-align:center\">' + props2 + D[i] + '</span></div>';\n }\n \n $('Od').children[0].innerHTML = html;\n // Face wrapper\n html = '';\n \n for (i = 0; i < n; i++) \n {\n html += '<div class=\"Face\" name=\"Face\" style=\"position:absolute;top:0px;left:0;height:' + a + ';width:' + a + ';text-align:center\">' + props + Face[i] + '</span></div>';\n }\n \n $('Of').children[0].innerHTML = html;\n // Hours wrapper\n html = '';\n \n for (i = 0; i < H.length; i++)\n {\n html += '<div class=\"Hours\" name=\"Hours\" style=\"position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:' + hCol + ';text-align:center;font-weight:bold\">' + H[i] + '</div>';\n } \n \n $('Oh').children[0].innerHTML = html;\n // Minute wrapper\n \n html = '';\n \n for (i = 0; i < M.length; i++)\n \n {\n \n html += '<div class=\"Minutes\" name=\"Minutes\" style=\"position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:' + mCol + ';text-align:center;font-weight:bold\">' + M[i] + '</div>';\n \n } \n \n $('Om').children[0].innerHTML = html;\n \n \n \n // Seconds wrapper\n \n html = '';\n \n for (i = 0; i < S.length; i++)\n \n {\n \n html += '<div class=\"Seconds\" name=\"Seconds\" style=\"position:absolute;width:16px;height:16px;font-family:Arial;font-size:16px;color:' + sCol + ';text-align:center;font-weight:bold\">' + S[i] + '</div>';\n \n } \n \n $('Os').children[0].innerHTML = html;\n \n \n \n // Mouse move event handler\n \n \n function Mouse(evnt) \n \n {\n \n if (typeof evnt === 'undefined')\n \n {\n \n ymouse = event.Y + ClockFromMouseY;\n \n xmouse = event.X + ClockFromMouseX;\n \n }\n else\n {\n ymouse = evnt.clientY + ClockFromMouseY;\n xmouse = evnt.clientX + ClockFromMouseX;\n }\n }\n \n document.onmousemove = Mouse;\n \n function ClockAndAssign() \n \n {\n var time = new Date();\n var secs = time.getSeconds();\n var sec = -1.57 + Math.PI * secs / 30;\n var mins = time.getMinutes();\n var min = -1.57 + Math.PI * mins / 30;\n var hr = time.getHours();\n var hrs = -1.575 + Math.PI * hr / 6 + Math.PI * parseInt(time.getMinutes(), 10) / 360;\n \n $('Od').style.top = window.document.body.scrollTop;\n $('Of').style.top = window.document.body.scrollTop;\n $('Oh').style.top = window.document.body.scrollTop;\n $('Om').style.top = window.document.body.scrollTop;\n $('Os').style.top = window.document.body.scrollTop;\n \n for (i = 0; i < n; i++)\n {\n var F = $$('Face')[i];\n F.style.top = y[i] + ClockHeight * Math.sin(-1.0471 + i * Split * Math.PI / 180) + scrll;\n F.style.left = x[i] + ClockWidth * Math.cos(-1.0471 + i * Split * Math.PI / 180);\n }\n \n for (i = 0; i < H.length; i++)\n {\n var HL = $$('Hours')[i];\n HL.style.top = y[i] + HandY + (i * HandHeight) * Math.sin(hrs) + scrll;\n HL.style.left = x[i] + HandX + (i * HandWidth) * Math.cos(hrs);\n }\n \n for (i = 0; i < M.length; i++)\n {\n var ML = $$('Minutes')[i].style;\n ML.top = y[i] + HandY + (i * HandHeight) * Math.sin(min) + scrll;\n ML.left = x[i] + HandX + (i * HandWidth) * Math.cos(min);\n }\n \n for (i = 0; i < S.length; i++)\n {\n var SL = $$('Seconds')[i].style;\n SL.top = y[i] + HandY + (i * HandHeight) * Math.sin(sec) + scrll;\n SL.left = x[i] + HandX + (i * HandWidth) * Math.cos(sec);\n }\n \n for (i = 0; i < D.length; i++)\n {\n var DL = $$('Date')[i].style;\n DL.top = Dy[i] + ClockHeight * 1.5 * Math.sin(currStep + i * Dsplit * Math.PI / 180) + scrll;\n DL.left = Dx[i] + ClockWidth * 1.5 * Math.cos(currStep + i * Dsplit * Math.PI / 180);\n }\n currStep -= step;\n }\n \n function Delay() \n {\n scrll = 0;\n Dy[0] = Math.round(DY[0] += ((ymouse) - DY[0]) * speed);\n Dx[0] = Math.round(DX[0] += ((xmouse) - DX[0]) * speed);\n for (i = 1; i < D.length; i++) {\n Dy[i] = Math.round(DY[i] += (Dy[i - 1] - DY[i]) * speed);\n Dx[i] = Math.round(DX[i] += (Dx[i - 1] - DX[i]) * speed);\n }\n y[0] = Math.round(Y[0] += ((ymouse) - Y[0]) * speed);\n x[0] = Math.round(X[0] += ((xmouse) - X[0]) * speed);\n for (i = 1; i < n; i++) {\n y[i] = Math.round(Y[i] += (y[i - 1] - Y[i]) * speed);\n x[i] = Math.round(X[i] += (x[i - 1] - X[i]) * speed);\n }\n ClockAndAssign();\n setTimeout(Delay, 20);\n }\n \n Delay();\n }());\n </script>\n \n <script type=\"text/javascript\">\n \"use strict\";\n var clock_parts = [Od, Of, Oh, Om, Os];\n var clock_part_setters = [date_setter, face_setter, hour_setter, minute_setter, second_setter];\n \n function for_each(array,func){Array.prototype.forEach.call(array,func);}\n \n function get_theme(event){return event.target.options[event.target.selectedIndex].dataset.theme;\n }\n \n function select_option(select_elm,theme){select_elm.dataset.theme = theme;\n // IE hack\n select_elm.className = select_elm.className;\n for_each(select_elm.options, function(option_elm){\n if(option_elm.dataset.theme == theme){\n option_elm.selected = true;\n }\n });\n }\n \n function set_theme(elms,theme){\n for_each(elms, function(elm){\n elm.dataset.theme = theme;\n // IE hack\n elm.className = elm.className;\n });\n // update clock_part_setters\n for_each(clock_parts,function(part,i){\n select_option(clock_part_setters[i],part.dataset.theme);\n });\n // update clock_setter\n var is_same_theme = clock_parts.every(function(part){\n return part.dataset.theme == clock_parts[0].dataset.theme;\n });\n if(is_same_theme){\n clock_setter_none.hidden = true;\n select_option(clock_setter,clock_parts[0].dataset.theme);\n }\n else{\n clock_setter_none.hidden = false;\n select_option(clock_setter,\"white\");\n }\n }\n function match_theme(){\n var theme_table = {\n // back_theme: \"clock_theme\",\n black: \"silver\",\n blue: \"black\",\n silver: \"blue\",\n \n };\n set_theme(clock_parts, theme_table[back.dataset.theme]);\n }\n </script>\n </body>\n </html>\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T14:45:07.570", "favorite_count": 0, "id": "17733", "last_activity_date": "2015-10-17T14:16:27.753", "last_edit_date": "2015-10-17T14:16:27.753", "last_editor_user_id": "3054", "owner_user_id": "9359", "post_type": "question", "score": 2, "tags": [ "javascript", "html" ], "title": "同じ属性が設定されている要素に、スタイルシートで別のスタイルを設定するには?", "view_count": 162 }
[ { "body": "例えば、 \n「id が \"clock\" の要素の子孫で \"data-theme\" 属性の値が \"black\" の要素」 \nを選択する CSSセレクタは `#clock [data-theme=\"black\"]` のように書けます。 \nこれを利用して以下のように時計部分の color を特別に指定するとよいでしょう。 \n(もし、background-color の指定もするならば、このプロパティが子孫に継承されない事も考慮する必要があります)\n\n```\n\n /* 時計 */\n #clock [data-theme=\"black\"] { color: black; }\n #clock [data-theme=\"blue\"] { color: blue; }\n #clock [data-theme=\"silver\"] { color: silver; }\n #clock [data-theme=\"white\"] { color: white; }\n \n [data-theme=\"black\"]{ color: white; background-color: black; }\n [data-theme=\"blue\"]{ color: white; background-color: blue; }\n [data-theme=\"silver\"]{ color: black; background-color: silver; }\n [data-theme=\"white\"]{ color: black; background-color: white; }\n \n```\n\nもちろん、ボタンの方の color を指定してもいいですし、いろいろやり方はあると思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-16T16:44:17.400", "id": "17735", "last_activity_date": "2015-10-16T16:44:17.400", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "17733", "post_type": "answer", "score": 1 } ]
17733
17735
17735
{ "accepted_answer_id": null, "answer_count": 1, "body": "フォント名からフォントファイル名(*.ttf)を取得したいと考えています。 \n例:Times New Roman → times.ttf\n\n(ここでのフォント名とは、LOGFONT 構造体の lfFaceName で取得できる名前のことです。)\n\n下記の内容を参考に、レジストリの \nHKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts \nを参照することを試みています。\n\n参考:<https://stackoverflow.com/questions/11387564/get-a-font-filepath-from-\nname-and-style-in-c-windows>\n\n一般的に、英語のフォントであれば lfFaceNameとレジストリに格納されているフォント名が一致するので問題ないのですが、日本語フォントの場合は\nlfFaceName が日本語で(例:メイリオ)、レジストリで使われているフォント名が英語(例:Meiryo )であったりして、一致しません。\n\n問題解決のために、lfFaceName で得られる日本語フォント名から、英語のフォント名を取得する方法をお教えいただければ幸いです。\n\n英語のフォント名を取得することが目的ではなくて、フォントファイル名(*.ttf)を取得することが本来の目的ですので、まったく異なる方法で達成できるのでしたら、その方法をお教えいただければ幸いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T03:38:04.303", "favorite_count": 0, "id": "17741", "last_activity_date": "2015-10-18T13:54:36.870", "last_edit_date": "2017-05-23T12:38:56.083", "last_editor_user_id": "-1", "owner_user_id": "12817", "post_type": "question", "score": 9, "tags": [ "c++", "windows", "font" ], "title": "フォント名からフォントファイル名(*.ttf) を取得するには?(C++ / Windows)", "view_count": 6152 }
[ { "body": "ファイル名を取得する方法は分かりませんので、英語の名前を取得する方法を回答します。\n\nGDI+の[FontFamily.GetFamilyName](https://msdn.microsoft.com/en-\nus/library/windows/desktop/ms536177.aspx)を使用すると、他の言語での名称を取得できます。言語IDを指定する仮引数があるので、英語なら`MAKELANGID(LANG_ENGLISH,\nSUBLANG_ENGLISH_US)`を渡すと良いです。\n\n```\n\n #include <iostream>\n #include <windows.h>\n #include <gdiplus.h>\n \n using namespace std;\n \n int main()\n {\n std::wcout.imbue(std::locale(\"\"));\n \n Gdiplus::GdiplusStartupInput gdiplusStartupInput;\n ULONG_PTR gdiplusToken;\n Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);\n \n Gdiplus::FontFamily f(L\"メイリオ\");\n \n WCHAR name[LF_FACESIZE]{};\n f.GetFamilyName(name, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));\n wcout << name << endl;\n \n //Gdiplus::GdiplusShutdown(gdiplusToken);\n }\n \n```\n\nこのプログラムを実行すると、`Meiryo`という出力が得られます。\n\nただし、この方法にも1つ問題があります。日本語環境で`L\"微软雅黑\"`(Microsoft YaHeiの中国語簡体字表記)を指定しても、Microsoft\nYaHeiになりません。そのように、使用中の言語以外ではうまくいかないようです。このあたりをなんとかする方法はちょっと分かりませんでした。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T13:49:28.207", "id": "17779", "last_activity_date": "2015-10-18T13:54:36.870", "last_edit_date": "2015-10-18T13:54:36.870", "last_editor_user_id": "8616", "owner_user_id": "8616", "parent_id": "17741", "post_type": "answer", "score": 5 } ]
17741
null
17779
{ "accepted_answer_id": "24610", "answer_count": 1, "body": "WebAudioAPIを用いてAudio要素をJavaScriptで制御しています。\n\n長時間のmp3ファイルのうち、1000秒〜1100秒までを再生させたいとします。1000秒から再生を開始するのはcurrentTimeを指定することで実現できました。\n\nしかし、再生を開始するとmp3の先頭からロードが始まり、1000秒地点までロードが到達するまで待機時間が発生します。この待機時間をなくすために任意の範囲だけ(この場合だと1000秒〜1100秒の範囲)ロードさせるようにしたいと考えています。\n\nrangeリクエストで取得するbytesの範囲を指定できれば実現可能ではないかと調べてみたのですが、WebAudioAPIでrangeリクエストをコントロールする方法を見るけることができませんでした。\n\n何か良い方法を知っている方、よろしくお願いいたします。\n\n```\n\n var audioCtx = new (window.AudioContext || window.webkitAudioContext)();\r\n var myAudio = document.querySelector('audio');\r\n var source = audioCtx.createMediaElementSource(myAudio);\r\n \r\n source.connect(audioCtx.destination);\r\n \r\n source.mediaElement.addEventListener(\"play\", function() {\r\n source.mediaElement.currentTime = 1000; // ロードも1000秒地点から開始させたい\r\n });\n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T04:44:15.727", "favorite_count": 0, "id": "17744", "last_activity_date": "2016-05-06T14:48:39.367", "last_edit_date": "2015-10-17T04:51:39.740", "last_editor_user_id": "3968", "owner_user_id": "3968", "post_type": "question", "score": 3, "tags": [ "javascript" ], "title": "WebAudioAPIでmp3の任意の範囲だけロードさせたい", "view_count": 296 }
[ { "body": "すこし前の質問ですが回答させてもらいます。\n\n先頭から読み出しが開始されるのは、`<audio>`のDOMプロパティ`preload`が既定で`auto`になっているためです。この結果、ブラウザは自動的にソースを読み込んで再生準備をはじめてしまいます。まずはこれを無効化するために、`preload=\"none\";`を設定します。続いて`currentTime`を設定しておけば、再生ボタンを押したとき、この部分から再生できると思います。\n\nこの様子は`buffered`プロパティを参照して確認できます。現在どこからどこまでを読み込んだかを示すもので、私の環境では`currentTime`に設定した時刻付近から読み込みが開始されることが確認できました。 \nブラウザの挙動の差異やネットワークの状態で状況が変わるかもしれませんが、参考になれば幸いです。\n\n以下、動作テストに使用したものを載せておきます。すこし大きめの音声ファイルを`src`に設定して、これの真ん中の時刻から再生を開始するものです。\n\n```\n\n var inputUrl = document.querySelector('#inputUrl');\r\n var setUrl = document.querySelector('#setUrl');\r\n var player = document.querySelector('#player');\r\n var showBuffRange = document.querySelector('#showBuffRange');\r\n var log = document.querySelector('#log');\r\n \r\n var localLogging = function () {\r\n log.innerHTML += [].join.call(arguments, ' ') + '<br />';\r\n };\r\n \r\n // sample big audio file\r\n // thanks http://www.ee.columbia.edu/~dpwe/sounds/music/\r\n inputUrl.value = 'http://www.ee.columbia.edu/~dpwe/sounds/music/temple_of_love-sisters_of_mercy.wav';\r\n \r\n \r\n // disable preloading\r\n player.preload = 'none';\r\n \r\n player.addEventListener('loadedmetadata', function () {\r\n // set position to start\r\n player.currentTime = player.duration * 0.5;\r\n localLogging('set currentTime = ' + player.currentTime);\r\n \r\n // play, if you want\r\n player.play();\r\n localLogging('play');\r\n });\r\n \r\n // set src property\r\n setUrl.addEventListener('click', function () {\r\n player.src = inputUrl.value;\r\n localLogging('set src = ' + player.src);\r\n });\r\n \r\n // show buffered range\r\n var update = function () {\r\n try {\r\n showBuffRange.textContent = 'buffered: from ' + player.buffered.start(0) + 's to ' + player.buffered.end(0) + 's';\r\n } catch (e) {\r\n showBuffRange.textContent = 'buffered: none';\r\n }\r\n setTimeout(update, 500);\r\n };\r\n \r\n update();\n```\n\n```\n\n url: <input id=\"inputUrl\" type=\"text\" />\r\n <input id=\"setUrl\" type=\"button\" value=\"set to player.src\" />\r\n <audio id=\"player\" controls></audio>\r\n \r\n <div id=\"showBuffRange\">bufferd:</div>\r\n <div id=\"log\" />\n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-05-06T14:48:39.367", "id": "24610", "last_activity_date": "2016-05-06T14:48:39.367", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "17744", "post_type": "answer", "score": 2 } ]
17744
24610
24610
{ "accepted_answer_id": null, "answer_count": 0, "body": "CakePHP2.6を使用しています。\n\nquery()で実行するSQLにlimit句がありその値をバインド変数で可変にしたいと考えています。\n\n```\n\n limit :limit\n \n```\n\nとし、\n\n```\n\n $this->query($sql, ['limit' => 1], false);\n \n```\n\nと値をセットして実行するとlimit句に文字列の1が入ってしまいエラーとなります。\n\nPDOならbindValueの引数にPDO::PARAM_INTを設定して解消出来るようですが \nCakephpだとDboSource::_execute()内でexecute()が実行されるまでにそれが設定出来るような箇所は無いように見えます。\n\nCakePHPでlimit句に値を指定する方法はあるのでしょうか\n\n追記 \n?を使った方法でも同様のエラーとなります。\n\n```\n\n LIMIT ?\n \n```\n\n```\n\n $this->query($sql, [1], false);\n \n```\n\nまたエラーメッセージは以下のとおりです。\n\nError: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an\nerror in your SQL syntax; check the manual that corresponds to your MySQL\nserver version for the right syntax to use near ''1'' at line 12", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T05:56:06.617", "favorite_count": 0, "id": "17745", "last_activity_date": "2015-10-17T07:24:30.290", "last_edit_date": "2015-10-17T07:24:30.290", "last_editor_user_id": "11050", "owner_user_id": "11050", "post_type": "question", "score": 4, "tags": [ "cakephp" ], "title": "CakePHPのquery()でlimitにバインド変数を使いたい", "view_count": 966 }
[]
17745
null
null
{ "accepted_answer_id": "17839", "answer_count": 1, "body": "現在、IIS7 + ASP.NET(VB) にて、次のように記述しています。\n\n```\n\n <%\n if request = page1\n %><!-- #INCLUDE file=\"page1.inc\" --><%\n else if request = page2\n %><!-- #INCLUDE file=\"page2.inc\" --><%\n else\n %><!-- #INCLUDE file=\"default.inc\" --><%\n end if\n %>\n \n```\n\nしかし、これでは一度全てのpage*.incが読み込まれるものと思っています。それはとてもナンセンスだと思います。(ifで分岐もナンセンスではありますが・・・) \n例えば、Perlだと次のような記述が出来ます。\n\n```\n\n my $request = 'page' . $num . '.pl';\n require $request;\n \n```\n\n(勿論上記の書き方には脆弱性があるのでそのままは使いませんが、例えば、です。) \nVB.NET?にはこのように、特定のものだけを読み込むような手法はありますでしょうか? \nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T06:47:24.187", "favorite_count": 0, "id": "17746", "last_activity_date": "2021-10-30T21:15:18.237", "last_edit_date": "2021-10-30T21:15:18.237", "last_editor_user_id": "4236", "owner_user_id": "8667", "post_type": "question", "score": 1, "tags": [ "asp.net", "vb.net" ], "title": "条件によって読み込むファイルを切り替えるには", "view_count": 739 }
[ { "body": "ASP.NET(.aspx)は初回(厳密にはアプリケーションプールのライフサイクル内での初回…だったはず)リクエスト時に自動的にコンパイルされます。(初回のレスポンスが遅いのはこのためです) \n2回目以降はコンパイル済みのもので処理されるのですべてが読み込まれている必要があります。\n\nロジックで読み込むものを切り替える場合は、sample1.aspx, sample2.aspx,…\nとして条件によりServer.Transfer()する事もできます。(こちらの方が各ページの管理・編集が楽かも)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T05:19:50.390", "id": "17839", "last_activity_date": "2015-10-20T05:19:50.390", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7343", "parent_id": "17746", "post_type": "answer", "score": 1 } ]
17746
17839
17839
{ "accepted_answer_id": "17818", "answer_count": 1, "body": "画面遷移の際の\n\n```\n\n classViewController.records = [[LessonManager sharedManager].lessons[self.collectionView.indexPathsForSelectedItems]records];\n \n```\n\nで\n\n```\n\n Expected method to read dictionary element not found on object of type NSMutableArray\n \n```\n\nと警告が発生します 印はLessonManagerのところについています。\n\nどのように直せばいいのでしょうか。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T07:02:18.477", "favorite_count": 0, "id": "17747", "last_activity_date": "2015-10-19T10:59:37.237", "last_edit_date": "2015-10-17T11:54:06.453", "last_editor_user_id": "5519", "owner_user_id": "8802", "post_type": "question", "score": 1, "tags": [ "objective-c", "iphone" ], "title": "Expected method to read dictionary element not found on object of type NSMutableArrayの警告が出ます。", "view_count": 524 }
[ { "body": "`UICollectionView`の`- (NSArray\n*)indexPathsForSelectedItems;`は`NSArray`を返します(複数セルの選択に対応している)。`NSArray`なのでそのままでは`lessons`プロパティの添え字として利用できません。\n\nコレクションビューで複数選択を禁止しているなら中身は空か1つだけ入ってるかのどちらかなので、`firstObject`メソッドなどで配列から取り出して、空でなければ添え字として利用する、といった処理になると思います。\n\n```\n\n NSIndexPath *selectedIndexPath = self.collectionView.indexPathsForSelectedItems.firstObject;\n if (selectedIndexPath) {\n classViewController.records = [[LessonManager sharedManager].lessons[selectedIndexPath.item] records];\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T10:59:37.237", "id": "17818", "last_activity_date": "2015-10-19T10:59:37.237", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "17747", "post_type": "answer", "score": 0 } ]
17747
17818
17818
{ "accepted_answer_id": "18023", "answer_count": 1, "body": "このプログラムでのエラーを治していただける方、お願いします。\n\n```\n\n package a.a;\n \n import android.app.Activity;\n import android.os.Bundle;\n import android.view.Menu;\n import android.view.MenuItem;\n public class A extends Activity {\n \n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_a);\n }\n \n @Override\n public boolean onCreateOptionsMenu(Menu menu) {\n // Inflate the menu; this adds items to the action bar if it is present.\n getMenuInflater().inflate(R.menu.menu);\n return true;\n }\n \n @Override\n public boolean onOptionsItemSelected(MenuItem item) {\n // Handle action bar item clicks here. The action bar will\n // automatically handle clicks on the Home/Up button, so long\n // as you specify a parent activity in AndroidManifest.xml.\n int id = item.getItemId();\n if (id == R.id.action_settings) {\n return true;\n }\n return super.onOptionsItemSelected(item);\n }\n }\n \n```\n\nそして、エラーが、 \ngetMenuInflater().inflate(R.menu.menu); \nの行で、 \nこの行に複数マーカーがあります \n\\- menu は解決できないか、フィールド \nではありません \n\\- menu は解決できないか、フィールド \nではありません\n\nif (id == R.id.action_settings) { \nの行で \naction_settings は解決できないか、フィールドではありません\n\nというエラーが出ます。 \nR.javaの中にmenuという項目が無いからだと思い、追加したりしても元に戻ってしまいます。また、R.idの中にもやはりaction_settingsが無くて、どうしたら追加できるか、などが分からず四時間くらい格闘しています。どなたか解決できる方、教えてください。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T07:20:42.070", "favorite_count": 0, "id": "17748", "last_activity_date": "2015-10-24T11:47:12.070", "last_edit_date": "2015-10-17T10:04:49.037", "last_editor_user_id": "5044", "owner_user_id": "12819", "post_type": "question", "score": -2, "tags": [ "android", "java", "eclipse" ], "title": "R.javaの中身", "view_count": 1105 }
[ { "body": "R.javaはres配下の各種リソースファイルを元にビルド時に生成・上書きされるものなので \nおそらく、コメントにあるようにres/menu/menu.xmlを消してしまったものと思われます。\n\n上記ファイルなどに問題はないのに、R.javaに該当フィールドが無い場合は \nビルドが出来なくて、現状のリソース構成でR.javaが生成されないという状態かも知れません。 \nこの場合はビルドを無理矢理にでも通してしまえば良いので、 \nエラー箇所を全てコメントアウトして\n\n```\n\n public class A extends Activity {\n \n // @Override\n // protected void onCreate(Bundle savedInstanceState) {\n // super.onCreate(savedInstanceState);\n // setContentView(R.layout.activity_a);\n // }\n \n (中略)\n }\n \n```\n\nなどとして、一度ビルドを通してからコメントアウト箇所を元に戻してみると \nR.javaの中身が更新されてエラー箇所の赤線が消えたりしないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-24T11:47:12.070", "id": "18023", "last_activity_date": "2015-10-24T11:47:12.070", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12943", "parent_id": "17748", "post_type": "answer", "score": 0 } ]
17748
18023
18023
{ "accepted_answer_id": "17753", "answer_count": 1, "body": "iPhoneAからiPhoneBにメンバー変数の変化をリアルタイムに伝える方法で、 \nサーバーを介しない方法は何かありますか?\n\n例えば、iPhoneAでのXの値が、iPhoneBに瞬時に伝わるという事をやりたいのですが。\n\niPhoneAとiPhoneBの所有者は別で、iCloudアカウントが同一でない場合です。\n\niPhoneAとiPhoneBがBluetoothや同一のWi-Fiを共有できない \n長距離同士のやりとりをしたいです。\n\nLineアプリなどのように相手の端末を認証して、 \nそこからの通知を受け取りたいです。\n\nアドバイスよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T07:49:05.370", "favorite_count": 0, "id": "17749", "last_activity_date": "2015-10-19T00:52:34.737", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12297", "post_type": "question", "score": 2, "tags": [ "swift" ], "title": "複数のiPhone間でサーバーを介しないでメンバー変数の値を共有する方法はありますか?", "view_count": 986 }
[ { "body": "サーバを介しない通信を行いたいと言う事ですが、実現は出来ないかと思います。\n\n仮に条件を無視して考えると \nまず、遠隔と言う事でBluetoothは使用できません \nVPNを立てなければ同一のLAN環境を構築することは出来ないでしょう。\n\nでは、遠隔の方への通信はどうするかと言うとソケット通信で相手へ通信する訳です。 \nソケット通信と言うと\"TCP/IP\"で通信するので相手のIPを知る必要があります。 \nですが、ソケット通信で通信を行うにしてもIPは動的に変化します。 \n仮に固定したとしてもグローバルIPを固定するサービスを行わなくては実現できません。 \nでは、どうやって相手のIPを知ることが出来るのでしょうか?\n\nサーバにIPを保存するしか手はありません。\n\n自分たちで使用する分であれば自分でIPを確認し伝え合う事も出来るでしょうが、 \n恐らくそういう事ではないのですよね? \n例に挙げているLineのアプリですが、 \nLineもサーバは使用しています。 \n韓国に2台、アメリカ・日本に1台ずつの4台です。\n\n以上、私が知る限りでは方法はありません。 \n\n* * *\n\n \nあまり記述しても主題からそれてしまうので最低限知っておけばいいものとして\n\n```\n\n ・データベース(MySQLなど)\n ・サーバ側で使える言語(PHPなど)\n ・サーバとの通信方法の考察(HTTP通信でJSONを取得するなど)\n \n```\n\nこれだけあればサーバとデータの通信ができます。\n\n実現したい内容を察するに流れとして\n\n```\n\n 1.端末をサーバに接続し`独自のID`や`UUID`(作る必要はありますが)と紐づけ\n 2.端末起動中は定期的に通信し、起動中の旨を保存\n ※呼び出し側\n 1.クライアント側でユーザリストなんか作って選択\n 2.自分のIPをサーバに保存、呼び出し\n 3.相手側の応答後、相手のIPを取得する\n 4.ソケット通信\n ※受け付け側\n 1.未起動時の場合、PUSH通知\n 2.起動している際にサーバに紐づけているIP更新\n 3.ソケット受信待機\n \n```\n\nこんな感じでしょうか? \n細かいことを言えばキリがないですが、 \nサーバに高い負荷をかけるならサーバ構築の技術も必要です。 \nインフラ関係の技術は得意分野ではないですが、 \nテスト環境だけならLINUXとか無料ですし、VM使うなりで練習してはいかがでしょうか?", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T09:12:01.337", "id": "17753", "last_activity_date": "2015-10-19T00:52:34.737", "last_edit_date": "2015-10-19T00:52:34.737", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "17749", "post_type": "answer", "score": 4 } ]
17749
17753
17753
{ "accepted_answer_id": null, "answer_count": 0, "body": "MobileSingleStickControlを使って仮想ボタンでのジャンプボタンを作ったのですが、ボタンが押されたことを一回目だけ取るのですが二回目以降ボタンが全く反応しなくなってしまいます。 \n`Debug.Log (\"update\");`はコンソールで呼ばれ続けているのに、 \n`Debug.Log (\"Input.getButtonDown jump\");` 1回 \n`Debug.Log(\"jump true\");` 1回 \n`Debug.Log (\"jump false\");` 11回 \nのように表示され、ボタンが押されたということを二度と受け取らなくなってしまいます。 \nどのようにすれば ボタンとして動かすことが出来るのでしょうか\n\n[ButtonHandler.cs] \n\n```\n\n using System;\n using UnityEngine;\n \n namespace UnityStandardAssets.CrossPlatformInput\n {\n public class ButtonHandler : MonoBehaviour\n {\n \n public string Name;\n \n void OnEnable()\n {\n \n }\n \n public void SetDownState()\n {\n CrossPlatformInputManager.SetButtonDown(Name);\n }\n \n \n public void SetUpState()\n {\n CrossPlatformInputManager.SetButtonUp(Name);\n }\n \n \n public void SetAxisPositiveState()\n {\n CrossPlatformInputManager.SetAxisPositive(Name);\n }\n \n \n public void SetAxisNeutralState()\n {\n CrossPlatformInputManager.SetAxisZero(Name);\n }\n \n \n public void SetAxisNegativeState()\n {\n CrossPlatformInputManager.SetAxisNegative(Name);\n }\n \n public void Update()\n {\n Debug.Log (\"update\");\n if (UnityStandardAssets.CrossPlatformInput.CrossPlatformInputManager.GetButtonDown(\"Jump\"))\n {\n Debug.Log (\"Input.getButtonDown jump\");\n }\n }\n }\n }\n \n```\n\n[Jump.js] \n\n```\n\n #pragma strict\n \n function Start () {\n \n }\n \n function Update () {\n var myAnimator=GetComponent(Animator);\n if (UnityStandardAssets.CrossPlatformInput.CrossPlatformInputManager.GetButtonDown(\"Jump\"))\n {\n myAnimator.SetBool(\"Jump\",true);\n Debug.Log(\"jump true\");\n }\n \n \n var state:AnimatorStateInfo=myAnimator.GetCurrentAnimatorStateInfo(0);\n if(state.IsName(\"Locomotion.Jump\"))\n {\n myAnimator.SetBool(\"Jump\",false);\n Debug.Log (\"jump false\");\n }\n }\n \n```\n\n[![コンソール画面](https://i.stack.imgur.com/YQ2PO.png)](https://i.stack.imgur.com/YQ2PO.png)\n\n[![Hierarchy](https://i.stack.imgur.com/Mm9EE.png)](https://i.stack.imgur.com/Mm9EE.png)\n\n[![unity-\nchan](https://i.stack.imgur.com/RwTWt.png)](https://i.stack.imgur.com/RwTWt.png)", "comment_count": 10, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T08:41:30.023", "favorite_count": 0, "id": "17751", "last_activity_date": "2015-10-18T17:14:17.873", "last_edit_date": "2015-10-18T17:14:17.873", "last_editor_user_id": "12716", "owner_user_id": "12716", "post_type": "question", "score": 1, "tags": [ "unity3d" ], "title": "GUIボタンが押せないのですが", "view_count": 708 }
[]
17751
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "画像の直リンクをNginx\nで拒否したいと思います。valid_refererを使った自ドメイン以外のリファラーを拒否する方法のチュートリアルは結構ありますが、指定ドメインで直リンクを拒否する方法がわかりません。invalid_refererというもので同様のことができるのでしょうか。\n\n```\n\n location ~ .(gif|png|jpe?g)$ {\n invalid_referer none blocked ~*badsite.com;\n if ($invalid_referer) {\n return 403;\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T08:57:25.510", "favorite_count": 0, "id": "17752", "last_activity_date": "2015-11-19T05:37:22.343", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4596", "post_type": "question", "score": 2, "tags": [ "nginx" ], "title": "Nginx で直リンク拒否ドメインを指定", "view_count": 714 }
[ { "body": "`$invalid_referer` 変数は `valid_referers` ディレクティブによって設定されるもののようですが、私は\n`valid_referers` ディレクティブで否定の正規表現がうまく設定できませんで、代替案としてこんな感じで `map`\nを使って実装できそうですがいかがでしょう?\n\n```\n\n map $http_referer $block_by_referer {\n ~^https?://bad.example.com/ 1;\n default 0;\n }\n ...\n location ~ \\.(gif|png|jpe?g)$ {\n if ($block_by_referer) {\n return 403;\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T05:16:52.763", "id": "17838", "last_activity_date": "2015-10-20T05:16:52.763", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5530", "parent_id": "17752", "post_type": "answer", "score": 2 } ]
17752
null
17838
{ "accepted_answer_id": null, "answer_count": 0, "body": "例えば以下の対角行列でm(0, 0), m(1, 1), m(2, 2), m(3, 3)のみを取得したいです。 \n要素の取得時に、その要素の行数と列数も取得したい場合はどうすればいいのでしょうか。\n\n```\n\n boost::numeric::ublas::compressed_matrix<double> m(4, 4);\n m(0, 0) = 1;\n m(1, 1) = 2;\n m(2, 2) = 3;\n m(3, 3) = 4;\n for(auto i = m.begin1(); i != m.end1(); ++i){\n std::cout << *i << std::endl;\n }\n \n```\n\n処理時間の無駄だと思うので、次の様な全ての要素をiterateする実装は避けたいです。\n\n```\n\n for(int i = 0; i < m.size1(); ++i){\n for(int j = 0; j < m.size2(); ++j){\n if(m(j, i) == 0){ continue; }\n std::cout << m(j, i) << std::endl;\n }\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T11:49:47.703", "favorite_count": 0, "id": "17755", "last_activity_date": "2015-10-17T11:49:47.703", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12825", "post_type": "question", "score": 1, "tags": [ "c++", "boost" ], "title": "Boost.ublasのcompressed_matrixで存在する要素の行数と列数を得ながら全てiterateしたい", "view_count": 186 }
[]
17755
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "CakePHP Ver. 2.5.8 を利用しています。\n\n公式のチュートリアルに沿って「[シンプルな認証と承認のアプリケーション](http://book.cakephp.org/2.0/ja/tutorials-\nand-examples/blog-auth-example/auth.html)」をやってみました。\n\nしかし、`FlashHelper` が、ないとエラーがでます。\n\n```\n\n Missing Helper\n Error: FlashHelper could not be found.\n \n Error: Create the class FlashHelper below in file: app/View/Helper/FlashHelper.php \n \n <?php\n class FlashHelper extends AppHelper {\n \n }\n \n```\n\nこのように、エラーがでます。\n\n`app/View/Helper` のディレクトリまで移動して `ls` してみても \n`AppHelper.php` しかありません。\n\n`lib/Controller/Component` の中には `FlashHelper.php` があります。\n\nこれはどう解釈したらいいのでしょうか。。。\n\n質問の内容が不十分かもしれませんが、ヘルパーとコンポーネントまわりについて理解が足りていないのかもしれません。\n\nご回答お待ちしております。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T16:24:17.037", "favorite_count": 0, "id": "17757", "last_activity_date": "2015-10-18T09:45:53.157", "last_edit_date": "2015-10-18T09:34:33.657", "last_editor_user_id": "8000", "owner_user_id": "10741", "post_type": "question", "score": 0, "tags": [ "php", "cakephp" ], "title": "Error: FlashHelper could not be found. と表示される", "view_count": 1472 }
[ { "body": "FlashComponent や FlashHelper が追加されたのは CakePHP 2.7 からのようです。\n\n> ## CakePHP 2.7.0 がリリースされました\n>\n> ### 非推奨\n>\n> * SessionComponent::setFlash() は非推奨になった。代わりに FlashComponent を使用する\n> * SessionHelper::flash() は非推奨になった。代わりに FlashHelper を使用する\n>\n\n>\n> \\--- <http://bakery.cakephp-users.jp/2015/07/14/cakephp_2_7_0_released/>\n> より引用\n\nそれ以前のバージョンでは上記のように SessionComponent と SessionHelper\nを使うようですが、このあたりの説明はセッションコンポーネントのマニュアルに書かれています。\n\n[セッション — CakePHP Cookbook 2.x ドキュメント >\n通知メッセージの作成](http://book.cakephp.org/2.0/ja/core-\nlibraries/components/sessions.html#creating-notification-messages)\n\n* * *\n\n> app/View/Helper のディレクトリまで移動して ls してみても AppHelper.php しかありません。\n\nコンポーネントやヘルパは CakePHP 付属のもの以外にもユーザーが作成することができます。この自分で作った(アプリケーション独自の)ものを置く場所が\n`app/` 以下なので、そこに `AppHelper.php` しかないのは特におかしなことではありません。本来あるべき場所は `lib/` の方です。\n\n実際 Github で CakePHP 2.7.0 のファイルツリーを見てみると、\n\n * [`lib/Cake/Controller/Component/FlashComponent.php`](https://github.com/cakephp/cakephp/blob/2.7.0/lib/Cake/Controller/Component/FlashComponent.php)\n * [`lib/Cake/View/Helper/FlashHelper.php`](https://github.com/cakephp/cakephp/blob/2.7.0/lib/Cake/View/Helper/FlashHelper.php)\n\nというファイルが存在します。なのでむしろ\n\n> lib/Controller/Component の中には FlashHelper.php があります。\n\nこっちの方が謎です。 2.5.8 のツリーに FlashHelper.php というファイルは見当たらないのですが・・・。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T09:33:49.487", "id": "17769", "last_activity_date": "2015-10-18T09:45:53.157", "last_edit_date": "2015-10-18T09:45:53.157", "last_editor_user_id": "8000", "owner_user_id": "8000", "parent_id": "17757", "post_type": "answer", "score": 2 } ]
17757
null
17769
{ "accepted_answer_id": "17820", "answer_count": 2, "body": "はじめまして、よろしくお願い申し上げます。\n\n以下質問となるので、お答えいただければ幸いです。\n\n例えばなのですが、15枚の絵札から5枚のカードを引くプログラムを書いてください. \nといった問題をRuby言語で学習する場合に適した書籍、サイトなどあるのでしょうか??\n\n上記のようなテスト行い、基準点に達することができず、アルゴリズムの学習をよりしなければと強く思いググっみたのですが、あまり適したサイトを見つけることができなかった為、こちらで質問させていただきます。\n\nできればRubyの言語でアルゴリズムの学習ができればと考えております。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-17T20:19:03.600", "favorite_count": 0, "id": "17758", "last_activity_date": "2015-10-19T12:21:48.773", "last_edit_date": "2015-10-18T00:19:43.277", "last_editor_user_id": "85", "owner_user_id": "10491", "post_type": "question", "score": 1, "tags": [ "ruby", "アルゴリズム" ], "title": "Rubyでアルゴリズムを学ぶのに適した書籍やサイトを教えてください", "view_count": 3751 }
[ { "body": "範囲が広すぎないしは主観的のクローズモデ対象になりそうな内容ですが・・・\n\nアルゴリズムとは「計算方法」であるため、言語によらず共通なものです。 \n「アルゴリズム解説本」というのを必要とする読者は、言語を問わないので多そうですが \n「アルゴリズムを Ruby で解く本」はごく限られた読者にしか必要とされない、 \nとオイラは思うわけです。 \n購読層のパイが明らかに小さそうな本は最初から出版されません。無いものねだりな気がします。\n\nあと、書籍にせよ web page にせよ、各個人に向いてる向いてないが必ずあります。 \nオイラにとってわかりやすかった書籍が、他の人にもわかりやすいかと問われれば No です。\n\n雑談系掲示板でも「私にとってわかりやすい書籍を紹介してください」だと盛り上がりません。 \n「あなた自身にとってわかりやすかった書籍を勝手に紹介してください」ならば盛り上がるでしょう。 \nでもどちらの質問も SO 的には NG です。\n\n(目的)なにか解きたい問題があって、 \n(手段)それを解く計算方法を算出する・理解する \nのなら良いのですが、目的と手段が逆転していませんか? \nその辺を間違えるとただの「お勉強のためのお勉強」となってつまらないこと必至です。 \nアルゴリズムなんて、必要になったときに検索して見つけりゃ十分です。\n\nSO においては「答えの無い・出しようの無い質問」はあまり好まれません。 \n提示の例題を実装しようとして、こんなふうに考えたが、こんな感じでうまくいかない、 \nどう改善すればいいでしょうか?という質問なら SO の rubyist たちが突っ込んでくれるでしょう。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T07:05:34.893", "id": "17807", "last_activity_date": "2015-10-19T07:05:34.893", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "17758", "post_type": "answer", "score": 2 }, { "body": "アルゴリズムを学ぶのに適した書籍はたくさんあるのですが、 \nとりわけRubyでと指定されると少ない気がします。 \nだからと言って、別の言語で解説している書籍をわざわざ \nRubyに置き換えるのも面倒なので、主にRubyで書かれた書籍を \n紹介します。\n\n「プログラマ脳を鍛える数学パズル シンプルで高速なコードが書けるようになる70問」 \n(<http://www.shoeisha.co.jp/book/detail/9784798142456>) \n→コードが載っているだけでなく、対話も交えているので読みやすいと思います。 \nまた、一問一問の量が多くないので、時間が空いている時にさっと読めます。\n\n(Rubyで書かれた書籍でアルゴリズムにも言及している書籍)\n\n「Ruby②」 \n(<http://www.shoeisha.co.jp/book/detail/9784798118000>) \n→第7章でアルゴリズムにふれています。\n\n「Rubyによる情報科学入門」 \n(<http://www.kindaikagaku.co.jp/information/kd0362.htm>) \n→題名からは分かりませんが、アルゴリズムの書籍と言えるのではないでしょうか? \n演習が豊富で、かなり数学寄りの書籍。\n\n(おまけ) \nその他の言語(C,C++,Javaが主)によるアルゴリズムに関する書籍 \n【基礎的なことが書いてある書籍】 \n②初心者向け \n「プログラミングの宝箱 アルゴリズムとデータ構造」 \n(<http://www.sbcr.jp/products/4797324198.html?sku=4797324198>) \n③中級者向け \n「アルゴリズムクイックリファレンス」 \n(<http://www.oreilly.co.jp/books/9784873114286/>) \n【プロコンっぽい書籍】 \n①超初心者向け \n「オンラインジャッジではじめるC/C++プログラミング入門」 \n(<https://book.mynavi.jp/ec/products/detail/id=25382>) \n③中級者向け \n「プログラミングコンテスト攻略のためのアルゴリズムとデータ構造」 \n(<https://book.mynavi.jp/ec/products/detail/id=35408>) \n「世界で闘うプログラミング力を鍛える150問 トップIT企業のプログラマになるための本」 \n(<https://book.mynavi.jp/ec/products/detail/id=22752>) \n「プログラミングコンテストチャレンジブック [第2版]」 \n(<https://book.mynavi.jp/ec/products/detail/id=22672>) \n「最強最速アルゴリズマー養成講座」 \n(<http://www.sbcr.jp/products/4797367171.html>) \n【パズル】 \n③中級者向け \n続ナノピコ教室 \n(<http://www.kyoritsu-pub.co.jp/bookdetail/9784320025417>)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T11:40:57.397", "id": "17820", "last_activity_date": "2015-10-19T12:21:48.773", "last_edit_date": "2015-10-19T12:21:48.773", "last_editor_user_id": "5363", "owner_user_id": "5363", "parent_id": "17758", "post_type": "answer", "score": 4 } ]
17758
17820
17820
{ "accepted_answer_id": "17762", "answer_count": 1, "body": "/subscribers/{imsi}/set_expiry_time を以下の条件で実行したときに New expiry date is before\nthe current time が発生します。パラメータの指定が悪いのでしょうか? \n※APIは、<https://dev.soracom.io/jp/docs/api/> から確認しております。\n\nURL: /subscribers/{imsi}/set_expiry_time \njson:\n\n```\n\n {\n \"expiryTime\": 1446336000 // 2015-11-01 00:00:00 +0000 UTC\n }\n \n```\n\nResponse Body\n\n```\n\n {\n \"code\": \"SEM0006\",\n \"message\": \"New expiry date is before the current time\"\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T03:56:33.180", "favorite_count": 0, "id": "17761", "last_activity_date": "2015-10-18T05:06:31.260", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7266", "post_type": "question", "score": 0, "tags": [ "soracom" ], "title": "/subscribers/{imsi}/set_expiry_time で New expiry date is before the current time が発生する", "view_count": 59 }
[ { "body": "expiryTimeの指定はミリ秒単位となります。 \nそのため、2015-11-01 00:00:00 +0000 UTC は 1446336000000 を指定下さい。\n\nAPIドキュメントにもミリ秒単位である旨、記載させていただきます。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T05:06:31.260", "id": "17762", "last_activity_date": "2015-10-18T05:06:31.260", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12626", "parent_id": "17761", "post_type": "answer", "score": 1 } ]
17761
17762
17762
{ "accepted_answer_id": null, "answer_count": 2, "body": "iOSからS3に画像をアップしたいです。本番環境はHerokuに置いてあり、画像だけをS3に保存したいです。開発はRailsで行っており、libraryはpaperclipを用いています。リンク先を参考にしましたが\"status\ncode: 500, headers\"というエラーが帰ってくる状況です。\n<https://devcenter.heroku.com/articles/paperclip-s3>\n\n未だ問題点の特定が出来ておりません。アドバイスあればご教示いただきたいです。\n\n```\n\n #terminal\n $heroku config:set S3_BUCKET_NAME=\"kenja.jp\"\n $heroku config:set AWS_ACCESS_KEY_ID=my_access_key_id\n $heroku config:set AWS_SECRET_ACCESS_KEY=my_secret_access_key\n \n #app/models/user.rb\n has_attached_file :photo, \n :styles => { medium: \"300x300>\", thumb: \"100x100>\" },\n :storage => :s3,\n :bucket => 'kenja.jp',\n :s3_permissions => :public,\n :url => \":s3_domain_url\",\n :path => \"/assets/photos/:id/:style/:basename.:extension\",\n :s3_host_name => \"s3-ap-northeast-1.amazonaws.com\",\n :s3_credentials => :\"#{Rails.root}/config/s3.yml\"\n \n \n #config/environments/staging.rb\n config.paperclip_defaults = {\n :storage => :s3,\n :s3_credentials => {\n :bucket => ENV['kenja.jp'],\n :access_key_id => ENV['my_access_key_id'],\n :secret_access_key => ENV['my_secret_access_key']\n }\n }\n \n \n #config/paperclip.rb\n Paperclip::Attachment.default_options[:url] = ':s3_domain_url'\n Paperclip::Attachment.default_options[:path] ='/:class/:attachment/:id/:style.:extenstion'\n Paperclip::Attachment.default_options[:s3_host_name] = 's3-ap-northeast-1.amazonaws.com'\n \n \n #app/apis/v1/users.rb\n params do \n requires :id, type:Integer\n requires :icon, type:Rack::Multipart::UploadedFile\n end\n post '/post_picture' do\n photo_file = ActionDispatch::Http::UploadedFile.new(params[:icon])\n @user = User.find(params[:id])\n @user.update(photo: photo_file)\n @user.photo\n end\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T05:26:46.097", "favorite_count": 0, "id": "17763", "last_activity_date": "2015-10-18T07:23:27.143", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "6098", "post_type": "question", "score": 1, "tags": [ "ios", "ruby-on-rails", "heroku", "amazon-s3" ], "title": "HerokuからS3に画像をアップできません。", "view_count": 607 }
[ { "body": "500エラーなのでサーバー側(Rails側)でなんらかのエラーが発生しているんだと思います。\n\nHerokuのサーバーログを見ると詳細なエラーメッセージやスタックトレースが載っているはずです。まずそれを確認してください。 \nエラーメッセージやスタックトレースをじっくり確認すれば、この問題も自己解決するかもしれません。 \n解決した場合は原因と解決策を自分で回答してください。\n\n解決しなければログの内容と、解決のために自分で試してみたことを追記してください。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T05:47:35.440", "id": "17764", "last_activity_date": "2015-10-18T05:47:35.440", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "parent_id": "17763", "post_type": "answer", "score": 3 }, { "body": "heroku logsで確認したところ以下のエラーが確認できました。\n\n```\n\n 2015-10-18T06:33:10.144859+00:00 app[web.1]: app/apis/v1/users.rb:112:in `block (2 levels) in <class:Users>'\n 2015-10-18T06:33:10.144858+00:00 app[web.1]: NameError (uninitialized constant Paperclip::Storage::S3::AWS):\n 2015-10-18T06:33:10.128265+00:00 app[web.1]: User Load (0.9ms) SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" = $1 LIMIT 1 [[\"id\", 15]]\n \n```\n\nリンク先を確認したところ、以下のようにすればよかったようです。\n\n```\n\n gem 'aws-sdk', '< 2.0'\n \n```\n\n<https://stackoverflow.com/questions/28374401/nameerror-uninitialized-\nconstant-paperclipstorages3aws>", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T07:23:27.143", "id": "17766", "last_activity_date": "2015-10-18T07:23:27.143", "last_edit_date": "2017-05-23T12:38:56.467", "last_editor_user_id": "-1", "owner_user_id": "6098", "parent_id": "17763", "post_type": "answer", "score": 1 } ]
17763
null
17764
{ "accepted_answer_id": null, "answer_count": 1, "body": "VagrantでCakePHPをComposerからインストールしてローカル開発環境を作成しようと思っていたところ、以下と同じ状況になってしまい\n\n[CakePHP cache was unable to write in Centos\n7](https://stackoverflow.com/questions/30412433/cakephp-cache-was-unable-to-\nwrite-in-centos-7) \n[AWSのEC2にCakePHP2.6を導入したのですがエラーが消えません。](https://teratail.com/questions/10268)\n\nファイルの権限を`chmod 777 -R temp`と変更してみましたがエラーが消えません。\n\n```\n\n Uncaught exception 'CacheException' with message \n 'Cache engine \"_cake_core_\" is not properly configured.\n Ensure required extensions are installed, and credentials/permissions are correct' in /webroot/hoge/Vendor/cakephp/cakephp/lib/Cake/Cache/Cache.php:186\n Stack trace:\n #0 /webroot/hoge/Vendor/cakephp/cakephp/lib/Cake/Cache/Cache.php(151): Cache::_buildEngine('_cake_core_')\n #1 /webroot/hoge/App/Config/core.php(354): Cache::config('_cake_core_', Array)\n #2 /webroot/hoge/Vendor/cakephp/cakephp/lib/Cake/Core/Configure.php(72): include('/webroot/hoge...')\n #3 /webroot/hoge/Vendor/cakephp/cakephp/lib/Cake/bootstrap.php(431): Configure::bootstrap(true)\n #4 /webroot/hoge/App/webroot/index.php(98): include('/webroot/hoge...')\n #5 {main}\n thrown in /webroot/hoge/Vendor/cakephp/cakephp/lib/Cake/Cache/Cache.php on line 186\n \n```\n\n開発環境は\n\n * centOS 7.1\n * CakePHP 2.X\n\nほとんどの場合chmodで回避できた方が多い様ですが、私の場合は何か違う所が問題なのかもしれないのでどなたか同じ状況で解決策をご存知の方がいらっしゃいましたらご教授願います。\n\n追記:以下の設定で環境構築をしています。\n\nVagratnfile\n\n```\n\n # -*- mode: ruby -*-\n # vi: set ft=ruby :\n \n Vagrant.configure(2) do |config|\n config.vm.define \"hoge\" do |node|\n node.vm.box = \"bento/centos-7.1\"\n node.vm.hostname = \"hoge\"\n node.vm.network :private_network, ip: \"192.168.33.61\"\n node.vm.network :public_network, ip: \"192.168.11.61\"\n node.vm.provision \"ansible\" do |ansible|\n ansible.playbook = \"playbook.yml\"\n end\n node.vm.synced_folder \"./webroot\", \"/webroot\", type: \"nfs\", mount_options: [\"async\", \"nolock\", \"nfsvers=3\", \"vers=3\", \"tcp\", \"noatime\", \"soft\", \"rsize=8192\", \"wsize=8192\"]\n end\n \n end\n \n```\n\ncomposer.json ファイル\n\n```\n\n {\n \"name\": \"hoge\",\n \"repositories\": [\n {\n \"type\": \"pear\",\n \"url\": \"http://pear.cakephp.org\"\n }\n ],\n \"require\": {\n \"cakephp/cakephp\": \">=2.4.9\",\n \"cakedc/search\": \"dev-master\"\n },\n \"require-dev\": {\n \"phpunit/phpunit\": \"3.7.*\",\n \"cakephp/debug_kit\" : \"2.2.*\"\n },\n \"config\": {\n \"vendor-dir\": \"Vendor/\"\n }\n }\n \n```\n\ncore.php\n\n```\n\n Cache::config('_cake_core_', array(\n 'engine' => $engine,\n 'prefix' => $prefix . 'cake_core_',\n 'path' => CACHE . 'persistent' . DS,\n 'serialize' => ($engine === 'File'),\n 'duration' => $duration,\n 'mask' => 0777,\n ));\n \n Cache::config('_cake_model_', array(\n 'engine' => $engine,\n 'prefix' => $prefix . 'cake_model_',\n 'path' => CACHE . 'models' . DS,\n 'serialize' => ($engine === 'File'),\n 'duration' => $duration,\n 'mask' => 0777,\n ));\n \n```", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T07:41:38.097", "favorite_count": 0, "id": "17767", "last_activity_date": "2015-10-19T12:19:12.393", "last_edit_date": "2017-05-23T12:38:55.250", "last_editor_user_id": "-1", "owner_user_id": "8500", "post_type": "question", "score": 1, "tags": [ "cakephp", "centos", "vagrant" ], "title": "Vagrant + CakePHP + CentOS 7.1でうまく表示されない問題", "view_count": 741 }
[ { "body": "自己解決致しました。\n\n[vagrant共有フォルダのパーミッションでハマった話](http://blog.buddying.jp/tips/2015-06-03/184/)\n\n> どうやらvagrantの共有フォルダはコマンドで所有者や権限の変更できないらしい。\n\nという事でしたのでVagrantfileを記事の内容と同じ\n\n```\n\n node.vm.synced_folder \"./\", \"/vagrant\",\n :owner => \"apache\",\n :group => \"apache\",\n :mount_options => [\"dmode=775,fmode=775\"]\n \n```\n\nと設定しreloadしたら無事にローカル開発環境ができました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T12:19:12.393", "id": "17825", "last_activity_date": "2015-10-19T12:19:12.393", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8500", "parent_id": "17767", "post_type": "answer", "score": 1 } ]
17767
null
17825
{ "accepted_answer_id": null, "answer_count": 2, "body": ".NET4.5 \ninput = \"abc123def$456ghi\" (注 文字列、数字列ともランダムとします) \nにおいて、先頭に$がない数字列を検出したく(123だけを検出したい) \npattern = \"(?\\<!\\$)\\d+\" \nで行うと、\"123\" , \"56\" となってしまいます。\n\nどなたか、解法がわかるかた教えてください。 \nまた、正規表現だけでは無理だという回答でもいただけるとありがたいです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T09:33:31.673", "favorite_count": 0, "id": "17768", "last_activity_date": "2015-10-18T21:44:48.200", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12830", "post_type": "question", "score": 0, "tags": [ ".net", "正規表現" ], "title": "正規表現 否定後読み 文字列中の数字列の先頭に'$'がない数字列の検出", "view_count": 430 }
[ { "body": "```\n\n var pattern = @\"(?<=[^$\\d])\\d+\";\n \n```\n\nのように肯定後読みで`$`もしくは数字ではない文字を探せばいいのではないでしょうか。ただこれでは文字列先頭の数字が含まれませんので、\n\n```\n\n var pattern = @\"(^|(?<=[^$\\d]))\\d+\";\n \n```\n\nと`^`も追加する必要があります。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T09:57:11.543", "id": "17770", "last_activity_date": "2015-10-18T09:57:11.543", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5750", "parent_id": "17768", "post_type": "answer", "score": 0 }, { "body": "質問文に「否定後読み」とありそれについてはpgrhoさんおよびunaristさんが答えられていますが、別解を。 \n[.NET Frameworkの正規表現](https://msdn.microsoft.com/ja-\njp/library/e347654k\\(v=vs.110\\).aspx)がPerl、Python、Emacs、Tcl、JavaScriptなどと同じ従来型NFAエンジンであることを利用して\n\n```\n\n var input = \"abc123def$456ghi\";\n var pattern = @\"\\$\\d*|(\\d+)\";\n foreach(Match m in Regex.Matches(input, pattern)){\n if(m.Groups[1].Success)\n Console.WriteLine(m.Groups[1].Value);\n }\n \n```\n\nで`\"123\"`を得ることができます。 \n従来型NFAエンジンでは一致する限り取り込まれるので、`\\$\\d*`で`'$'`及びそれに続く数値を取り込みます。望ましくない`\"$456\"`はここでマッチし次に流れることはありません。そうでない場合に限り`(\\d+)`にマッチしますので、これをグループでキャプチャします。 \nただし前半にマッチした場合でも全体では`m.Success`となっていますので、`m.Groups[1].Success`のみに絞り込みます。\n\n正規表現エンジン自体の特性を理解していると、.NET\nFramework以外にも応用が効きます。例えばJavaScriptの場合、後読みはありませんが私の挙げたパターンであれば表現できます。\n\n* * *\n\n「否定後読み」を使ったpgrhoさんおよびunaristさんのアプローチについても。\n\n```\n\n var pattern = @\"\\d+(?<!\\$\\d+)\";\n \n```\n\nでもできます。こちらはまず数値、`\"123\"`と`\"456\"`との両方がマッチさせます。その上で`\\$\\d+`の否定後読みで`'$'`が先行している`\"$456\"`については除外し、結果的に`\"123\"`だけがマッチします。 \nこのパターンは正規表現の内容が人間にも読み易いものになっているかなと思います。(1文字ずつ否定後読みの確認をせずに済むため、たぶんパフォーマンス的にもいいはずです。)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T11:54:05.633", "id": "17774", "last_activity_date": "2015-10-18T21:44:48.200", "last_edit_date": "2015-10-18T21:44:48.200", "last_editor_user_id": "4236", "owner_user_id": "4236", "parent_id": "17768", "post_type": "answer", "score": 2 } ]
17768
null
17774
{ "accepted_answer_id": "17772", "answer_count": 1, "body": "スタックオーバーフローで、(何も画像をアップロードしていない時点の)デフォルトユーザ画像は、どのように生成しているのでしょうか?\n\n一人ひとり違うよう自動生成しているようにも見えるのですが、その方法を知りたいです", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T10:55:24.353", "favorite_count": 0, "id": "17771", "last_activity_date": "2015-10-18T11:33:46.300", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 5, "tags": [ "画像" ], "title": "スタックオーバーフローの、デフォルトユーザ画像はどのように生成しているのでしょうか?", "view_count": 192 }
[ { "body": "Metaにまさにその質問があります。\n\n[How is the default user avatar\ngenerated?](https://meta.stackexchange.com/questions/17443/how-is-the-default-\nuser-avatar-generated)\n\nこのような画像はIdenticonと呼ばれていて、メールアドレスのハッシュ値としてランダムな値を得て画像を生成しているようです。厳密なアルゴリズムまではよくわかりませんが、オリジナルは[こちら](https://github.com/donpark/identicon)で、他にも[PHPの実装](http://scott.sherrillmix.com/blog/blogger/wp_identicon/)などが紹介されています。[英語版のWikipedia](https://en.wikipedia.org/wiki/Identicon)も参考になります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T11:33:46.300", "id": "17772", "last_activity_date": "2015-10-18T11:33:46.300", "last_edit_date": "2017-03-20T10:32:31.520", "last_editor_user_id": "-1", "owner_user_id": "10330", "parent_id": "17771", "post_type": "answer", "score": 10 } ]
17771
17772
17772
{ "accepted_answer_id": "17778", "answer_count": 2, "body": "メソッド1:コンストラクタパターン\n\n```\n\n function Dog(name, breed){\n Animal.call(this, \"dog\");\n this.name = name;\n this.breed = breed;\n }\n \n```\n\nで、\n\n```\n\n Animal.call(this, \"dog\");\n \n```\n\nは何をしているのでしょうか?\n\n・なくても意味は通るようにも思うのですが…\n\n<http://postd.cc/javascript-inheritance-patterns/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T11:44:33.013", "favorite_count": 0, "id": "17773", "last_activity_date": "2015-10-18T12:44:03.453", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 1, "tags": [ "javascript" ], "title": "Animal.call(this, \"dog\"); は何をしているのでしょうか? なぜ必要?", "view_count": 145 }
[ { "body": "他のオブジェクト指向言語でいう、親クラスのコンストラクタやイニシャライザの呼び出しに相当するかと思います。\n\n元のサンプルコードでいうと、this.typeの値に違いが出ます。\n\n```\n\n var sparkie = new Dog(\"Sparkie\", \"Border Collie\");\n console.log(sparkie.type);\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T12:43:12.053", "id": "17777", "last_activity_date": "2015-10-18T12:43:12.053", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4010", "parent_id": "17773", "post_type": "answer", "score": 1 }, { "body": "「意味が通る」かどうかは知りませんが、クラスベースの言語でいうところの「基底クラスのコンストラクタ」を呼び出す処理です。それがないと、基底クラス、ここでは\nAnimal のコンストラクタが実行されないため、その中で行われている `this.type` の設定が行われません。\n\n```\n\n // http://postd.cc/javascript-inheritance-patterns/\r\n \r\n function Animal(type){\r\n this.type = type;\r\n }\r\n Animal.isAnimal = function(obj, type){\r\n if(!Animal.prototype.isPrototypeOf(obj)){\r\n return false;\r\n }\r\n return type ? obj.type === type : true;\r\n };\r\n function Dog(name, breed){\r\n // ↓これは不要?\r\n // Animal.call(this, \"dog\");\r\n \r\n this.name = name;\r\n this.breed = breed;\r\n }\r\n Object.setPrototypeOf(Dog.prototype, Animal.prototype);\r\n Dog.prototype.bark = function(){\r\n console.log(\"ruff, ruff\");\r\n };\r\n Dog.prototype.print = function(){\r\n console.log(\"The dog \" + this.name + \" is a \" + this.breed);\r\n };\r\n Dog.isDog = function(obj){\r\n return Animal.isAnimal(obj, \"dog\");\r\n };\r\n \r\n var sparkie = new Dog(\"Sparkie\", \"Border Collie\");\r\n // 本来はtrueになるはずだが・・・\r\n document.write('Dog.isDog(sparkie): ' + Dog.isDog(sparkie));\n```\n\nクラスベースの言語では `super(hoge)` という感じにそのまま呼び出せたりもしますが、Javascript にそのような機能はないため、\n`Function.prorotype.call()` を使うことで、 `new Animal(\"dog\")` としたとき同様 `this`\nが対象オブジェクトを指すようにしています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T12:44:03.453", "id": "17778", "last_activity_date": "2015-10-18T12:44:03.453", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "parent_id": "17773", "post_type": "answer", "score": 1 } ]
17773
17778
17777
{ "accepted_answer_id": "18116", "answer_count": 1, "body": "C#にはクラスを値型で宣言する方法があります。Java8で同じことはできませんか。\n\n**詳細** \nクラスは常に参照型になります。 \nしかし、例えばC#ではstructによりオブジェクトを参照型ではなく値型として宣言できます。これをもちいるとC++のクラスのようにオブジェクトに割り当てられる領域の生存期間を(ガベージコレクタのことを気にせずに)明確にできます。Java8で同じことはできませんか。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T12:34:51.277", "favorite_count": 0, "id": "17775", "last_activity_date": "2015-10-31T07:07:18.773", "last_edit_date": "2015-10-31T07:07:18.773", "last_editor_user_id": "12831", "owner_user_id": "12831", "post_type": "question", "score": 3, "tags": [ "java" ], "title": "オブジェクト型を値型で宣言できるか", "view_count": 393 }
[ { "body": "Java 8現在、[C#の`struct`型](https://msdn.microsoft.com/ja-\njp/library/saxz13w4.aspx)に相当する「値型」は定義できません。\n\n未来のJava言語仕様を検討する活動の一つに [Project\nValhalla](http://openjdk.java.net/projects/valhalla/) というものがあり、そこでは「[Value\nTypes](http://cr.openjdk.java.net/%7Ejrose/values/values-0.html), [Value\nObjects](http://openjdk.java.net/jeps/169)」導入が議論されています。現時点では、それらがいつ導入されるかも分かりませんが、[Java\n10/11あたりでの導入を目指している](http://www.publickey1.jp/blog/15/java_10_11osjavaone_2015.html)ようです。\n\n* * *\n\n(これ以降はProject Valhalla資料に基づきます。最終的なJava仕様では変更されるかもしれません)\n\nJavaで導入検討されているValue\nTypesでは、全フィールドへの`final`修飾が必須、つまり値型のフィールド値を後から変更することはできません。Value\nTypesではfinalかつImmutableな[\"Value-based\nClass\"](http://docs.oracle.com/javase/8/docs/api/java/lang/doc-\nfiles/ValueBased.html)での性能改善を目的としており、過度な複雑度を導入しないよう意図的に制限するようです。[State of the\nValues](http://cr.openjdk.java.net/%7Ejrose/values/values-0.html)より関連個所を引用します:\n\n> **Details, details** \n> Can a value class contain a non-final field? No. (Logically possible, with\n> a surprising explosion of complexity.)\n>\n> **Open questions** \n> _Fieldwise side effects._ Why are value fields always final? Why can’t I\n> side-effect just one field in a value? I want all the efficiency of “by\n> value” and all the mutability of “by reference”! This is a long\n> conversation. There are logically consistent ways to provide such things\n> which, on balance, appear to be dismayingly complex. Java will never be C++,\n> though there are proposals to improve its interoperation with C++. As noted\n> above, values will certainly play a part with such interoperation.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-27T05:22:24.293", "id": "18116", "last_activity_date": "2015-10-27T07:03:33.547", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "49", "parent_id": "17775", "post_type": "answer", "score": 4 } ]
17775
18116
18116
{ "accepted_answer_id": "17849", "answer_count": 1, "body": "iOSにて、あるボタンを押して「写真」配下にアルバムを作成し、そのアルバム内に撮影した写真を保存する機能を加えようとしています。\n\nただ、アルバムの作成はできたものの、そのアルバムを指定して写真を保存するということができていません。(下記では、「カメラロール」に保存されてしまいます。)\n\nこちらの方法について見つけることができず、ご存知のかたいらっしゃいましたら、ご教授いただければ幸いです。\n\nなお、現在作成しているコードは下記のとおりです。\n\n【アルバムを作成する】\n\n```\n\n @IBAction func tapAddBookBtn(sender: AnyObject) {\n var titleTextField: UITextField?\n \n //タイトル入力をpopupで求める\n let alertController: UIAlertController = UIAlertController(title: \"タイトル登録\", message: \"本のタイトルを入力してください\", preferredStyle: .Alert)\n \n //cancelボタン\n let cancelAction: UIAlertAction = UIAlertAction(title: \"Cancel\", style: .Cancel) { action -> Void in\n print(\"Pushed CANCEL\")\n }\n alertController.addAction(cancelAction)\n \n //タイトル登録ボタン\n let registAction: UIAlertAction = UIAlertAction(title: \"登録\", style: .Default) { action -> Void in\n print(\"regist\")\n print(titleTextField?.text)\n \n let albumName :String = readPhotoAlbum.applicationName + (titleTextField?.text)!\n \n PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in\n self.request = PHAssetCollectionChangeRequest.creationRequestForAssetCollectionWithTitle(albumName)\n },completionHandler: { (isSuccess, error) -> Void in\n if isSuccess == true {\n print(\"Success!\")\n }\n else{\n print(\"error occured\")\n } \n }) \n }\n alertController.addAction(registAction)\n \n alertController.addTextFieldWithConfigurationHandler { textField -> Void in\n titleTextField = textField\n textField.placeholder = \"Title\"\n }\n \n presentViewController(alertController, animated: true, completion: nil)\n \n }\n \n```\n\n【画像を保存する(カメラロール)】\n\n```\n\n @IBAction func tapSaveBtn(sender: AnyObject) {\n \n //保存確認\n let alertController: UIAlertController = UIAlertController(title: \"保存確認\", message: \"本当に保存してよいですか?\", preferredStyle: .Alert)\n \n //保存確認->cancel\n let cancelAction: UIAlertAction = UIAlertAction(title: \"キャンセル\", style: .Cancel) { action -> Void in\n print(\"Pushed CANCEL\")\n }\n alertController.addAction(cancelAction)\n \n //保存確認->保存\n let saveAction: UIAlertAction = UIAlertAction(title: \"保存\", style: .Default) { action -> Void in\n print(\"save\")\n \n //savingView配下のeditingPhoto等を1枚の画像として保存\n UIGraphicsBeginImageContextWithOptions(self.editingPhoto.frame.size, false, 0)\n self.savingView.layer.renderInContext(UIGraphicsGetCurrentContext()!)\n \n let exportImage = UIGraphicsGetImageFromCurrentImageContext()\n \n UIGraphicsEndImageContext()\n \n //写真保存(「特定のアルバム」内には保存できていない。)\n UIImageWriteToSavedPhotosAlbum(exportImage,\n self, \"image:didFinishSavingWithError:contextInfo:\", nil)\n }\n }\n alertController.addAction(saveAction)\n \n presentViewController(alertController, animated: true, completion: nil)\n }\n \n```\n\nなお環境は、iOS9,xcode7.0.1です。\n\nよろしくお願いいたします。\n\n* * *\n\n※追記 \nHarawoさんの回答を参考にし、下記で動くことを確認しました。\n\n【アルバムを作成する】\n\n```\n\n @IBAction func tapAddBookBtn(sender: AnyObject) {\n var titleTextField: UITextField?\n \n //タイトル入力をpopupで求める\n let alertController: UIAlertController = UIAlertController(title: \"タイトル登録\", message: \"本のタイトルを入力してください\", preferredStyle: .Alert)\n \n //cancelボタン\n let cancelAction: UIAlertAction = UIAlertAction(title: \"Cancel\", style: .Cancel) { action -> Void in\n print(\"Pushed CANCEL\")\n }\n alertController.addAction(cancelAction)\n \n //タイトル登録ボタン\n let registAction: UIAlertAction = UIAlertAction(title: \"登録\", style: .Default) { action -> Void in\n print(\"regist\")\n print(titleTextField?.text)\n \n let albumName :String = readPhotoAlbum.applicationName + (titleTextField?.text)!\n \n PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in\n self.request = PHAssetCollectionChangeRequest.creationRequestForAssetCollectionWithTitle(albumName)\n },completionHandler: { (isSuccess, error) -> Void in\n if isSuccess == true {\n print(\"Success!\")\n }\n else{\n print(\"error occured\")\n } \n }) \n }\n alertController.addAction(registAction)\n \n alertController.addTextFieldWithConfigurationHandler { textField -> Void in\n titleTextField = textField\n textField.placeholder = \"Title\"\n }\n \n presentViewController(alertController, animated: true, completion: nil)\n \n }\n \n```\n\n【画像を保存する(カメラロール)】\n\n```\n\n @IBAction func tapSaveBtn(sender: AnyObject) {\n \n //保存確認\n let alertController: UIAlertController = UIAlertController(title: \"保存確認\", message: \"本当に保存してよいですか?\", preferredStyle: .Alert)\n \n //保存確認->cancel\n let cancelAction: UIAlertAction = UIAlertAction(title: \"キャンセル\", style: .Cancel) { action -> Void in\n print(\"Pushed CANCEL\")\n }\n alertController.addAction(cancelAction)\n \n //保存確認->保存\n let saveAction: UIAlertAction = UIAlertAction(title: \"保存\", style: .Default) { action -> Void in\n print(\"save\")\n \n //savingView配下のeditingPhoto等を1枚の画像として保存\n UIGraphicsBeginImageContextWithOptions(self.editingPhoto.frame.size, false, 0)\n self.savingView.layer.renderInContext(UIGraphicsGetCurrentContext()!)\n \n let exportImage = UIGraphicsGetImageFromCurrentImageContext()\n \n UIGraphicsEndImageContext()\n \n //アルバム名を指定する\n let albumTitle = titleTextField\n \n var theAlbum: PHAssetCollection?\n \n // アルバムを検索\n let result = PHAssetCollection.fetchAssetCollectionsWithType(PHAssetCollectionType.Album, subtype: PHAssetCollectionSubtype.Any, options: nil)\n result.enumerateObjectsUsingBlock({(object, index, stop) in\n if let theCollection = object as? PHAssetCollection where\n theCollection.localizedTitle == albumTitle\n {\n theAlbum = theCollection\n }\n })\n // アルバムにイメージを保存\n if let anAlbum = theAlbum {\n PHPhotoLibrary.sharedPhotoLibrary().performChanges({\n let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(exportImage)\n let assetPlaceholder = createAssetRequest.placeholderForCreatedAsset!\n let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: anAlbum)\n albumChangeRequest!.addAssets([assetPlaceholder])\n }, completionHandler: nil)\n print(\"save image into the Album.\")\n }\n }\n alertController.addAction(saveAction)\n \n presentViewController(alertController, animated: true, completion: nil)\n }\n \n```", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T12:35:04.203", "favorite_count": 0, "id": "17776", "last_activity_date": "2015-10-25T07:51:39.580", "last_edit_date": "2015-10-25T07:51:39.580", "last_editor_user_id": "12734", "owner_user_id": "12734", "post_type": "question", "score": 1, "tags": [ "ios", "swift" ], "title": "指定したアルバム内への画像の保存方法について", "view_count": 6433 }
[ { "body": "iOS 8より、Photo.appのライブラリにアクセスするフレームワークに、 **Photos Framework** が推奨されることになりました。\n\n[Photos Framework\nReference](https://developer.apple.com/library/prerelease/ios/documentation/Photos/Reference/Photos_Framework/index.html#//apple_ref/doc/uid/TP40014408)\n\n以下、一例として、「MyAlbum」という名前のアルバムに、`UIImage`インスタンスを保存するコードを載せておきます。(ボタンを押したら、保存)\n\n```\n\n @IBAction func savePhoto(sender: AnyObject) {\n let albumTitle = \"MyAlbum\" // アルバム名\n let savingImage = UIImage(named: \"a.png\")! // 保存するイメージ\n var theAlbum: PHAssetCollection? // アルバムをオブジェクト化\n // フォトライブラリからMyAlbumを検索\n let result = PHAssetCollection.fetchAssetCollectionsWithType(PHAssetCollectionType.Album, subtype: PHAssetCollectionSubtype.Any, options: nil)\n result.enumerateObjectsUsingBlock({(object, index, stop) in\n if let theCollection = object as? PHAssetCollection where\n theCollection.localizedTitle == albumTitle\n {\n theAlbum = theCollection // 見つかったら、theAlbumに代入\n }\n })\n // アルバムにイメージを保存する\n if let anAlbum = theAlbum {\n PHPhotoLibrary.sharedPhotoLibrary().performChanges({\n let createAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromImage(savingImage)\n let assetPlaceholder = createAssetRequest.placeholderForCreatedAsset!\n let albumChangeRequest = PHAssetCollectionChangeRequest(forAssetCollection: anAlbum)\n albumChangeRequest!.addAssets([assetPlaceholder])\n }, completionHandler: nil)\n } else {\n print(\"MyAlbum was not found.\")\n }\n }\n \n```\n\niOS 9より _Assets Library Framework_ はDeprecatedになります。ご注意ください。Assets\nLibraryより、Photosのほうがいくぶん使いやすくなったかなという印象があります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T08:45:10.777", "id": "17849", "last_activity_date": "2015-10-20T08:45:10.777", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7362", "parent_id": "17776", "post_type": "answer", "score": 1 } ]
17776
17849
17849
{ "accepted_answer_id": "17782", "answer_count": 1, "body": "[windyakin/Honoka](https://github.com/windyakin/Honoka)のv3.3.5-cについてです。\n\n`bootstrap.scss`ファイルをコンパルしようとしたのですが、 \nbootstrap自体がないようでコンパイルできませんでした。\n\nそこで、 \n[Bootstrap · The world's most popular mobile-first and responsive front-end\nframework.](http://getbootstrap.com/) \nからブラウザでダウンロードし、`scssディレクトリ`直下に置き、`scssコマンド`でコンパイルしました。\n\nしかし`README.md`をよく読むと上記の手順ではなく、 \n`Bower`や`Grunt`を使うようになりましたということが書かれております。 \n(とはいえ具体的な手順については書かれていない)\n\n具体的にどのディレクトリでどのようなコマンドを使えばよいのでしょうか?\n\nbundleであれば、Gemfileがあれば、Gemfileがあるディレクトリで \n`bundle install`をするという推測が立ちますが、 \n`Bower`や`Grunt`でもそのような推測方法はありますでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T14:20:02.650", "favorite_count": 0, "id": "17781", "last_activity_date": "2015-10-20T11:17:53.550", "last_edit_date": "2015-10-20T11:17:53.550", "last_editor_user_id": "9008", "owner_user_id": "9008", "post_type": "question", "score": 1, "tags": [ "node.js", "bootstrap", "grunt", "bower" ], "title": "BowerやGruntを使ってHonokaをコンパイルしたい", "view_count": 437 }
[ { "body": "`bower`, `grunt`は`NodeJS`を使用したCLIです。\n\n[公式ページ](https://nodejs.org/en/)からNodeJSをインストールするか、[nodebrew](https://github.com/hokaccha/nodebrew)で任意のバージョンを利用できます。インストールが終了すると、`npm`コマンドを使用できるようになります。NodeJS-\nPackage-Managerの意です。\n\n```\n\n curl -L git.io/nodebrew | perl - setup\n nodebrew install-binary v4.2.0\n nodebrew use v4.2.0\n # use v4.2.0\n \n node -v\n # v4.2.0\n npm -v\n # 2.14.7\n \n```\n\nこれで、Honokaの公式リポジトリから、scssのコンパイルが出来るようになります。\n\n```\n\n git clone https://github.com/windyakin/Honoka.git\n cd Honoka\n \n npm install grunt-cli --global # `grunt build`コマンドが利用可能に\n npm install # `grunt`で使用する依存モジュールを、`Honoka/package.json`を使用して解決する\n \n grunt build # `.scss`のコンパイル。`Honoka/dist` フォルダ内のcss/jsを全て更新する\n # ...\n # Done, without errors.\n \n```\n\nscssのコンパイルにrubyのscssを使用しますので、これが無い場合は、以下の記事を参考にしてください。\n\n> [Sassを使ってCSSを爆速コーディング!Sassの導入方法と使いかた。 -\n> Qiita](http://qiita.com/saison/items/472ff5a398fceefaa85c)\n\nなお、bowerですが、コンパイル済みのファイルをリリース/ダウンロードするためのコマンドになります。 \n以下のようにすると、コンパイル済みのファイルを入手できます。\n\n```\n\n npm install bower --global\n bower -v\n # 1.6.3\n \n bower install \"Honoka#3.3.5-c\"\n # Honoka#3.3.5-c bower_components/Honoka\n # └── bootstrap#3.3.5\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T15:43:21.553", "id": "17782", "last_activity_date": "2015-10-18T15:43:21.553", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9834", "parent_id": "17781", "post_type": "answer", "score": 1 } ]
17781
17782
17782
{ "accepted_answer_id": null, "answer_count": 0, "body": "リモートのCent OS7上でDockerコンテナを起動し、その中でMariaDBを動かしています。\n\nこのリモートのMariaDBにmysqlコマンドで接続しようとすると、一瞬だけ繋がってすぐ接続が切れます。\n\nリモート側の設定の問題だと思うのですが、どのあたりを確認し、設定を変更すればよいでしょうか?\n\n# 現在わかっていること\n\nローカルでmysqlコマンドを叩くと、次のエラーがでたり出なかったりします。 \n`ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization\npacket', system error: 54 \"Connection reset by peer\"`\n\n運良く接続できた場合、SQLを何か実行しようとすると先ほどのエラーか、次のエラーが出ます。 \n`ERROR 2013 (HY000): Lost connection to MySQL server during query`\n\nDocker上のMariaDBは`/usr/bin/mysqld_safe &`で起動\n\n`/var/log/mariadb/mariadb.log`には起動時のログしか出ていない\n\n(2015-10-19追記)\n\nDockerのホストはCentOS 7.1.1503です。\n\n```\n\n $ cat /etc/centos-release\n CentOS Linux release 7.1.1503 (Core)\n \n```\n\nDockerコンテナはdocker.io/centos(IMAGE:ce20c473cd8a)を元に作成しています。\n\nMariaDBと手元のPC間はインターネット経由です。\n\n利用者は自分だけで、ほぼ負荷はかかっていません。\n\nDockerホストはfirewalldをOFFに、iptablesをONにしています。\n\n```\n\n $ sudo systemctl status firewalld\n firewalld.service - firewalld - dynamic firewall daemon\n Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)\n Active: inactive (dead)\n \n $ sudo systemctl status iptables\n iptables.service - IPv4 firewall with iptables\n Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled)\n Active: active (exited) since <起動した時刻>\n Main PID: <PID> (code=exited, status=0/SUCCESS)\n CGroup: /system.slice/iptables.service\n \n```", "comment_count": 7, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T15:59:03.310", "favorite_count": 0, "id": "17783", "last_activity_date": "2015-10-19T05:45:12.817", "last_edit_date": "2015-10-19T05:45:12.817", "last_editor_user_id": "845", "owner_user_id": "845", "post_type": "question", "score": 1, "tags": [ "mariadb" ], "title": "リモートのMariaDBにmysqlコマンドで接続すると一瞬だけ繋がってすぐ切れる", "view_count": 895 }
[]
17783
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "PHP でメール送信機能付きのお問い合わせフォームを作っております。\n\n[![エラー/ブラウザ画面](https://i.stack.imgur.com/9egDP.png)](https://i.stack.imgur.com/9egDP.png)\n\n事象としては PHP のモジュール拡張機能である `mb_string` が読み込めていないことだと思いますが、未だに解決できません。 \n原因とその解決法を教えてください。\n\n以下のコマンドで `mb_string` はインストール済みです。\n\n```\n\n sudo yum --enablerepo=remi install -y php php-devel php-mysql php-mbstring php-gd\n \n```\n\n※環境:\n\n * mac\n * PHP 5.4.45\n * Vargant\n\nで動かしています。\n\n* * *\n\n実際のコードは以下に転記しておきます。 \n(個人情報の関係上、送信先と送信元は空白指定です)\n\n```\n\n <?php\n \n mb_language(\"ja\");\n mb_internal_encoding('UTF-8');\n \n $name = $_POST['name'];\n $title = $_POST['title'];\n $address = $_POST['address'];\n $message = $_POST['message'];\n \n //初期化\n $sTo = '';\n $sFromMail = '';\n $sSubject = '';\n $sMessage = '';\n $sHeaders = '';\n \n //送信先\n $sTo = '';\n //送信元\n $sFromMail = '';\n //題\n $sSubject = '【件名】メール送信テスト';\n //ヘッダー\n $sHeaders = \"From: {$sFromMail}\\r\\n\";\n //$sHeaders .= 'Return-Path: [email protected]';\n //本文\n $sMessage .=\n \"\\n\"\n .\"<p>お名前:<?php echo htmlspecialchars($name, ENT_QUOTES, 'utf-8'); ?></p>\"\n .\"<p>件名:<?php echo htmlspecialchars($title, ENT_QUOTES, 'utf-8'); ?></p>\"\n .\"<p>メールアドレス:<?php echo htmlspecialchars($address, ENT_QUOTES, 'utf-8'); ?></p>\"\n .\"<p>本文:<?php echo htmlspecialchars($message, ENT_QUOTES, 'utf-8'); ?><br />\";\n \n //送信処理\n if(mb_send_mail($sTo, $sSubject, $sMessage, $sHeaders)){\n echo 'メール送信に成功致しました。<br/>';\n }else{\n echo 'メール送信に失敗致しました。<br/>';\n }\n \n ?>\n \n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <title>[課題]PHP基礎編(2)</title>\n <link rel=\"stylesheet\" href=\"\">\n </head>\n <body>\n <h1>お問い合わせいただき、ありがとうございました!</h1>\n </body>\n </html>\n \n```\n\n`/etc/php.d/mbstring.ini` の中身:\n\n```\n\n ; language for internal character representation.\n ; http://php.net/mbstring.language\n mbstring.language = Japanese\n \n ; internal/script encoding.\n ; Some encoding cannot work as internal encoding.\n ; (e.g. SJIS, BIG5, ISO-2022-*)\n ; http://php.net/mbstring.internal-encoding\n mbstring.internal_encoding = UTF-8\n \n ; http input encoding.\n ; http://php.net/mbstring.http-input\n mbstring.http_input = pass\n \n ; http output encoding. mb_output_handler must be\n ; registered as output buffer to function\n ; http://php.net/mbstring.http-output\n ;mbstring.http_output = pass\n \n ; enable automatic encoding translation according to\n ; mbstring.internal_encoding setting. Input chars are\n ; converted to internal encoding by setting this to On.\n ; Note: Do _not_ use automatic encoding translation for\n ; portable libs/applications.\n ; http://php.net/mbstring.encoding-translation\n mbstring.encoding_translation = Off\n \n ; automatic encoding detection order.\n ; auto means\n ; http://php.net/mbstring.detect-order\n mbstring.detect_order = UTF-8,SJIS,EUC-JP,JIS,ASCII\n \n ; substitute_character used when character cannot be converted\n ; one from another\n ; http://php.net/mbstring.substitute-character\n mbstring.substitute_character = none;\n \n ; overload(replace) single byte functions by mbstring functions.\n ; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),\n ; etc. Possible values are 0,1,2,4 or combination of them.\n ; For example, 7 for overload everything.\n ; 0: No overload\n ; 1: Overload mail() function\n ; 2: Overload str*() functions\n ; 4: Overload ereg*() functions\n ; http://php.net/mbstring.func-overload\n mbstring.func_overload = 0\n \n ; enable strict encoding detection.\n mbstring.strict_detection = Off\n \n ; This directive specifies the regex pattern of content types for which mb_output_handler()\n ; is activated.\n ; Default: mbstring.http_output_conv_mimetype=^(text/|application/xhtml\\+xml)\n ;mbstring.http_output_conv_mimetype=\n \n <mbstring.iniの中身>\n \n ; Enable mbstring extension module\n extension=mbstring.so\n \n```", "comment_count": 9, "content_license": "CC BY-SA 4.0", "creation_date": "2015-10-18T16:02:49.617", "favorite_count": 0, "id": "17784", "last_activity_date": "2019-06-03T01:21:56.543", "last_edit_date": "2019-06-01T18:59:43.537", "last_editor_user_id": "32986", "owner_user_id": "7176", "post_type": "question", "score": 2, "tags": [ "php" ], "title": "mb_languageなどのmb関数が読み込めない", "view_count": 5698 }
[ { "body": "※解決済みのようなのでコメントより抜粋\n\n> `php -i | grep mbstring`の出力結果はどうなりますか? \n> `yum`を使われているところから見て`centos`だと思いますが、 \n> `/etc/php.d/mbstring.ini`は存在していますか? \n> holywise 15年10月18日 21:07\n>\n> 「/etc/php.d/mbstring.ini,」が表示されます! 既に`php-mbstring`はインストール済みです。 \n> Daiki Yamada 15年10月19日 11:37\n>\n> その1行しか出ていないのであれば、`mbstring`は正常に読み込まれていないものと思われます。 \n> `/etc/php.ini`の`mbstring`関係の設定および、`/etc/php.d/mbsring.ini`の内容を提示できますか? \n> holywise 15年10月19日 12:07\n\n上記によりmb系のモジュールが正常に読み込まれていないことが発覚。\n\n> `extension=mbstring.so`を絶対パスで指定するとどうなるでしょうか? \n> `extension=/usr/lib64/php/modules/mbstring.so`(パスが違っていたら適宜変更して下さい) \n> user9156 15年10月19日 13:14\n>\n> 絶対パスでいけました!でもなぜでしょうか。 \n> Daiki Yamada 15年10月19日 16:13\n>\n> `php.ini`の`extension_dir`の設定を確認してみて下さい。 \n> 本来のディレクトリ以外のパスに設定されているのかもしれません。 user9156 15年10月19日 22:56\n\n拡張モジュールの読込先が本来のディレクトリ以外を参照しているため、 \nモジュールのインストール先との齟齬でmbモジュールが読み込めなかったようです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-06-03T01:21:56.543", "id": "55463", "last_activity_date": "2019-06-03T01:21:56.543", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7676", "parent_id": "17784", "post_type": "answer", "score": 1 } ]
17784
null
55463
{ "accepted_answer_id": null, "answer_count": 2, "body": "現在以下のことをしようとしています。\n\n 1. ユーザーの名前(Name)をsplitted_nameという変数に代入。\n 2. splitted_name[0]をfirst_nameに保存(first_name = splitted_name[0])\n 3. splitted_name[0]とsplitted_name[-1]が別の値であればlast_nameにsplitted_name[-1]を保存\n\n以下がコードです。\n\n```\n\n class ConvertNameIntoFirstAndLastName < ActiveRecord::Migration\n def up\n execute <<-SQL\n DO\n $do$\n DECLARE\n u record;\n BEGIN\n FOR u IN SELECT * FROM users LOOP\n DECLARE\n splitted_name text[];\n BEGIN\n splitted_name := CASE WHEN u.name IS NULL THEN '{''}'\n ELSE regexp_split_to_array(u.name, E'\\\\s+')\n END;\n UPDATE users\n SET \n first_name = splitted_name[0],\n last_name = CASE WHEN splitted_name[0] = splitted_name[-1] THEN ''\n ELSE splitted_name[-1]\n END,\n name = splitted_name[0] || ' ' || (CASE WHEN splitted_name[0] = splitted_name[-1] THEN '{''}'\n ELSE splitted_name[-1]\n END)\n WHERE id = u.id;\n END;\n END LOOP;\n END;\n $do$;\n SQL\n end\n \n def down\n end\n end\n \n```\n\nしかし、漢字でnameが保存されている場合にこのSQL文のu.nameが常にnullを返します。(DBのエンコーディングはUnicodeに設定されています。)\n\n下記がエラー内容です。\n\nPG::NotNullViolation: ERROR: null value in column \"name\" violates not-null\nconstraint \n=> 実際にはnameはnullではなく漢字のstringが入っています。\n\nどなたか同様の問題を解決された方はいるでしょうか?原因と解決法がわかると助かります。\n\nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T16:41:34.827", "favorite_count": 0, "id": "17785", "last_activity_date": "2015-10-18T23:17:17.030", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12835", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "postgresql", "unicode" ], "title": "Rails Migration内でのexecute >> SQLでUnicodeキャラクターが常にnullを返します", "view_count": 123 }
[ { "body": "すみません。勉強不足でPostgresqlでArrayの最初の値がArray[0]Array[1]でないと取得出来ないことや、Array[-1]が無いことを知りませんでした。\n\n以下のコードで動きました。\n\n```\n\n class ConvertNameIntoFirstAndLastName < ActiveRecord::Migration\n def up\n execute <<-SQL\n DO\n $do$\n DECLARE\n u record;\n BEGIN\n FOR u IN SELECT * FROM users LOOP\n DECLARE\n splitted_name text[];\n BEGIN\n splitted_name := regexp_split_to_array(regexp_replace(u.name, ' ', ' '), ' ');\n UPDATE users\n SET \n first_name = splitted_name[1],\n last_name = CASE WHEN splitted_name[1] = splitted_name[array_upper(splitted_name, 1)] THEN ''\n ELSE splitted_name[array_upper(splitted_name, 1)]\n END,\n name = splitted_name[1] || ' ' || (CASE WHEN splitted_name[1] = splitted_name[array_upper(splitted_name, 1)] THEN ''\n ELSE splitted_name[array_upper(splitted_name, 1)]\n END)\n WHERE id = u.id;\n END;\n END LOOP;\n END;\n $do$;\n SQL\n end\n \n def down\n end\n end\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T17:38:35.963", "id": "17786", "last_activity_date": "2015-10-18T17:38:35.963", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12835", "parent_id": "17785", "post_type": "answer", "score": 2 }, { "body": "「そもそも論」ですが、Railsのマイグレーションはスキーマの変更(テーブルやカラムの追加、インデックスの変更、etc)を目的としているので、既存データの変更に使うのは本来の用途から少し外れている気がします。(db:rollback\nでデータを元に戻すのもほとんど無理でしょうし)\n\n参考: [Active Record マイグレーション | Rails\nガイド](http://railsguides.jp/active_record_migrations.html)\n\nあと、コードを見たところどうしてもDB上でやらなければいけない処理のようにも見えなかったので、Rails側で処理した方が簡単に書ける気がしました。\n\nたとえば以下のような変換用のメソッドを用意して、それをサーバー上のrails consoleで実行する、というのも一つの方法です。\n\n```\n\n class User < ActiveRecord::Base\n def self.convert_name_into_first_and_last_name\n self.transaction do\n self.all.each do |user|\n splitted_name = user.name.split(/[  ]+/)\n user.first_name = splitted_name.first\n # splitted_nameが3つ以上に分割されている場合は別途考慮が必要\n user.last_name = splitted_name.size == 2 ? splitted_name.last : ''\n user.name = splitted_name.join(' ')\n user.save!\n end\n end\n end\n end\n \n # rails console\n User.convert_name_into_first_and_last_name\n \n```\n\nこうしておくと、変更処理のテストコードも書きやすくなります。\n\nよかったらこういう方法も検討してみてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T23:17:17.030", "id": "17788", "last_activity_date": "2015-10-18T23:17:17.030", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "parent_id": "17785", "post_type": "answer", "score": 2 } ]
17785
null
17786
{ "accepted_answer_id": null, "answer_count": 0, "body": "Pythonを勉強している学生のものです。 \n<http://aidiary.hatenablog.com/entry/20111001/1317441171> \nこちらのサイトを参考にPythonでスペクトログラムを作成しようと思い試していました。\n\n読み込んだファイルが268mbでどうやらファイルサイズが多くメモリーエラーが出てしまいました。 \nttp://d.hatena.ne.jp/cslab/20110907/1315363388 \n対策を調べていてここに行き着きました。\n\npython27\\Lib\\site-packages\\matplotlib\\font_manager.py \n220行目に \nlocal = None \nを追記 \nしかしエラーはとれず、、、\n\nPython2.6とはちがうのかと諦めています。 \nエラーのとり方がありましたら教えてください。\n\nmjy様ありがとうございます。 \nエラー内容:MemoryError: としかでていません \n動作環境(OS:win7_64bit、Python2.7及びmatplotlibはexeで簡単に導入できるものを使用)、サイズの小さいファイルではエラーが出ないのか:744kbのwavファイルで試したところエラーは出ませんでした。\n\nlocal = None 消しておきました\n\n失礼しました \nこの画像のようなエラーです \n[![画像の説明をここに入力](https://i.stack.imgur.com/67A1B.jpg)](https://i.stack.imgur.com/67A1B.jpg)", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-18T20:49:22.637", "favorite_count": 0, "id": "17787", "last_activity_date": "2015-10-19T07:28:59.613", "last_edit_date": "2015-10-19T07:28:59.613", "last_editor_user_id": "12646", "owner_user_id": "12646", "post_type": "question", "score": 1, "tags": [ "python", "matplotlib" ], "title": "Python2.7 matplotlibメモリーエラーについて", "view_count": 1202 }
[]
17787
null
null
{ "accepted_answer_id": "17794", "answer_count": 2, "body": "**質問背景** \n・単なる興味本位 \n・インスタンスにprototypeは設定できないのかな、と思いました \n・prototypeは予約語ではない(?)ので,普通のプロパティとして使用可能? \n<https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Reserved_Words>\n\n```\n\n var Hoge = function(p1) {\n this.p1 = p1;\n };\n \n Hoge.prototype = {\n m1: function() {\n return this.p1;\n }\n };\n \n var hoge = new Hoge('プ1');\n hoge.m1(); //\"プ1\"\n \n```\n\n* * *\n\n・自動設定されない\n\n```\n\n hoge.prototype; //undefined\n \n```\n\n* * *\n\n・インスタンスにprototypeは自動的に設定されないようなので、手動設定に挑戦 \n・目的はないです \n・挙動確認したいためだけの単なる興味本位\n\n```\n\n hoge.prototype = {\n m2: function() {\n return this;\n }\n };\n \n```\n\n* * *\n\n・Function オブジェクトではないから?\n\n```\n\n hoge.m2(); //Uncaught TypeError: hoge.m2 is not a function(…)\n \n```\n\n* * *\n\n・prototypeは予約語ではない(?)ので,普通のプロパティとして使用可能、ということでしょうか?\n\n```\n\n hoge.prototype.m2(); //Object {}\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T00:20:16.087", "favorite_count": 0, "id": "17789", "last_activity_date": "2015-10-19T02:16:58.000", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 2, "tags": [ "javascript" ], "title": "インスタンスにprototypeは自動設定されない? 無理やり設定した場合は、普通のプロパティとして取り扱われる?", "view_count": 143 }
[ { "body": "prototypeについて誤解があるようです。 \nFunctionオブジェクトのprototypeはそれで生成したオブジェクト(this)の\"prototype\"に設定されるわけではありません。 \nJavascriptは、オブジェクト自体に存在しないプロパティやファンクションは、そのコンストラクタのprototypeのプロパティやファンクションを探します。 \nhoge.constructor.prototypeにあなたの作成したm1というファンクションを持つオブジェクトが設定されているでしょう。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T01:08:33.417", "id": "17792", "last_activity_date": "2015-10-19T01:08:33.417", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12836", "parent_id": "17789", "post_type": "answer", "score": 0 }, { "body": "ややこしいので、以下ではオブジェクトがプロパティを継承するオブジェクトを「プロトタイプ」、名前がたまたまprototypeであるプロパティを「prototypeプロパティ」と書きます。\n\nオブジェクトの「prototypeプロパティ」は、そのオブジェクトの「プロトタイプ」ではありません。 \nおっしゃる通り、「prototypeプロパティ」は普通のプロパティです。 \nプロトタイプチェーンで「prototypeプロパティ」が参照される事はありません。 \n質問の例ですと、Hogeは「prototypeプロパティ」の m1 がありますが、m1 という名前でプロパティを参照しても、これは辿られません。\n\n```\n\n Hoge.prototype;\n // -> { m1: [Function] }\n Hoge.m1();\n // エラー\n \n```\n\nでは、Hogeのプロトタイプテェーンで参照される「プロトタイプ」は何なのかというと、`Object.getPrototypeOf(Hoge)`\nで調べられます。Hogeは関数なので定義した時に処理系が`Function.prototype`を自動で設定しています。callプロパティ(メソッド)を調べると、プロトタイプテェーンでFunction.prototype.callが辿られているのが分かります。\n\n```\n\n Object.getPrototypeOf(Hoge) === Function.prototype\n // -> true\n Hoge.call == Function.prototype.call\n // -> true\n \n```\n\nでは、「prototypeプロパティ」が普通のプロパティであるなら、いつ使われるかというと、new演算子がオブジェクトを作る時です。new\nは新しいオブジェクトの「プロトタイプ」にコンストラクタオブジェクトの「prototypeプロパティ」を設定します。\n\n```\n\n hoge = new Hoge(1);\n Hoge.prototype === Object.getPrototypeOf(hoge);\n // -> true\n \n```\n\nこのように、new が使う約束になっている事以外は「prototypeプロパティ」に特別な作用はないのです。\n\nただ、さらにややこしい事にブラウザによっては「__proto__プロパティ」という物があります。 \nこれは本当にオブジェクトの「プロトタイプ」を参照しており、場合によって設定し直す事も可能です。\n\n```\n\n hoge.__proto__ = {\n m2: function() {\n return this;\n }\n };\n \n hoge.m2()\n // -> Object { p1: \"プ1\" }\n hoge.m1()\n // エラー: \n // hogeの「プロトタイプ」をnew演算子が設定した物(Hogeの「prototypeプロパティ」)\n // と入れ替えたため。m1は辿れなくなった。\n \n```\n\n「__proto__プロパティ」は標準でなく(後から書き換えが可能な事から性能上の問題もあるらしいです)、使うべきではありません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T01:38:10.273", "id": "17794", "last_activity_date": "2015-10-19T02:16:58.000", "last_edit_date": "2015-10-19T02:16:58.000", "last_editor_user_id": "3054", "owner_user_id": "3054", "parent_id": "17789", "post_type": "answer", "score": 1 } ]
17789
17794
17794
{ "accepted_answer_id": "17791", "answer_count": 1, "body": "例えば下記のようなディレクトリ構成の場合\n\n```\n\n ├── controllers\n │   ├── controller.go\n ├── main.go\n \n```\n\n`controllers`パッケージ(`controller.go`)から、`main`パッケージ、すなわち、`main.go`の関数を呼ぶにはどうすればいいのでしょうか。\n\n`github.com/<user-name>/<project-\nname>`をインポートすると、`golint`のエラーは消えましたが、実行すると循環参照はできないとのエラーがでました。\n\n`github.com/<user-name>/<project-name>/main`ではパッケージが見つからないというエラーが出ました。 \nご教授ねがえますでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T00:45:20.953", "favorite_count": 0, "id": "17790", "last_activity_date": "2015-10-19T00:52:23.880", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7232", "post_type": "question", "score": 0, "tags": [ "go" ], "title": "Golangでパッケージからmainパッケージの関数を呼ぶ", "view_count": 1531 }
[ { "body": "`controllers` パッケージの関数を呼び出す際に、引数で `main`\nパッケージの関数を渡します。フックやコールバックを予め登録するという考え方です。\n\n関数の代わりに `interface` を使うという手もあります。`controller` 側で定義された `interface` を満たすように\n`main` 側に実装し、`controller` を呼び出す前にその実装を渡すイメージです。C言語やJavaとは異なり、golangでは\n`interface` の実装する際は定義を直接参照する必要がない、充足してさえいれば良いことを利用します。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T00:52:23.880", "id": "17791", "last_activity_date": "2015-10-19T00:52:23.880", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "208", "parent_id": "17790", "post_type": "answer", "score": 1 } ]
17790
17791
17791
{ "accepted_answer_id": null, "answer_count": 1, "body": "お世話になります。\n\n現在開発中のフォームに2つのテキスト(input type=\"text\")項目があります。\n\nこれらの項目のうち、片方が入力されると、もう片方も入力しないとエラーになるようにしたいのですが方法が分かりません。\n\n環境は、jQuery validation engine です。\n\nよろしくお願いいたします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T02:07:31.623", "favorite_count": 0, "id": "17795", "last_activity_date": "2015-10-19T04:50:42.060", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10533", "post_type": "question", "score": 0, "tags": [ "jquery" ], "title": "jQquery validation engine で、2つの項目のうちどちらか片方が入力された場合、両方を必須にするには", "view_count": 5249 }
[ { "body": "[こちらのサイト](http://posabsolute.github.io/jQuery-Validation-Engine/)内にある\n[groupRequired](http://posabsolute.github.io/jQuery-Validation-\nEngine/#grouprequired)の例か、または\n[condRequired](http://posabsolute.github.io/jQuery-Validation-\nEngine/#condrequired)の例どちらかで満たせるかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T04:50:42.060", "id": "17799", "last_activity_date": "2015-10-19T04:50:42.060", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5778", "parent_id": "17795", "post_type": "answer", "score": 1 } ]
17795
null
17799
{ "accepted_answer_id": "17833", "answer_count": 1, "body": "Androidのみでいいのですが、WEBブラウザのリンクをクリックしたときに \n起動するアプリケーションをMonacaで作成したいと考えています。\n\nアプリの起動自体はできたのですが、そのときにそのリンクのURLの中に含まれている \nパラメータ(またはそのURL自体でもいいです)をアプリで受け取りたいのですが、 \nその方法がわからず困っております。 \n(例えば、URL内に埋め込まれたIDをアプリで受け取って、そのIDに対応した内容の \nアプリのページを表示させたい。)\n\n一般的なアプリではインテント経由で受け取ったりするようですが、 \nMonacaのWebIntentプラグインでは調べてみても、別のアプリに渡す方法しか \n見つけられませんでした。\n\nMonacaアプリで実現できる方法をご存知の方、ご教授いただけませんでしょうか。 \nよろしくお願いします。\n\n起動自体はAndroidManifest.xmlに以下のように`intent-filter`タグ、`action`タグ、 \n`category`タグ、`data`タグを追加することで実現できました。\n\n```\n\n <intent-filter>\n <action android:name=\"android.intent.action.VIEW\" />\n <category android:name=\"android.intent.category.DEFAULT\" />\n <category android:name=\"android.intent.category.BROWSABLE\"/>\n <data android:scheme=\"myapp\" android:host=\"simple\" />\n </intent-filter>\n \n```\n\n呼び出しのリンクは以下です。\n\n```\n\n <a href=\"myapp://simple/command\">TEST Link</a>\n \n```\n\n[こちらのサイト](http://www.ipentec.com/document/document.aspx?page=android-start-\napplication-at-url-link-click-on-web-browser)を参考にしました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T02:52:29.343", "favorite_count": 0, "id": "17796", "last_activity_date": "2015-10-20T01:06:53.410", "last_edit_date": "2015-10-20T00:54:11.573", "last_editor_user_id": "7290", "owner_user_id": "12837", "post_type": "question", "score": 1, "tags": [ "android", "monaca" ], "title": "WEBブラウザのリンクからMonacaアプリを起動したときにパラメータを受け取りたい", "view_count": 843 }
[ { "body": "Monacaで作成したアプリをURLSchemeで起動することは出来ますが、 \nパラメータを付与して起動することは出来ません。 \n(MonacaのAndroidのMainActivityを編集することが出来ないため)\n\n以前Assialの方へ要望として提出しましたが、未だに実装されていないのが現状です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T01:06:53.410", "id": "17833", "last_activity_date": "2015-10-20T01:06:53.410", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7676", "parent_id": "17796", "post_type": "answer", "score": 0 } ]
17796
17833
17833
{ "accepted_answer_id": null, "answer_count": 1, "body": "先月発表されたSORACOMを色々いじり倒そうとしているのですが、 \nSORACOM Beamの設定でつまずいてしまいました。\n\nまずはBeamへの接続確認を行おうとして、以下の状態になりました。\n\n**設定**\n\n * SORACOM Beamの設定\n * Beamを設定したグループへSIMをアサイン\n * (念のため)SIMを停止 ⇒ 利用再開\n * モバイルルーターへSORACOM SIMを乗せる\n * PCを上のモバイルルータに接続\n\n**状態**\n\n * インターネットには繋がる(普通にネットも見れる)\n * `ping www.google.co.jp` ⇒ 繋がる\n * `ping beam.soracom.io` ⇒ `ping: sendto: Host is down`\n * `curl http://beam.soracom.io:8888/` \n⇒ `curl: (7) Failed to connect to beam.soracom.io port 8888: Operation timed\nout`\n\nというような状況です。 \nどうにもbeam.soracom.ioに繋がらないような状況で、どなたか助けになる情報持っていたら教えて下さい。\n\n**環境**\n\nOS: Mac OS X YOSEMITE \nSIM: ナノ データ通信/SMS \nルーター: Docomo BF-01B \nです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T03:15:12.957", "favorite_count": 0, "id": "17797", "last_activity_date": "2015-10-19T06:35:17.777", "last_edit_date": "2015-10-19T06:00:24.440", "last_editor_user_id": "7290", "owner_user_id": "12838", "post_type": "question", "score": 0, "tags": [ "soracom" ], "title": "SORACOM Beamの接続について", "view_count": 288 }
[ { "body": "`beam.soracom.io`はリンクローカルアドレス(`169.254.254.169`)に紐付いているので、リンクローカルアドレスのルーティング設定をご確認ください。 \n今回はWi-Fiルーター経由とのことですので、OS XのルーティングとWi-Fiルーターのルーティングそれぞれが関係します。同機種別型番のDWR-\nPGの設定例をスライドにまとめているのでP.14〜P.16の辺りを参考にしてください。\n\n * [ぼくのかんがえたさいきょうの SORACOM Beam検証環境 // Speaker Deck](https://speakerdeck.com/takipone/bokufalsekangaetasaikiyoufalse-soracom-beamjian-zheng-huan-jing)", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T06:35:17.777", "id": "17804", "last_activity_date": "2015-10-19T06:35:17.777", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12845", "parent_id": "17797", "post_type": "answer", "score": 2 } ]
17797
null
17804
{ "accepted_answer_id": "17811", "answer_count": 1, "body": "swift2にて質問させてください。\n\nTCP/IPまたはUDP通信を行いNSData型でdataは受信できているのですが \nswift2において、byte配列というような型は存在しないのでしょうか。\n\nbyte配列に変換し、そのxx番目の配列のxビット目を抜き出す・・・ \n当の処理を考えているのですが、どのようにしてNSData型のdataをbyte配列のようにして扱ってよいのかわからずに困っています。\n\n初心者まるだしの質問で申し訳ないですが \n何かアドバイスいただけると助かります。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T05:45:03.250", "favorite_count": 0, "id": "17801", "last_activity_date": "2015-10-19T08:14:29.137", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12842", "post_type": "question", "score": 0, "tags": [ "swift" ], "title": "NSData型からバイト配列に", "view_count": 7890 }
[ { "body": "XcodeのPlaygroundで動かしてみてください。\n\n```\n\n import Foundation\n \n let aString = \"Hello, world!\" \n // 文字列からNSDataインスタンスを作る。\n if let aData: NSData = aString.dataUsingEncoding(NSUTF8StringEncoding) {\n // aDataのバイト数と同じ大きさの配列を作る。\n var aBuffer = Array<Int8>(count: aData.length, repeatedValue: 0)\n // aBufferにバイナリデータを格納。\n aData.getBytes(&aBuffer, length: aData.length) // &がアドレス演算子みたいに使える。\n for aChar in aBuffer {\n print(\"\\(aChar)\") // 各文字のutf-8の文字コードが出力される。\n }\n }\n \n```\n\n出力:\n\n> 72 101 108 108 111 44 32 119 111 114 108 100 33\n\n`NSData`から、バイナリデータを抽出する簡単なサンプルコードです。本来は、C言語の配列に`getBytes()`するところですが、Swiftの配列(`Array`)で代用できる点に注目してください。", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T08:14:29.137", "id": "17811", "last_activity_date": "2015-10-19T08:14:29.137", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7362", "parent_id": "17801", "post_type": "answer", "score": 1 } ]
17801
17811
17811
{ "accepted_answer_id": "17803", "answer_count": 1, "body": "テストで使用するため、擬似個人情報を生成できるツールを探しています。 \n生成したい情報は日本/日本語の氏名・郵便番号・住所などです。\n\nWebサービスであれば[疑似個人情報データ生成サービス](http://hogehoge.tk/personal/)などがあるのですが、 \n自分でカスタマイズ・メンテナンスを行いながら運用していきたいため、OSSのものを探しています。\n\n言語などについてはは特にこだわりはありません。\n\nよろしくお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T05:50:36.487", "favorite_count": 0, "id": "17802", "last_activity_date": "2015-10-19T06:29:56.403", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12841", "post_type": "question", "score": 4, "tags": [ "テスト" ], "title": "擬似的な個人情報を生成できるOSSのライブラリ/ツールを教えてください", "view_count": 220 }
[ { "body": "python の faker なら日本語の氏名・郵便番号・住所を生成できそうですがいかがでしょうか \n<http://qiita.com/ohbarye/items/452fefa2be5d56268b50> \n自分では試していないのであしからずお願いします", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T06:29:56.403", "id": "17803", "last_activity_date": "2015-10-19T06:29:56.403", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12847", "parent_id": "17802", "post_type": "answer", "score": 4 } ]
17802
17803
17803
{ "accepted_answer_id": null, "answer_count": 0, "body": "お世話になっております。\n\nMonacaでハイブリッドアプリを作成しております。\n\niOSの仕様 \nwebkit-transparentが設定されている時 \nposition:fixedが使用できず全てposition:staticになるため、 \n固定したいブロック要素が固定できずにいます(Android)では固定できています。\n\nこのような場合、どういった設定でブロック要素を固定すればよいのでしょうか? \nご存じの方がいらっしゃったらよろしくお願い致します。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T06:49:08.247", "favorite_count": 0, "id": "17805", "last_activity_date": "2015-10-19T06:49:08.247", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12846", "post_type": "question", "score": 1, "tags": [ "ios", "monaca", "css" ], "title": "Monacaでposition:fixedを使用するには", "view_count": 223 }
[]
17805
null
null
{ "accepted_answer_id": "17808", "answer_count": 1, "body": "postgresqlについて質問です。\n\n * users\n\n * id\n * name\n * posts\n\n * id\n * user_id\n * name\n\n`users ---< posts`\n\nこのような関係のテーブルがあります。 \n`posts`をもたない`users`のデータをdeleteしたいのですが、sql文の書き方がわかりません。\n\n教えていただけないでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T06:55:36.200", "favorite_count": 0, "id": "17806", "last_activity_date": "2015-10-19T07:06:45.303", "last_edit_date": "2015-10-19T07:06:45.303", "last_editor_user_id": "85", "owner_user_id": "10439", "post_type": "question", "score": 0, "tags": [ "sql", "postgresql" ], "title": "Postsを持たないUsersだけを削除するSQL文の書き方を教えてください", "view_count": 109 }
[ { "body": "こんなSQLでいけると思います。\n\n```\n\n delete from users\n where not exists(\n select * from posts where posts.user_id = users.id\n )\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T07:06:03.053", "id": "17808", "last_activity_date": "2015-10-19T07:06:03.053", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "85", "parent_id": "17806", "post_type": "answer", "score": 2 } ]
17806
17808
17808
{ "accepted_answer_id": "17840", "answer_count": 1, "body": "nginx と php-fpm 環境にて「upstream sent too big\nheader」というエラーがでたのですが、調べてみると以下の2つのパラメータを調整するとよいという情報がでてきました。\n\n * fastcgi_buffers\n * fastcgi_buffer_size\n\nそこで、これらを以下のように設定する正しく画面が表示できるようになりました。\n\n```\n\n fastcgi_buffers 8 16k\n fastcgi_buffer_size 16k\n \n```\n\nしかし、ドキュメントを見ても fastcgi_buffers の **8**\nの(下記のnumberの部分)がどういう意味なのかわからず、妥当な設定値がわかりません。\n\n<http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_buffers>\n\nこの設定値はどのような意味を持つのか教えてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T08:12:09.707", "favorite_count": 0, "id": "17810", "last_activity_date": "2015-10-20T05:34:25.703", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2535", "post_type": "question", "score": 1, "tags": [ "nginx" ], "title": "nginxのfastcgi_buffersの設定値の意味を教えてください", "view_count": 4265 }
[ { "body": "[こちら](http://server-setting.info/centos/nginx-fastcgi-\ncache.html)のサイトに説明が記載してありました。\n\n> FastCGIの応答のバッファサイズ(4k or 8k)とその個数を設定します。デフォルトは、個数は 8 \n> 個で、バッファサイズはシステムに依存します。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T05:34:25.703", "id": "17840", "last_activity_date": "2015-10-20T05:34:25.703", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7266", "parent_id": "17810", "post_type": "answer", "score": 0 } ]
17810
17840
17840
{ "accepted_answer_id": null, "answer_count": 6, "body": "Ubuntuの標準のbashシェルで、たとえば長いファイル名のファイルのバックアップを \n手でコマンド入力するときに、何か省略して簡単に打ち込める方法は無いでしょうか?\n\n例\n\n```\n\n cp very-long-filename.txt very-long-filename.txt.old\n \n```\n\nを\n\n```\n\n cp (very-log-filename.txt) \\1.old\n \n```\n\nのように前方参照させるようなやりかたです", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T08:17:56.130", "favorite_count": 0, "id": "17812", "last_activity_date": "2015-11-06T11:59:52.833", "last_edit_date": "2015-10-19T12:15:52.383", "last_editor_user_id": "7290", "owner_user_id": "12849", "post_type": "question", "score": 6, "tags": [ "bash", "ubuntu" ], "title": "Ubuntuのbashで`cp 文字数が多いファイル名 文字数が多いファイル名.old`を簡単に打つ", "view_count": 439 }
[ { "body": "Bash の対話セッションなら Emacs や vi\nのキーバインディングでコマンドラインの編集ができますので、このような例ですと私は頭を使う前に次のように操作しがちです。\n\nまず次のようにタイプしてから、\n\n```\n\n $ cp very-long-file-name.txt\n \n```\n\nこのように操作します。\n\n * `Ctrl`+`A` (先頭に移動)\n * `Ctrl`+`F`\n * `Ctrl`+`F` (カーソルが `cp` の後にくる)\n * `Ctrl`+`K` (行末までのテキストをキルバッファに格納)\n * `Ctrl`+`Y` (キルバッファをヤンク)\n * `Ctrl`+`Y` (もういちどヤンク)\n * `.``O``L``D` (`.old` を追加)\n * `Ctrl`+`M` (実行)\n\n日本語が混じっていたりなど、面倒なファイル名を扱う場合には特に便利です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T09:10:14.073", "id": "17814", "last_activity_date": "2015-10-19T09:15:56.107", "last_edit_date": "2015-10-19T09:15:56.107", "last_editor_user_id": "9873", "owner_user_id": "9873", "parent_id": "17812", "post_type": "answer", "score": 5 }, { "body": "[bash](/questions/tagged/bash \"'bash' のタグが付いた質問を表示\") の対話セッションなら [tab]\nキーでファイル名補完ができるので \ncp や mv など、既にあるファイル名を渡す目的には適当に補完しながら打ち込むのが簡単。 \nこの例では末尾補填なので、2回同じファイル名を補完で入力し、 \n最後 [backspace] でスペースを消して .txt の直後にカーソルを持ってきて .old とか。\n\nEmacs に慣れている人(オイラを含む)なら yaegashi さんの Emacs-bind のほうが楽っすけど \nオイラの周囲の人間を見てる範囲では、慣れてない人でも [tab] 補完は違和感なくできる様子です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T10:00:33.490", "id": "17816", "last_activity_date": "2015-10-19T10:00:33.490", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "17812", "post_type": "answer", "score": 1 }, { "body": "いろいろやり方はあると思いますが、私がよくやるのは次の2パターンです。\n\nまず、ここまで入力するのは共通。カーソル位置は右端にあるものとします。\n\n$ cp very-long-file-name.txt\n\nパターン1:\n\n 1. Ctrl+`w` を入力。(`very-long-file-name.txt` をカット)\n 2. Ctrl+`y` を入力。(`very-long-file-name.txt` をペースト)\n 3. `` を入力。(スペースを入力)\n 4. Ctrl+`y` を入力。(`very-long-file-name.txt` をペースト)\n 5. `.old` を入力して Enter して実行。\n\nパターン2:\n\n 1. Enter を押して実行。(このパターンだと引数が足らずエラーになるが気にしない)\n 2. Ctrl+`p` を入力。 (エラーになった前回のコマンドラインをヒストリーから復帰)\n 3. `` を入力。(スペースを入力)\n 4. ESC,`.` を入力。(ESC キー、ドット `.` を順番に押す。前回のコマンドラインの最後の引数をペースト)\n 5. `.old` を入力して Enter で実行。\n\nといった感じです。ご参考まで。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T12:11:15.087", "id": "17823", "last_activity_date": "2015-10-19T12:11:15.087", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3061", "parent_id": "17812", "post_type": "answer", "score": 3 }, { "body": "for文でやる方法もあります。\n\n```\n\n for f in very-long-filename.txt; do cp $f $f.old; done\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T03:59:44.900", "id": "17837", "last_activity_date": "2015-10-20T04:17:35.353", "last_edit_date": "2015-10-20T04:17:35.353", "last_editor_user_id": "12865", "owner_user_id": "12865", "parent_id": "17812", "post_type": "answer", "score": -2 }, { "body": "GNU cp 限定ですが\n\n```\n\n $ cp -bf -S .old file file\n $ ls\n file file.old\n \n```\n\n環境変数 `SIMPLE_BACKUP_SUFFIX` に `.old` を設定すれば `-S .old` を省略できます。\n\n```\n\n $ export SIMPLE_BACKUP_SUFFIX=.old\n $ cp -bf file file\n $ ls\n file file.old\n \n```\n\n個人的には `.old` 付けるより バックアップの上書きを回避するため 番号を付けるほうがいいと思います。\n\n```\n\n $ cp --backup=t -f file file ←1回目\n $ cp --backup=t -f file file ←2回目\n \n```\n\nもしくは\n\n```\n\n $ export SIMPLE_BACKUP_SUFFIX=numbered\n $ cp -bf file file ←1回目\n $ cp -bf file file ←2回目\n \n```\n\n結果は\n\n```\n\n $ ls\n file file.~1~ file.~2~\n \n```\n\nなお `mv` `ln` `install` `patch` でも同じオプションが使えます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T03:34:58.240", "id": "17925", "last_activity_date": "2015-10-22T03:34:58.240", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "17812", "post_type": "answer", "score": 1 }, { "body": "何故か `bash` の履歴展開機能を挙げている人がいないので書いておきます。履歴展開 (history expansion;\n対話シェルで既定で有効になっています) の指定を使えば、まさに質問文の様な事ができます。即ち、\n\n例\n\n```\n\n cp very-long-filename.txt very-long-filename.txt.old\n \n```\n\nを\n\n```\n\n cp very-log-filename.txt !#:1.old\n \n```\n\nと書く事ができます。`!#:1` の部分が履歴展開の指定です。意味は「`!` (= 履歴展開) `#` (= 現在のコマンドライン) `:` (= の )\n`1` (= 1つ目の単語)」です。上記を実行すると、コマンド内容が一旦 `cp very-long-filename.txt very-long-\nfilename.txt.old` に展開されてから実行されます。\n\n履歴展開の指定方法の詳細については [`man\nbash`](http://linuxjm.osdn.jp/html/GNU_bash/man1/bash.1.html#lbCX)\nを御覧になるのが良いと思います。履歴展開は指定ミスをしやすいので、慣れない内は直接実行せずに一旦コマンド `M-^` (history-expand-\nline) を用いて展開してから実行するのがおすすめです。履歴展開の指定 `!~` をコマンドラインに入力してから `M-^`\nを押すと、コマンドラインの内容が履歴展開後の内容に置き換わります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-11-06T11:59:52.833", "id": "18481", "last_activity_date": "2015-11-06T11:59:52.833", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5300", "parent_id": "17812", "post_type": "answer", "score": 1 } ]
17812
null
17814
{ "accepted_answer_id": "17826", "answer_count": 1, "body": "# 前置き\n\n(やや混乱しているので質問がわかりづらいかもしれません)\n\n大昔`Perl`で`CGI`によるWebアプリを作ったときに、`Apatch`で`Perl`で書いたプログラムを呼び出していた記憶があります。\n\n## Rails\n\n`Rails`ですが、`Webサーバー`と`アプリケーションサーバー`が分かれている印象です。\n\n## CGI\n\n上記`CGI`のやり方では`Webサーバー`は存在しますが、`アプリケーションサーバー`は存在しないと認識しています。\n\n# Webサーバーとアプリケーションサーバーで混乱\n\n`Rails`ですと\n\n## Webサーバー\n\n例えば`Rack` (←回答よりこれは勘違い)\n\n## アプリケーションサーバー\n\n例えば`Unicorn`、`Puma`\n\nといったように、ソフトウェアとして`Webサーバー`と`アプリケーションサーバー`が分かれていると認識しています。\n\n## Webサーバーとアプリケーションサーバーを同時に満たすものがある?\n\n`WEBrick`ですが、`Webサーバー`と`アプリケーションサーバー`どちらの役目もしているような気がしていて混乱しています。(`dev環境`だと`アプリケーションサーバー`など意識せず`WEBrick`だけで動いている気がする)\n\n## Rackは各種アプリケーションサーバーの仕様の乱立を避けるために生まれた?\n\n各種アプリケーションサーバーがどんどん出てきたときに、デプロイの作業がバラバラとなり、それを救うために`Rack`が生まれたというような内容を見かけました。 \nとなると、`アプリケーションサーバー`の違いを吸収するために`Webサーバー(Rack)`を用意するということでしょうか? \n(そもそも`Webサーバー`は`HTTP`などのリクエストを受け取るもので`アプリケーションサーバー`の違いを吸収するものではないような...)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T08:36:02.320", "favorite_count": 0, "id": "17813", "last_activity_date": "2015-10-20T23:26:23.737", "last_edit_date": "2015-10-20T23:26:23.737", "last_editor_user_id": "9008", "owner_user_id": "9008", "post_type": "question", "score": 4, "tags": [ "ruby-on-rails", "ruby", "rack" ], "title": "webサーバー、アプリケーションサーバー、Rackといった仕様や概念と、WEBrick、Unicorn、Pumaといった実装の関係が頭の中で結びつきません", "view_count": 5758 }
[ { "body": "webサーバー、アプリケーションサーバー、Rack、Unicorn、Puma、Railsと言った用語や概念の理解がこんがらかっているように見えたので、このあたりをきれいに説明している記事を探してみました。\n\nおそらく以下の記事が回答にぴったりだと思います。\n\n<http://www.justinweiss.com/articles/a-web-server-vs-an-app-server/>\n\nこの記事の中からnakanishiさんの理解に役立ちそうなセクションをピックアップして、ざっくり翻訳してみました。\n\n* * *\n\n### webサーバーとは\n\n * **webサーバー** はユーザー送られてきた自サイトへのリクエストを受け取り、なんらかの処理を加えるプログラムです。そして、場合によってはあなたのRailsアプリケーションにリクエストを投げます。NginxとApacheは最も有名な **webサーバー** です。\n * CSSやJavaScript、画像など、頻繁に変化しないファイルへのリクエストであれば、Railsアプリケーションはそのリクエストを処理する必要がないかもしれません。 **webサーバー** はRailsアプリケーションに処理を移譲することなく、そのリクエストを自分で処理できます。また、そうした方が通常は速く完了します。\n * **webサーバー** はSSLリクエストや静的なファイルやアセット、圧縮されたリクエスト等を処理したり、その他大半のwebサイトが必要としそうな数多くの処理をこなしたりすることができます。そしてもし、あなたのRailsアプリケーションがリクエストを処理しなければならない場合は、 **webサーバー** はリクエストを **アプリケーションサーバー** にパスします。\n\n### アプリケーションサーバーとは\n\n * **アプリケーションサーバー** はあなたのRailsアプリケーションを動かしているものです。 **アプリケーションサーバー** はあなたのコードを読み込み、アプリケーションをメモリに保持します。 **アプリケーションサーバー** は **webサーバー** からリクエストを受け取ると、Railsアプリケーションにそのことを知らせます。アプリケーションがリクエストを処理すると、 **アプリケーションサーバー** はそのレスポンスを **webサーバー** に返します。(そのレスポンスは最終的にユーザーへ届きます。)\n\n * 大半の **アプリケーションサーバー** は **webサーバー** を使わずに単体で実行できます。これはあなたがdevelopmentモードでやっていることです!しかしproduction環境では **webサーバー** を手前に置くことが多いはずです。 **webサーバー** は複数のアプリケーションを一度に処理したり、アセットを素早くレンダリングしたり、リクエストごと発生する多くの処理をさばいたりしてくれます。\n\n * Rails用の **アプリケーションサーバー** は山ほどあります。たとえば、Mongrel(ただし最近はほとんど使われていない)、 **Unicorn** 、Thin、Rainbows、 **Puma** などです。それぞれに異なる長所があり、異なる設計思想を持っています。とはいえ、みんなやっていることは一緒です。つまり、どの **アプリケーションサーバー** もあなたのRailsアプリケーションを動かし、リクエストを処理し続けています。\n\n### Rackとは\n\n * **Rack** は魔法です。 **Rack** を使えばどの **アプリケーションサーバー** であってもあなたのRailsアプリケーションを動かすことができます。(Railsに限らず、SinatraやPadrinoであっても同じです)\n * **Rack** はRailsのようなRuby製のwebフレームワークと **アプリケーションサーバー** の両方が話せる共通言語のようなものだと考えてください。両者が共通言語を理解できるので、Railsは **Unicorn** と話せますし、 **Unicron** はRailsと話せます。しかも、Railsも **Unicorn** も相手のことを知っておく必要は全くありません。\n\n### webサーバーとアプリケーションサーバーはどういう関係なのか?\n\n * それでは、この話を全部まとめるとどうなるでしょうか?\n\n * まず、webリクエストは **webサーバー** にぶつかります。そのリクエストがRailsで処理できるものであれば、 **webサーバー** はリクエストに簡単な処理を加えて **アプリケーションサーバー** に渡します。 **アプリケーションサーバー** は **Rack** を使ってRailsアプリケーションに話しかけます。Railsアプリケーションがリクエストの処理を終えると、Railsはレスポンスを **アプリケーションサーバー** に返します。そして、 **webサーバー** はあなたのアプリケーションを使っているユーザーにレスポンスを返します。\n\n * もっと具体的に言えば、Nginxはリクエストを **Unicorn** に渡します。 **Unicorn** はリクエストを **Rack** に渡します。 **Rack** はリクエストをRailsのrouterに渡します。routerはリクエストを適切なcontrollerに渡します。そしてレスポンスが逆の順番で返されます。\n\n[(全文訳はこちら)](http://qiita.com/jnchito/items/3884f9a2ccc057f8f3a3)\n\n* * *\n\nこの内容をじっくり読んで理解すれば、疑問点の大半は解消されると思うのですがいかがでしょうか? \n(ちなみに僕も理解があやふやなところがあったので、翻訳してみてスッキリしました)", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T13:19:44.037", "id": "17826", "last_activity_date": "2015-10-20T22:06:39.500", "last_edit_date": "2015-10-20T22:06:39.500", "last_editor_user_id": "85", "owner_user_id": "85", "parent_id": "17813", "post_type": "answer", "score": 11 } ]
17813
17826
17826
{ "accepted_answer_id": "17853", "answer_count": 2, "body": "laravel5.0で現在開発をしておりまして、表側と管理側はサブドメインを切り分けて運用を行おうと思っており、以下の様な記述をしております。 \n(www.example.comが表側で、admin.example.comを管理側のURLとします)\n\n```\n\n Route::group(['domain' => 'admin.example.com'], function() {\n // routingのコード\n });\n \n```\n\nそこで、開発環境と本番環境のドメインが異なるため、現在上記の記述と\n\n```\n\n Route::group(['domain' => 'admin.example1.net'], function() {\n // routingのコード\n });\n \n```\n\nと2つ記述して運用しております。 \n無名関数の中は全く同じにしております。\n\nしかし当然ながら運用的には煩雑になってしまうため、無名関数内は共通化できればと思っております。 \nそこで試しに、無名関数内の記述を\n\n```\n\n $admin_route = function() {\n // routingのコード\n };\n \n```\n\nといった形で切り出し、\n\n```\n\n Route::group(['domain' => 'admin.example.com'], $admin_route);\n Route::group(['domain' => 'admin.example1.net'], $admin_route);\n \n```\n\nと記述したところ、エラーとなり上手く動作しませんでした。\n\nエラーメッセージは、\n\n> ErrorException in Router.php line 345: \n> Argument 2 passed to Illuminate\\Routing\\Router::group() must be an instance\n> of Closure, null given, called in\n> /vagrant/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php\n> on line 213 and defined\n\nになります。\n\nどのように記述すれば動作するのか、もしくはそもそも共通化させることは無理なのか、ご教示頂けたらと思います。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T10:29:05.990", "favorite_count": 0, "id": "17817", "last_activity_date": "2015-10-20T10:34:18.077", "last_edit_date": "2015-10-19T11:16:11.783", "last_editor_user_id": "9025", "owner_user_id": "9025", "post_type": "question", "score": 0, "tags": [ "php", "laravel" ], "title": "laravel5でroutes.php内の無名関数について", "view_count": 406 }
[ { "body": "自己解決してしまいました。。\n\n```\n\n function admin_route() {\n return function() {\n Route::get('/', 'HomeController@index');\n };\n }\n \n $admin_route = admin_route();\n \n Route::group(['domain' => 'admin.example.com'], $admin_route);\n Route::group(['domain' => 'admin.example1.net'], $admin_route);\n \n```\n\nという記述で問題なく動作致しました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T08:13:55.923", "id": "17847", "last_activity_date": "2015-10-20T10:01:24.203", "last_edit_date": "2015-10-20T10:01:24.203", "last_editor_user_id": "9025", "owner_user_id": "9025", "parent_id": "17817", "post_type": "answer", "score": 0 }, { "body": "エラーメッセージの内容としては「Router クラスの group() の第二引数は Closure 型でなければならないが、実際に渡されたのは null\nだった」というものです。\n\n※`Route` は [Facade](http://www.1x1.jp/blog/2014/03/laravel-facade-class.html)\nなので、`Route::group(...)` と書くと Router クラスの group() が呼び出されます。\n\n質問に書かれたコード片を見る限りでは正しく代入できているように思いますし、仮に文法に問題があれば別のエラーが出ていそうです。\n\n新規プロジェクトを作成し、以下のように routes.php を変更してみましたが、問題なく動きました。\n\n```\n\n $route = function () {\n Route::get('/', function () {\n return view('welcome');\n });\n };\n \n Route::group(['domain' => 'localhost'], $route);\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T10:34:18.077", "id": "17853", "last_activity_date": "2015-10-20T10:34:18.077", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "parent_id": "17817", "post_type": "answer", "score": 1 } ]
17817
17853
17853
{ "accepted_answer_id": "61195", "answer_count": 3, "body": "チェックボックスと連動して変化する表示を CSS だけで実装できないかと、以下のようなコードを書きました。これは Chrome 46\nでは期待通りに動き、チェック状態がテキストで表示されます。\n\n```\n\n input:before {\r\n content: 'not checked';\r\n position: absolute;\r\n top: 30px;\r\n }\r\n input:checked:before {\r\n content: 'checked';\r\n }\n```\n\n```\n\n <input type=\"checkbox\" />\n```\n\nしかし Firefox や IE 11 では動作せず、開発者ツールで見ると `:before` が効いていないようです。\n\nこれは Chrome の独自仕様に過ぎず、他ブラウザでの動作は期待しない方がいいのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T11:18:31.270", "favorite_count": 0, "id": "17819", "last_activity_date": "2019-12-23T11:33:11.980", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8000", "post_type": "question", "score": 6, "tags": [ "css" ], "title": "input[type=checkbox] に対して :before, :after 疑似要素が使えるのはChromeだけ?", "view_count": 19937 }
[ { "body": "`::before`や`::after`は対象となる要素のコンテンツの先頭および末尾に疑似的に要素を追加するものです。\n\n```\n\n <style>\n div::before{\n content: 'abc';\n }\n </style>\n <div>def</div>\n \n```\n\nは\n\n```\n\n <div><div::before />def</div>\n \n```\n\nであり \n\n```\n\n <div>abcdef</div>\n \n```\n\nとなります。そのため、コンテンツを持たない`<input/>` `<img/>` `<hr/>`などには使えません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T11:59:54.497", "id": "17822", "last_activity_date": "2015-10-19T11:59:54.497", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "17819", "post_type": "answer", "score": 6 }, { "body": "inputには中身が無いので挿入のしようも無い、というのが Firefox の仕様の解釈なのだと思います。 \n隣に中身を持てる要素を用意し、隣接セレクタで設定するとよいです。\n\n```\n\n input + span:before {\r\n content: 'not checked';\r\n }\r\n input:checked + span:before {\r\n content: 'checked';\r\n }\n```\n\n```\n\n <input type=\"checkbox\" />\r\n <span></span>\n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T12:12:38.387", "id": "17824", "last_activity_date": "2015-10-19T12:12:38.387", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "17819", "post_type": "answer", "score": 4 }, { "body": "> これは Chrome の独自仕様に過ぎず、他ブラウザでの動作は期待しない方がいいのでしょうか?\n\nはい、期待しないほうが良いと思います。\n\n* * *\n\nCSS 2 では `img` 要素で画像が表示されない場合に、設定しておいた `before`, `after`\n擬似要素により生成されたコンテンツが表示される、という例が載っていました[[1]](https://www.w3.org/TR/2008/REC-\nCSS2-20080411/generate.html#propdef-content)。\n\n> ### 12.2 The 'content' property[[1]](https://www.w3.org/TR/2008/REC-\n> CSS2-20080411/generate.html#propdef-content)\n>\n> The next rule inserts the text of the HTML \"alt\" attribute before the image.\n> If the image is not displayed, the reader will still see the \"alt\" text.\n```\n\n> IMG:before { content: attr(alt) }\n> \n```\n\n一方で、 CSS 2.1 は置換要素における `before`, `after`\n擬似要素の扱いを定義していない[[2]](https://www.w3.org/TR/CSS21/generate.html#before-after-\ncontent)ため、それらがどのように扱われるのかは **各ブラウザの実装に依存** しています。これは CSS 2.1 の 12 章 1\n節で言及されています。したがって、 CSS 2.1 において、置換要素に対して `before`, `after`\n擬似要素が使えないことを示す十分な根拠は存在しません。実際に、質問文で置換要素に `before`, `after` 擬似要素が効かないとされている\nFirefox においても、\n\n * `hr` 要素では `before`, `after` 擬似要素が動作する\n * `type` 属性に `image` を設定した `input` 要素において、 `before` 擬似要素によりデフォルトのテキストが挿入される\n\nなど、その動作に一貫性がありません。\n\n> ### 12.1 The :before and :after pseudo-\n> elements[[2]](https://www.w3.org/TR/CSS21/generate.html#before-after-\n> content)\n>\n> Note. This specification does not fully define the interaction of :before\n> and :after with replaced elements (such as IMG in HTML). This will be\n> defined in more detail in a future specification.\n\n次に CSS 2.1 以外の仕様をみると、 CSS Generated Content Module Level 3 で置換要素における `before`,\n`after` 擬似要素の扱いが言及されています[[3]](https://www.w3.org/TR/css-content-3/#content-\nproperty)が、この仕様は草案段階であり、従来定義されていなかった項目のため、これを多くのブラウザが実装するまでには時間がかかると考えられます。\n\n> ### 1\\. Inserting and replacing content with the content\n> property[[3]](https://www.w3.org/TR/css-content-3/#content-property)\n>\n> Note: Replaced elements do not have ::before or ::after pseudo-elements; the\n> content property replaces their entire contents.", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-12-07T04:42:37.270", "id": "61195", "last_activity_date": "2019-12-23T11:33:11.980", "last_edit_date": "2019-12-23T11:33:11.980", "last_editor_user_id": "32986", "owner_user_id": "32986", "parent_id": "17819", "post_type": "answer", "score": 3 } ]
17819
61195
17822
{ "accepted_answer_id": null, "answer_count": 2, "body": "つまってしまったので教えてください。 \nRais,Rubyは初めて書いているので、見当違いのことをしているかもしれません。\n\nRailsからOpen3のcapture3メソッドを実行してデーモンを立ち上げたいのですが、「cannot load such\nfile」となってしまいました。\n\n```\n\n # top_controller.rb(Railsからの呼び出し処理)\n \n def daemon_start\n cmd = \"/bin/app start;\"\n out, err, status = Open3.capture3(cmd)\n p out \n p err \n p status.exitstatus\n \n redirect_to root_path\n end\n \n```\n\n \n\n```\n\n # app(呼び出されるapp)\n \n #!/usr/bin/env ruby\n require 'bundler/setup'\n require 'daemons'\n require 'pathname'\n \n base_dir = Pathname('../../').expand_path(__FILE__)\n Daemons.run(\n base_dir.join('bin/bot'),\n app_name: 'bot',\n dir_mode: :normal,\n dir: base_dir.join('tmp'),\n log_dir: base_dir.join('log'),\n log_output: true\n )\n \n```\n\n \n\n```\n\n #表示内容(err)\n \n \"bin/app:3:in `require': cannot load such file -- daemons (LoadError)\\n\\tfrom bin/app:3:i\"\n \n```\n\n \n\n以下、試してみたことです。\n\n * appをターミナルから実行 \n→問題なく起動します。\n\n * ruby -Iでgemのパスを追加 \ncmdを \ncmd = \"ruby -I /Users/owner/.rvm/gems/ruby-2.2.0/gems/daemons-1.2.3/lib\n/bin/app start;\" \nと変えたところ、エラーは出なくなります。 \n(-Iで/Users/owner/.rvm/gems/ruby-2.2.0/gems/を渡すと最初のエラーと変わらずです)\n\n * requireしているパスを絶対パスに変更 \n同じ様に、エラーは出なくなります。\n\n * app内で$LOAD_PATH.unshiftする \n$LOAD_PATH.unshift('/Users/owner/.rvm/gems/ruby-2.2.0/gems/daemons-\n1.2.3/lib') \n同じ様に、エラーは出なくなります。 \nただ、上2つもそうなのですが、appから呼ばれるbotの中でrequireしているgemが見つからないとなってしまいます。\n\n \n\n```\n\n #そのときのエラー表示内容\n (botがrequireしているretryableの中でrequireしているファイルが見つからない)\n \n /Users/owner/.rvm/gems/ruby-2.2.0/gems/retryable-2.0.2/lib/retryable.rb:1:in `require': cannot load such file -- retryable/version (LoadError)\n \n```\n\n【質問】 \nappをターミナルから実行すれば正常に動いているので、パスが通ってないことが問題と考えています。 \n使用するgemに上で試したことと同じ対応をすべてのgemにすればなんとかなるのかもしれませんですが、それなりの数があるため避けたいです。 \nもっといい方法でパスを通す方法があるでしょうか? \nなんでもいいので教えていただきたいです。 \n足りない情報があれば追記します。 \nよろしくお願いします。\n\n【環境】 \nRails:4.1 \nRuby:2.2.0(Railsで使用) \nRuby:2.2.0(appで使用)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T14:43:27.280", "favorite_count": 0, "id": "17827", "last_activity_date": "2018-07-23T04:12:41.660", "last_edit_date": "2018-05-09T15:59:48.413", "last_editor_user_id": "754", "owner_user_id": "12840", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "ruby", "rubygems", "bundler" ], "title": "Open3やDaemonsを使って外部のRubyスクリプトを実行する際に、実行に必要なgemをロードできるようにしたい", "view_count": 914 }
[ { "body": "Rails側でappの実行に必要となるgemをbundle installしたら、とりあえず起動できました。 \nですが、もっといい方法があるかもしれないので、引き続き回答をお待ちしています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T03:06:44.257", "id": "17836", "last_activity_date": "2015-10-20T03:06:44.257", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12840", "parent_id": "17827", "post_type": "answer", "score": 1 }, { "body": "## 原因\n\n```\n\n ## /bin/app の中の ##\n require 'bundler/setup'\n \n```\n\nは何をやるかというと、カレントディレクトリから上に登っていって、最初に見つけた Gemfile の情報を利用して gem を LOAD_PATH\nに設定します。さらにはその際に、グローバルでインストールされている gem の load_path 情報は、 bundler\nが設定するものと被ってはいけないので、\n[`clean_load_path`](https://github.com/bundler/bundler/blob/0c5d3b8c1f391aa5175321675ecd91ee6a1f231b/lib/bundler/shared_helpers.rb#L330)\nでもってそれらを無視する挙動になっている様子です。なので、 bundler を利用する場合は、それが読み込む Gemfile に、すべての依存 gem\nを記述しなければ、正しく動作しなさそうです。\n\n## 今回何が起こったかを簡単にまとめると\n\n 1. Rails のプロセスから `Open3` が呼ばれる (pwd はおそらく rails の root) その際、実行されたコマンドは pwd を rails から引き継ぐ。\n 2. `bin/app` の `require 'bundler/setup'` の中で、 Gemfile の探索が行われる\n 3. Rails 自身の Gemfile が発見される\n 4. Rails の Gemfile が指定される gem たちでもって、 `LOAD_PATH` は設定されるが、そこには `daemon` などは含まれていない\n\n## 取り得る対応\n\nおそらく、 daemon やら app やらは rails とは独自に開発されている ruby のアプリケーションなのだと思います。 rails\nとは独自であるならば、 Gemfile をそれ用に用意して、ひとつのプロジェクトとして設定しましょう。そして、 `Open3` を実行する際に、 app の\nGemfile が利用されるようにしましょう。\n\n例えば次のように実行できるようにしたり:\n\n```\n\n # top_controller.rb の中で\n cmd = 'cd /path/to/app/dir && bundle exec bin/app'\n Open3.capture3 cmd\n # ...\n \n```\n\nもしくは、利用したい Gemfile を明示的に指定したりなど\n\n```\n\n # app (呼び出される app)\n ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', __dir__)\n # => (app ファイルがあるディレクトリからの相対パスでもって Gemfile を指定)\n \n```\n\nまた、 daemon のスクリプトまで含めて rails プロジェクトの管理下に入れてしまう、というのも手の一つではあります。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2018-05-09T15:43:42.307", "id": "43897", "last_activity_date": "2018-05-10T02:26:40.553", "last_edit_date": "2018-05-10T02:26:40.553", "last_editor_user_id": "754", "owner_user_id": "754", "parent_id": "17827", "post_type": "answer", "score": 1 } ]
17827
null
17836
{ "accepted_answer_id": null, "answer_count": 1, "body": "プログラミング初心者です。 \n現在、「Monaca」を使ってアプリを開発しています。\n\nカードを裏返すアニメーションを組んでいるのですが、 \nデバッガーで確認したところ、iOS端末とandroid端末で \n動作に違いが出てしまいます。\n\n使用している端末は、 \niOS:iPhone5 \nandroid:GalaxyS5(SC-04F)、Nexus7(ME571) \nです。\n\niOS端末での動きは問題ないのですが、 \nandroid端末のNexus7での動きがやや重くなる印象です。 \nちなみに、Nexus7にインストールされている「AndroidシステムのWebView」のアップデートはされています。\n\n改善する良い方法、アプローチの仕方等ありましたら、教えて頂ければ幸いです。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-19T22:50:29.163", "favorite_count": 0, "id": "17830", "last_activity_date": "2015-10-20T00:43:03.707", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12862", "post_type": "question", "score": 2, "tags": [ "javascript", "ios", "android", "monaca", "jquery" ], "title": "ハイブリッドアプリで、端末ごと(iOS、android)で生じてしまうアニメーションの動きを改善する良い方法はありますか?", "view_count": 257 }
[ { "body": "AndroidはバージョンによってWebViewが大きく異なります。\n\n・〜4.3まではAndroid固有のブラウザベースでのWebView \n・4.4.xはChromiumベースのWebView \n・5.x〜はAndroid OSから切り離して、Google Play経由でのアップデートが可能 \n(Chromiumベースなのは同じ)\n\nもし、Android4.xもアプリの対象に入っているのであれば、Crosswalkを使ってみてはいかがでしょうか?\n\nCrosswalkは自身のプロジェクトにライブラリとしてWebViewエンジンごと組み込むので、全てのAndroid\nOSで同じWebViewを使うことができます。\n\nMonacaでも利用できるようですよ。 \n<http://blog.asial.co.jp/1371>\n\n少しでも助けになれば幸いです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T00:43:03.707", "id": "17832", "last_activity_date": "2015-10-20T00:43:03.707", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8968", "parent_id": "17830", "post_type": "answer", "score": 2 } ]
17830
null
17832
{ "accepted_answer_id": "17854", "answer_count": 2, "body": "[ddollar/foreman](https://github.com/ddollar/foreman)についてです。\n\n## ジョブ, プロセス\n\n[David Dollar](http://blog.daviddollar.org/2011/05/06/introducing-\nforeman.html)\n\n> My apps no longer consist of a single web process; I usually have have \n> one or more types of background workers to run different types of jobs \n> and a clock process to handle scheduling.\n\n種類の違う **バックグラウンドで動くジョブ** をスケジューリングしているというようなことが書いてあります。\n\n[Foreman as Process Manager](https://robots.thoughtbot.com/foreman-as-process-\nmanager) \nここにも **Process Manager** とあり、 **ジョブ** のことを **プロセス** とも呼んでいるものと考えます。\n\n### 具体的にジョブ, プロセスとは?\n\n[Using foreman and environment variables to isolate and run your apps in\ndevelopment - Maurício Linhares'\nramblings](http://mauricio.github.io/2014/02/09/foreman-and-environment-\nvariables.html)\n\n> If you’re building Rails apps you probably found yourself installing \n> many external dependencies to run it. A database, a full text search \n> engine, an in memory cache, background worker processes and many other \n> tools that run as separate processes in your machine.\n\nとあるので、具体的に **ジョブ** や **プロセス** と呼ばれているものは、 \nデータベースやフルテキストサーチエンジンやキャッシュと理解しました。\n\n### 具体的なソフトウェアで考えると...\n\n上記では、データベースやキャッシュなどと表記されていますが、具体的なソフトウェアの名前を上げると、`MySQL`,`PostgreSQL`,`Redis`,`Unicorn(これもforemanの扱う対象?)`といったものが上がると思います。\n\n## Process Manager?\n\niPhoneアプリ開発では`Objective-C`を用い非同期処理を実現するために、`GCD`を使ったりして処理の制御を頻繁にしておりました。\n\n`foreman`も似たようなことをしているのではないかと推測しているのですが、 \n`PostgreSQL`,`Redis`,`Unicorn`というものを`foreman`が管理するというのがいまいち想像がつきません。`PostgreSQL`,`Redis`,`Unicorn`といったものを個別に立ち上げても`OS`がプロセスを扱う役目を担っているはずですので、`foreman`がいったい内部でどのようなことをしていてどのようなメリットがあるのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T00:33:51.557", "favorite_count": 0, "id": "17831", "last_activity_date": "2019-04-04T04:47:22.550", "last_edit_date": "2015-10-20T11:44:40.603", "last_editor_user_id": "9008", "owner_user_id": "9008", "post_type": "question", "score": 5, "tags": [ "ruby-on-rails", "ruby", "rubygems", "foreman" ], "title": "foremanとはなんでしょうか 使う利点は?", "view_count": 3359 }
[ { "body": "Railsアプリを開発するとき、ウェブサーバーのプロセスを1つ立ち上げて開発出来るのであればforemanは必要ありません。\n\nしかし、開発をすすめるうち、ウェブサーバー以外にも以下のように`rails\ns`で立ち上げるウェブサーバー以外にも、同時に実行しておかないといけないプロセスがいくつも出てきます。\n\n * バックグラウンドでジョブを実行するためのワーカープロセス\n * ワーカープロセスに定期的/ある特定の時間に処理を実行してもらうため、適切なタイミングでワーカープロセスにジョブを渡すためのクロックプロセス\n * ウェブ/ワーカー/クロックプロセスから、ジョブをエンキューするためのキュー\n * Railsで管理していないアセットをビルドするためのプロセス\n\n## 具体的なソフトウェアの例\n\n一例ですが、僕がいま開発しているアプリを実行するためには、以下のコマンドを実行して5つのプロセスを同時に立ち上げる必要があります。\n\n * bundle exec rails s\n * bundle exec sidekiq -c 1\n * bundle exec clockwork lib/clock.rb\n * gulp watch\n * redis-server\n\n※僕の場合はデータベースは常時立ち上げているのでforemanで管理していません\n\n### foremanを使わない場合\n\n * これらのプロセスを1つ1つ手でコマンドを実行して立ち上げる\n * デバッグで標準出力をみたいときにはこれらのプロセスの標準出力を1つ1つ見に行く\n * 全ての開発者がこれらのコマンドを手で実行する\n * このアプリケーションの実行に必要なコマンドを足したときには他の開発者に知らせる\n\n### foremanを使う場合のメリット\n\n * プロセスの種類と立ち上げるコマンドProcfileに書いておけば、foremanのコマンド一発でこれらのプロセスを立ち上げ開発を開始できる\n * 標準出力をまとめてみれるのでforemanのコマンドを実行した画面を見ればすべてのログがみれる\n * 開発しているアプリケーションを実行するために必要なコマンドをProcfileに書いておけば誰でもforemanのコマンド1つで実行できる\n * 開発しているアプリケーションを実行するために必要なコマンドが増えた場合も、Procfileに追加するだけで、誰でもforemanのコマンド1つで実行できる\n\n### foremanがやってること\n\n雰囲気はこの辺みるとわかると思います。\n\n<https://github.com/ddollar/foreman/blob/59d87c91a2004e05f6b12d4b150dcb4c911eb31c/lib/foreman/engine.rb#L52,L62>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T10:57:12.933", "id": "17854", "last_activity_date": "2015-10-20T10:57:12.933", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2599", "parent_id": "17831", "post_type": "answer", "score": 6 }, { "body": "個人的に、 foreman を使う一番大きなメリットは、 Procfile に記述した内容をそのまま sysVinit/upstart/systemd\nの形式で、デーモンとしてエクスポートできることだと思っています。\n\nつまり、モダンなウェブアプリとは、複数のコマンドによって実行されるプロセス群が協調動作を行うことで、それが最終的な動作となりますが、それを、\n\n * 手元(development) ではただの複数プロセス起動ツールとして\n * production では、それらのプロセスをデーモン化してデプロイすることで\n\n開発者は `Procfile` だけをメンテするだけで、 development/production\nのプロセスの起動をいい感じにハンドルしてくれるツールが、 Procfile です。\n\n例えば、 Heroku は app のプロセス群をチューニングする際には、 Procfile\nを書いてくれ、というような文書があった記憶があります。おそらく、 heroku の裏側でも Procfile\nから、それらをデーモン化する処理が行われているのだと思っています。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-04-04T04:47:22.550", "id": "53906", "last_activity_date": "2019-04-04T04:47:22.550", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "754", "parent_id": "17831", "post_type": "answer", "score": 2 } ]
17831
17854
17854
{ "accepted_answer_id": "17835", "answer_count": 1, "body": "前回にもストアアプリ関係の質問をさせて頂いた者です。\n\nc#での開発になります。 \nWindows8.1 \nvisulstadio Express for Windows 2013を使用しています。\n\nストアアプリにローカルデータベースを同梱させる方法なのですが、\n\n<https://social.msdn.microsoft.com/Forums/vstudio/ja-\nJP/b60b3656-bcd7-4f8d-b457-263eb31fd065?forum=csharpgeneralja> \nこちらを読んでいるのですが根本的な解決方法が明示されているように思えませんでした。 \n「同梱させるべきではない」とさえ言われているように思えます。\n\n<http://anopara.matrix.jp/2013/02/25/%E6%A5%AD%E5%8B%99%E3%82%A2%E3%83%97%E3%83%AA%E3%82%B1%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92windows-8-%E3%82%B9%E3%83%88%E3%82%A2%E3%82%A2%E3%83%97%E3%83%AA%EF%BC%88%E6%97%A7metro-\nstyle/> \nこちらのサイトでは初手で「無理」と言われていますが、 \n下まで読んでいると環境の問題が上げられています。\n\n>\n> Windowsストアアプリでは標準機能でローカルDBをサポートしていないようだ。ただ、NuGetでSQLiteが使えるようになる拡張機能を取ってこれるらしい。\n\nと書かれています。 \n前回には既にこの問題が解決されております。\n\nつまり環境的にも技術的にも、ストアアプリにSQLiteでローカルデータベースを同梱させる事が可能だという事だと思っています。\n\nしかし、そもそもストアアプリにローカルデータベースを同梱させるとはどういう事なのかという件に関して、自分の認識が曖昧である事に気が付きました。\n\nアプリとローカルDBの同梱についての仕組みなどを勉強したいと共に、 \n実装方法も知りたいです。\n\nsqlite3ではデータベースファイルという物が作られるという情報がネットにありましたが、 \nコマンドラインでの操作があるのでストアアプリとはまた別の物なのではないかと思っています。\n\n現在、実際にコードを記述して試したところ、 \n「App1」プロジェクトで作成した「food」DBの「Food」TABLE(?)にレコードを数件入れ、 \n一度プロジェクトを閉じて開き直し、実行してもデータが保持されている事が確認できています。\n\nまた、「App2」プロジェクトを作成し、「food」DBの「Food」TABLE(?)のレコードを抽出しようとした所、何もレコードが入っていないという結果になりました。\n\nネットで調べた結果、「TABLE作成の記述が抜けていた為にエラーが出た」とあった為、 \n私のコードでもTABLE作成の記述を書いたり消したりして実行を試しましたが、結果は同じでした。\n\n現在の結果は、ストアアプリにローカルデータベースを同梱させている状態なのでしょうか?\n\n意見やアドバイス、参考になるサイトなど教えていただきたいです。 \nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T02:25:31.393", "favorite_count": 0, "id": "17834", "last_activity_date": "2015-10-20T02:58:35.870", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12797", "post_type": "question", "score": 0, "tags": [ "c#", "visual-studio", "sqlite", "database" ], "title": "ストアプリにSQLiteでローカルデータベースを同梱させたい", "view_count": 1334 }
[ { "body": "そもそもストアアプリは自由にファイル操作することを許されていません。ですのでApp1が作成したファイルをApp2から参照することも許されません。[先の質問回答](https://ja.stackoverflow.com/a/17756/4236)でも\n\n```\n\n var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, \"Food.db\");\n \n```\n\nと書かれたように、アプリケーション毎に提供された特定のディレクトリにだけアクセスできます。\n\nデータベースについて調査するよりも前に、ストアアプリがどのように制限された環境なのかを調査することをお勧めします。 \n例えば質問文に「同梱」という語が見られますが、ということは完成したアプリケーションを配布する計画があるのでしょうか?\nストアアプリは通常のアプリケーションと異なり実行ファイルをコピーしただけでは動作しません。基本的にはMicrosoft社の提供するWindowsストアにアップロードし、一般公開する必要があります。その公開時に「同梱」するという意味になりますが、その点は認識されているのでしょうか?\n\n[先のコメント](https://ja.stackoverflow.com/questions/17730/c%E3%81%A7%E3%82%B9%E3%83%88%E3%82%A2%E3%82%A2%E3%83%97%E3%83%AA%E3%81%A7%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8Bsqlite%E3%81%AEdb%E3%82%92%E4%BD%9C%E3%82%8A%E3%81%9F%E3%81%84/17756#comment16328_17730)では開発環境だけで動作すれば構わないような記述をされていたので、同梱を検討されているとは思いませんでした。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T02:58:35.870", "id": "17835", "last_activity_date": "2015-10-20T02:58:35.870", "last_edit_date": "2017-04-13T12:52:38.920", "last_editor_user_id": "-1", "owner_user_id": "4236", "parent_id": "17834", "post_type": "answer", "score": 1 } ]
17834
17835
17835
{ "accepted_answer_id": null, "answer_count": 2, "body": "現在、サクラVPSを借り、CentOS,Apache httpd,Java,Tomcatでwebアプリケーションを公開しようとしています。 \n以下のURLでアクセスできる状態までもっていきました。\n\nhttp://○○○.com/tomcat/アプリケーション名/\n\nこのURLから「tomcat/アプリケーション名」を消して、 \nhttp://○○○.com/ \nでアクセスできるようにしたいのですが、どのようにすればできるでしょうか。\n\nよろしくお願いいたします。\n\n* * *\n\n追記10/22 -1\n\n* * *\n\napache httpdを使用しています。\n\ntomcatのserver.xmlは以下です。\n\n```\n\n <?xml version='1.0' encoding='utf-8'?>\n <Server port=\"8005\" shutdown=\"SHUTDOWN\">\n <Listener className=\"org.apache.catalina.startup.VersionLoggerListener\" />\n <GlobalNamingResources>\n <Resource name=\"UserDatabase\" auth=\"Container\"\n type=\"org.apache.catalina.UserDatabase\"\n description=\"User database that can be updated and saved\"\n factory=\"org.apache.catalina.users.MemoryUserDatabaseFactory\"\n pathname=\"conf/tomcat-users.xml\" />\n </GlobalNamingResources>\n <Service name=\"Catalina\">\n <Connector port=\"8080\" protocol=\"HTTP/1.1\"\n connectionTimeout=\"20000\"\n redirectPort=\"8443\" />\n <Connector port=\"8009\" protocol=\"AJP/1.3\" redirectPort=\"8443\" />\n <Engine name=\"Catalina\" defaultHost=\"localhost\">\n <Realm className=\"org.apache.catalina.realm.LockOutRealm\">\n <Realm className=\"org.apache.catalina.realm.UserDatabaseRealm\"\n resourceName=\"UserDatabase\"/>\n </Realm>\n <Host name=\"localhost\" appBase=\"webapps\"\n unpackWARs=\"true\" autoDeploy=\"true\">\n <Valve className=\"org.apache.catalina.valves.AccessLogValve\" directory=\"logs\"\n prefix=\"localhost_access_log\" suffix=\".txt\"\n pattern=\"%h %l %u %t &quot;%r&quot; %s %b\" />\n </Host>\n </Engine>\n </Service>\n </Server>\n \n```\n\n* * *\n\n追記10/22 -2\n\n* * *\n\ntake88さんコメントありがとうございます。 \n以下に書いてあるものでよいでしょうか? \nいろいろと調べなおした結果、ajpというもので連携しているようなのですが、 \nその設定が以下のようになっていました。\n\nパス: \n/etc/httpd/conf.d/proxy_ajp.conf\n\nproxy_ajp.confの内容: \nProxyPass /tomcat/ ajp://localhost:8009/", "comment_count": 7, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T05:47:28.900", "favorite_count": 0, "id": "17841", "last_activity_date": "2015-10-25T23:10:51.143", "last_edit_date": "2015-10-25T23:10:51.143", "last_editor_user_id": "5778", "owner_user_id": "12867", "post_type": "question", "score": -2, "tags": [ "java", "centos", "tomcat" ], "title": "さくらVPSを使ったjava-webサーバー構築", "view_count": 1072 }
[ { "body": "コメントにも書きましたが、Webサーバの現状の設定に関する説明が無いので、 \n設定云々での回答はできそうにありません。\n\nですので、設定にあまり関連しない形での回答を提示します。\n\nURLを変えたいということではなくアクセスしたいという要求を前提とした場合、 \nWebサーバのドキュメントルートにある`index.html`を下記のように書き換え、 \n`http://○○○.com/`にアクセスがあった場合に、`/tomcat/アプリケーション名`にリダイレクトさせてしまえば、設定に関係なく実現できます。\n\n```\n\n <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n <html>\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n <meta http-equiv=\"refresh\" content=\"0; url=/tomcat/アプリケーション名\">\n </head>\n </html>\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T07:56:47.743", "id": "17844", "last_activity_date": "2015-10-20T07:56:47.743", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10724", "parent_id": "17841", "post_type": "answer", "score": 1 }, { "body": "まずはTomcatについてだけ回答書きます。\n\n**Tomcatの設定**\n\n`/アプリケーション名/` はコンテキストの `docBase` を変更するか war ファイルの名前を `ROOT.war` に変更すれば 省略できます。\n\nEx) `http://example.com/tomcat/your_app_name/` → `<http://example.com/tomcat/>\n\n前者の場合は、次のファイルを作成します。 \nファイルの場所:`conf/localhost/Catalina/ROOT.xml` \nファイルの内容:\n\n```\n\n <Context docBase=\"/path/to/your_app_name.war\">\n (略)\n </Context>\n \n```\n\nこのファイルは context.xml の代わりに読み込まれます。 \nDatabaseの接続設定などが必要でしたら適宜変更してください。\n\n`docBase=\"/path/to/your_app_name.war\"` の部分は war ファイルのパスを書きます。 \nwebapps の下に war を置くとうまく動かないようですので 何処か別の場所に war\nを置いてください。Tomcatを再起動すると設定が読み込まれます。\n\n後者の場合は、単に war ファイルを mv します。 \nこちらのほうが簡単ですが warを差し替える度にリネームが必要ですので `ROOT.xml` の方をおすすめします。\n\n```\n\n $ mv your_app_name.war ROOT.war\n $ mv ROOT.war Tomcatインストール先/webapps/\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T05:55:39.180", "id": "17932", "last_activity_date": "2015-10-22T05:55:39.180", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "17841", "post_type": "answer", "score": 1 } ]
17841
null
17844
{ "accepted_answer_id": "18230", "answer_count": 1, "body": "以下のページを参考にMLlibを実装したところ、predict関数の返り値が1か-1で、スパムの確率が高いほど1に近くそうでなければ0に近い値が出るというようにはできないようなのですが、MLlibではこのような「確率」を返す関数というのは用意されてないのでしょうか。 \nなお、NaiveBayesをSVMWithSGDに変えてみてもやはり1か0で超平面からの距離のような連続的な値にはならないようです。\n\n[Scala ではじめる Spark / MLlib の単純ベイズ分類器 - ALBERT Engineer\nBlog](http://tech.albert2005.co.jp/blog/2014/07/17/mllib-naivebayes/ \"Scala\nではじめる Spark / MLlib の単純ベイズ分類器 - ALBERT Engineer Blog\")", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T07:02:35.673", "favorite_count": 0, "id": "17843", "last_activity_date": "2015-10-30T01:31:37.030", "last_edit_date": "2015-10-21T01:03:52.533", "last_editor_user_id": "816", "owner_user_id": "816", "post_type": "question", "score": 1, "tags": [ "機械学習" ], "title": "MLlibで予測値を「確率」で出す方法", "view_count": 287 }
[ { "body": "SVMWithSGDについてはわかりました。[公式ドキュメント](http://spark.apache.org/docs/latest/mllib-\nlinear-methods.html \"Linear Methods - MLlib - Spark 1.5.1\nDocumentation\")にあるようにデフォルトで設定されているしきい値0をclearThresholdすればpredictでナマの値が出るようになります。\n\n```\n\n model = SVMWithSGD.train(dataSet, NUM_ITERATIONS)\n model.clearThreshold()\n val score = model.predict(point.features)//0.8094...のようなナマの値\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-30T01:31:37.030", "id": "18230", "last_activity_date": "2015-10-30T01:31:37.030", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "816", "parent_id": "17843", "post_type": "answer", "score": 0 } ]
17843
18230
18230
{ "accepted_answer_id": "17875", "answer_count": 1, "body": "Android Studio で開発をしていますが、始めて間もないのでわからないことだらけです。 \nどうか知識を貸してください。\n\n現在ListViewでの背景を動的に変更したいと考えています(ゼブラカラーに変更)。\n\nただ、ネット上の先人達のサンプルを多数確認しましたが、解決できない問題点がいくつかあるので箇条書きにしていきます。\n\n・AppcompatActivityを継承している(ターゲットバージョンを古く設定している、また新しい機能も使いたい)のでArrayAdapter<>を継承できない。\n\n⇒getViewをオーバーライドして int position を持ってくることができない。\n\n・動的に背景を変更したいので指定して変更ではなくif分岐で処理したい。 \n⇒int position が必要になってくる\n\n(ex)\n\n```\n\n if(position%2==0){\n view.setBackgroundColor(Color.BLACK);\n }else{\n view.setBackgroundColor(Color.BLUE);\n }\n \n```\n\nなど\n\n・そのほかのサンプルにあった getItemAtPosition などを利用しようとも考えたが利用できなかった。\n\npositionだけを獲得する方法はあるのでしょうか?また、無理にpositionを獲得しなくても、このような処理を施すことはできるのでしょうか?よろしくお願いします。\n\n以下サンプルを付け加えました。\n\n```\n\n public class MainActivity extends AppCompatActivity {\n final String[] baseArray = {\"ApplePie\", \"BananaBread\", \"CupCake\", \"Donut\", \"Eclair\", \"Froyo\", \"GingerBread\", \"Honeycomb\", \"IcecreamSandwich\",\n \"JellyBean\", \"KitKat\", \"Lollipop\", \"Marshmallow\"};\n \n ListView list1;\n Button btn1;\n int position;\n String item;\n \n @Override\n protected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.activity_main);\n Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);\n //setSupportActionBar(toolbar);\n \n FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);\n fab.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View view) {\n Snackbar.make(view, \"Replace with your own action\", Snackbar.LENGTH_LONG)\n .setAction(\"Action\", null).show();\n }\n });\n \n findView();\n \n ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_multiple_choice, baseArray);\n \n list1.setAdapter(adapter);\n \n /*if (position % 2 == 0) {\n list1.setBackgroundColor(Color.rgb(100, 100, 100));\n } else {\n list1.setBackgroundColor(Color.RED);\n }*/\n }\n @Override\n public boolean onCreateOptionsMenu (Menu menu){\n // Inflate the menu; this adds items to the action bar if it is present.\n getMenuInflater().inflate(R.menu.menu_main, menu);\n return true;\n }\n \n @Override\n public boolean onOptionsItemSelected (MenuItem item){\n // Handle action bar item clicks here. The action bar will\n // automatically handle clicks on the Home/Up button, so long\n // as you specify a parent activity in AndroidManifest.xml.\n int id = item.getItemId();\n \n //noinspection SimplifiableIfStatement\n if (id == R.id.action_settings) {\n return true;\n }\n \n return super.onOptionsItemSelected(item);\n }\n \n public void findView() {\n \n btn1 = (Button) findViewById(R.id.button1);\n list1 = (ListView) findViewById(R.id.listView1);\n \n }\n }\n \n```", "comment_count": 3, "content_license": "CC BY-SA 4.0", "creation_date": "2015-10-20T08:04:14.713", "favorite_count": 0, "id": "17845", "last_activity_date": "2020-03-29T06:07:54.353", "last_edit_date": "2020-03-29T06:07:54.353", "last_editor_user_id": "3060", "owner_user_id": "12789", "post_type": "question", "score": 1, "tags": [ "java", "android", "android-listfragment" ], "title": "アンドロイドのListViewの背景について", "view_count": 383 }
[ { "body": "ネット上の先人達のサンプルでは、`Adapter`クラスを継承したものを各自実装しています。\n\n1 new -> Java classで`MainActivity`と同じパッケージに`MyAdapter.java`を追加する。\n\n2 次のように、`ArrayAdapter<String>`を継承させる。コンストラクタなど、必要なものを作る。\n\n```\n\n public class MyAdapter extends ArrayAdapter<String> {\n // コンストラクタ\n public MyAdapter(Context context, int resource, String[] objects){\n super(context, resource, objects);\n }\n // ここに、getView()などを記述する\n }\n \n```\n\n3 `MainActivity`側で、次のように`MyAdapter`を使用するよう書き換える。\n\n```\n\n ArrayAdapter<String> adapter = new MyAdapter(getApplicationContext(), android.R.layout.simple_list_item_multiple_choice, baseArray);\n \n```", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T00:40:01.080", "id": "17875", "last_activity_date": "2015-10-21T01:45:49.763", "last_edit_date": "2015-10-21T01:45:49.763", "last_editor_user_id": "845", "owner_user_id": "845", "parent_id": "17845", "post_type": "answer", "score": 2 } ]
17845
17875
17875
{ "accepted_answer_id": "17930", "answer_count": 1, "body": "`docker start` 後にすぐ終了してしまうコンテナに対して、特定のファイルを削除するコマンドを実行したいです。\n\n<https://hub.docker.com/_/redmine/> \nこちらのDockerイメージを使ってRedmineを動かしていたのですが、PC再起動後に再び `docker start`\nしたらすぐに終了してしまうようになりました。 \nどうも、 `/usr/src/redmine/tmp/pids/server.pid`\nが居残ってるのが問題みたいなので削除しようと思うのですが、その方法が分かりません。\n\n何かいい方法はないでしょうか?", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T08:08:54.543", "favorite_count": 0, "id": "17846", "last_activity_date": "2015-10-22T04:38:37.087", "last_edit_date": "2015-10-22T04:38:37.087", "last_editor_user_id": "12868", "owner_user_id": "12868", "post_type": "question", "score": 1, "tags": [ "docker", "redmine" ], "title": "Dockerで起動後にすぐ終了してしまうコンテナに対してコマンドを実行したい", "view_count": 6499 }
[ { "body": "標題とは異なる対応ですが、問題が解決しましたので記載致します。\n\nデータを引っ張りだして、新しいコンテナに入れる形で復旧致しました。\n\n 1. `docker export` を使用して対象コンテナをエクスポート\n 2. エクスポートしたtarを展開して、redmineの必要なデータを取り出す\n 3. 新しいredmineコンテナを作成\n 4. また同じ過ちを繰り返さないように、 `/docker-entrypoint.sh` に `rm -f /usr/src/redmine/tmp/pids/server.pid` を追記\n 5. 取り出したファイルを新しいコンテナにコピーする\n 6. コピーしたファイルの所有者を `redmine:redmine` に変更\n 7. コンテナを再起動\n\nまた、私がコピーしたファイルは以下です\n\n * /usr/src/redmine/sqlite/redmine.db\n * /usr/src/redmine/files/* (空でしたが...)\n * /usr/src/redmine/config/configuration.yml\n * /usr/src/redmine/public/themes/使っていたテーマ", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T04:38:19.543", "id": "17930", "last_activity_date": "2015-10-22T04:38:19.543", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12868", "parent_id": "17846", "post_type": "answer", "score": 1 } ]
17846
17930
17930
{ "accepted_answer_id": "17852", "answer_count": 1, "body": "詳解swiftで勉強しています。\n\nプロトコルの定義のところで、Comparableプロトコルを列挙型に適合する場合、 \n実体型をもつ列挙型は、すでに「==」をもっていますとあるのですが、\n\n通常の列挙型(実体型ではない)は「==」が使用できないように思えるのですが、 \n実際は使用できます。\n\nこの意味は、どう理解すべきでしょうか", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T08:22:05.923", "favorite_count": 0, "id": "17848", "last_activity_date": "2015-10-20T11:08:58.360", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "11148", "post_type": "question", "score": 2, "tags": [ "swift" ], "title": "列挙型の2項演算子について", "view_count": 430 }
[ { "body": "```\n\n enum CompassPoint {\n case North\n case South\n case East\n case West\n }\n \n```\n\n上記のような、Assciated Valueを持たない単なるEnumはコンパイラによって自動的に`Equatable`になります。\n\n> Simple enums that have no associated data (like MyBool) are automatically\n> made Equatable by the compiler, so no additional code is required. \n> <https://developer.apple.com/swift/blog/?id=8>\n\n \n\nそのため、`==`で比較する際には下記で定義されいている演算子が使用されます。\n\n```\n\n public func ==<T : Equatable>(lhs: T?, rhs: T?) -> Bool\n \n```\n\n \n\n```\n\n enum Barcode {\n case UPCA(Int, Int, Int, Int)\n case QRCode(String)\n }\n \n```\n\n一方、上記のようなAssociated Valueを持つEnumはそうはならないので、自分で`==`を実装する必要があります。\n\n> However, you can make arbitrary types equatable by conforming to the\n> Equatable protocol and implementing the == operator. \n> <https://developer.apple.com/swift/blog/?id=8>\n\n \n\n```\n\n enum Math: Double {\n case Pi = 3.1415\n case Phi = 1.6180\n case Tau = 6.2831\n }\n \n```\n\n上記のようなDoubleやStringを継承しているようなEnumで`==`による比較ができるのは`RawRepresentable`に適合するので、下記の演算子が使用されるためです。\n\n```\n\n func ==<T : RawRepresentable where T.RawValue : Equatable>(lhs: T, rhs: T) -> Bool\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T10:30:21.007", "id": "17852", "last_activity_date": "2015-10-20T11:08:58.360", "last_edit_date": "2015-10-20T11:08:58.360", "last_editor_user_id": "5519", "owner_user_id": "5519", "parent_id": "17848", "post_type": "answer", "score": 8 } ]
17848
17852
17852
{ "accepted_answer_id": null, "answer_count": 0, "body": "ImageMagick にて文字を描画すると Mac の環境のものより画質が落ちます。\n\nフォントをレンダリングする方式が違うのだと思いますが、Mac 環境でのみなら同じように描画することはできないでしょうか? よろしくお願いします。\n\n## imagemagick にて生成\n\nQuality: 85 \n[![imagemagick](https://i.stack.imgur.com/hMsX7.png)](https://i.stack.imgur.com/hMsX7.png)\n\nQuality: 100\n\n[![imagemagick2](https://i.stack.imgur.com/mFllY.jpg)](https://i.stack.imgur.com/mFllY.jpg)\n\n## Mac Chrome ブラウザ\n\n[![mac](https://i.stack.imgur.com/ZJaDF.png)](https://i.stack.imgur.com/ZJaDF.png)\n\n[![mac2](https://i.stack.imgur.com/mzu7c.png)](https://i.stack.imgur.com/mzu7c.png)\n\n## コード\n\nRMagick を使っています。\n\n```\n\n require 'RMagick'\n img = Magick::ImageList.new('Lenna.jpg')\n \n font = '/Library/Fonts/YuMincho.ttc'\n draw = Magick::Draw.new\n \n draw.annotate(img, 0, 0, 100, 50, '2014年も終わる') do\n self.font = font\n self.fill = 'red'\n self.pointsize = 30\n self.gravity = Magick::NorthWestGravity\n end\n \n img.write('result.jpg')\n \n```", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T08:49:11.277", "favorite_count": 0, "id": "17850", "last_activity_date": "2015-10-20T10:02:21.907", "last_edit_date": "2015-10-20T10:02:21.907", "last_editor_user_id": "7969", "owner_user_id": "7969", "post_type": "question", "score": 1, "tags": [ "imagemagick" ], "title": "ImageMagick で描画するフォントの画質を上げたい", "view_count": 326 }
[]
17850
null
null
{ "accepted_answer_id": "17865", "answer_count": 2, "body": "```\n\n time data \n 1 67\n 2 39\n \n 2000 45\n \n```\n\ntime.csvというデータが有りますが(下参照)、2つ実現できないことがあって困っています。 \n1,R上で1~1500まで切り取って新しいデータセットを作る。 \n2,すでに推定の終わっているモデルを用いてdataの隣にpredictのデータを並べる。 \n(例) predict=3+time*1.4\n\n一応いろいろ試してはいますがうまく行きません。 \n下のコードだとエラーが出てしまいます。\n\n```\n\n data <-read.csv(\"time.csv\",header=TRUE)\n pre<-data.frame(time=1:1500,data=data,predict=3+time*1.4)\n \n```\n\nEXCELだと簡単ですがRだとパッケージ分析ばかりやっていてクリーニングはEXCELにやらせていましたが、データが大きくなったり複雑になるとRのほうが楽だと思い今回質問させていただきました。RstudioやパッケージでSQLを使うという手もあるかと思いましたがRを用いる方向でお願い致します。\n\n**結果** \n1の方でとりあえずやってみましたが、\n\n```\n\n data <-read.csv(\"time.csv\", header=TRUE)\n pre<-data.frame(jikan=data$time[1:1000,],deeta=data$data[1:1000,])\n Error in data$data[1:1000,]: incorrect number of dimensions\n \n```\n\nのようなエラーが出てしまいます。元データを見てもずれはないようですし、timeがintでdataがnumだったのをどちらもnumに揃えてもエラーが変わりません。 \nどこに問題があるのでしょうか?\n\n**結果2**\n\n```\n\n > pre<-data.frame(jikan=data$time[1:1000],deeta=data$data[1:1000])\n Error in data.frame(jikan = data$time[1:1000], deeta = data$data[1:1000]) : \n 引数に異なる列数のデータフレームが含まれています: 0, 1000 \n \n```\n\nと今度はエラーが出ました。どのように対処すればよろしいでしょうか。\n\n**追記**\n\n```\n\n > head(data,n=10)\n time data\n 1 1 7.8\n 2 2 5.6\n 3 3 5.1\n 4 4 7.3\n 5 5 10.8\n 6 6 6.2\n 7 7 5.2\n 8 8 5.5\n 9 9 5.7\n 10 10 6.3\n \n```\n\nです。", "comment_count": 13, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T11:33:23.493", "favorite_count": 0, "id": "17860", "last_activity_date": "2015-10-21T15:17:19.853", "last_edit_date": "2015-10-21T10:13:02.613", "last_editor_user_id": "12457", "owner_user_id": "12457", "post_type": "question", "score": 1, "tags": [ "r", "database" ], "title": "Rを用いたデータの整理と生成", "view_count": 2970 }
[ { "body": "※ 質問欄に掲載されている `time.csv` ですが、スペース区切りに見えます。一応、以下の回答ではカンマ区切りを前提としています。\n\n> 2,すでに推定の終わっているモデルを用いてdataの隣にpredictのデータを並べる。\n\n`data` はデータフレームですので、列データに `$` でアクセスして `[1:1500]` で範囲を指定します。\n\n```\n\n data <-read.csv(\"time.csv\", header=TRUE)\n pre <- data.frame(data[1:1500,], predict=3+(data$time[1:1500])*1.4)\n \n```\n\n**追記**\n\n質問欄の結果2について、こちらでの実行手順を以下に示します。\n\n```\n\n $ head time.csv\n time,data\n 1,422\n 2,624\n 3,808\n :\n 1998,49\n 1999,628\n 2000,592\n \n $ R --version\n R version 3.1.2 (2014-10-31) -- \"Pumpkin Helmet\"\n \n $ R\n > data <-read.csv(\"time.csv\", header=TRUE)\n > pre <- data.frame(jikan=data$time[1:1000],deeta=data$data[1:1000])\n > head(pre)\n jikan deeta\n 1 1 422\n 2 2 624\n 3 3 808\n 4 4 888\n 5 5 484\n 6 6 739\n > str(pre)\n 'data.frame': 1000 obs. of 2 variables:\n $ jikan: int 1 2 3 4 5 6 7 8 9 10 ...\n $ deeta: int 422 624 808 888 484 739 357 677 588 907 ...\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T12:09:43.270", "id": "17865", "last_activity_date": "2015-10-21T10:28:27.250", "last_edit_date": "2015-10-21T10:28:27.250", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "17860", "post_type": "answer", "score": 1 }, { "body": "data.frameのサブセットは、以下のようにつくれます。\n\n```\n\n data_partial <- data[1:1500, ]\n \n```\n\nカラムの追加は以下のようにできます。毎回`data.frame()`で作り直す必要はありません。\n\n```\n\n data_partial$predict <- 3 + data_partial$time * 1.4\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T15:17:19.853", "id": "17909", "last_activity_date": "2015-10-21T15:17:19.853", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2544", "parent_id": "17860", "post_type": "answer", "score": 1 } ]
17860
17865
17865
{ "accepted_answer_id": null, "answer_count": 0, "body": "Obj-CでCocoaアプリを開発しています。 \nxcode上でrunした時は正常に動作しますが、.appにした後実行すると挙動がおかしくなります。 \n常駐アプリとしてカーソルの現在位置の値を用いているのですが、どうも値が取得できていないようです。 \n(*システム環境設定で、アプリケーションにコンピュータの制御を許可にしています。) \n原因がわからないため、教えていただけるとありがたいです。 \nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T14:49:29.063", "favorite_count": 0, "id": "17866", "last_activity_date": "2015-10-20T14:49:29.063", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12873", "post_type": "question", "score": 1, "tags": [ "objective-c", "macos" ], "title": "Cocoaアプリのarchive(.app)後の挙動がおかしい", "view_count": 44 }
[]
17866
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "ターミナルでmysqlを起動しようとすると以下のようなエラーが表示されます。 \n「ERROR 2002 (HY000): Can't connect to local MySQL server through socket\n'/tmp/mysql.sock' (2)」\n\n以下の解決法を試しましたが、無理でした。 \n<http://d.hatena.ne.jp/TamaC/20090330/1238418696>\n\n原因とその解決法を教えてください", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T15:59:20.550", "favorite_count": 0, "id": "17867", "last_activity_date": "2015-10-21T12:37:24.747", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7176", "post_type": "question", "score": 2, "tags": [ "mysql" ], "title": "Centosでmysqlが起動できない", "view_count": 753 }
[ { "body": "エラーメッセージ中の「`(2)`」はエラー番号を表します。 \nエラー番号の意味を知るには、perror コマンドを実行します。\n\n```\n\n % perror 2\n OS error code 2: No such file or directory\n \n```\n\nつまり、`/tmp/mysql.sock` が無いということです。\n\n考えられるのは、次の原因です。\n\n 1. mysqld が起動していない。\n\nps コマンドで mysqld が起動しているかどうか確認してみるのがいいと思います。\n\n 2. 起動中の mysqld と mysql コマンドが用いる mysql.sock ファイルの場所が異なる。\n\nmysqld コマンドが用いるソケットファイルは `mysqld --help -v | grep ^socket` で確認できます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T16:21:00.950", "id": "17868", "last_activity_date": "2015-10-21T12:37:24.747", "last_edit_date": "2015-10-21T12:37:24.747", "last_editor_user_id": "208", "owner_user_id": "3249", "parent_id": "17867", "post_type": "answer", "score": 3 } ]
17867
null
17868
{ "accepted_answer_id": "17885", "answer_count": 1, "body": "PlayFramework 2.2 with Javaを使ってアプリを作っています。\n\nModelの保存時に、追跡情報としてcreate_user_id/update_user_idを保存したいのですが、 \nPlayFrameworkのModelからセッション情報を取り出せません。\n\n現在は、保存時にControllerから毎回セッションから取り出したUserのエンティティを渡しているのですが、ひどい実装なので、 \nModel.save()メソッドを呼び出したときに、Model側でセッションからログインユーザーを取得して \n保存してくれるような実装にしたいです。\n\n何か、ベストプラクティスをご存知の方がいらっしゃいましたらご教授頂けませんか。\n\n```\n\n public abstract class AbstractTrailModel extends Model {\n \n public static final int INSERT = 1;\n public static final int UPDATE = 2;\n public static final int DELETE = 3;\n \n @ManyToOne(cascade = CascadeType.ALL)\n @Constraints.Required\n public User createUser;\n \n @ManyToOne(cascade = CascadeType.ALL)\n @Constraints.Required\n public User createUser;\n \n @Constraints.Required\n public Integer is_delete;\n \n \n public void save(User loginUser){\n \n if(create_time != null){\n setTrailInfo(UPDATE, loginUser);\n super.save();\n \n }else{\n setTrailInfo(INSERT, loginUser);\n super.save();\n }\n }\n \n \n public void setTrailInfo(int code, User loginUser){\n \n switch(code) {\n case INSERT:\n createUser = loginUser;\n case UPDATE:\n case DELETE:\n updateUser = loginUser;\n }\n \n if(code == DELETE){\n is_delete = 1;\n \n }else{\n is_delete = 0;\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T16:52:09.943", "favorite_count": 0, "id": "17869", "last_activity_date": "2015-10-21T04:35:02.500", "last_edit_date": "2015-10-20T17:48:29.407", "last_editor_user_id": "12251", "owner_user_id": "12251", "post_type": "question", "score": 2, "tags": [ "java", "playframework" ], "title": "PlayFrameworkでModelからセッション情報を取得する方法はありますか?", "view_count": 600 }
[ { "body": "Playのセッションを取り出す件については、`play.mvc.Http.Context.current().session()`を呼び出すと、`play.mvc.Http.Session`オブジェクトを取得できます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T04:35:02.500", "id": "17885", "last_activity_date": "2015-10-21T04:35:02.500", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4464", "parent_id": "17869", "post_type": "answer", "score": 2 } ]
17869
17885
17885
{ "accepted_answer_id": "17871", "answer_count": 1, "body": "PythonとNumpyの以下のプログラムに関する質問です。\n\n```\n\n import numpy as np\n \n total = np.array([0,0,0])\n \n total_list = []\n \n array_list = [np.array([0,0,0]), np.array([1,2,3]), np.array([4,5,6])]\n \n for array in array_list:\n \n total += array\n \n total_list.append(total)\n \n print total_list\n \n```\n\n単純に、array_listの要素を前から足し込んだものを、 \ntotal_listにappendするだけです。\n\n本来ならば、 \n[array([0, 0, 0]), array([1, 2, 3]), array([5, 7, 9])] \nという出力になると思うのですが、 \n[array([5, 7, 9]), array([5, 7, 9]), array([5, 7, 9])] \nと出力されてしまいます。\n\nすごく初歩的なのかもしれませんが、このバグが取れません。 \n申し訳ありませんが、よろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T18:41:46.590", "favorite_count": 0, "id": "17870", "last_activity_date": "2015-11-20T16:48:13.007", "last_edit_date": "2015-11-20T16:48:13.007", "last_editor_user_id": "10685", "owner_user_id": "12874", "post_type": "question", "score": 4, "tags": [ "python" ], "title": "Pythonでforループを使ってリストを生成すると、すべての要素が同じ値になる", "view_count": 11916 }
[ { "body": "基本的に Python では、変数は参照型です。つまりオブジェクト (値) の実体は、変数とは別の場所にあって、変数はその場所を指しているだけです。\n\n提示されたコードでは、ループの一回目が終わった時は、こんな感じになっています。\n\n```\n\n total --------> [0,0,0]\n ^\n list |\n [0] -------------+\n \n```\n\n二回目のループで `total += array` を行った時に、実体を直接アップデートするので、こうなります。\n\n```\n\n total --------> [1,2,3]\n ^\n list |\n [0] -------------+\n \n```\n\nその直後の append では同じ参照を追加するので\n\n```\n\n total --------> [1,2,3]\n ^ ^\n list | |\n [0] -------------+ |\n [1] ---------------+\n \n```\n\n最終的には\n\n```\n\n total --------> [5,7,9]\n ^ ^ ^\n list | | |\n [0] -------------+ | |\n [1] ---------------+ |\n [2] -----------------+\n \n```\n\nになります。\n\n`+=`\nでは、いちいち新しいオブジェクトを作って代入するという実装方法もあり得たのでしょうが、そうするとメモリの確保と開放が頻繁に起こることになります。numpy\nでは大きなデータを扱うことが多いので、それは避けたのでしょう。\n\n提示されたコードの append のところを \n`total_list.append(total.copy())` \nと修正すれば、いいでしょう。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-20T19:57:58.050", "id": "17871", "last_activity_date": "2015-10-20T19:57:58.050", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3605", "parent_id": "17870", "post_type": "answer", "score": 7 } ]
17870
17871
17871
{ "accepted_answer_id": null, "answer_count": 0, "body": "タイトルのバージョンの実機を使って、以下のページで音声が再生できるか確認したところ、音声が再生されません。\n\n> [AndroidとiOSで音を鳴らす -\n> jsdo.it/@59naga](http://jsdo.it/59naga/mobileAudio)([Internet\n> Archive](https://web.archive.org/web/20191017110711/http://jsdo.it/59naga/mobileAudio))\n\n**touchstart直後にplayを実行しないと音声は無効にされる** 、という以前の仕様が変更になったのでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2015-10-20T20:19:21.033", "favorite_count": 0, "id": "17872", "last_activity_date": "2019-10-17T11:08:21.527", "last_edit_date": "2019-10-17T11:08:21.527", "last_editor_user_id": "19110", "owner_user_id": "9834", "post_type": "question", "score": 1, "tags": [ "javascript", "html5" ], "title": "iOS9.0.2 Safari601.1でAudioContext-BufferSourceを再生するには", "view_count": 78 }
[]
17872
null
null
{ "accepted_answer_id": "17876", "answer_count": 2, "body": "下記のようなinterface型の変数`r`をint64型に変換したいのですができません。\n\n```\n\n fmt.Println(r) => [40]\n v := reflect.valueOf(r)\n fmt.Println(v.Type()) => []interface{}\n fmt.Println(v.Kind()) => slice\n \n```\n\nこれを素直に`a, ok := r.(int64)`としても、スライスなので`a, ok := r.([]int64)`としても変換できませんでした。 \nこれはどうやって変換すればいいのでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T00:07:21.273", "favorite_count": 0, "id": "17873", "last_activity_date": "2015-10-21T11:21:18.580", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7232", "post_type": "question", "score": 1, "tags": [ "go" ], "title": "interface型をint64型に変換したい", "view_count": 2590 }
[ { "body": "スライスの要素を一つ一つ変換していく事になります。\n\n```\n\n a := make([]int64, len(r))\n for i, v := range r {\n switch v.(type) {\n case int64:\n a[i] = v.(int64)\n }\n }\n \n fmt.Println(a) // => [40]\n \n```\n\nただ、int64 型ではない要素はスキップされますので初期値(0)のままになります。\n\n```\n\n r := []interface{}{int64(40), \"foo\", 100}\n fmt.Println(a) // => [40 0 0]\n \n```\n\n**追記**\n\n`int64` 型に変換可能な型を持つ要素を全て取り込む場合を追記しておきます。\n\n```\n\n package main\n \n import (\n \"fmt\"\n \"reflect\"\n )\n \n func main() {\n r := []interface{}{int64(40), int(1), float64(1.8), int8(100), int16(2000), int32(30000)}\n \n fmt.Println(r)\n vr := reflect.ValueOf(r)\n fmt.Println(vr.Type())\n fmt.Println(vr.Kind())\n \n a := make([]int64, 0, len(r))\n for _, v := range r {\n switch v.(type) {\n case int64:\n a = append(a, v.(int64))\n case int:\n a = append(a, int64(v.(int)))\n case int8:\n a = append(a, int64(v.(int8)))\n case int16:\n a = append(a, int64(v.(int16)))\n case int32:\n a = append(a, int64(v.(int32)))\n }\n }\n \n fmt.Println(a)\n }\n \n```\n\n※ float/float32/float64 型の変数も変換できないことはないのですが、整数値に丸められたり(切り捨て)、overflow\nを起こす場合もありますので除外しています", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T00:48:13.973", "id": "17876", "last_activity_date": "2015-10-21T11:21:18.580", "last_edit_date": "2015-10-21T11:21:18.580", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "17873", "post_type": "answer", "score": 2 }, { "body": "この方法でいかがでしょうか? \n<https://play.golang.org/p/c413UEvofS>\n\n```\n\n package main\n \n import (\n \"fmt\"\n \"reflect\"\n )\n \n func main() {\n r := []interface{}{40}\n fmt.Println(r) // [40]\n v := reflect.ValueOf(r)\n fmt.Println(v.Type()) // []interface {}\n fmt.Println(v.Kind()) // slice\n \n v2 := reflect.ValueOf(r[0])\n fmt.Println(v2.Type()) // int\n fmt.Println(v2.Kind()) // int\n \n v3 := reflect.ValueOf(int64(r[0].(int)))\n fmt.Println(v3.Type()) // int64\n fmt.Println(v3.Kind()) // int64\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T00:50:46.063", "id": "17877", "last_activity_date": "2015-10-21T00:50:46.063", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7266", "parent_id": "17873", "post_type": "answer", "score": 1 } ]
17873
17876
17876
{ "accepted_answer_id": null, "answer_count": 1, "body": "<https://dev.soracom.io/jp/docs/api/#!/Operator/create_operator>\n\nの新規operatorのinvitationメールを送るためのAPIについて、 \npasswordパラメータをsignup時に指定されている以下のフォーマット以外にすると、\n\n```\n\n Passwords must:\n - Be a minimum of 8 characters\n - Include at least one lowercase letter (a-z)\n - Include at least one uppercase letter (A-Z)\n - Include at least one number (0-9)\n \n```\n\nAPIのレスポンスは HTTP Status Code == 400となり、 \nResponse bodyは以下のものが返ってきます。\n\n```\n\n {\n \"code\": \"AUM0010\",\n \"message\": \"Invalid password format.\"\n }\n \n```\n\nできれば、なのですがAPI ドキュメントにも記載していただくと良いかな、と思います。m(_ _)m", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T01:40:47.750", "favorite_count": 0, "id": "17879", "last_activity_date": "2015-10-21T02:08:09.890", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12747", "post_type": "question", "score": -1, "tags": [ "soracom" ], "title": "APIリファレンス (/operators) での passwordパラメータフォーマットの記載について", "view_count": 91 }
[ { "body": "ご指摘ありがとうございます。そのとおりですね。 \nパスワードのフォーマットについて API リファレンスに記載するようにします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T02:08:09.890", "id": "17881", "last_activity_date": "2015-10-21T02:08:09.890", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12626", "parent_id": "17879", "post_type": "answer", "score": 0 } ]
17879
null
17881
{ "accepted_answer_id": "18166", "answer_count": 1, "body": "FastCopyを使ってWindowsとLinux PC間のデータをコピーしたい。\n\nSource:LINUXのPath \nDestDir:Windowsの外付けドライブ\n\n「実行」ボタンを押しましたら、下記エラーメッセージが表示されました。\n\n> GetVolumeInformation(ログオン失敗: ユーザー名を認識できないか、またはパスワードが間違っています。\n\nLINUX側の/etc/smb.confを下記のように設定してみましたら、\n\n```\n\n [global]\n hosts allow = xxx.xxx.xxx.xxx (WindowsPC の IP Address)\n security = share\n \n [Share]\n path = /opt/FTS\n writable = yes\n guest ok = yes\n guest only = yes\n create mode = 0777\n directory mode = 0777\n share modes = yes\n \n```\n\nWindowsからLinuxへコピーができましたが、コピーできたファイルの所有者/グループが **nobody/nobody** となります。 \nコピーできましたらファイルの所有者/グループはroot/rootにしたいです。\n\n設定方法を教えていただけますか。よろしくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T02:53:42.483", "favorite_count": 0, "id": "17883", "last_activity_date": "2018-03-28T05:47:34.267", "last_edit_date": "2018-03-28T05:47:34.267", "last_editor_user_id": "3060", "owner_user_id": "12546", "post_type": "question", "score": 0, "tags": [ "linux", "windows", "samba" ], "title": "FastCopyでLinux上からファイルをコピーするとき「GetVolumeInformation ログオン失敗」と表示される", "view_count": 1376 }
[ { "body": "所有者を指定(root)する場合はsmb.conf の共有の設定で以下のようにしてください\n\nforce user = root \nforce group = root", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-28T08:46:05.157", "id": "18166", "last_activity_date": "2015-10-28T08:46:05.157", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7343", "parent_id": "17883", "post_type": "answer", "score": 1 } ]
17883
18166
18166
{ "accepted_answer_id": "17892", "answer_count": 1, "body": "monacaでタブでpage2に移動した際にボタンを押すとmodalを表示したいのですが \n<http://ja.onsen.io/reference/ons-modal.html> \nこちらを参考に入れてみたのですが全く動きません・・\n\nご教授いただけますでしょうか。\n\nindex.html\n\n```\n\n <!DOCTYPE HTML>\n <html ng-app=\"myApp\">\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 <script src=\"components/loader.js\"></script>\n <script src=\"js/app.js\"></script>\n <link rel=\"stylesheet\" href=\"components/loader.css\">\n <link rel=\"stylesheet\" href=\"css/style.css\">\n <script>\n ons.bootstrap()\n \n $(document.body).on(\"pageinit\", '#my-page', function() {\n $(\"#show-modal\", this).click(function() {\n modal.show();\n setTimeout('modal.hide()', 2000);\n });\n });\n </script>\n \n </head>\n <body>\n \n <ons-tabbar var=\"tabbar\">\n <ons-tabbar-item page=\"navigator.html\" active=\"true\">\n <div class=\"my-icon\"><img class=\"nav_img\" src=\"img/icon01.png\" alt=\"HOME\" width=\"36\" /></div>\n </ons-tabbar-item>\n <ons-tabbar-item page=\"page2_in.html\">\n <div class=\"my-icon\"><img class=\"nav_img\" src=\"img/icon02.png\" alt=\"ITEM\" width=\"36\" /></div>\n </ons-tabbar-item>\n </ons-tabbar>\n \n <ons-template id=\"navigator.html\">\n <ons-navigator title=\"Navigator\" var=\"myNavigator\" page=\"page1.html\">\n </ons-navigator>\n </ons-template>\n \n <ons-template id=\"page2_in.html\">\n <ons-navigator title=\"Navigator\" var=\"myNavigator\" page=\"page2.html\">\n </ons-navigator>\n </ons-template>\n \n </body>\n </html>\n \n```\n\npage2.html\n\n```\n\n <ons-page id=\"my-page\">\n \n <ons-toolbar fixed-style>\n <div class=\"center\">ITEM</div>\n </ons-toolbar>\n \n <div ons-loading-placeholder=\"start.html\">\n アプリケーションの読み込みを行っています...\n </div>\n <ons-template id=\"start.html\">\n \n <ons-button id=\"show-modal\" modifier=\"light\">Open Modal</ons-button>\n \n  </ons-template>\n \n <ons-modal var=\"modal\">\n <ons-icon icon=\"ion-load-c\" spin=\"true\"></ons-icon>\n <br>\n <br> Please wait.\n <br>Closing in 2 seconds.\n </ons-modal>\n \n </ons-page>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T03:49:57.033", "favorite_count": 0, "id": "17884", "last_activity_date": "2015-10-22T01:15:38.933", "last_edit_date": "2015-10-21T03:58:39.237", "last_editor_user_id": "12624", "owner_user_id": "12624", "post_type": "question", "score": 0, "tags": [ "monaca" ], "title": "monaca タブ移動したページでmodalが使用できない", "view_count": 815 }
[ { "body": "`ons-loading-placeholder`属性の要素と関連部分(`ons-template`)を削除すると動作します。 \n※一部JavaScriptも修正してあります。 \n※jQueryコンポーネントは有効。\n\n> Onsen UIが必要なフレームワーク一式の読み込みを完了するまで、読み込み中画面を表示することができます。これはOnsen\n> UIをWebアプリケーションで使用する場合に便利です。ons-loading-placeholder属性を持つ要素は、Onsen\n> UIの読み込みが完了した時点で、ons-loading-placeholder要素が参照するテンプレートに置き換わります。\n\nまずは、一つ一つの機能を把握して使用すべきだと思います。\n\nindex.html\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 <script src=\"components/loader.js\"></script>\n <script src=\"js/app.js\"></script>\n <link rel=\"stylesheet\" href=\"components/loader.css\">\n <link rel=\"stylesheet\" href=\"css/style.css\">\n <script>\n ons.bootstrap()\n ons.ready(function() {\n $(document.body).on(\"pageinit\", \"#my-page\", function() {\n $(\"#show-modal\", this).click(function() {\n modal.show();\n setTimeout(\"modal.hide()\", 2000);\n });\n });\n });\n </script>\n </head>\n <body>\n <ons-tabbar var=\"tabbar\">\n <ons-tabbar-item page=\"navigator.html\" active=\"true\">\n <div class=\"my-icon\">\n <img class=\"nav_img\" src=\"img/icon01.png\" alt=\"HOME\" width=\"36\" />\n </div>\n </ons-tabbar-item>\n <ons-tabbar-item page=\"page2_in.html\">\n <div class=\"my-icon\">\n <img class=\"nav_img\" src=\"img/icon02.png\" alt=\"ITEM\" width=\"36\" />\n </div>\n </ons-tabbar-item>\n </ons-tabbar>\n <ons-template id=\"navigator.html\">\n <ons-navigator title=\"Navigator\" var=\"myNavigator\" page=\"page1.html\"></ons-navigator>\n </ons-template>\n <ons-template id=\"page2_in.html\">\n <ons-navigator title=\"Navigator\" var=\"myNavigator\" page=\"page2.html\"></ons-navigator>\n </ons-template>\n </body>\n </html>\n \n```\n\npage2.html\n\n```\n\n <ons-page id=\"my-page\">\n <ons-toolbar fixed-style>\n <div class=\"center\">ITEM</div>\n </ons-toolbar>\n <ons-button id=\"show-modal\" modifier=\"light\">Open Modal</ons-button>\n <ons-modal var=\"modal\">\n <ons-icon icon=\"ion-load-c\" spin=\"true\"></ons-icon>\n <br>\n <br>Please wait. \n <br>Closing in 2 seconds. \n </ons-modal>\n </ons-page>\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T06:18:35.160", "id": "17892", "last_activity_date": "2015-10-22T01:15:38.933", "last_edit_date": "2015-10-22T01:15:38.933", "last_editor_user_id": "9566", "owner_user_id": "9566", "parent_id": "17884", "post_type": "answer", "score": 0 } ]
17884
17892
17892
{ "accepted_answer_id": null, "answer_count": 0, "body": "StoryBoardは使わずコードのみでTableViewを作成しています。 \nUITableViewを継承したTableViewのカスタムクラスに、2つのカスタムセルのクラスを登録し、 \nセルの行によって、UITableViewCellクラスと2つのカスタムクラスの、計三種類のセルを \nSelfSizingCellとして表示したいのですが、警告が出てしまいます。 \nTableViewの設定としては\n\n```\n\n tableView.estimatedRowHeight = 70.0\n tableView.rowHeight = UITableViewAutomaticDimension\n \n```\n\n上記のコードを書いています。 \n警告は以下です。\n\n> Warning once only: Detected a case where constraints ambiguously \n> suggest a height of zero for a tableview cell's content view. We're \n> considering the collapse unintentional and using standard height \n> instead.\n\nTableViewの高さを返すメソッド(`tableView:heightForRowAtIndexPath`)を実装すればこの警告は消えるのですが、そうするとセルの高さがすべて固定されてしまいます。 \nカスタムセルクラスが一つの場合は警告が出ないので、複数の(カスタム)セルクラスを使用していることが原因かと思っております。 \nどのようにしたら警告が出なくなるのでしょうか? \nお知恵をお貸し頂けると幸いです。 \nよろしくお願い致します。", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T05:07:23.180", "favorite_count": 0, "id": "17887", "last_activity_date": "2015-10-21T05:25:16.047", "last_edit_date": "2015-10-21T05:25:16.047", "last_editor_user_id": "7362", "owner_user_id": "12878", "post_type": "question", "score": 2, "tags": [ "ios", "swift", "xcode", "uitableview" ], "title": "UITableViewのSelfSizingCellについて", "view_count": 3240 }
[]
17887
null
null
{ "accepted_answer_id": null, "answer_count": 3, "body": "オブジェクトを非表示にするのではなくオブジェクトをn秒後になるまで使えなくするといった \n仕様にしたいのですが、方法はありますでしょうか", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T05:20:25.697", "favorite_count": 0, "id": "17888", "last_activity_date": "2015-10-21T06:40:18.860", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9268", "post_type": "question", "score": -1, "tags": [ "c#", "unity3d" ], "title": "オブジェクトを一時的に使用できないようにする方法", "view_count": 219 }
[ { "body": "一旦、オブジェクトをコピーしてn秒後に戻すとかはどうでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T05:22:48.700", "id": "17889", "last_activity_date": "2015-10-21T05:22:48.700", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12881", "parent_id": "17888", "post_type": "answer", "score": 0 }, { "body": "「使えなくする」の意図するところがまだ分かりませんが、そのオブジェクトにスクリプトを付けて(付いていればその中で)「処理中」というフラグを用意して「処理できない時間です」という判断をしたらいいかと思います。\n\n```\n\n bool isActive = false;\n \n public void StartAction() {\n if (isActive) return; // 「処理中」なので何もしない\n \n StartCoroutine(DoAction());\n }\n \n Enumerator DoAction() {\n isActive = true;\n \n // 何か処理\n \n yield return new WaitForSeconds(10.0f); // 10秒間\n isActive = false;\n }\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T06:24:35.047", "id": "17893", "last_activity_date": "2015-10-21T06:24:35.047", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2079", "parent_id": "17888", "post_type": "answer", "score": 2 }, { "body": "staticメンバに前回実行した時間を記録しておいて、メソッド実行時に現在時間と比較して、実行可能な時間帯でなければ待機する、という形で実装してみてはいかがでしょうか。 \nオブジェクトが同時に複数存在するときに、ちょっと複雑になりそうですが……。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T06:40:18.860", "id": "17894", "last_activity_date": "2015-10-21T06:40:18.860", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9515", "parent_id": "17888", "post_type": "answer", "score": 0 } ]
17888
null
17893
{ "accepted_answer_id": null, "answer_count": 3, "body": "自然言語文中にメソッド名を記述するときに、Objective-Cでは+[Foo bar]や-[Foo\nbaz:qux:]の様に書いたと思いますが、Swiftではどのように書くのが一般的でしょうか?", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T06:03:21.327", "favorite_count": 0, "id": "17890", "last_activity_date": "2020-02-08T18:32:21.887", "last_edit_date": "2015-10-21T07:33:59.993", "last_editor_user_id": "238", "owner_user_id": "238", "post_type": "question", "score": 3, "tags": [ "swift" ], "title": "Swiftのメソッドの自然言語文中での表記法", "view_count": 509 }
[ { "body": "私自身は、「自然言語文中」にこのような表記はしたことないですが、質問者さんのおっしゃる「スタックトレース」中では、下図のように、Swift環境では表示されます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/wz0wt.png)](https://i.stack.imgur.com/wz0wt.png)\n\nクラスメソッドは、`static Hoge.fuga() -> ()`とあるように、`static`で、インスタンスメソッドと区別するようです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T10:14:16.520", "id": "17898", "last_activity_date": "2015-10-21T10:14:16.520", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7362", "parent_id": "17890", "post_type": "answer", "score": 0 }, { "body": "Rubyだとインスタンスメソッドは`Range#each`のように「#」で繋いで書き、クラスメソッドは`Range.new`のように「.」で繋いで書きます。このようなドキュメントや本を書く上で標準化された表記法のルールがあるか、という質問ですよね?\n\nObjective-Cでは`+[Foo bar]`や`-[Foo\nbaz:qux:]`のように「+」と「-」で区別し、あるいは文脈でレシーバが明らかなら、`-objectsForKeys:notFoundMarker:`などと書くのが慣例的に行われてきたと思います。\n\nSwiftは今のところはっきりと決まったものは無いと思います。\n\n強いていえば単体のメソッドやfunctionはアップルのドキュメントに倣って`drawRect(_:)`のように書いている本やサイトが多いと思います。\n\nRubyのようにクラスメソッドとインスタンスメソッド(あるいはStaticメソッド)をうまく区別する表記法は無くて、区別なく`Array.append(_:)`のように単にドットで繋げて書いていることが多数のようです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T16:45:24.173", "id": "17913", "last_activity_date": "2015-10-21T16:45:24.173", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "17890", "post_type": "answer", "score": 5 }, { "body": "Swiftではありませんが、Javaはドキュメント中で`ClassName.methodName()`と表記することが正式となっています。オーバーロードを区別するための引数リストは`ClassName.methodName(Type1,\nType2, ...)`のように型名のみだったり、`ClassName.methodName(Type1 arg1, Type2 arg2,\n...)`のようにパラメータ名を含めたりすることもあります。静的メソッド(クラスメソッド)と非静的メソッド(インスタンスメソッド)で区別する記法はありません。\n\n * [javadoc - Java API ドキュメントジェネレータ](https://docs.oracle.com/javase/jp/1.5.0/tooldocs/windows/javadoc.html#@see)\n\nJavadoc形式のコメント内では`ClassName#methodName()`と表記しますが、ドキュメントジェネレータに処理させた結果として出力される文書では、`#`は`.`に置換されるようになっています。 \n※個人のブログ記事などでは文章中でも`ClassName#methodName()`と表記されていることが多いですが、おそらくJavadoc中の表記をそのまま(間違って)使っているのだと思われます。\n\nC#も`ClassName.MethodName()`の形式です。\n\n * [<see> \\- C# プログラミング ガイド | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/csharp/programming-guide/xmldoc/see)\n\nC++はスコープ解決演算子`::`を使った`ClassName::MemberFuncName()`の形式です。規格書にも頻出します。\n\n * [ISO/IEC 14882:2014, N3797 (draft)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-07T16:29:05.650", "id": "52632", "last_activity_date": "2020-02-08T18:32:21.887", "last_edit_date": "2020-02-08T18:32:21.887", "last_editor_user_id": "15413", "owner_user_id": "15413", "parent_id": "17890", "post_type": "answer", "score": 1 } ]
17890
null
17913
{ "accepted_answer_id": null, "answer_count": 1, "body": "タイトルに有る通りDB2(v9.5)にPHP5.6から接続したいのですがエラーが出て接続できません。\n\n**エラー内容**\n\n```\n\n [IBM][CLI Driver] SQL0332N Character conversion from the source code page \"819\" to the target code page \"UNKNOWN\" is not supported. SQLSTATE=57017 SQLCODE=-332\n \n```\n\n**接続元情報**\n\n * Linux Centos6.7\n * PHP 5.6\n * ibm_db2 1.9.7\n\n**接続先情報**\n\n * WindowsServer 2003 R2\n * IBM DB2 v9.5\n\n対象DBのコードセットはIBM-943になっていてUnicodeで構築されていた他DBに対してはアクセスできたので接続元環境に関しては大丈夫だと思ってます。\n\nエラーの「UNKNOWN」の部分を設定できればどうにかなると思ってたのですがWindowsの環境変数にDB2CODEPAGEをセットしたり下記コマンドを叩いても表示は変わりませんでした。\n\n```\n\n db2set DB2CODEPAGE=943\n \n```\n\n解決方法をご存じの方はよければご協力お願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T06:17:31.593", "favorite_count": 0, "id": "17891", "last_activity_date": "2015-10-31T02:49:59.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4262", "post_type": "question", "score": 2, "tags": [ "php", "database" ], "title": "IBM DB2 v9.5におけるCLI接続エラー", "view_count": 922 }
[ { "body": "自己解決できました。\n\n問題はPHP実行時に環境変数が組み込まれていないことだったので/etc/sysconfig/httpdにDB2CODEPAGE=943を追記することによって無事に接続できました。\n\nご協力感謝です。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-31T02:49:59.813", "id": "18263", "last_activity_date": "2015-10-31T02:49:59.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4262", "parent_id": "17891", "post_type": "answer", "score": 1 } ]
17891
null
18263
{ "accepted_answer_id": null, "answer_count": 0, "body": "[ドキュメント](https://www.ng.bluemix.net/docs/containers/container_optional.html#container_volumes)を参考に、単一コンテナに対して、ストレージボリュームをマウントしようとしていますが成功しません。 \nもし成功している方がいれば、次の作業に誤りがないかご指摘いただけますでしょうか。\n\n 1. ストレージボリュームの作成\n\n`cf ic volume create volume01`\n\n 2. ストレージボリュームをコンテナ起動時のオプションに指定\n\n`cf ic run -v volume01:/data2 --name container01 <コンテナイメージ>`\n\n※2.後に container01 に入って /data2 を確認しましたが、存在しませんでした。\n\nよろしくお願いいたします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T06:59:46.533", "favorite_count": 0, "id": "17895", "last_activity_date": "2015-10-21T06:59:46.533", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12882", "post_type": "question", "score": 1, "tags": [ "bluemix" ], "title": "IBM Container にストレージボリュームをマウントするには", "view_count": 140 }
[]
17895
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "Xcode7にアップデートした後、iPhone6以降のモデルのサイズ・レイアウトが崩れてしまいます。 \n(実機・シミュレータともに)\n\nTartget→General→App Icons and Launch Imagesの3つをそれぞれ\n\n①アップデート前:AppIcon、LaunchImage、空欄 \n②アップデート後:AppIcon、LaunchImage、Launch Image \nのように設定していました。\n\n①では6,6sにも対応し、②では5sまでしか対応しませんでした。 \nLaunchScreen.storyboardを追加する方法も試しましたが、 \nWatchOS storyboards do not support target device type 'iPhone' \nのエラーが出てしまい、その後進めることができませんでした。 \nこちらのエラーの解決方法も調べましたが、わかりませんでした....\n\niPhone6以降にもサイズを対応させるにはどうしたら良いでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T08:25:00.483", "favorite_count": 0, "id": "17897", "last_activity_date": "2016-08-24T14:20:32.077", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12886", "post_type": "question", "score": -1, "tags": [ "ios", "objective-c", "xcode", "iphone", "xcode7" ], "title": "Xcode7でiPhone6以降のレイアウトが崩れてしまいます", "view_count": 1111 }
[ { "body": "まず`WatchOS storyboards do not support target device type\n'iPhone'`こちらのエラーですが、おそらくwatchOS用のStoryboardがiPhone\nApp用のスキームでビルドされているのではないでしょうか。 \nStoryboardの設定で「Target Membership」を確認してみてください。\n\n様々な画面サイズに対応させるには、Auto\nLayoutを使いましょう。iOS7以降から利用できる機能です。現在はiPadも含め様々な画面サイズの端末が登場しているので、Auto\nLayoutの対応はほぼ必須だと考えてよいでしょう。余力がありましたら、Size Classesも有効にして画面の回転やiPadのSplit\nView(マルチタスキング)対応もしてみるのもよいかとおもいます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-29T06:33:19.800", "id": "18192", "last_activity_date": "2015-10-29T06:33:19.800", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12968", "parent_id": "17897", "post_type": "answer", "score": 1 } ]
17897
null
18192
{ "accepted_answer_id": "17904", "answer_count": 1, "body": "c++のlambda式から、キャプチャした変数のリストを取得することはできますか?\n\n```\n\n int x = 10;\n auto f = [x](){};\n //auto captureList = f.captureList;\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T12:59:31.037", "favorite_count": 0, "id": "17900", "last_activity_date": "2015-10-21T14:33:21.517", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8825", "post_type": "question", "score": 2, "tags": [ "c++", "c++11", "lambda" ], "title": "lambdaからcapture-listを取得する方法", "view_count": 149 }
[ { "body": "英語版で同様の質問 ([Get captured variables from\nlambda?](https://stackoverflow.com/questions/19963041/get-captured-variables-\nfrom-lambda)) がありました。結論から言うと「できない」ようです。\n\nリンク先で引用している言語仕様 (5.1.2 [expr.prim.lambda]) をざっと訳してみると\n\n * コピーキャプチャに対しては、static ではない、無名のデータメンバがクロージャ内で宣言される。その順番は規定しない。\n * 参照キャプチャに対しては、そのようなデータメンバを宣言するかどうかも規定しない。\n\nなので、キャプチャについてのメタデータはないと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T14:33:21.517", "id": "17904", "last_activity_date": "2015-10-21T14:33:21.517", "last_edit_date": "2017-05-23T12:38:55.307", "last_editor_user_id": "-1", "owner_user_id": "3605", "parent_id": "17900", "post_type": "answer", "score": 4 } ]
17900
17904
17904
{ "accepted_answer_id": null, "answer_count": 1, "body": "本当はやりたいことがあるのですが、試しにcpコマンドを書いてみました。\n\n**.travis.yml**\n\n```\n\n script:\n - cp README.md TEMP.md\n \n```\n\n設定画面は下記のようになっています。\n\n \n \n[![画像の説明をここに入力](https://i.stack.imgur.com/wyCRU.png)](https://i.stack.imgur.com/wyCRU.png)\n\n**ログ抜粋**\n\n> This job is running on container-based infrastructure, which does not \n> allow use of 'sudo', setuid and setguid executables. If you require \n> sudo, add 'sudo: required' to your .travis.yml See \n> <http://docs.travis-ci.com/user/workers/container-based-infrastructure/> \n> for details. $ rvm use default Using \n> /home/travis/.rvm/gems/ruby-1.9.3-p551 $ ruby --version ruby 1.9.3p551 \n> (2014-11-13 revision 48407) [x86_64-linux] $ rvm --version rvm 1.26.10 \n> (latest-minor) by Wayne E. Seguin , Michal \n> Papis [<https://rvm.io/]> $ bundle --version Bundler \n> version 1.7.6 $ gem --version \n> 2.4.5 $ cp README.md TEMP.md\n>\n> The command \"cp README.md TEMP.md\" exited with 0.\n>\n> Done. Your build exited with 0.\n\ngemやなんやらが動いているのが気になりますが(たぶん関係ない)、\n\n> 2.4.5 $ cp README.md TEMP.md\n>\n> The command \"cp README.md TEMP.md\" exited with 0.\n>\n> Done. Your build exited with 0.\n\nなのでうまくいってるようです。しかし特にGitHub上のmasterブランチに変化はありません。\n\n## 追記:\n\n[サイトをリニューアルした | kuune.org](http://kuune.org/text/2015/01/29/site-renewal/)\n\n引用:\n\n> 技術的な話をすると、Hugo という Go で作られた静的サイトジェネレーターを使って構築したものを GitHub Pages \n> でホストしていて、\n>\n> git push → Travis-CI でビルド → Travis-CI が gh-pages に push → 公開\n\nHugoでできたサイトをCIでビルドしているとあります。 \nおもいっきり推測なのですが、Hugoはpublicというディレクトリの下にHTMLが作られるので、ディレクトリ構成を変えていることをビルドと呼んでいると思いました(publicディレクトリを消すとか)。そういった意味でcpコマンドを試してみたのですが、何か反映させる方法があるのでしょうか?", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T13:58:42.617", "favorite_count": 0, "id": "17903", "last_activity_date": "2015-10-22T05:07:52.820", "last_edit_date": "2015-10-21T14:29:47.913", "last_editor_user_id": "9008", "owner_user_id": "9008", "post_type": "question", "score": -1, "tags": [ "travis-ci", "hugo" ], "title": "Travis CIでcpコマンドでファイルが作られていない", "view_count": 128 }
[ { "body": "テストやビルドの結果、ソースが変更されてはいけないのでは無いでしょうか。 \n変更されたら、そのソースでテスト・ビルドしなければいけませんから、無限ループです。\n\nHugoの例だと、ビルドの成果物(ソースも公開したいのならば含めても構いませんが)をソースのリポジトリとは別の公開用のリポジトリへpushする物なのではないかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T05:07:52.820", "id": "17931", "last_activity_date": "2015-10-22T05:07:52.820", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "17903", "post_type": "answer", "score": 1 } ]
17903
null
17931
{ "accepted_answer_id": "17911", "answer_count": 3, "body": "表題通りなんですが、vimでカーソル位置を維持しつつ最終行へ移動するにはどうすればよいでしょうか? \n以下のような場面で使いたいのです。\n\n例えばTSVファイルで2015/10/22の2に移動してから、CTRL-\nVで短形ヴィジュアル選択し、Gで最終行へ移動します。で、2の位置まで移動してからrキーで一文字変更しています。 \n例えばgGと入力すると、カーソル位置が維持されて移動の必要がなければ便利なんですが・・・ \n上記はあくまで例なので、置換すればいいんじゃない?等の回答もあるかと思いますが、 \nあくまで、かーする位置を維持しつつ最終行へ移動する方法が知りたいです。\n\nわかりにくい説明かと思いますが、 \nよろしくおねがいします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T15:16:44.133", "favorite_count": 0, "id": "17908", "last_activity_date": "2015-10-22T12:31:15.363", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12888", "post_type": "question", "score": 5, "tags": [ "vim" ], "title": "vimでカーソル位置を維持しつつ最終行へ移動", "view_count": 526 }
[ { "body": "vimrc に、\n\n```\n\n set nostartofline\n \n```\n\nと書いてみてください。詳しくは `:help 'startofline'` を参照してください。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-21T15:24:29.240", "id": "17911", "last_activity_date": "2015-10-21T15:24:29.240", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2541", "parent_id": "17908", "post_type": "answer", "score": 5 }, { "body": "thincaさんの回答がBestだと思います。 \n一応、デフォルト(`set startofline`)の場合の方法も紹介しますね。\n\n```\n\n <C-V>GOm`O``\n \n```\n\n`<C-V>` 矩形ビジュアルモード開始 (`:h ctrl-v`) \n`G` 最終行の最初の非空白文字に移動 (`:h G`) \n`O` 同じ行内のビジュアル選択されたもう一方の隅(右)に移動 (`:h v_O`) \n`m`` カーソル位置を直前位置マークにセット (`:h m``) \n`O` 同じ行内のビジュアル選択されたもう一方の隅(左)に移動 \n```` ビジュアル選択左隅を`m``がおこなわれた位置(== ビジュアル選択右隅の位置)にセット (`:h ```)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T02:35:18.777", "id": "17920", "last_activity_date": "2015-10-22T02:35:18.777", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2687", "parent_id": "17908", "post_type": "answer", "score": 1 }, { "body": "「`<C-V>9999j`でいいのでは?」という私のボケに対するツッコミを待っていたのだけど誰からも入らなかったので自分で書いときます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T12:31:15.363", "id": "17959", "last_activity_date": "2015-10-22T12:31:15.363", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2687", "parent_id": "17908", "post_type": "answer", "score": 2 } ]
17908
17911
17911
{ "accepted_answer_id": "18156", "answer_count": 1, "body": "iOSアプリでAsset\nCatalogを使うことで画像管理が楽になりますが、最終的なユーザーのダウンロードするアプリサイズは、最適化したもののみ取得することになっているのでしょうか? \n例えばiPad用の画像はiphoneにはダウンロードされない、といったように。 \nだとすれば、iphone6ユーザーに対し、Asset\nCatalogに@3xの画像や、ipadの画像を設定しても、ほとんど影響を受けないということでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T01:11:28.627", "favorite_count": 0, "id": "17915", "last_activity_date": "2015-10-28T04:28:11.573", "last_edit_date": "2015-10-26T00:06:45.707", "last_editor_user_id": "2772", "owner_user_id": "2772", "post_type": "question", "score": 0, "tags": [ "ios", "swift", "xcode" ], "title": "iOSアプリはAsset Catalogを使うことで、ユーザーがApp Storeでダウンロードする画像ファイルを最適化してくれるのでしょうか?", "view_count": 417 }
[ { "body": "App Slicingが有効な端末に対しては、必要なリソースのみダウンロードされる仕組みになっています。\n\n> App Slicing Now Available October 5, 2015\n>\n> The issue affecting app slicing has been fixed, and device-specific \n> versions of apps will be delivered when downloaded by users running \n> iOS 9.0.2 or later.\n\n<https://developer.apple.com/news/>\n\niOS 9.0.2 からApp Slicingが有効になっています。\n\n> Note: Sliced apps are supported on devices running 9.0 and later; \n> otherwise, the store delivers universal apps to customers.\n\niOS 9.0 以前の端末は対象外です。 \n詳しくは「App Thining」についてのApple公式ドキュメントをご参考ください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-28T04:28:11.573", "id": "18156", "last_activity_date": "2015-10-28T04:28:11.573", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12968", "parent_id": "17915", "post_type": "answer", "score": 5 } ]
17915
18156
18156
{ "accepted_answer_id": null, "answer_count": 2, "body": "ffmpegのインストールが無事に終わり、いざffmpegのコマンドを実行すると以下のエラーが表示されました。\n\n```\n\n ffmpeg: error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No such file or directory\n \n```\n\nこのようなエラーが起きたら `export LD_LIBRARY_PATH=\"/usr/local/lib\"`\nを実行すればコマンドが使えるようになるという記事を見つけたので、使ったら無事ffmpegを実行できました。\n\nしかし問題があって、私はRaspberry Pi\nB+にffmpegを入れて使っているのですが、Raspiをsshで操作するたびにffmpegのリンクが切れているみたいで上記のエラーが起きます。\n\nその度にexportを使うのも面倒なのでちゃんとファイルを読みにいくようにしたいのですが、どうすればいいでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2015-10-22T02:06:21.260", "favorite_count": 0, "id": "17917", "last_activity_date": "2022-05-07T21:39:33.827", "last_edit_date": "2022-05-07T05:29:24.910", "last_editor_user_id": "3060", "owner_user_id": "9349", "post_type": "question", "score": 1, "tags": [ "raspberry-pi", "ffmpeg" ], "title": "ffmpeg の動作に必要な共有ライブラリのパスを設定したい", "view_count": 1512 }
[ { "body": "```\n\n echo 'export LD_LIBRARY_PATH=\"/usr/local/lib:$LD_LIBRARY_PATH\"' >> ~/.bashrc\n \n```\n\nこれを実行するとbashを起動するたびにLD_LIBRARY_PATHが設定されます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2022-05-06T12:55:01.017", "id": "88672", "last_activity_date": "2022-05-06T12:55:01.017", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "52506", "parent_id": "17917", "post_type": "answer", "score": 2 }, { "body": "空の`/etc/ld.so.conf.d/00-ffmpeg.conf`ファイルを作って、中に`/usr/local/lib`と書いて下さい。詳しくは`man\nldconfig`にあります。 \n \nこうすれば`~/.bashrc`を汚さずに済みます。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2022-05-07T21:39:33.827", "id": "88693", "last_activity_date": "2022-05-07T21:39:33.827", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "35709", "parent_id": "17917", "post_type": "answer", "score": 1 } ]
17917
null
88672
{ "accepted_answer_id": null, "answer_count": 0, "body": "solr 4.10で下記のsqlのようなJOINして各core内の要素を取得する方法がわからずハマっております。\n\n```\n\n SELECT\n child.*,parent.*\n FROM child \n JOIN parent\n WHERE child.parent_id=parent.id AND parent.tag='hoge'`\n \n```\n\nchildとparentは多対一の関係でparentが複数になることはありません。 \n下記の通り試したところ、WHERE句は問題なく指定できましたがSELECT句でparentの要素を取ることができない状態です。\n\n```\n\n select?q={!join from=parent_id to=id fromIndex=parent}id:1+tag:hoge\n \n```\n\n自分で調べた感じでは無理なのではという気もしておりますが、ご教示のほどよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T02:19:28.160", "favorite_count": 0, "id": "17918", "last_activity_date": "2015-10-22T04:37:09.300", "last_edit_date": "2015-10-22T04:37:09.300", "last_editor_user_id": "754", "owner_user_id": "3827", "post_type": "question", "score": 3, "tags": [ "java", "solr" ], "title": "solr 4.10で 異なるcore間のデータをjoinして要素を取得する方法は?", "view_count": 400 }
[]
17918
null
null
{ "accepted_answer_id": "17949", "answer_count": 2, "body": "システムをrubyのバージョンをアップ(ruby 1.9.2p320⇒2.2.3)しました。Railsのバージョンは3.2.19\nDBはMySQLを使用しています。 \nテストを実行したところエラーが発生し以下のようなエラーが発生しました。\n\n```\n\n Failures:\n \n 1) …の場合は、 そのまま例外をraiseする。\n Failure/Error: lambda{Job.find_by_id(@conn, 0)}.should raise_error(ex)\n expected Unauthorized but nothing was raised\n \n```\n\nプロダクトコードは以下のようでテストでmrqを実行したときに任意のエラーを発生させようとしてます。\n\n```\n\n def self.find_by_id(conn, id)\n options = {…}\n response = Job.mrq(conn, options)\n \n```\n\nテストコードです。\n\n```\n\n before(:each) do\n Job.should_receive(:mrq).and_raise(ex)\n end\n context \"…の場合は、\" do\n let(:ex){SomeError.new(\"Unauthorized\", 401)}\n it \"そのまま例外をraiseする。\" do\n lambda{Job.find_by_id(@conn, 0)}.should raise_error(ex)\n end\n end\n \n```\n\nrspec (2.11.0)を使用してます。ruby 1.9.2では動作していました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T02:31:54.777", "favorite_count": 0, "id": "17919", "last_activity_date": "2015-10-23T04:11:42.627", "last_edit_date": "2015-10-22T10:18:06.070", "last_editor_user_id": "2599", "owner_user_id": "10851", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "ruby", "rspec" ], "title": "RSpecでエラーを発生させたいのにnothing was raisedと出る", "view_count": 2471 }
[ { "body": "本当にRubyのバージョンアップがテスト失敗の原因なのでしょうか? \nテストコードも本番コードも変更していないのに、バージョンアップ後にテストが失敗するようになったのでしょうか?\n\nとりあえず、コードを見たところ `mrq` にスタブを当てているのに、テストコードの中では `find_by_id` が呼ばれているように見えます。\n\n正しくはこうなるのではないでしょうか?\n\n```\n\n before(:each) do\n Job.should_receive(:mrq).and_raise(ex)\n end\n context \"…の場合は、\" do\n let(:ex){SomeError.new(\"Unauthorized\", 401)}\n it \"そのまま例外をraiseする。\" do\n # find_by_id => mrq\n lambda{Job.mrq(@conn, 0)}.should raise_error(ex)\n end\n end\n \n```\n\n## 追記\n\n以下のように書くと結果はどうなりますか?\n\n```\n\n context \"…の場合は、\" do\n let(:ex){SomeError.new(\"Unauthorized\", 401)}\n it \"そのまま例外をraiseする。\" do\n Job.should_receive(:mrq).and_raise(ex)\n Job.find_by_id(@conn, 0)\n end\n end\n \n```\n\n`:mrq`が呼ばれなかったという理由でFailするようであれば、そもそもfind_by_idでJob.mrqが呼ばれるようなフローになっていないのかもしれません。(意図しない条件分岐に入ってしまっている等)\n\nまた、find_by_idの実装を以下のように極端にシンプルに変えると確実にスタブが呼ばれてエラーが発生する、つまりテストがパスするはずです。これも試してみてください。\n\n```\n\n def self.find_by_id(conn, id)\n Job.mrq(conn, nil)\n end\n \n```\n\nこのように、「エラーの原因の仮説を立てる」「仮説が正しいことを検証できるコードを書く」「結果を確認する」「期待した結果が得られない(=仮説が間違っていた)場合は別の仮説を立てる」「コードを書いて実行する」・・・(以下繰り返し)、というような「当たり前のデバッグ手順」を踏んで原因を絞り込んでいくしかないかなーという気がします。 \nまた、デバッガを使ってステップ実行していくのも有効でしょう。\n\n質問で書かれているコード自体は大きな問題がないように見えます。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T03:54:51.013", "id": "17926", "last_activity_date": "2015-10-22T08:41:49.873", "last_edit_date": "2015-10-22T08:41:49.873", "last_editor_user_id": "85", "owner_user_id": "85", "parent_id": "17919", "post_type": "answer", "score": 1 }, { "body": "ドキュメントに書いてあるように、`raise_error`マッチャ―の引数に渡すのは例外クラスです。例外クラスのインスタンスではありません。 \n<https://www.relishapp.com/rspec/rspec-expectations/v/2-11/docs/built-in-\nmatchers/raise-error-matcher>\n\n以下のように、`SomeError`クラスを渡すようにすると通ると思います。\n\n```\n\n lambda{Job.find_by_id(@conn, 0)}.should raise_error(SomeError)\n \n```\n\nより詳しく例外オブジェクトについて検証したいのであれば、ブロックを渡して検証するといいです。\n\n```\n\n lambda{Job.find_by_id(@conn, 0)}.should raise_error(SomeError) {|e| e.should eq ex }\n \n```\n\n<https://www.relishapp.com/rspec/rspec-expectations/v/2-11/docs/built-in-\nmatchers/raise-error-matcher#set-expectations-on-error-object-passed-to-block>\n\n## なぜRubyのバージョンを上げて落ちるようになったか\n\n内部の実装的には、`raise_error`マッチャーの引数に渡した値が`rescue`節に渡ります。 \n<https://github.com/rspec/rspec-\nexpectations/blob/v2.11.0/lib/rspec/matchers/built_in/raise_error.rb#L23>\n\n以下のように、`rescue`に例外クラスのインスタンスを渡すようなプログラムが、Ruby 1.9.2では実行出来るが、Ruby\n2.2.3では実行できなくなったため、バージョンアップで落ちるようになったのではないでしょうか。\n\n```\n\n class FooError < StandardError; end\n bar = FooError.new\n begin; raise bar; rescue bar => e; p e; end\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T09:05:56.167", "id": "17949", "last_activity_date": "2015-10-23T04:11:42.627", "last_edit_date": "2015-10-23T04:11:42.627", "last_editor_user_id": "2599", "owner_user_id": "2599", "parent_id": "17919", "post_type": "answer", "score": 3 } ]
17919
17949
17949
{ "accepted_answer_id": null, "answer_count": 1, "body": "名前を強く押された(Peek)ら連絡先情報を表示しようとしています。\n\nUIViewControllerPreviewingDelegateの \npreviewingContext:viewControllerForLocation:で \n[CNContactViewController\nviewControllerForContact:contact];を使ってCNContactViewControllerのインスタンスを取得しています。\n\nしかし、テストすると表示される人と表示されない人があり表示されない場合は\n\nplugin com.apple.MobileAddressBook.ContactViewViewService interrupted \nviewServiceDidTerminateWithError:: Error\nDomain=_UIViewServiceInterfaceErrorDomain Code=3 \"(null)\"\nUserInfo={Message=Service Connection Interrupted}\n\nというログが書き出されています。 \n表示される・されない人は常に同じなので、連絡先データが関連しているようにも思えます。\n\n何をチェックすればいいのでしょうか?\n\nちなみに実機(iOS 9.0.2, iOS 9.1)でテストしています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T02:38:19.870", "favorite_count": 0, "id": "17921", "last_activity_date": "2015-10-22T08:43:49.867", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9033", "post_type": "question", "score": 2, "tags": [ "ios" ], "title": "CNContactViewControllerをPeekしようとすると真っ白い画面になることがある", "view_count": 318 }
[ { "body": "その後のテストでUINavigationControllerに含まれていると問題ないことがわかりました。しかし、それだと問題があるのでその方法は使えません。\n\n解決策としてCNContactViewControllerのdisplayedPropertyKeysに任意の項目だけを指定することで回避することができました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:43:49.867", "id": "17942", "last_activity_date": "2015-10-22T08:43:49.867", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9033", "parent_id": "17921", "post_type": "answer", "score": 2 } ]
17921
null
17942
{ "accepted_answer_id": "18207", "answer_count": 1, "body": "お世話になります \nonsen-\nui+angularJSを使用してアプリケーションを作成したところ、オーバーライドしたAngularJSの$exceptionHandlerが実行されたり、されなかったりするという現象が発生しました。 \nいろいろ調べたのですが、法則性が見つからず原因が特定できません。\n\n代表的なものとして、通常の例外は$exceptionHandlerがキャッチしてくれるのですが、 \nons.ready内で発生した例外は$exceptionHandlerでキャッチしてくれません。\n\n```\n\n // オーバーライドした$exceptionHandler\n (function () {\n \"use strict\"; \n angular.module('App')\n .factory('$exceptionHandler', ['$window', function ($window) {\n return function (exception) {\n $window.alert(exception);\n };\n }]);\n }());\n \n```\n\n```\n\n // オーバーライドした$exceptionHandlerがキャッチしてくれるケース\n angular.module('App').controller(\n 'ExceptionController', ['$scope', function ($scope) {\n throw new Error(\"ErrorTest\");\n }]);\n \n```\n\n```\n\n // オーバーライドした$exceptionHandlerがキャッチしてくれないケース\n angular.module('App').controller(\n 'ExceptionController', ['$scope', function ($scope) {\n ons.ready(function () {\n throw new Error(\"ErrorTest\");\n });\n }]);\n \n```\n\nこのほかにも、ons-navigatorタグで指定したng-\ncontrollerのコントローラー内で発生した例外はオーバーライドした$exceptionHandlerがキャッチしてくれますが、ons-\npageタグで指定したng-controllerのコントローラー内で発生した例外はキャッチしてくれないなどのケースがあります。\n\n原因をご存知の方がおられたらご教授のほどよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T03:12:00.893", "favorite_count": 0, "id": "17924", "last_activity_date": "2015-10-29T12:58:26.933", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12895", "post_type": "question", "score": 2, "tags": [ "monaca", "onsen-ui", "angularjs", "cordova" ], "title": "Onsen-UI上でオーバーライドした$exceptionHandlerが実行されない", "view_count": 237 }
[ { "body": "Angularのソースにコメントがありました。\n\n> Note, that code executed in event-listeners (even those registered \n> using jqLite's `on`/`bind` methods) does not delegate exceptions to \n> the {@link ng.$exceptionHandler $exceptionHandler} (unless executed \n> during a digest).\n>\n> If you wish, you can manually delegate exceptions, e.g. \n> `try { ... } catch(e) { $exceptionHandler(e); }`\n\nイベントリスナ内で発生した例外は、digestループ中でない限り$exceptionHandlerには渡らないとあります。`ons.ready()`の引数に指定した関数は`$ons-\nready`イベントのハンドラ内で実行されるため、上記のケースにあたります。 \nちなみに、`$scope.$apply()`で囲むとちゃんとアラートで表示されました。\n\n```\n\n ons.ready(function(){\n $scope.$apply(function() {\n throw 'error';\n });\n });\n \n```\n\n`<ons-page>`タグで指定したコントローラ内の例外をキャッチしないという件は、こちらでは再現しませんでした。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-29T12:58:26.933", "id": "18207", "last_activity_date": "2015-10-29T12:58:26.933", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8532", "parent_id": "17924", "post_type": "answer", "score": 0 } ]
17924
18207
18207
{ "accepted_answer_id": "17958", "answer_count": 4, "body": "RとRubyによるデータ解析入門という本のサンプルコードにて、\n\nplotがpdfでは保存されているのですが、Rstudioの右下にあるplot paneでは表示できません。\n\nたとえば実装例4-9などです。該当コードのサンプルリポジトリは \n<https://github.com/setoyama60jp/everyday/tree/master/Chapter4> \nにあります。\n\nなぜ右下にあるplot paneには表示されないのでしょうか? \nまた、どうすれば表示されるようになりますか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T04:16:36.983", "favorite_count": 0, "id": "17927", "last_activity_date": "2017-02-07T08:22:07.310", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12896", "post_type": "question", "score": 0, "tags": [ "r" ], "title": "Rstudioでplot paneにプロットできない問題", "view_count": 16535 }
[ { "body": "Rではグラフの出力先を変更することが出来ます。 \nコード内にあるpdf()の部分を実行せずにプロットすれば、Rstudioの右下に表示されると思います。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T04:37:33.227", "id": "17928", "last_activity_date": "2015-10-22T04:37:33.227", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12897", "parent_id": "17927", "post_type": "answer", "score": 0 }, { "body": "※ スクリーンショットを載せます\n\n以下の様に `print()` で囲んで実行します。\n\n**example4-5.r**\n\n```\n\n ##pdf(\"figure4-2.pdf\")\n :\n print(ggplot(data = df) + scale_shape_manual(name=\"Type\", values=c(2,3,4)) + \n geom_smooth(aes(x = population, y = mean)) +\n geom_point(aes(x = population, y = mean, shape = \"mean\")) +\n geom_smooth(aes(x = population, y = median)) +\n geom_point(aes(x = population, y = median, shape = \"median\")) + \n geom_smooth(aes(x = population, y = max)) +\n geom_point(aes(x = population, y = max, shape = \"max\")) +\n scale_y_continuous(\"queue size\") +\n scale_x_continuous(\"population\"))\n \n```\n\nもしくは、`ggplot` の結果を変数にバインドして `print()` か `plot()` を実行します。\n\n```\n\n plt <- ggplot(data = df) + ...\n print(plt) ## or plot(plt)\n \n```\n\n**Screenshot**\n\n[![screenshot](https://i.stack.imgur.com/ATPw1.png)](https://i.stack.imgur.com/ATPw1.png)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T07:35:51.167", "id": "17935", "last_activity_date": "2015-10-22T08:04:48.517", "last_edit_date": "2015-10-22T08:04:48.517", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "17927", "post_type": "answer", "score": 0 }, { "body": "いちど`pdf()`で出力先を変えた後は、`dev.off()`でその出力先を閉じるまでそのPDFファイルに出力されつづけます。\n\n`dev.off()`を何度か実行するか、Session > Restart\nR(Ctrl+Shift+F10)でRのセッションを再起動してみても同じでしょうか?(RStudioは、アプリケーションを閉じてもセッションが保存されるので、明示的にセッションを再起動する必要があります。設定にもよりますけど)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T12:24:46.107", "id": "17958", "last_activity_date": "2015-10-22T12:24:46.107", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2544", "parent_id": "17927", "post_type": "answer", "score": 1 }, { "body": "[![R Studio Global\noptions](https://i.stack.imgur.com/PE84P.png)](https://i.stack.imgur.com/PE84P.png)\n\nR StudioのGlobal Options内にある,R Markdownを選んで,Show output inline for\n...のチェックを外せば良いのではないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-02-07T08:22:07.310", "id": "32456", "last_activity_date": "2017-02-07T08:22:07.310", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20546", "parent_id": "17927", "post_type": "answer", "score": 0 } ]
17927
17958
17958
{ "accepted_answer_id": "17939", "answer_count": 1, "body": "twitter auth を使用したRailsアプリケーションをherokuにアップロード後、'auth/twitter'へのボタンを押すと \nWe're sorry, but something went wrong.という画面が出ます。\n\nherokuのログを見てみると、\n\n```\n\n Started GET \"/auth/twitter\" for ***.**.***.** at 015-10-22 03:19:23 +0000\n \n OAuth::Unauthorized (400 Bad Request):\n \n vendor/bundle/ruby/2.0.0/gems/oauth-0.4.7/lib/oauth/consumer.rb:216:in `token_request'\n ...\n 015-10-22T03:19:23.433349+00:00 heroku[router]: at=info method=GET path=\"/auth/twitter\" host=*******.herokuapp.com request_id=*** fwd=\"***\" dyno=web.1 connect=2ms service=103ms status=500 bytes=1754\n \n```\n\nと出力されます。 \nローカルの開発環境では問題なく動作するため、リンクの指定等、プログラムには問題ないのではと踏んでいます。 \n`heroku run rake db:migrate`も何度も試しましたが、うまく動作しません。\n\nお力添えお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T06:09:31.513", "favorite_count": 0, "id": "17933", "last_activity_date": "2015-10-22T08:46:41.913", "last_edit_date": "2015-10-22T08:45:41.093", "last_editor_user_id": "85", "owner_user_id": "11188", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "heroku" ], "title": "twitter auth 400 bad request", "view_count": 759 }
[ { "body": "Heroku用のTwitter appを新たに作成し、Twitter app側もRails側もHeroku用の設定を施す必要があります。\n\n具体的には\n\n * Rails側でHeroku用Twitter appのkeyやsecretを使っているか(ちゃんと値が設定されているか)\n * Twitter app側でHeroku用のコールバックURLが指定されているか\n\nこのあたりをしっかり確認する必要があると思います。\n\n下記のページも参考になるかもしれません。\n\n[gem 'omniauth-twitter'で認証しようとしてOAuth::Unauthorized 401 Unauthorizedなんてエラーがでたら\n- Qiita](http://qiita.com/hirokishirai/items/5a43977a38ecd922bfb9)\n\nそれでもダメであれば、具体的に試行錯誤した内容やその結果、Twitter関連のコード、スタックトレースの全体等を追記してください。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:22:23.197", "id": "17939", "last_activity_date": "2015-10-22T08:46:41.913", "last_edit_date": "2015-10-22T08:46:41.913", "last_editor_user_id": "85", "owner_user_id": "85", "parent_id": "17933", "post_type": "answer", "score": 0 } ]
17933
17939
17939
{ "accepted_answer_id": "17988", "answer_count": 1, "body": "タイトルの通りですが、 PHPUnit + Selenium 2 + PhantomJS で `<input type=\"file\">` のテストの書き方(\n`<input type=\"file\">` に値を入力する方法)がわからず困っています。 \n(そもそも `<input type=\"file\">` に対して PHPUnit から値を入力することが可能なのでしょうか...?)\n\n下記は想定通り動作しなかったコードです。\n\n```\n\n $element = $this->byCssSelector('input[type=\"file\"][name=\"file\"]');\n $element->value('/path/to/dummyimage01.png');\n \n```\n\n上記コードでは `<input type=\"file\" name=\"file\">` には何も入力されていませんでした。\n\n当方の環境は下記の通りです。\n\n * Mac OSX El Capitan (10.11.1)\n * PHP: 5.5.24\n * PHPUnit: 4.8.6\n * Selenium: 2.47.1\n * PhantomJS: 2.0.0", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T06:46:17.107", "favorite_count": 0, "id": "17934", "last_activity_date": "2015-10-23T10:47:35.933", "last_edit_date": "2015-10-22T11:48:09.537", "last_editor_user_id": "8160", "owner_user_id": "8160", "post_type": "question", "score": 0, "tags": [ "php" ], "title": "PHPUnit + Selenium 2 + PhantomJS で <input type=\"file\"> のテストの書き方", "view_count": 572 }
[ { "body": "PHPUnit + Selenium 2でのアップロードのファイルの指定の仕方は、 \n<https://github.com/giorgiosironi/phpunit-\nselenium/blob/a6fdffdd56f4884ef39e09a9c62e5e4eb273e42c/Tests/Selenium2TestCase/SessionCommand/FileTest.php#L10> \nにあるように以下のようにします。\n\n```\n\n $remote_file = $this->file('selenium-1-tests/html/banner.gif');\n \n```\n\n上記のコードそのままですが、アップロードは例えば以下のようになります。\n\n```\n\n $this->url('php/file_upload.php');\n $remote_file = $this->file('selenium-1-tests/html/banner.gif');\n $this->byName('upload_here')\n ->value($remote_file);\n $this->byId('submit')\n ->click();\n \n```\n\nこれで動作するはずですが、PhantomJS 2.0のファイルアップロードは壊れており機能しません。 \n<https://github.com/ariya/phantomjs/issues/12506> \nこれは、2.0.1で修正予定とのことです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-23T10:47:35.933", "id": "17988", "last_activity_date": "2015-10-23T10:47:35.933", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5489", "parent_id": "17934", "post_type": "answer", "score": 1 } ]
17934
17988
17988
{ "accepted_answer_id": null, "answer_count": 1, "body": "```\n\n git clone \n Cloning into\n Username for '\n Password for '\n remote: Counting objects: 50195, done.\n  remote: Compressing objects: 100% (28896/28896), done.\n  fatal: The remote end hung up unexpectedly6 MiB | 724.00 KiB/s\n  fatal: early EOF\n  fatal: index-pack failed\n \n```\n\nとなり \ngitlab.comのおなじ質問から (<https://gitlab.com/gitlab-org/omnibus-gitlab/issues/138>)\n\n```\n\n unicorn['worker_timeout'] = 60 \n \n```\n\nを\n\n```\n\n unicorn['worker_timeout'] = 600\n \n```\n\nに変えたのですがやはり出来ない状態です。 \n後は何が考えられますでしょうか", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T07:43:17.227", "favorite_count": 0, "id": "17936", "last_activity_date": "2016-10-10T14:11:19.117", "last_edit_date": "2016-10-10T14:11:19.117", "last_editor_user_id": "754", "owner_user_id": "12901", "post_type": "question", "score": 0, "tags": [ "gitlab" ], "title": "gitlabでcloneが The remote end hung up unexpectedly, early EOF エラーになる", "view_count": 600 }
[ { "body": "OP がコメントで言及されていたのですが、 `git gc` で解決したそうです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2016-10-10T13:58:30.687", "id": "29462", "last_activity_date": "2016-10-10T13:58:30.687", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "754", "parent_id": "17936", "post_type": "answer", "score": 1 } ]
17936
null
29462
{ "accepted_answer_id": null, "answer_count": 1, "body": "ログイン前提のAPIたちのテストケースを作成したいのですが、前段としてログイン処理が必要になります。 \nテスト実行前にログイン処理をして、その戻り値(セッションID)を使い回してテストケースを実行する必要があるのですがどうすればよいでしょうか? \nログイン処理は一回だけで済ませたいです。 \nこのまま実行すると`Could not create an instance of HogeSpec`とインスタンス化できないと言われてしまいます。\n\n```\n\n class HogeSpec extends Specification {\n \n // このuserSessionIdを各テストケースで使いたい\n val userSessionId = BaseSpec.beforeAuth()\n \n \"hogeAPIのテスト\" should {\n \"ステータス200が返ってくること\" in {\n // do something\n // userSessionIdを使ってAPIをテストしたい\n }\n }\n \n \"fugaAPIのテスト\" should {\n \"ステータス200が返ってくること\" in {\n // do something\n // userSessionIdを使ってAPIをテストしたい\n }\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:08:32.443", "favorite_count": 0, "id": "17937", "last_activity_date": "2016-04-20T10:05:58.887", "last_edit_date": "2015-10-22T09:29:10.033", "last_editor_user_id": "3397", "owner_user_id": "3397", "post_type": "question", "score": 1, "tags": [ "scala", "playframework" ], "title": "specs2でテスト実行前に共通の処理をしたい", "view_count": 158 }
[ { "body": "自己解決しました。\n\n`lazy`で遅延評価にすることでエラーの回避ができました。 \nこれでuserSessionIdを使い回せるようになりました。 \n特別`BeforeExample`などを使う必要はありませんでした。\n\n```\n\n - val userSessionId = BaseSpec.beforeAuth()\n + lazy val userSessionId = BaseSpec.beforeAuth()\n \n```\n\nこちらの解答が参考になったので共有します。 \n<https://stackoverflow.com/questions/21830495/specs2-could-not-create-an-\ninstance>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-23T01:35:28.140", "id": "17962", "last_activity_date": "2015-10-23T01:35:28.140", "last_edit_date": "2017-05-23T12:38:56.083", "last_editor_user_id": "-1", "owner_user_id": "3397", "parent_id": "17937", "post_type": "answer", "score": 1 } ]
17937
null
17962
{ "accepted_answer_id": "17941", "answer_count": 1, "body": "よろしくお願いします。\n\nとあるDBを、c#でSQLiteを使って作りたいです。\n\nWindowsFormアプリケーションで使用するので、 \nVisualStdio Community 2015 で作成しています。\n\nWindows8.1です。\n\nテーブルを作成するクリエイト文で、\n\n> 型 'System.Data.SQLite.SQLiteException' のハンドルされていない例外が \n> System.Data.SQLite.dll で発生しました\n>\n> 追加情報:SQL logic error or missing database\n>\n> near \"(\": syntax error\n\nというエラーが発生します。\n\nコードは以下の通りです。\n\n```\n\n namespace WindowsFormsApplication1\n {\n public partial class Form1 : Form\n {\n public Form1()\n {\n InitializeComponent();\n \n /****** DB,TABLE,レコード作成のソースコード******/\n \n //dbファイル名\n string db_file = \"test.db\";\n \n //db接続\n using (var conn = new SQLiteConnection(\"Data Source=\" + db_file))\n {\n //dbを開く\n conn.Open();\n \n //コマンド生成宣言\n using (SQLiteCommand command = conn.CreateCommand())\n {\n //create文格納\n command.CommandText = \"create table AAA(aaa_cd TEXT(2) PRIMARY KEY NOT NULL, aaa_nm TEXT(40) NOT NULL)\";\n //コマンド実行\n command.ExecuteNonQuery();\n }\n \n //コマンド生成宣言\n using (SQLiteCommand command1 = conn.CreateCommand())\n {\n command1.CommandText = \"create table BBB(bbb_cd TEXT(4) PRIMARY KEY NOT NULL, bbb_nm(40) TEXT NOT NULL)\";\n command1.ExecuteNonQuery();\n }\n \n //コマンド生成宣言\n using (SQLiteCommand command2 = conn.CreateCommand())\n {\n \n command2.CommandText = \"create table CCC(aaa_cd TEXT(2) PRIMARY KEY NOT NULL, bbb_cd TEXT(4) NOT NULL)\";\n command2.ExecuteNonQuery();\n }\n \n //トランザクション処理\n using (SQLiteTransaction sqlt = conn.BeginTransaction())\n {\n //コマンド生成宣言\n using (SQLiteCommand command = conn.CreateCommand())\n {\n //List<AAA>のレコード一覧をforeachで回しながらTABLEに格納する処理\n foreach (AAATable m in mList)\n {\n //insert文格納\n command.CommandText = \"insert into AAA(aaa_cd,aaa_nm) values('\" + m.aaa_cd + \"', '\" + m.aaa_nm + \"')\";\n //コマンド実行\n command.ExecuteReader();\n }\n \n //List<BBBTable>のレコード一覧をforeachで回しながらTABLEに格納する処理\n foreach (BBBTable m in mList2)\n {\n //insert文格納\n command.CommandText = \"insert into BBB(bbb_cd,bbb_nm) values('\" + m.bbb_cd + \"', '\" + m.bbb_nm + \"')\";\n //コマンド実行\n command.ExecuteReader();\n }\n \n //List<CCCTable>のレコード一覧をforeachで回しながらTABLEに格納する処理\n foreach (CCCTable m in mList3)\n {\n //insert文格納\n command.CommandText = \"insert into CCC(aaa_cd,bbb_cd) values('\" + m.aaa_cd + \"', '\" + m.bbb_cd + \"')\";\n //コマンド実行\n command.ExecuteReader();\n }\n }\n //トランザクション処理終了\n sqlt.Commit();\n }\n \n //dbを閉じる\n conn.Close();\n }\n \n /**************************************\n ここから各Tableのダミーデータ作成\n **************************************/\n \n //AAATableのダミーデータ作成\n private class AAATable\n {\n public string aaa_cd;\n public string aaa_nm;\n \n public AAATable(string _aaa_cd, string _aaa_nm)\n {\n aaa_cd = _aaa_cd;\n aaa_nm = _aaa_nm;\n }\n }\n \n //BBBTableのダミーデータ作成\n private class BBBTable\n {\n public string bbb_cd;\n public string bbb_nm;\n \n public BBBTable(string _bbb_cd, string _bbb_nm)\n {\n bbb_cd = _bbb_cd;\n bbb_nm = _bbb_nm;\n }\n }\n \n //CCCTableのダミーデータ作成\n private class CCCTable\n {\n public string aaa_cd;\n public string bbb_cd;\n \n public CCCTable(string _aaa_cd, string _bbb_cd)\n {\n aaa_cd = _aaa_cd;\n bbb_cd = _bbb_cd;\n }\n }\n \n /************* ここまで **************/\n \n /**************************************\n ここから格納するレコード一覧 \n **************************************/\n \n //AAATablに格納するレコード一覧\n List<AAATable> mList = new List<AAATable>()\n {\n new AAATable(@\"xx\",@\"あああ\"),\n new AAATable(@\"yy\",@\"いいい\"),\n new AAATable(@\"zz\",@\"ううう\"),\n };\n \n //BBBTableに格納するレコード一覧\n List<BBBTable> mList2 = new List<BBBTable>()\n {\n new BBBTable(@\"u\",@\"わ\"),\n new BBBTable(@\"v\",@\"を\"),\n new BBBTable(@\"w\",@\"ん\"),\n };\n \n //CCCTableに格納するレコード一覧\n List<CCCTable> mList3 = new List<CCCTable>()\n {\n new CCCTable(@\"xx\",@\"u\"),\n new CCCTable(@\"yy\",@\"v\"),\n new CCCTable(@\"zz\",@\"w\"),\n };\n \n /************* ここまで **************/\n }\n }\n \n```\n\nこの中で、\n\n```\n\n //コマンド生成宣言\n using (SQLiteCommand command1 = conn.CreateCommand())\n {\n command1.CommandText = \"create table BBB(bbb_cd TEXT(4) PRIMARY KEY NOT NULL, bbb_nm(40) TEXT NOT NULL)\";\n command1.ExecuteNonQuery();\n }\n \n```\n\n2つ目のクリエイト文を実行するExecuteNonQuery();でエラーが発生しています。\n\n最後の } にブレークポイントを設定し実行するとエラーが発生し、 \nExecuteNonQuery();の行にブレークポイントを設定して実行すると、ブレークポイントで止まります。(ブレークが実行される?)\n\nエラー文の通りの原因ではなく、恐らく複数のテーブルを作成するコードの書き方自体が間違っているのではないかと思ってはいるのですが、調べてみても予約語が使われていた例やDBのパスがちゃんと設定されていないだとかといった物しか出てきませんでした。\n\n参考になるサイトや原因、解決策等何でも良いので意見がほしいです。 \nよろしくお願いします。\n\n/****追記****/\n\n一部コードを変えてもダメでした。\n\n```\n\n //コマンド生成宣言\n using (SQLiteCommand command = conn.CreateCommand())\n {\n //create文格納\n command.CommandText = \"create table AAA(aaa_cd TEXT(2) PRIMARY KEY NOT NULL, aaa_nm TEXT(40) NOT NULL)\";\n //コマンド実行\n command.ExecuteNonQuery();\n }\n \n //コマンド生成宣言\n using (SQLiteCommand command1 = conn.CreateCommand())\n {\n command1.CommandText = \"create table BBB(bbb_cd TEXT(4) PRIMARY KEY NOT NULL, bbb_nm(40) TEXT NOT NULL)\";\n command1.ExecuteNonQuery();\n }\n \n //コマンド生成宣言\n using (SQLiteCommand command2 = conn.CreateCommand())\n {\n \n command2.CommandText = \"create table CCC(aaa_cd TEXT(2) PRIMARY KEY NOT NULL, bbb_cd TEXT(4) NOT NULL)\";\n command2.ExecuteNonQuery();\n }\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:28:04.990", "favorite_count": 0, "id": "17940", "last_activity_date": "2015-10-24T22:39:54.893", "last_edit_date": "2015-10-22T08:35:47.103", "last_editor_user_id": "12797", "owner_user_id": "12797", "post_type": "question", "score": -2, "tags": [ "c#", "visual-studio", "sqlite" ], "title": "SQLiteのクリエイト文を実行する箇所でnear \"(\": syntax errorというエラーが発生", "view_count": 9976 }
[ { "body": "> bbb_nm(40) TEXT\n\nここは`bbb_nm TEXT(40)`では。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:33:55.813", "id": "17941", "last_activity_date": "2015-10-22T08:33:55.813", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5750", "parent_id": "17940", "post_type": "answer", "score": 2 } ]
17940
17941
17941
{ "accepted_answer_id": "17954", "answer_count": 1, "body": "このコードにて文字の選択範囲の取得まではできているのですが、 \nselectedTextに入ってる文字のカラーを赤に変更し、 \nそのままUItextviewに適応させるやり方で苦戦しております。 \nご教授のほどお願いします!\n\n```\n\n - (void)textViewDidChangeSelection:(UITextView *)textView {\n NSLog(@\"called!:textViewDidChangeSelection\");\n selectedText = [textView.text substringWithRange:textView.selectedRange];\n \n```\n\n}", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:44:13.343", "favorite_count": 0, "id": "17943", "last_activity_date": "2015-10-22T10:38:26.957", "last_edit_date": "2015-10-22T09:28:54.670", "last_editor_user_id": "12902", "owner_user_id": "12902", "post_type": "question", "score": 1, "tags": [ "objective-c" ], "title": "UITextViewにて選択範囲だけ動的にカラーを変更したい", "view_count": 818 }
[ { "body": "テキストの属性、例えばフォント、フォントの大きさ、文字の色、文字の背景色、行の中央揃え、右寄せ、このような属性を操作するには、`NSAttributedString`クラスを使います。`UITextView`のプロパティ`attributedText`で、`NSAttributedString`型のテキストを取得できます。 \nテキストの属性をあとから変更するには、`NSMutableAttributedString`クラスである必要があります。 \nテキストビューをStoryboardで設置している場合、テキストの属性を`Attributed`にしておきます。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/zrmbH.png)](https://i.stack.imgur.com/zrmbH.png)\n\n以下、ボタンを押したら、テキストビュー`textView`の選択部分を赤色に変更するプログラムです。\n\n```\n\n - (IBAction)changeColor:(id)sender {\n // テキストの選択範囲を取得。\n NSRange selectedRange = self.textView.selectedRange;\n // 1文字以上を選択していたら\n if (selectedRange.length > 0) {\n // attributedStringを取得して、Mutableにコピー。\n NSMutableAttributedString *theText = [self.textView.attributedText mutableCopy];\n // 選択部分だけ文字色を赤に変える。\n [theText addAttribute: NSForegroundColorAttributeName value: UIColor.redColor range: selectedRange];\n // 変更を加えたattributedStringを戻す。\n self.textView.attributedText = theText;\n }\n }\n \n```\n\n`NSAttributedString`について、把握する項目がちょっとしたボリュームになります。じっくり勉強してください。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T10:32:04.957", "id": "17954", "last_activity_date": "2015-10-22T10:38:26.957", "last_edit_date": "2015-10-22T10:38:26.957", "last_editor_user_id": "7362", "owner_user_id": "7362", "parent_id": "17943", "post_type": "answer", "score": 0 } ]
17943
17954
17954
{ "accepted_answer_id": null, "answer_count": 1, "body": "最近uniteを入れて、uniteなしのvimには戻れない位に依存しているのですが、 \nファイル拡張子を指定したunite-grepの方法がわからず、ファイル指定したい場合のみ\n\n```\n\n :Ag HOGE -G \\.h$\n \n```\n\nのようにag.vimを使用しています。 \nできれば全部uniteのみで完結させたいのですが、どうすれば可能でしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:44:32.170", "favorite_count": 0, "id": "17944", "last_activity_date": "2015-11-22T07:15:43.587", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12903", "post_type": "question", "score": 0, "tags": [ "vim" ], "title": "vim unite-grepで特定のファイル(*.h など)のみ検索する方法について", "view_count": 927 }
[ { "body": "grep 自体にはファイルパターンを指定するオプションがないので、`unite-grep` は直接はサポートしていないようです。 \n内部で使っているコマンドに引数を渡すことはできるので、`unite-grep` が ag を使う設定になっているのであれば、\n\n```\n\n :Unite grep::-G\\ \\\\.h$\n \n```\n\nとすることで指定することは可能なようです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-23T05:54:15.830", "id": "17971", "last_activity_date": "2015-10-23T05:54:15.830", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2541", "parent_id": "17944", "post_type": "answer", "score": 1 } ]
17944
null
17971
{ "accepted_answer_id": "17952", "answer_count": 2, "body": "数値以外の単位などを含む文字列から、数値のみを抽出する方法を教えてください。\n\n例えば、以下のようなケースです。\n\n * `体重62.5kg` -> `62.5`", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T08:52:37.103", "favorite_count": 0, "id": "17947", "last_activity_date": "2015-10-22T09:50:29.820", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3423", "post_type": "question", "score": 1, "tags": [ "php" ], "title": "数字以外を含む全角文字列から数字のみを抽出したい", "view_count": 1631 }
[ { "body": "以下で出来ました。\n\n```\n\n function ExtractNumeric($str){\n $str = mb_convert_kana($str,\"as\");\n $str = preg_replace('/[^0-9\\.]/','',$str);\n return (float)$str;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T09:30:39.577", "id": "17950", "last_activity_date": "2015-10-22T09:30:39.577", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3423", "parent_id": "17947", "post_type": "answer", "score": 1 }, { "body": "文字列に複数の数値が含まれている場合を考慮すると `preg_match_all()` の方が良いかも知れません。\n\n```\n\n $str = \"身長178.2cm、体重62.5kg\";\n \n $str = mb_convert_kana($str, \"as\");\n preg_match_all('/[\\d.]+/', $str, $matches);\n var_dump($matches[0]);\n =>\n array(2) {\n [0]=>\n string(5) \"178.2\"\n [1]=>\n string(4) \"62.5\"\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2015-10-22T09:50:29.820", "id": "17952", "last_activity_date": "2015-10-22T09:50:29.820", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "17947", "post_type": "answer", "score": 1 } ]
17947
17952
17950