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": 0, "body": "私はドロップダウンリストを使い選択されたの項目の値を別のテーブル(Distrip)に写したですが。ドロップダウンリストの項目の値がnullになって、項目の値を別のテーブルに写すことができません。 \nmodel とmodel classは以下の通りです。\n\n```\n\n public partial class LineInfo\n {\n public int Line_ID { get; set; }\n public string CoID { get; set; }\n public string CoName { get; set; }\n }\n \n public partial class Distrip{\n public int ID { get; set; }\n public int Line_ID { get; set; }\n }\n public class Modle\n {\n public LineInfo lineinfo { get; set; }\n public List<Dist_Info> Distrip { get; set; }\n }\n \n```\n\nコントローラーは以下の通りです。\n\n```\n\n public ActionResult Line_ID()\n {\n count = db.Line_Info.Max(p => p.Line_ID);\n IEnumerable<SelectListItem> line = db.LineInfo\n .Select(x => new SelectListItem\n {\n Value = x.Line_ID.ToString(),\n Text = x.CoName,\n });\n ViewBag.line = line;\n view ();\n }\n \n [HttpPost]\n [ValidateAntiForgeryToken]\n public ActionResult Line_ID(OpeModle Ope)\n {\n if (ModelState.IsValid)\n {\n foreach (var dist in Ope.Distrip)\n {\n db.Dist_Info.Add(dist);\n }\n db.SaveChanges();\n ViewBag.message = \"Data successfully saved!\";\n }\n \n return View();\n }\n \n```\n\nViewは狙い通り会社名が表示されています。 \nViewは以下の通りです。\n\n```\n\n @model OpeModle\n \n <table class=\"table\">\n <thead border=\"1\">\n <tr>\n <td colspan=\"2\" style=\"text-align:center;font-size:larger; width:800px\">\n Distriotion\n </td>\n </tr>\n </thead>\n \n <tr border=\"1\">\n <th>@Html.Label(\"Tili\", \"Line_ID \", new { @class = \"col-md-2 control-label\" })</th>\n <th>@Html.Label(\"Tili\", \"会社名 \", new { @class = \"col-md-2 control-label\" })</th>\n </tr>\n \n @for (int i = 0; i < ViewBag.count; i++)\n {\n @Html.HiddenFor(model => model.Distrip[i].Dist_ID, new { id = \"natureOfVisitField\", Value = ViewBag.countDis + i })\n <tr>\n <th>@Html.Label(\"Tili\", \"Line_ID \", new { @class = \"col-md-2 control-label\" })</th>\n \n <th>\n <div class=\"form-group\">\n <div class=\"col-md-10\">\n @Html.DropDownList(\"Line_ID\", (IEnumerable<SelectListItem>)ViewBag.line, \"Select\")\n @Html.ValidationMessageFor(model => model.Distrip[i].Line_ID, \"\", new { @class = \"text-danger\" })\n </div>\n </div>\n </th>\n \n </tr>\n }\n \n </table>\n \n```\n\nデバッグしたらHttpPostにてDistripのIDが狙い通りきていますがLine_IDは0になっています。 \nどう直せば良いでしょうか? \nご教授をよろしくお願いします。", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-24T13:56:58.027", "favorite_count": 0, "id": "37467", "last_activity_date": "2017-08-26T13:28:46.180", "last_edit_date": "2017-08-26T13:28:46.180", "last_editor_user_id": "23844", "owner_user_id": "23844", "post_type": "question", "score": 0, "tags": [ "asp.net", "mvc" ], "title": "ドロップダウンリストの項目の値がnullになっています。", "view_count": 961 }
[]
37467
null
null
{ "accepted_answer_id": null, "answer_count": 3, "body": "機械学習によく出てくるbatch_sizeとはバッチとはなんですか?\n\n```\n\n y_vals = np.transpose([np.array([y[13] for y in housing_data])])\n x_vals = np.array([[x for i,x in enumerate(y)\n if housing_header[i] in cols_used] for y in housing_data])\n \n #min-maxスケーリングを使って、x値を0〜1の値にスケーリング\n x_vals = (x_vals - x_vals.min(0)) / x_vals.ptp(0)\n \n np.random.seed(13)\n train_indices = np.random.choice(len(x_vals), round(len(x_vals)*0.8), replace=False)\n test_indices = np.array(list(set(range(len(x_vals))) - s et(train_indices)))\n x_vals_train = x_vals[train_indices]\n x_vals_test = x_vals[test_indices]\n y_vals_train = y_vals[train_indices]\n y_vals_test = y_vals[test_indices]\n \n k = 4\n batch_size=len(x_vals_test)\n \n```\n\n参照:TensoFlow機械学習クックブック", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-24T22:07:01.970", "favorite_count": 0, "id": "37472", "last_activity_date": "2017-12-27T23:52:51.713", "last_edit_date": "2017-08-25T03:40:49.333", "last_editor_user_id": "19110", "owner_user_id": "23690", "post_type": "question", "score": 1, "tags": [ "tensorflow", "機械学習" ], "title": "機械学習によく出てくるbatch_sizeとはバッチとはなんですか?", "view_count": 22456 }
[ { "body": "バッチ(Batch)は、計算機処理の用語です。\n\n計算機で処理をするやり方は、大きく分けて次の2種類になります。 \na) データを揃えておいて一気にプログラム処理をする \nb) オペレータがプログラムからの出力に応じて、データなどを入力しながら処理をすすめる\n\nバッチ(バッチ処理)はa)のやり方です。 b)のほうはインタラクティブ処理とかリアルタイム処理とか呼ばれます。\n\nWindows等で一連のコマンドを実行するためのファイルの拡張子は\".bat\"ですが、Batchに由来します。\n\n== \n質問のコードに出てくる batchは、複数のデータに対して同じ処理を一気に行う事を意味すると推測されます。\n\n```\n\n batch_size=len(x_vals_test)\n \n```\n\nは、テスト用データを使って学習結果を判断する処理をするための準備として、処理するデータの数を求めているのでしょう。 \nテスト用のデータ(x_vals_testとy_vals_test)は、もう少し上のコードで準備されています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T00:34:02.190", "id": "37474", "last_activity_date": "2017-08-25T00:34:02.190", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "37472", "post_type": "answer", "score": 2 }, { "body": "ここでいうバッチは、処理されるデータの「ひとまとまり」を指してます。バッチサイズ=データサイズ、です。コンピュータ用語での「バッチ」は処理のほうを指すのが一般的で、処理される方を指して言うのはあまり一般的な用法では無いと思います。\n\nバッチは一般的な用語で、計算機分野以外でも使われます。「JCO臨界事故」(俗に「バケツでウラン」事故)でも、バケツ一杯分の原料やそれを処理することを1バッチ、と表現してました。そもそも辞書を見ると「パンや陶器など一焼き分、一窯分」なんて書いてあります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T08:33:45.453", "id": "37485", "last_activity_date": "2017-08-25T08:33:45.453", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "37472", "post_type": "answer", "score": 3 }, { "body": "機械学習では、学習を早く、うまく進めるための一つの方法として、「バッチ」という考え方が導入されています。これは、すべてのデータを利用して学習を進めるのではなく、データの一部を利用することで計算量を減らそうという考え方です。\n\nそして、学習を進める際に利用するデータの一部(ひとまとめのデータ)を抽象的に「バッチ」と呼び、このときに利用するデータの数を「バッチサイズ」と呼びます。\n\nbatch_size=len(x_vals_test)\n\nは、(なぜだかはわかりませんが)テストデータのサイズを、バッチサイズとして扱うということでしょう。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-12-27T23:52:51.713", "id": "40569", "last_activity_date": "2017-12-27T23:52:51.713", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "26813", "parent_id": "37472", "post_type": "answer", "score": 2 } ]
37472
null
37485
{ "accepted_answer_id": "37588", "answer_count": 2, "body": "php初心者です。 \nWebサイト内で共通の操作を行うヘルパー関数群をまとめたモジュールを作りました(my_helper.php)。 \nこれをwebサイト内の任意のファイルから呼び出したいのですがどうしたら良いのでしょうか。\n\nサイトの構造は例えば以下のような例です。\n\n```\n\n /root/\n /toppage/\n index.php\n /subpage/\n index.php\n /q_and_a/\n index.php\n /common-module/\n helper.php <-こんな感じで配置したい\n \n```\n\nincludeを使って相対パスで呼び出すことをしていたのですが、階層が深くなるにつれて../../..を書くのが醜くメンテナンスも大変なので、別の方法を取り入れたいと思っているところです。\n\nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-24T22:32:14.127", "favorite_count": 0, "id": "37473", "last_activity_date": "2017-09-07T17:09:51.690", "last_edit_date": "2017-08-25T00:27:48.460", "last_editor_user_id": "3060", "owner_user_id": "24920", "post_type": "question", "score": 1, "tags": [ "php" ], "title": "PHP自作ライブラリの配置場所はどこにするのがベストなのか", "view_count": 1643 }
[ { "body": "配置は問題ないように感じます。 \nパスの指定方法を、\n\n 1. $_SERVER['DOCUMENT_ROOT']を使う\n 2. 絶対パスで指定する\n\nのどちらかにしてみてはいかがでしょうか。\n\n1番はechoなりに上記変数を突っ込んでいただくとわかりますが、ドキュメントルート(ドメイン直下)までのパスが出力されますので、そこからのパスを繋げればOKです。\n\n2番はサーバのルートからの絶対パスなので、サーバが変わる可能性がある場合や、そもそもレンタルサーバなどでパスがわからない可能性もあるので、あまりおすすめではないです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T01:58:37.563", "id": "37588", "last_activity_date": "2017-08-30T01:58:37.563", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25099", "parent_id": "37473", "post_type": "answer", "score": 1 }, { "body": "関数群であれば、 `include_path` などに絶対パスを追記して、読み込み場所を追加するのが最適です。 \n<http://php.net/manual/ja/function.set-include-path.php>\n\n他の手段として、各ファイルがクラスとして独立しているのであれば`spl_autoload_register` などを用いて解決するのが良いのではないかと。 \n<http://php.net/manual/ja/function.spl-autoload-register.php>\n\n蛇足ですが、 \n他の手法として、composerのautoloaderを使用したほうがディレクトリの配置も、呼び出しも楽になると思います。 \n具体的に\n\n * 各ファイル及びクラス群にnamespaceを使用し、ディレクトリごとにおける名前空間をきっちり定義する。\n * useで必要なクラスを必要なだけ呼び出す。 (includeで煩雑な呼び出しが不要になります。)\n\ncomposerはパッケージマネージャなイメージが多いかと思われますが、こういった用途にも使用できかつ、サードパーティのモジュールも合わせて置くことが可能なので、検討されてはいかがでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-07T17:09:51.690", "id": "37785", "last_activity_date": "2017-09-07T17:09:51.690", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18542", "parent_id": "37473", "post_type": "answer", "score": 1 } ]
37473
37588
37588
{ "accepted_answer_id": "37491", "answer_count": 1, "body": "**Q1.ページの表示速度を高速化する場合、「1ページ目を速く表示する方法」と「キャッシュ等を利用して2ページ目以降を速くする方法」があると思うのですが、**\n\n・[PageSpeed](https://developers.google.com/speed/docs/insights/BlockingJS?hl=ja)は、1ページのみで判断するのでしょうか? \n・2ページ目以降(キャッシュ)は考慮しない?\n\n※単純にSEO効果だけを考えるなら、「1ページ目を速く表示」することだけを考えれば良い?\n\n* * *\n\n**Q2.「async」「defer」を使用しない場合** \n・外部スクリプトではなく、インライン化した方が良い? \n・遅延する方法としてasyncしか記載されていないのですが、DOMContentLoadedは考慮されない?\n\n* * *\n\n**Q3.PageSpeedは、CDNのキャッシュは考慮しない(と考えられる)?**", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T02:00:35.410", "favorite_count": 0, "id": "37476", "last_activity_date": "2017-08-25T14:25:25.697", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 0, "tags": [ "javascript" ], "title": "PageSpeedは、1ページのみで判断? 2ページ目以降(キャッシュ)は考慮しない?", "view_count": 76 }
[ { "body": "質問者さんの言う「2ページ目」が何を指しているのか不明確ですが、\n\n再訪問時にキャッシュが機能するかどうかでしょうか? そうであればPageSpeedはページがキャッシュ可能に設定されているかを評価しています。\n\n調査対象のページからリンクされる次のページのことでしょうか? そうであればPageSpeedはページ毎に評価するので、各ページについて調査するまでです。\n\n* * *\n\n> 外部スクリプトではなく、インライン化した方が良い?\n\n[小さなJavaScriptをインライン化する](https://developers.google.com/speed/docs/insights/BlockingJS?hl=ja#InlineJS)とある通りです。小さくなく複数ページから読み込まれるJavaScriptの場合はインライン化は非効率です。\n\n> 遅延する方法としてasyncしか記載されていないのですが、DOMContentLoadedは考慮されない?\n\nHTMLの仕様が関係します。HTMLファイルのタグ解析中に`<script>`タグに到達した場合、指定されているスクリプトファイルのダウンロードが完了し更にそのスクリプトファイルを解析完了するまでタグ解析は中断されます。 \n`DOMContentLoaded`等、記述内容に依らずダウンロードおよび解析が完了するまでHTMLタグの解析が中断されることに変わりありません。 \nそしてHTMLタグ解析が中断された場合、(解析されていないわけですから当然のことですが)後続する外部リソースの読み込みも開始されませんので、ページの読み込みパフォーマンスに与える影響が大きいです。 \nそこでHTMLタグ解析を中断させない唯一の方法が`async`(もしくは`defer`)の指定なわけです。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T14:25:25.697", "id": "37491", "last_activity_date": "2017-08-25T14:25:25.697", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "37476", "post_type": "answer", "score": 1 } ]
37476
37491
37491
{ "accepted_answer_id": null, "answer_count": 1, "body": "apache pyarrowを使って任意のファイルをバイナリ形式で読み込み \nそのバイナリをlistにつめてparquet形式で出力するということをやっています。 \n以下のソースで検証しているのですが、parquet形式で出力すると \nファイルサイズが元のファイルの7倍になります。 \nテキストファイルで出力したファイルを開いてみると、データは無圧縮状態のようで \n圧縮がかかっていません。 \nなんとか圧縮をかけることはできないでしょうか?\n\n```\n\n # -*- coding: utf-8 -*-\n import pyarrow as pa\n import pyarrow.parquet as pq\n \n open_data_path = \"test_log_70mb.txt\"\n file_list = []\n with open(open_data_path, 'rb') as f:\n data = bytes(f.read())\n file_list.append(data)\n \n pa_data = [\n pa.array(file_list)\n ]\n \n pa_batch = pa.RecordBatch.from_arrays(pa_data, [\"file_list\"])\n table = pa.Table.from_batches([pa_batch])\n pq.write_table(table, \"./test_parquet\", compression=\"gzip\")\n \n```\n\n結果\n\n```\n\n total 71734\n -rwxrwxrwx 1 vagrant vagrant 423 Aug 25 02:05 test2.py\n -rwxrwxrwx 1 vagrant vagrant 73454817 Aug 25 02:05 test_log_70mb.txt\n vagrant@apex01:/vagrant/arrow_test$ python test2.py\n vagrant@apex01:/vagrant/arrow_test$ ls -l\n total 511880\n -rwxrwxrwx 1 vagrant vagrant 423 Aug 25 02:05 test2.py\n -rwxrwxrwx 1 vagrant vagrant 73454817 Aug 25 02:05 test_log_70mb.txt\n -rwxrwxrwx 1 vagrant vagrant 450709316 Aug 25 02:05 test_parquet\n \n```\n\n環境 \npython 2.7 \npyarrow 0.6.0", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T02:16:40.037", "favorite_count": 0, "id": "37477", "last_activity_date": "2022-04-09T12:06:30.597", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25032", "post_type": "question", "score": 2, "tags": [ "python", "apache" ], "title": "parquet形式で出力するとファイルサイズが増大する", "view_count": 759 }
[ { "body": "```\n\n compression = 'snappy'\n \n```\n\nはどうですか?", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2017-09-28T13:58:15.043", "id": "38272", "last_activity_date": "2020-03-03T15:10:29.650", "last_edit_date": "2020-03-03T15:10:29.650", "last_editor_user_id": "32986", "owner_user_id": "25585", "parent_id": "37477", "post_type": "answer", "score": 1 } ]
37477
null
38272
{ "accepted_answer_id": null, "answer_count": 1, "body": "Common LispでOpenGLの[チュートリアル](https://learnopengl.com/#!Getting-started/Hello-\nTriangle)を試していたのですが, \n`(gl:gen-vertex-array)`でエラーが出てしまいます.\n\n```\n\n OpenGL signalled (1282 . INVALID-OPERATION) from GEN-VERTEX-ARRAYS.\n [Condition of type CL-OPENGL-BINDINGS:OPENGL-ERROR]\n \n```\n\nデバッガでcontinueすると\n\n```\n\n The value \n (1) \n is not of type \n (UNSIGNED-BYTE 32)\n [Condition of type TYPE-ERROR]\n \n```\n\nと出ます. \n上のサイトの翻訳をしているとエラーが出てしまいますが,replで単体で`(gen-vertex-array)`を評価するとエラーが出ません. \nどうすれば解決できるか教えていただけないでしょうか. \nソースコードは\n\n```\n\n (require :asdf)\n (asdf:oos 'asdf:load-op :cl-glfw3)\n (asdf:oos 'asdf:load-op :cl-opengl)\n (asdf:oos 'asdf:load-op :cl-glu)\n (asdf:oos 'asdf:load-op :trivial-main-thread)\n (require 'cffi)\n (defpackage glfw-test\n (:use :cl :trivial-main-thread)\n (:export #:run\n #:bound))\n (in-package :glfw-test)\n \n (defclass shader ()\n ((vbuff :accessor vertex-buffer)\n (ibuff :accessor index-buffer)\n (vshader :accessor vertex-shader)\n (fshader :accessor fragment-shader)\n (varray :accessor vertex-array)\n (program :accessor program)))\n \n (defvar *vertex-shader-source*\n \"#version 330 core\n layout (location = 0) in vec3 apos;\n void main ()\n {\n gl_position = vec4(apos.x, apos.y, apos.z, 1.0);\n }\n \")\n (defvar *fragment-shader-source*\n \"#version 330 core\n out vec4 fragcolor;\n void main()\n {\n fragcolor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n }\n \")\n \n (defgeneric shader-init (shader)\n (:documentation \"シェーダを初期化\"))\n (defmethod shader-init ((shader shader))\n ;;バーテックスシェーダ\n (setf (vertex-shader shader) (gl:create-shader :vertex-shader))\n (gl:shader-source (vertex-shader shader) *vertex-shader-source*)\n (gl:compile-shader (vertex-shader shader))\n ;;フラグメントシェーダ\n (setf (fragment-shader shader) (gl:create-shader :fragment-shader))\n (gl:shader-source (fragment-shader shader) *fragment-shader-source*)\n (gl:compile-shader (fragment-shader shader))\n ;;シェーダプログラム\n (setf (program shader) (gl:create-program))\n (gl:attach-shader (program shader) (vertex-shader shader))\n (gl:attach-shader (program shader) (fragment-shader shader))\n (gl:link-program (program shader))\n ;;使い終わったシェーダを削除\n (gl:delete-shader (vertex-shader shader))\n (gl:delete-shader (fragment-shader shader))\n ;;アレイ\n (let ((vertices (gl:alloc-gl-array :float 9))\n (verts #(-0.5 -0.5 0.0\n 0.5 -0.5 0.0\n 0.0 0.5 0.0)))\n (dotimes (i (length verts))\n (setf (gl:glaref vertices i) (aref verts i)))\n \n (setf (vertex-array shader) (gl:gen-vertex-array))\n (setf (vertex-buffer shader) (gl:gen-buffers 1))\n \n (gl:bind-vertex-array (vertex-buffer shader))\n \n (gl:bind-buffer :array-buffer (vertex-buffer shader))\n (gl:buffer-data :array-buffer :static-draw vertices)\n (gl:free-gl-array vertices));freeにする\n \n (gl:vertex-attrib-pointer 0 3 :float nil 3 (cffi:null-pointer))\n (gl:enable-vertex-attrib-array 0)\n ;;アレイを解除\n (gl:bind-buffer :array-buffer 0)\n (gl:bind-vertex-array 0)\n \n (gl:use-program (program shader)))\n \n (defun main-loop ()\n (gl:clear-color 0.2 0.3 0.3 1.0)\n (gl:clear :color-buffer-bit)\n )\n \n (defun main ()\n (with-body-in-main-thread ()\n (glfw:with-init-window (:width 480 :height 400 :title \"test glfw\")\n (let ((shdr (make-instance 'shader)))\n (shader-init shdr)\n ;;メインループ\n (loop until (glfw:window-should-close-p)\n do (gl:clear :depth-buffer-bit)\n ;;描画\n (main-loop)\n (glfw:swap-buffers)\n (glfw:poll-events);;イベントに対する反応を書いておかないとウィンドウが表示されない.消去できない\n (sleep (/ 1 60));更新を60fpsに\n )\n ))))\n \n (defun run ()\n #+sbcl(sb-int:with-float-traps-masked (:invalid) (main));;SBCLはこれがないとエラー\n #-sbcl(main)\n )\n (run)\n \n```\n\nとなっています.ライブラリは事前にquicklispで導入しました.replでこれをloadするとエラーになってしまいます.", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T03:54:34.053", "favorite_count": 0, "id": "37478", "last_activity_date": "2020-11-24T08:08:35.947", "last_edit_date": "2017-08-25T17:25:40.620", "last_editor_user_id": "19110", "owner_user_id": "23130", "post_type": "question", "score": 1, "tags": [ "common-lisp", "opengl" ], "title": "cl-openglのgem-vertex-arrayのエラー", "view_count": 307 }
[ { "body": "この行が問題です。\n\n```\n\n (gl:bind-vertex-array (vertex-buffer shader))\n \n```\n\nbind すべきは `(vertex-buffer shader)` ではなく `(vertex-array shader)` です。この部分を修正すれば\n`(CL-OPENGL-BINDINGS:BIND-VERTEX-ARRAY (1))` でのエラーは出なくなりますが、続いて `(CL-OPENGL-\nBINDINGS:BIND-BUFFER :ARRAY-BUFFER (1))` でエラーがでるようになります。これは `gl:gen-buffers`\nの戻り値をそのまま `(vertex-buffer shader)` としているからです(正しくはその第0要素を `setf` することになります)。\n\nまた GLSL 3.30 を利用するために、環境によっては `glfw:with-init-window` で `:context-version-\nmajor` などを設定する必要があるかもしれません。シェーダースクリプトをコンパイルしたときのログに \"error: GLSL 3.30 is not\nsupported.\" が出てきた場合は参考にしてください。\n\nひとまず cl-opengl の examples にある [shader-vao.lisp](https://github.com/3b/cl-\nopengl/blob/master/examples/misc/shader-vao.lisp) が参考になるのではないかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T19:53:07.123", "id": "37497", "last_activity_date": "2017-08-25T20:09:57.327", "last_edit_date": "2017-08-25T20:09:57.327", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "37478", "post_type": "answer", "score": 0 } ]
37478
null
37497
{ "accepted_answer_id": null, "answer_count": 1, "body": "例えば、ユーザー情報をもつuserテーブル \nuser_0, user_1, user_2, user_3(userIdを4で除算したときのあまりがテーブル名の後ろにつく) \nに対してentityとrepositoryをテーブルの数だけ複数実装しなくても良い実装方法を知りたいです。\n\n最悪の場合、service層で使用するrepositoryを動的に変更しようとはしてますが、同じようなentityとrepositoryを複数実装したくないです。\n\nよろしくお願いします。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T05:32:53.110", "favorite_count": 0, "id": "37480", "last_activity_date": "2019-10-15T09:01:00.133", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7585", "post_type": "question", "score": 1, "tags": [ "mysql", "spring", "spring-boot", "database", "jpa" ], "title": "Spring Data JPAで分割されたテーブルにアクセスするベストプラクティスな実装方法が知りたい", "view_count": 601 }
[ { "body": "DBからのアプローチですが、同じ構造のテーブルであれば、`UNION`したVIEWを用意する方法があると思います。つまり、以下のようなVIEW「`user`」を作れば、entityもrepositoryも1つで十分になると思います。\n\n```\n\n CREATE VIEW user as (\n select * from user_0\n union\n select * from user_1\n union\n select * from user_2\n union\n select * from user_3\n );\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T10:08:55.457", "id": "37569", "last_activity_date": "2017-08-29T10:08:55.457", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20098", "parent_id": "37480", "post_type": "answer", "score": 1 } ]
37480
null
37569
{ "accepted_answer_id": "37742", "answer_count": 1, "body": "tf.gatherとtf.expand_dimsはどういう意味でしょうか? \n公式サイトを見ましたがよくわかりませんでした。\n\n```\n\n top_k_xvals, top_k_indices = tf.nn.top_k(tf.negative(distance), k=k)\n \n x_sums = tf.expand_dims(tf.reduce_sum(top_k_xvals, 1),1)\n x_sums_repeated = tf.matmul(x_sums, tf.ones([1, k], tf.float32))\n x_val_weights = tf.expand_dims(tf.div(top_k_xvals,x_sums_repeated), 1)\n \n top_k_yvals = tf.gather(y_target_train, top_k_indices)\n prediction = tf.squeeze(tf.matmul(x_val_weights, top_k_yvals), axis=[1])\n \n```\n\n参照:TensorFlow機械学習クックブック", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T05:58:22.833", "favorite_count": 0, "id": "37482", "last_activity_date": "2017-09-05T23:50:01.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23690", "post_type": "question", "score": 0, "tags": [ "python", "tensorflow" ], "title": "tf.gatherとtf.expand_dimsはどういう意味でしょうか?", "view_count": 5935 }
[ { "body": "tf.expand_dims(input, axis) は input テンソルの axis に指定した階に 1 次元挿入する.\n\ne.g. shape が (2,3,4) の input の axis=2 に 1 次元を挿入すると (2,3,1,4) になる.\n\nPyTorch でいう unsqueeze と同じ.\n\n~~\n\ntf.gather(params, indices, axis) は params テンソルの axis に指定した階でスライスして,indeices\nで指定したインデックスのテンソルだけ取り出してくっつける.\n\ne.g. [[1,2,3],[4,5,6]] という params テンソルの axis=1 でスライスすると [1,4] と [2,5] と [3,6]\nという 3 つのテンソルができ,indeces=[1,2] なら 1,2 番目のテンソルを取り出してくっつけるので [[2,3],[5,6]] になる.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T23:50:01.150", "id": "37742", "last_activity_date": "2017-09-05T23:50:01.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25227", "parent_id": "37482", "post_type": "answer", "score": 0 } ]
37482
37742
37742
{ "accepted_answer_id": null, "answer_count": 2, "body": "以下のコードに何か違いはありますか?\n\n```\n\n file = open(\"sample.txt\", \"w\", encoding=\"utf-8\")\n print(\"hello\", file=file)\n file.write(\"hello\")\n file.close()\n \n```\n\npython3ではprint文でファイル書き込みができますが、使い分ける状況などはありますか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T11:14:54.343", "favorite_count": 0, "id": "37487", "last_activity_date": "2020-07-25T06:09:31.920", "last_edit_date": "2017-08-29T03:09:59.263", "last_editor_user_id": "3054", "owner_user_id": "15279", "post_type": "question", "score": 5, "tags": [ "python", "python3" ], "title": "python3のprint関数とwriteメソッドの違い", "view_count": 5251 }
[ { "body": "\"ファイルへの出力(書き込み)\"という意味では一見同じですが、細かく見ると以下のような違いがあるようです。\n\n> print : デフォルトでは出力の末尾に改行を追加する(変更は可能)。 \n> write : 渡された文字列をそのまま出力。文字列以外は受け取れない。\n\nwriteの場合は繰り返し実行した時、以下の通り文字列が繋がって出力されます。\n\n```\n\n write(\"Hello\")\n write(\"Hello\")\n write(\"Hello\")\n # => HelloHelloHello\n \n```\n\n参考: \n[Python Tips:改行なしで文字列を出力したい](http://www.lifewithpython.com/2013/12/python-\nprint-without-.html)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2017-08-25T17:35:44.893", "id": "37495", "last_activity_date": "2020-07-25T06:09:31.920", "last_edit_date": "2020-07-25T06:09:31.920", "last_editor_user_id": "3060", "owner_user_id": "3060", "parent_id": "37487", "post_type": "answer", "score": 5 }, { "body": "> 使い分ける状況などはありますか?\n\n`print` より `write` の方が速いです。 \n質問のような単純なケースで 1.5 〜 3 倍程度速いと思います。 \nまた、`print` はバイナリモードで開いたファイルオブジェクトには使用できません(引数が bytes\nであっても、テキスト表現の文字列に変換して書き込み、失敗します)。\n\n* * *\n\nPython3 の `print`\nは文ではなく、[関数になっています](https://docs.python.jp/3/whatsnew/2.6.html#pep-3105-print-\nas-a-function)。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T23:22:46.037", "id": "37499", "last_activity_date": "2017-08-25T23:22:46.037", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "37487", "post_type": "answer", "score": 4 } ]
37487
null
37495
{ "accepted_answer_id": null, "answer_count": 1, "body": "Ruby on Railsを勉強しようと思い \n`rails server`でサーバーを立ち上げようとしたら\n\n> FATAL: prematurely zombied\n\nと言われ失敗してしまいました。\n\nネットで検索してもなかなか見つからないのですが \nこれはどういったエラーなのでしょうか? \n解決策などもあればお願いします\n\n## ■追記\n\n開発環境:\n\n * iMac OSX Elcapitan\n * ruby:2.4.1p111\n * rails:5.1.3\n\n開発環境構築のために Ruby のアップデートや、 gem で Rails のインストールも行いました。 \nRuby のバージョンアップの際にリカバリーモードで `csrutil disable` を実行しました。\n\n参考にしたサイトは、ドットインストールの1「Ruby on Rails」の第二回です。 \n<http://dotinstall.com/lessons/basic_rails_v3/41802> \nここの `rails server -b IPAddress -d` で投稿のエラーが出力されました。\n\n* * *\n\n`-d`を抜いて実行してみました。 \n実行されているようなのですが ブラウザでアドレスを打ち込んでもページを開くことができませんでした。 以下実行時の出力です。\n\n```\n\n => Booting Puma\n => Rails 5.1.3 application starting in development on 192.168.10.6:3000\n => Run rails server -h for more startup options\n Puma starting in single mode...\n * Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller\n * Min threads: 5, max threads: 5\n * Environment: development\n * Listening on tcp://192.168.10.6:3000\n Use Ctrl-C to stop\n \n```\n\n* * *\n\n以上、よろしくおねがいいたします。", "comment_count": 4, "content_license": "CC BY-SA 4.0", "creation_date": "2017-08-25T11:36:04.843", "favorite_count": 0, "id": "37488", "last_activity_date": "2022-02-19T02:06:45.560", "last_edit_date": "2021-08-04T08:17:15.910", "last_editor_user_id": "3060", "owner_user_id": "8776", "post_type": "question", "score": 3, "tags": [ "ruby-on-rails" ], "title": "Ruby on Railsでサーバー起動に失敗しました", "view_count": 1521 }
[ { "body": "rb-fsevent は、子プロセスとして fsevent_watch というプログラムを実行しています。 \nこの fsevent_watch は、起動時に親プロセスを確認し、もしいなかったら、`prematurely zombied`\nというメッセージを出力して終了するようです。\n\nrails 起動時に `-d` を付けているので、親プロセスの終了が早すぎるのかもしれません。 \n`-d` を付けなければ大丈夫かもしれません。 \n`-d` を付けない場合、rails 起動後、待っててもプロンプトには戻りませんので、 \nrails を終了するには `kill -9` でなく ctrl+c を入力してください。\n\n上に「親プロセスの終了が早すぎるのかも」と書きましたが、そこまで早いものか? という気がするので、ちょっと自信はありません。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T16:54:14.050", "id": "37494", "last_activity_date": "2017-08-25T16:54:14.050", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5288", "parent_id": "37488", "post_type": "answer", "score": 1 } ]
37488
null
37494
{ "accepted_answer_id": null, "answer_count": 2, "body": "いろんなシステムを見てきてDBのテーブルに格納する日付項目に対して型がVARCHAR2やDATEであったりするのですが、どう使い分けているのでしょうか。 \nVARCHAR2であることのメリット、DATE型にすることのメリットなど何かあるのでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T16:20:38.703", "favorite_count": 0, "id": "37492", "last_activity_date": "2017-08-27T05:32:44.043", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "17348", "post_type": "question", "score": 1, "tags": [ "database" ], "title": "DBのテーブルの日付項目に関して", "view_count": 1138 }
[ { "body": "日付に限らず、型が用意されているのであればそれを使うのが大原則です。文字列として保存してしまうと、計算や比較をするのにいちいちややこしい処理が必要になります。無意味ですしバグのものとです。\n\n文字列型を使うのは、データの都合などでそうせざるを得ないなど消極的な理由の場合のみです。西暦和暦が混在していてそのままの形で保存しないといけないとか、n月0日みたいな無効日に特別な意味があるとか。\n\n文字列型が使用されるもう一つの理由として、「なんでも文字列型」にしたがるおかしな人が一定います。ひどい人になると数値ですら文字列型で保存しろという主張をしてたりします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T01:58:13.663", "id": "37502", "last_activity_date": "2017-08-26T01:58:13.663", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "37492", "post_type": "answer", "score": 5 }, { "body": "日付型が提供されているなら、日付型を使うのがベストと考えます。文字列型での格納はパフォーマンスでもデメリットが大きいです。大小関係の比較などについては、インデックスも使われません。経過日数を計算するような関数が提供されていても、前段で型変換をおこなう必要が生じます。\n\n文字列型で格納するメリットは殆どありません。無理に上げるなら移植性の高さです。データベースが異なれば、日付型でも有効桁数や格納可能な範囲など、随分と扱いが異なります。また文字列型ならロケールの設定によって挙動が異なると言った事もありません。異なるデータベース間での互換性を重視して最小公約数的な機能しか使わないという制約下なら、文字列型格納するメリットもあるでしょう。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T05:32:44.043", "id": "37520", "last_activity_date": "2017-08-27T05:32:44.043", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "12774", "parent_id": "37492", "post_type": "answer", "score": 2 } ]
37492
null
37502
{ "accepted_answer_id": null, "answer_count": 3, "body": "リーダブルコードなどを読んで、否定はなるべく使わない方が良いというのは分かるのですが、 \nどうしても使わざるを得ない状況もあるかと思います。 \nその場合、例えばPythonでは以下どちらの書き方が良いのでしょうか?\n\n```\n\n if not hasSomething()\n if doesNotHaveSomething()\n \n```\n\nもしくは他の書き方があれば教えてください", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T16:22:26.530", "favorite_count": 0, "id": "37493", "last_activity_date": "2017-08-26T02:01:55.990", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "15279", "post_type": "question", "score": 0, "tags": [ "python", "python3" ], "title": "否定形の読みやすさについて", "view_count": 1682 }
[ { "body": "「(否定を)どうしても使わざるを得ない」=「否定を使うことがリーダブル」と読めますが。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T17:36:33.953", "id": "37496", "last_activity_date": "2017-08-25T17:36:33.953", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13227", "parent_id": "37493", "post_type": "answer", "score": 1 }, { "body": "一般に「否定を使わない」というのは否定演算子を使うなという事ではなく、メソッド名などにおいての話なのではないでしょうか。 \n否定形の要素があるとそれの否定で「否定の否定」が出てきてしまう事、一貫性が失われる事、などが原因ではないでしょうか。 \nまさに、`doesNotHaveSomething()` などというメソッドを用意する必要はなくて、 `not hasSomething()` でいいよね?\nという話だと思います。\n\n(これに従うかどうかは主観の問題ですね)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-25T22:47:23.680", "id": "37498", "last_activity_date": "2017-08-25T22:47:23.680", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "37493", "post_type": "answer", "score": 0 }, { "body": "リーダブルコードの主張はこうです\n\n * 名前に否定形は使わない\n * 条件式に否定は使わない\n\n後者については、否定を使った方が読みやすい場合もあるとも書かれています。\n\n> if not hasSomething() \n> if doesNotHaveSomething()\n\nリーダブルコードではthenとelseをひっくり返して前者の`not`を消すことを考えろといっているわけですが、それが出来ないのであれば、前者を使うほうがよいでしょう。\n\n後者は、`doesNotHaveSomething()`が`false`を返したときに結局どういう状態なのか考えるのが大変です。これが「名前に否定形を使わない」とされる理由です。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T01:40:57.960", "id": "37500", "last_activity_date": "2017-08-26T02:01:55.990", "last_edit_date": "2017-08-26T02:01:55.990", "last_editor_user_id": "5793", "owner_user_id": "5793", "parent_id": "37493", "post_type": "answer", "score": 3 } ]
37493
null
37500
{ "accepted_answer_id": "37509", "answer_count": 2, "body": "[![画像1](https://i.stack.imgur.com/POtbD.png)](https://i.stack.imgur.com/POtbD.png) \n\\-------------画像1-------------\n\n画像1のようにindexが1,2,3,4という順番で並んでいて \n2行目の列を削除すると\n\n[![画像2](https://i.stack.imgur.com/w5yBV.png)](https://i.stack.imgur.com/w5yBV.png) \n\\-------------画像2-------------\n\n画像2のようにindexが1,3,4となってしまうかと思うのですが\n\n[![画像3](https://i.stack.imgur.com/UqJ6r.png)](https://i.stack.imgur.com/UqJ6r.png) \n\\-------------画像3-------------\n\n画像3のように、 \n2のindexが削除されたら \n3と4のindexを自動的に1つずつズレて \n2と3にリネームされるようにしたいです。 \nそういった機能はPostgreSQLにはありますか? \n無いとしたら、そういった機能を自分で作成しなくてはいけませんか?\n\n[追記] \nシーンの一覧画面を作る際、「scene_indexが5~10までのデータを取り出したい」 \n(5個ずつデータベースから取り出して、ページネーションを使って並べたい) \nというような場合があり、カラムを用‌​意していないと取り出しにくいのではないか‌​なと思い \nこのような質問にさせていただ‌​きました。 \nscene_indexが歯抜け‌​状態になっているデータベースからでも \n指‌​定した位置の前後5個のデータを取り出す、という処理が出来るのであれば \nそれでも良い‌​かと思うのですが、そういった方法があるかも分からなかったた‌​め \nこのような質問をするに至っています。", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T05:03:22.903", "favorite_count": 0, "id": "37503", "last_activity_date": "2017-08-26T22:22:38.990", "last_edit_date": "2017-08-26T12:55:15.057", "last_editor_user_id": "22541", "owner_user_id": "22541", "post_type": "question", "score": 1, "tags": [ "postgresql", "database" ], "title": "PostgreSQLで特定の行を削除した時に全体のindexをズラすには?", "view_count": 312 }
[ { "body": "`scene_index` の値の順序が分かれば良いのであれば view を使う方法もあるかと思います。具体的には、以下の様にして view を作成します。\n\n```\n\n # CREATE VIEW scene_view AS SELECT ROW_NUMBER() OVER (ORDER BY scene_index) AS nth, * FROM scene;\n \n # select * from scene_view;\n nth | scene_index | accountd | scene_name | created_date \n -----+-------------+----------+--------------+--------------\n 1 | 1 | 120 | 初ステージ | 2013-06-22\n 2 | 2 | 59 | てすと | 2012-12-22\n 3 | 3 | 301217 | 作れたかな? | 2015-02-03\n 4 | 4 | 982 | あああ | 2014-08-22\n (4 rows)\n \n # delete from scene where scene_index = 2;\n # select * from scene_view;\n nth | scene_index | accountd | scene_name | created_date \n -----+-------------+----------+--------------+--------------\n 1 | 1 | 120 | 初ステージ | 2013-06-22\n 2 | 3 | 301217 | 作れたかな? | 2015-02-03\n 3 | 4 | 982 | あああ | 2014-08-22\n (3 rows)\n \n # insert into scene values(0, 0, 'ゼロ', '1970/1/1');\n # select * from scene_view;\n nth | scene_index | accountd | scene_name | created_date \n -----+-------------+----------+--------------+--------------\n 1 | 0 | 0 | ゼロ | 1970-01-01\n 2 | 1 | 120 | 初ステージ | 2013-06-22\n 3 | 3 | 301217 | 作れたかな? | 2015-02-03\n 4 | 4 | 982 | あああ | 2014-08-22\n (4 rows)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T12:13:42.503", "id": "37509", "last_activity_date": "2017-08-26T12:13:42.503", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "37503", "post_type": "answer", "score": 2 }, { "body": "> scene_indexが5~10までのデータを取り出したい\n\nであれば、`scene_index`の **値**\nで絞り込むのではなく[LIMITとOFFSET](https://www.postgresql.jp/document/7.3/user/queries-\nlimit.html)を使用して5行目から6行を表す\n\n```\n\n LIMIT 6 OFFSET 5\n \n```\n\nを指定することで実現できますので、`scene_index`の値にこだわる必要はないかもしれません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T13:05:20.853", "id": "37512", "last_activity_date": "2017-08-26T22:22:38.990", "last_edit_date": "2017-08-26T22:22:38.990", "last_editor_user_id": "4236", "owner_user_id": "4236", "parent_id": "37503", "post_type": "answer", "score": 4 } ]
37503
37509
37512
{ "accepted_answer_id": null, "answer_count": 2, "body": "es6からcalssが使えるようになりましたが,c#のように他のファイルでclassを書いてから使用する方法を教えてください。 \n(環境はnode.jsでコマンドプロンプト上で実行しています)\n\n[マルチポスト](https://teratail.com/questions/89887)", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T06:28:57.607", "favorite_count": 0, "id": "37504", "last_activity_date": "2017-08-29T05:32:16.027", "last_edit_date": "2017-08-26T07:13:42.467", "last_editor_user_id": "8100", "owner_user_id": "8100", "post_type": "question", "score": 1, "tags": [ "javascript", "node.js", "es6" ], "title": "classを別ファイルから使用する", "view_count": 3501 }
[ { "body": "コメントのリンクを参考に以下のようにすればうまくいきました。 \nclass編集側のファイル\n\n```\n\n module.exports = class Cat{\n // クラスの中み\n }\n \n```\n\n利用側のファイル\n\n```\n\n const Cat = require(./ファイル名);\n let cat = new Cat;\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T08:22:32.693", "id": "37507", "last_activity_date": "2017-08-26T08:22:32.693", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8100", "parent_id": "37504", "post_type": "answer", "score": 3 }, { "body": "ES6の場合、クラスの定義は下記で\n\n```\n\n export default class Cat {\n }\n \n```\n\n使用する側はこれでいいかと思います。\n\n```\n\n import Cat from 'Cat';\n \n```\n\n上記を実行する際はbabelでトランスパイルする必要があります。追記させていただきましたm(__)m", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T01:17:29.147", "id": "37552", "last_activity_date": "2017-08-29T05:32:16.027", "last_edit_date": "2017-08-29T05:32:16.027", "last_editor_user_id": "7585", "owner_user_id": "7585", "parent_id": "37504", "post_type": "answer", "score": 0 } ]
37504
null
37507
{ "accepted_answer_id": null, "answer_count": 1, "body": "指定したユーザのツイートから特定のハッシュタグがついてツイートをランダムで一件だけ取得する方法を探しています。\n\n[TwitterのREST\nAPIのドキュメント](https://dev.twitter.com/rest/reference/get/search/tweets)を見ましたが、これを実現できそうなAPIは無さそうでした。 \nTwitterのAPIを使わなくとも、何がいい方法があればお願いします。\n\nちなみに上記を利用してAndroidアプリの作成を考えています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T07:42:19.023", "favorite_count": 0, "id": "37505", "last_activity_date": "2017-08-26T08:20:48.677", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "21081", "post_type": "question", "score": 0, "tags": [ "android", "twitter" ], "title": "TwitterからユーザIDとハッシュタグを指定してランダムにツイートを取得する方法はありますか?", "view_count": 847 }
[ { "body": "検索API (`search/tweets`)に `from:jack #ImWithKap` のようなscreen\nnameとハッシュタグを含めた検索クエリを投げ、結果からランダムに選択することで実現は可能かと思います。\n\nただし、\n\n * 検索APIのサンプル対象は近傍1週間\n * 一度のリクエストで取得できる件数は100件まで\n\nなどといった制約があるので注意が必要です。 \n(公式アプリのCK専用のエンドポイントでは前者の制約が回避できますがここでは割愛します)\n\n[The Search API — Twitter\nDevelopers](https://dev.twitter.com/rest/public/search)\n\n(既に登録されていることを前提にtwilog等の外部ログサービスの検索をスクレイピングしたりすることも可能かもしれませんが、おすすめはしません。)", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T08:20:48.677", "id": "37506", "last_activity_date": "2017-08-26T08:20:48.677", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2376", "parent_id": "37505", "post_type": "answer", "score": 1 } ]
37505
null
37506
{ "accepted_answer_id": null, "answer_count": 1, "body": "### 内容\n\nWebpackでjQueryのスライダー用ライブラリSlickを使用しているのですが、 \nslick-theme.scssをimportするとscss内で定義されている画像とフォントのパスが \nlocalhostのドキュメントルートからのパスになってしまい404 Not Foundとなってしまいます。\n\n現状回避策として、htmlファイルに直接書きを記述することでslick-theme.cssのみWeb上から読み込んでいる状態です。\n\n```\n\n <link rel=\"stylesheet\" type=\"text/css\" href=\"http://cdn.jsdelivr.net/jquery.slick/1.6.0/slick-theme.css\"/>\n \n```\n\n### ディレクトリ構造\n\n```\n\n [ProjectDirectory]\n ├── package.json\n ├── public\n │ ├── commons.js\n │ ├── entry.js\n │ ├── detail\n │ │ └── 1.html\n │ └── js\n │ └── ①detail.js(この中でslickをimport)\n ├── src\n │ ├── entry.js\n │ └── js\n │ ├── _common.js\n │ ├── detail.js\n │ └── list.js\n └── ②webpack.config.babel.js\n \n```\n\n#### ①detail.js\n\n```\n\n // <[slick読み込み]===============================>\n import 'slick-carousel';\n import 'slick-carousel/slick/slick.scss';\n import 'slick-carousel/slick/slick-theme.scss';\n \n // <[slickerの設定]>============================>\n $('.slider').slick({\n dots: true,\n centerMode: true,\n centerPadding: '150px',\n responsive: [\n {\n breakpoint: 767,\n settings: {\n centerMode: false\n }\n }\n ]\n })\n \n```\n\n#### ②webpack.config.js\n\n```\n\n 'use strict';\n // <[Origin]==================================>\n const\n webpack = require('webpack'),\n path = require('path'),\n autoprefixer = require('autoprefixer'),\n precss = require('precss')\n \n // <[Paths]==================================>\n const\n src_path = path.resolve(__dirname, 'src'),\n dist_path = path.resolve(__dirname, 'public')\n \n // <[Plugins]==================================>\n const\n CommonsChunkPlugin = new webpack.optimize.CommonsChunkPlugin({\n name: 'commons',\n filename: 'commons.js'\n }),\n jQuery = new webpack.ProvidePlugin({\n $: 'jquery',\n jQuery: 'jquery'\n }),\n NamedModulesPlugin = new webpack.NamedModulesPlugin(),\n HotModuleReplacementPlugin = new webpack.HotModuleReplacementPlugin(),\n LoaderOptionsPlugin = new webpack.LoaderOptionsPlugin({\n options: {\n postcss: [\n require('autoprefixer')({\n browsers: ['last 2 versions']\n })\n ]\n }\n })\n \n // <[ModuleRules]=============================>\n const\n LOADER_ES6 = {\n test: /\\.js$/,\n include: src_path,\n use: [{\n loader: 'babel-loader',\n options: {\n presets: [\n ['es2015', {modules: false}]\n ]\n }\n }]\n },\n LOADER_SCSS = {\n test: /\\.(css|scss)$/,\n loader: ['style-loader', 'css-loader?-url', 'sass-loader', 'postcss-loader']\n },\n LOADER_OTHERS = {\n test: /\\.(eot|svg|woff|ttf|gif)$/,\n loader: 'url-loader'\n }\n \n \n // <[CoreConfigs]=============================>\n const\n config = {\n context: src_path,\n entry: {\n 'entry': './entry.js',\n 'js/list': './js/list.js',\n 'js/detail': './js/detail.js'\n },\n output: {\n path: dist_path,\n publicPath: '/',\n filename: '[name].js'\n },\n module: {\n rules: [\n LOADER_ES6,\n LOADER_SCSS,\n LOADER_OTHERS\n ],\n },\n plugins: [\n jQuery,\n NamedModulesPlugin,\n HotModuleReplacementPlugin,\n CommonsChunkPlugin,\n LoaderOptionsPlugin\n ],\n devServer: {\n contentBase: dist_path,\n port: 8080,\n inline: true,\n hot: true\n }\n }\n \n module.exports = config;\n \n```\n\n### ブラウザで表示されるエラーログ\n\n```\n\n http://localhost:8080/detail/ajax-loader.gif 404 (Not Found)\n http://localhost:8080/detail/fonts/slick.woff\n http://localhost:8080/detail/fonts/slick.ttf \n \n```", "comment_count": 1, "content_license": "CC BY-SA 4.0", "creation_date": "2017-08-26T10:39:58.433", "favorite_count": 0, "id": "37508", "last_activity_date": "2023-08-22T04:15:25.657", "last_edit_date": "2023-08-22T04:15:25.657", "last_editor_user_id": "3060", "owner_user_id": "25054", "post_type": "question", "score": 0, "tags": [ "webpack", "slick.js" ], "title": "WebpackでSlick.jsを使用する際に、\"slick-theme.scss\"内で使用されている画像とフォントが読み込めない", "view_count": 3590 }
[ { "body": "slick-theme.scssファイル内で以下のパスが設定されているので、`/detail`からの相対パスになってしまっているようです。\n\n```\n\n $slick-font-path: \"./fonts/\" !default;\n $slick-loader-path: \"./\" !default;\n \n```\n\n私のプロジェクトではscssからslickのスタイルをimportをしているのですが、そこでfile-pathを設定しています。\n\n```\n\n // プロジェクト内のscss\n $slick-font-path: \"~slick-carousel/slick/fonts/\";\n $slick-loader-path: \"~slick-carousel/slick/\";\n @import \"~slick-carousel/slick/slick.scss\";\n @import \"~slick-carousel/slick/slick-theme.scss\";\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T01:56:11.233", "id": "37554", "last_activity_date": "2017-08-29T01:56:11.233", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25076", "parent_id": "37508", "post_type": "answer", "score": 1 } ]
37508
null
37554
{ "accepted_answer_id": "37516", "answer_count": 1, "body": "EC2のセキュリティグループ設定時にIPアドレスの末尾に付加する/24等の意味を教えてください\n\nSSH TCP 22 0.0.0.0/0 <\\- この/0の意味が分かりません \nSSH TCP 22 113.52.16.113/32 <\\- この/32の意味が分かりません\n\nご教授をお願いします。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2017-08-26T22:22:57.783", "favorite_count": 0, "id": "37515", "last_activity_date": "2021-03-08T04:26:53.310", "last_edit_date": "2021-03-08T04:26:53.310", "last_editor_user_id": "4236", "owner_user_id": "24920", "post_type": "question", "score": 3, "tags": [ "amazon-ec2" ], "title": "EC2のセキュリティグループ設定時にIPアドレスの末尾に付加する/24等の意味", "view_count": 1110 }
[ { "body": "設定するのは正確には「IPアドレス」ではなく[CIDR; Classless Inter-Domain\nRouting](https://ja.wikipedia.org/wiki/Classless_Inter-\nDomain_Routing)と呼ばれる「IPアドレス範囲」です。\n\n0.0.0.0/0 は 0.0.0.0~255.255.255.255 つまりIPv4全体を表し、 \n113.52.16.113/32 は 113.52.16.113~113.52.16.113 つまり113.52.16.113のみを表します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-26T22:29:34.820", "id": "37516", "last_activity_date": "2017-08-26T22:29:34.820", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "37515", "post_type": "answer", "score": 7 } ]
37515
37516
37516
{ "accepted_answer_id": null, "answer_count": 2, "body": "すみません、初心者です。vagrant+centos6にmysqlをインストールすると以下の通りエラーが出るのですが、どなたか解決方法をご教示いただけないでしょうか?\n\n```\n\n [vagrant@localhost ~]$ sudo rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm\n http://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm を取得中\n 警告: /var/tmp/rpm-tmp.5Iv17p: ヘッダ V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY\n 準備中... ########################################### [100%]\n 1:mysql57-community-relea########################################### [100%]\n [vagrant@localhost ~]$ sudo yum install mysql mysql-devel mysql-server mysql-utilities\n 読み込んだプラグイン:fastestmirror\n インストール処理の設定をしています\n Loading mirror speeds from cached hostfile\n * base: www.ftp.ne.jp\n * epel: mirror.premi.st\n * extras: www.ftp.ne.jp\n * updates: ftp.iij.ad.jp\n パッケージ mysql は mysql-community-client によって不要になりました。代わりに mysql-community-client-5.7.19-1.el7.x86_64 のインストールを試みています。\n パッケージ mysql-devel は mysql-community-devel によって不要になりました。代わりに mysql-community-devel-5.7.19-1.el7.x86_64 のインストールを試みています。\n パッケージ mysql-server は mysql-community-server によって不要になりました。代わりに mysql-community-server-5.7.19-1.el7.x86_64 のインストールを試みています。\n 依存性の解決をしています\n --> トランザクションの確認を実行しています。\n ---> Package mysql-community-client.x86_64 0:5.7.19-1.el7 will be インストール\n --> 依存性の処理をしています: mysql-community-libs(x86-64) >= 5.7.9 のパッケージ: mysql-community-client-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libstdc++.so.6(GLIBCXX_3.4.15)(64bit) のパッケージ: mysql-community-client-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libc.so.6(GLIBC_2.14)(64bit) のパッケージ: mysql-community-client-5.7.19-1.el7.x86_64\n ---> Package mysql-community-devel.x86_64 0:5.7.19-1.el7 will be インストール\n ---> Package mysql-community-server.x86_64 0:5.7.19-1.el7 will be インストール\n --> 依存性の処理をしています: mysql-community-common(x86-64) = 5.7.19-1.el7 のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: systemd のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: systemd のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libstdc++.so.6(GLIBCXX_3.4.15)(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libnuma.so.1(libnuma_1.2)(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libnuma.so.1(libnuma_1.1)(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libc.so.6(GLIBC_2.17)(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libsasl2.so.3()(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libnuma.so.1()(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n ---> Package mysql-utilities.noarch 0:1.6.5-1.el7 will be インストール\n --> 依存性の処理をしています: python(abi) = 2.7 のパッケージ: mysql-utilities-1.6.5-1.el7.noarch\n --> 依存性の処理をしています: mysql-connector-python >= 2.0.0 のパッケージ: mysql-utilities-1.6.5-1.el7.noarch\n --> トランザクションの確認を実行しています。\n ---> Package mysql-community-client.x86_64 0:5.7.19-1.el7 will be インストール\n --> 依存性の処理をしています: libstdc++.so.6(GLIBCXX_3.4.15)(64bit) のパッケージ: mysql-community-client-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libc.so.6(GLIBC_2.14)(64bit) のパッケージ: mysql-community-client-5.7.19-1.el7.x86_64\n ---> Package mysql-community-common.x86_64 0:5.7.19-1.el7 will be インストール\n ---> Package mysql-community-libs.x86_64 0:5.7.19-1.el7 will be インストール\n --> 依存性の処理をしています: libc.so.6(GLIBC_2.14)(64bit) のパッケージ: mysql-community-libs-5.7.19-1.el7.x86_64\n ---> Package mysql-community-server.x86_64 0:5.7.19-1.el7 will be インストール\n --> 依存性の処理をしています: systemd のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: systemd のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libstdc++.so.6(GLIBCXX_3.4.15)(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libc.so.6(GLIBC_2.17)(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n --> 依存性の処理をしています: libsasl2.so.3()(64bit) のパッケージ: mysql-community-server-5.7.19-1.el7.x86_64\n ---> Package mysql-connector-python.x86_64 0:2.1.7-1.el7 will be インストール\n --> 依存性の処理をしています: python(abi) = 2.7 のパッケージ: mysql-connector-python-2.1.7-1.el7.x86_64\n ---> Package mysql-utilities.noarch 0:1.6.5-1.el7 will be インストール\n --> 依存性の処理をしています: python(abi) = 2.7 のパッケージ: mysql-utilities-1.6.5-1.el7.noarch\n ---> Package numactl.x86_64 0:2.0.9-2.el6 will be インストール\n --> 依存性解決を終了しました。\n エラー: パッケージ: mysql-community-client-5.7.19-1.el7.x86_64 (mysql57-community)\n 要求: libc.so.6(GLIBC_2.14)(64bit)\n エラー: パッケージ: mysql-community-libs-5.7.19-1.el7.x86_64 (mysql57-community)\n 要求: libc.so.6(GLIBC_2.14)(64bit)\n エラー: パッケージ: mysql-utilities-1.6.5-1.el7.noarch (mysql-tools-community)\n 要求: python(abi) = 2.7\n インストール: python-2.6.6-66.el6_8.x86_64 (@base)\n python(abi) = 2.6\n 利用可能: python34-3.4.5-2.el6.i686 (epel)\n python(abi) = 3.4\n エラー: パッケージ: mysql-connector-python-2.1.7-1.el7.x86_64 (mysql-connectors-community)\n 要求: python(abi) = 2.7\n インストール: python-2.6.6-66.el6_8.x86_64 (@base)\n python(abi) = 2.6\n 利用可能: python34-3.4.5-2.el6.i686 (epel)\n python(abi) = 3.4\n エラー: パッケージ: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community)\n 要求: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)\n エラー: パッケージ: mysql-community-client-5.7.19-1.el7.x86_64 (mysql57-community)\n 要求: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)\n エラー: パッケージ: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community)\n 要求: libsasl2.so.3()(64bit)\n エラー: パッケージ: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community)\n 要求: libc.so.6(GLIBC_2.17)(64bit)\n エラー: パッケージ: mysql-community-server-5.7.19-1.el7.x86_64 (mysql57-community)\n 要求: systemd\n 問題を回避するために --skip-broken を用いることができません\n これらを試行できます: rpm -Va --nofiles --nodigest\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T00:40:10.833", "favorite_count": 0, "id": "37517", "last_activity_date": "2019-04-05T12:03:20.657", "last_edit_date": "2017-08-27T02:41:38.777", "last_editor_user_id": "19110", "owner_user_id": "25057", "post_type": "question", "score": 0, "tags": [ "mysql", "centos", "vagrant" ], "title": "vagrant+centos6にmysqlをインストールするとエラーが出る", "view_count": 1254 }
[ { "body": "```\n\n yum install http://dev.mysql.com/get/mysql-community-release-el6-11.noarch.rpm\n \n```\n\nでもNGでしたが、\n\n```\n\n yum -y install mysql-server\n \n```\n\nでやってみたら、インストールできました。\n\nとにかく、 \n<http://dev.mysql.com/get/mysql-community-release-el6-11.noarch.rpm> \nへのアクセスを拒まれている感じでした。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T03:27:07.743", "id": "37519", "last_activity_date": "2018-01-30T11:48:55.743", "last_edit_date": "2018-01-30T11:48:55.743", "last_editor_user_id": "3060", "owner_user_id": "25057", "parent_id": "37517", "post_type": "answer", "score": 0 }, { "body": "既に解決されているようですが rpm の依存関係のチェックで弾かれています。 \nrpm パッケージは他のrpmパッケージに依存している場合があります。 \n依存先のパッケージを先に(もしくは同時に)インストールする必要があります。\n\nmysql-community-libs-5.7.19-1.el7.x86_64が依存しているパッケージは次のコマンドで確認することができます。\n\n```\n\n # rpm -qpR mysql57-community-release-el6-11.noarch.rpm\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2018-01-30T10:21:10.940", "id": "41325", "last_activity_date": "2018-01-30T10:21:10.940", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "37517", "post_type": "answer", "score": 1 } ]
37517
null
41325
{ "accepted_answer_id": "37556", "answer_count": 1, "body": "[2 つめの WebExtension - Mozilla | MDN](https://developer.mozilla.org/ja/Add-\nons/WebExtensions/Walkthrough#choose_beast.js)の`choose_beast.js`のコード中で`chrome`となっている部分が、[英語版](https://developer.mozilla.org/en-\nUS/Add-\nons/WebExtensions/Your_second_WebExtension#choose_beast.js)では`browser`となっています。どちらも同じように動作するようですが、これら2つの違いは何なのでしょうか?", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T07:27:19.307", "favorite_count": 0, "id": "37523", "last_activity_date": "2017-08-29T03:40:28.317", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13199", "post_type": "question", "score": 1, "tags": [ "javascript", "firefox-webextension" ], "title": "'browser'と'chrome'の違いは何ですか?", "view_count": 201 }
[ { "body": "どちらもJavaScript APIの名前空間ですが、`chrome`はGoogle\nChrome向けに作られた拡張機能の移植のために用意されています。より具体的には、`browser`では非同期処理のために`Promise`及びコールバックベースのAPIが利用できますが、`chrome`ではコールバックベースのAPIしか利用できないという違いがあります。\n\nちなみにGoogle\nChromeでは`chrome`を、Edgeでは`browser`を使いますが、どちらもコールバックのみで`Promise`はサポートされていません。\n\n参考: \nGoogle Chrome: [JavaScript APIs - Google\nChrome](https://developer.chrome.com/apps/api_index) \nMicrosoft Edge: [Extensions - Supported APIs - Microsoft Edge Development |\nMicrosoft Docs](https://docs.microsoft.com/en-us/microsoft-\nedge/extensions/api-support/supported-apis) \nMozilla Firefox: [JavaScript APIs - Mozilla |\nMDN](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T03:40:28.317", "id": "37556", "last_activity_date": "2017-08-29T03:40:28.317", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13199", "parent_id": "37523", "post_type": "answer", "score": 1 } ]
37523
37556
37556
{ "accepted_answer_id": null, "answer_count": 0, "body": "ヘルパー関数とはどういったものでしょうか。 \n自分自身、JavaやJavaScriptの経験があり、JavaやJavaScriptのコードを例にヘルパー関数について理解を深めたいのですが説明しているサイトがなかなか見つからないです。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T11:35:54.253", "favorite_count": 0, "id": "37525", "last_activity_date": "2017-08-28T00:07:44.027", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "17348", "post_type": "question", "score": 0, "tags": [ "javascript", "java" ], "title": "ヘルパー関数について。", "view_count": 7528 }
[]
37525
null
null
{ "accepted_answer_id": "37530", "answer_count": 1, "body": "とある組み込みマイコン向けのHTTPライブラリで難儀しています。 \nライブラリにgetという関数があり、これを実行すると指定したURLにHTTP 1.1でGETを発行して、応答の本文を文字列として返してくるのですが、 \nサーバーがChunked transfer encodingで応答すると(即ち、応答ヘッダに Transfer-Encoding: Chunked\nが含まれた状態)、これをデコードせずに生の文字列を返してしまうのです。\n\n応答ヘッダを取得することはできないので、プログラム側でチャンクをデコードすることはできません。(チャンク化されているかどうかを一意に判別できないため) \nまた、TCPやHTTPを含めた一切の通信処理は、完全に独立したMCU内で処理されるため、自分でsocketを使ってHTTPを実装することもできません。「\n\n但し、get関数の引数として、要求ヘッダに1行だけ任意のヘッダを追加できる機能があるので、これを利用して、サーバーに、チャンク化しないように要求できないかと考えているのですが・・・ \n何か方法はないでしょうか?", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T14:01:09.380", "favorite_count": 0, "id": "37527", "last_activity_date": "2017-08-27T19:52:14.697", "last_edit_date": "2017-08-27T14:38:48.950", "last_editor_user_id": "20722", "owner_user_id": "20722", "post_type": "question", "score": 1, "tags": [ "http" ], "title": "HTTP 1.1でChunked transfer encodingを拒否する方法", "view_count": 6709 }
[ { "body": "OOPerさんのコメントにあるようにHTTP/1.1において`Transfer-Encoding:\nchunked`への対応は必須ですので、未対応ということは不正なクライアントであるとしか言いようがありません。 \n補足をしておくと、HTTP/1.0ではコンテンツ長が不明な場合、コネクション切断をもってコンテンツの終端を表していましたが、これでは異常終了と区別できません。HTTP/1.1で`chunked`が導入され必須となっているのもコンテンツ長が不明なコンテンツを正確に扱うためです。\n\n> get関数の引数として、要求ヘッダに1行だけ任意のヘッダを追加できる機能があるので、これを利用して、サーバーに、チャンク化しないように要求できないか\n\n[TEヘッダー](https://www.rfc-\neditor.org/rfc/rfc7230#section-4.3)を用いることでクライアント側が解釈可能な`Transfer-\nEncoding`を事前通知することができます。この機能が正攻法ではありますが、既に説明しているように`chunked`は必須なためこれを拒否するようなリクエストは認められていません。\n\n期待通りの動作をするか確実ではありませんが、WebサーバーApacheのデフォルト設定には[おかしな挙動をするクライアントに対してプロトコルの動作を変更する](http://httpd.apache.org/docs/current/env.html#examples)というものがあります。設定内容としては\n\n```\n\n BrowserMatch \"MSIE 4\\.0b2;\" nokeepalive downgrade-1.0 force-response-1.0\n BrowserMatch \"RealPlayer 4\\.0\" force-response-1.0\n BrowserMatch \"Java/1\\.0\" force-response-1.0\n BrowserMatch \"JDK/1\\.0\" force-response-1.0\n \n```\n\n等があります。これを逆手にとって、`User-Agent: MSIE\n4.0b2;`等を送信することで、Webサーバーに対してHTTP/1.0で応答するように求めることができるかもしれません。HTTP/1.0であれば`chunked`は存在しませんので`Transfer-\nEncoding: chunked`が返されることはないはずです。 \n(WebサーバーがApacheとは限りませんが、おかしな挙動をするクライアント対策が施されていることを期待してということです。)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T19:52:14.697", "id": "37530", "last_activity_date": "2017-08-27T19:52:14.697", "last_edit_date": "2021-10-07T07:34:52.683", "last_editor_user_id": "-1", "owner_user_id": "4236", "parent_id": "37527", "post_type": "answer", "score": 2 } ]
37527
37530
37530
{ "accepted_answer_id": "37529", "answer_count": 1, "body": "自作クラスのオブジェクト作成時の挙動と、自身のオブジェクトを表す `self` の挙動に関して、 \n以下の2つの不明点があり解決出来ません。 \n解決方法を教えて頂きたいですm(__)m\n\n## 1\\. **1つ目の不明点(自作クラスのオブジェクト生成時の挙動)**\n\n`scikit-learn` ライブラリの推定器 estimator の基本クラス\n`sklearn.base.BaseEstimator`,`sklearn.base.ClassifierMixin` を多重継承した、 \n自作クラス `class EnsembleLearningClassifier( BaseEstimator, ClassifierMixin ):`\nを生成する際に、以下のような記述をすると、コンパイルエラーが出てしまう。 \nエラー内容は、 **TypeError: 'module' object is not callable**\n\n```\n\n import EnsembleLearningClassifier\n \n ensemble_clf1 = EnsembleLearningClassifier( \n classifiers = [ pipe1, pipe2, pipe3 ],\n class_labels = [ \"Logistic Regression\", \"Decision Tree\", \"k-NN\" ]\n )\n \n```\n\n以下のようにすると、コンパイルエラーにならない。\n\n```\n\n import EnsembleLearningClassifier\n \n ensemble_clf1 = EnsembleLearningClassifier.EnsembleLearningClassifier( \n classifiers = [ pipe1, pipe2, pipe3 ],\n class_labels = [ \"Logistic Regression\", \"Decision Tree\", \"k-NN\" ]\n )\n \n```\n\n## 2\\. **2つ目の不明点(自身のオブジェクトを表す`self` の挙動)**\n\n自作クラス `EnsembleLearningClassifier` のオブジェクト作成後、自身のオブジェクトを表す `self` の 属性値が\n`classifiers=None` になってしまう。 \n以下、オブジェクトの生成コード\n\n```\n\n ensemble_clf1 = EnsembleLearningClassifier.EnsembleLearningClassifier( \n classifiers = [ pipe1, pipe2, pipe3 ],\n class_labels = [ \"Logistic Regression\", \"Decision Tree\", \"k-NN\" ]\n )\n \n```\n\n以下、 `EnsembleLearningClassifier` 自作クラスのオブジェクト `ensemble_clf1` での、print\n関数`ensemble_clf1.print(\"ensemble_clf1\")`の実行結果。 \nオブジェクト生成時に、コンストラクタの引数を `classifiers = [ pipe1, pipe2, pipe3\n]`と設定したにも関わらず、自身のオブジェクトを表す `self` の 属性値が `classifiers=None` になってしまう。 \nこれを `classifiers=[ pipe1, pipe2, pipe3 ]`となるように修正したい。\n\n```\n\n -------------------------------------------------------------------\n ensemble_clf1\n \n [Attributes]\n __classifiers :\n Pipeline(steps=[('sc', StandardScaler(copy=True, with_mean=True, with_std=True)), ('clf', LogisticRegression(C=0.001, class_weight=None, dual=False, fit_intercept=True,\n intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n penalty='l2', random_state=0, solver='liblinear', tol=0.0001,\n verbose=0, warm_start=False))])\n Pipeline(steps=[('sc', StandardScaler(copy=True, with_mean=True, with_std=True)), ('clf', DecisionTreeClassifier(class_weight=None, \n \n criterion='entropy', max_depth=3,\n max_features=None, max_leaf_nodes=None,\n min_impurity_split=1e-07, min_samples_leaf=1,\n min_samples_split=2, min_weight_fraction_leaf=0.0,\n presort=False, random_state=0, splitter='best'))])\n Pipeline(steps=[('sc', StandardScaler(copy=True, with_mean=True, with_std=True)), ('clf', KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n metric_params=None, n_jobs=1, n_neighbors=3, p=2,\n weights='uniform'))])\n __n_classifier : 3\n __class_labels : ['Logistic Regression', 'Decision Tree', 'k-NN']\n __weights : None\n __vote_method : majority_vote\n \n [self]\n EnsembleLearningClassifier(class_labels=None, classifiers=None, vote=None,\n weights=None)\n -------------------------------------------------------------------\n \n```\n\n**デバッグ画面:** \n`all_clf[3]` の値が `EnsembleLearningClassifier(class_labels=None,\nclassifiers=None, vote=None,weights=None)`となってしまう。 \nオブジェクト生成時に、コンストラクタの引数を `classifiers = [ pipe1, pipe2, pipe3\n]`と設定したにも関わらず、自身のオブジェクトを表す `self` の 属性値が `classifiers=None` になってしまう。 \nこれを `classifiers=[ pipe1, pipe2, pipe3 ]`となるように修正したい。\n\n[![デバッグ画面](https://i.stack.imgur.com/qN02F.png)](https://i.stack.imgur.com/qN02F.png)\n\n> **< 実装中のコード>**\n>\n> 以下のリンク先(GitHub)の `main2.py`,`EnsembleLearningClassifier.py`ファイル \n>\n> <https://github.com/Yagami360/MachineLearning_Samples_Python/tree/master/EnsembleLearning_scikit-\n> learn>\n\n<参考URL>\n\n> scikit-learn ライブラリ\n>\n\n>> 開発者向け情報 : \n> <http://scikit-learn.org/stable/developers/contributing.html#rolling-your-\n> own-estimator> \n> `sklearn.base` モジュールの API Reference \n> `sklearn.base` : \n> <http://scikit-learn.org/stable/modules/classes.html#module-sklearn.base> \n> `sklearn.base.BaseEstimator` : \n> <http://scikit-\n> learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html#sklearn.base.BaseEstimator>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T14:20:48.827", "favorite_count": 0, "id": "37528", "last_activity_date": "2017-08-27T16:10:43.013", "last_edit_date": "2017-08-27T15:24:39.537", "last_editor_user_id": "20266", "owner_user_id": "20266", "post_type": "question", "score": 0, "tags": [ "python", "機械学習", "scikit-learn" ], "title": "scikit-learn ライブラリを継承した自作クラスのオブジェクト生成時にエラー : TypeError: 'module' object is not callable が発生してしまう。又、自身のオブジェクトを表す self が 意図に反して None となってしまう。", "view_count": 1164 }
[ { "body": "**1\\. について** \nPythonでは`import\n<モジュール名>`とすると、`<モジュール名>.<モジュール内で定義された名前>`という形でアクセスできるようになります。もし一番目のコードのようにモジュール名を省略したいのであれば、`from\n<モジュール名> import <モジュール内で定義された名前>`と書く必要があります。\n\n**2.について** \nこちらは動かしてみたわけでもないので自信が無いですが、\n\n[挙げられたドキュメント](http://scikit-\nlearn.org/stable/modules/generated/sklearn.base.BaseEstimator.html#sklearn.base.BaseEstimator)の以下の記述\n\n> Notes\n>\n> All estimators should specify all the parameters that can be set at the\n> class level in their **init** as explicit keyword arguments (no *args or\n> **kwargs).\n\n及び[BaseEstimatorのソース](https://github.com/scikit-learn/scikit-\nlearn/blob/ef5cb84a/sklearn/base.py#L175)を見る限り\n\n```\n\n EnsembleLearningClassifier(class_labels=None, classifiers=None, vote=None, weights=None)\n \n```\n\nという内容は`__init__`の引数と同名の属性を探し出して値として表示しているようなので、\n**引数と同じ名前の属性を定義する、具体的には`__init__`中に`self.classifiers =\nclassifiers`といった記述を行う必要がある**のだと思います。 \n(BaseEstimatorのコード中には`value = getattr(self, key,\nNone)`という記述があり、属性が存在しない場合に`None`になるので、今回の事例にも合致します)", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-27T16:10:43.013", "id": "37529", "last_activity_date": "2017-08-27T16:10:43.013", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13199", "parent_id": "37528", "post_type": "answer", "score": 1 } ]
37528
37529
37529
{ "accepted_answer_id": "37533", "answer_count": 1, "body": "Railsのhas_many, belongs_toを両方のモデルで指定する必要性はなんなのでしょうか。\n\nRailsチュートリアル(<https://railstutorial.jp/book/ruby-on-rails-\ntutorial?version=4.2#sec-demo_user_has_many_microposts>) \nの例を見ると片方にはhas_manyを、もう片方にはbelong_toを指定しています。\n\nですが、私の経験上has_manyだけ指定してbelong_toは書かなくても、joinする分には困らないなとの認識です。\n\n 1. 両方のモデルで指定する必要があるか?\n 2. 必要が無い場合は、両方のモデルで指定するメリットは何か?\n\nこの2点についてアドバイスいただけると助かります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T02:05:25.873", "favorite_count": 0, "id": "37532", "last_activity_date": "2017-08-28T02:38:34.293", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25065", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails" ], "title": "Railsのhas_many, belongs_toを両方のモデルで指定する必要性について", "view_count": 1710 }
[ { "body": "1、あくまでリレーションなので、モデル間で参照がない場合はhas_manyやbelongs_toは必要ないです。\n\n例えば \nCategoryがBookを複数持っている時\n\n```\n\n class Category < ApplicationRecord\n has_many :books\n end\n \n```\n\nは`category.books`でそのカテゴリーに含まれている本を全て取得できます。 \n一方でcontrollerなどのコード中に`book.category`、この本がどのカテゴリーに含まれているかという参照がないなら\n\n```\n\n class Book < ApplicationRecord\n belongs_to :category\n end\n \n```\n\nの記述は無くてもよいです。\n\n2、に関してですが、コードを見た時にリレーションがわかりやすいくらいだと思います。\n\n個人的な感想ですが、あった方がモデル間の関係がわかりやすくなるので、 \n特に理由がなければ、書いてあった方が良いと思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T02:27:42.190", "id": "37533", "last_activity_date": "2017-08-28T02:38:34.293", "last_edit_date": "2017-08-28T02:38:34.293", "last_editor_user_id": "5436", "owner_user_id": "5436", "parent_id": "37532", "post_type": "answer", "score": 2 } ]
37532
37533
37533
{ "accepted_answer_id": "37537", "answer_count": 1, "body": "**CentOS7 導入を検討しているのですが、MariaDB が採用された理由は何でしょうか?** \n・MySQLは完全なオープンソースではない?\n\n* * *\n\n**質問背景** \n・MySQL使用継続を考えているのですが、MariaDB が今後標準となっていくのなら、このタイミングで切り替えた方が良いかも、と悩んでいます \n・MySQLバージョンアップデートする際、バージョン間差異が結構あって苦労したので、「DB変更だとそれ以上に大変かも。なるべく避けたい」と思っているのですが……\n\n* * *\n\n**現在の環境** \n・CentOS6 \n・MySQL5.7", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T04:32:42.800", "favorite_count": 0, "id": "37535", "last_activity_date": "2017-08-28T05:06:06.893", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7886", "post_type": "question", "score": 1, "tags": [ "mysql", "centos", "mariadb" ], "title": "CentOS 7 で MariaDB が採用された理由について", "view_count": 1244 }
[ { "body": "CentOSはRHEL(RedHat Enterprise\nLinux)をベースにしたディストリビューションですので、正確にはRHELの意向に従った形になります。\n\nmariaDBの誕生、及びRHELをはじめ多くのディストリビューションがmariaDBに移行したきっかけは、MySQLがSun\nMicrosystemsと共にOracleに買収されたことにより、MySQLの今後に不安を感じたからだと言われています。\n\n元々Oracleは商用DBを持っており、オープンソースのMySQLを引き取ったけどちゃんと今まで通りMySQLの面倒を見てくれるの?といったところでしょうか。\n\n<http://enterprisezine.jp/dbonline/detail/4220> \n<https://japan.zdnet.com/article/35056719/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T05:06:06.893", "id": "37537", "last_activity_date": "2017-08-28T05:06:06.893", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "37535", "post_type": "answer", "score": 3 } ]
37535
37537
37537
{ "accepted_answer_id": "37549", "answer_count": 1, "body": "v-initで2バイト文字を渡すと、以下のエラーになりますが原因がわかりません。 \n半角英数字及び、objectであれば渡せます。 \nvue.js自体がbindでの2バイト文字を許容していないのでしょうか? \nphpのblade画面からデータを取得する必要があるため、dataに初期定義することはできません。\n\n**v-init=\"あああ\"** \nVue warn]: Property or method \"あああ\" is not defined on the instance but\nreferenced during render. Make sure to declare reactive data properties in the\ndata option.\n\n**v-init=\"1234\"(全角)** \n\\- invalid expression: v-init=\"1234\"\n\ncustomDirective.vue\n\n```\n\n Vue.directive('init', {\n bind(el, bindings, vnode)\n {\n console.log(el.name, bindings.expression);\n // v-initに渡された値をタグのnameプロパティと同一の名前のv-modelに渡す\n vnode.context[el.name] = bindings.expression ? bindings.expression : '';\n }\n });\n \n```\n\nmain.js\n\n```\n\n var app = new Vue({\n el: '#main',\n data: {\n test: ''\n }\n });\n \n```\n\nhtml\n\n```\n\n <main id=\"main\">\n <form>\n <input type=\"text\" name=\"test\" v-init=\"あああ\" v-model=\"test\">\n <form>\n </main>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T05:14:03.510", "favorite_count": 0, "id": "37539", "last_activity_date": "2017-08-28T18:27:28.953", "last_edit_date": "2017-08-28T05:31:28.290", "last_editor_user_id": "16768", "owner_user_id": "16768", "post_type": "question", "score": 1, "tags": [ "javascript", "vue.js" ], "title": "vue.jsのcustomDirectiveで全角がbindできません", "view_count": 315 }
[ { "body": "サクッと試してみたところ、ダブルクォーテーションの中身が JavaScript\nの式として一度評価された後に、評価した式の何らかのメソッドを実行しようとするみたいで、式として成り立つものでなおかつ変数なら定義されているものを入れないとダメっぽいです。\n\nなので半角英数字で定義されていない変数名を入れてやると同じエラーを吐きます。\n\n↓のようにシングルクォーテーションで囲ってやるとかして、`bindings.value` を代入してやれば意図したとおりにいくと思います。\n\n### html\n\n```\n\n <input type=\"text\" name=\"test\" v-init=\"'あああ'\" v-model=\"test\">\n \n```\n\n### customDirective.vue\n\n```\n\n vnode.context[el.name] = bindings.value ? bindings.value : '';\n \n```", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T18:27:28.953", "id": "37549", "last_activity_date": "2017-08-28T18:27:28.953", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25074", "parent_id": "37539", "post_type": "answer", "score": 0 } ]
37539
37549
37549
{ "accepted_answer_id": null, "answer_count": 1, "body": "PythonからMeCabを弄ろうと環境を設定しているのですが、以下のコードの最終行のparse部分で \n_UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: invalid\ncontinuation byte_ \nというエラーが発生してしまいます。\n\n```\n\n import MeCab\n \n tagger = MeCab.Tagger('Owakati')\n tagger.parse('')\n \n text = '自然言語処理は楽しい'\n result = tagger.parse(text)\n \n```\n\n開発環境は、OS:Windows 7 32bit、Python 3.6.0(Anaconda3 4.3.1)、MeCab 0.996 \nmecab-python は\n[ここ](http://qiita.com/yukinoi/items/990b6933d9f21ba0fb43)を参照し、mecab-python-\nwindowsパッケージをpipでインストールしています。 \ntagger.parse('') はpythonのGCにひっかからないように必要との情報をもとに入れています。\n\nどなたか同様の事象の経験があり、解決された方などいらっしゃいますでしょうか。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T07:52:13.117", "favorite_count": 0, "id": "37543", "last_activity_date": "2017-08-29T05:39:09.097", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24303", "post_type": "question", "score": 0, "tags": [ "python3", "mecab" ], "title": "Python MeCab バインディング", "view_count": 490 }
[ { "body": "自己解決いたしました。お騒がせしてしまい申し訳ありません。\n\nMecab本体のインストール時の文字コード指定をUTF-8以外にしており、後からスタートメニューの「Recompile UTF-8\ndictionary」を実行しているのでUTF-8も動作すると考えていました。しかしながら、再インストールを行い、インストール時の文字コード指定をUTF-8にすることで挙動が変化し、正常に動作しました。どうやら、「Recompile\nxxxx dictionary」は有効ではないようです。\n\nkenji noguchi さんご回答ありがとうございました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T05:39:09.097", "id": "37559", "last_activity_date": "2017-08-29T05:39:09.097", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24303", "parent_id": "37543", "post_type": "answer", "score": 1 } ]
37543
null
37559
{ "accepted_answer_id": null, "answer_count": 0, "body": "Python\nIDLEでMatplotlibパッケージを使用したいのですが、Anacondaをインストールした後に、IDLEでMatplotlibをインポートしても以下のようなエラーが発生(numpyはインポート成功したのですが)してしまいます。ちなみにTerminalではきちんと機能します。\n\n```\n\n >>> import matplotlib.pyplot as plt\n Traceback (most recent call last):\n File \"<pyshell#2>\", line 1, in <module>\n import matplotlib.pyplot as plt\n File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/pyplot.py\", line 29, in <module>\n import matplotlib.colorbar\n File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/colorbar.py\", line 36, in <module>\n import matplotlib.contour as contour\n File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/contour.py\", line 23, in <module>\n import matplotlib.text as text\n File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/text.py\", line 33, in <module>\n from matplotlib.backend_bases import RendererBase\n File \"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backend_bases.py\", line 66, in <module>\n import matplotlib.backend_tools as tools\n File \"<frozen importlib._bootstrap>\", line 961, in _find_and_load\n File \"<frozen importlib._bootstrap>\", line 950, in _find_and_load_unlocked\n File \"<frozen importlib._bootstrap>\", line 655, in _load_unlocked\n File \"<frozen importlib._bootstrap_external>\", line 674, in exec_module\n File \"<frozen importlib._bootstrap_external>\", line 779, in get_code\n File \"<frozen importlib._bootstrap_external>\", line 487, in _compile_bytecode\n ValueError: bad marshal data (unknown type code)\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T08:58:44.497", "favorite_count": 0, "id": "37545", "last_activity_date": "2017-08-28T08:58:44.497", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24254", "post_type": "question", "score": 1, "tags": [ "python3", "anaconda", "matplotlib" ], "title": "AnacondaのパッケージMatplotlibをPython IDLEで使用したい。", "view_count": 629 }
[]
37545
null
null
{ "accepted_answer_id": null, "answer_count": 2, "body": "bootstrapを使ってサイトを作っているのですがposition:absoluteで配置した要素の隣にdiv要素を配置してブラウザ幅を縮小するとdiv要素の中身がabsolute指定した要素にめり込んでしまいます。ネットでみるとabsoluteした要素にfloatが使えないようなのですがどうにか使える方法をご存じの方はいないでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T12:14:41.547", "favorite_count": 0, "id": "37548", "last_activity_date": "2018-02-06T12:59:05.490", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20519", "post_type": "question", "score": -1, "tags": [ "css", "html5" ], "title": "absoluteでは回り込みができない?", "view_count": 782 }
[ { "body": "[`position:\nabsolute`](https://developer.mozilla.org/ja/docs/Web/CSS/position#Value) は\n\n> **absolute** \n> 要素のためのスペースが確保されません。\n\nとあるように、他の要素は当該要素が存在しなかったものとしてレイアウトが行われます。当然回り込むことはありません。\n\n記載されている質問文だけではどのようなレイアウトを検討されているか第三者にはわかりませんので、上記動作を念頭にスタイルを検討してください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-28T22:43:21.763", "id": "37551", "last_activity_date": "2017-08-28T22:43:21.763", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "37548", "post_type": "answer", "score": 1 }, { "body": "`absolute`した要素に`float`は使えません。隣のdiv要素に`absolute`、`float`、`margin`、`padding`等の設定で調整は可能かと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T03:27:45.007", "id": "37654", "last_activity_date": "2017-09-01T03:27:45.007", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25147", "parent_id": "37548", "post_type": "answer", "score": 0 } ]
37548
null
37551
{ "accepted_answer_id": "37565", "answer_count": 1, "body": "下記entriesテーブルにインデックスをどのように貼るのが良いのか困っております。\n\n### entriesテーブル\n\n```\n\n id # シーケンス、PK\n language # 言語, jaとかenとかはいる\n title # タイトル\n description # 説明文\n \n```\n\n### SQLのためのインプット\n\n * word = 検索言語1\n * language = ‘ja’\n\n### SQL\n\n```\n\n select * from entries\n where language = “ja”\n and (title like “%{word}%” or description like “%{word}%”)\n \n```\n\n### 困ってること\n\nインデックスをどう貼るのがよいか? \n下のように2つインデックスを貼っても、1SQLのこのテーブルに対しては1つしかインデックスが使われないので、おそらくindex1かindex2が使われることになるかと。 \nでも、titleにたいしても、descriptionにたいしてもインデックスを使われるようにしたいです。\n\n```\n\n index1 (language, title)\n index2 (language, description)\n \n```\n\n### 拡張\n\n * 今は検索単語1だけですが、検索単語を2つ入れた場合、 \n検索単語1と検索単語2でのAND検索になるようにしたいです。その場合にインデックスどうはるかもちょっといいアイデアがないです。\n\n * Railsで実装していて、kaminariというページング用のgemを使っています。できればこのgemを使ったページングを行いたいです。。ということはSQLは1個にする必要がありそう。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T04:51:47.310", "favorite_count": 0, "id": "37557", "last_activity_date": "2017-08-29T08:00:32.810", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25065", "post_type": "question", "score": 0, "tags": [ "ruby-on-rails", "mysql" ], "title": "OR検索が絡む時のMySQLでの複合インデックスのはりかた", "view_count": 646 }
[ { "body": "そもそもLIKEによる部分一致検索にはインデックスは使えません。(前方一致検索であればインデックスがつかえる可能性があります。)\n\nパフォーマンス上問題があるのであれば、全文検索エンジンの導入を検討してください。DBに寄って異なるので、「MySQL 全文検索」とか「PostgreSQL\n全文検索」とかで調べてみてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T08:00:32.810", "id": "37565", "last_activity_date": "2017-08-29T08:00:32.810", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "37557", "post_type": "answer", "score": 2 } ]
37557
37565
37565
{ "accepted_answer_id": "37563", "answer_count": 2, "body": "```\n\n <style>\r\n .show {\r\n display:none;\r\n }\r\n \r\n input:checked ~ .show {\r\n display:block;\r\n }\r\n </style>\r\n \r\n <input id=\"on-off\" type=\"checkbox\">\r\n <label for=\"on-off\">表示する</label>\r\n <p class=\"show\">表示される(通常時display:none)</p>\n```\n\nご回答頂けると幸いです。 \nこのように何かを表示を切り替える際にinput要素を使用することは、 \nマークアップ的には間違いなのでしょうか。\n\n最も適切な使用方法としてはformタグ内でデーター送信のために用いることだとは存じていますが、私は明らかな間違いではないと現時点では思っています。\n\ninput要素はformを構成する要素としてフォーム部品ともしばしば説明されていますが、 \nHTML Living StandardやMDNを見る限りではform内の使用に限定されている訳でもなく、 \ninputタグ単品での説明からはユーザーからの選択やコントロール、データを受ける要素という認識を受けました。\n\nこのようなマークアップに至った経緯を申しますと、この程度ならjavascriptで記述しなくてもいいのでは無いか?と思った次第です。script記述量は少しでも少ない方が読み込みの面でも良いと思いましたので...\n\n同じエンジニアの方と意見が割れたので質問させていただきました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T05:19:07.570", "favorite_count": 0, "id": "37558", "last_activity_date": "2017-08-29T07:31:42.793", "last_edit_date": "2017-08-29T07:31:42.793", "last_editor_user_id": "22718", "owner_user_id": "22718", "post_type": "question", "score": 1, "tags": [ "html5" ], "title": "input要素を使ったマークアップについて", "view_count": 145 }
[ { "body": "主観になってしまいますが。。。\n\n入力項目を条件によって表示・非常時切り替えるのも普通だと思います。良くあるインターフェイスだと思います。表示非表示の切り替えについても、CSSでやってもJavaScriptでやっても良いと思います。\n\n一番大事なのは、そのプロジェクト内で統一されているか?というトコです。 \nこの程度はCSS、この程度だからJavaScriptと判断するのって難しくないですか?ここで言われている`程度`も他者に分かるように伝えられますか?程度云々はそんなに大きな理由にならない気がします。 \n例えば、他の項目はJavaScriptで表示/非表示の制御が行われているのに、当該項目だけCSSでやるというのはナンセンスだと思いますね。\n\n読み込み速度を気にされていますが、そんな数文字の差でクリティカルな問題になるような環境なんでしょうか?今時のネットワークなら1000文字違っても体感はそんな気にならないと思いますが。。。 \n限られた環境でなければそこまで心配することも無い気がします。最終的にminifyするんだろうし。。。\n\n* * *\n\n意見の一致しない方が居られるとのことですが、その方に『なぜこの方法がダメなのか?』理由をきちんと聞いてみた方が良いんでないかなぁ~?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T07:20:03.153", "id": "37561", "last_activity_date": "2017-08-29T07:20:03.153", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2383", "parent_id": "37558", "post_type": "answer", "score": 0 }, { "body": "[HTML5 4.10 Froms 4.10.1\nIntroduction](https://www.w3.org/TR/html5/forms.html#introduction-1)には次の一文があります。\n\n> No client-side scripting is needed in many cases, though an API is available\n> so that scripts can augment the user experience or use forms for purposes\n> other than submitting data to a server.\n>\n> 参考訳:\n> 多くの場合、クライアントサイドスクリプトは必要ありませんが、APIが存在するため、スクリプトによってユーザーエクスペリエンスを向上させたり、データをサーバーに送信する以外の目的でフォームを使用できます。\n\nというわけで今回の`<input>`も正しい利用方法の一つだと思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T07:30:47.183", "id": "37563", "last_activity_date": "2017-08-29T07:30:47.183", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "37558", "post_type": "answer", "score": 1 } ]
37558
37563
37563
{ "accepted_answer_id": "37562", "answer_count": 1, "body": "現在、TERASOLUNA Server Framework for\nJava(Web版)チュートリアルについての実装や調査を行っているのですが、下記の当初はチュートリアルの内容の通り\n\n[2.2 チュートリアル学習環境の整備 \n](http://terasoluna.osdn.jp/tutorial/server-web/Document/WebTutorial_2.2.html)\n\n・Java SE 5.0 \n・Apache Tomcat 5.5 \n・H2 Database Engine 1.0 \n・Eclipse SDK 3.2.xx\n\nのツールで操作や実装を行えました。\n\n次はこのチュートリアルの操作を最新版でできないかという、試みをしているのですが \nterasoluna-spring-thin-blankをインポート\n\n画像のように \n?アイコンが乱立してサーバー起動しても404エラーが返ってくる状態になってしまっています。 \n[![terasoluna-spring-thin-\nblankプロジェクトをインポートした結果](https://i.stack.imgur.com/aYFa8.jpg)](https://i.stack.imgur.com/aYFa8.jpg)\n\n新しく設定してみた環境は、\n\n・Java SE 8.0 \n・Apache Tomcat 9.0.0 \n・H2 Database Engine 1.0 \n・Pleiades All in One 4.7.0.v20170628 \nEclipse 4.7 Oxygen 0\n\nのように変えています。\n\nあくまでチュートリアルのバージョン通りに行えば順調にいきますが、 \nツールを最新版に変えてカスタマイズした場合に、互換性の問題等があるのでしょうか?\n\n何か考えられる要因があれば、教えていただきたいのですがよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T06:45:29.753", "favorite_count": 0, "id": "37560", "last_activity_date": "2017-08-29T07:26:34.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25002", "post_type": "question", "score": 0, "tags": [ "java" ], "title": "TERASOLUNA Server Framework for Java(Web版)チュートリアル 最新版環境構築について", "view_count": 435 }
[ { "body": "Java SE 8.0は、それ以前のJava SEと互換性に問題があります。\n\n非互換性についての詳しい説明は、以下の記事を参照してください。 \n[JDK\n8の互換性ガイド](http://www.oracle.com/technetwork/jp/java/javase/overview/8-compatibility-\nguide-2156366-ja.html#A999097)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T07:26:34.150", "id": "37562", "last_activity_date": "2017-08-29T07:26:34.150", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "37560", "post_type": "answer", "score": 0 } ]
37560
37562
37562
{ "accepted_answer_id": null, "answer_count": 1, "body": "MongoDBにてレプリカセット構成で環境を構築しています。 \nDBサーバ、configサーバは正常に動作しているのですが、 \nmongosサーバへ接続ができません。 \n※mongosサーバはconfigサーバとは接続できています。\n\n```\n\n [root@mongos user]# mongo\n MongoDB shell version v3.4.7\n connecting to: mongodb://127.0.0.1:27017\n 2017-08-29T07:50:01.514+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused\n 2017-08-29T07:50:01.514+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :\n connect@src/mongo/shell/mongo.js:237:13\n @(connect):1:6\n exception: connect failed\n \n```\n\nmongosの設定ファイルは以下です。\n\n```\n\n # mongod.conf\n \n # for documentation of all options, see:\n # http://docs.mongodb.org/manual/reference/configuration-options/\n \n # where to write logging data.\n systemLog:\n destination: file\n logAppend: true\n path: /var/log/mongodb/mongos.log\n \n # Where and how to store data.\n #storage:\n # dbPath: /var/lib/mongos\n # journal:\n # enabled: true\n # engine:\n # mmapv1:\n # wiredTiger:\n \n # how the process runs\n processManagement:\n fork: true # fork and run in background\n pidFilePath: /var/run/mongodb/mongos.pid # location of pidfile\n \n # network interfaces\n net:\n port: 27017\n #bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.\n \n \n #security:\n \n #operationProfiling:\n \n #replication:\n \n sharding:\n configDB: rep/192.168.1.100:27019\n \n ## Enterprise-Only Options\n \n #auditLog:\n \n #snmp:\n \n```\n\n解決方法など、わかる方がいらっしゃれば幸いです。 \nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T08:08:33.467", "favorite_count": 0, "id": "37566", "last_activity_date": "2020-10-14T11:04:55.457", "last_edit_date": "2017-08-29T22:35:56.203", "last_editor_user_id": "19110", "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "mongodb" ], "title": "mongosに接続できない", "view_count": 1643 }
[ { "body": "レプリカセットだけであれば、mongosやconfigサーバは不要です。mongosやconfigサーバはシャードクラスタを使う場合に必要になるものです。\n\n<https://docs.mongodb.com/manual/core/sharded-cluster-config-servers/>\n\n> Config servers store the metadata for a sharded cluster.\n\n* * *\n\n接続の状態としては\n\n```\n\n Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused\n \n```\n\nということなので、\"mongo\"を打っているのと同じマシンの27017番ポートにつなぎに行こうとしているものの、繋がっていない状態です。\n\nmongoを打っているのと同じマシン上でmongosを起動されているでしょうか?", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T17:31:09.213", "id": "37579", "last_activity_date": "2017-08-29T17:31:09.213", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20119", "parent_id": "37566", "post_type": "answer", "score": 1 } ]
37566
null
37579
{ "accepted_answer_id": "37571", "answer_count": 1, "body": "下記のような[[ ]]はどういう意味でしょうか?\n\n```\n\n [[temp_pred]] = sess.run(prediction, feed_dict={x_data:t, y_target:y_data})\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T09:52:56.327", "favorite_count": 0, "id": "37568", "last_activity_date": "2017-08-29T10:20:25.597", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23690", "post_type": "question", "score": 4, "tags": [ "python" ], "title": "[[ ]]の意味について", "view_count": 149 }
[ { "body": "シーケンスの展開代入です。\n\n```\n\n >>> x, y = 1, 2\n >>> x\n 1\n >>> y\n 2\n >>> (x, y) = (1, 2)\n >>> x\n 1\n >>> y\n 2\n >>> [x, y] = (1, 2)\n >>> x\n 1\n >>> y\n 2\n >>> [x, y] = [1, 2]\n >>> x\n 1\n >>> y\n 2\n >>> [x, [y]] = [1, [2]]\n >>> x\n 1\n >>> y\n 2\n >>> [[y]] = [[2]]\n >>> y\n 2\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T10:20:25.597", "id": "37571", "last_activity_date": "2017-08-29T10:20:25.597", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "806", "parent_id": "37568", "post_type": "answer", "score": 8 } ]
37568
37571
37571
{ "accepted_answer_id": "37582", "answer_count": 1, "body": "Zip, io.BytesIO の意味や使い方はどういうものでしょうか? \nデータをWebからロードする方法について教えてくださればありがたいです。\n\n```\n\n zip_url = 'http://archive.ics.uci.edu/ml/machine-learning-databases/00228/smsspamcollection.zip'\n r = requests.get(zip_url)\n z = ZipFile(io.BytesIO(r.content))\n file = z.read('SMSSpamCollection')\n \n```\n\n参照:Tensorflow機械学習クックブック", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T11:33:59.347", "favorite_count": 0, "id": "37573", "last_activity_date": "2017-08-29T17:59:48.823", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23690", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "Zip, io.BytesIOの意味、使い方について", "view_count": 3147 }
[ { "body": "実行の流れは次の通りです。\n\n 1. HTTP GETをrequestsで実行\n 2. r.contentの結果をio.BytesIOでファイルストリームに変換\n 3. ZipFileにファイルストリームを引き渡してZipFileオブジェクトを作成\n 4. ZipFileオブジェクトからSMSSpamCollectionファイルを抽出\n\n`requests`はHTTPのGET/POSTなどの操作が簡単にできる便利なライブラリです。`get()`で取得したデータは`r.content`に\n**データ全体** が`bytes`バッファに格納されています。\n\n```\n\n >>> type(r.content)\n <class 'bytes'>\n \n```\n\nZipFileはzipfileモジュールで提供されるクラスで、ZIPで圧縮されたデータの操作が行えます。\n\n```\n\n >>> help(ZipFile)\n Help on class ZipFile in module zipfile:\n \n class ZipFile(builtins.object)\n | Class with methods to open, read, write, close, list zip files.\n |\n | z = ZipFile(file, mode=\"r\", compression=ZIP_STORED, allowZip64=True)\n |\n | file: Either the path to the file, or a file-like object.\n | If it is a path, the file will be opened and closed by ZipFile.\n | mode: The mode can be either read 'r', write 'w', exclusive create 'x',\n | or append 'a'.\n | compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),\n | ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).\n | allowZip64: if True ZipFile will create files with ZIP64 extensions when\n | needed, otherwise it will raise an exception when this would\n | be necessary.\n \n```\n\nZipFileクラスの引数は上のヘルプでわかるように、ファイルへのパスかファイルオブジェクトです。bytesをそのまま読み込むことはできないようです。そのためbytesをファイルオブジェクトとして扱うためにio.BytesIOを使います。\n\n```\n\n >>> help(io.BytesIO)\n Help on class BytesIO in module io:\n \n class BytesIO(_BufferedIOBase)\n | Buffered I/O implementation using an in-memory bytes buffer.\n \n```\n\nウェブからロードする方法はこのサンプルの通りで良いと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T17:54:42.963", "id": "37582", "last_activity_date": "2017-08-29T17:59:48.823", "last_edit_date": "2017-08-29T17:59:48.823", "last_editor_user_id": "7837", "owner_user_id": "7837", "parent_id": "37573", "post_type": "answer", "score": 2 } ]
37573
37582
37582
{ "accepted_answer_id": "37578", "answer_count": 2, "body": "`Xamarin Live Player`を使いたく Visual Studio Preview を Mac\nで使おうとしたのですが、Windows用のインストーラーしか見つかりませんでした。\n\n<https://www.visualstudio.com/vs/preview/>\n\nおそらくMacではPreview版が使えないということなのだと思うのですが、「できない。」と明示されている部分も見つからなかったのでインストールできる方法があるなら知りたく質問いたしました。\n\nよろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T12:15:05.813", "favorite_count": 0, "id": "37574", "last_activity_date": "2017-08-29T12:47:35.010", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "post_type": "question", "score": 0, "tags": [ "visual-studio", "xamarin", "macos" ], "title": "Visual Studio Preview を macOS にインストールする方法はありますか?", "view_count": 99 }
[ { "body": "PreviewはあくまでVisual Studio 2017のリリース形態ですので当然にWindowsしかサポートしていないと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T12:30:51.580", "id": "37576", "last_activity_date": "2017-08-29T12:30:51.580", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5750", "parent_id": "37574", "post_type": "answer", "score": 0 }, { "body": "[Xamarin Live Player Setup](https://developer.xamarin.com/guides/cross-\nplatform/live/install/?ide=xs#2._Get_the_Visual_Studio_for_Mac_Preview_or_for_Windows)によると\n\n> Xamarin Live Player requires: \n> \\- OS X 10.11, macOS 10.12, or greater \n> \\- Visual Studio for Mac ([Alpha channel\n> preview](https://developer.xamarin.com/recipes/cross-\n> platform/ide/change_updates_channel/#xamarinstudio)) \n> \\- A Mac and a device on the same WiFi network\n\nとのことですので、Visual Studio 2017 [15.4\nPreview](https://developer.xamarin.com/recipes/cross-\nplatform/ide/change_updates_channel/#visualstudio2017) or newerだけでなく、Visual\nStudio for Mac ([Alpha channel\npreview](https://developer.xamarin.com/recipes/cross-\nplatform/ide/change_updates_channel/#xamarinstudio))でも動作するようです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T12:47:35.010", "id": "37578", "last_activity_date": "2017-08-29T12:47:35.010", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "37574", "post_type": "answer", "score": 0 } ]
37574
37578
37576
{ "accepted_answer_id": "37586", "answer_count": 1, "body": "Raspberry Pi 3で「5 Enable Camera」の選択肢が表示されません。 \nPi3では「5 Enable Camera」の選択肢は無いのがデフォルトなのでしょうか。\n\n```\n\n sudo apt-get update\n sudo apt-get upgrade\n \n```\n\nでOSの更新をしたり、再起動したりしましたが、やはり表示されません。\n\n手元の画面では、「5 Interfacing Options」→「P1 Camera」から有効化の是否が選択できるようですが…。ここが「5 Enable\nCamera」とイコールと考えてよいのでしょうか。\n\n簡単なところと思いますが、調べてもわからずで詰まっております。 \nどなたか教えていただけますととても助かります。 \nよろしくお願いいたします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T12:18:41.830", "favorite_count": 0, "id": "37575", "last_activity_date": "2017-08-30T01:31:30.013", "last_edit_date": "2017-08-29T14:09:45.620", "last_editor_user_id": "5288", "owner_user_id": "25088", "post_type": "question", "score": 0, "tags": [ "raspberry-pi", "raspbian" ], "title": "Raspberry Pi 3で「5 Enable Camera」の選択肢が無い。", "view_count": 838 }
[ { "body": "> 2017/05現在、raspi-configでカメラを有効にする場合は下記のメニューを順番に選択します。 \n> 5 Interfacing Options - Configure connections to peripher \n> P1 Camera - Enable/Disable connection to the \n> Would you like the camera interface to be enabled? - \n> Would you like to reboot now? -\n\nとのことなので、そちらで良いようですよ。\n\n<http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_3_camera_setup/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T01:31:30.013", "id": "37586", "last_activity_date": "2017-08-30T01:31:30.013", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25099", "parent_id": "37575", "post_type": "answer", "score": 1 } ]
37575
37586
37586
{ "accepted_answer_id": "37585", "answer_count": 1, "body": "一般に提供されている任意のWebアプリケーションについて、こちらのクレデンシャル(パスワードなど)をデータベースに保存する際に暗号化しているかどうかを、開発者側からでは無くユーザー側から確認できる手段は存在しますか?", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-29T12:37:33.820", "favorite_count": 0, "id": "37577", "last_activity_date": "2017-08-30T01:31:10.350", "last_edit_date": "2017-08-30T00:19:13.540", "last_editor_user_id": "5793", "owner_user_id": "25090", "post_type": "question", "score": 0, "tags": [ "security" ], "title": "任意のWebアプリケーションに対するセキュリティ確認について", "view_count": 135 }
[ { "body": "ユーザといってもどういう立場なのかで違いますが\n\n悪意あるユーザー(クラッカー)として盗みやすいサイトを探している、のであればこの場でお手伝いしないほうが良さそうです。\n\n一般ユーザーとして「このサイトにパスワードを登録して漏れないかを心配している」のであれば \n一番簡単には「パスワードを忘れた」画面で、サイト側がどういう挙動を示すかで調査することができるでしょう。\n\n「現パスワードがメールで届く」サイトはパスワードを平文保存していると考えてよいです(非可逆変換していれば Web\nアプリケーション自体も元パスワードを知ることができないため)セキュリティ意識0なので近づかないほうが良さそうです。\n\n「新しいパスワードはこれです」をメールで送ってくるサイトは(パスワードをきっちり非可逆変換して保存しているにせよ)セキュリティ意識が薄いと考えてよいです。\n\n「このメールが届いてから*分以内に添付 URL にアクセスしたら新パスワードを設定できます」だったらそこそこ信頼してよいでしょう。当該 URL が\nhttps の場合に限ります。\n\nサイト側がどんな言語やデータベースで Web アプリを組んでいてどうこう、を調査する行為はそのままアタック行為ですから、試すなら相手の了解を取ってから。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T01:31:10.350", "id": "37585", "last_activity_date": "2017-08-30T01:31:10.350", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "8589", "parent_id": "37577", "post_type": "answer", "score": 0 } ]
37577
37585
37585
{ "accepted_answer_id": null, "answer_count": 2, "body": "数台程度の簡単なネットワーク構成図を書くのに便利なツールってありませんか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T00:50:54.793", "favorite_count": 0, "id": "37583", "last_activity_date": "2019-01-23T05:31:40.407", "last_edit_date": "2017-08-30T01:11:31.710", "last_editor_user_id": "76", "owner_user_id": "25097", "post_type": "question", "score": 2, "tags": [ "network" ], "title": "数台程度の簡単なネットワーク構成図を書くのに便利なツールってありませんか?", "view_count": 387 }
[ { "body": "アプリケーションであれば「[Dia](http://dia-\ninstaller.de/index.html.en)」というダイアグラム描画ツールで作成できます(Windows/Mac OS X/Linux)。\n\n**サンプル図** \n[![Network\nMap\\(Sample\\)](https://i.stack.imgur.com/JNbUb.png)](https://i.stack.imgur.com/JNbUb.png)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T01:38:21.997", "id": "37587", "last_activity_date": "2017-08-30T01:38:21.997", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "37583", "post_type": "answer", "score": 3 }, { "body": "ツールはいろいろあると思いますので実際に試すのが一番だと思いますが \n個人的には最近はCacooで書いてます。Visioほどじゃないけど、PowerPointよりはいろいろできて、操作が簡単。\n\nあと nwdiag はテキストで書かれたコードを図に変換するツールでこれもたまに使います。 \nいちいち線を引いたりするのが面倒に感じるクチなので、勝手に図を作ってくれるのが嬉しいです。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-01-23T05:31:40.407", "id": "52239", "last_activity_date": "2019-01-23T05:31:40.407", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "37583", "post_type": "answer", "score": 1 } ]
37583
null
37587
{ "accepted_answer_id": null, "answer_count": 1, "body": "maven central など nexus repository を利用することで、いろいろな jar\nファイルを依存関係として追加できます。ふと、ここでアップロードされている jar\nファイルが、対象のソースコードからビルドされているのかを確かめる方法があるのか、と疑問に思いました。というのも、ソースコードをビルドしてデプロイする間に、悪意の第三者が入りこんで、\njar の成果物を置き換えることが、できてしまうのではないか、と考えたからです。\n\n質問:\n\n * ビルドされたであろうソースコードがわかっている場合に、対象の jar ファイルが、確かにそのソースコードをビルドした結果得られるものであると検証することはできますか?", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T02:17:32.390", "favorite_count": 0, "id": "37589", "last_activity_date": "2017-08-30T03:10:12.787", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "754", "post_type": "question", "score": 1, "tags": [ "java", "security" ], "title": "jar ファイルが、確かに対象のソースからビルドされているかを確かめる方法はあるか", "view_count": 240 }
[ { "body": "[JD-\nGUI](http://jd.benow.ca/)などのデコンパイラを利用して、クラスファイルを一括で逆コンパイルして、ソースコードと比較するというのはどうでしょうか?もしくは逆にソースコードをコンパイルして比較するとか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T03:10:12.787", "id": "37594", "last_activity_date": "2017-08-30T03:10:12.787", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "21092", "parent_id": "37589", "post_type": "answer", "score": 1 } ]
37589
null
37594
{ "accepted_answer_id": "37597", "answer_count": 2, "body": "変数に値が入っていなければ値を代入し、入っていれば何もしない処理を、 \n現在は次のようにしています。\n\n```\n\n if not variable:\n variable = value\n \n```\n\nNoneの場合は:\n\n```\n\n if variable is None:\n variable = value\n \n```\n\n出来れば、辞書型の\"variable.setdefault(value)\"のように一行で書きたいと思っております。 \n関数を作ろうとも思ったのですが、\n\n```\n\n def setdefault(variable, value):\n if not variable:\n return value\n \n variable = setdefault(variable, value)\n \n```\n\nのようになり、変数名を引数として渡すのもスマートでは無いなと。。\n\n何か良い方法はないでしょうか。ご教授願います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T02:29:22.973", "favorite_count": 0, "id": "37591", "last_activity_date": "2017-08-30T03:22:57.610", "last_edit_date": "2017-08-30T02:58:19.613", "last_editor_user_id": "19110", "owner_user_id": "24908", "post_type": "question", "score": 3, "tags": [ "python" ], "title": "変数に値が入っていなければ値を代入し、入っていれば何もしない処理をスマートにできないでしょうか。", "view_count": 17647 }
[ { "body": "三項演算子風の`if`を使えば1行で書けます。\n\n```\n\n variable = value if variable is None else variable\n \n```\n\nもしくは`None`が偽と解釈されることと、ブール演算子が短絡評価されることを利用して`or`を使って書けますね。ただし、`0`や空文字列`\"\"`、空リスト`[]`も偽と解釈されてしまうので注意が必要です。\n\n```\n\n In [1]: None or 1\n Out[1]: 1\n \n In [2]: 0 or 1\n Out[2]: 1\n \n```\n\n偽として扱われる値については[こちら](https://docs.python.jp/3/library/stdtypes.html#truth-\nvalue-testing)に一覧があります。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T03:19:45.733", "id": "37596", "last_activity_date": "2017-08-30T03:19:45.733", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13199", "parent_id": "37591", "post_type": "answer", "score": 3 }, { "body": "一応、同じプログラムを三項演算子で書くと1行になります。\n\n```\n\n variable = value if variable is None else v\n \n```\n\n[\"PEP 505 -- None-aware operators\"](https://www.python.org/dev/peps/pep-0505/)\nの \"Existing Alternatives\" という節に他の方法も載っています。そこにも書いてあるように、[Request\nパッケージ](https://github.com/requests/requests/blob/14a555ac716866678bf17e43e23230d81a8149f5/requests/models.py#L212)では上の書き方が使われています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T03:22:57.610", "id": "37597", "last_activity_date": "2017-08-30T03:22:57.610", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "37591", "post_type": "answer", "score": 3 } ]
37591
37597
37596
{ "accepted_answer_id": null, "answer_count": 1, "body": "たびたび初歩的な質問で申し訳ありません。 \n下記質問では大変お世話になりました。 \n[R言語におけるデータフレームから欠損値を除去する方法、欠損値しかない列の除去(もしくは0への変換)](https://ja.stackoverflow.com/questions/36141/r%E8%A8%80%E8%AA%9E%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B%E3%83%87%E3%83%BC%E3%82%BF%E3%83%95%E3%83%AC%E3%83%BC%E3%83%A0%E3%81%8B%E3%82%89%E6%AC%A0%E6%90%8D%E5%80%A4%E3%82%92%E9%99%A4%E5%8E%BB%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95-%E6%AC%A0%E6%90%8D%E5%80%A4%E3%81%97%E3%81%8B%E3%81%AA%E3%81%84%E5%88%97%E3%81%AE%E9%99%A4%E5%8E%BB-%E3%82%82%E3%81%97%E3%81%8F%E3%81%AF0%E3%81%B8%E3%81%AE%E5%A4%89%E6%8F%9B)\n\n現在、csv作成→Rへ入力→Mann-whitney計算→csv出力を、様々なご指導を元に下記にように実行しています。\n\n```\n\n Data <- read.csv(\"sample.csv\", header=TRUE)\n Data_long <- gather(Data, key = fac, value = value, factor_key = TRUE)\n Data_long_rmNA <- drop_na(Data_long, value)\n temp <- with(Data_long_rmNA, pairwise.wilcox.test(value, fac, exact = FALSE, p.adjust.method = \"none\"))$p.value\n write.csv(temp, file = \"sample_result.csv\", quote = F)\n \n```\n\n現状、満足していますが、入力するcsvファイルがたくさんあるため、sampleのところにいちいち名前を入力するのが面倒なため、下記にようにしてみました。\n\n```\n\n i <- \"sample\"\n Data <- read.csv(sprintf(\"%s.csv\", i), header=TRUE)\n Data_long <- gather(Data, key = fac, value = value, factor_key = TRUE)\n Data_long_rmNA <- drop_na(Data_long, value)\n temp <- with(Data_long_rmNA, pairwise.wilcox.test(value, fac, exact = FALSE, p.adjust.method = \"none\"))$p.value\n write.csv(temp, file = sprintf(\"%s_result.csv\", i), quote = F)\n \n```\n\nところで、さらにこれを自動化することはできないでしょうか?For文で書けばできるのではと思っています。しかし、入力するcsvファイルの名前が規則性がないもので、困っています。たぶんファイル名が1,\n2, 3...とかならFor文でできそうなのですが。。。\n\n例えば、ファイル名が、A4fg, Brtg, Huji, CVYh...とあった場合に、\n\n```\n\n Data <- (A4fg, Brtg, Huji, CVYh...)\n \n```\n\nのようなコードを最初に入れて、これを順々に実行していく、というコードを書きたいと考えています。もちろん出力時はそのファイル名_result.csvとして出力できれば、助かります。\n\nご指導のほど、よろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T02:51:14.660", "favorite_count": 0, "id": "37592", "last_activity_date": "2022-06-17T06:06:15.563", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24217", "post_type": "question", "score": 0, "tags": [ "r" ], "title": "R言語におけるループでの複数のファイルの入力および処理", "view_count": 4999 }
[ { "body": "Hope this helps!(お役に立てれば!)\n\n```\n\n # setwd(\"<absolute path of directory having all csv files>\")\n setwd(\"<対象になる全てのCSVファイルが入ったディレクトリへの絶対パス>\")\n #上記のディレクトリ内の全てのCSVファイルを列挙\n #list all csv files in above directory\n files <- list.files(pattern = \"\\\\.csv$\")\n \n for (f in 1:length(files)){\n i <- gsub(\"(.*).csv\",\"\\\\1\",files[f])\n # <your code>\n <あなたのコード>\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2017-08-30T07:45:02.770", "id": "37607", "last_activity_date": "2018-11-19T12:33:39.420", "last_edit_date": "2018-11-19T12:33:39.420", "last_editor_user_id": "30827", "owner_user_id": null, "parent_id": "37592", "post_type": "answer", "score": 1 } ]
37592
null
37607
{ "accepted_answer_id": null, "answer_count": 2, "body": "Jetson TX2にQt5とQtcreatorをインストールしたいと思っています。\n\nJetsonにQtを入れている方がいたので下の記事を参考にしました。 \n<http://www.jetsonhacks.com/2017/01/31/install-qt-creator-nvidia-jetson-tx1/>\n\nここで最初の手順として、\n\n>\n```\n\n> sudo apt-get install qt5-default qtcreator -y\n> \n```\n\nとありますが、一覧にはない(※)と出てきます。\n\nコマンドを入力する直前に`sudo apt-get update`,`sudo apt-get\nupgrade`を行ったのですが、リポジトリが交信された結果qt5-defaultとqtcreatorが無くなったということでしょうか? \nもしそうならばリポジトリを戻したとかはできないでしょうか?\n\n(※)\n\n```\n\n Package qtcreator is not available, but is referred to by another package.\n This may mean that the package is missing, has been obsoleted, or\n is only available from another source\n However the following packages replace it:\n qtchooser\n \n E: Unable to locate package qt5-default\n E: Package 'qtcreator' has no installation candidate\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T02:56:13.890", "favorite_count": 0, "id": "37593", "last_activity_date": "2018-10-29T05:00:53.733", "last_edit_date": "2017-08-30T03:05:05.840", "last_editor_user_id": "21092", "owner_user_id": "21215", "post_type": "question", "score": 0, "tags": [ "linux", "ubuntu", "qt5" ], "title": "ubuntu16.04にQt5をインストールしたい", "view_count": 5049 }
[ { "body": "以下の記事が参考になるのではないでしょうか。(英語ですけど、nvidia.comのサイトなので信憑性の高い情報だと思われます) \n[QuickTime & Creator on\nTX2](https://devtalk.nvidia.com/default/topic/1003711/jetson-tx2/quicktime-\namp-creator-on-tx2/)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T01:09:43.417", "id": "37651", "last_activity_date": "2017-09-01T01:09:43.417", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "37593", "post_type": "answer", "score": 0 }, { "body": "Ubuntu のパッケージ検索すると qtcreator は **[universe]** と表示されているので、 \nuniverse のレポジトリを追加する必要があります。\n\nこのあたりが参考になるでしょうか? \n<https://askubuntu.com/questions/148638/how-do-i-enable-the-universe-\nrepository>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2018-09-21T08:38:16.883", "id": "48619", "last_activity_date": "2018-09-21T08:38:16.883", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "28622", "parent_id": "37593", "post_type": "answer", "score": 1 } ]
37593
null
48619
{ "accepted_answer_id": null, "answer_count": 1, "body": "私は **RaspberryPi3** を使い **Leapmotion** を制御しようを考えていたのですが、 **RaspberryPi3** に直接\n**Leamotion** をつなぐことはできないと学びました。PCに **Leapmotion** を接続し、 **WebServer** 上で\n**RaspberryPi3** がそのPCから **Leapmotion** のデータを取ってくるしか方法がないと最近知ったのですが、\n**JavaScript** で **WebServer** の立ち上げ方が調べても全く分かりません。簡単なところなのかもしれませんが教えてほしいです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T03:10:42.837", "favorite_count": 0, "id": "37595", "last_activity_date": "2020-03-19T07:02:10.420", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25101", "post_type": "question", "score": 0, "tags": [ "javascript", "raspberry-pi", "websocket", "leap-motion" ], "title": "websocketでウェブサーバーを構築したい。", "view_count": 247 }
[ { "body": "[ドキュメント](https://developer.leapmotion.com/documentation/javascript/devguide/Leap_Architecture.html)によれば、\n\n> The Leap Motion service runs a WebSocket server on the localhost domain at\n> port 6437.\n\nとの事ですので、質問者さんが作ろうとしているサーバーは SDK に含まれています。 \nつまり、自分で作る必要はありません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T11:59:49.377", "id": "37616", "last_activity_date": "2017-08-30T11:59:49.377", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "37595", "post_type": "answer", "score": 1 } ]
37595
null
37616
{ "accepted_answer_id": "37687", "answer_count": 1, "body": "お世話になっております。 \n以下のサイトを参考にサイトを作成しております。 \n<http://qiita.com/kaki_k/items/511611cadac1d0c69c54>\n\nDjangoのチェックボックスをmaterializecssの形に合わせて出力したいです。 \nデフォルトで出力するとlabelの中にinputが含まれていますが、labelとinputを分離するにはどのように修正すればよいでしょうか。\n\nmaterializecssのチェックボックスは以下 \n<http://materializecss.com/forms.html>\n\n# 現状ソースコード\n\n## [model.py]\n\n```\n\n from django.db import models\n \n class Actress(models.Model):\n ITEM = (\n (1, 'test1'),\n (2, 'test2'),\n (3, 'test3'),\n )\n item = models.IntegerField('アイテム', null=True, default=None, choices=ITEM)\n \n```\n\n## [forms.py]\n\n```\n\n from django import forms\n from cms.models import Actress\n \n class ActressForm(forms.ModelForm):\n \n class Meta:\n \n model = Actress\n fields = ('item')\n \n```\n\n## [html]\n\n```\n\n <form class=\"col s12\" action=\"{% url 'cms:actress_add' %}\" method=\"post\" role=\"form\">\n {% csrf_token %}\n <div class=\"row\">\n {% for value in form.item %}\n <p>\n <input type=\"checkbox\" id=\"{{ forloop.counter }}\" />\n <label for=\"{{ forloop.counter }}\">{{ value }}</label>\n </p>\n {% endfor %}\n </div>\n </form>\n \n```\n\n# 現状出力コード\n\n```\n\n <p>\n <input type=\"checkbox\" id=\"1\">\n <label for=\"1\">\n <label for=\"id_item_0\">\n <input type=\"checkbox\" name=\"item\" value=\"1\" id=\"id_item_0\">test1\n </label>\n </label>\n </p>\n \n```\n\n# 理想の出力コード\n\n```\n\n <p>\n <input type=\"checkbox\" id=\"1\">\n <label for=\"1\">test1</label>\n </p>\n \n```\n\nよろしくお願いいたします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T03:28:34.077", "favorite_count": 0, "id": "37598", "last_activity_date": "2017-09-03T03:02:16.843", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25102", "post_type": "question", "score": 0, "tags": [ "python", "django" ], "title": "Djangoのチェックボックスをmaterializecssの形に合わせて出力したい", "view_count": 521 }
[ { "body": "HTML側を以下のように書き換えて解決しました。\n\n{% csrf_token %} {% for key, value in form.item.field.choices %}\n\n{{ value }}\n\n{% endfor %}", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T03:02:16.843", "id": "37687", "last_activity_date": "2017-09-03T03:02:16.843", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25102", "parent_id": "37598", "post_type": "answer", "score": 0 } ]
37598
37687
37687
{ "accepted_answer_id": "37600", "answer_count": 1, "body": "はじめまして \n最近Pythonを触るようになったのですが、ドコモの雑談対話APIを使って動かして見たいプログラミングがPython2のものだったので3に変換しているのですが、どうしてもエラーが出てしまうので質問させていただきました。 \n<http://yu-write.blogspot.jp/2013/11/python-docomoapi.html> \nこちらのものをPython3で動かすために\n\n```\n\n #!/usr/bin/env python\n # -*- coding: utf-8 -*-\n \n #Docomoの雑談対話APIを使ってチャットできるスクリプト\n \n \n import sys\n import urllib.request\n import json\n import os\n \n \n APP_URL = 'https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue'\n \n \n class DocomoChat(object):\n #Docomoの雑談対話APIでチャット\n \n def __init__(self, api_key):\n api_key = os.environ.get('DOCOMO_DIALOGUE_API_KEY', api_key)\n super(DocomoChat, self).__init__()\n self.api_url = APP_URL + ('?APIKEY=%s'%api_key)\n self.context, self.mode = None, None\n \n def __send_message(self, input_message='', custom_dict=None):\n req_data = {'utt': input_message}\n if self.context:\n req_data['context'] = self.context\n if self.mode:\n req_data['mode'] = self.mode\n if custom_dict:\n req_data.update(custom_dict)\n request = urllib.request(self.api_url, json.dumps(req_data))\n request.add_header('Content-Type', 'application/json')\n try:\n response = urllib.urlopen(request)\n except Exception as e:\n print (e)\n sys.exit()\n return response\n \n def __process_response(self, response):\n resp_json = json.load(response)\n self.context = resp_json['context'].encode('utf-8')\n self.mode = resp_json['mode'].encode('utf-8')\n return resp_json['utt'].encode('utf-8')\n \n def send_and_get(self, input_message):\n response = self.__send_message(input_message)\n received_message = self.__process_response(response)\n return received_message\n \n \n def set_name(self, name, yomi):\n response = self.__send_message(custom_dict={'nickname': name, 'nickname_y': yomi})\n received_message = self.__process_response(response)\n return received_message\n \n \n def main():\n chat = DocomoChat('api_key')\n resp = chat.set_name('あなたのニックネーム', 'ニックネームのヨミガナ')\n print ('相手  : %s'% resp)\n message = ''\n while message != 'バイバイ':\n message = raw_input('あなた : ')\n resp = chat.send_and_get(message)\n print ('相手  : %s'%resp)\n \n if __name__ == \"__main__\":\n main()\n \n```\n\nこのように調べながら少しづつ変更していき、APIも.bash_profileに入れたものを使えるようにできないかと試しているのですが、現状では、\n\n```\n\n $ python talk.py\n Traceback (most recent call last):\n File \"talk.py\", line 71, in <module>\n main()\n File \"talk.py\", line 62, in main\n resp = chat.set_name('あなたのニックネーム', 'ニックネームのヨミガナ')\n File \"talk.py\", line 55, in set_name\n response = self.__send_message(custom_dict={'nickname': name, 'nickname_y': yomi})\n File \"talk.py\", line 33, in __send_message\n request = urllib.request(self.api_url, json.dumps(req_data))\n TypeError: 'module' object is not callable\n \n```\n\nこのようにTypeErrorがでてしまいます。 \nこのエラーについても調べて「モジュールの名前.対象のクラス」にしたら良いとは分かったのですが、どの部分に対してこの変更を行ったら良いのかもわからず行き詰ってしまいました。 \nまた、そもそもPython2で動かしたら良いのではとも思い行って見たのですが、動きはしたのですが文字化けしてしまいました。\n\n質問の書き方があっているかもわかりませんし、すごく初歩的なところを質問しているのかもしれませんがどうぞ宜しくお願いします。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T03:44:24.727", "favorite_count": 0, "id": "37599", "last_activity_date": "2017-08-30T04:14:26.640", "last_edit_date": "2017-08-30T04:00:34.363", "last_editor_user_id": "19110", "owner_user_id": "25104", "post_type": "question", "score": 3, "tags": [ "python", "python3" ], "title": "ドコモの雑談対話APIのPython2プログラミングのPython3化", "view_count": 302 }
[ { "body": "この行\n\n```\n\n request = urllib.request(self.api_url, json.dumps(req_data))\n \n```\n\nは元々の [YuraYura](https://www.blogger.com/profile/15070671187447610013)\nさんによる[プログラム](http://yu-write.blogspot.jp/2013/11/python-\ndocomoapi.html)では下のようになっていました。\n\n```\n\n request = urllib2.Request(self.api_url, json.dumps(req_data))\n \n```\n\nここの書き換えが間違っています。[`urllib.request`](https://docs.python.jp/3/library/urllib.request.html)\nまでで1つのモジュール名です。このモジュールの `Request` メソッドを呼び出したいので、`urllib.request.Request`\nと書いてください。\n\n* * *\n\n参考: `urllib2`\nパッケージの[ドキュメント](https://docs.python.org/2/library/urllib2.html)には以下のように書かれています。\n\n> The [`urllib2`](https://docs.python.org/2/library/urllib2.html#module-\n> urllib2) module has been split across several modules in Python 3 named\n> `urllib.request` and `urllib.error`. The\n> [2to3](https://docs.python.org/2/glossary.html#term-2to3) tool will\n> automatically adapt imports when converting your sources to Python 3.", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T04:14:26.640", "id": "37600", "last_activity_date": "2017-08-30T04:14:26.640", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "37599", "post_type": "answer", "score": 2 } ]
37599
37600
37600
{ "accepted_answer_id": "37604", "answer_count": 1, "body": "Eclipseでmavenプロジェクトを更新時、「Maven構成更新中のエラー\n次のプロジェクトのmaven構成を更新できません:ネストできません。ネストを可能にするにはsrcから除外してください。」と表示されます。\n\n対処法として下記3点を実施しました。 \n1.\"<http://qiita.com/makito/items/6ee52ba9796a8b3498c8>\"の情報を参考に対応。 \n2.srcフォルダにはサブフォルダがいくつかあり、pom.xml上の\"uild-helper-maven-plugin\"にてサブフォルダ設定済。 \n3.Javaのビルドパスにサブフォルダの追加設定。\n\n上記対応してもエラーは解消できません。 \n何か他の対処方法があれば、ご教授頂けますでしょうか?\n\n以上、よろしくお願いいたします。\n\n【補足情報】 \nフォルダ構造とpom.xmlについて補足しました。 \n■フォルダ構造について \nmavenプロジェクト\"eformadm\"内のソースフォルダ\"src\"内に下記サブフォルダが複数存在します。\n\n```\n\n \\\\eformadm\\src\\cycommon\n \\\\eformadm\\src\\core\n \\\\eformadm\\src\\web\n \n```\n\n■pom.xmlについて\n\n```\n\n <project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n <modelVersion>4.0.0</modelVersion>\n <groupId>eformadm</groupId>\n <artifactId>eformadm</artifactId>\n <version>0.0.1-SNAPSHOT</version>\n <packaging>war</packaging>\n <properties>\n <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n </properties>\n <build>\n <finalName>eformadm</finalName>\n <sourceDirectory>src</sourceDirectory>\n <resources>\n <resource>\n <directory>res/conf</directory>\n <excludes>\n <exclude>**/*.java</exclude>\n </excludes>\n </resource>\n <resource>\n <directory>res/sql</directory>\n <excludes>\n <exclude>**/*.java</exclude>\n </excludes>\n </resource>\n </resources>\n <plugins>\n <plugin>\n <artifactId>maven-compiler-plugin</artifactId>\n <version>3.5.1</version>\n <configuration>\n <source>1.8</source>\n <target>1.8</target>\n </configuration>\n </plugin>\n <plugin>\n <artifactId>maven-war-plugin</artifactId>\n <version>3.0.0</version>\n <configuration>\n <warSourceDirectory>WebContent</warSourceDirectory>\n <webXml>WebContent/WEB-INF/web.xml</webXml>\n </configuration>\n </plugin>\n <plugin>\n <groupId>org.codehaus.mojo</groupId>\n <artifactId>build-helper-maven-plugin</artifactId>\n <version>3.0.0</version>\n <executions>\n <execution>\n <id>add-source</id>\n <phase>generate-sources</phase>\n <goals>\n <goal>add-source</goal>\n </goals>\n <configuration>\n <sources>\n <source>src/cycommon</source>\n <source>src/core</source>\n <source>src/web</source>\n </sources>\n </configuration>\n </execution>\n </executions>\n </plugin>\n </plugins>\n </build>\n <dependencies>\n <dependency>\n <groupId>asm</groupId>\n <artifactId>asm</artifactId>\n <version>3.3.1</version>\n </dependency>\n <dependency>\n <groupId>commons-collections</groupId>\n <artifactId>commons-collections</artifactId>\n <version>3.2.1</version>\n </dependency>\n <dependency>\n <groupId>org.apache.commons</groupId>\n <artifactId>commons-compress</artifactId>\n <version>1.13</version>\n </dependency>\n <dependency>\n <groupId>commons-fileupload</groupId>\n <artifactId>commons-fileupload</artifactId>\n <version>1.3.2</version>\n </dependency>\n <dependency>\n <groupId>commons-io</groupId>\n <artifactId>commons-io</artifactId>\n <version>2.4</version>\n </dependency>\n <dependency>\n <groupId>org.apache.commons</groupId>\n <artifactId>commons-lang3</artifactId>\n <version>3.4</version>\n </dependency>\n <dependency>\n <groupId>commons-logging</groupId>\n <artifactId>commons-logging</artifactId>\n <version>1.1.3</version>\n </dependency>\n <dependency>\n <groupId>org.freemarker</groupId>\n <artifactId>freemarker</artifactId>\n <version>2.3.23</version>\n </dependency>\n <dependency>\n <groupId>org.javassist</groupId>\n <artifactId>javassist</artifactId>\n <version>3.20.0-GA</version>\n </dependency>\n <dependency>\n <groupId>log4j</groupId>\n <artifactId>log4j</artifactId>\n <version>1.2.17</version>\n </dependency>\n <dependency>\n <groupId>org.mybatis</groupId>\n <artifactId>mybatis</artifactId>\n <version>3.3.0</version>\n </dependency>\n <dependency>\n <groupId>org.mybatis</groupId>\n <artifactId>mybatis-spring</artifactId>\n <version>1.2.3</version>\n </dependency>\n <dependency>\n <groupId>ognl</groupId>\n <artifactId>ognl</artifactId>\n <version>3.1.12</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-aop</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-beans</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-context</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-context-support</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-core</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-expression</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-jdbc</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-tx</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.springframework</groupId>\n <artifactId>spring-web</artifactId>\n <version>4.1.6.RELEASE</version>\n </dependency>\n <dependency>\n <groupId>org.postgresql</groupId>\n <artifactId>postgresql</artifactId>\n <version>42.1.1</version>\n </dependency>\n <dependency>\n <groupId>org.apache.struts</groupId>\n <artifactId>struts2-core</artifactId>\n <version>2.5.10.1</version>\n </dependency>\n <dependency>\n <groupId>javax.servlet</groupId>\n <artifactId>javax.servlet-api</artifactId>\n <version>3.1.0</version>\n </dependency>\n <dependency>\n <groupId>org.apache.tomcat</groupId>\n <artifactId>tomcat-dbcp</artifactId>\n <version>7.0.78</version>\n </dependency>\n <dependency>\n <groupId>org.apache.struts</groupId>\n <artifactId>struts2-spring-plugin</artifactId>\n <version>2.5.10.1</version>\n </dependency>\n <dependency>\n <groupId>org.apache.struts</groupId>\n <artifactId>struts2-json-plugin</artifactId>\n <version>2.5.10.1</version>\n </dependency>\n </dependencies>\n </project>\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T05:11:13.620", "favorite_count": 0, "id": "37602", "last_activity_date": "2017-08-30T06:32:36.090", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25105", "post_type": "question", "score": 0, "tags": [ "eclipse", "spring", "maven", "struts" ], "title": "Eclipseでmavenプロジェクトを更新時にエラーが表示される", "view_count": 16227 }
[ { "body": "質問文中に載せられている`pom.xml`では、`<sourceDirectory>src</sourceDirectory>`\nで`src`ディレクトリをソースディレクトリと指定し、また、`build-helper-maven-plugin`設定によって`src`以下の\n`src/cycommon`などもまたソースディレクトリとして指定するようになってしまっています。 \nこれがネストエラーと言われてしまう原因です。\n\n実際には`src`はソースディレクトリとして指定しなくて良いはずなので、\n\n 1. `pom.xml`のソースディレクトリ設定を修正(`src`ソースディレクトリ指定をやめる)し、\n 2. その設定をEclipseに反映する\n\nことでエラーは消えると思われます。 \n(実際には、2番だけ行えばEclipse上のエラーはなくなるでしょう。ただし、大元の`pom.xml`を直しておかないと、再インポートした際などに再現しかねません。)\n\n* * *\n\n`pom.xml`修正方法としては、私としては次のものが妥当であると考えます。\n\n * `src\\cycommon`, `src\\core`, `src\\web`のうちひとつを(`src`指定を削除し、代わりに)`<sourceDirectory>`で設定する。残りの2つを従来どおり`build-helper-maven-plugin`で設定する。\n\n別案としては、次の修正方法があるでしょう(末尾に記載した参考リンク先に書かれている方法)。\n\n * 単に`<sourceDirectory>src</sourceDirectory>` 行を `pom.xml`から削除する。削除することでデフォルトソースディレクトリ`src/main/java`が使用されるようになり、ネスト状態ではなくなる。また実際には`src/main/java`は存在しないので副作用は発生しない(意図しないものが追加でコンパイルされるようなことにはならない)。\n\n* * *\n\nEclipse設定の修正については、プロジェクトプロパティの「Javaビルドパス」設定から`eformadm/src`を削除すればよいです。\n\nあるいは一旦Eclipse設定を削除してしまって再度Eclipseに取り込んでも良いです(ただしEclipseプロジェクトに対し何か追加設定している場合、その設定は消えることに注意)。\n\n* * *\n\n参考:\n\n * [java - Eclipse Build Path Nesting Errors - Stack Overflow](https://stackoverflow.com/questions/10838109/eclipse-build-path-nesting-errors)\n * [eclipse - Maven suddenly wants src/ instead of src/main/java - Stack Overflow](https://stackoverflow.com/questions/34015536/maven-suddenly-wants-src-instead-of-src-main-java)", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T06:32:36.090", "id": "37604", "last_activity_date": "2017-08-30T06:32:36.090", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2808", "parent_id": "37602", "post_type": "answer", "score": 0 } ]
37602
37604
37604
{ "accepted_answer_id": "38010", "answer_count": 1, "body": "下記のコード **os.chdir(os.path.dirname(os.path.realpath(__file__)))というところで\nNameError: name '__file__' is not defined** というエラーが出ます \nどうすれば良いでしょうか?\n\n```\n\n import tensorflow as tf\n import matplotlib.pyplot as plt\n import numpy as np\n import random\n import os\n import string\n import requests\n import collections\n import io\n import gzip\n import tarfile\n import urllib.request\n from nltk.corpus import stopwords\n from tensorflow.python.framework import ops\n ops.reset_default_graph()\n \n os.chdir(os.path.dirname(os.path.realpath(__file__)))\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T08:16:06.047", "favorite_count": 0, "id": "37608", "last_activity_date": "2017-09-18T06:07:45.617", "last_edit_date": "2017-08-30T09:32:35.300", "last_editor_user_id": "23690", "owner_user_id": "23690", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "os.chdir(os.path.dirname(os.path.realpath(__file__)))でエラーが出ます", "view_count": 1398 }
[ { "body": "__file__はmoduleとして呼ぶか、scriptとして実行したときじゃないと定義されません。 \nなので、notebook上で__file__は使えません。 \n[同じような質問](https://stackoverflow.com/questions/39125532/file-does-not-exisit-\nin-jupyter-notebook)があったので転載しておきます。 \n__file__等が定義されているかは、print(globals())してみるとわかります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-18T06:07:45.617", "id": "38010", "last_activity_date": "2017-09-18T06:07:45.617", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25449", "parent_id": "37608", "post_type": "answer", "score": 5 } ]
37608
38010
38010
{ "accepted_answer_id": null, "answer_count": 1, "body": "swift3で作成しています。\n\nUITabBarControllerを利用して画面の切り替えを行っているのですが \nFirstViewControllerとSecondtViewControllerとあります。 \nFirstViewControllerの画面がアクティブの時、SecondtViewControllerのタブをクリックすれば \nSecondtViewControllerに切り替わるのですが、 \nFirstViewControllerの画面がアクティブの時、FirstViewControllerのタブをクリックした場合、メッセージを出したい(printでのconsoleに表示でも可)のですが \nどうしたらよいのでしょうか?\n\n解決しました", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T08:36:13.460", "favorite_count": 0, "id": "37609", "last_activity_date": "2023-03-27T08:05:05.740", "last_edit_date": "2017-09-04T02:33:35.087", "last_editor_user_id": "9987", "owner_user_id": "9987", "post_type": "question", "score": 0, "tags": [ "swift3", "uitabbarcontroller" ], "title": "UITabBarControllerを利用したてアクティブなタブが再度タップされたとき", "view_count": 684 }
[ { "body": "`UITabBarController`のサブクラスを作成し、`didSelectViewController`というデリゲートメソッドを実装すると選択されたViewControllerが取得できます。\n\n[こちらのサイト](http://hidef.jp/post-725/)が参考になるかと思います。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T09:02:11.973", "id": "37610", "last_activity_date": "2017-08-30T09:02:11.973", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10958", "parent_id": "37609", "post_type": "answer", "score": 0 } ]
37609
null
37610
{ "accepted_answer_id": null, "answer_count": 1, "body": "現在,変換したい名前(文字列)のリストと,その名前と1対1対応している対応表があります. \n具体的には,リストは\n\n> [1] \n> \"あ\" \"か\" \"さ\" \"た\" \"な\" \"は\" \n> [2] \n> \"ま\" \"や\" \"ら\" \"わ\" \"い\" \"き\"\n\nのような感じで,対応表は\n\n> ひらがな 漢字 \n> あ 亜 \n> い 医 \n> う 鵜 \n> え 絵 \n> お 御 \n> か 科 …\n\nのようになっています. \nここから,この対応表を用いて,リストにある名前を変換したいです. \nつまり,例で言うと\n\n> [1] \n> \"亜\" \"科\" \"差\" \"多\" \"名\" ”歯\" \n> [2] \n> \"間\" \"矢\" \"等\" \"和\" \"医\" \"気\"\n\nのようにリストの内容を対応表に従って一括で変換する事を目標としています. \nstringrパッケージなどを試してみたのですが上手くいかず… \nstringrで上手くいくならその方法を,もしstringr以外にふさわしいパッケージがあったらそれを使った方法をお願いしたいと思います. \nよろしくお願いします.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T09:21:56.360", "favorite_count": 0, "id": "37612", "last_activity_date": "2019-09-30T09:01:40.510", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23335", "post_type": "question", "score": 0, "tags": [ "r" ], "title": "R言語で,対応表に従ってリストの内容を変更したい", "view_count": 1763 }
[ { "body": "以下は `match()` \\+ `lapply()` で処理する方法です。なお、変換表にない組み合わせの場合は `NA` になります。\n\n```\n\n trans <- data.frame(\n hiragana = c(\"あ\", \"い\", \"う\", \"え\", \"お\", \"か\", \"さ\", \"た\", \"な\", \"は\",\n \"ま\", \"や\", \"ら\", \"わ\", \"い\", \"き\"),\n kanji = c(\"亜\", \"医\", \"鵜\", \"絵\", \"御\", \"科\", \"差\", \"多\", \"名\", \"歯\",\n \"間\", \"矢\", \"等\", \"和\", \"医\", \"気\")\n )\n \n src <- list(\n c(\"あ\", \"か\", \"さ\", \"た\", \"な\", \"は\"),\n c(\"ま\", \"や\", \"ら\", \"わ\", \"い\", \"き\")\n )\n \n lapply(src, function(x) {\n as.vector(trans$kanji[match(x, trans$hiragana)])\n })\n \n =>\n \n [[1]]\n [1] \"亜\" \"科\" \"差\" \"多\" \"名\" \"歯\"\n \n [[2]]\n [1] \"間\" \"矢\" \"等\" \"和\" \"医\" \"気\"\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T12:25:40.230", "id": "37617", "last_activity_date": "2017-08-30T12:25:40.230", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "37612", "post_type": "answer", "score": 1 } ]
37612
null
37617
{ "accepted_answer_id": null, "answer_count": 1, "body": "iOS11ではFaceBook、twitterにログインする機能がなくなり、SLComposeViewControllerを使ったシェア機能が実装できなくなりました。SLComposeViewControllerをつかわないFaceBook、Twitterでのシェアの方法を教えてくださると助かります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T10:46:11.797", "favorite_count": 0, "id": "37614", "last_activity_date": "2017-08-31T02:54:07.973", "last_edit_date": "2017-08-30T11:48:33.060", "last_editor_user_id": "5519", "owner_user_id": "25112", "post_type": "question", "score": 3, "tags": [ "swift", "ios", "swift3" ], "title": "iOS11においてのシェア機能の実装", "view_count": 2934 }
[ { "body": "まず、\n\n> SLComposeViewControllerを使ったシェア機能が実装できなくなりました。\n\nというのはあまり正確ではありません。 \nTwitterやFacebookの公式アプリがインストールされている場合は、iOS\n11でもSLComposeViewControllerを使った投稿ができるようです。\n\n(※ ただし、iOS 11 beta 8\nの時点では、Twitterに投稿しようとすると「Twitterアカウントがありません」というアラートが表示される問題があります。Twitterアプリ上でログインしていればアラートがでても投稿はできます)\n\n公式アプリがインストールされていない場合の投稿については以下の様な選択肢があります\n\n 1. TwitterやFacebookの公式SDKを利用する(フル機能の投稿画面が使いたいなら) \n * Twitter公式による移行ガイド: [Migrating from iOS Social Framework](https://dev.twitter.com/twitterkit/ios/migrate-social-framework)\n * FacebookSDK: [iOS用Facebook SDKスタートガイド](https://developers.facebook.com/docs/ios/getting-started?locale=ja_JP)\n 2. Webの投稿画面をSafariやSFSafariViewControllerなどで開く (画像などが不要でテキストのみでOKなら) \n * Twitter: <https://twitter.com/intent/tweet?text=>... \n * Facebook: [https://www.facebook.com/dialog/share?app_id=...&href=](https://www.facebook.com/dialog/share?app_id=...&href=)...\n 3. 公式アプリをインストールしていない場合は、アプリのインストールを促す \n * アプリのインストール有無は `\"twitter://\"` や `\"fb://\"` を UIApplication のcanOpenURLでチェックすることで判断できます。\n 4. 公式アプリをインストールしていないユーザーは少数とみなして切り捨てる、または共有機能をUIActivityViewControllerのみにする\n\n1と2の方式はどちらも[Facebook 開発者向けページ](https://developers.facebook.com/)\nでアプリの登録が必要が必要になります。\n\nどうぞ、ご参考に。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T02:47:27.283", "id": "37631", "last_activity_date": "2017-08-31T02:54:07.973", "last_edit_date": "2017-08-31T02:54:07.973", "last_editor_user_id": "23829", "owner_user_id": "23829", "parent_id": "37614", "post_type": "answer", "score": 7 } ]
37614
null
37631
{ "accepted_answer_id": null, "answer_count": 0, "body": "pyaudioでリアルタイムでマイク入力を読み込み,pyqt5上でウィンドウを作ってそこに何秒か毎にlibrosa.display.specshow()でスペクトログラムを表示・保存したいと考えています. \nそこでpyqt5のウィンドウ上でlibrosa.display.specshow()を出すにはどうすればよいでしょうか. \nscipyでスペクトログラムを表示させることは(多分)できました.\n\n```\n\n import sys\n import numpy as np\n import pyaudio\n from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas\n from matplotlib.figure import Figure\n import librosa\n import librosa.display\n from scipy import signal\n \n from PyQt5.QtCore import (QLineF, QPointF, QRectF, Qt, QTimer)\n from PyQt5.QtGui import (QBrush, QColor, QPainter)\n from PyQt5.QtWidgets import (QApplication, QGraphicsView, QGraphicsScene, QGraphicsItem,\n QGridLayout, QVBoxLayout, QHBoxLayout, QSizePolicy,\n QLabel, QLineEdit, QPushButton)\n \n \n class MainWindow(FigureCanvas):\n def __init__(self, parent=None, width=4, height=3, dpi=200):\n # マイクインプット設定\n self.FORMAT = pyaudio.paFloat32\n self.CHANNELS = 1 # モノラル\n self.RATE = 44100 # サンプリング周波数\n self.CHUNK = 1024 # 1度に読み取る音声のデータ幅\n self.UPDATE_SECOND = 100 # 更新時間[ms]\n \n self.audio = pyaudio.PyAudio()\n self.stream = self.audio.open(format=self.FORMAT,\n channels=self.CHANNELS,\n rate=self.RATE,\n input=True,\n output=False,\n frames_per_buffer=self.CHUNK)\n \n fig = Figure(figsize=(width, height), dpi=dpi)\n self.axes = fig.add_subplot(111)\n self.axes.hold(False)\n super(MainWindow, self).__init__(fig)\n self.setParent(parent)\n \n FigureCanvas.setSizePolicy(self,\n QSizePolicy.Expanding,\n QSizePolicy.Expanding)\n FigureCanvas.updateGeometry(self)\n \n # アップデート時間設定\n timer = QTimer(self)\n timer.timeout.connect(self.update_figure)\n timer.start(self.UPDATE_SECOND)\n \n def update_figure(self):\n # マイク入力読み込み\n data = self.audioinput()\n \n # fft_data = librosa.stft(data)\n # librosa.display.specshow(librosa.logamplitude(np.abs(fft_data) ** 2, ref_power=np.max), y_axis='log',\n # x_axis='time')\n \n # scipyで無理やり\n f, t, Sxx = signal.spectrogram(data, fs=self.RATE, nperseg=512)\n self.axes.pcolormesh(t, f, Sxx, vmax=1e-9, cmap='jet')\n \n self.draw()\n \n def audioinput(self):\n ret = self.stream.read(self.CHUNK)\n ret = np.fromstring(ret, np.float32)\n \n return ret\n \n \n if __name__ == '__main__':\n app = QApplication(sys.argv)\n mainWindow = MainWindow()\n mainWindow.show()\n sys.exit(app.exec_())\n \n```\n\n<http://takeshid.hatenadiary.jp/entry/2015/11/27/045123> \n<http://d.hatena.ne.jp/mFumi/20141112/1415806010> \nこちらのサイトのプログラムでpyaudioでリアルタイムでマイク入力の読み込みや,pyqt5上でのmatplotlibの連携をすることができました. \nlibrosa.displayだと単体で表示できてしまうため,埋め込むことは難しいのでしょうか", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T12:46:45.557", "favorite_count": 0, "id": "37618", "last_activity_date": "2017-08-30T12:46:45.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25110", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "pyqt上でlibrosaのスペクトログラムを表示・保存したい", "view_count": 944 }
[]
37618
null
null
{ "accepted_answer_id": "37622", "answer_count": 3, "body": "現在、「独習C++」という書籍を使用しC++を独学で勉強しています。この書籍の中でメモリの動的確保の節の例題プログラム中で、不明点があり質問させて頂きました。以下に例題プログラムを記します。\n\n```\n\n #include \"stdafx.h\"\n #include \"iostream\"\n \n using namespace std;\n \n int main()\n {\n int *p;\n \n p = new int[5]; //5つの整数用のメモリを割り当てる\n \n //割り当ての成功を確認\n if (!p) {\n cout << \"メモリの割り当てエラー\" << endl;\n return 1;\n }\n \n int i;\n \n for (i = 0; i < 5; i++) {\n p[i] = i;           //※1\n }\n \n for (i = 0; i < 5; i++) {\n cout << \"整数型p[\" << i << \"]は:\";\n cout << p[i] << endl;         //※2\n }\n \n delete[] p; //メモリの解放\n \n return 0;\n }\n \n```\n\nプログラム中の※1,※2で、それぞれ動的に確保したint型ポインタに値の格納と値の表示が行われています。ここで、私が疑問に思っているのはなぜ間接参照演算子*を使用せずにポインタ変数に値を代入できているのか?p[i]はアドレスを格納する変数なのではないか?ということです。私が思うに、※1の部分は\n\n```\n\n *(p + i) = i;\n \n```\n\n※2の部分は\n\n```\n\n cout << *(p + i) << endl;\n \n```\n\nと書くべきなのではないかと思います。 \nしかし、実際に両方の構文を試してみると、どちらの書き方でもプログラムは正常に動作しました。何故ポインタ変数に直接的に値を格納するような書き方(p[i] =\ni;)ができるのか。これをどのように解釈すればよいか悩んでいます。初歩的な質問ですが、ご回答いただければ幸いです。 \nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T14:08:05.400", "favorite_count": 0, "id": "37620", "last_activity_date": "2017-08-30T16:02:37.453", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25114", "post_type": "question", "score": 2, "tags": [ "c++", "ポインタ" ], "title": "C++でのポインタから値へのアクセス方法についての質問です。", "view_count": 544 }
[ { "body": "> 6.5.2.1 Array subscripting \n> ... \n> 2 A postfix expression followed by an expression in square brackets [] is a\n> subscripted \n> designation of an element of an array object. The definition of the\n> subscript operator [] \n> is that E1[E2] is identical to (*((E1)+(E2))). Because of the conversion\n> rules that \n> apply to the binary + operator, if E1 is an array object (equivalently, a\n> pointer to the \n> initial element of an array object) and E2 is an integer, E1[E2] designates\n> the E2-th \n> element of E1 (counting from zero).\n\n`p[i]`は`*(p + i)`のシンタックスシュガーで、まったく同じ意味になります。`i[p]`と書いても同じ意味になります。\n\n```\n\n #include <stdio.h>\n \n int main(void) {\n int a[3] = { 10, 20, 30 };\n printf(\"a[0] = %d\\n\", a[0]);\n printf(\"a[1] = %d\\n\", 1[a]);\n printf(\"a[2] = %d\\n\", *(2 + a));\n return 0;\n }\n \n```\n\nつまり、上記のコードを実行すると次のような出力になります。\n\n```\n\n a[0] = 10\n a[1] = 20\n a[2] = 30\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T14:37:06.997", "id": "37622", "last_activity_date": "2017-08-30T14:37:06.997", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5519", "parent_id": "37620", "post_type": "answer", "score": 2 }, { "body": "実は`*(p + i)`は、`p[i]`と全く同じ意味なのです。例えば、`*(p + 1)`を`*(1 +\np)`と書けるように、`p[1]`も`1[p]`と書けます (あくまで文法的な話で、現実的には、このように書くメリットはないと思いますが)。\n\nでは、配列はどうなのかというと、例えば\n\n```\n\n int a[10];\n a[1] = 10; // (1)\n \n```\n\n(1)のところで使われている`a`は、配列の先頭の要素のアドレス、つまり`int`のデータを指すアドレスを返すことになっています。一方、ポインタの場合は\n\n```\n\n int *p = new int[10];\n *(p + 1) = 10; // (2)\n \n```\n\n`p`は`int`のポインタですので、当然`int`を指すアドレスが入っています。つまり(1)も(2)も、`int`データを指すアドレスに 1\nを足して中身を参照するという、式として全く同じことをしていることになります。\n\n配列でもポインタでも実は同じなので、`*(p + i)`は、`p[i]`と全く同じ意味になっているわけです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T14:47:02.967", "id": "37624", "last_activity_date": "2017-08-30T14:47:02.967", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3605", "parent_id": "37620", "post_type": "answer", "score": 2 }, { "body": "妥当な疑問です。配列は暗黙的にポインタに変換され、`p[i]` に対する代入と `*(p + i)` に対する代入は同じ意味になります。`p[i]`\nは「配列 `p` の `i` 番目の値」であり、`*(p + i)` は「`(p + i)` が参照する場所の値」であることに注意してください。\n\nたとえばポインタ `p` へ確保した配列を箱の絵で表すとすると、下のような絵が描けます。\n\n```\n\n +---+---+---+---+---+\n int[5] | | | | | | 配列\n +---+---+---+---+---+\n ^ ^\n | |\n | |\n | |\n int* | p+0 | p+3 ポインタ\n \n```\n\n(上の ASCII アートは\n[fredoverflow](https://stackoverflow.com/users/252000/fredoverflow)\nさんの[投稿](https://stackoverflow.com/a/4810668/5989200)を参考にしました)\n\n参考\n\n * [How do I use arrays in C++?](https://stackoverflow.com/a/4810668/5989200) \\-- 本家 Stack Overflow\n * [Pointers to arrays](http://www.cplusplus.com/doc/tutorial/pointers/#arrays) \\-- CPlusPlus.com チュートリアル", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T14:51:52.017", "id": "37625", "last_activity_date": "2017-08-30T16:02:37.453", "last_edit_date": "2017-08-30T16:02:37.453", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "37620", "post_type": "answer", "score": 1 } ]
37620
37622
37622
{ "accepted_answer_id": "37632", "answer_count": 2, "body": "とある問題を解くために以下のようなコードをかきました。 \nしかし、gravityメソッドが勝手にprivate扱いされてしまいます。 \n'#'の付いている行をすべてコメントアウトすると期待通りに動きました。 \nどなたか詳しい方、なぜgravityがprivate扱いされてしまうのか教えてください \n処理系は2.3.1です。\n\n* * *\n```\n\n line = gets.chomp.split(' ')\n $W = line[0].to_i\n $H = line[1].to_i\n $N = line[2].to_i\n $sen = Array.new\n $H.times do\n    $sen << gets.chomp.split(\"\")\n end\n $sen.reverse!\n $sen = $sen.transpose\n \n def gravity #落ちる\n    $sen.each do |y|\n       y.delete('0')\n       ($H-y.length).times do\n          y << '0'\n       end\n    end\n end #\n $sen.gravity #\n p $sen\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T14:39:49.863", "favorite_count": 0, "id": "37623", "last_activity_date": "2017-08-31T03:22:49.430", "last_edit_date": "2017-08-30T15:28:49.253", "last_editor_user_id": "13199", "owner_user_id": "24965", "post_type": "question", "score": 2, "tags": [ "ruby" ], "title": "Rubyで勝手にprivate method扱いされる", "view_count": 2374 }
[ { "body": "「なぜgravityがprivate扱いされてしまうのか教えてください」という質問については、Ruby公式マニュアルに[「トップレベルで定義したメソッドはmainオブジェクトのprivateメソッドとして定義されます。」](https://docs.ruby-\nlang.org/ja/2.3.0/class/main.html)と書かれています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T21:13:28.553", "id": "37627", "last_activity_date": "2017-08-30T21:13:28.553", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4010", "parent_id": "37623", "post_type": "answer", "score": 2 }, { "body": "このコードの本質的な問題は`gravity`メソッドの呼び出し方が不適切なことです。本来は`undefined\nmethod`になるほうが好ましいように思えるのですが、後述するRubyの動作により、プライベートメソッドの呼び出しのエラーになってしまいます。\n\n単純な解決策としては`$sen.gravity`ではなく、`gravity`として呼び出してください。\n\nまた、メソッド定義じゃなくしたら動作した、とありますが、このコードだとメソッド定義する必要がないので、それも一つの解決策だと思います。\n\n* * *\n\nマニュアルには確かに「トップレベルで定義したメソッドは main オブジェクトの private メソッドと\nして定義されます。」と書いてあるのですが、質問のコードの挙動とは矛盾しているので説明になってません。\n\nマニュアルの通りであれば、`gravity`は`main`オブジェクトのメソッドなのですから、`$sen.gravity`は`undefined\nmethod`になるはずです。ところが実際には`private method 'gravity' called`のエラーになります。\n\n実際には、トップレベルで定義したメソッドはKernelモジュールのプライベートなインスタンスメソッドとして定義されます。KernelモジュールはObjectクラスがincludeしておりObjectクラスは全てのクラスのスーパークラスなので、トップレベルで定義したメソッドは全てのクラスにおいてプライベートなインスタンスメソッドとして参照できることになります。\n\n```\n\n def m\n p self.class\n end\n \n [].__send(:m) #=> Array\n {}.__send(:m) #=> Hash\n #無理矢理呼び出す\n \n def hoge\n puts \"hoge\"\n end\n \n class Hoge\n def fuga\n hoge\n end \n end\n \n Hoge.new.fuga #=> \"hogeを表示\"\n Hoge.new.hoge #=> private method `hoge' called for #<Hoge:0x00000804ce1f10> (NoMethodError)\n \n```\n\n* * *", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T03:22:49.430", "id": "37632", "last_activity_date": "2017-08-31T03:22:49.430", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "37623", "post_type": "answer", "score": 4 } ]
37623
37632
37632
{ "accepted_answer_id": "37629", "answer_count": 1, "body": "タイトルの通り、JavaScriptでキャッシュされたファイルのリストを取得することは可能でしょうか?もし可能ならば、詳細を教えてください。よろしくお願いします。\n\n具体的にはブラウザにWebフォントがキャッシュされているかどうかを調べ、キャッシュされていればすぐにページを表示し、されていない場合はローディング画面を出してからページを表示させたいと思っています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-30T19:42:39.497", "favorite_count": 0, "id": "37626", "last_activity_date": "2017-09-01T05:44:39.653", "last_edit_date": "2017-09-01T05:44:39.653", "last_editor_user_id": "19687", "owner_user_id": "19687", "post_type": "question", "score": 0, "tags": [ "javascript" ], "title": "JavaScriptでキャッシュされたファイルのリストを取得する", "view_count": 877 }
[ { "body": "キャッシュファイルというのはブラウザのキャッシュファイルを指しているのでしょうか? \nそうであれば、File API を利用して取得できなくもないですけど、ブラウザによって保存場所が異なるのでいずれにしろ難しいのではないかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T00:48:51.013", "id": "37629", "last_activity_date": "2017-08-31T00:48:51.013", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2265", "parent_id": "37626", "post_type": "answer", "score": 0 } ]
37626
37629
37629
{ "accepted_answer_id": null, "answer_count": 2, "body": "記述するべき内容が不足していたら申し訳ありません。\n\n \n\n* * *\n\n### やりたいこと\n\n配列内を **正規表現を用いて** 検索し、「マッチした文字列」の中で「一番要素数が大きい文字列」を取得したいです。\n\n \n\n* * *\n\n### 現状\n\n「文字列」(=inData、可変)と「区切文字」(=delimiter、可変、正規表現を使う場合あり)を投げると、\n\n```\n\n ・Regex.splitを用いて区切る\n ・「区切前方文字(=front)」を代入\n ・「マッチした区切文字(delimiter)」を代入\n ・「区切後方文字(=behind)」を代入\n ・区切れたら(inData内からdelimiterがマッチする箇所が1つでも存在したら)true/区切れなかったらfalseを返す\n \n```\n\n上記のことを行う関数(GetSplitData)を作りました。\n\n「区切文字にマッチする箇所が1箇所のみだった」時の動きの例は以下の通りです。 \nこれは想定通り動作しています。\n\n```\n\n 例:GetSplitData(\"AAA BBB\", \"\\s+\", \"\", \"\")// inData, delimiter, front, behind\n 戻り値→inData = \"AAA BBB\"\n front = \"AAA\"\n delimiter = \" \"\n behind = \"BBB\"\n return true\n \n```\n\n今回「区切り文字にマッチする箇所が複数存在した」時の動きを悩んでいます。 \n望む形は以下の通りです。\n\n```\n\n 例:GetSplitData(\"AAA00BBB0000CCC\", \"[0-9]+\", \"\", \"\")\n →inData = \"AAA00BBB0000CCC\"\n front = \"AAA00BBB\"\n delimiter = \"0000\"\n behind = \"CCC\"\n return true\n \n```\n\n \n\nRegex.splitを用いている為、現在の動きだと \nStringの配列内に\"AAA\",\"00\",\"BBB\",\"0000\",\"CCC\"が入ります。 \nここから後ろの\"0000\"を取得する方法が思いつきません。 \n複数存在したら再度配列をdelimiterで舐めようかと思ったのですが、 \n**配列を正規表現を用いて舐める方法** が検索しても出てきませんでした。 \nまた、後ろのdelimiterが取得出来た所で、 \nその **前後を取得する方法** も思いつきません。 \n(正規表現なしならLastIndexOfが使えそうだなとは思いましたが…。使うとどうも\"[0-9]+\"という文字列を検索しに行ってしまう?) \n(私が調べ損ねているだけで、LastIndexOfでも正規表現が使えるのでしょうか?)\n\n使えそうなメソッド、アルゴリズム、考え方等ございましたらご教授願います。 \n皆様のお知恵をお貸しいただければと思います。 \nどうぞよろしくお願いいたします。\n\n \n\n### 環境\n\n・Microsoft Visual Studio 2013 Express for Windows \n・.NET Framework 4.5.1 \n・C# 5.0\n\n \n\n* * *\n\n### 追記\n\n混乱させてしまい申し訳ございません。 \ndelimiterの採用条件は「文字列の長さ」ではなく「一番後ろにあるもの」です。 \n\"AAA0000BBB00CCC\"というinData、\"[0-9]+\"というdelimiterが来た場合、 \ndelimiterに採用するのは「00」です。一番後ろにある為。 \narray[x]のxのことを「要素数」と勘違いしておりました。 \n用語を正しく使わなかった為に混乱させてしまい、大変失礼いたしました。\n\n \n\n* * *\n\n### 追記2 そもそもこの質問をすることになった経緯\n\n```\n\n public bool GetSplitData(string inData, string delimiter, ref string front, ref string behind)\n {\n // 区切文字は後ろから検索する\n int index = inData.IndexOf(delimiter);\n // 区切り無し\n if (index == -1) return false;\n \n front = inData.Substring(0, index);\n behind = inData.Substring(index + delimiter.Length, inData.Length - (index + delimiter.Length));\n return true;\n }\n \n```\n\n \n\n 1. この関数は「○○課 山田 太郎」のような文字列を区切る為に使用していた\n 2. 最初は上記のコードを使って区切っていた(そもそもindexOfは「最初に見つけた部分のindexを返す関数」のはずなのに何故か最後の部分のindexを返してくれる。未だに謎です。)\n 3. 「1.」の時はデリミターに「課」を入力させ、別の関数で「前にくっつける」ことを行い、「○○課」「山田 太郎」と区切っていた\n 4. 後になって「○○課\\r\\n山田 太郎」や「○○課○○部 山田太郎」というのが出てきた\n 5. indexOfに\"\\r\\n\"や\"(課|部)\"を入れても区切ってくれない\n 6. 「区切文字がマッチする箇所が複数存在したら一番後ろで区切る」という仕様が決められている\n 7. 質問に至る", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T00:18:30.100", "favorite_count": 0, "id": "37628", "last_activity_date": "2018-03-15T00:15:16.517", "last_edit_date": "2017-09-01T00:11:09.567", "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": -1, "tags": [ "c#", ".net", "正規表現" ], "title": "配列内を正規表現で検索したい", "view_count": 2238 }
[ { "body": "`LastIndexOf`のように検索したいのか文字数で判断したいのかよくわかりませんが、`Regex.Matches`を呼び出して最長または最後`Match`を採用すればよいのでは。\n\n```\n\n var ms = Regex.Matches(inData, delimiter);\n if (ms.Count > 0)\n {\n var m = ms[mc.Count -1];\n \n front = inData.Substring(0, m.Index);\n delimiter = m.Value;\n behind = inData.Substring(m.Index + m.Length);\n \n return true;\n }\n \n```\n\n## 正規表現で否定先読みを使用すべきではない理由\n\n正規表現を複数の箇所にマッチさせる場合、特定の箇所にマッチしたかどうか自体が後続の結果に影響します。ですので正規表現自体を書き換えるのは避けるべきです。\n\n### 例\n\n文字列`aaba`にパターン`(a+|aba)`をマッチさせた場合、該当しうる箇所は\n\n 1. 1 文字目: `a`\n 2. 1-2文字目: `aa`\n 3. 2 文字目: `a`\n 4. 2-4文字目: `aba`\n 5. 4 文字目: `a`\n\nです。しかし`Regex.Matches`でマッチさせた場合、結果として`aa`(2.)と`a`(5.)が得られます。 \nこれは`aa`に含まれる1.と、`aa`の途中から始まる3.と4.が除外されたからです。\n\nしかし否定先読みで`(a+|aba)(?!.*(a+|aba))`とパターンを変えると、1.と2.は4文字目の`a`のためにマッチしません。ですので2文字目から始まる3.と4.が比較され、より長い`aba`がマッチします。\n\nもちろん「`a`も`aba`も終了位置は同じ」と開き直ることもできますが、`GetSplitData`メソッドの実装を知らない人になぜ`a`ではなく`aba`がデリミターなのかという仕様を説明することは難しいでしょう。 \n単純に`Regex.Matches`を使用すれば正規表現の基本ルールにのっとっていますので、第三者へのわかりやすさからこちらをお勧めします。\n\n## 例2\n\n否定先読みを使うと問題になるもっとわかりやすいケースがあったので結果だけ掲載しておきます。原因は上で説明した通りです。\n\n * `Regex.Split(\"a==b==c\", \"==\")` -> `\"a\", \"b\", \"c\"`\n * `Regex.Split(\"a====c\", \"==\")` -> `\"a\", \"\", \"c\"`\n * `Regex.Split(\"a====c\", \"==(?!.*==)\")` -> `\"a=\", \"=c\"`", "comment_count": 9, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T01:24:31.387", "id": "37630", "last_activity_date": "2017-08-31T22:44:05.053", "last_edit_date": "2017-08-31T22:44:05.053", "last_editor_user_id": "5750", "owner_user_id": "5750", "parent_id": "37628", "post_type": "answer", "score": 0 }, { "body": "sayuri様、pgrho様、ご回答ありがとうございました。 \n今回は先に回答していただいたsayuri様をベストアンサーとさせていただきます。 \npgrho様のラムダ式、linqを用いた書き方も非常に勉強になりました。別の箇所で参考にさせていただきます。\n\n以下、実際に動かしたプログラムです。\n\n \n\n```\n\n public bool GetSplitData(string inData, ref string delimiter, ref string front, ref string behind)\n {\n // 否定先読みの正規表現に置き換える\n string pattern = String.Format(\"({0}(?!.*{0}))\", delimiter);\n Regex splitRegex = new Regex(pattern);\n // SplitでinDataを区切る\n string[] splited = splitRegex.Split(inData);\n // 3つに区切れたら振り分ける\n if (splited.Length == 3)\n {\n front = splited[0];\n delimiter = splited[1];\n behind = splited[2];\n return true;\n }\n else return false;\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T07:44:44.377", "id": "37637", "last_activity_date": "2017-08-31T07:44:44.377", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "parent_id": "37628", "post_type": "answer", "score": 0 } ]
37628
null
37630
{ "accepted_answer_id": null, "answer_count": 4, "body": "下記の(例1.変換前)のようなXML形式のファイルから、 \ntestを含む要素を丸っと削除したいと考えています。\n\ntestを含む要素が2000個ほどまばらに存在し、 \n繰り返し行う作業のため、絶対自動化したいのですが、 \nsedを使ってどう表現すればいいのかずっと頭を抱えています。\n\n(例1.変換前) → testを含む要素を削除 → (例2.変換後)\n\nこのtestを含む要素の削除方法について、 \nアドバイスをいただけないでしょうか。\n\n実装言語としては、シェルスクリプトを想定していますが、ツール、言語等問いません。\n\n恐らく実装された経験がある方、類似の方法を検索する際に必要なキーワードがピンとくる方からすれば楽勝案件なのでは・・・と思っています。そのため、ピンとくるキーワードだけの解答でも大変助かります。\n\n(例1.変換前)\n\n```\n\n <dependency>\n <groupId>com.fasterxml.jackson.core</groupId>\n <artifactId>jackson-annotations</artifactId>\n <version>${jackson.version}</version>\n <type>jar</type>\n <scope>compile</scope>\n </dependency>\n <dependency>\n <groupId>com.fasterxml.jackson.core</groupId>\n <artifactId>jackson-annotations</artifactId>\n <version>${jackson.version}</version>\n <type>test</type>\n <scope>compile</scope>\n </dependency>\n \n```\n\n(例2.変換後)\n\n```\n\n <dependency>\n <groupId>com.fasterxml.jackson.core</groupId>\n <artifactId>jackson-annotations</artifactId>\n <version>${jackson.version}</version>\n <type>jar</type>\n <scope>compile</scope>\n </dependency>\n \n```", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T06:11:04.857", "favorite_count": 0, "id": "37636", "last_activity_date": "2018-01-10T00:40:07.517", "last_edit_date": "2017-08-31T06:31:52.450", "last_editor_user_id": "21092", "owner_user_id": "25128", "post_type": "question", "score": 0, "tags": [ "shellscript", "xml", "sed" ], "title": "[言語不問]XML中の、特定文字列を持つ子要素を持つ親要素を消す方法", "view_count": 1189 }
[ { "body": "XMLパーサーのライブラリを使ったプログラムをつくった方がいいかもしれませんね。javaで **最低限動くもの** だったら、こんな感じでいいと思います。\n\n```\n\n import java.io.File;\n import java.io.FileOutputStream;\n \n import javax.xml.parsers.DocumentBuilder;\n import javax.xml.parsers.DocumentBuilderFactory;\n import javax.xml.transform.Transformer;\n import javax.xml.transform.TransformerFactory;\n import javax.xml.transform.dom.DOMSource;\n import javax.xml.transform.stream.StreamResult;\n \n import org.w3c.dom.Document;\n import org.w3c.dom.Element;\n import org.w3c.dom.Node;\n import org.w3c.dom.NodeList;\n \n public class RemoveTestDependencies {\n public static void main(String[] args) {\n try {\n DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();\n DocumentBuilder builder = dbfactory.newDocumentBuilder();\n Document doc = builder.parse(new File(args[0]));\n Element root = doc.getDocumentElement();\n NodeList childNodes = root.getChildNodes();\n for (int i = 0; i < childNodes.getLength(); i++) {\n Node item = childNodes.item(i);\n if (\"dependencies\".equals(item.getNodeName())) {\n NodeList childNodes2 = item.getChildNodes();\n int length = childNodes2.getLength();\n for (int j = 0; j < childNodes2.getLength(); j++) {\n Node item2 = childNodes2.item(j);\n if (\"dependency\".equals(item2.getNodeName())) {\n NodeList childNodes3 = item2.getChildNodes();\n for (int k = 0; k < childNodes3.getLength(); k++) {\n Node item3 = childNodes3.item(k);\n if (item3 != null && \"type\".equals(item3.getNodeName())\n && item3.getTextContent() != null\n && item3.getTextContent().indexOf(\"test\") >= 0) {\n item.removeChild(item2);\n }\n }\n }\n }\n System.out.println(\"Removed \"+ (length - childNodes2.getLength()) + \" dependencies\");\n }\n }\n TransformerFactory transFactory = TransformerFactory.newInstance();\n Transformer transformer = transFactory.newTransformer();\n DOMSource source = new DOMSource(doc);\n File newXML = new File(args[1]);\n FileOutputStream os = new FileOutputStream(newXML);\n StreamResult result = new StreamResult(os);\n transformer.transform(source, result);\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n }\n \n```\n\n引数に修正前後のpom.xmlのパスを渡します。\n\n```\n\n java RemoveTestDependencies C:\\test\\pom.xml C:\\test\\pom_new.xml\n \n```\n\n※適当に書いたので、例外処理などはちゃんと実装する必要があります。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T09:47:48.923", "id": "37640", "last_activity_date": "2017-08-31T09:47:48.923", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "21092", "parent_id": "37636", "post_type": "answer", "score": 1 }, { "body": "`sed` は行指向のコマンドですので、XML のようなフォーマットを扱うのは非常に難しく、殆ど不可能です。 \nシェルスクリプトで XML を扱うには、\n\n * XML 専用のコマンドを使用する\n * XML を行指向のフォーマットに変換してから処理する\n * 該当部分だけ、XML を扱うライブラリが用意されているプログラミング言語でコマンドとして作成する\n\nといった事が必要です。 \nXML 専用のコマンドをいくつか紹介すると、`xsltproc`(XSLT\nを覚える必要がある)、`xmllint`(今回の例には力不足か)、`xmlstarlet`(xpath で簡単な編集までならできる)などです。\n\n`xmlstarlet` を使用する例:\n\n```\n\n # この xpath が質問の要件を満たしているかは、十分に検討していません\n xmlstarlet ed -d '//dependency[type[text()=\"test\"]]' in.xml\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T09:57:40.003", "id": "37642", "last_activity_date": "2017-08-31T09:57:40.003", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "37636", "post_type": "answer", "score": 3 }, { "body": "```\n\n ## GNU sed の場合\n $ sed --version\n sed (GNU sed) 4.4\n $ sed -nr '\n /<dependency>/,/<\\/dependency>/{\n H\n /<\\/dependency>/{\n x\n s/^\\n//\n /<type>test<\\/type>/!p\n s/.*//\n h\n }\n }' dependency.xml\n \n ## Awk の場合\n $ awk -v RS='</?dependency>' '\n /<type>/ && !/<type>test<\\/type>/{\n print \"<dependency>\" $0 \"</dependency>\"\n }' dependency.xml\n \n ## GNU grep の場合\n $ grep --version\n grep (GNU grep) 3.1\n $ grep -Pzo '<dependency>((?!</dependency>)(.|\\n))*?<type>((?!test<).)*?/type>(.|\\n)*?</dependency>\\n?' dependency.xml \n \n```\n\nGNU sed 版の場合、`<dependency>` タグは同一行になくて `<type>`\nタグは同一行にあることが前提なので、かなり無理がありそうです(XML 文字列のフォーマットを強制しているので)。\n\nAwk 版は `RS` 変数を使って `<dependency> 〜 </dependency>` ブロックを 1 論理行とみなして処理していて、GNU\ngrep 版では `negative lookahead((?!...))` を使っています。\n\n全体的に「やればできないことはない」といった所でしょうかね。お勧めできませんけれども。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T12:43:01.940", "id": "37647", "last_activity_date": "2017-08-31T15:05:47.867", "last_edit_date": "2017-08-31T15:05:47.867", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "37636", "post_type": "answer", "score": 1 }, { "body": "このようなフィルタリングはXSLTでやれば簡単ですね.御要望の条件を\n\n「子要素のテキストに\"test\"を含むdependency要素を削除する.」\n\nと解釈させていただきますと、次のようなXSLTスタイルシートで一発でできます.\n\n```\n\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n version=\"1.0\">\n \n <!--子要素のテキストに\"test\"を含むdependency要素は読み飛ばす-->\n <xsl:template match=\"dependency[*[contains(.,'test')]]\"/>\n \n <!-- 他は単純にコピーする -->\n <xsl:template match=\"*\">\n <xsl:copy>\n <xsl:copy-of select=\"@*\"/>\n <xsl:apply-templates/>\n </xsl:copy>\n </xsl:template>\n \n </xsl:stylesheet>\n \n```\n\nXSLT 1.0の機能で十分です.私はSaxonでやりましたがWindowsに入っているMSXMLでもいけるはずです.", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T00:31:47.423", "id": "37650", "last_activity_date": "2017-09-01T00:31:47.423", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9503", "parent_id": "37636", "post_type": "answer", "score": 3 } ]
37636
null
37642
{ "accepted_answer_id": null, "answer_count": 1, "body": "python-pptxを使っているのですが,スライドのサイズをA4にしたいです。 \nどのようにしたら良いでしょうか?", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T09:23:00.213", "favorite_count": 0, "id": "37638", "last_activity_date": "2017-08-31T09:54:30.867", "last_edit_date": "2017-08-31T09:54:30.867", "last_editor_user_id": "19110", "owner_user_id": "25132", "post_type": "question", "score": -1, "tags": [ "python" ], "title": "python-pptxでスライドのサイズを変えたい", "view_count": 1390 }
[ { "body": "[ドキュメント](https://python-\npptx.readthedocs.io/en/latest/api/presentation.html#presentation-\nobjects)に書いてあるように `Presentation` オブジェクトには `slide_height` と `slide_width`\nが存在しているので、これを書き換えればサイズが変わります。\n\n参考\n\n * [A4 の大きさ](https://ja.wikipedia.org/wiki/%E7%B4%99%E3%81%AE%E5%AF%B8%E6%B3%95#A.E5.88.97)\n * 単位が [English Metric Unit](https://en.wikipedia.org/wiki/Office_Open_XML_file_formats#DrawingML) (EMU; 1 cm = 360 000 emu) なので注意してください。\n * [mm <\\--> emu の変換器](http://lcorneliussen.de/raw/dashboards/ooxml/)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T09:52:54.557", "id": "37641", "last_activity_date": "2017-08-31T09:52:54.557", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19110", "parent_id": "37638", "post_type": "answer", "score": 1 } ]
37638
null
37641
{ "accepted_answer_id": "37655", "answer_count": 1, "body": "h2databaseの接続ができなくて困っています。\n\nコンソール自体の起動はできて、 JDBC URL:jdbc:h2:tcp://localhost/~/test \nのテスト動作も問題なくおこなえますが、別のアドレスJDBC URL:jdbc:h2:~/terasolunaを指定すると、以下のようにログがでます。\n\n```\n\n 一般エラー: java.lang.RuntimeException: rowcount remaining=-1 SYS\n General error: java.lang.RuntimeException: rowcount remaining=-1 SYS [50000-78] HY000/50000 (ヘルプ)\n org.h2.jdbc.JdbcSQLException: 一般エラー: java.lang.RuntimeException: rowcount remaining=-1 SYS\n General error: java.lang.RuntimeException: rowcount remaining=-1 SYS [50000-78] \n at org.h2.message.Message.getSQLException(Message.java:103) \n at org.h2.message.Message.convert(Message.java:257) \n at org.h2.engine.Database.<init>(Database.java:226) \n at org.h2.engine.Engine.openSession(Engine.java:56) \n at org.h2.engine.Engine.openSession(Engine.java:125) \n at org.h2.engine.Engine.getSession(Engine.java:108) \n at org.h2.engine.Session.createSession(Session.java:242) \n at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:108) \n at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:87) \n at org.h2.Driver.connect(Driver.java:57) \n at org.h2.server.web.WebServer.getConnection(WebServer.java:625) \n at org.h2.server.web.WebThread.test(WebThread.java:1028) \n at org.h2.server.web.WebThread.process(WebThread.java:440) \n at org.h2.server.web.WebThread.processRequest(WebThread.java:184) \n at org.h2.server.web.WebThread.process(WebThread.java:239) \n at org.h2.server.web.WebThread.run(WebThread.java:194) \n Caused by: java.lang.RuntimeException: rowcount remaining=-1 SYS \n at org.h2.message.Message.getInternalError(Message.java:179) \n at org.h2.table.TableData.addIndex(TableData.java:202) \n at org.h2.engine.Database.open(Database.java:564) \n at org.h2.engine.Database.<init>(Database.java:207) \n ... 13 more \n \n```\n\n再度、やり直すたびに、ポート番号は特定してタスクを消去して競合しないようにはしていますが、考えられる原因はどのようなものがあありますでしょうか?\n\n追加:h2db_init実行時のログ\n\n```\n\n C:\\Users\\hironori\\Desktop\\pleiades\\workspace\\terasoluna-spring-thin-blank\\h2db>\n ava -cp h2.jar org.h2.tools.RunScript -url jdbc:h2:~/terasoluna -user sa -scrip\n terasoluna.script -showResults\n Exception in thread \"main\" org.h2.jdbc.JdbcSQLException: 一般エラー: java.lang.\n untimeException: rowcount remaining=-1 SYS\n General error: java.lang.RuntimeException: rowcount remaining=-1 SYS [50000-78]\n at org.h2.message.Message.getSQLException(Message.java:103)\n at org.h2.message.Message.convert(Message.java:257)\n at org.h2.engine.Database.<init>(Database.java:226)\n at org.h2.engine.Engine.openSession(Engine.java:56)\n at org.h2.engine.Engine.openSession(Engine.java:125)\n at org.h2.engine.Engine.getSession(Engine.java:108)\n at org.h2.engine.Session.createSession(Session.java:242)\n at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:108)\n at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:87)\n at org.h2.Driver.connect(Driver.java:57)\n at java.sql.DriverManager.getConnection(Unknown Source)\n at java.sql.DriverManager.getConnection(Unknown Source)\n at org.h2.tools.RunScript.process(RunScript.java:319)\n at org.h2.tools.RunScript.run(RunScript.java:151)\n at org.h2.tools.RunScript.main(RunScript.java:94)\n Caused by: java.lang.RuntimeException: rowcount remaining=-1 SYS\n at org.h2.message.Message.getInternalError(Message.java:179)\n at org.h2.table.TableData.addIndex(TableData.java:202)\n at org.h2.engine.Database.open(Database.java:564)\n at org.h2.engine.Database.<init>(Database.java:207)\n ... 12 more\n \n```\n\nオプション追加実行後のログ\n\n```\n\n C:\\Users\\hironori\\Desktop\\pleiades\\workspace\\terasoluna-spring-thin-blank\\h2db>j\n ava -Dh2.check=false -cp h2.jar org.h2.tools.RunScript -url jdbc:h2:~/terasoluna\n -user sa -script terasoluna.script -showResults\n Exception in thread \"main\" org.h2.jdbc.JdbcSQLException: テーブル USERLIST が見\n つかりません\n Table USERLIST not found; SQL statement:\n CREATE INDEX PUBLIC.IDX_USERLIST ON PUBLIC.USERLIST(ID) [42102-78]\n at org.h2.message.Message.getSQLException(Message.java:103)\n at org.h2.message.Message.getSQLException(Message.java:114)\n at org.h2.message.Message.getSQLException(Message.java:77)\n at org.h2.schema.Schema.getTableOrView(Schema.java:348)\n at org.h2.command.ddl.CreateIndex.update(CreateIndex.java:60)\n at org.h2.engine.MetaRecord.execute(MetaRecord.java:85)\n at org.h2.engine.Database.open(Database.java:584)\n at org.h2.engine.Database.<init>(Database.java:207)\n at org.h2.engine.Engine.openSession(Engine.java:56)\n at org.h2.engine.Engine.openSession(Engine.java:125)\n at org.h2.engine.Engine.getSession(Engine.java:108)\n at org.h2.engine.Session.createSession(Session.java:242)\n at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:108)\n at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:87)\n at org.h2.Driver.connect(Driver.java:57)\n at java.sql.DriverManager.getConnection(Unknown Source)\n at java.sql.DriverManager.getConnection(Unknown Source)\n at org.h2.tools.RunScript.process(RunScript.java:319)\n at org.h2.tools.RunScript.run(RunScript.java:151)\n at org.h2.tools.RunScript.main(RunScript.java:94)\n \n```", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T09:41:52.043", "favorite_count": 0, "id": "37639", "last_activity_date": "2017-09-01T04:59:38.720", "last_edit_date": "2017-09-01T04:59:38.720", "last_editor_user_id": "21092", "owner_user_id": "25002", "post_type": "question", "score": 0, "tags": [ "sql", "database" ], "title": "H2databaseの接続エラーについて", "view_count": 2803 }
[ { "body": "`h2db_init.bat`の次の行に\n\n```\n\n java -cp h2.jar org.h2.tools.RunScript -url %H2URL% -user %H2USER% -script terasoluna.script -showResults\n \n```\n\n`-Dh2.check=false`というオプションを付加してから、実行したら結果が変わりませんか?\n\n```\n\n java -Dh2.check=false -cp h2.jar org.h2.tools.RunScript -url %H2URL% -user %H2USER% -script terasoluna.script -showResults\n \n```", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T04:07:25.147", "id": "37655", "last_activity_date": "2017-09-01T04:07:25.147", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "21092", "parent_id": "37639", "post_type": "answer", "score": 0 } ]
37639
37655
37655
{ "accepted_answer_id": null, "answer_count": 1, "body": "QtCreatorは非Qtのプロジェクトにも対応していると聞きましたが、QtCreatorからLGPLv3ではないバイナリが作成できますでしょうか?\n\nつまり、非QtプロジェクトにQtCreatorがコード片の混入したり、ライブラリをリンクしたりしてLGPLv3のライセンスでリリースしなければならなくなることはないでしょうか?\n\n通常IDEのライセンスがプロジェクトにライセンスが影響するとは思えないのですが、文書で示されたものが見てみたいです。\n\nAndroid Projectのために GCC/libstdc++ の\nGPL例外条項は把握しています。これのQtCreator版のようなものを求めています。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T10:48:32.147", "favorite_count": 0, "id": "37643", "last_activity_date": "2021-01-28T13:06:20.627", "last_edit_date": "2019-07-27T03:40:13.747", "last_editor_user_id": "3060", "owner_user_id": "4727", "post_type": "question", "score": 0, "tags": [ "qt", "ライセンス", "qt-creator", "gpl" ], "title": "オープンソース版のQtCreatorで例えばBSDライセンスのバイナリが作成できますか?", "view_count": 355 }
[ { "body": "自身見かけたことはなく、[Qtのライセンスに関するページ](https://www.qt.io/qt-licensing-\nterms/)にもQtCreatorで作成したコード自体のライセンスがLGPLv3になるかならないかは明記されていませんでした。(リンクするオブジェクトの例外項はありました)\n\n個々のソフトウェアのライセンス条件についての確認であれば、ライセンサ当人(Qt Company)に確認するのが確実かと思います。\n\n#エディタとして使う限りは、自動生成されるコードは0にできます。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T00:56:22.063", "id": "37673", "last_activity_date": "2017-09-02T00:56:22.063", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20098", "parent_id": "37643", "post_type": "answer", "score": 0 } ]
37643
null
37673
{ "accepted_answer_id": null, "answer_count": 0, "body": "wordpress(GPLライセンス)において、下記のケースは違反にあたりますでしょうか? \nもしくは、ソース開示が必要なケースにあたりますでしょうか?\n\n・wordpressベースで改変を行い、db,apiのみを利用するCMSを構築し自社サーバに設置。 \n有料で不特定多数のユーザにCMS提供", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T11:54:03.863", "favorite_count": 0, "id": "37646", "last_activity_date": "2017-08-31T11:54:03.863", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3827", "post_type": "question", "score": 1, "tags": [ "ライセンス", "gpl" ], "title": "GPLライセンスにおいて不特定多数のユーザへのサービス提供に関して", "view_count": 112 }
[]
37646
null
null
{ "accepted_answer_id": "37682", "answer_count": 1, "body": "[昨日質問させていただいた内容](https://ja.stackoverflow.com/q/37599/19110)は解決したのですが、その後\n\n```\n\n POST data should be bytes or an iterable of bytes. It cannot be of type str.\n \n```\n\nというエラーコードに悩んでいます。 \n調べたところスタックトレースを見ると良いともあったのですが、できるように色々いじって見たのですが、他にエラーが増えてしまうだけでした。\n\nプログラムとして現状\n\n```\n\n #!/usr/bin/env python\n # -*- coding: utf-8 -*-\n \n #Docomoの雑談対話APIを使ってチャットできるスクリプト\n \n import sys\n import urllib.request\n import json\n import os\n \n APP_URL = 'https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue'\n \n class DocomoChat(object):\n #Docomoの雑談対話APIでチャット\n \n def __init__(self, api_key):\n api_key = os.environ.get('DOCOMO_DIALOGUE_API_KEY', api_key)\n super(DocomoChat, self).__init__()\n self.api_url = APP_URL + ('?APIKEY=%s'%api_key)\n self.context, self.mode = None, None\n \n def __send_message(self, input_message='', custom_dict=None):\n req_data = {'utt': input_message}\n if self.context:\n req_data['context'] = self.context\n if self.mode:\n req_data['mode'] = self.mode\n if custom_dict:\n req_data.update(custom_dict)\n request = urllib.request.Request(self.api_url, json.dumps(req_data))\n request.add_header('Content-Type', 'application/json')\n try:\n response = urllib.request.urlopen(request)\n except Exception as e:\n print (e)\n sys.exit()\n return response\n \n def __process_response(self, response):\n resp_json = json.load(response)\n self.context = resp_json['context'].encode('utf-8')\n self.mode = resp_json['mode'].encode('utf-8')\n return resp_json['utt'].encode('utf-8')\n \n def send_and_get(self, input_message):\n response = self.__send_message(input_message)\n received_message = self.__process_response(response)\n return received_message\n \n \n def set_name(self, name, yomi):\n response = self.__send_message(custom_dict={'nickname': name, 'nickname_y': yomi})\n received_message = self.__process_response(response)\n return received_message\n \n \n def main():\n chat = DocomoChat('api_key')\n resp = chat.set_name('あなたのニックネーム', 'ニックネームのヨミガナ')\n print (('相手  : %s'% resp))\n message = ''\n while message != 'バイバイ':\n message = eval(input('あなた : '))\n resp = chat.send_and_get(message)\n print (('相手  : %s'%resp))\n \n if __name__ == \"__main__\":\n main()\n \n```\n\nこのような状態です。\n\n質問ばかりの頼りきりで申し訳有りません。 \n宜しくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T17:02:23.040", "favorite_count": 0, "id": "37648", "last_activity_date": "2017-09-04T05:51:14.730", "last_edit_date": "2017-09-02T15:11:50.390", "last_editor_user_id": "19110", "owner_user_id": "25104", "post_type": "question", "score": 0, "tags": [ "python", "python3" ], "title": "ドコモAPIを使用した対話プログラムのエラー: POST data should be bytes or an iterable of bytes", "view_count": 566 }
[ { "body": "[`urllib.request.Request`](https://docs.python.jp/3/library/urllib.request.html#urllib.request.Request)\nの `data` 引数は bytes 型である必要があります。この引数に対して現状のコードでは\n[`json.dumps`](https://docs.python.jp/3/library/json.html#json.dumps)\n関数の戻り値がそのまま渡されていますが、これは str 型です。今回は `Content-Type` が `application/json`\nなのでそのまま bytes 型に変換し\n\n```\n\n json.dumps(JSONを表すデータ).encode('何らかのエンコーディング')\n \n```\n\nという形で渡してあげれば良いです。 (補足:`Content-Type` が標準の `application/x-www-form-urlencoded`\nの場合、更に URL エンコードする必要があります。)\n\n念の為、こちらで動作したコードを [gist\nに上げておきました](https://gist.github.com/nekketsuuu/e7b7a4f232af46a74306660c5c41a211)。\n\n* * *\n\n### 参考\n\n * [docomo 雑談対話 API のリファレンス](https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_name=dialogue&p_name=api_1#tag01)\n * [Python3: JSON POST Request WITHOUT requests library](https://stackoverflow.com/q/25491541/5989200) \\-- Stack Overflow\n\n### 追記\n\n他に気づいた点を簡単に書いておきます。\n\n * Python 2 の `raw_input` 関数に対応する Python 3 の関数は `input` です。\n * 一般に、任意の入力が考えられる場所で `eval` を使うのは危ないです。今回の場合、単に不要です。\n * Python 2 と Python 3 では Unicode 文字列の扱いが変わったため、 `str.encode` 関数の挙動が変わっています。Python 2 では Unicode 文字列と単なる文字列が区別されていたため、文字列から文字列へ変換するために `encode` 関数が使われていました。Python 3 では文字列型の区別が無くなり、更に bytes 型が追加されたため、`encode` 関数は str 型から bytes 型への変換に使われるようになりました。簡単なサンプルコードを下に示しておきます。\n``` $ python2\n\n >>> u'あいう'\n u'\\u3042\\u3044\\u3046'\n >>> u'あいう'.encode('utf-8')\n '\\xe3\\x81\\x82\\xe3\\x81\\x84\\xe3\\x81\\x86'\n >>> type(u'あいう')\n <type 'unicode'>\n >>> type(u'あいう'.encode('utf-8'))\n <type 'str'>\n >>> exit()\n \n $ python3\n >>> u'あいう' # Python 3 では u が不要です\n 'あいう'\n >>> 'あいう'.encode('utf-8')\n b'\\xe3\\x81\\x82\\xe3\\x81\\x84\\xe3\\x81\\x86'\n >>> type(u'あいう')\n <class 'str'>\n >>> type('あいう'.encode('utf-8'))\n <class 'bytes'>\n >>> exit()\n \n```", "comment_count": 9, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T15:31:06.317", "id": "37682", "last_activity_date": "2017-09-04T05:51:14.730", "last_edit_date": "2017-09-04T05:51:14.730", "last_editor_user_id": "19110", "owner_user_id": "19110", "parent_id": "37648", "post_type": "answer", "score": 1 } ]
37648
37682
37682
{ "accepted_answer_id": null, "answer_count": 1, "body": "Xcode Version 8.1(8B62) DeploymentTarget iOS 8.4 \nCore Dataにデータを追加する処理を作っております。 \nXcodeの機能でサブクラスを自動生成して自作メソッドを追加しました。\n\n[![Xcodeで作成したデータモデル](https://i.stack.imgur.com/lU2ly.png)](https://i.stack.imgur.com/lU2ly.png)\n\n```\n\n // Media+CoreDataClass.h\n @interface Media : NSManagedObject\n -(void)import:(NSArray *)received;\n @end\n \n @property (nullable, nonatomic, copy) NSString *id;\n @property (nonatomic) int16_t diskNo;\n @property (nullable, nonatomic, copy) NSString *title;\n \n // Media+CoreDataClass.m\n -(void)import:(NSArray *)received {\n \n self.id = [received valueForKey:@\"id\"];\n self.diskNo = [(NSNumber *)[received valueForKey:@\"diskNo\"] intValue];\n self.title = [received valueForKey:@\"title\"];\n }\n \n```\n\n以下は正常に終了するのですが、\n\n```\n\n appDelegate_ = (AppDelegate *)[[UIApplication sharedApplication] delegate];\n context_ = appDelegate_.persistentContainer.viewContext;\n Media *media = [NSEntityDescription insertNewObjectForEntityForName:@\"Media\"\n inManagedObjectContext:context_];\n media.id = [json valueForKey:@\"id\"];\n media.diskNo = [(NSNumber *)[json valueForKey:@\"diskNo\"] intValue];\n media.title = [json valueForKey:@\"title\"];\n [appDelegate_ saveContext];\n \n```\n\n以下のようにメソッド呼び出しをするとエラーとなります。\n\n```\n\n appDelegate_ = (AppDelegate *)[[UIApplication sharedApplication] delegate];\n context_ = appDelegate_.persistentContainer.viewContext;\n Media *media = [NSEntityDescription insertNewObjectForEntityForName:@\"Media\"\n inManagedObjectContext:context_];\n [media import:json];\n [appDelegate_ saveContext];\n \n```\n\n> -[Media import:]: unrecognized selector sent to instance 0x6000002c2370 \n> Terminating app due to uncaught exception 'NSInvalidArgumentException',\n> reason: '-[Media import:]: unrecognized selector sent to instance\n> 0x6000002c2370'\n\nNSManagedObjectのサブクラスに自作メソッドの追加はできると様々なサイトに書かれていたのですが、やり方がまずい点があればご指摘お願い致します。", "comment_count": 4, "content_license": "CC BY-SA 3.0", "creation_date": "2017-08-31T21:08:08.230", "favorite_count": 0, "id": "37649", "last_activity_date": "2017-09-01T17:09:35.873", "last_edit_date": "2017-08-31T22:49:36.543", "last_editor_user_id": "25139", "owner_user_id": "25139", "post_type": "question", "score": 0, "tags": [ "xcode", "objective-c", "coredata" ], "title": "NSManagedObjectのサブクラスの自作メソッドを呼ぶとunrecognized selector sent to instanceが発生する", "view_count": 659 }
[ { "body": "NSManagedObjectのサブクラスを生成して機能追加を行いたい場合 \n1\\. データモデルを作成する \n2\\. Class - CodegenをManual/Noneにする \n[![Manual/None](https://i.stack.imgur.com/1ALfd.png)](https://i.stack.imgur.com/1ALfd.png) \n3\\. メニューよりEditor - Create NSManagedSubclassを選択 \n4\\. 生成されたサブクラスに機能追加を行う \n5\\. コンパイル・リンク\n\nサブクラスを生成せず(機能追加をせず)CoreDataを利用する場合 \n1\\. データモデルを作成する \n2\\. Class - CodegenをClass Definitionにする \n[![Class\nDefinition](https://i.stack.imgur.com/28lhm.png)](https://i.stack.imgur.com/28lhm.png) \n3\\. コンパイル・リンク\n\nこの時、メニューからCreate\nNSManagedSubclassでサブクラスを生成していた場合、リンク時に同名のクラスが既に存在する旨のエラーが発生する。(サブクラス一式をコンパイル・リンクの対象から外せばエラーは出なくなりますが、当然ながらこのまま実行すると例えば自分で追加したメソッドを呼び出した際は\nunrecognized selector sent to instance が発生する)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T17:09:35.873", "id": "37670", "last_activity_date": "2017-09-01T17:09:35.873", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25139", "parent_id": "37649", "post_type": "answer", "score": 1 } ]
37649
null
37670
{ "accepted_answer_id": "37659", "answer_count": 1, "body": "以下のようなことをやりたいのですが、どうすればいいでしょうか?\n\n```\n\n Hashtable data = new Hashtable();\n data[\"key1\"] = uint.MaxValue;\n data[\"key2\"] = ulong.MaxValue;\n \n //確認(問題なし)\n uint key1 = (uint)data[\"key1\"]; //4294967295\n ulong key2 = (ulong)data[\"key2\"]; //18446744073709551615\n \n //{\"key2\":18446744073709551615,\"key1\":4294967295}\n string json = JsonConvert.SerializeObject(data);\n \n //復元\n Hashtable data2 = JsonConvert.DeserializeObject<Hashtable>(json);\n \n```\n\nこの復元したdata2を元の型にしようとするとエラーが起きます\n\n```\n\n //System.InvalidCastException : Unable to cast object of type 'System.Int64' to type 'System.UInt32'.\n uint key3 = (uint)data2[\"key1\"];\n \n //System.InvalidCastException : Unable to cast object of type 'System.Numerics.BigInteger' to type 'System.UInt64'.\n ulong key4 = (ulong)data2[\"key2\"];\n \n```\n\nどなたか解決方法を教えて下さい \nよろしくお願いします", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T04:32:46.403", "favorite_count": 0, "id": "37657", "last_activity_date": "2017-09-01T06:53:08.513", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22913", "post_type": "question", "score": 1, "tags": [ "c#", "json" ], "title": "C# Hashtableを使ったJsonConvertの数値型で変換エラー", "view_count": 1008 }
[ { "body": "型を明示せずにデシリアライズしているため、`Hashtable`に含まれる数値が元の型と異なっているようです。基本的な対策としてはメッセージにある通りの型に一度キャストしてから目的の型に変換することですが、\n\n```\n\n uint key3 = (uint)(long)data2[\"key1\"];\n ulong key4 = (ulong)(BigInteger)data2[\"key2\"];\n \n```\n\n`IConvertible`を使用するとJson.NETの実装に依存しない記述が可能です。ですが`BigInteger`は`IConvertible`を実装しませんので、別に扱わなくてはなりません。`\n\n```\n\n uint key3 = ((IConvertible)data2[\"key1\"]).ToUInt32(null);\n ulong key4 = data2[\"key2\"] is BigInteger : (ulong)(BigInteger)data2[\"key2\"]\n :((IConvertible)data2[\"key2\"]).ToUInt64(null);\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T06:53:08.513", "id": "37659", "last_activity_date": "2017-09-01T06:53:08.513", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5750", "parent_id": "37657", "post_type": "answer", "score": 1 } ]
37657
37659
37659
{ "accepted_answer_id": null, "answer_count": 0, "body": "タイトルの日本語がわかりにくくてすみません。\n\nコマンドプロンプトで出力される文字列を、 \nコマンドプロンプト上への表示(標準出力)でもなく、 \nファイルを保存するのでもなく、 \nクリップボードにコピー(clipへのパイプ)するのでもなく、 \n別アプリ上へのキーボード入力として出力する方法はないでしょうか。\n\n例えば、開いておいたテキストエディタに文字列が入力されていく、という感じです。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T05:46:51.543", "favorite_count": 0, "id": "37658", "last_activity_date": "2017-09-01T05:46:51.543", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25152", "post_type": "question", "score": 0, "tags": [ "コマンドプロンプト" ], "title": "コマンドプロンプトで別アプリ上へのキーボード入力として出力したい", "view_count": 142 }
[]
37658
null
null
{ "accepted_answer_id": "37665", "answer_count": 1, "body": "**前提・実現したいこと**\n\nその年の売上を月毎に算出してます。 \nまた、会社、販売場所をグループ化しています。\n\n店舗と店舗免税を区別せずに店舗として、合計値を算出したいです。\n\nご教授の程、宜しくお願い申し上げます。\n\n**補足情報**\n\nMySQL 5.7\n\n**現在の状態**\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/MaQum.png)](https://i.stack.imgur.com/MaQum.png)\n\n**該当のソースコード**\n\n```\n\n SELECT \n CASE \n WHEN (`orderer_id`= 2 AND `point_of_sale_id`=2) THEN 'F 社 - 店舗' \n WHEN (`orderer_id`= 2 AND `point_of_sale_id`=3) THEN 'F 社 - 店舗免税'\n WHEN (`orderer_id`= 2 AND `point_of_sale_id`=4) THEN 'F 社 - 国内通販' \n WHEN (`orderer_id`= 2 AND `point_of_sale_id`=5) THEN 'F 社 - 海外通販' \n WHEN (`orderer_id`= 2) THEN 'F 社 - 合計' \n WHEN (`orderer_id`= 3 AND `point_of_sale_id`=2) THEN 'R 社 - 店舗' \n WHEN (`orderer_id`= 3 AND `point_of_sale_id`=3) THEN 'R 社 - 店舗免税' \n WHEN (`orderer_id`= 3 AND `point_of_sale_id`=4) THEN 'R 社 - 国内通販' \n WHEN (`orderer_id`= 3 AND `point_of_sale_id`=5) THEN 'R 社 - 海外通販' \n WHEN (`orderer_id`= 3) THEN 'R 社 - 合計' \n WHEN (`orderer_id`= 4 AND `point_of_sale_id`=2) THEN 'C 社 - 店舗' \n WHEN (`orderer_id`= 4 AND `point_of_sale_id`=3) THEN 'C 社 - 店舗免税' \n WHEN (`orderer_id`= 4 AND `point_of_sale_id`=4) THEN 'C 社 - 国内通販' \n WHEN (`orderer_id`= 4 AND `point_of_sale_id`=5) THEN 'C 社 - 海外通販' \n WHEN (`orderer_id`= 4) THEN 'C 社 - 合計' \n END AS '発注元の会社 - 販売した場所' \n ,sum.`1月`\n ,sum.`2月`\n ,sum.`3月`\n ,sum.`4月`\n ,sum.`5月`\n ,sum.`6月`\n ,sum.`7月`\n ,sum.`8月`\n ,sum.`9月`\n ,sum.`10月`\n ,sum.`11月`\n ,sum.`12月`\n FROM (\n SELECT \n `orderer_id`\n ,`point_of_sale_id`\n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '01'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '1月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '02'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '2月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '03'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '3月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '04'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '4月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '05'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '5月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '06'\n , CASE\n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '6月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '07'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '7月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '08'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '8月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '09'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '9月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '10'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '10月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '11'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '11月' \n ,SUM(\n IF(\n EXTRACT(MONTH from `payment_confirm`) = '12'\n , CASE \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=2 OR `point_of_sale_id`=4) THEN `usually_grand_total` + `grand_consumption_tax_total` \n WHEN (`orderer_id`= 2 OR `orderer_id`= 3 OR `orderer_id`= 4) AND (`point_of_sale_id`=3 OR `point_of_sale_id`=5) THEN `custom_grand_total` \n END\n , 0)\n ) AS '12月' \n FROM \n vw_sales_budget \n WHERE \n EXTRACT(YEAR from `payment_confirm`) = '2017' \n AND \n `orderer_id` NOT IN(1) \n AND \n `point_of_sale_id` NOT IN(1) \n GROUP BY \n orderer_id\n ,point_of_sale_id\n WITH ROLLUP \n ) AS sum; \n \n```\n\n**ビュー**\n\n```\n\n CREATE \n ALGORITHM = UNDEFINED \n DEFINER = `hironobu`@`localhost` \n SQL SECURITY DEFINER\n VIEW `vw_sales_budget` AS\n SELECT \n `ps`.`process_status_id` AS `process_status_id`,\n `so`.`orderer_id` AS `orderer_id`,\n `pos`.`point_of_sale_id` AS `point_of_sale_id`,\n `so`.`usually_grand_total` AS `usually_grand_total`,\n `so`.`custom_grand_total` AS `custom_grand_total`,\n `so`.`grand_consumption_tax_total` AS `grand_consumption_tax_total`,\n `so`.`payment_confirm` AS `payment_confirm`\n FROM\n (((`sales_order` `so`\n JOIN `processes_status` `ps` ON ((`so`.`processing_status_id` = `ps`.`process_status_id`)))\n JOIN `companys` `cp` ON ((`so`.`orderer_id` = `cp`.`company_id`)))\n JOIN `point_of_sales` `pos` ON ((`so`.`point_of_sale_id` = `pos`.`point_of_sale_id`)))\n WHERE\n (`so`.`processing_status_id` <> 8)\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T10:22:02.053", "favorite_count": 0, "id": "37662", "last_activity_date": "2017-09-01T13:04:09.687", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5731", "post_type": "question", "score": 0, "tags": [ "mysql", "sql", "database" ], "title": "条件が一致したとき、合計値を算出する", "view_count": 344 }
[ { "body": "以下のようなSQLで実現できると思います\n\n```\n\n SELECT\n CASE\n -- mysql は 集約関数外で 集約対象カラム を利用すると 値が1つランダムに手に入る\n -- (だいたい先頭の値、保証はなく実装依存)\n -- なので、店舗 + 店舗免税 の集約をしたカラムの point_of_sale_id は [2, 3] のどちらか\n -- キチンとする(PostgreSQLとかでも動くようにする)なら\n -- MAX(point_of_sale_id) AS point_of_sale_id_agg\n -- のようにする\n WHEN (`orderer_id`= 2 AND `point_of_sale_id`=2) OR\n (`orderer_id`= 2 AND `point_of_sale_id`=3) THEN 'F 社 - 店舗 + 店舗免税' \n WHEN (`orderer_id`= 2 AND `point_of_sale_id`=4) THEN 'F 社 - 国内通販' \n WHEN (`orderer_id`= 2 AND `point_of_sale_id`=5) THEN 'F 社 - 海外通販' \n WHEN (`orderer_id`= 2) THEN 'F 社 - 合計' \n WHEN (`orderer_id`= 3 AND `point_of_sale_id`=2) OR\n (`orderer_id`= 3 AND `point_of_sale_id`=3) THEN 'R 社 - 店舗 + 店舗免税' \n WHEN (`orderer_id`= 3 AND `point_of_sale_id`=4) THEN 'R 社 - 国内通販' \n WHEN (`orderer_id`= 3 AND `point_of_sale_id`=5) THEN 'R 社 - 海外通販' \n WHEN (`orderer_id`= 3) THEN 'R 社 - 合計' \n WHEN (`orderer_id`= 4 AND `point_of_sale_id`=2) OR\n (`orderer_id`= 4 AND `point_of_sale_id`=3) THEN 'C 社 - 店舗 + 店舗免税' \n WHEN (`orderer_id`= 4 AND `point_of_sale_id`=4) THEN 'C 社 - 国内通販' \n WHEN (`orderer_id`= 4 AND `point_of_sale_id`=5) THEN 'C 社 - 海外通販' \n WHEN (`orderer_id`= 4) THEN 'C 社 - 合計' \n END AS '発注元の会社 - 販売した場所' \n ,SUM(sum.`1月`)\n -- ...\n ,SUM(sum.`12月`)\n FROM (\n -- ...\n ) AS sum\n GROUP BY\n `orderer_id`,\n CASE point_of_sale_id\n WHEN 2 THEN 2 -- 店舗(店舗免税と同じ値)\n WHEN 3 THEN 2 -- 店舗免税(店舗と同じ値)\n ELSE point_of_sale_id -- それ以外\n END\n ;\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T13:04:09.687", "id": "37665", "last_activity_date": "2017-09-01T13:04:09.687", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9796", "parent_id": "37662", "post_type": "answer", "score": 1 } ]
37662
37665
37665
{ "accepted_answer_id": "37664", "answer_count": 1, "body": "Kotlinで下記のように、メンバ変数を委譲先にするとUnresolved reference: helloImplとなります。\n\n```\n\n interface IHello {\n fun hello()\n }\n \n class HelloImpl: IHello {\n override fun hello() {\n println(\"Hello\")\n }\n }\n \n class Hello: IHello by helloImpl {\n val helloImple = HelloImpl()\n }\n \n```\n\nbyの後ろで直接インスタンスを生成した場合や\n\n```\n\n class Hello: IHello by HelloImpl() {\n }\n \n```\n\nコンストラクタの引数を使用した場合はエラーになりません。\n\n```\n\n class Hello(val helloImpl: HelloImpl) : IHello by helloImpl {\n }\n \n```\n\nしかし、直接インスタンスを渡すと、委譲先のオブジェクトにアクセスできませんし、クラス内部で生成できるのでコンストラクタの引数にしたくもありません。 \nメンバ変数を委譲先にする方法はないのでしょうか?\n\nあるいは、`IHello by HelloImpl()`で生成したオブジェクトにアクセスする手段はないでしょうか?`this.HelloImpl`等で。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T10:23:17.860", "favorite_count": 0, "id": "37663", "last_activity_date": "2017-09-02T10:24:05.143", "last_edit_date": "2017-09-02T10:24:05.143", "last_editor_user_id": "17238", "owner_user_id": "17238", "post_type": "question", "score": 3, "tags": [ "kotlin" ], "title": "KotlinのClass Delegationでメンバ変数を委譲先にできないのはなぜ?", "view_count": 351 }
[ { "body": "メンバ変数を委譲先にする方法については[Class delegate using internal property - Language Design -\nKotlin Discussions](https://discuss.kotlinlang.org/t/class-delegate-using-\ninternal-property/1867)に同様の質問がありました。答えは「今のところは不可能」だそうです。\n\nリンク先にもあるように、コンストラクタの引数になっていることを隠す目的なら`private constructor`を使うことができます。\n\n```\n\n class Hello private constructor(val h: IHello) : IHello by h {\n constructor() : this(HelloImpl())\n }\n \n```\n\n**9月2日追記** \n`by`に続けて書く形で生成したオブジェクトへのアクセスついても[Access internally stored object used for\nclass delegation - Kotlin\nDiscussions](https://discuss.kotlinlang.org/t/access-internally-stored-object-\nused-for-class-delegation/2478)に同様の質問があり、やはり不可能だそうです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-01T11:34:18.407", "id": "37664", "last_activity_date": "2017-09-02T08:11:41.820", "last_edit_date": "2017-09-02T08:11:41.820", "last_editor_user_id": "13199", "owner_user_id": "13199", "parent_id": "37663", "post_type": "answer", "score": 4 } ]
37663
37664
37664
{ "accepted_answer_id": null, "answer_count": 0, "body": "[![main.storyboard](https://i.stack.imgur.com/sZozA.png)](https://i.stack.imgur.com/sZozA.png)\n\n現在、Point View というゲーム点数を表示するだけのViewを配置しています。 \nこの点数はTableView下にスクロールをしても常に表示したいと考えています。 \n(上から下にスクロールしたときも定位置で表示したい)\n\nしかし下記のようにしてもうまく動作できておりません。\n\n```\n\n import UIKit\n \n class TopTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, Calk {\n \n @IBOutlet var tableview: UITableView!\n @IBOutlet var pointView: UIView!\n @IBOutlet var dispPoint: UILabel!\n \n \n /* 中略 */\n \n /* スクロール時 */\n \n func scrollViewDidScroll(_ scrollView: UIScrollView) {\n \n pointView.frame = CGRect(x:0+scrollView.contentOffset.x, y:0, width:0, height:0)\n \n \n }\n \n```\n\n[![追従失敗](https://i.stack.imgur.com/p9IeC.png)](https://i.stack.imgur.com/p9IeC.png)\n\n上記画像のように、Viewが追従表示されないだけではなく \nViewのカラーがなくなり、上にずれてしまいます。 \n一体どのように改善すればよいのか、お手数ですがどなたかご回答をよろしくお願いします。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T03:07:57.267", "favorite_count": 0, "id": "37674", "last_activity_date": "2017-09-02T03:07:57.267", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23206", "post_type": "question", "score": 0, "tags": [ "xcode", "swift3", "uitableview", "uiscrollview" ], "title": "TableViewの中にViewを配置し、スクロールするとViewも追従して表示しつづけたい", "view_count": 725 }
[]
37674
null
null
{ "accepted_answer_id": "37708", "answer_count": 2, "body": "サーバー構築初心者で初歩的な質問かもしれませんがすいません。 \nーーーーーーーーーーーーーーーーーーーーー \n【サーバー情報】 \nCentOS release 6.8 (Final) \nx86_64(64bit) \nApache/2.2.15 (Unix) \nmysql Ver 14.14 Distrib 5.6.37 \nPHP 5.6.28 \nーーーーーーーーーーーーーーーーーーーーー\n\nPHPとmysqlをアップデートした後、改めてphpMyAdminを導入しようとしたのですが、 \n以下のコマンドで実行し、\n\n```\n\n yum install phpMyAdmin\n \n```\n\nエラーが以下のようにでてインストールできません\n\n```\n\n 121 packages excluded due to repository priority protections\n 依存性の解決をしています\n --> トランザクションの確認を実行しています。\n ---> Package phpMyAdmin.noarch 0:4.0.10.20-1.el6 will be インストール\n --> 依存性の処理をしています: php-tcpdf-dejavu-sans-fonts のパッケージ: phpMyAdmin-4.0.10.20-1.el6.noarch\n --> 依存性の処理をしています: php-tcpdf のパッケージ: phpMyAdmin-4.0.10.20-1.el6.noarch\n --> 依存性の処理をしています: php-php-gettext のパッケージ: phpMyAdmin-4.0.10.20-1.el6.noarch\n --> トランザクションの確認を実行しています。\n ---> Package php-php-gettext.noarch 0:1.0.12-1.el6 will be インストール\n ---> Package php-tcpdf.noarch 0:6.2.13-1.el6 will be インストール\n --> 依存性の処理をしています: php-tidy のパッケージ: php-tcpdf-6.2.13-1.el6.noarch\n --> 依存性の処理をしています: php-bcmath のパッケージ: php-tcpdf-6.2.13-1.el6.noarch\n ---> Package php-tcpdf-dejavu-sans-fonts.noarch 0:6.2.13-1.el6 will be インストール\n --> トランザクションの確認を実行しています。\n ---> Package php-bcmath.x86_64 0:5.3.3-49.el6 will be インストール\n --> 依存性の処理をしています: php-common(x86-64) = 5.3.3-49.el6 のパッケージ: php-bcmath-5.3.3-49.el6.x86_64\n ---> Package php-tidy.x86_64 0:5.3.3-49.el6 will be インストール\n --> 依存性の処理をしています: php-common(x86-64) = 5.3.3-49.el6 のパッケージ: php-tidy-5.3.3-49.el6.x86_64\n --> 依存性解決を終了しました。\n エラー: パッケージ: php-bcmath-5.3.3-49.el6.x86_64 (base)\n 要求: php-common(x86-64) = 5.3.3-49.el6\n インストール: php-common-5.6.28-1.el6.remi.x86_64 (@remi-php56)\n php-common(x86-64) = 5.6.28-1.el6.remi\n 利用可能: php-common-5.3.3-49.el6.x86_64 (base)\n php-common(x86-64) = 5.3.3-49.el6\n 利用可能: php56u-common-5.6.31-1.ius.el6.x86_64 (ius)\n php-common(x86-64) = 5.6.31-1.ius.el6\n 利用可能: php70u-common-7.0.22-2.ius.el6.x86_64 (ius)\n php-common(x86-64) = 7.0.22-2.ius.el6\n 利用可能: php71u-common-7.1.8-2.ius.el6.x86_64 (ius)\n php-common(x86-64) = 7.1.8-2.ius.el6\n エラー: パッケージ: php-tidy-5.3.3-49.el6.x86_64 (base)\n 要求: php-common(x86-64) = 5.3.3-49.el6\n インストール: php-common-5.6.28-1.el6.remi.x86_64 (@remi-php56)\n php-common(x86-64) = 5.6.28-1.el6.remi\n 利用可能: php-common-5.3.3-49.el6.x86_64 (base)\n php-common(x86-64) = 5.3.3-49.el6\n 利用可能: php56u-common-5.6.31-1.ius.el6.x86_64 (ius)\n php-common(x86-64) = 5.6.31-1.ius.el6\n 利用可能: php70u-common-7.0.22-2.ius.el6.x86_64 (ius)\n php-common(x86-64) = 7.0.22-2.ius.el6\n 利用可能: php71u-common-7.1.8-2.ius.el6.x86_64 (ius)\n php-common(x86-64) = 7.1.8-2.ius.el6\n 問題を回避するために --skip-broken を用いることができません\n これらを試行できます: rpm -Va --nofiles --nodigest\n \n```\n\nアドバイスをいただけるとありがたく存じます\n\n追記:お返事ありがとうございます \nyum repolistを実行してみた結果ですm(_ _)m\n\n```\n\n 読み込んだプラグイン:fastestmirror, priorities, security\n Loading mirror speeds from cached hostfile\n epel/metalink | 6.6 kB 00:00 \n * base: ftp.iij.ad.jp\n * epel: ftp.riken.jp\n * extras: ftp.iij.ad.jp\n * ius: hkg.mirror.rackspace.com\n * remi-safe: mirrors.mediatemple.net\n * updates: ftp.iij.ad.jp\n base | 3.7 kB 00:00 \n extras | 3.4 kB 00:00 \n ius | 2.3 kB 00:00 \n mysql-connectors-community | 2.5 kB 00:00 \n mysql-tools-community | 2.5 kB 00:00 \n mysql56-community | 2.5 kB 00:00 \n remi-safe | 2.9 kB 00:00 \n updates | 3.4 kB 00:00 \n 121 packages excluded due to repository priority protections\n リポジトリー ID リポジトリー名 状態\n base CentOS-6 - Base 6,706\n epel Extra Packages for Enterprise Linux 6 - x86_64 12,269+111\n extras CentOS-6 - Extras 45\n ius IUS Community Packages for Enterprise Linux 6 - x86_64 406+1\n mysql-connectors-community MySQL Connectors Community 34+8\n mysql-tools-community MySQL Tools Community 51\n mysql56-community MySQL 5.6 Community Server 377\n remi-safe Safe Remi's RPM repository for Enterprise Linux 6 - x86_64 2,179+1\n updates CentOS-6 - Updates \n \n```\n\n追記2:ありがとう御座いましたm(_ _)m \n解決いたしました \nもっとリポジトリについて学びたいと思います", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T03:51:29.260", "favorite_count": 0, "id": "37675", "last_activity_date": "2017-09-04T23:04:13.470", "last_edit_date": "2017-09-04T23:04:13.470", "last_editor_user_id": "25165", "owner_user_id": "25165", "post_type": "question", "score": 0, "tags": [ "centos", "phpmyadmin", "yum" ], "title": "centOS6.8にphpMyAdminをyumでインストールしたさいのエラー", "view_count": 2903 }
[ { "body": "php-5.6.28 をインストールした際、remi, remi-php56 リポジトリを有効にして yum install したのではありませんか?\n\n```\n\n yum --enablerepo=remi-php56 --enablerepo=remi install phpMyAdmin\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T06:20:26.523", "id": "37691", "last_activity_date": "2017-09-03T06:20:26.523", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4603", "parent_id": "37675", "post_type": "answer", "score": 1 }, { "body": "CentOSはRHELをベースにしているため、標準でインストール出来るパッケージは安定性を重視しており \n必ずしも各アプリケーションの\"最新版\"とは限りません。\n\n<http://vault.centos.org/6.8/os/x86_64/Packages/php-5.3.3-47.el6.x86_64.rpm>\n\nCentOS 6.8向けのPHPはv5.3.3が提供されていますが、より新しいバージョン(v5.6.28)に更新するため \nREMIリポジトリからインストールしたのだと思います。\n\nREMIリポジトリでは最新のバージョンが利用できる反面、CentOS本来のリポジトリにあるパッケージと \nコンフリクト(衝突)を起こす可能性があるため、必要時のみ有効にしての利用が推奨されています。\n\n今回の場合であれば以下の様に再度REMIリポジトリのみを有効にした状態でphpMyAdminパッケージの \nインストールを試してみてください。\n\n```\n\n # yum --disablerepo=\\* --enablerepo=remi,remi-php56 update\n # yum --disablerepo=\\* --enablerepo=remi,remi-php56 install phpMyAdmin\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T06:44:59.613", "id": "37708", "last_activity_date": "2017-09-04T06:44:59.613", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "37675", "post_type": "answer", "score": 0 } ]
37675
37708
37691
{ "accepted_answer_id": null, "answer_count": 2, "body": "機械学習のために大量に画像を保存したいんですがWeb上の画像を一気に保存する方法や効率よく保存する方法はありませんか? \nMacを使っています。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T08:00:03.623", "favorite_count": 0, "id": "37676", "last_activity_date": "2017-09-03T22:52:41.803", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23690", "post_type": "question", "score": -1, "tags": [ "画像", "機械学習" ], "title": "Web上の画像を一気に保存する方法はありませんか?", "view_count": 384 }
[ { "body": "質問が漠然としているので回答も漠然としたものになります.\n\n一般に我々は画像の場所を知ることができます.さらに画像の場所がわかれば我々はそれを保存することができます.したがって欲しいたくさんの画像の場所をそれぞれ知ることができれば,それを順に保存して行くことができるでしょう.\n\n画像を取りに行く先の取得に関しては様々な手段があります.例えば flickr は 検索ができる\n[api](https://www.flickr.com/services/api/flickr.photos.search.html)\nを整備しているのでこういったものを使ってもいいでしょう.何らかのサイトで表示されている画像を集めたいならいわゆるスクレイピングの範疇になるかもしれません.とにかく色々な方法で,欲しい画像たちの\nurl を手に入れましょう.\n\n保存に関してはそれこそ言語ごとに様々な書きようがあります.簡単には `wget` や `curl` を呼びだせばよいでしょうし,たとえば python なら\n[`urllib.request.urlretrieve`](https://docs.python.org/3/library/urllib.request.html#urllib.request.urlretrieve)\nのような便利な関数もあります.この時,大量のリクエストを一度に投げるのは非常に行儀の悪い(そして場合によってはより具体的に問題になる)ことですので,適当に間隔を空けながら順にダウンロードしていくことになると思います.\n\n* * *\n\nとはいうものの,機械学習を試してみるのが目的であればふつうは公開されているデータセットを使うのが一番というようにも思います(画像の選定,いらんものが入ってないかの確認,必要ならアノテーションの付加,そういう重要な手間が全部省けます).何か入門書をお使いならしばしばおすすめのデータセットが載っています.手書きの数字認識では\n[MNIST](http://yann.lecun.com/exdb/mnist/) が有名で,google\nも[なんかやっているみたい](https://research.googleblog.com/2016/09/introducing-open-\nimages-dataset.html) ですし,英語版 wikipedia\nに[一覧記事](https://en.wikipedia.org/wiki/List_of_datasets_for_machine_learning_research)もあるようです.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T07:19:52.453", "id": "37693", "last_activity_date": "2017-09-03T07:19:52.453", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2901", "parent_id": "37676", "post_type": "answer", "score": 3 }, { "body": "一般論として実装方法や作法を一通り説明すると本一冊必要になります。\n\nピンポイントな本がありますので紹介しておきます。\n\n * Rubyによるクローラー開発技法 ISBN 4797380357\n * Pythonクローリング&スクレイピング ISBN 4774183679\n\n読んだわけではないので内容は保証できません。また同テーマの本はほかにもあります。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T22:52:41.803", "id": "37701", "last_activity_date": "2017-09-03T22:52:41.803", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5793", "parent_id": "37676", "post_type": "answer", "score": 2 } ]
37676
null
37693
{ "accepted_answer_id": "37681", "answer_count": 1, "body": "現在、uuid-by-stringを使用しています。 \nuuid-by-stringを使用すると、基本的には被らないuuidが作成されるのですが\n\n```\n\n const getUUID = require('uuid-by-string');\n console.log(\"おっぱい:\"+getUUID(\"おっぱい\"));\n console.log(\"ちっぱい:\"+getUUID(\"ちっぱい\"));\n \n```\n\nとすると、何故かuuidが被って、どちらも同じidで\n\n```\n\n おっぱい:A8BE6F3B-3DED-4879-8A0B-4705EEBAF673\n ちっぱい:A8BE6F3B-3DED-4879-8A0B-4705EEBAF673\n \n```\n\nが生成されてしまうみたいです。 \n例が下品な単語ですみません…。 \n日本語には対応していないのでしょうか? \n他に何か日本語文字列から、固有の英数字idを生成する方法はないでしょうか?", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T08:29:02.567", "favorite_count": 0, "id": "37677", "last_activity_date": "2017-09-02T15:20:04.210", "last_edit_date": "2017-09-02T15:20:04.210", "last_editor_user_id": "3054", "owner_user_id": "22541", "post_type": "question", "score": 3, "tags": [ "javascript", "node.js" ], "title": "Node.jsで特定の文字列から固有のidを作成する方法について", "view_count": 1767 }
[ { "body": "> 他に何か日本語文字列から、固有の英数字idを生成する方法はないでしょうか?\n\n大きく分けると、ハッシュ値を使う方法と、ASCII の範囲に収まる方式でエンコードする方法があります。 \nハッシュ値を使う方法は、文字列が長くても得られる ID の長さを一定に出来ます。 \nしかし、元の文字列が長すぎなければ、エンコードしてそのまま ID に使えるかも知れません。\n\n(UUID の例には[`uuid` モジュール](https://github.com/kelektiv/node-uuid)を使用しています。`uuid-\nby-string` というモジュールより信頼できると思います)\n\n```\n\n \"use strict\"\n \n // ハッシュ値の16進表記\n const crypto = require(\"crypto\")\n function mkhash(str) {\n //const hash = crypto.createHash(\"md5\")\n //const hash = crypto.createHash(\"sha1\")\n const hash = crypto.createHash(\"sha256\")\n hash.update(str)\n return hash.digest(\"hex\")\n }\n console.log(\"hash: \", mkhash(\"やかん\"))\n \n // UUID v5(sha1 のハッシュ値を用いて生成する方式)\n // npm install uuid\n const uuidv5 = require(\"uuid/v5\")\n const NAMESPACE_UUID = \"78fab293-e73b-482b-b3cb-a1982e48e870\" // 必要に応じて手元で生成\n console.log(\"uuidv5:\", uuidv5(\"やかん\", NAMESPACE_UUID))\n \n // 文字列の16進表記\n console.log(\"hex: \", new Buffer(\"やかん\").toString(\"hex\"))\n \n // 文字列の Base64 (英数字の他に記号 +,/,= が混じります)\n console.log(\"base64:\", new Buffer(\"やかん\").toString(\"base64\"))\n \n // 国際化ドメイン名の方式 (Punycode)\n const punycode = require(\"punycode\")\n console.log(\"puny: \", punycode.encode(\"やかん\"))\n \n // URI エンコード(パーセントエンコード)\n console.log(\"uri: \", encodeURIComponent(\"やかん\"))\n \n```\n\n出力:\n\n```\n\n hash: b640b4b18beb20bd80c031e1ef646c6fe2bdb336a292139814f01b8975d8c253\n uuidv5: 582878e9-c602-5e5b-a493-4a9365a16010\n hex: e38284e3818be38293\n base64: 44KE44GL44KT\n puny: u8j2fwb\n uri: %E3%82%84%E3%81%8B%E3%82%93\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T15:14:30.227", "id": "37681", "last_activity_date": "2017-09-02T15:14:30.227", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3054", "parent_id": "37677", "post_type": "answer", "score": 2 } ]
37677
37681
37681
{ "accepted_answer_id": null, "answer_count": 2, "body": "Raspberry初心者です。 \nCO2センサーの[MH-Z19](http://clima-\nsensor.ru/files/MH-Z19_Manual_V2.pdf)と[ラズパイ3モデルB](https://www.amazon.co.jp/gp/product/B01CHJRAL8/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1)をオスメスで繋ごうとしています。 \nただ、ラズパイGPIOの6番GNDとセンサー側のGND(7番)をつなぐと、ラズパイの電源が落ちてしまいます。 \nラズパイ側のGPIOにはジャンパーワイヤを繋ぎ、センサーには繋がない場合には電源は落ちません。 \n原因・対策として何が考えられるでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T12:12:54.953", "favorite_count": 0, "id": "37678", "last_activity_date": "2018-09-13T02:27:07.047", "last_edit_date": "2018-05-11T03:54:37.480", "last_editor_user_id": "3060", "owner_user_id": "25169", "post_type": "question", "score": 0, "tags": [ "raspberry-pi", "gpio", "センサー" ], "title": "Raspberry PiとCO2センサーのGNDを繋いだ際に電源が落ちてしまう現象", "view_count": 811 }
[ { "body": "電源や信号は接続せずに、GNDのみを接続するだけで電源が落ちるという事でしょうか。\n\nそうであればMH-Z19には問題はなく、ラズパイのGNDと思っている箇所がGNDではないと考えられます。 \n電源が落ちる理由は \n①電源の供給能力がオーバーするか、 \n②ラズパイのリセット端子がONとなるか、 \n③電源のイネーブル端子がOffとなる位しかないと思います。\n\nまずはあなたがGPIO6番と考えておられる端子が本当にGNDかを把握するため、 \nテスターでGND端子との抵抗値を測定してみてください。 \nすでに確認済であれば、 \nラズパイには複数のGND端子があるので、他の端子で同様の現象が発生するか \n確認して頂ければと思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T02:26:47.053", "id": "37686", "last_activity_date": "2017-09-03T02:26:47.053", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23008", "parent_id": "37678", "post_type": "answer", "score": 3 }, { "body": "MH-Z19 の GND と Vin は隣接していたと思いますがこれがピンのハンダ不良などでショートしているということはないでしょうか?\n確認してみてください。", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2018-09-13T00:43:02.667", "id": "48339", "last_activity_date": "2018-09-13T02:27:07.047", "last_edit_date": "2018-09-13T02:27:07.047", "last_editor_user_id": "19110", "owner_user_id": "30082", "parent_id": "37678", "post_type": "answer", "score": 1 } ]
37678
null
37686
{ "accepted_answer_id": null, "answer_count": 0, "body": "二人のシフトを管理できるiOSアプリを作成しようと考えています。 \nシステム構成的には、クライアントサイドはswift3で実装して、サーバサイドはgoからDBを操作しようと考えていました。\n\nそこで、DB設計をしていたのですが、二人のリレーションをどうやって定義すれば良いかという問題に当たりました。 \n僕が考えた候補は二つあり\n\n```\n\n CREATE TABLE `users` (\n `id` INTEGER AUTO_INCREMENT,\n `name` VARCHAR(255),\n `uuid` VARCHAR(255),\n PRIMARY KEY (`id`)\n );\n \n CREATE TABLE `pairs` (\n `id` INTEGER AUTO_INCREMENT,\n `user1_id` INTEGER,\n `user2_id` INTEGER,\n PRIMARY KEY (`id`),\n FOREIGN KEY (`user1_id`) REFERENCES `users`(`id`),\n FOREIGN KEY (`user2_id`) REFERENCES `users`(`id`)\n );\n \n```\n\nのようにユーザ間のリレーションを定義するテーブルを作成するか、\n\n```\n\n CREATE TABLE `users` (\n `id` INTEGER AUTO_INCREMENT,\n `name` VARCHAR(255),\n `uuid` VARCHAR(255),\n `partner_id` INTEGER,\n PRIMARY KEY (`id`),\n FOREIGN KEY (`partner_id`) REFERENCES `users`(`id`)\n );\n \n```\n\nのように一つのテーブルで自身のテーブルを参照する、という感じです。 \nどちらの方が扱い安く、スマートでしょうか? \nまた、もっといい設計があれば教えていただきたいです。 \nまた、iOSでデータベースを扱うのにはRealmが一般的だと思いますが、 \n複数のiOSの端末間で扱う場合はサーバを立ててDBを扱うやり方で大丈夫でしょうか? \nご回答お待ちしております。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T13:39:33.903", "favorite_count": 0, "id": "37679", "last_activity_date": "2017-09-02T13:39:33.903", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25172", "post_type": "question", "score": 1, "tags": [ "swift", "mysql", "sql", "database" ], "title": "ユーザ同士を関連づけるDB設計", "view_count": 339 }
[]
37679
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "httpd.confのDocumentRootを`/srv/http/example`に変更し、ディレクトリ内にはindex.phpがあります。 \nIPアドレスは192.168.160.142が割り当てられています。 \nホストOSのWindowsからのみ`http://192.168.160.142`でアクセスが可能です。 \nこの状態から`http://example.com`でアクセスできるようにすべく、以下のことを試しました。\n\n 1. httpd.confに`ServerName example.com:80`の行を追加\n 2. hostsに`192.168.160.142 example.com`の行を追加\n 3. `hostname example.com`で一時的にホストネームを変更\n\nしかし、ブラウザにはサーバーが見つかりませんと表示されます。 \n解決策がありましたらご教授をお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T14:52:27.780", "favorite_count": 0, "id": "37680", "last_activity_date": "2017-09-04T02:31:05.333", "last_edit_date": "2017-09-04T02:31:05.333", "last_editor_user_id": "2238", "owner_user_id": "25173", "post_type": "question", "score": 0, "tags": [ "linux", "apache", "vmware" ], "title": "Windows上のVMware Workstation 12 Playerで立てたサーバー(Linux, Apache)にドメインを使ってアクセスしたい", "view_count": 235 }
[ { "body": "単にホストOS(Windows)からだけアクセス出来ればよいのなら、Windowsのhostsファイルにエントリを追加してやればいいと思います。Windowsのバージョンによってファイルの保存場所が異なるので確認してください。\n\n`192.168.160.142 hogehoge.com`\n\nhttpd.confのServerNameで設定したものはあくまでApache側での処理に使用するもので、Windows側には伝わりません(詳細は割愛しますがApacheのホスト名を設定するための項目でもありません)。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-02T15:52:33.823", "id": "37683", "last_activity_date": "2017-09-02T15:52:33.823", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "37680", "post_type": "answer", "score": 1 } ]
37680
null
37683
{ "accepted_answer_id": "37703", "answer_count": 2, "body": "EC2インスタンスでパブリックDNSというものがあります、 \nたとえばそれをブラウザのURLで指定すればインターネット上からアプリケーションにアクセスできたり、 \nssh先に設定できたり。\n\nここで疑問です。 \nパブリックDNSという名前はどう解釈すればいいのでしょうか。 \n先述の使い方では、ホスト名になっていて、それにアクセスするとインスタンスまでいきつけるという役割になってるかと思いますが、そもそもDNSはホストとIPをマッピングするものです。\n\nパブリックホストならしっくりくるのですが、パブリックDNSとはパブリックにだれてもアクセスできるDNSという意味に解釈できて、今ネーミングに違和感を感じます。\n\nAWSの人しかわからんよ、、とか言われるかもですがわかる方がいればご回答をお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T03:19:27.880", "favorite_count": 0, "id": "37688", "last_activity_date": "2017-09-04T00:57:36.290", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25065", "post_type": "question", "score": 0, "tags": [ "aws" ], "title": "AWSにおけるパブリックDNSという概念について", "view_count": 8849 }
[ { "body": "[Amazon EC2 インスタンスの IP\nアドレッシング](http://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/using-\ninstance-addressing.html)には\n\n> * プライベート IPv4 アドレスと内部 DNS ホスト名\n> * パブリック IPv4 アドレスと外部 DNS ホスト名\n>\n\nと表現されていて、厳密には「パブリックDNS」という表現はされていません。\n\nコンソールは確かに **パブリック DNS (IPv4)** という表記になっていますが、説明ツールチップには\n\n> インスタンスのパブリックホスト名により、インスタンスのパブリック IP アドレスまたは Elastic IP アドレスが解決されます。\n\nと説明されていて「パブリックDNS」は俗称のように感じました。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T05:41:40.283", "id": "37690", "last_activity_date": "2017-09-03T05:41:40.283", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "4236", "parent_id": "37688", "post_type": "answer", "score": 0 }, { "body": "VPCのドキュメントで用語の説明がされています。\n\n[VPC での DNS の使用 - Amazon Virtual Private\nCloud](http://docs.aws.amazon.com/ja_jp/AmazonVPC/latest/UserGuide/vpc-\ndns.html)\n\n> DNS ホスト名\n>\n> デフォルト VPC 内にインスタンスを起動すると、パブリック IPv4 アドレスとプライベート IPv4 アドレスに対応するパブリック DNS\n> ホスト名およびプライベート DNS ホスト名がインスタンスに割り当てられます。デフォルト以外の VPC 内にインスタンスを起動すると、プライベート\n> DNS ホスト名がインスタンスに割り当てられ、VPC に指定した DNS 属性に応じて、およびインスタンスにパブリック IPv4\n> アドレスがある場合、パブリック DNS ホスト名が割り当てられる可能性があります。\n>\n> Amazon が提供するプライベート (内部) DNS ホスト名はインスタンスのプライベート IPv4 アドレスに解決され、ip-private-\n> ipv4-address.ec2.internal の書式が us-east-1 リージョンに使用され、ip-private-\n> ipv4-address.region.compute.internal の書式が (private.ipv4.address が逆引きルックアップ\n> IP アドレスとなっている) 他のリージョンに使用されます。プライベート DNS\n> ホスト名は、同じネットワーク内のインスタンス間の通信に使用できます。ただし、インスタンスが含まれるネットワークの外部の DNS\n> ホスト名を解決することはできません。\n>\n> パブリック (外部) DNS ホスト名には、us-east-1 リージョンには ec2-public-\n> ipv4-address.compute-1.amazonaws.com 書式、その他のリージョンには ec2-public-\n> ipv4-address.region.amazonaws.com 書式が使用されます。パブリック DNS\n> ホスト名を解決すると、インスタンスのパブリック IPv4 アドレス (インスタンスのネットワークの外部の場合) およびインスタンスのプライベート\n> IPv4 アドレス (インスタンスのネットワーク内からの場合) となります。\n>\n> IPv6 アドレスの DNS ホスト名は付与されません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T00:57:36.290", "id": "37703", "last_activity_date": "2017-09-04T00:57:36.290", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "37688", "post_type": "answer", "score": 0 } ]
37688
37703
37690
{ "accepted_answer_id": "37699", "answer_count": 1, "body": "タイマーで0.01秒ごとに数字を1増やし、その数字をキーとして辞書から取り出した値をUILabelに表示するというアプリを作りました。が、ラベルにアニメーションをつけたところ、それも0.01秒ごとに実行されてしまい、ラベルが点滅したりしてしまいます。\n\n```\n\n override func viewDidLoad() {\n super.viewDidLoad()\n timer = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(labelUpdate), userInfo: nil, repeats: true)\n }\n \n func labelUpdate() {\n testInt += 1\n if let label = testDict[testInt] {\n let anime = CATransition()\n anime.type = kCATransitionMoveIn\n anime.subtype = kCATransitionFromBottom\n anime.duration = 0.2\n testLabel.layer.add(anime, forKey: nil)\n testLabel.text = label\n }\n }\n \n```\n\n辞書のキーは毎回異なるのでこのように、キーがnilでないときにラベルを更新という処理にしたのですが、nilのときにもanimeが実行されているようです・・・ \n変更するときのみ、アニメーションしてくれればそれでいいのですが・・・\n\n \n \n**追記** \n辞書は例えば`var testDict = [1: \"りんご\", 200:\"バナナ\", 470:\"卵\"]`のようなものです。 \ntestIntは任意のタイミングでUIButtonでリセットします。\n\n理想は上記の例で言えば\"りんご\"から\"バナナ\"に変更されるときに1度だけアニメーションするというものです。\n\n今のままで実行すると、\"りんご\"や\"バナナ\"と表示されたUILabelが点滅したあとに突然指定したアニメーションをしたり、\"りんご\"という文字が点滅した文字の下にもう一つ現れてそこに点滅している文字に重なったりと、正しい動きではないと思われる動きになってしまいます。\n\n \n \n**さらに追記** \n再度、確認させてもらったところ、 \n点滅したり文字が重なったりということは起こらず、ただアニメーションに関するコードが全くないかのように普通に文字が入れ替わるという動作になってしまいました。\n\n \n \n**コード追加**\n\n```\n\n var testDict = [\"00:01\": \"りんご\", \"00:05\":\"バナナ\", \"00:07\":\"卵\"]\n func labelUpdate() {\n let min = Int(player.currentPlaybackTime) / 60\n let sec = Int(player.currentPlaybackTime.truncatingRemainder(dividingBy: 60))\n timeKey = String(format: \"%02d:%02d\", min, sec)\n //この部分が問題でした。大変申し訳ございません\n if let label = testDict[timeKey] {\n let anime = CATransition()\n anime.type = kCATransitionMoveIn\n anime.subtype = kCATransitionFromBottom\n anime.duration = 0.2\n testLabel.layer.add(anime, forKey: nil)\n testLabel.text = label\n }\n }\n \n```\n\ntimerを0.01秒ごとにしたのはmm:ssが実際の再生中の曲の再生時間と同期するためです。 \ncurrentPlaybackTimeが1秒増えるタイミングとtimerで更新しているmm:ssの値がずれてしまうとコンマ数秒単位でずれてしまうので・・・\n\nしかしこのせいで、testDict[timeKey]がnilでないときの処理が0.01x100回実行されてしまうようです。\n\n点滅するのは100回MoveInが実行されるため。 \n重なって表示されるのは次の秒数になった瞬間、testLabel.text = labelが保持されたまま0.2秒かけてアニメーションも実行されたためでした。\n\n本当に申し訳ない話ですが、ここまで気がつきませんでした。\n\n見た目では問題なかった(気がつかなかった)のですが、こうなるとtestLabel.text =\nlabelも100回繰り返されていることになっていますよね・・・。 \nその場合、どうしたらいいのでしょうか。 \n今は辞書キーがnilじゃなかったら更新を1秒に100回繰り返していますが、 \n1度変わってしまえば残り99回は必要ありませんし、そうすればアニメーションも正常に機能すると思うのです・・・。\n\nつまり、\n**辞書キーがnilじゃないとき、1度のみUILabelの表示を更新してそのときアニメーションを実行、また別のキーと値が取り出せたらそれも一回のみUILabelの表示の更新とアニメーション**\nという処理をしたいということでした。", "comment_count": 10, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T07:01:11.687", "favorite_count": 0, "id": "37692", "last_activity_date": "2017-09-03T13:43:47.810", "last_edit_date": "2017-09-03T12:29:48.100", "last_editor_user_id": "25183", "owner_user_id": "25183", "post_type": "question", "score": 0, "tags": [ "ios", "swift3", "ios10" ], "title": "CATransitionとタイマー", "view_count": 96 }
[ { "body": "すでにご質問の中で根本的な原因が記載されていますが、秒部分までをキーとして0.01秒ごとに一致するキーがあるかどうかをチェックしているので、時間が一致している間の1秒間、およそ100回アニメーションを実施している、という状態になっています。\n\nアニメーションの開始タイミングを`player`の現在再生時間(`currentPlaybackTime`)に同期させたいという要求があるようですので、適当な時間でポーリングを行うのは仕方ないところでしょうから、単純に「1回アニメーションを始めたら、時間が変わるまで次のアニメーションは始めない」と言うチェックを入れるのが、簡単で確実だろうと思います。\n\n(ちなみにポーリングの間隔は0.1秒程度でもほとんどの普通の人には違和感がないと思いますが。)\n\n```\n\n //最後にアニメーションしたタイミング\n var lastTimeKey = \"--:--\"\n \n func labelUpdate() {\n let min = Int(player.currentPlaybackTime) / 60\n let sec = Int(player.currentPlaybackTime.truncatingRemainder(dividingBy: 60))\n let timeKey = String(format: \"%02d:%02d\", min, sec)\n //タイミングが変わった時だけアニメーションすべきかどうかチェックを入れる\n if timeKey != lastTimeKey, let label = testDict[timeKey] {\n let anime = CATransition()\n anime.type = kCATransitionMoveIn\n anime.subtype = kCATransitionFromBottom\n anime.duration = 0.2\n testLabel.layer.add(anime, forKey: nil)\n testLabel.text = label\n \n //最後にアニメーションしたタイミングを覚えておく\n lastTimeKey = timeKey\n }\n }\n \n```\n\nもちろん`lastTimeKey`の値は`player.currentPlaybackTime`がリセットされるような操作をした場合には、再度初期値に戻しておく必要があります。\n\n他にももっと良い方法があるかもしれません。ご自身でより良い方法を見つけられた場合には、遠慮なさらず是非とも回答の形で投稿していただければと思います。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T13:43:47.810", "id": "37699", "last_activity_date": "2017-09-03T13:43:47.810", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "13972", "parent_id": "37692", "post_type": "answer", "score": 0 } ]
37692
37699
37699
{ "accepted_answer_id": null, "answer_count": 0, "body": "プロジェクトを複製する方法を検索すると \n[このサイト](http://kubou.net/archives/325)に行き着きますが、 \n全くコピーできません。\n\n具体的には \n2項でIdentity and Type > NameをRenameしたとき、スナップショットも促されませんし、代わりにworking copy xxxx\nhas uncommitted changed Xcode...という警告が出ます。 \n4項ではIdentity and Type >\nLocationにあるフォルダアイコンをクリックとありますが、アイコンが薄いグレーになっており、クリックもできませんし、Renameしなくても新しくなったディレクトリになっています。 \nもちろん.pchファイルも参照できません。\n\nちなみに4項の時点でwarningも6つ出ており、もちろんbuildもできません。", "comment_count": 5, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T07:55:26.493", "favorite_count": 0, "id": "37694", "last_activity_date": "2017-09-03T09:30:10.997", "last_edit_date": "2017-09-03T09:30:10.997", "last_editor_user_id": "19110", "owner_user_id": "25183", "post_type": "question", "score": 0, "tags": [ "swift3", "xcode8" ], "title": "Xcode8を使ったSwift3のプロジェクトをコピーする最新の方法を教えてください", "view_count": 389 }
[]
37694
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "```\n\n POST /v2/users/create HTTP/1.1\n Host: mixch.tv\n Connection: keep-alive\n X-Mixch-Country: jp\n X-Mixch-Attribution: Organic\n Accept: */*\n X-Mixch-AdvertisingId: A29428C7-8C02-419F-A071-E47E3DA184A9\n User-Agent: mixch/5.2.1 (iPhone; iOS 10.2; Scale/2.00)\n Accept-Language: ja-JP;q=1\n Accept-Encoding: gzip, deflate\n Content-Length: 262033\n Content-Type: multipart/form-data; boundary=Boundary+EF9D031E6AE26D0E\n \n --Boundary+EF9D031E6AE26D0E\n Content-Disposition: form-data; name=\"birth_year\"\n \n -1\n --Boundary+EF9D031E6AE26D0E\n Content-Disposition: form-data; name=\"nickname\"\n \n Hi\n --Boundary+EF9D031E6AE26D0E\n Content-Disposition: form-data; name=\"prefecture\"\n \n -1\n --Boundary+EF9D031E6AE26D0E\n Content-Disposition: form-data; name=\"file\"; filename=\"file.png\"\n Content-Type: image/jpeg\n \n ����\n \n```\n\nこれのmultipartのリクエストの送信の仕方を教えてください... \nPython2でお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T10:16:10.987", "favorite_count": 0, "id": "37696", "last_activity_date": "2017-09-05T12:06:49.067", "last_edit_date": "2017-09-05T12:06:49.067", "last_editor_user_id": "20532", "owner_user_id": "22925", "post_type": "question", "score": 0, "tags": [ "python" ], "title": "multipartのrequestsについてなのです", "view_count": 2817 }
[ { "body": "マニュアルにそのまんまのmultipartの例がありますよ。 \n<http://requests.readthedocs.io/en/latest/user/quickstart/#post-a-multipart-\nencoded-file>\n\n```\n\n import requests\n \n \n data = dict(\n birth_year=-1,\n nickname=\"Hi\",\n prefecture=-1,\n )\n \n files = dict(\n file=open('xxx.png', 'rb')\n )\n \n r = requests.post('http://localhost:8888', files=files, data=data)\n print(r.text)\n \n```\n\n別のターミナルで`nc -l\n8888`として実行すると、次の内容がPOSTされていることがわかります。BoundaryのIDは実行時に決まるランダムな文字列なので、値をきにする必要はありません。\n\n```\n\n $ nc -l 8888\n POST / HTTP/1.1\n Host: localhost:8888\n User-Agent: python-requests/2.18.1\n Accept-Encoding: gzip, deflate\n Accept: */*\n Connection: keep-alive\n Content-Length: 420\n Content-Type: multipart/form-data; boundary=177b060d764643c398b667b5841c06df\n \n --177b060d764643c398b667b5841c06df\n Content-Disposition: form-data; name=\"birth_year\"\n \n -1\n --177b060d764643c398b667b5841c06df\n Content-Disposition: form-data; name=\"nickname\"\n \n Hi\n --177b060d764643c398b667b5841c06df\n Content-Disposition: form-data; name=\"prefecture\"\n \n -1\n --177b060d764643c398b667b5841c06df\n Content-Disposition: form-data; name=\"file\"; filename=\"xxx.png\"\n \n \n --177b060d764643c398b667b5841c06df--\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-03T17:30:21.220", "id": "37700", "last_activity_date": "2017-09-03T17:30:21.220", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7837", "parent_id": "37696", "post_type": "answer", "score": 1 } ]
37696
null
37700
{ "accepted_answer_id": null, "answer_count": 0, "body": "Rにて,.xlsxファイルを編集するため,rJavaをインストールし,library(xlsx)を実行したところ,以下のようなエラーが表示されてしまします.\n\n```\n\n > library(xlsx)\n 要求されたパッケージ rJava をロード中です \n Unable to find any JVMs matching version \"(null)\".\n Error: package or namespace load failed for ‘rJava’:\n .onLoad は loadNamespace()('rJava' に対する)の中で失敗しました、詳細は: \n call: dyn.load(file, DLLpath = DLLpath, ...) \n error: 共有ライブラリ '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so' を読み込めません: \n dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib\n Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so\n Reason: image not found \n エラー: パッケージ ‘rJava’ をロードできませんでした \n 追加情報: 警告メッセージ: \n 命令 '/usr/libexec/java_home' の実行は状態 1 を持ちました \n No Java runtime present, try --request to install.\n \n```\n\nなお,実行環境はmacOS Sierra ver.10.12.5です. \n当方,プログラミング初学者のため,至らない点等多々あると思いますが,ご回答の方何卒よろしくお願いいたします.", "comment_count": 6, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T04:53:19.047", "favorite_count": 0, "id": "37705", "last_activity_date": "2017-09-04T05:43:50.890", "last_edit_date": "2017-09-04T05:43:50.890", "last_editor_user_id": "13199", "owner_user_id": "25195", "post_type": "question", "score": 0, "tags": [ "r" ], "title": "「エラー: パッケージ ‘rJava’ をロードできませんでした」の表示", "view_count": 2667 }
[]
37705
null
null
{ "accepted_answer_id": "52895", "answer_count": 2, "body": "Google Vault からメールデータを抽出またはダウンロードする \nプログラムを開発することは可能でしょうか。 \n公開されているAPIにはそのようなAPIは存在しないように見えます。\n\n宜しくお願いいたします。\n\n<https://developers.google.com/vault/>", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T06:14:25.720", "favorite_count": 0, "id": "37707", "last_activity_date": "2019-02-20T06:08:13.820", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25198", "post_type": "question", "score": 0, "tags": [ "google-api" ], "title": "APIなどを使用し、Google Vault からメールデータ取得したい", "view_count": 273 }
[ { "body": "使ったことは無いですがこれなんかどうです? \n<https://developers.google.com/vault/reference/rest/>", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T07:25:46.710", "id": "37727", "last_activity_date": "2017-09-05T07:25:46.710", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "18637", "parent_id": "37707", "post_type": "answer", "score": 0 }, { "body": "半年前から取得できるようになっています。 \n<https://developers.google.com/vault/guides/exports>", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2019-02-20T06:08:13.820", "id": "52895", "last_activity_date": "2019-02-20T06:08:13.820", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25198", "parent_id": "37707", "post_type": "answer", "score": 1 } ]
37707
52895
52895
{ "accepted_answer_id": "37977", "answer_count": 1, "body": "[![画像の説明をここに入力](https://i.stack.imgur.com/q3kKn.png)][1 \n] \n↑print(omg)の結果 \n画像の独自のデータセットを読み込もうとしています。 \n下記のコードの`img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))`でエラーがでました。 \n`data`\nというディレクトリの下にa,b,c,d,e,fというディレクトリがあってそのディレクトリに画像のファイルが大量に入っています。ファイルの拡張子はpngやjpegです。 \nデータセットの読み込みを教えていただければありがたいです。\n\n```\n\n import os\n import numpy as np\n import cv2\n import tensorflow as tf\n NUM_CLASSES = 6 #分類するクラス数\n IMG_SIZE = 28\n \n #画像のあるディレクトリ\n train_img_dirs = ['a', 'b', 'c', 'd', 'e', 'f']\n \n #学習画像データ\n train_image = []\n #学習データのラベル\n train_label = []\n for i, d in enumerate(train_img_dirs):\n # ./data/以下の各ディレクトリ内のファイル名取得\n files = os.listdir('Users/name/desktop/zissou/data/' + d)\n for f in files:\n # 画像読み込み\n img = cv2.imread('Users/name/desktop/zissou/data/' + d + '/' + f)\n # 1辺がIMG_SIZEの正方形にリサイズ\n img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))\n # 1列にして\n img = img.flatten().astype(np.float32)/255.0\n train_image.append(img)\n \n # one_hot_vectorを作りラベルとして追加\n tmp = np.zeros(NUM_CLASSES)\n tmp[i] = 1\n train_label.append(tmp)\n \n # numpy配列に変換\n train_image = np.asarray(train_image)\n train_label = np.asarray(train_label)\n \n```\n\nエラー内容\n\n```\n\n Traceback (most recent call last)\n <ipython-input-65-4ca319834c1e> in <module>()\n 6 img = cv2.imread('/Users/tadashintaro/desktop/zissou/data/' + d + '/' + f)\n 7 # 1辺がIMG_SIZEの正方形にリサイズ\n ----> 8 img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))\n 9 # 1列にして\n 10 img = img.flatten().astype(np.float32)/255.0\n \n error: /Users/jenkins/miniconda/1/x64/conda- bld/conda_1486587097465/work/opencv- 3.1.0/modules/imgproc/src/imgwarp.cpp:3229: error: (-215) ssize.area() > 0 in function resize** \n \n```\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/FpQ46.png)](https://i.stack.imgur.com/FpQ46.png)\n\n参照:<http://qiita.com/domkade/items/fc9903c2119fdfa9a234>", "comment_count": 10, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T08:36:57.737", "favorite_count": 0, "id": "37709", "last_activity_date": "2017-09-15T15:43:56.690", "last_edit_date": "2017-09-05T12:49:21.343", "last_editor_user_id": "23690", "owner_user_id": "23690", "post_type": "question", "score": 1, "tags": [ "python", "tensorflow" ], "title": "files = os.listdir('./data/' + d)でのエラーについて", "view_count": 872 }
[ { "body": "さてコメント欄で指摘されているように類似の質問があるとおり,とりあえず今のところ話題になっているメッセージからは読み込もうとしているファイルの中に空のものがあるのではないかというのが一番怪しいということにしましょう.というわけで\n\n### Q. フォルダ下にたくさんの画像ファイルらしきものがあるとき,その中から空のものを見つけるにはどうすればよいか.\n\n多分いちばん簡単なのは, Linux 上でしたら\n[`find`](https://www.gnu.org/software/findutils/manual/html_mono/find.html#Size)\nのようなコマンドを使うことですけれども,せっかくなので今あるコードをできるだけ再利用してみましょう. \n(ところで,\n質問する前に余分なコードはできるだけ省くようにすべきです.そうして初めて問題の所在が分かって正しいググり方も分かるということがあります.今回なら\ntensorflow 周りは一切要りませんし,`resize` を試みて困ってるわけですからそれ以降の処理も余分です)\n\nファイルごとに処理をしているところでこういう感じにできたら良さそうですね.\n\n```\n\n for f in files:\n # 画像読み込み\n img = cv2.imread('Users/name/desktop/zissou/data/' + d + '/' + f)\n # 空ファイルがあったら教えてもらう\n if is_empty(img):\n print(\"{} っていうディレクトリの{}っていうファイルが怪しい!\".format(d,f)) \n \n```\n\nでは空ファイルをどうみつけていくか.その前に空ファイルがどう扱われるか実験してみましょう. ターミナル(Bash を想定しています)で `$ touch\nempty.jpg` などで空のファイルを作っておいて\n\n```\n\n #!/usr/bin/env python3\n \n import cv2\n \n empty = cv2.imread('./empty.jpg')\n print(empty) # None\n cv2.resize(empty, (3,3)) # OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in resize, file /io/opencv/modules/imgproc/src/imgwarp.cpp, line 3483\n \n```\n\nいい感じにそれっぽいエラーがでること,空ファイルを読むと `None` が返されていることがわかります(ファイル名を間違えていても同様に `None`\nが返ってきます).というわけで\n\n```\n\n if img is None:\n \n```\n\nなどで判定を入れてみるのが良いだろうと思います.\n\n以下余談.\n\n* * *\n\n### そもそも不明なエラーが出てるけど原因を探りたい\n\nときというのは色々あると思いますが,エラーメッセージで検索する他に,今回でしたら例えばどのファイルで詰まってるのを知りたいとしましょう.僕ならこうします:\n\n```\n\n for f in files:\n # 画像読み込み\n img = cv2.imread('Users/name/desktop/zissou/data/' + d + '/' + f)\n try:\n img = cv2.resize(img, (IMG_SIZE, IMG_SIZE))\n except Exception as e:\n # うまく行かないときは報告\n print(e)\n print(\"{} っていうディレクトリの{}っていうファイルが怪しい!\".format(d,f)) \n \n```\n\n書捨て的なトライアルができるのはスクリプト言語の気軽なところなので,色々試してみるといいです.", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-15T15:38:21.573", "id": "37977", "last_activity_date": "2017-09-15T15:43:56.690", "last_edit_date": "2017-09-15T15:43:56.690", "last_editor_user_id": "2901", "owner_user_id": "2901", "parent_id": "37709", "post_type": "answer", "score": 0 } ]
37709
37977
37977
{ "accepted_answer_id": "37931", "answer_count": 1, "body": "Chainerを利用して、15入力3出力のニューラルネットワークを作成しようと思い、以下のコードを書きました。\n\n```\n\n # -*- coding:utf-8 -*-\n \n import numpy as np\n import chainer\n from chainer.datasets import tuple_dataset\n from chainer import Variable\n from chainer import Function, gradient_check, report, training, utils, \n Variable\n from chainer import datasets, iterators, optimizers, serializers\n from chainer import Link, Chain, ChainList\n import chainer.functions as F\n import chainer.links as L\n from chainer.training import extensions\n \n import csv\n \n batchsize = 10\n epoch = 20\n \n \n class NChain(Chain):\n \n def __init__(self):\n \n super(NChain, self).__init__()\n self.n_out = 3 # 出力数\n self.n_units = 8 # 中間層ノード数\n \n with self.init_scope():\n self.l1 = L.Linear(None, self.n_units)\n self.l2 = L.Linear(None, self.n_units)\n self.l3 = L.Linear(None, self.n_out)\n \n def __call__(self, x):\n \n h1 = F.relu(self.l1(x))\n h2 = F.relu(self.l2(h1))\n y = self.l3(h2)\n return y\n \n \n class datasets():\n def get_data():\n train_data = [] # trainデータを格納\n train_enr = [] # trainの格納時に利用(15個で一つのデータのため)\n label_data = [] # 教師データ\n dataset_number = 0 # データ総数を格納\n \n # ファイル読み込み(./answer.csv)\n csvfile = './answer.csv'\n f = open(csvfile, \"r\")\n reader = csv.reader(f)\n # ヘッダーを読み飛ばす\n header = next(reader)\n \n # 教師データの作成\n for row in reader:\n # 入力\n if(len(row) - 1 == 5):\n for i in range(5):\n train_enr.append(float(row[i]))\n if(len(train_enr) == 15):\n train_data.append(\n Variable(np.array(train_enr, \n dtype='float32')))\n train_enr = []\n # 出力\n elif(len(row) - 1 == 3):\n label_data.append(\n Variable(np.array([float(row[0]), float(row[1]), \n float(row[2])], dtype='float32')))\n \n # データ数を1カウント\n dataset_number += 1\n \n # データセットの8割をtrain, 2割をtest用にする\n threshold = int((dataset_number * 8) / 10)\n \n # Trainerで使えるように整形\n train = tuple_dataset.TupleDataset(\n train_data[0:threshold], label_data[0:threshold])\n \n test = tuple_dataset.TupleDataset(\n train_data[threshold:], label_data[threshold:])\n \n return train, test\n \n \n def main():\n \n model = NChain()\n \n optimizer = optimizers.Adam()\n optimizer.setup(model)\n \n # データセット読み込み\n train, test = datasets.get_data()\n \n train_iter = chainer.iterators.SerialIterator(train, batchsize)\n test_iter = chainer.iterators.SerialIterator(test, batchsize,\n repeat=False, \n shuffle=False)\n \n # Set up a trainer\n updater = training.StandardUpdater(train_iter, optimizer, \n device=None)\n trainer = training.Trainer(updater, (epoch, 'epoch'), \n out='result')\n \n trainer.extend(extensions.Evaluator(test_iter, model))\n trainer.extend(extensions.LogReport())\n trainer.extend(extensions.PrintReport(\n ['epoch', 'main/accuracy', 'validation/main/accuracy']))\n trainer.extend(extensions.ProgressBar())\n \n # Run the training\n trainer.run()\n \n \n if __name__ == '__main__':\n main()\n \n```\n\nしかし、今までデータセットを自前で作成したりTrainerを使ったことがなかったのですが、練習のために試してみたところ以下のようなエラーが出ました。\n\n```\n\n Traceback (most recent call last):\n File \"chainer_pl.py\", line 115, in <module>\n main()\n File \"chainer_pl.py\", line 111, in main\n trainer.run()\n File \"/usr/local/lib/python3.5/dist-\n packages/chainer/training/trainer.py\", line 296, in run\n update()\n File \"/usr/local/lib/python3.5/dist-\n packages/chainer/training/updater.py\", line 223, in update\n self.update_core()\n File \"/usr/local/lib/python3.5/dist-\n packages/chainer/training/updater.py\", line 234, in update_core\n optimizer.update(loss_func, *in_arrays)\n File \"/usr/local/lib/python3.5/dist-packages/chainer/optimizer.py\", \n line 527, in update\n loss = lossfun(*args, **kwds)\n TypeError: __call__() takes 2 positional arguments but 3 were given\n \n```\n\nどうやらTrainerのUpdateの際のエラーなようですが、解決方法が分かりません。 \nどなたかご教示いただけますでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T10:48:58.530", "favorite_count": 0, "id": "37711", "last_activity_date": "2017-10-15T12:53:53.240", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": 0, "tags": [ "python", "機械学習", "chainer", "ニューラルネットワーク" ], "title": "ChainerのTrainer実行時にエラーが出る", "view_count": 2651 }
[ { "body": "こんにちは。 \nNChainを定義して、モデルを読み込むときに損失関数が組み込まれていないため、 \nUpdaterがバックプロップ出来ないのではないでしょうか? \n具体的な損失関数はわかりませんが、例えば、softmax cross entropyで分類する場合、 \nmodel = NChain() \nではなく、 \nmodel = L.Classifier(NChain()) \nで解決すると思います。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-13T14:52:00.053", "id": "37931", "last_activity_date": "2017-09-13T14:52:00.053", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25369", "parent_id": "37711", "post_type": "answer", "score": 1 } ]
37711
37931
37931
{ "accepted_answer_id": "37714", "answer_count": 1, "body": "WindowsフォームアプリケーションからODP.NET等で直接データベース(Oracle)に接続する場合とWCF経由でデータベースにアクセスする場合では、前者のほうがパフォーマンスは高いでしょうか? \n(WCF経由の場合はWCFのサービスがデータベースにアクセスします。)\n\nWCF経由のほうが直感的には、パフォーマンスが低くなると考えております。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T11:57:35.773", "favorite_count": 0, "id": "37712", "last_activity_date": "2017-09-04T13:34:48.707", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "9228", "post_type": "question", "score": 0, "tags": [ "winforms", "wcf" ], "title": "Windows Form からデータベースにアクセスする場合のアーキテクト毎のパフォーマンスについて教えてください。", "view_count": 246 }
[ { "body": "一般論としては通信とWCFの初期化/出力にかかる時間だけ遅延します。ですが設計によって高速化が期待できる場合もあります。\n\nまず検索結果やデータの加工結果をWCFサービスのメモリ上にキャッシュする場合が考えられます。キャッシュを利用できれば2度目以降の処理はDBアクセス自体が不要になります。もちろんキャッシュされているデータがDBより古くなっている可能性もありますが、すべてのDB処理をWCFサービスを通して行うようにすれば更新時にキャッシュを破棄できます。\n\n上記のようにWCFサービスではWCF経由のDB更新が発生したかどうかを把握することができます。これによって数秒おきにDB更新の有無を検索するような処理を効率化することができますし、さらにはサーバーからのプッシュ配信に変更し、リアルタイムにクライアントを更新することも可能になります。\n\nまた1個の処理で.NETからDBに複数回アクセスする場合、クライアント⇔DBの往復通信時間×Nの待ち時間が発生します。もしWCF⇔DBの通信が高速であればWCFで処理を行った方が効率が良いことも考えられます。\n\nいずれにせよ漫然とWCFを導入しただけで高速化することは考えにくいので、サービスを挟むことで何ができるかを考えて、実際の構成に即した環境で検証した方が良いでしょう。余談ですがサービス経由でDBにアクセスする構成の最大のメリットは「DBのセキュリティ向上」だと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T13:34:48.707", "id": "37714", "last_activity_date": "2017-09-04T13:34:48.707", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5750", "parent_id": "37712", "post_type": "answer", "score": 1 } ]
37712
37714
37714
{ "accepted_answer_id": null, "answer_count": 0, "body": "Pythonでの画像表示について質問です。\n\n[![画像の説明をここに入力](https://i.stack.imgur.com/EPQ4K.png)](https://i.stack.imgur.com/EPQ4K.png)\n\nこの画像のような透過PNGの画像をデスクトップ上に、ウィンドウなしに、HUDのように表示させるには、どのようにすれば、よいでしょうか?\n\n完成イメージとしてはこのようなものです。 \n[![画像の説明をここに入力](https://i.stack.imgur.com/9Xnup.png)](https://i.stack.imgur.com/9Xnup.png)\n\nなお環境はmacOS Sierra、Python 3.6.1 (Anaconda)です。 \n外部のライブラリなどでも構いません。", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T12:59:02.710", "favorite_count": 0, "id": "37713", "last_activity_date": "2017-09-04T13:29:25.943", "last_edit_date": "2017-09-04T13:29:25.943", "last_editor_user_id": "25205", "owner_user_id": "25205", "post_type": "question", "score": 0, "tags": [ "python", "画像" ], "title": "Pythonでデスクトップに画像のみを表示する方法を教えてください。", "view_count": 676 }
[]
37713
null
null
{ "accepted_answer_id": null, "answer_count": 1, "body": "ラズベリーパイのカメラモジュールを使って画像を撮影したいのですが、ラズパイがカメラを認識せず動作しない状態にあります。いろいろサイトを当たったところ \n・カメラのsunnyラベルのところをクリック \n・カメラを再接続してみる \n・ラズパイを再起動してみる \nすべて試しましたが一向に変化がありません。カメラ自体はLEDが点灯しており電源供給はされているようですがそれ以外は動作していません。 \nどなたか解決法を教えてください。よろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T14:44:36.393", "favorite_count": 0, "id": "37716", "last_activity_date": "2018-06-16T06:41:46.440", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "19263", "post_type": "question", "score": 0, "tags": [ "raspberry-pi" ], "title": "ラズベリーパイカメラモジュールの接続について", "view_count": 1024 }
[ { "body": "OSはRaspbianをお使いかと思いますが、一応Raspbianのバージョンをご確認ください。2013-05-25-wheezy-\nraspbianより古いものでは、カメラモジュールに対応していません。さすがにそこまで古くないと思いますが、最近のものですと、2017-07-05-raspbian-\njessie か 2017-08-16-raspbian-stretch でしょうか。\n\n`sudo raspi-config` を実行すると、「Enable Camera」または「Interfacing\nOptions」という選択肢があると思います。そこで、カメラモジュールの有効/無効を切り替えます。\n\nカメラが有効になったら、`raspistill`というコマンドで撮影します。`/opt/vc/bin`にあると思います。`/opt/vc/bin/raspistill\n-o image.jpg`の様にに使います。コマンドの詳細については検索してください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T15:48:54.027", "id": "37717", "last_activity_date": "2017-09-04T15:48:54.027", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3337", "parent_id": "37716", "post_type": "answer", "score": 1 } ]
37716
null
37717
{ "accepted_answer_id": "37721", "answer_count": 1, "body": "`UITableView`にパンを認識させたいと思って`UIPanGestureRecognizer`を使ってみたのですが、それをしたらテーブルを上下にスクロールさせることができなくなってしまいました。\n\nこれを解消するためにGoogle検索をしたところ海外の質問に対する回答でで下のコードを記述すると良いと書いてありました。\n\n```\n\n override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {\n   if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {\n let translation = panGestureRecognizer.translation(in: superview)\n if fabs(translation.x) > fabs(translation.y) {\n return true\n }\n return false\n }\n return false\n }\n \n```\n\nが、これをどこに書いたら良いのかわかりません。 \nいろいろなところに試してみましたが、うまくいきません。 \nそもそもこれでうまくいくのかどうかもわかりません。\n\nどなたか教えてくださいませんか。\n\n以下テーブルを作っている私のコードです\n\n```\n\n var table = UITableView()\n \n extension ViewController: UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate {\n \n func equipList(_ notification: Notification) {\n \n //テーブル設定(省略)\n \n table.delegate = self\n table.dataSource = self\n \n let pan = UIPanGestureRecognizer(target: self, action: #selector(pan(_:)))\n pan.delegate = self\n table.addGestureRecognizer(pan)\n \n self.view.addSubview(table)\n \n }\n \n @objc(tableView:cellForRowAtIndexPath:) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n var cell = UITableViewCell()\n \n //セル設定(省略)\n \n return cell\n }\n func tableView(_ tableView: UITableView, numberOfSection section: Int) -> Int {\n return 0\n }\n func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n return 100\n }\n }\n \n```\n\nこれに\n\n```\n\n extension UITableView {\n open override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {\n print(gestureRecognizer)\n if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {\n let translation = panGestureRecognizer.translation(in: table)\n if fabs(translation.x) > fabs(translation.y) {\n print(\"A\")\n return true\n }\n print(\"B\")\n return false\n }\n print(\"C\")\n return false\n }\n }\n }\n \n```\n\nエラーが出なかったからこれかな?といった感じで記述してみたのですけれど、うまくいきません。 \n`gestureRecognizer`では`UIScrollViewPanGestureRecognizer`が呼ばれているようで。ちなみに全てBが返ってきて、スクロールはできません。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T19:39:46.923", "favorite_count": 0, "id": "37718", "last_activity_date": "2017-09-05T03:49:06.783", "last_edit_date": "2017-09-05T03:49:06.783", "last_editor_user_id": "21092", "owner_user_id": "19428", "post_type": "question", "score": 0, "tags": [ "ios", "xcode", "swift3", "uitableview" ], "title": "UITableViewにUIPanGestureRecognizerを使ってもスクロールできなくならないようにしたい。", "view_count": 901 }
[ { "body": "```\n\n extension UITableView {\n \n```\n\nの中ではなく、\n\n```\n\n extension ViewController: UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate {\n \n```\n\nの中に定義するのではダメでしょうか?\n\nイメージ的には\n\n```\n\n extension ViewController: UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate {\n func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {\n if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer {\n let translation = panGestureRecognizer.translation(in: panGestureRecognizer.view)\n if fabs(translation.x) > fabs(translation.y) {\n return true\n }\n return false\n }\n return false\n }\n \n ・・・\n \n```\n\nこういった感じです。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T01:14:43.933", "id": "37721", "last_activity_date": "2017-09-05T01:14:43.933", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "369", "parent_id": "37718", "post_type": "answer", "score": 0 } ]
37718
37721
37721
{ "accepted_answer_id": null, "answer_count": 1, "body": "```\n\n data<-read.csv(\"try.csv\",header=T)\n make.names(col.names, unique = TRUE)\n \n```\n\nでエラー: 'サno' に不正なマルチバイト文字があります \nと表示されます。文字のエンコーディングのために、\n\n```\n\n data<-read.csv(\"try.csv\",header=T,fileEncoding=\"utf-8\")\n \n```\n\nとした場合もエラーが発生します。どのように解決したらよいでしょうか。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-04T23:28:11.153", "favorite_count": 0, "id": "37719", "last_activity_date": "2020-02-20T06:02:45.367", "last_edit_date": "2017-09-05T04:03:34.440", "last_editor_user_id": "2383", "owner_user_id": "25207", "post_type": "question", "score": 0, "tags": [ "r", "csv" ], "title": "Rでcsvデータを読み込もうとすると、エラーが発生します。どう解決したらよいでしょうか。", "view_count": 3304 }
[ { "body": "CSVファイルを、テキストエディタなどで明示的にUTF-8に変換するか、あるいはお使いの環境がMacOSの場合は fileEncoding=\"CP932\"\nを指定してあげれば良いかと思います。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T00:28:02.010", "id": "37720", "last_activity_date": "2017-09-05T00:28:02.010", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25106", "parent_id": "37719", "post_type": "answer", "score": 1 } ]
37719
null
37720
{ "accepted_answer_id": "37768", "answer_count": 1, "body": "`@IBOutlet`で複数のボタンを追加しておくと、どれぞれにオートレイアウトの制約をつけることができますが、`@IBOutlet`なしでループでボタンを追加した場合、それぞれのボタンにオートレイアウトの制約をつける方法がわかりません。\n\n`@IBOutlet`を使わないのは、前もってボタンの数だけ`@IBOutlet var\nボタン名:UIButton!`を用意する必要があるとの理解からです。 \n使わない方がスッキリすると考えていることと、ボタンの数が変動するからです。\n\nテストにしているコードを記します。\n\nKeyboardExtentionでの作成において、オートレイアウトでの要素配置が必須ということで、オートレイアウトの制約を設定する必要があり、方法を探しております。\n\nどのように改良すべきか、別の方法の検討が必要なのか、ご提案や改善策をいただければ幸いです。 \nよろしくお願いいたします。\n\n```\n\n import UIKit\n \n class KeyboardViewController: UIInputViewController {\n \n @IBOutlet var nextKeyboardButton: UIButton!\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // Perform custom UI setup here\n self.nextKeyboardButton = UIButton(type: .system)\n \n self.nextKeyboardButton.setTitle(NSLocalizedString(\"Next Keyboard\", comment: \"Title for 'Next Keyboard' button\"), for: [])\n self.nextKeyboardButton.sizeToFit()\n self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false\n \n self.nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents)\n \n self.view.addSubview(self.nextKeyboardButton)\n \n self.nextKeyboardButton.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true\n self.nextKeyboardButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true\n \n print(\"1stViewController's viewDidLoad() is called)\", UIScreen.main.bounds.size)\n \n //ボタンの表示\n buttonIndicate()\n \n }\n \n override func updateViewConstraints() {\n super.updateViewConstraints()\n \n // Add custom view sizing constraints here\n // viewの高さ設定\n heightControl()\n }\n \n override func viewWillAppear(_ animated: Bool) {\n super.viewDidDisappear(animated)\n }\n \n override func viewDidAppear(_ animated: Bool) {\n super.viewDidAppear(animated)\n }\n \n override func viewWillLayoutSubviews() {\n super.viewWillLayoutSubviews()\n }\n \n override func viewDidLayoutSubviews() {\n super.viewDidLayoutSubviews()\n }\n \n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n // Dispose of any resources that can be recreated\n }\n \n override func textWillChange(_ textInput: UITextInput?) {\n // The app is about to change the document's contents. Perform any preparation here.\n }\n \n override func textDidChange(_ textInput: UITextInput?) {\n // The app has just changed the document's contents, the document context has been updated.\n var textColor: UIColor\n let proxy = self.textDocumentProxy\n if proxy.keyboardAppearance == UIKeyboardAppearance.dark {\n textColor = UIColor.white\n } else {\n textColor = UIColor.black\n }\n self.nextKeyboardButton.setTitleColor(textColor, for: [])\n }\n \n func heightControl(){\n var cgfHeight:CGFloat = 350.0\n let screenSize = UIScreen.main.bounds\n if screenSize.width>screenSize.height {\n // Landscape\n print(\"よこ\")\n cgfHeight = 300.0\n } else {\n // Portrait\n print(\"たて\")\n }\n print(\"vDA1\" , UIScreen.main.bounds.size , cgfHeight)\n let heightConstraintView = NSLayoutConstraint(item: self.view, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 0, constant: cgfHeight)\n //heightConstraintView.priority = 999.0\n view.addConstraint(heightConstraintView)\n }\n \n \n //ボタンの表示\n func buttonIndicate(){\n print(\"buttonIndicate\")\n for roop in 0...11 {\n //ボタンの横位置を決める\n let K_X:Double = 50.0 * Double(roop)\n let button:UIButton = UIButton()\n //サイズと場所を設定する\n button.frame = CGRect(x:K_X, y:10.0, width:24.0, height:20.0)\n //表示されるテキスト\n button.setTitle(String(roop), for: .normal)\n //文字をセンターにする\n button.titleLabel?.textAlignment = NSTextAlignment.center\n //フォントのサイズ指定\n button.titleLabel?.font = UIFont.systemFont(ofSize: 24.0)\n //テキストの色\n button.setTitleColor(UIColor.black, for: .normal)\n //バックグラウンドカラー\n button.backgroundColor = UIColor.green\n //タグ番号\n button.tag = roop\n button.restorationIdentifier = String(roop)\n //ボタンをタップした時に実行するメソッドを指定\n button.addTarget(self, action: #selector(btnPress(_:)), for:.touchUpInside)\n \n //viewにボタンを追加する\n self.view.addSubview(button)\n \n //おそらくここでオートレイアウトの設定をする?\n //ボタンの左端は、親ビューの左端からK_X+20ptの位置\n //self.button.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: CGFloat(K_X + 20)).isActive = true\n //ボタンの高さは50pt\n //self.button.heightAnchor.constraint(equalToConstant: 50.0).isActive = true\n }\n }\n \n func btnPress(_ sender: UIButton){\n print(sender.tag)\n }\n }\n \n```\n\n追記:`@IBOutlet var buttons:[UIButton] =\n[]`を使うと、`view.addSubview`した複数のものに、個別指定でアクセスできそうですが、オートレイアウトが効きません。\n\n```\n\n @IBOutlet var buttons:[UIButton] = []\n \n //ボタンの表示\n func buttonIndicate(){\n for roop in 0...11 {\n \n ....中略....\n \n buttons.append(button)\n }\n \n //viewにボタンを追加する\n for roop in 0...11{\n self.view.addSubview(buttons[roop])\n buttons[roop].leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: CGFloat(50 * roop)).isActive = true\n buttons[roop].heightAnchor.constraint(equalToConstant: 50.0).isActive = true\n buttons[roop].widthAnchor.constraint(equalTo: self.view.widthAnchor, multiplier: 0.15).isActive = true\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T02:55:28.500", "favorite_count": 0, "id": "37722", "last_activity_date": "2017-09-07T02:44:15.957", "last_edit_date": "2017-09-06T10:22:09.887", "last_editor_user_id": "10845", "owner_user_id": "10845", "post_type": "question", "score": 0, "tags": [ "swift", "ios" ], "title": "Swift コードで追加した複数のボタンにオートレイアウトの制約をつけたい", "view_count": 446 }
[ { "body": "以下のコードにおいて自己解決しました。\n\n```\n\n @IBOutlet var buttons:[UIButton] = []\n \n //ボタンの表示\n func buttonIndicate(){\n for roop in 0...11 {\n \n ....中略....\n \n //このあと追加する制約とコンフリクトさせないため\n button.translatesAutoresizingMaskIntoConstraints = false\n \n buttons.append(button)\n }\n \n //viewにボタンを追加する\n for roop in 0...11{\n self.view.addSubview(buttons[roop])\n //ボタンに制約の追加\n self.buttons[roop].leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: CGFloat(50 * roop)).isActive = true\n self.buttons[roop].heightAnchor.constraint(equalToConstant: 50.0).isActive = true\n self.buttons[roop].widthAnchor.constraint(equalTo: self.view.widthAnchor, multiplier: 0.15).isActive = true\n }\n }\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-07T02:44:15.957", "id": "37768", "last_activity_date": "2017-09-07T02:44:15.957", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "10845", "parent_id": "37722", "post_type": "answer", "score": 0 } ]
37722
37768
37768
{ "accepted_answer_id": "37736", "answer_count": 1, "body": "あるサーバの`yum`のリポジトリを変えたくなくて試験サーバでRPMをダウンロードすることを思いつきました。 \n`yum`の`downloadonly`でダウンロードしようとしたのですが、試験サーバでは幾つかのモジュールが既にインストールされていて`reinstall`を必要としていました。\n\n```\n\n パッケージ php-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-cli-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-common-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-gd-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-mbstring-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-mysqlnd-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-pdo-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-soap-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-tidy-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-xml-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n パッケージ php-5.6.31-1.el7.remi.x86_64 はインストール済みか最新バージョンです\n \n```\n\n`reintall`でダウンロードした後に`install`を実行したので全部ダウンロードできたのですが、 \nふと、下記のように両方指定出来ないものかと考えました。\n\n```\n\n yum install reinstall --setopt=protected_multilib=false --skip-broken --downloadonly --downloaddir=. --enablerepo=remi,remi-php56 php php-bcmath php-cli php-common php-dba php-devel php-embedded php-enchant php-fpm php-gd php-imap php-intl php-ldap php-mbstring php-mcrypt php-mysqlnd php-odbc php-pdo php-pear php-pecl-apc php-pecl-apc-devel php-pecl-memcache php-pgsql php-process php-pspell php-recode php-snmp php-soap php-tidy php-xml php-xmlrpc php-zts > yum_module_download.log\n \n```\n\n上記を走らせて見ると`reinstall`というモジュールを探しにいってしまうのですが、両方指定できる方法はないのでしょうか?", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T08:42:43.927", "favorite_count": 0, "id": "37728", "last_activity_date": "2017-09-05T13:38:56.567", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": null, "post_type": "question", "score": 1, "tags": [ "php", "yum" ], "title": "yumでinstallオプションと同時にreinstallオプションを使えるか", "view_count": 497 }
[ { "body": "`yum`コマンドの`install`または`reinstall`オプションは同時に指定することはできません。\n\n* * *\n\n本来やりたい事はrpmパッケージのダウンロードかと思われるので、もしそうであれば`yumdownloader`コマンドを試してみてください。 \n`yumdownloader`は`yum-utils`パッケージに含まれるコマンドなので、確認の上インストールしておきます。\n\n```\n\n $ yum install yum-utils -y\n $ which yumdownloader\n /usr/bin/yumdownloader\n \n```\n\n基本的にはパッケージ名を指定して実行するだけでカレントディレクトリにrpmパッケージをダウンロードすることができますが、他にも`--destdir\nDIR`で保存先の指定、`--resolve`で依存パッケージも合わせてダウンロードさせることができます。 \nパッケージ名はワイルドカードでも指定できるので、今回の例であれば以下のように実行するとよいでしょう。\n\n```\n\n $ yumdownloader --destdir /tmp --resolve php*\n \n```", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T13:38:56.567", "id": "37736", "last_activity_date": "2017-09-05T13:38:56.567", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3060", "parent_id": "37728", "post_type": "answer", "score": 3 } ]
37728
37736
37736
{ "accepted_answer_id": "37783", "answer_count": 2, "body": "html\n\n```\n\n <textarea id=\"blogContentInputArea\" class=\"form-control\"></textarea>\n <input type=\"button\" value=\"送信\" onclick=\"blogContribution();\" class=\"submitButton\"/>\n \n```\n\njavascript\n\n```\n\n function blogContribution()\n {\n var content = $(\"#blogContentInputArea\").val();\n $.post(`/blog/blogAdds`,{ content: content },\n (data) => {\n \n });\n }\n \n```\n\n上記のように、テキストエリアと、送信ボタンの2つがあるhtmlを作成し \njavascriptファイルを読み込んで、jQueryでテキストエリアの内容をpostで送ろうと思っています。\n\nhtmlに1行追加して、ファイル選択画面を付け、 \nテキストエリアの内容の送信と、ファイルの送信を同時に行いたいのですが \nどうすれば出来ますか?\n\n```\n\n <textarea id=\"blogContentInputArea\" class=\"form-control\"></textarea>\n <input type=\"file\" name=\"upfile\" value=\"\" class=\"fileuploader\"/>\n <input type=\"button\" value=\"送信\" onclick=\"blogContribution();\" class=\"submitButton\"/>\n \n```\n\nサーバ側では、Node.js + Expressを使用しています。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T11:00:47.940", "favorite_count": 0, "id": "37733", "last_activity_date": "2017-09-08T05:57:18.110", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22541", "post_type": "question", "score": 0, "tags": [ "javascript", "html", "jquery", "node.js" ], "title": "jQueryでファイルを送信する方法について", "view_count": 1321 }
[ { "body": "form要素でラップしてsubmitする方法ではいかがでしょうか? \nenctype属性の指定をしてあげればアップロードできます。\n\n```\n\n <form enctype=\"multipart/form-data\" method=\"post\" name=\"frm\">\n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-07T09:25:59.183", "id": "37781", "last_activity_date": "2017-09-08T05:57:18.110", "last_edit_date": "2017-09-08T05:57:18.110", "last_editor_user_id": "2265", "owner_user_id": "2265", "parent_id": "37733", "post_type": "answer", "score": 1 }, { "body": "もし、ajaxで`multipart/form-data`で送信したいという意味であれば `FormData` を利用して送信することが可能です。\n\n```\n\n $(document.forms.someForm).submit(function(){\r\n $.ajax('/blog/blogAdds', {\r\n type: 'POST',\r\n data: new FormData(this),\r\n processData: false,\r\n contentType: false, \r\n });\r\n return false;\r\n });\n```\n\n```\n\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\r\n \r\n <form enctype=\"multipart/form-data\" method=\"post\" name=\"someForm\">\r\n <textarea id=\"blogContentInputArea\" class=\"form-control\"></textarea>\r\n <input type=\"file\" name=\"upfile\" value=\"\" class=\"fileuploader\"/>\r\n <input type=\"submit\" value=\"送信\" class=\"submitButton\"/>\r\n </form>\n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-07T12:37:50.643", "id": "37783", "last_activity_date": "2017-09-07T12:37:50.643", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "2376", "parent_id": "37733", "post_type": "answer", "score": 1 } ]
37733
37783
37781
{ "accepted_answer_id": "37812", "answer_count": 1, "body": "PrintPreviewの導入に成功し、プリントのプレビュー表示を \n早速出してみました。 \nプレビューを表示するためのコードです。 \n読んでもらえたら結構勉強になるかもしれ \nません。 \nプレビューを表示するためにどうすればい \nいのか考えあぐねていたら、ここを読んでみて \nピンと来た気がします。毎度長文で申し訳あり \nません。 \n[Print A Text Through A Printer Using\nPyQt4](http://Print%20A%20Text%20Through%20A%20Printer%20Using%20PyQt4)\n\n```\n\n      printer = QtGui.QPrinter()\n printer.setDocName(self.windowTitle())\n printer.setPageSize(QtGui.QPrinter.A4) \n printer.setOutputFormat(QtGui.QPrinter.NativeFormat)\n printer.setOrientation(QtGui.QPrinter.Portrait)\n printer.setResolution(QtGui.QPrinter.HighResolution)\n printer.setCopyCount(self.printer_pagecountspinbox.value())\n #ここで、ドキュメントに設定してある余白を、プリンターにもセットしてしまうと、二重に計上されるバグ?そのため、コメント化を行って、回避。\n # printer.setPageMargins(self.main_menubar_layout_document_left_margin_spinbox.value(),self.main_menubar_layout_document_top_margin_spinbox.value(),\\\n # self.main_menubar_layout_document_right_margin_spinbox.value(),self.main_menubar_layout_document_bottom_margin_spinbox.value(),\\\n # QtGui.QPrinter.Millimeter)\n if self.main_view.textediter.document().documentLayout().pageCount() == 1:\n #なぜか、一ページ目の白紙ドキュメントは、サイズがQtCore.QSizeF(797,-1)となり、正常に1ページ目を表示してくれないため、再認識修正(コンストラクタで本当はやってるんだけど反映されない。ここは、B5やB4等を増やしたときに拡張する予定)\n self.main_view.textediter.document().setPageSize(QtCore.QSizeF(797,1123))\n self.print_preview_widget = QtGui.QPrintPreviewDialog(printer,self) \n #showMaximized()を使い、全体表示をすれば、何も映らなくなる。なぜかわからないバグ。 \n self.print_preview_widget.setGeometry(150,150,1500,1500)\n #ここがミソ。コールしない。コールすると打ち出しを始めてしまったりする C++と表記が異なる点。QPrinter* つまり、ポインタを渡せという事。純粋Pythonerには少しハードルが高かった。\n #今までもコールでprinterをセットしていたかもしれない。忘れたころにまたやってしまう失敗。\n #残念ながら、self.main_view.textediter.document().print_とした場合、Failed to connect signal エラーが発生、これでもよくないかと考えてしまう。\n self.print_preview_widget.paintRequested.connect(self.main_view.textediter.print_)\n self.print_preview_widget.exec_() \n \n```\n\n**具体的な問題** \n既にページネーションが行われているので、ページ間の \n余白は意識することなくQTextEditの編集中の状態をその \nまま、プレビューに表示できるようになりました。 \nもちろんプリントもできます。 \nしかし、`QTextObjectInterface`によるカスタムオブジ \nェクトが、正確に表示されません。 \n`QTextObjectInterface`内のpainterメソッドは、下記の \nコードかこちらを参照 \n[QTextObjectInterfaceの導入方法について](https://ja.stackoverflow.com/questions/37162/qtextobjectinterface-\npyside%E3%81%A7%E3%81%AE%E5%B0%8E%E5%85%A5%E6%96%B9%E6%B3%95%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6) \nちょうどカスタムオブジェクトが描かれているべきところに、 \n灰のつぶのような小さな点が見えたので、もしやと思い、拡 \n大ボタンを押して、1500%くらいまで 拡大してみました。 \nすると、豆粒から見ても豆粒のような、灰カスのような文字が、 \n大きさはともかくとして、正確に表示されていました。 \n**空白であるにせよ、そこに文字が入り込むだけのスペース \nが空いています。その空白の左はじに、灰粕のように、黒い粉 \nがついています。painterのフォントサイズだけ1以下にされて \nしまったような外観です。** \nつまり、QTextEdit中には通常の表示がなされているはずのカス \nタム オブジェクトが、プレビュー画面で表示したときは、どん \nなにFontをいじっても、蟻よりも小さくなっています。 \nもちろん、そのままプリントしても、その通りの文字でした。 \nさすがプレビューとは言えない状況でした。 \n私のエディタは、Wordソフトのように、ページネーションが行わ \nれているので、`QTextDocument or QTextEdit.print_()`を \n利用すれば、そのまま表示してくれます。 \n私は、あくまでもこの方法でプリントしたいと思っています。 \n[便利なプリントメソッド~ページネーション時にはこれ。](https://pyside.github.io/docs/pyside/PySide/QtGui/QTextDocument.html#PySide.QtGui.PySide.QtGui.QTextDocument.print_) \nカスタムオブジェクトを、プリント時に改めて挿入すればよい \nとも思いましたが、一応レンダリングはなされている以上、小さ \nな黒い点+挿入文字で、正確な表記ではなくなります。また、上 \n記のメソッドを使えば、painterでごちゃごちゃ書かなくてもい \nいので、非常に楽なのです。特に`TextBlock`がページ間でまた \nがった場合の処理が不要になるので、一番楽です。 \n小さいながらも、文字が載っているということは、必ず、この文 \n字を正常な状態で載せる方法もあると思っています。しかしその \n手がかりが今のところ全くつかめません。 \nCustomTextObjectを作れる仕組みがありながら、セーブ&ロード、 \nプリントの手段については、リファレンスに載っていないのは、案 \n外簡単な方法があるんじゃないかと考えています。じゃないと作っ \nてもアプリを消せばすべておじゃんになるから、絵にかいた餅もい \nいところだと思うからです。 \nそして、こちらが、自分なりのルビ表示機能のコードです。実際ま \nだルビは汚いです。 \n\n```\n\n class RubyTextObjectInterface(QtGui.QPyTextObject):\n def __init__(self,parent=None):\n super(RubyTextObjectInterface, self).__init__(parent=None) \n \n def intrinsicSize(self,doc, posInDocument, format): \n try: \n #ここのformatはQTextFormat\n #ここに、docを引数として通すと、後の処理で原因不明のエラーが発生 format_tc = QtGui.QTextCursor(doc)は、エラーになる。\n findblock = doc.findBlock(posInDocument)\n format_tc = QtGui.QTextCursor(findblock)\n format_tc_charFormat = format_tc.charFormat()\n format_charFormat = format.toCharFormat()\n format_charFormat.setFont(format_tc_charFormat.font())\n rubysize = format.property(4)\n offset = format.property(5) \n size = QtCore.QSize(len(format.property(1))*format_charFormat.font().pointSize()+(len(format.property(2))-1)*rubysize,format_charFormat.font().pointSize()+rubysize+offset+2)\n return size\n except Exception as e:\n print(33,e) \n def drawObject(self,painter,rect,doc,posInDocument,format):\n \n try:\n #そもそものviewportを取得してみた。結果は(0,0,796,1131)\n # print(102,painter.viewport())\n # painter.setViewport(int(doc.rootFrame().frameFormat().leftMargin()),int(doc.rootFrame().frameFormat().topMargin()),int(doc.pageSize().width()),int(doc.pageSize().height()*doc.documentLayout().pageCount()))\n #formatのプロパティに現在位置を登録し、常に更新\n format.setProperty(3,posInDocument) \n rubysize = format.property(4)\n offset = format.property(5)\n #ドキュメント上のテキストカーソルを取得 \n format_tc = QtGui.QTextCursor(doc)\n #拡張書式のある場所へ移動\n format_tc.setPosition(posInDocument)\n #現在カーソルがある位置のcharFormat()を取得\n format_tc_charFormat = format_tc.charFormat()\n #formatをcharFormat化\n format_charFormat = format.toCharFormat()\n #ルビに現在のカーソル位置のフォントをセット\n format_charFormat.setFont(format_tc_charFormat.font())\n #rectは親文字のための位置情報なので、rubyはその上にレンダリングさせるように微調整\n ruby_rect = QtCore.QRectF(rect.x(),rect.y()-rubysize-offset,rect.width(),rubysize+offset)\n painter.setFont(format.property(7))\n painter.drawText(rect,format.property(1))\n painter.setFont(QtGui.QFont(format.property(8).rawName(),rubysize))\n painter.drawText(ruby_rect,format.property(6),format.property(2))\n \n```\n\nご存知の方や、こうすればどうかというお考えをお持ちの方は \n何でもいいのでお寄せください。よろしくお願いします。 \n**~蛇足~** \n**カスタムテキストオブジェクトに当たっての導入必要な処理** 進捗状況 \n①BoldやItalic,Underlineをダイナミックに適用する。 × \n②fontの変更、fontsizeの変更をダイナミックに適用する。 × \n③printoutとpreview表示を可能にする。 × \n④save&loadを可能にする。(強引に可能にしたが、もっと楽な方法が欲しい) △ \n⑤copy&pasteを可能にする。 × \n①と②と⑤は、脳内でちょっと図が出来上がっていて、④は、もっ \nと楽な方法が欲しいです。これはまたおいおい質問していけれ \nばいいなと思っています。 \nすぐに試してみる事も可能なのですが、インターフェースの \nメソッドを、IntrinsicSizeとdrawObject以外に追加しても \n怒られませんよね?", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T11:16:37.783", "favorite_count": 0, "id": "37734", "last_activity_date": "2017-09-08T12:26:42.840", "last_edit_date": "2017-09-07T06:14:16.690", "last_editor_user_id": "24284", "owner_user_id": "24284", "post_type": "question", "score": 0, "tags": [ "python", "qt" ], "title": "Custom Text Objects PrintPreviewの表示について-Ruby表示コードとPreview表示コード掲載-", "view_count": 148 }
[ { "body": "直接実行できるコードではないので、気づく範囲の回答になりますが、 \n少なくとも`QPrinter.setResolution()`の引数を間違えているように見えます。 \nこのメソッドの引数は、具体的なDPIを指定することになっており、`QPrinter.HighResolution`は指定しません。`QPrinter.HighResolution`は`QPrinter`のコンストラクタで指定します。(参考:\n[QPrinterの文書](https://srinikom.github.io/pyside-\ndocs/PySide/QtGui/QPrinter.html)) \nあるいは、プレビューであれば`QPrintPreviewDialog`のコンストラクタに`QPrinter`を指定しなくても十分と思います。\n\n一方、`QPrinter.HighResolution`を`QPrinter`に指定する場合、1200DPIとして扱われるようなので、`RubyTextObjectInterface.intrinsicSize()`や`drawObject()`内で描画物を「1200\n÷ 96」倍で描画すると、プレビュー画面で見えるようになると思います。\n\n#「96」は`QPrinter.ScreenResolution`を指定した際のDPI。\n\n以上、参考になれば幸いです。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-08T12:26:42.840", "id": "37812", "last_activity_date": "2017-09-08T12:26:42.840", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "20098", "parent_id": "37734", "post_type": "answer", "score": 1 } ]
37734
37812
37812
{ "accepted_answer_id": null, "answer_count": 1, "body": "最近ではaarやjarをjcenterやmaven centralなどで公開することがよくあると思いますが、google play\nservicesのようにライブラリを部分的に公開する方法を探しています。\n\n分割で公開するだけならばモジュールを切り分けてそれぞれアップすれば良いのですが、やりたいこととしてはgoogle play\nservicesのようにproguardをかけつつ分割して公開という感じです。\n\nGoogle play\nservicesのようにコアになるクラス群があって、それぞれのモジュールでそれを参照して処理を書いている場合、単にそれぞれのモジュールでproguardをかけてしまうとコアライブラリの難読化とずれてしまったり、各モジュール間で名前が衝突してしまうのでmappingファイルをみるなりして、全てで同じ名前に難読化されるようにして上げる必要があるかと思います。\n\nもちろん各モジュールでルートになるパッケージを変えて、そのパッケージ名さえ難読化されないようにしてしまえば、依存関係にあるコードとの整合性さえ取ればいいのですが、Google\nplay servicesでは各モジュールで同一のパッケージにそれぞれでクラスを追加していたりします。 \nそうなってくると各モジュールで難読化後に名前の衝突が発生する可能性が出てしまいます。\n\nこういうGooogle play\nservicesのようなライブラリはどういうふうにプロジェクトを管理していたり、成果物を生成しているのか(1つのモジュールに全てのコードを書いて成果物を分割できるようにしているのか、複数モジュールで切り分けて難読化をうまいこと整合性とっているのかなど)、ご存知の方いらっしゃいましたらご教授いただけると幸いです。\n\nよろしくお願いいたします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T12:52:10.597", "favorite_count": 0, "id": "37735", "last_activity_date": "2018-08-21T00:54:33.370", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22734", "post_type": "question", "score": 3, "tags": [ "android", "java", "gradle" ], "title": "ライブラリの分割提供", "view_count": 161 }
[ { "body": "google play servicesがどうなのか、正確なところは私にはわかりませんが:\n\nproguardでpublicな部分だけ難読化しないように設定(keep,\npublic)した上で、ライブラリ間で依存関係にあるメソッド・クラスのみpublic修飾すれば良いです。(いや、それがしたくないんだ、ということでしたら済みません)", "comment_count": 0, "content_license": "CC BY-SA 4.0", "creation_date": "2018-08-21T00:54:33.370", "id": "47681", "last_activity_date": "2018-08-21T00:54:33.370", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "7572", "parent_id": "37735", "post_type": "answer", "score": 1 } ]
37735
null
47681
{ "accepted_answer_id": "37836", "answer_count": 1, "body": "いつもお世話になっております。\n\n以下サイトを参考にGameplayKitを勉強しております。 \nGKComponentを継承したクラス内のentity?.componentの箇所がnilになってしまいます。 \n自分の力では解決できそうにない為、教えて頂けると幸いです。 \nご教授ご鞭撻のほどよろしくお願い致します。\n\n参考サイト \n<https://github.com/marielin/CocoaBlast/blob/master/CocoaBlast_guide.md>\n\n参考コード\n\n```\n\n class PlayerControlComponent: GKComponent {\n /// A convenience property for the entity's sprite component.\n var spriteComponent: SpriteComponent? {\n return entity?.component(ofType: SpriteComponent.self)\n }\n ...\n \n```\n\n自己解決致しましたので、回答にソースコードを記載せて頂きました。", "comment_count": 2, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T14:16:48.057", "favorite_count": 0, "id": "37737", "last_activity_date": "2017-09-10T15:34:39.353", "last_edit_date": "2017-09-10T15:32:40.337", "last_editor_user_id": "20142", "owner_user_id": "20142", "post_type": "question", "score": 0, "tags": [ "swift3" ], "title": "GameplayKitにて、GKComponentを継承したクラス内でentityがnilになる", "view_count": 101 }
[ { "body": "簡易なソースコードで試したところ意図した動作で動いていることを確認しました。 \nそのコードを記載致します。 \nいろいろアドバイス頂きありがとうございます。\n\n```\n\n class GameScene {\n \n init() {\n }\n \n required init?(coder aDecoder: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n \n func didMove() {\n let entityManager = EntityManager()\n }\n }\n \n class EntityManager {\n \n init() {\n let player: GKEntity = Player()\n \n if let visual = player.component(ofType: Visual.self) {\n print(visual.callDamage()) // \"hit\"\n }\n }\n }\n \n class Player: GKEntity {\n \n override init() {\n super.init()\n addComponent(Visual())\n addComponent(Damage())\n }\n \n required init?(coder aDecoder: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n }\n \n class Visual: GKComponent {\n \n // 自身のエンティティにおいてコンポーネントから他のコンポーネントを呼び出す便利なプロパティ\n var damage: Damage? {\n return entity?.component(ofType: Damage.self)\n }\n \n override init() {\n super.init()\n }\n \n required init?(coder aDecoder: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n \n func callDamage() -> String {\n return (self.damage?.message())!\n }\n }\n \n class Damage: GKComponent {\n \n override init() {\n super.init()\n }\n \n required init?(coder aDecoder: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n \n func message() -> String {\n return \"hit\"\n }\n }\n \n let i = GameScene()\n i.didMove()\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-09T17:31:33.500", "id": "37836", "last_activity_date": "2017-09-09T17:47:03.683", "last_edit_date": "2017-09-09T17:47:03.683", "last_editor_user_id": "20142", "owner_user_id": "20142", "parent_id": "37737", "post_type": "answer", "score": 0 } ]
37737
37836
37836
{ "accepted_answer_id": "37740", "answer_count": 1, "body": "本の情報によるとアプリの設定画面の「Deployment info」で「 Landscape\nLeft」だけにチェックするとシュミレーターが横画面になると書いてあり下の図の様にしたのですがシュミレーターは縦画面のままです。\n\nどの様な原因が考えられますか?\n\nちなみに画像を載せようとしましたが2imb以下にしてくれという表示で断念しております\n\nDeployment info\n\nDeployment Target 10.3\n\nDevices iPhone\n\nMaine interface Main\n\nDevice Orientation Portrait\n\n```\n\n Upside Down\n \n```\n\nチェック済み → Landscape Left\n\n```\n\n Landscape Right\n \n```\n\nStatus Bar Style Light", "comment_count": 3, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T14:59:10.703", "favorite_count": 0, "id": "37738", "last_activity_date": "2017-09-05T20:07:56.717", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25189", "post_type": "question", "score": 0, "tags": [ "xcode" ], "title": "Xcodeのシュミレーターが横向きにならない", "view_count": 1254 }
[ { "body": "_**どの様な原因が考えられますか?**_\n\n単にXcodeのバージョンによる挙動の違いでしょう。どのバージョンからだったのか記録は残していませんが、現在のXcodeでは、アプリをLandscapeオンリーに設定しても、シミュレータの表示の向きには影響しなくなってしまっています。\n\nアプリをLandscapeオンリーに設定すると言うことは、ユーザがデバイスを縦に持った時にも、アプリは画面を横長方向に使うと言うことなので、現在のXcodeのシミュレータは、デフォルトでは「ユーザがデバイスを縦に持った時」の動作をシミュレートしていると言うことになります。\n\nボタン1個の画像で恐縮ですが、こんな感じなら正解ということです。 \n[![Landscape縦持ち画像](https://i.stack.imgur.com/g3Ml5.jpg)](https://i.stack.imgur.com/g3Ml5.jpg)\n\nユーザがデバイスを横持ちした時の状態にするには、Simulatorのメニューから\n\n### Hardware > Rotate Left\n\n### Hardware > Rotate Right\n\nを選んで、明示的に回転させてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T20:07:56.717", "id": "37740", "last_activity_date": "2017-09-05T20:07:56.717", "last_edit_date": "2020-06-17T08:14:45.997", "last_editor_user_id": "-1", "owner_user_id": "13972", "parent_id": "37738", "post_type": "answer", "score": 0 } ]
37738
37740
37740
{ "accepted_answer_id": null, "answer_count": 1, "body": "google apps\nscriptを使って、対象Spreadsheetのsheetの指定cellにbuttonのようなユーザインタフェースをつくりたいが、そのやり方について教えてください。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-05T23:34:41.650", "favorite_count": 0, "id": "37741", "last_activity_date": "2020-07-02T09:01:40.200", "last_edit_date": "2017-09-06T02:08:40.957", "last_editor_user_id": "3060", "owner_user_id": "25226", "post_type": "question", "score": 0, "tags": [ "html" ], "title": "google apps scriptでSpreadsheetにbuttonを作る方法", "view_count": 124 }
[ { "body": "**cell内にbuttonを作成することはできません。**\n\n[stackoverflow](http://There%20seems%20to%20be%20no%20way%20to%20place%20buttons%20\\(drawings,%20images\\)%20within%20cells%20in%20a%20way%20that%20would%20allow%20them%20to%20be%20linked%20to%20Apps%20Script%20functions.)\n\n> There seems to be no way to place buttons (drawings, images) within cells in\n> a way that would allow them to be linked to Apps Script functions.", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-10-09T21:07:23.027", "id": "38552", "last_activity_date": "2017-10-09T21:07:23.027", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "23533", "parent_id": "37741", "post_type": "answer", "score": 0 } ]
37741
null
38552
{ "accepted_answer_id": "37746", "answer_count": 1, "body": "javascriptのオブジェクトと配列について\n\n下記のように作成するという事はわかったのですが、 \n純粋なオブジェクトと配列は、中カッコと大カッコの部分のみなのでしょうか? \nつまり変数にオブジェクトと配列を代入していると考えてよいのでしょうか?\n\nそれともvar含むすべてがオブジェクトと配列そのものなのでしょうか? \n変数名の部分が配列の名前とも聞きますが、初心者なので頭がこんがらがってしまいます\n\n```\n\n // 空の Object オブジェクトを作成する\n var obj = { };\n \n // 空の配列を作成する\n var arr = [];\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-06T00:56:37.117", "favorite_count": 0, "id": "37743", "last_activity_date": "2017-09-06T04:48:28.937", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "24247", "post_type": "question", "score": 0, "tags": [ "javascript" ], "title": "javascriptのオブジェクトと配列について", "view_count": 432 }
[ { "body": "javascriptでは[リテラル](https://www.google.co.jp/search?q=%E3%83%AA%E3%83%86%E3%83%A9%E3%83%AB)形式でオブジェクト([オブジェクトリテラル](https://www.ajaxtower.jp/js/object/index2.html)、[オブジェクトリテラル表記法](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Object_initializer#%E3%82%AA%E3%83%96%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%83%AA%E3%83%86%E3%83%A9%E3%83%AB%E8%A1%A8%E8%A8%98%E6%B3%95_vs_JSON))を作成できるので「値を代入している?」と考えてらっしゃるかもしれません。\n\n実際、略式で記載されているものをキチンと書くとこうなります。 \n[new演算子](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/new)を使用した初期化で作成されたものをインスタンスと呼びます。\n\n```\n\n var obj = new Object();\n var arr = new Array();\n \n```\n\nまた、別の言語では変数宣言型(Integer,String,Booleanなど)によって代入できる型に制限があったりしますが、 \njavascriptの変数宣言である`var`は代入される値によって任意の型に変わります。\n\n```\n\n //number\r\n var n = 1;\r\n console.log((typeof n));\r\n \r\n //string\r\n n = \"one : \" + n;\r\n console.log((typeof n));\r\n \r\n //object(Array)\r\n n = new Array();\r\n console.log((typeof n));\r\n \r\n //object\r\n n = new Object();\r\n console.log((typeof n));\r\n \r\n //function\r\n n = function(){ alert(\"Hello world\"); };\r\n console.log((typeof n));\n```\n\n上記を見て「ArrayもObjectって出てるじゃないか」と思うかもしれませんがjavascriptでのインスタンスは全てobject型となります。 \njavascriptにおけるArrayとは下記になります。\n\n * 真偽判定で偽となる値ではない\n * \"object\"型である\n * \"length\"プロパティがある\n * \"length\"プロパティが数値である\n * \"length\"プロパティが列挙不可\n * \"splice\"関数を保持\n\n* * *\n\nオブジェクト名の認識が下記のようなことであればその通りです。\n\n```\n\n var obj = {};\r\n \r\n //変数名として\r\n obj[\"val1\"] = \"value one\";\r\n \r\n //オブジェクト名として\r\n obj.val2 = \"value two\";\r\n \r\n console.log(obj);\n```", "comment_count": 11, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-06T02:44:28.290", "id": "37746", "last_activity_date": "2017-09-06T04:48:28.937", "last_edit_date": "2017-09-06T04:48:28.937", "last_editor_user_id": null, "owner_user_id": null, "parent_id": "37743", "post_type": "answer", "score": 2 } ]
37743
37746
37746
{ "accepted_answer_id": null, "answer_count": 1, "body": "セレクトボックスのドロップダウンリストを閉じた状態でのキーアップ、キーダウンを禁止するため、下記どちらかの対応を考えたのですが、該当するイベントが見当たりません。(ドロップダウンリスト展開時はキー操作可能としたい)どのような実装をすれば良いかご教示頂けませんでしょうか。 \n・ドロップダウンリストの要素を選択した時にフォーカスを外す \n⇒onchangeだと既にselectされた要素を選択時が拾えなかった \n・ドロップダウンリストが閉じた時にフォーカスを外す\n\n【コード】\n\n```\n\n <div id=\"apDivTEST\">\n <select name=\"TEST\" id=\"TEST\" style=\"width:354px; height:40px; font-size:20px; background-color: #000; color: #CFCBC8; border-color: #000; outline:none;\">\n <option value=\"A\" id=\"TEST_1\"></option>\n <option value=\"B\" id=\"TEST_2\"></option>\n </select>\n </div>\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-06T01:21:40.510", "favorite_count": 0, "id": "37744", "last_activity_date": "2018-03-29T06:41:40.697", "last_edit_date": "2018-03-29T06:41:40.697", "last_editor_user_id": "19110", "owner_user_id": "25229", "post_type": "question", "score": 1, "tags": [ "javascript" ], "title": "セレクトボックスのドロップダウンリストを閉じたときのイベント", "view_count": 1930 }
[ { "body": "> ドロップダウンリスト展開時はキー操作可能としたい\n\nkeyup、keydownイベントが発生している要素をチェックし、それがセレクトボックスリストの場合のみイベントを許可するようにすると良いかと思います。\n\n```\n\n function isSelectBox(element) {\n return element.id === 'TEST'; // セレクトボックス要素の場合はtrueを返す\n }\n \n document.onkeydown = function(event) {\n return isSelectBox(event.target);\n };\n \n document.onkeyup = function(event) {\n return isSelectBox(event.target);\n };\n \n```\n\nイベントハンドラに登録する関数にて`false`を`return`するとそのイベントを無効化することが出来ます。 \nですので、イベントの発生元要素(上記`event.target`)を取得し、セレクトボックスの場合は`true`を返すようにするとセレクトボックス選択時のみイベントが有効化されます。\n\n※ 対象ブラウザによって挙動が異なる可能性があるためご注意下さい。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2018-03-29T05:43:08.093", "id": "42739", "last_activity_date": "2018-03-29T05:43:08.093", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "27930", "parent_id": "37744", "post_type": "answer", "score": 1 } ]
37744
null
42739
{ "accepted_answer_id": null, "answer_count": 1, "body": "Railsを使って管理者が画像ファイルや音声ファイルをアップして、それを第3者が確認できるというアプリを作っています。 \n機能としては、管理画面でアップしたものを別のトップページで確認できるというシンプルなものなのですが、ファイルの置き場所はどこに置くのが一般的なのでしょうか。\n\nファイルのアップにはCarrierwaveというgemを使っています。ファイルの保存先は/public/uploadsディレクトリとなっています。\n\nこの辺りから少し当方の知識もまだ足りていない部分で、 \n本番環境(heroku)でアプリを起動してファイルをアップしていっても、このディレクトリに保存されますよね? \nその場合のリスクなどはあるのでしょうか。 \nまた、Amazon S3などのクラウドにファイルを置く方法もたくさんネットで見つかったのですが、やはりファイルはクラウドに置いて置く方がいいのでしょうか? \nクラウドにおいて置くメリットなども教えていただけると助かります。\n\nよろしくお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-06T02:24:31.763", "favorite_count": 0, "id": "37745", "last_activity_date": "2017-09-09T11:01:52.107", "last_edit_date": "2017-09-06T02:52:01.860", "last_editor_user_id": "25232", "owner_user_id": "25232", "post_type": "question", "score": 1, "tags": [ "ruby-on-rails", "ruby", "amazon-s3" ], "title": "Railsアプリケーション 画像・音声ファイルの置き場所について", "view_count": 589 }
[ { "body": "herokuはDynoが再起動した時およびアイドル状態になった時にファイルが削除されてしまいますので、Amazon\nS3のような外部ストレージを使うしか方法がありません。\n\n独自サーバーやVPSなどに本番環境を置く場合でも画像や音声のデータをユーザーが投稿できる場合はファイルの容量の増加の程度が予測しづらいため、やはりS3を使ったほうがいいでしょう。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-09T11:01:52.107", "id": "37829", "last_activity_date": "2017-09-09T11:01:52.107", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "3271", "parent_id": "37745", "post_type": "answer", "score": 2 } ]
37745
null
37829
{ "accepted_answer_id": null, "answer_count": 1, "body": "```\n\n $venue_type = $_GET['vt'];\n $guest_count = $_GET['gc'];\n $area = $_GET['area'];\n $keyword = $_GET['s'];\n \n $the_query = new WP_Query();\n \n if($keyword){ $taxquerysp[] = array( 'taxonomy'=>'category', 'terms'=> $keyword);}\n if($keyword){ $taxquerysp[] = array( 'taxonomy'=>'post_tag', 'terms'=> $keyword);}\n $taxquerysp['relation'] = 'OR';\n \n if($venue_type){ $metaquerysp[] = array( 'key'=>'venue_type', 'value'=> $venue_type );}\n if($guest_count){ $metaquerysp[] = array( 'key'=>'guest_count', 'value'=> $guest_count );}\n $metaquerysp['relation'] = 'AND';\n \n if($metaquerysp || $area || $keyword){\n $query1 = array(\n 'post_type' => 'wedding_reports',\n 'tax_query' => $taxquerysp,\n 'meta_query' => $metaquerysp,\n 's' => $keyword\n );\n $current_articl1 = new WP_Query($query1);\n }\n \n```\n\n上記のような検索を実現したいのですが、wordpressでのフリーワード検索とtaxonomyとカスタムフィールドのAND検索は可能なのでしょうか?\n\nよろしくお願い致します。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-06T02:56:15.093", "favorite_count": 0, "id": "37747", "last_activity_date": "2017-09-07T08:50:21.053", "last_edit_date": "2017-09-06T03:08:06.790", "last_editor_user_id": "9988", "owner_user_id": "9988", "post_type": "question", "score": 0, "tags": [ "wordpress" ], "title": "wordpressでのフリーワード検索とtaxonomyとカスタムフィールドのAND検索は可能なのか", "view_count": 1457 }
[ { "body": "AND検索は可能です。\n\n関数:WP_Queryやget_postsは、パラメータ'tax_query'、'meta_query'、's'などが同時に指定されるとAND条件で記事データを抽出します。\n\nwordpressがフォルダー”word”にインストールされ \nカスタムフィールド abcdef_abc に 'dog'が \nカテゴリに、a1 が 設定されている記事で \nフリーワード検索で'ねこ'が存在するデータを絞り込むなら、以下のコード実行すると確認する事が出来ると思います。\n\n```\n\n require \"word/wp-config.php\";\n \n $ptype ='post';\n \n $taxonomyc =\n array(array(\n 'taxonomy' => 'category',\n 'field' => 'slug',\n 'terms' => 'a1'\n ));\n \n $metac =\n array(\n array(\n 'key' => 'abcdef_abc',\n 'value' => 'dog',\n )\n );\n \n $current_articl1 = new WP_Query(array('numberposts'=> 5000, 'order'=> 'DESC', 'orderby' => 'post_date','post_type' => $ptype,'tax_query' => $taxonomyc,'meta_query' => $metac,'s'=>'ねこ'));\n $pt = get_posts(array('numberposts'=> 5000, 'order'=> 'DESC', 'orderby' => 'post_date','post_type' => $ptype,'tax_query' => $taxonomyc,'meta_query' => $metac,'s'=>'ねこ'));\n print_r($pt);\n \n```\n\nWP_Query関数がパラメータを展開したSQLは以下の通りです。($current_articl1−>requestに入っています。)\n\n```\n\n SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND (\n wp_term_relationships.term_taxonomy_id IN (2)\n ) AND (((wp_posts.post_title LIKE '%ねこ%') OR (wp_posts.post_excerpt LIKE '%ねこ%') OR (wp_posts.post_content LIKE '%ねこ%'))) AND (wp_posts.post_password = '') AND (\n ( wp_postmeta.meta_key = 'abcdef_abc' AND wp_postmeta.meta_value = 'dog' )\n ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10\n \n```", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-07T08:50:21.053", "id": "37780", "last_activity_date": "2017-09-07T08:50:21.053", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "22793", "parent_id": "37747", "post_type": "answer", "score": 1 } ]
37747
null
37780
{ "accepted_answer_id": "37754", "answer_count": 1, "body": "nginx初心者です。\n\nレンタルVPSでWebサイトを公開しようと、CentOS7上でnginx1.12.1を動かしています。\n\n起動しようとすると、以下のエラーが吐かれます。\n\n```\n\n systemd[1]: Starting nginx - high performance web server...\n nginx[4361]: nginx: [emerg] \"http\" directive is not allowed here in /etc/nginx/conf.d/default.conf:1\n nginx[4361]: nginx: configuration file /etc/nginx/nginx.conf test failed\n systemd[1]: nginx.service: control process exited, code=exited status=1\n systemd[1]: Failed to start nginx - high performance web server.\n systemd[1]: Unit nginx.service entered failed state.\n systemd[1]: nginx.service failed.\n \n```\n\n`/etc/nginx/conf.d/default.conf`の1行目から問題があるようで、default.confは以下のように記述しました。\n\n```\n\n http {\n server {\n listen 80;\n server_name ドメイン;\n \n charset UTF-8;\n #access_log /var/log/nginx/host.access.log main;\n \n location / {\n root /var/www/html;\n index index.html index.htm index.php;\n }\n \n #error_page 404 /404.html;\n \n # redirect server error pages to the static page /50x.html\n #\n error_page 500 502 503 504 /50x.html;\n location = /50x.html {\n root /usr/share/nginx/html;\n }\n \n # proxy the PHP scripts to Apache listening on 127.0.0.1:80\n #\n #location ~ \\.php$ {\n # proxy_pass http://127.0.0.1;\n #}\n \n # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\n #\n location ~ \\.php$ {\n root /var/www/html;\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n include fastcgi_params;\n }\n \n # deny access to .htaccess files, if Apache's document root\n # concurs with nginx's one\n #\n #location ~ /\\.ht {\n # deny all;\n #}\n }\n }\n \n```\n\n全体的に書き方には問題ないように思えますが、起動に失敗するのはなぜでしょうか?\n\n教えていただけると幸いです。よろしくお願いします。", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-06T04:17:08.457", "favorite_count": 0, "id": "37748", "last_activity_date": "2017-09-06T08:14:42.340", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "25223", "post_type": "question", "score": 1, "tags": [ "centos", "nginx" ], "title": "nginx 起動ができない", "view_count": 2341 }
[ { "body": "conf.d の下のファイルを include している親ファイルがあるはずです。\n\nたぶん /etc/nginx/nginx.conf が Include しているのではと思いますが、Include された結果 http\nディレクティブが二重に定義されてしまっているのだと思います。\n\nしたがって、default.conf を\nバーチャルサーバー向けの設定に変えるか、Includeしている親ファイルの方を修正するのが良いように見受けられます。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-06T08:14:42.340", "id": "37754", "last_activity_date": "2017-09-06T08:14:42.340", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "5008", "parent_id": "37748", "post_type": "answer", "score": 2 } ]
37748
37754
37754
{ "accepted_answer_id": "37887", "answer_count": 1, "body": "[TERASOLUNAのチュートリアル](http://terasoluna.osdn.jp/tutorial/server-\nweb/Document/WebTutorial_3.1.html)\n\nでデータベースをOracle DBに切り替える作業を行っているのですが、\n\n「データベースへの接続に失敗しました。 \nListener refused the connection with the following error: \nORA-12505, TNS:listener does not currently know of SID given in connect\ndescriptor」\n\nというエラーが出てしまいます。\n\n接続情報は \nデータベース定義名:TERASOLUNA \nJDBCドライバー: odbc6jar\n\nJDBC Driver:oracle.jdbc.OracleDriver \nJDBC タイプ:Type4 \n接続文字列:jdbc:oracle:thin:@192.168.11.89:1521:ORCL(ipはコマンドのipconfigで調べました) \n接続ユーザ:taro(SQLコマンドでUSERを作成) \n接続パスワード:パスワード(SQLコマンドで作成)\n\n以上の設定で接続を試してみましたが、うまくいきません。\n\nTERASOLUNAのチュートリアルと自分のPC環境設定と照らし合わせて、接続情報の引き出し方はこれであっているか。 \n確認しておくべき点をご教授願いたいのですが、お願いします。", "comment_count": 1, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-06T05:21:09.343", "favorite_count": 0, "id": "37750", "last_activity_date": "2017-09-12T06:15:29.880", "last_edit_date": "2017-09-11T09:53:04.643", "last_editor_user_id": "21092", "owner_user_id": "25002", "post_type": "question", "score": 0, "tags": [ "database" ], "title": "eclipseとoracleを接続する際のデータ定義と接続情報について", "view_count": 5255 }
[ { "body": "以下の記事に確認すべき事項と、対処方法が説明されていますから参考になるのではないでしょうか。 \n[ORA-12505: TNS:\nリスナーは接続記述子で指定されたSIDを現在認識していません](http://www.noguopin.com/oracle/index.php?ORA-12505)", "comment_count": 0, "content_license": "CC BY-SA 3.0", "creation_date": "2017-09-12T06:15:29.880", "id": "37887", "last_activity_date": "2017-09-12T06:15:29.880", "last_edit_date": null, "last_editor_user_id": null, "owner_user_id": "217", "parent_id": "37750", "post_type": "answer", "score": 0 } ]
37750
37887
37887