question
dict | answers
list | id
stringlengths 2
5
| accepted_answer_id
stringlengths 2
5
⌀ | popular_answer_id
stringlengths 2
5
⌀ |
---|---|---|---|---|
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "PCを再起動させずにメモリを解放する方法が知りたいです。 \nコマンド等でメモリ解放できないでしょうか?\n\n2つのGPUを使用しており、片方は動作中のままにしたいので、 \n再起動や、全てのプロセスを停止させたりはしたくないです。\n\n以下は `nvidia-smi` コマンドを実行した画面です。\n\n[](https://i.stack.imgur.com/zsnbb.png)\n\n●環境 \nOS:ubuntu14.04 \nGPU:GeForce GTX 1080 \n※python(chainer)で機械学習を実行中にエラーとなり、メモリが解放されなくなりました。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-11-22T02:39:42.143",
"favorite_count": 0,
"id": "39750",
"last_activity_date": "2022-08-06T08:01:05.110",
"last_edit_date": "2021-09-01T16:30:53.683",
"last_editor_user_id": "3060",
"owner_user_id": "26296",
"post_type": "question",
"score": 6,
"tags": [
"python",
"機械学習",
"chainer",
"memory-leaks",
"gpu"
],
"title": "nvidia GPUのメモリを再起動せずに解放する方法が知りたい",
"view_count": 16628
} | [
{
"body": "Chainerは使ったことがありませんが、killコマンドで不要なプロセスを消せばよいらしいです。 \n<https://qiita.com/miyamotok0105/items/033b850a205f958808e9>\n\nゾンビプロセスを残さないようなシステム設計を検討したほうがよいかと。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T09:25:50.943",
"id": "39822",
"last_activity_date": "2017-11-25T09:25:50.943",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "15413",
"parent_id": "39750",
"post_type": "answer",
"score": 1
}
]
| 39750 | null | 39822 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "keepalivedで、特定のvirtual ip宛でアクセスが来たら、クライアントサーバへ向かわせる処理を行なっています。\n\nですがホストからクライアントへ「telnet ipアドレス\n80」は通信が成功するのに、keepalivedではログに「Keepalived_healthcheckers[5189]: Timeout WEB\nread server」が表示されてしまいます。weightも0になります。\n\n設定など見直しているのですが、いまいち原因がわかりません。\n\nこの問題を解決するためのヒントをいただければ幸いです。\n\n環境 \ncentos6.7",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T03:11:05.210",
"favorite_count": 0,
"id": "39752",
"last_activity_date": "2017-11-22T03:11:05.210",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19397",
"post_type": "question",
"score": 0,
"tags": [
"linux",
"centos",
"network"
],
"title": "keepalivedでクライアントサーバとの通信が失敗する",
"view_count": 127
} | []
| 39752 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Chainerを使ってひらがな73文字を畳み込みニューラルネットワークで画像から学習させ、モデルを保存しました。その学習させたモデルをserializers.load_npzで読み込み、手書き画像を入力し認識させ、上位5個を割合と一緒に結果として表示させるコードを書いています。\n\n目標としている表示結果(例)\n\n```\n\n tegaki_na.pngの識別結果\n な:60%\n た:25%\n は:10%\n あ:4%\n を:1%\n \n```\n\nしかし、その割合として利用しようとしていたpredictorのdataから得られる行列(要素73個)は正の値から負の値まであるため、そのまま割合としては使えないことがわかりました(すべてを足しても1や100になることはありませんでした)。 \n公式のChainer.Links.Classifierの項目を読んでもpredictorの出力の形までは説明が書いておらず、手詰まりになっためここで質問させていただきました。\n\n以下ソースコードです。ここではpredictorの中の実際の値をそのまま出力するようになっています(これをパーセントにしたい)\n\n```\n\n import numpy as np\n import cv2\n import chainer\n import chainer.links as L\n from chainer import Variable\n #畳み込みのモデルはconvolution_model.pyとして保存してある\n import convolution_model as CNN\n \n label = ['あ', 'い', 'う', 'え', 'お',\n 'か', 'が', 'き', 'ぎ', 'く', 'ぐ', 'け', 'げ', 'こ', 'ご',\n 'さ', 'ざ', 'し', 'じ', 'す', 'ず', 'せ', 'ぜ', 'そ', 'ぞ',\n 'た', 'だ', 'ち', 'ぢ', 'つ', 'づ', 'て', 'で', 'と', 'ど',\n 'な', 'に', 'ぬ', 'ね', 'の',\n 'は', 'ば', 'ぱ', 'ひ', 'び', 'ぴ', 'ふ', 'ぶ', 'ぷ', 'へ', 'べ', 'ぺ', 'ほ', 'ぼ', 'ぽ',\n 'ま', 'み', 'む', 'め', 'も',\n 'や', 'ゆ', 'よ',\n 'ら', 'り', 'る', 'れ', 'ろ', 'わ', 'ゐ', 'ゑ', 'を', 'ん']\n \n #画像サイズは48x48である前提\n model = L.Classifier(CNN.Model())\n chainer.serializers.load_npz('nihongo.model', model)\n \n def loadimg(image):\n img_ = cv2.imread(image, 0) #グレースケールとして読み込み\n \n height, width = img_.shape[:2]\n if height!=48 or width!=48: #縦または横の長さが48pxではない場合\n img_ = cv2.resize(img_,(48,48)) #48x48にリサイズ\n \n img_ = img_.astype(np.float32)/255\n temp=[]\n temp2=[]\n temp.append(img_)\n temp2.append(temp)\n img_ = np.array(temp2)\n return img_\n \n def score(image):\n img = loadimg(image)\n \n result = model.predictor(Variable(img))\n result = result.data[0] #それぞれの文字である確率?\n \n a_label = np.argsort(result)\n a_ratio = np.sort(result)\n \n a_label = a_label[-1::-1]\n a_ratio = a_ratio[-1::-1]\n return a_label, a_ratio\n \n```\n\n実行するときのコード(作業ディレクトリにカレントを移動している前提)\n\n```\n\n IMGName='test_ga.png'\n AL,AR = score(IMGName)\n \n print(IMGName,'の結果')\n for i in range(73):\n ans_l=AL[i]\n print(str(label[ans_l]),':',str(AR[i]))\n \n```\n\n結果\n\n```\n\n tegaki_na.pngの識別結果\n な:42.3303\n た:30.025\n は:26.0882\n あ:25.0445\n を:19.8176\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T06:51:34.520",
"favorite_count": 0,
"id": "39757",
"last_activity_date": "2018-10-02T02:00:00.643",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "25555",
"post_type": "question",
"score": 1,
"tags": [
"python",
"chainer"
],
"title": "chainerの画像認識 Classifier.predictorの値とは",
"view_count": 1851
} | [
{
"body": "<http://docs.chainer.org/en/stable/reference/generated/chainer.links.Classifier.html#chainer-\nlinks-classifier> \n<https://github.com/chainer/chainer/blob/v3.1.0/chainer/links/model/classifier.py#L71>\n\n`L.Classifier`の初期化子に与えた第1引数が`predictor`属性に格納されますから、質問のソースで言うと`model =\nL.Classifier(CNN.Model())`の`CNN.Model()`の部分ですね。 \n`convolution_model.py`の中の`Model`で、あなたが定義した値が出ているだけですよ。\n\n(言葉を換えると、`L.Classifier`はあなたが定義した識別モデルを渡されているだけ、ということです)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T09:49:16.540",
"id": "39764",
"last_activity_date": "2017-11-22T10:11:32.253",
"last_edit_date": "2017-11-22T10:11:32.253",
"last_editor_user_id": "12274",
"owner_user_id": "12274",
"parent_id": "39757",
"post_type": "answer",
"score": 1
}
]
| 39757 | null | 39764 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "GitHubを利用して複数のパソコンでXcodeのプロジェクトを使えるようにしたいと思っています。 \nそこで、ネット上のページを参考にGitHubの設定を進めています。SSHの鍵を取得するためにという段階でターミナルで次のコマンドを実行したところ下記のエラーが出ています。ネットで探しても解決できませんでした。解決法を御教示いただけますか。 \n(ネットのページは「今日からはじめるGitHub 〜\n初心者がGitをインストールして、プルリクできるようになるまでを解説」<https://employment.en-\njapan.com/engineerhub/entry/2017/01/31/110000>)\n\n環境は、Sierra 10.12.6 MacBook Airです。\n\nコマンド\n\n```\n\n $ ssh-keygen -t rsa -b 4096 -C \"(自分のメールアドレス)\"\n \n```\n\nエラー\n\n```\n\n Too many arguments.\n usage: ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa | rsa1]\n [-N new_passphrase] [-C comment] [-f output_keyfile]...\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T08:24:17.013",
"favorite_count": 0,
"id": "39759",
"last_activity_date": "2017-11-23T01:00:23.413",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13657",
"post_type": "question",
"score": 0,
"tags": [
"xcode",
"github"
],
"title": "macでのSSHの鍵取得で「Too many arguments.」対策",
"view_count": 2318
} | [
{
"body": "もう一度1文字1文字を確実に入力しなおし、「Option」+「-(ハイフン)」になっていないようにして入力し直したところエラーは出なくなりました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T01:00:23.413",
"id": "39773",
"last_activity_date": "2017-11-23T01:00:23.413",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13657",
"parent_id": "39759",
"post_type": "answer",
"score": 3
}
]
| 39759 | null | 39773 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "JavaScriptでブラウザのUAを判定しているページから、さらにリダイレクトすることは可能でしょうか? \n非対応ケータイ、対応ケータイで別にページを振り分けたいのです。\n\n1\\. ページに飛んで来て、まずUAを判定する \n2\\. 0秒ですぐリダイレクトする(Aだったらこっち、Bだったらこっち)\n\nクリックなどの動作なしには無理なのでしょうか。 \n質問がわかりずらく申し訳ないですがお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T08:50:22.820",
"favorite_count": 0,
"id": "39760",
"last_activity_date": "2017-11-22T10:58:11.960",
"last_edit_date": "2017-11-22T09:56:26.283",
"last_editor_user_id": "3060",
"owner_user_id": "26300",
"post_type": "question",
"score": 0,
"tags": [
"javascript"
],
"title": "JavaScriptでブラウザを判定して異なるページにリダイレクトする方法",
"view_count": 732
} | [
{
"body": "可能です。`window.location.href`で飛ばせば良いです。(ループしないように リダイレクトを設定して下さい。) \n例、ja.stackoverflow.com のいろいろな所へ飛ばす場合\n\n```\n\n var ua = navigator.userAgent;\n if(ua.indexOf('iPhone') > 0 || ua.indexOf('iPod') > 0 || ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0){\n //スマホのとき\n window.location.href = \"https://ja.stackoverflow.com/questions\";\n \n }else if(ua.indexOf('iPad') > 0 || ua.indexOf('Android') > 0){\n //タブレットのとき\n window.location.href = \"https://ja.stackoverflow.com/tags\";\n }else{\n //?\n window.location.href = \"https://ja.stackoverflow.com\";\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T09:42:32.913",
"id": "39763",
"last_activity_date": "2017-11-22T10:58:11.960",
"last_edit_date": "2017-11-22T10:58:11.960",
"last_editor_user_id": null,
"owner_user_id": "22793",
"parent_id": "39760",
"post_type": "answer",
"score": 2
}
]
| 39760 | null | 39763 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "今日から始めましたけど、 \n`<p>` \nって、何ですか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T09:14:06.460",
"favorite_count": 0,
"id": "39761",
"last_activity_date": "2017-11-24T00:00:33.860",
"last_edit_date": "2017-11-22T09:15:50.277",
"last_editor_user_id": "5044",
"owner_user_id": "26301",
"post_type": "question",
"score": 1,
"tags": [
"html"
],
"title": "&lt;p>",
"view_count": 1438
} | [
{
"body": "`<p>`ですね。\n\nHTMLの中にタグを表す文字列は書けないので、 \n文字参照と言われる表現で書きます。 \n`&`で始まり`;`で終わる形式でその間の部分は名前か数値(10進形式`#nn`か16進形式`#xhh`)で文字を表現します。 \n( [参考リンク](http://w-d-l.net/html__entities/) )\n\n`<`は、`<` \n`>`は、`>` \nなので \n`<p>`は、`<p>`を表すことになります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T09:26:21.847",
"id": "39762",
"last_activity_date": "2017-11-24T00:00:33.860",
"last_edit_date": "2017-11-24T00:00:33.860",
"last_editor_user_id": "5793",
"owner_user_id": "5044",
"parent_id": "39761",
"post_type": "answer",
"score": 3
}
]
| 39761 | null | 39762 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Cで木構造をつくるにあたって,\n\n```\n\n //ノード\n struct tnode\n {\n struct tnode *left;\n char *value;\n struct tnode *right;\n };\n \n struct tnode *talloc(void)\n {\n return (struct tnode *)malloc(sizeof(struct tnode));\n }\n \n struct tnode *gentree(struct tnode *p, char *w)\n {\n if(p==NULL)\n {\n //端に来たら生成\n p=talloc();\n strcpy(p->value, w);\n p->left = p->right = NULL;\n }\n else\n {\n //端じゃないなら左右にNULLまで走査\n p->left = gentree(p->left, w);\n p->right = gentree(p->right, w);\n }\n return p;\n }\n \n void main()\n {\n struct tnode *root;\n root = NULL;\n \n root=gentree(root, \"aaa\");\n printf(\"%s\\n\", root->value);\n putchar('\\n');\n \n root=gentree(root, \"bbb\");\n printf(\"%s\\n\", root->value);\n printf(\"%s\\n\", root->left->value);\n printf(\"%s\\n\", root->right->value);\n }\n \n```\n\nこのようにして作成しようとしてます. \n木の構造としては,aaaが2つのbbbに分岐してほしいのですが,実行結果は\n\n```\n\n aaa\n \n bbb //aaaであってほしい\n bbb\n bbb\n \n```\n\nと,どこかでaaaがbbbに書き換えられてしまいます.試しに以下のように書き換えアドレスを確認したところ,2つのアドレスは同じでした.\n\n```\n\n root=gentree(root, \"aaa\");\n printf(\"%d\\n\", root);\n \n root=gentree(root, \"bbb\");\n printf(\"%d\\n\", root);\n \n```\n\n初歩的なことかもしれませんが,どうかご回答お願いいたします.",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T15:08:32.963",
"favorite_count": 0,
"id": "39765",
"last_activity_date": "2017-11-23T01:14:07.633",
"last_edit_date": "2017-11-23T01:14:07.633",
"last_editor_user_id": "19110",
"owner_user_id": "23768",
"post_type": "question",
"score": 0,
"tags": [
"c"
],
"title": "Cで木構造をつくろうとしたが、ノードの値を上手く保存できていない",
"view_count": 127
} | [
{
"body": "えっと、ほんとに動きます?\n\n```\n\n //ノード\n struct tnode\n {\n struct tnode *left;\n char *value;\n struct tnode *right;\n };\n \n```\n\nvalueがポインタで割当されてません。\n\n手っ取り早い(効率等まるっと無視)のは、\n\n```\n\n strcpy(p->value, w);\n \n```\n\nの前に\n\n```\n\n p->value = malloc((strlen(w) + 1) * sizeof(char));\n \n```\n\nすることですね。\n\nメモリ割り当て複数回すると効率がーとか考え出すなら裏技として\n\n```\n\n //ノード\n struct tnode\n {\n struct tnode *left;\n struct tnode *right;\n char value[0];\n };\n \n struct tnode *talloc(size_t val_size)\n {\n return (struct tnode *)malloc(sizeof(struct tnode) + sizeof(char) * val_size);\n }\n \n```\n\nなんて方法もあります。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T16:01:57.277",
"id": "39766",
"last_activity_date": "2017-11-22T16:10:31.267",
"last_edit_date": "2017-11-22T16:10:31.267",
"last_editor_user_id": "26230",
"owner_user_id": "26230",
"parent_id": "39765",
"post_type": "answer",
"score": 1
}
]
| 39765 | null | 39766 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "JDKをインストールし、Pathに通したつもりなのですが、\n\n```\n\n Microsoft Windows [Version 10.0.15063]\n (c) 2017 Microsoft Corporation. All rights reserved.\n \n C:\\WINDOWS\\system32>javac -version\n 'javac' は、内部コマンドまたは外部コマンド、\n 操作可能なプログラムまたはバッチ ファイルとして認識されていません。\n \n```\n\nPathと表示してみても、\n\n```\n\n C:\\WINDOWS\\system32>path\n PATH=\";C:\\ Program Files\\java\\jdk-9.0.1\\\";;C:\\ Program Files\\java\\jdk-9.0.1\\\n \n C:\\WINDOWS\\system32>\n \n```\n\nと表示されてしまいます。 \n原因として考えられるのを調べたところ、\n\n 1. システムの環境変数でPathが通っているか確認\n 2. 確認時に`;`を忘れていないか\n 3. 確認時に、`;`は入れずに、`bin`と入力するのを忘れていないか\n 4. ユーザー環境変数のPathに入力\n 5. `Path-HOME`の環境変数に入力する\n\nとやってみましたができません。`java -version` は通るのですが、`javac -version`が通りません。\n\nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T16:38:50.623",
"favorite_count": 0,
"id": "39767",
"last_activity_date": "2017-11-25T11:53:35.990",
"last_edit_date": "2017-11-25T11:53:35.990",
"last_editor_user_id": "46",
"owner_user_id": "25848",
"post_type": "question",
"score": 1,
"tags": [
"java",
"コマンドプロンプト"
],
"title": "コマンドプロンプトでJDKが使えない",
"view_count": 1805
} | [
{
"body": "javac.exe は、デフォルトでは C:\\Program Files\\Java\\jdk-9.0.1\\bin\nフォルダの中にインストールされます。したがって、環境変数PATHには、C:\\Program\nFiles\\Java\\jdk-9.0.1ではなく、C:\\Program Files\\Java\\jdk-9.0.1\\bin を設定する必要があります。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T14:23:42.237",
"id": "39790",
"last_activity_date": "2017-11-23T14:23:42.237",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12309",
"parent_id": "39767",
"post_type": "answer",
"score": 3
},
{
"body": "結果、 \nJAVA_HOME を新規で”インストール先”と入力 \nその後に \npathに”インストール先bin”と入力したら通りました。バックスラッシュや;に関しては私の場合は必要なかったです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T07:24:40.150",
"id": "39821",
"last_activity_date": "2017-11-25T07:24:40.150",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "25848",
"parent_id": "39767",
"post_type": "answer",
"score": 0
}
]
| 39767 | null | 39790 |
{
"accepted_answer_id": "39781",
"answer_count": 1,
"body": "```\n\n class MLP(chainer.Chain):\n \n def __init__(self, n_units, n_out):\n super(MLP, self).__init__()\n with self.init_scope():\n self.l1 = L.Linear(None, n_units) \n self.l2 = L.Linear(None, n_units) \n self.l3 = L.Linear(None, n_out) \n \n def __call__(self, x):\n h1 = F.relu(self.l1(x))\n h2 = F.relu(self.l2(h1))\n return self.l3(h2)\n \n```\n\nchainerでモデルを作成している上記コードで`super(MLP,\nself).__init__`の意味がわかりません。`super()`はサブクラスからスーパークラスを参照して、スーパークラスを利用するという認識だったのですが、ここでは`super`がサブクラス`MLP`のなかで`MLP`を参照しています。どうしてでしょうか。また、`super(MLP,\nself).__init__`と`with self.init_scope()`の意味も合わせて教えていただきたいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T18:24:08.407",
"favorite_count": 0,
"id": "39769",
"last_activity_date": "2017-11-23T03:44:08.750",
"last_edit_date": "2017-11-23T03:44:08.750",
"last_editor_user_id": "14744",
"owner_user_id": "25909",
"post_type": "question",
"score": 3,
"tags": [
"python",
"chainer"
],
"title": "スーパークラスの参照について",
"view_count": 3005
} | [
{
"body": "## `super(MLP, self).__init__` について\n\nPython の組み込み関数 `super()` は引数を指定できます。正確性を犠牲にして簡単に説明すると、`super(aa, bb)` で「`bb`\nが属するクラス `aa` の親または兄弟クラス」のような意味になります。\n\n今回の場合、`super(MLP, self).__init__` は `super().__init__`\nとして想像されるものと同じ意味になります。引数を指定することで、`self` の属するクラス `MLP`\nのスーパークラスを表していると明示しています。これらの引数は Python 3 だと省略できるのですが、Python 2\nだと省略できません。このためたとえば、Python 2 でも 3 でも動くことが意識されたコードでは必ず明示的に引数を書きます。\n\nなお Python は多重継承を許しているため、Python の `super()` は他の多くのプログラミング言語における `super`\nとは挙動が異なります。詳細な説明は Python 3\nの[ドキュメント](https://docs.python.jp/3/library/functions.html#super)や、本家 \nStack Overflow の投稿 [\"Understanding Python super() with __init__()\nmethods\"](https://stackoverflow.com/q/576169/5989200) をご覧下さい。\n\n## `with self.init_scope()` について\n\nPython の [with 文](https://docs.python.jp/3/reference/compound_stmts.html#the-\nwith-statement)で、`as` が省略された場合の書き方です。with\n文は、処理が実行される前後に特定の処理を入れたい場合などに使われます。本家 Stack Overflow の [\"Meaning of “with”\nstatement without “as” keyword\"](https://stackoverflow.com/q/26342769/5989200)\nなどが分かりやすいと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T03:09:05.923",
"id": "39781",
"last_activity_date": "2017-11-23T03:09:05.923",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "39769",
"post_type": "answer",
"score": 2
}
]
| 39769 | 39781 | 39781 |
{
"accepted_answer_id": "39818",
"answer_count": 1,
"body": "```\n\n clf = DecisionTreeClassifier(criterion='entropy', max_depth=1) \n sklearn.ensemble.BaggingClassifier(base_estimator=clf, n_estimators=10, max_samples=1, max_features=1)\n \n```\n\n上記のパラメータbase_estimator=clf1, n_estimators=10, max_samples=1,\nmax_features=1はそれぞれ何を表しているのでしょうか。 \nn_estimatorsは決定木の個数、\nmax_samplesはそれぞれの決定木に使われる(抽出サンプル数/全体数)という割合、max_featuresはそれぞれの決定木に使われる(抽出サンプルの特徴量数/全体の特徴量数)という割合であっていますでしょうか。\n\nまた、上記理解が正しい場合、さらに以下の疑問があります。 \nmax_samples=1のとき全体が抽出されるので、自動的に特徴量もmax_features=1になるような気がしており、どちらか一つの特徴量で良いのではないかと思っています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-22T19:09:39.290",
"favorite_count": 0,
"id": "39770",
"last_activity_date": "2017-11-25T02:05:50.663",
"last_edit_date": "2017-11-24T00:01:58.000",
"last_editor_user_id": "25909",
"owner_user_id": "25909",
"post_type": "question",
"score": 1,
"tags": [
"python",
"scikit-learn"
],
"title": "BaggingClassifierのパラメーターについて",
"view_count": 1389
} | [
{
"body": "それぞれ\n\n * base_estimator 基となる推定器\n * n_estimators 基となる推定器の数\n * max_samples 各推定器を訓練する時に用いるサンプル数\n * max_features 各推定器を訓練する時に用いる特徴量の数\n\nになります。\n\nただし、max_samplesとmax_featuresは、intの場合とfloatの場合で意味が変わります。intで与えた場合は絶対数を、floatで与えた場合は全体に対する割合を指します。\n\nより詳しい情報は[公式ドキュメント](http://scikit-\nlearn.org/stable/modules/generated/sklearn.ensemble.BaggingClassifier.html)をご覧ください。\n\n> また、上記理解が正しい場合、さらに以下の疑問があります。 \n>\n> max_samples=1のとき全体が抽出されるので、自動的に特徴量もmax_features=1になるような気がしており、どちらか一つの特徴量で良いのではないかと思っています。\n\nmax_samples=1.0としてもmax_features=1.0とはなりませんし、どちらか一つで良いとはなりません。\n\nサンプルと特徴量の違いを意識する必要があります。1行に1つのデータを持つ表形式の典型的なデータセットがあるとします。これがn行m列のデータセットであるとします。\n**サンプル** は各行に対応します。1行が1サンプルなので、このケースではnサンプルあることになります。一方、 **特徴量**\nは各列に対応します。1列が1特徴量なので、このケースではm個の特徴量があることになります。\n\nmax_samples=1.0の場合、n個すべてのサンプルを用いることを意味します。ただし、これは必ずしもm個すべての特徴量を用いるという意味ではありません。用いる特徴量の個数はmax_featuresで指定します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T02:05:50.663",
"id": "39818",
"last_activity_date": "2017-11-25T02:05:50.663",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26246",
"parent_id": "39770",
"post_type": "answer",
"score": 2
}
]
| 39770 | 39818 | 39818 |
{
"accepted_answer_id": "39774",
"answer_count": 1,
"body": "```\n\n n=1;\n while(n<=5)\n cout<< n << '';\n n++;\n \n```\n\n上記コードですが、 \n`1 2 3 4 5`と表示されると思いきや、なぜか`1 1 1 1 1 1 ・・・`と表示されてしまいます。 \n理由をご教示頂けますと幸いです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T00:51:10.990",
"favorite_count": 0,
"id": "39772",
"last_activity_date": "2017-11-23T01:23:43.490",
"last_edit_date": "2017-11-23T01:03:17.937",
"last_editor_user_id": "19110",
"owner_user_id": "26303",
"post_type": "question",
"score": 0,
"tags": [
"c++"
],
"title": "c++のwhile文が無限ループしてしまう",
"view_count": 538
} | [
{
"body": "ループする範囲を中括弧で囲んでください。\n\n元々のコードは以下の形をしています。\n\n```\n\n while (n <= 5)\n cout << n << ' ';\n n++;\n \n```\n\nこのコードでは、while 文によってループするのは `cout << n << ' ';`\nの行のみです。ループする範囲を中括弧で指定しない場合、while 文のすぐ次の部分 **のみ**\nがループすることになります。分かりやすくインデントを付けて書くと、以下のようなネスト構造になっています。\n\n```\n\n while (n <= 5)\n cout << n << ' '; /* この行のみが while ループの範囲内 */\n n++; /* この行は while ループの外 */\n \n```\n\n次のように中括弧で囲むように書くと、`cout << n << ' ';` と `n++;`\nの2行が共にループするようになります。構造の分かりやすさのためにインデントも付けています。\n\n```\n\n while (n <= 5) {\n cout << n << ' ';\n n++;\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T01:02:52.577",
"id": "39774",
"last_activity_date": "2017-11-23T01:23:43.490",
"last_edit_date": "2017-11-23T01:23:43.490",
"last_editor_user_id": "19110",
"owner_user_id": "19110",
"parent_id": "39772",
"post_type": "answer",
"score": 6
}
]
| 39772 | 39774 | 39774 |
{
"accepted_answer_id": "39786",
"answer_count": 1,
"body": "現在、以下のようなルートの設定で\n\n```\n\n use Illuminate\\Routing\\Router;\n \n Admin::registerHelpersRoutes();\n \n Route::group([\n 'prefix' => config('admin.prefix'),\n 'namespace' => Admin::controllerNamespace(),\n 'middleware' => ['web', 'admin'],\n ], function (Router $router) {\n \n $router->get('/', 'HomeController@index');\n $router->resource('section', SectionController::class);\n \n });\n \n```\n\n<http://127.0.0.1:8000/admin/section> \n<http://127.0.0.1:8000/admin/section/create> \n<http://127.0.0.1:8000/admin/section/1/edit>\n\nなどでアクセスできるようになっているのですが \n例えば新たに画面を作成し \n<http://127.0.0.1:8000/admin/section/batch_create> \nといったような形でアクセス可能にするにはどのようにすればよいのでしょうか? \n一括でデータをインサートできるような画面を作成したいのですが\n\n単純にコントローラに\n\n```\n\n public function batch_create()\n \n```\n\nするだけでは駄目でした・・。\n\nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T09:05:56.967",
"favorite_count": 0,
"id": "39785",
"last_activity_date": "2017-11-23T10:57:49.583",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26236",
"post_type": "question",
"score": 0,
"tags": [
"php",
"laravel"
],
"title": "Laravelのルート設定について",
"view_count": 133
} | [
{
"body": "```\n\n Route::group([\n 'prefix' => config('admin.prefix'),\n 'namespace' => Admin::controllerNamespace(),\n 'middleware' => ['web', 'admin'],\n ], function (Router $router) {\n \n $router->get('/', 'HomeController@index');\n $router->resource('section', SectionController::class);\n $router->get('selection/batch_create', 'SelectionController@batchCache'); // 追加\n \n });\n \n```\n\nのようにアクション毎にルートを追加します。(提示されている条件だとこのほかpostのルートも必要かも) \n詳しくは[ドキュメント](https://readouble.com/laravel/5.5/ja/routing.html)を。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T10:57:49.583",
"id": "39786",
"last_activity_date": "2017-11-23T10:57:49.583",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2376",
"parent_id": "39785",
"post_type": "answer",
"score": 0
}
]
| 39785 | 39786 | 39786 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "現在あるサービスの管理サイトを作成しようと考えています。 \nこの管理サイトはJavaScriptのSPAで構築しようとしています。以下にサービスの概要を書きます。\n\nバックエンドのAppサーバ \nドメイン: backend.example.com \nサーバ仕様: JSONによりデータベースに変更を加えたりデータを取得したりする。\n\n管理サイトのAppサーバ \nドメイン: admin.example.com \nサーバ仕様: 上記のバックエンドサーバのAPIを呼び出すことによってデータを追加したり閲覧したりする。\n\n管理サイトはBasic\nAuthでエントリーページとなるindex.htmlは認証できますが、JavascriptAPIの認証はどのように実装すればいいのでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T13:39:09.217",
"favorite_count": 0,
"id": "39788",
"last_activity_date": "2017-11-23T15:20:19.973",
"last_edit_date": "2017-11-23T15:20:19.973",
"last_editor_user_id": "7232",
"owner_user_id": "7232",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"security"
],
"title": "管理サイトにおけるAPIの認証について",
"view_count": 60
} | []
| 39788 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "いつもお世話になっております。\n\n以下のコードはどのような書式名なのか分かりますでしょうか? \nクロージャーの初期化でもないようで、(=がない為) \n調べても分からなかったのでご質問させて頂きました。\n\n```\n\n var value: String? { return \"abc\" }\n print(value!) // abc\n \n```\n\nよろしくお願い致します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T14:07:57.777",
"favorite_count": 0,
"id": "39789",
"last_activity_date": "2017-11-23T14:35:36.067",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20142",
"post_type": "question",
"score": 0,
"tags": [
"swift3"
],
"title": "「変数名 + ブロック」の書式名称が分かりません",
"view_count": 50
} | [
{
"body": "すみません。 \n自己解決しました。\n\nプロパティのget,setの記述方法で、getを省略した記述になります。 \nこの場合、読み取り専用となります。\n\n<https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html>\n\n```\n\n var value: String? { return \"abc\" }\n print(value!)\n //value = \"ABC\" ...読み取り専用なのでエラーする\n \n```\n\nありがとうございました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T14:35:36.067",
"id": "39792",
"last_activity_date": "2017-11-23T14:35:36.067",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20142",
"parent_id": "39789",
"post_type": "answer",
"score": 1
}
]
| 39789 | null | 39792 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "位置情報と日付を投げると過去の天気情報を取得できるAPIを探しています。 \nUnityで開発しているためC#で書かれてある参考サイトなどが嬉しいです。\n\nよろしくお願いします",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-23T14:27:29.753",
"favorite_count": 0,
"id": "39791",
"last_activity_date": "2017-12-08T02:48:56.787",
"last_edit_date": "2017-11-24T05:17:59.103",
"last_editor_user_id": "76",
"owner_user_id": null,
"post_type": "question",
"score": 0,
"tags": [
"c#",
"api"
],
"title": "過去の天気情報を取得できる無料のAPIを探しています",
"view_count": 5021
} | [
{
"body": "APIではないですが、国土交通省・気象庁のこのページでデータの検索やダウンロードが出来るようです。\n\nホーム > 各種データ・資料 > 過去の気象データ検索 \n<http://www.data.jma.go.jp/obd/stats/etrn/index.php> \nホーム > 各種データ・資料 > 過去の気象データ・ダウンロード \n<http://www.data.jma.go.jp/gmd/risk/obsdl/index.php>\n\nホーム > 案内・申請 > 情報ご利用ガイド \n<http://www.jma.go.jp/jma/kishou/usage_info/guide_top.html>\n\nなお、迅速に答えが欲しいならば、何人にもコメントされているように、 \n質問の背景とか、やりたいこと・欲しいものの細かい条件とかも記述しておく方が良いでしょう。 \nまた、検索は誰でも簡単に出来るので、自分で行った検索結果を示して、 \nどれが近いとか、これは条件が合わないとかの情報も付加すると良いと思います。\n\n例えば検索すればこんなのが直ぐに出てきます。\n\n商用利用可能な気象データ・天気APIの入手先一覧まとめ \n<http://sounansa.net/archives/1326>\n\nWebサイト制作やアプリ開発で使える天気予報APIのまとめ \n<http://hello-apis.blogspot.jp/2013/03/webapi.html>\n\nただし、どちらのサイトにもあるように、「商用利用=有料」ですし、 \n商用ではなくても、作ったサービスを公開して広く使えるようにしたり、 \n個人でも高頻度に使用して、提供元の業務に支障が出るようだと、最悪は \n逮捕・起訴などが考えられます。\n\nしばらく前に図書館の購入書籍案内に個人利用だが1分毎にアクセスに \n行って、システム自身の作りの弱さも手伝ってサービスをダウンさせて \n逮捕などされてた件が有名だと思います。\n\n十分に注意してください。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-08T02:48:56.787",
"id": "40124",
"last_activity_date": "2017-12-08T02:48:56.787",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26370",
"parent_id": "39791",
"post_type": "answer",
"score": 1
}
]
| 39791 | null | 40124 |
{
"accepted_answer_id": "39801",
"answer_count": 2,
"body": "与えられた文字列について、UTF-8に定義されているがShiftJIS(正確にはCP932)に定義されていない文字があるかどうか検出する方法はありますか? \n文字コードの変換のやり方は結構見つかりますが、ちゃんと変換できたのかどうかを判定したいのです。 \n※ShiftJISしか使えない旧システムとの連携があるため、「旧システムに渡せない文字」をユーザが入力したとき、弾けるように・・・ \nJava8を使っています。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T02:36:38.723",
"favorite_count": 0,
"id": "39795",
"last_activity_date": "2018-01-26T18:23:11.147",
"last_edit_date": "2017-11-24T05:37:03.510",
"last_editor_user_id": "8078",
"owner_user_id": "8078",
"post_type": "question",
"score": 4,
"tags": [
"java"
],
"title": "ShiftJISに無い文字を検出する方法",
"view_count": 9682
} | [
{
"body": "UTF-8の入力文字列(Java内部ではUnicode)をCP932バイト列に変換して、それを再度UTF-8に変換(逆変換)して、同じ内容にならなければ、その差分が定義されていない文字と判定する方法があると思います。\n\n#変換中にExceptionが発生すれば、その時点で定義されていない文字が含まれていることがわかります。\n\nただ、「旧システム」がCP932文字ならすべて受け取れるのか怪しいので、通常は流通可能な文字集合(ホワイトリスト)を規定して、入力文字(を変換したもの)をホワイトリストと比較する方法の方が確実かと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T06:48:13.277",
"id": "39801",
"last_activity_date": "2017-11-24T06:48:13.277",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20098",
"parent_id": "39795",
"post_type": "answer",
"score": 6
},
{
"body": "「文字列`s`がCP932(`MS932`)に変換できるかを調べる」ためのコード:\n\n```\n\n if (Charset.forName(\"MS932\").newEncoder().canEncode(s)) {\n // 変換可能\n } else {\n // 変換不能\n }\n \n```\n\n「文字列`s`をCP932(`MS932`)のバイト列に変換する、ただし変換不能ならその旨を伝える」ためのコード:\n\n```\n\n try {\n ByteBuffer bb = Charset.forName(\"MS932\").newEncoder()\n .onUnmappableCharacter(CodingErrorAction.REPORT)\n .encode(CharBuffer.wrap(s)); // ByteBufferを得る\n byte[] ba = bb.array(); // byte配列を得る\n } catch(CharacterCodingException e) {\n // 変換不能だった\n }\n \n```\n\n※「変換可能」とは「`String#getBytes()`で正常に(`?`に化けずに)変換可能」を指します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2018-01-26T18:23:11.147",
"id": "41232",
"last_activity_date": "2018-01-26T18:23:11.147",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "27076",
"parent_id": "39795",
"post_type": "answer",
"score": 1
}
]
| 39795 | 39801 | 39801 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "### 前提・実現したいこと\n\n`navigator.geolocation.watchPosition`でエラーが発生すると`PositionError`が発生しますがPositionErrorがどこにも定義されておらず困っています。\n\n`$q.defer( (resolve,reject) =>\nnavigator.geolocation.watchPosition(resolve,reject)\n)`の様なコードがあったとしてSPAでwatchしてる最中にページ移動した場合`reject`を呼びたいと思います。 \nrejectの定義は`function reject(error:PositionError)`としたいですよね?\n\nそこでページ遷移のイベントをフックして`reject( new PositionError(3,'Timeout')\n)`(疑似コード)を発生させたいと思いますが`PositionError`の所在が分からないので困っています。\n\n前述通り`error instanceOf PositionError`が通る形で解決策を探しております。\n\n[MDN](https://developer.mozilla.org/ja/docs/Web/API/Geolocation)のGeolocation関係のドキュメントは確認済みですがそれっぽい情報は見当たりませんでした。",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T05:38:50.037",
"favorite_count": 0,
"id": "39797",
"last_activity_date": "2017-11-24T05:38:50.037",
"last_edit_date": "2020-06-17T08:14:45.997",
"last_editor_user_id": "-1",
"owner_user_id": "3671",
"post_type": "question",
"score": 0,
"tags": [
"javascript"
],
"title": "PositionErrorはどこに定義さてるのでしょうか?",
"view_count": 69
} | []
| 39797 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "プログラム初心者です。 \nMonacaのサンプルにあるTODO管理アプリで、追加した写真や文字が一度閉じるとリセットされ消えます。閉じた後再度開いても残っているようにしたいのですが、プログラムや方法を教えてください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T06:26:31.817",
"favorite_count": 0,
"id": "39799",
"last_activity_date": "2020-10-03T15:04:15.383",
"last_edit_date": "2017-11-24T06:29:42.073",
"last_editor_user_id": "76",
"owner_user_id": "26313",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"monaca"
],
"title": "MonacaのTODO管理アプリで写真や文字を保持する方法",
"view_count": 397
} | [
{
"body": "はじめまして。MonacaのTODO管理アプリとのことですが、以下のURLにあるもので間違いないでしょうか?\n\n<https://docs.monaca.io/ja/sampleapp/samples/todo/>\n\nウェブサイトを一度閉じるとすべてリセットされてしまうというのは、入力されたデータが保存(永続化)されていないためです。MonacaはHTMLとJavaScriptでアプリを開発するためのフレームワークですので、JavaScriptを使ってデータの保存をしたければ、[LocalStorage](https://developer.mozilla.org/ja/docs/Web/API/Window/localStorage)などを使って、データの永続化をしてみるのをおすすめします。LocalStorageを使うことで、データの保存と読み出しを行うことができるようになるので、TODOを追加する際に保存、アプリを開く際に読み込みを行うことで、入力したデータを残すことができます。\n\nまた、こちらのQiitaの記事なども参考になります \n<https://qiita.com/masamitsu-konya/items/c69515604570150d3ab9>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T06:40:49.680",
"id": "39800",
"last_activity_date": "2017-11-24T06:40:49.680",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13444",
"parent_id": "39799",
"post_type": "answer",
"score": 1
}
]
| 39799 | null | 39800 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "CakePHPv2.5.5でUnitTestを行っています。\n\n**構成**\n\ndatabases.php\n\n```\n\n public $xxxx = array(\n // ...\n );\n public $test_xxxx = array(\n 'datasource' => 'Database/MysqlExportDb',\n 'persistent' => false,\n 'host' => 'localhost',\n 'login' => 'root',\n 'password' => 'root',\n 'database' => 'test',\n 'prefix' => '',\n 'encoding' => 'utf8',\n );\n \n```\n\nFixture定義\n\n```\n\n class KeywordFixture extends CakeTestFixture\n {\n public $useDbConfig = 'test_xxxx';\n \n public $fields = array(...);\n \n public $records = array(...);\n }\n \n```\n\nテストコード側\n\n```\n\n class ShellTest extends CakeTestCase\n {\n public $fixtures = array(\n 'plugin.search_export.keyword',\n );\n ...\n \n```\n\n**現象1**\n\nkeywordsテーブルが存在しない状態でテストを実行すると以下のエラーが発生します。\n\n> MissingTableException: Table keywords for model Keyword was not found in\n> datasource test_xxxx.\n\n**現象2**\n\n手動でkeywordsテーブルを作成して実行を行うと、テストが正しく実行された後keywordsテーブルが消滅します。\n\n**質問**\n\n現象2でテーブルが消えていることから何らかの形でFixtureは認識されていると考えています。 \nしかしテーブルの生成が行われない原因が分かりません。 \n考えられる原因を教えてください。\n\n<https://book.cakephp.org/2.0/ja/development/testing.html#id15>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T07:43:43.320",
"favorite_count": 0,
"id": "39803",
"last_activity_date": "2018-01-19T09:46:49.643",
"last_edit_date": "2018-01-19T09:46:49.643",
"last_editor_user_id": "7566",
"owner_user_id": "7566",
"post_type": "question",
"score": 0,
"tags": [
"cakephp",
"phpunit"
],
"title": "CakePHPのFixtureにおいてテーブルの生成が行われない",
"view_count": 1273
} | [
{
"body": "`useDbConfig` を指定されていることから、以下の現象ではないでしょうか。\n\n> 結論: \n> FixtureのuseDbConfigでDataSourceを指定するには、対になるDataSourceが定義されてないと駄目でした。 \n> 例) \n> $test_hoge = array(/* ... _/); なら $hoge = array(/_ ... */); \n> が定義されてないと駄目。\n\nCakePHP の $useDbConfig にはまった(備忘録) - nmtysh.log\n<http://nmtysh.hatenablog.com/entry/2013/11/27/005000>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T03:27:44.847",
"id": "39875",
"last_activity_date": "2017-11-27T03:27:44.847",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2668",
"parent_id": "39803",
"post_type": "answer",
"score": 1
}
]
| 39803 | null | 39875 |
{
"accepted_answer_id": "39805",
"answer_count": 1,
"body": "pythonを始めたばかりの未熟者です。 \n画像の赤と青を入れ替えるというプログラムなのですが、下記のプログラムを実行すると\n\n```\n\n Traceback (most recent call last):\n File \"exer1.py\", line 15, in <module>\n H = img.shape[0]\n AttributeError: 'NoneType' object has no attribute 'shape'\n \n```\n\nとなるのですがどう直せばいいのでしょうか \n自分が手を加えたのはfor文の中だけなので改善するのはその中でお願いします。\n\n```\n\n import numpy as np\n import sys\n import cv2\n \n fname_in = sys.argv[1]\n fname_out = sys.argv[2]\n \n img = cv2.imread(fname_in)\n \n H = img.shape[0]\n W = img.shape[1]\n \n for y in range(H) : \n for x in range(W) : \n r = img[y,x,2]\n g = img[y,x,1]\n b = img[y,x,0]\n img[y,x,0] = r \n img[y,x,2] = b\n # ここを編集\n \n cv2.imwrite(fname_out, img )\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T10:09:31.600",
"favorite_count": 0,
"id": "39804",
"last_activity_date": "2017-11-24T13:36:53.373",
"last_edit_date": "2017-11-24T13:36:53.373",
"last_editor_user_id": "19110",
"owner_user_id": "26315",
"post_type": "question",
"score": 0,
"tags": [
"python"
],
"title": "画像の高さを取得するとエラー AttributeError: 'NoneType' object has no attribute 'shape'",
"view_count": 44446
} | [
{
"body": "エラーメッセージでは`img =\ncv2.imread(fname_in)`で画像の読み込みに失敗したせいか、imgがNoneになっていると思われます。実行時の引数に存在している画像ファイルを渡しているか確認して見てください。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T10:28:39.623",
"id": "39805",
"last_activity_date": "2017-11-24T10:28:39.623",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26311",
"parent_id": "39804",
"post_type": "answer",
"score": 1
}
]
| 39804 | 39805 | 39805 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "お世話になります。 \n現在VisulStudio2015のC++を使って数値計算を行っているのですが、スペルや文法のエラーがコンパイル前のチェックでは問題なかったのに、ビルドを行おうとするとほぼすべての変数が変数として認識されなくなってしまいました。(定義されていない識別子です)。 \n何度も確認しましたが文法も間違った感じではなく、どうしてこのようなことが起こるのかわからないでいます。 \n対処法を押しえてください。よろしくお願いいたします。\n\n```\n\n #pragma once\n #include <iostream>\n #include <fstream>\n #include <cstdlib>\n #include <vector>\n #include <string>\n #include <cmath>\n #include <complex>\n #include <numeric>\n #include <functional>\n #include <map>\n #include <tuple>\n #include <algorithm>\n \n #define Alpha 0.06 //線形損失[cm-1]\n const double pi=3.141592653;\n const double e0=8.854*1e-12;\n const double u0=4*pi*1e-7;\n const double c = 299792458; //Light Speed\n const double h = 6.62607004e-34; //Planck Number\n const double g = 30.; //Raman Gain\n complex<double> j(0, 1);\n const double cross_section = (220e-9*445e-9) / (1e-2*1e-2); //[cm2]\n using namespace std;\n \n namespace fanctions {\n /*自然ラマン散乱*/\n auto seed = [](double pump, double cs) {return (13e-9*pump - 4.5e-11)*1e-9 / cs; };\n \n /*セルマイヤーの分散式*/\n auto n = [](double Lambda) {return sqrt(11.6858 + 0.939816 / method::nijo(Lambda) + 0.00810461*method::nijo(Lambda) / (nijo(Lambda) - method::nijo(1.1071))); };\n \n /*基本式*/\n //ストークス光\n auto f_Est = [](complex<double> Est, complex<double> Epump, complex<double> East, const double k, const double z, const double alpha_TPA){ return g / 2 * (conj(Epump)*Est + conj(East)*Epump*exp(j*k*z))*Epump - 0.5*(Alpha + alpha_TPA)*Est; };\n //レイリー散乱光\n auto f_Epump = [](complex<double> Est, complex<double> Epump, complex<double> East, const double omega_st, const double omega_ly, const double alpha_TPA){return g / 2 * (omega_ly / omega_st)*(norm(East) - norm(Est))*Epump - 0.5*(Alpha + alpha_TPA)*Epump; };\n //アンチストークス光\n auto f_East = [](complex<double> Est, complex<double> Epump, complex<double> East, const double k, const double z, const double omega_st, const double omega_ast, const double alpha_TPA){return -g / 2 * (omega_ast / omega_st)*(Epump*conj(Est)*exp(j*k*z) + Est*conj(Epump))*Epump - 0.5*(Alpha + alpha_TPA)*East; };\n \n /*ロスなし方程式*/\n //ストークス光\n auto non_loss_f_Est = [](complex<double> Est, complex<double> Epump, complex<double> East, const double k, const double z) { return g / 2 * (conj(Epump)*Est + conj(East)*Epump*exp(j*k*z))*Epump; };\n //レイリー散乱光\n auto non_loss_f_Epump = [](complex<double> Est, complex<double> Epump, complex<double> East, const double omega_st, const double omega_ly) {return g / 2 * (omega_ly / omega_st)*(norm(East) - norm(Est))*Epump; };\n //アンチストークス光\n auto non_loss_f_East = [](complex<double> Est, complex<double> Epump, complex<double> East, const double k, const double z, const double omega_st, const double omega_ast) {return -g / 2 * (omega_ast / omega_st)*(Epump*conj(Est)*exp(j*k*z) + Est*conj(Epump))*Epump; };\n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T11:39:30.917",
"favorite_count": 0,
"id": "39806",
"last_activity_date": "2017-11-24T21:20:06.787",
"last_edit_date": "2017-11-24T12:53:41.517",
"last_editor_user_id": "4236",
"owner_user_id": "19263",
"post_type": "question",
"score": -1,
"tags": [
"c++",
"visual-studio"
],
"title": "C++コンパイルエラー(定義されていない識別子です)",
"view_count": 3553
} | [
{
"body": "エラーメッセージと該当行を提示していただかないことには正確なことはわかりませんが、\n\n>\n```\n\n> /*セルマイヤーの分散式*/\n> auto n = [](double Lambda) {return sqrt(11.6858 + 0.939816 /\n> method::nijo(Lambda) + 0.00810461*method::nijo(Lambda) / (nijo(Lambda) -\n> method::nijo(1.1071))); };\n> \n```\n\n`method`が宣言されていませんが`method::nijo()`にアクセスしています。また`nijo()`も宣言されていません。\n\n* * *\n\n> スペルや文法のエラーがコンパイル前のチェックでは問題なかった\n\n[`IntelliSense`](https://msdn.microsoft.com/ja-\njp/library/hcw1s69b\\(v=vs.120\\).aspx)のことでしょうか?C# /\nVB.NETにおいて同機能は実際のコンパイラーを用いての解析となるためほぼ確実な事前チェックが行えますが、C++言語では言語の特性上、完全な解析は不可能です(複数回\n`#include`\nされた場合に何回目の解析結果を示すのか、など)。また解析自体もVC++コンパイラーではなく[EDG](https://www.edg.com/c)というツールが使われているため完全には一致していません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T12:53:16.517",
"id": "39808",
"last_activity_date": "2017-11-24T21:20:06.787",
"last_edit_date": "2017-11-24T21:20:06.787",
"last_editor_user_id": "4236",
"owner_user_id": "4236",
"parent_id": "39806",
"post_type": "answer",
"score": 3
}
]
| 39806 | null | 39808 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Google Maps JavaScript APIでサイト内に地図を表示させたいのですが、基本認証がかかっているサイトでは表示できないのでしょうか? \n一瞬表示されるのですが、「エラーが発生しました」となり、エラーコンソールに「Your site URL to be authorized」と出ます。\n\nどうかお力添えの程よろしくお願い申し上げます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T11:50:40.203",
"favorite_count": 0,
"id": "39807",
"last_activity_date": "2022-03-22T21:03:35.380",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13282",
"post_type": "question",
"score": 0,
"tags": [
"google-maps"
],
"title": "Google Maps JavaScript API が表示されない",
"view_count": 816
} | [
{
"body": "google maps apiは一般公開サイトにおいてはフリーで使えるものなので、認証をかけたときにはそういった症状になる可能性があります \n<https://developers.google.com/maps/support/availability?hl=ja>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T12:54:36.867",
"id": "39826",
"last_activity_date": "2017-11-25T12:54:36.867",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12233",
"parent_id": "39807",
"post_type": "answer",
"score": 1
}
]
| 39807 | null | 39826 |
{
"accepted_answer_id": "39935",
"answer_count": 1,
"body": "【やりたいこと】 \nxcodeのプロジェクトをGitHubにPushし、他のパソコンでも同じプロジェクトを使えるようにしたい。 \n【経過】 \nネット上の「XcodeからgitとGitHubを使う方法・基本編」「今日からはじめるGitHub 〜\n初心者がGitをインストールして、プルリクできるようになるまでを解説」 を参考に、GitHubへのSSH接続を確認するまではできました。 \n【問題点】 \nxcodeでcommitやbranchはできるのですが、Pushができません。 \nxcodeのmenu>sourceControl>pushと進んで、Pushのところを開けてもPushLocalChangeの下がNo remotes\navailableとなっていて、選択できません。 \n【やったこと】 \n・ネットで探しましたが、解決できません。(xcodeのmenu>sourceControl>でプロジェクトが出るという記事がありましたが、ここにプロジェクトは出てこないのです。) \n・Xcodeのメニューから> Preferences> Source Controlと開いてGitを確認すると自分の名前とメアドが入っています。 \n・cloneが作れるのではないかと思い、GitHubでプロジェクトのURLをコピーし、それをxcodeのSource\nControl>cloneで開いてみましたが、「reference 'refs/heads/master' not found (-9)」とエラーでした。\n\n【環境】 \nMacBookAir Sierra10.12.6 xcode9.0",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T13:01:06.927",
"favorite_count": 0,
"id": "39810",
"last_activity_date": "2017-11-29T13:10:10.120",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13657",
"post_type": "question",
"score": 0,
"tags": [
"xcode",
"github"
],
"title": "xcodeでGitHubにPushしたいのですが、No remotes availableとなっています。",
"view_count": 1635
} | [
{
"body": "Pushするには、Remotesに何か(通常はorigin)を設定する必要があります。 \n左上の左から2番目のアイコンを選択して、branchやtagやremoteの管理ツリーを開き、remoteをcontrol+クリックして、「Create\n\"xxx\" Remote on GitHub...」か「Add Existing Remote...」で設定してください。 \n[](https://i.stack.imgur.com/cAxYr.png)\n\n参考:[[iOS 11] Xcode\n9で“だいぶまとも”に!新機能をまとめてみた](https://dev.classmethod.jp/smartphone/iphone/xcode-9-new-\nfeatures/#toc-github)",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T13:10:10.120",
"id": "39935",
"last_activity_date": "2017-11-29T13:10:10.120",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7900",
"parent_id": "39810",
"post_type": "answer",
"score": 1
}
]
| 39810 | 39935 | 39935 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Google Site Searchは2018年3月にサービス終了となるため、移行先を検討しています。\n\nGoogleカスタム検索であれば無料で使えますが、コーポレートサイトのサイト内検索のために導入しているため、他社広告が出るのはNGという案件です。\n\nもし同じ境遇の方がいらっしゃれば、移行先のサービスを教えて頂けますでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T15:28:09.193",
"favorite_count": 0,
"id": "39812",
"last_activity_date": "2017-11-24T15:28:09.193",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "32",
"post_type": "question",
"score": 1,
"tags": [
"google-api"
],
"title": "Google Site Search廃止後の移行先について",
"view_count": 81
} | []
| 39812 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Pythonとpandasの以下のプログラムに関する質問です。\n\n以下の6つの変数は異なる期間とデータを持つ、index が datetimeindex の Series です。 \n1~3の違いは期間が異なり、aとbはデータが異なります。\n\nseason_a1 \nseason_b1\n\nseason_a2 \nseason_b2\n\nseason_a3 \nseason_b3\n\n```\n\n from pandas import DataFrame\n import numpy as np\n \n #結果を格納するDataFrame\n result_df1 = DataFrame(index=np.arange(0, 24))\n result_df2 = DataFrame(index=np.arange(0, 24))\n result_df3 = DataFrame(index=np.arange(0, 24))\n \n \n for year in range(2000, 2004):\n \n if str(year) in season_b1.index:\n a1 = season_a1[str(year)].index.hour.value_counts().sort_index()\n b1 = season_b1[str(year)].index.hour.value_counts().sort_index()\n result_df1['A' + str(year)] = a1\n result_df1['B' + str(year)] = b1\n # 1\n \n if str(year) in season_b2.index:\n a2 = season_a2[str(year)].index.hour.value_counts().sort_index()\n b2 = season_b2[str(year)].index.hour.value_counts().sort_index()\n result_df2['A' + str(year)] = a2\n result_df2['B' + str(year)] = b2\n # 2\n \n if str(year) in season_b3.index:\n a3 = season_a3[str(year)].index.hour.value_counts().sort_index()\n b3 = season_b3[str(year)].index.hour.value_counts().sort_index()\n result_df3['A' + str(year)] = a3\n result_df3['B' + str(year)] = b3\n # 3\n \n result_df1.to_csv(path1)\n result_df2.to_csv(path2)\n result_df3.to_csv(path3)\n \n```\n\n単純にvalue_counts()で集計した結果の\n\na1, b1 は、 result_df1 に。 \na2, b2 は、 result_df2 に。 \na3, b3 は、 result_df3 に。\n\n列として追加していき、 csvファイルとして出力するだけです。\n\n欲しい結果としては、result_df1~3 の結果が全て異なるものになって欲しいのですが、 \nそれぞれ元となるデータも変数名も異なるのに、 \n出力される結果が全て result_df3 の内容と同じになってしまいます。\n\n確認として、# 1~3 の部分で result_df1~3 の内容を print() してみたのですが、 \n1回目のループの # 2 のところで既に result_df1 が result_df2 と同じになっていて \n# 3 のところでは result_df1 , result_df2 も result_df3 と同じになっています。\n\n初歩的なミスだとは思うのですが、解決できません。 \n申し訳ございませんが、よろしくお願いいたします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-24T19:46:56.933",
"favorite_count": 0,
"id": "39814",
"last_activity_date": "2019-03-07T03:02:10.347",
"last_edit_date": "2017-11-25T07:26:28.120",
"last_editor_user_id": "26318",
"owner_user_id": "26318",
"post_type": "question",
"score": -1,
"tags": [
"python",
"python3",
"pandas",
"numpy"
],
"title": "Pythonでforループを使ってDataFrameを作成すると、異なる変数が全て同じ結果になる。",
"view_count": 1568
} | [
{
"body": "コメントにもあるように再現可能な最小限のコードがないと正確な回答をするのは難しいですが、例えば以下の部分で\n\n```\n\n result_df1 = DataFrame(index=np.arange(0, 24))\n result_df2 = DataFrame(index=np.arange(0, 24))\n result_df3 = DataFrame(index=np.arange(0, 24))\n \n```\n\n次のようになっていると、同じような現象が起こると思います。\n\n```\n\n result_df1 = DataFrame(index=np.arange(0, 24))\n result_df2 = result_df1\n result_df3 = result_df1\n \n```\n\n初期化時にこのようにしてしまうと、Pythonは参照を代入するのでresult_dfはすべて同一の値を持ちます。したがってすべて最後に代入したresult_df3の値になります。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T01:18:59.767",
"id": "39816",
"last_activity_date": "2017-11-25T01:18:59.767",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26246",
"parent_id": "39814",
"post_type": "answer",
"score": 0
}
]
| 39814 | null | 39816 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "MacをHigh Sierraにアップデートしたところ、`/tmp`の下にあった`mysql.sock`が消えてしまいました。 \nアンインストールして再インストールしたら直るかと思いましたが、sockファイルが生成されません。 \nそのためにmysqlが使えないのですが、どうしたら良いでしょうか。\n\n追記 \n`home brew`が悪さしているのかもしれないです。`brew info mysql`で以下のエラーが出ました。\n\n```\n\n mysql: stable 5.7.20 (bottled), devel 8.0.3-rc\n Open source relational database management system\n https://dev.mysql.com/doc/refman/5.7/en/\n Conflicts with:\n mariadb (because mysql, mariadb, and percona install the same binaries.)\n mariadb-connector-c (because both install plugins)\n mysql-cluster (because mysql, mariadb, and percona install the same binaries.)\n mysql-connector-c (because both install MySQL client libraries)\n percona-server (because mysql, mariadb, and percona install the same binaries.)\n /usr/local/Cellar/mysql/5.7.20 (324 files, 233.7MB) *\n Poured from bottle on 2017-11-25 at 09:34:57\n From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb\n ==> Dependencies\n Build: cmake ✘\n Required: openssl ✔\n ==> Requirements\n Required: macOS >= 10.7 ✔\n ==> Options\n --with-archive-storage-engine\n Compile with the ARCHIVE storage engine enabled\n --with-blackhole-storage-engine\n Compile with the BLACKHOLE storage engine enabled\n --with-debug\n Build with debug support\n --with-embedded\n Build the embedded server\n --with-local-infile\n Build with local infile loading support\n --with-test\n Build with unit tests\n --devel\n Install development version 8.0.3-rc\n ==> Caveats\n We've installed your MySQL database without a root password. To secure it run:\n mysql_secure_installation\n \n MySQL is configured to only allow connections from localhost by default\n \n To connect run:\n mysql -uroot\n \n To have launchd start mysql now and restart at login:\n brew services start mysql\n Or, if you don't want/need a background service you can just run:\n mysql.server start\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-11-25T00:24:13.857",
"favorite_count": 0,
"id": "39815",
"last_activity_date": "2019-09-09T04:05:30.727",
"last_edit_date": "2019-07-23T08:25:31.887",
"last_editor_user_id": "7676",
"owner_user_id": "25545",
"post_type": "question",
"score": 0,
"tags": [
"mysql",
"macos"
],
"title": "mysql.sockが消えた。",
"view_count": 297
} | [
{
"body": "自己解決しました。 \nrootだとmysql server起動できませんでした。 \n権限を全て自分のユーザー名にしたら解決しました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T01:28:04.507",
"id": "39817",
"last_activity_date": "2017-11-25T01:28:04.507",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "25545",
"parent_id": "39815",
"post_type": "answer",
"score": 1
}
]
| 39815 | null | 39817 |
{
"accepted_answer_id": "39856",
"answer_count": 1,
"body": "**前提**\n\n 1. form1にラベルとボタンを配置\n 2. ボタンクリックでform2を表示\n 3. form2にはデータを設定したリストボックスを配置済み\n\n**質問** \nform2のリストボックスのある行を選択した時、その行にあるデータをform1のラベルにセットしたい\n\n**コード**\n\n```\n\n sub listbox1_click\n form1.label1.text = listbox1.selectitem\n end sub\n \n```\n\n**結果**\n\n> error BC30469: 非共有メンバーを参照するには、オブジェクト参照が必要です。\n\n広域変数を用意した別モジュールを作成して、その中でform2を呼び出してデータを受け渡す方法を考えていますが、form2だけで完結する記述方法はありませんか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T04:11:23.897",
"favorite_count": 0,
"id": "39819",
"last_activity_date": "2017-11-26T11:19:16.857",
"last_edit_date": "2017-11-25T14:50:38.630",
"last_editor_user_id": "19110",
"owner_user_id": "25794",
"post_type": "question",
"score": 0,
"tags": [
"vb.net"
],
"title": "リストボックスの値を呼び出し元のフォームにあるラベルに表示",
"view_count": 1011
} | [
{
"body": "まず前提知識としてVB.NETでWindows\nFormsアプリケーションを作成した場合、フォームのデフォルトインスタンスと呼ばれるものが生成されます。これにより`Form`に定義されているインスタンスメンバーに`Shared`の文法でアクセスできます。おそらく質問のコードでは\n\n```\n\n Form2.Show()\n \n```\n\nのような呼び出しがあると思われますが、これは実質的に\n\n```\n\n My.Forms.Form2.Show()\n \n```\n\nという処理です。同様に`Form1`のインスタンスメンバーには`My.Forms.Form1`からアクセスすればよく、`Form1.Label1`のアクセスレベルは既定では`Friend`ですので単純に`Form2`内から\n\n```\n\n My.Forms.Form1.Label.Text = \"test\"\n \n```\n\nのように記述するのがVB.NETのコンテキストでは一番簡潔になります。\n\n* * *\n\nなおVB.NETのアプリケーションフレームワークに依存しないコードの場合は\n\n * `Form2`に目的の値(コントロール自体ではなく)を公開するプロパティを定義する\n * `Form2`をモードレス(`form.Show()`)で表示する場合、上記プロパティの変更イベントを定義する\n * `Form1`側で`ShowDialog`終了時または上記イベント発生時にプロパティ値を読み出すコードを記述する\n\nのがベストだと思います。この方針であれば`Form1`に関する処理を`Form2`に記述する必要がありませんし、`Form2`のコントロールを`Form1`に対して隠ぺいすることもできます。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T10:27:04.567",
"id": "39856",
"last_activity_date": "2017-11-26T10:35:05.503",
"last_edit_date": "2017-11-26T10:35:05.503",
"last_editor_user_id": "5750",
"owner_user_id": "5750",
"parent_id": "39819",
"post_type": "answer",
"score": 0
}
]
| 39819 | 39856 | 39856 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "pythonでopenweathermapから天気予報を取るプログラムの勉強をしています。ですが401エラーがでてしまい先に進むことができません。401エラーは「許可されていない」との情報をインターネットで見たのですが、サイトへのログインはしています。\n\nログインしているのに「許可されてない」となる理由がわからないのですが、なぜ「許可されていない」エラーになるのか、わかる方がいましたら回答いただけないでしょうか?\n\n```\n\n import json, requests, pprint\n APPID = '-'#APIキーの定義\n url = 'http://api.openweathermap.org/data/2.5/forecast/daily?q={}&cnt=3&appid={}'.format('Akashi-shi,jp', APPID)\n response = requests.get(url)\n response.raise_for_status()\n \n weather_data = json.loads(response.text)\n pprint.pprint(weather_data)\n \n```\n\n* * *\n\n解決しました。【URLの表記ミスでした】 \n書籍の内容と公式ドキュメントでは表記に違いがありました。今度からは公式ドキュメントは必ず確認しようと思いました。\n\n```\n\n # × → url ='http://api.openweathermap.org/data/2.5/forecast/daily?q={}&cnt=3&appid={}'.format('London', APPID)\n url ='http://api.openweathermap.org/data/2.5/weather?q={}&appid={}'.format('London', APPID)\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T10:06:51.087",
"favorite_count": 0,
"id": "39823",
"last_activity_date": "2018-06-07T07:49:12.277",
"last_edit_date": "2017-11-25T11:50:45.427",
"last_editor_user_id": "26076",
"owner_user_id": "26076",
"post_type": "question",
"score": 0,
"tags": [
"python",
"json"
],
"title": "pythonでのJSONデータの取得がうまくいきません。助けてほしいです。",
"view_count": 593
} | [
{
"body": "エラーメッセージによると有効なAPPIDが設定されてないためのようです。こちらのサービスには詳しくありませんが、下記のリンクにある指示に従ってアカウントを作成し、APPIDを取得する必要があるのではないでしょうか。\n\n<http://openweathermap.org/faq>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T11:30:33.203",
"id": "39824",
"last_activity_date": "2017-11-25T11:30:33.203",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26311",
"parent_id": "39823",
"post_type": "answer",
"score": 1
}
]
| 39823 | null | 39824 |
{
"accepted_answer_id": "39829",
"answer_count": 2,
"body": "x = 2, y = 1, z = 0 のとき、\n\n```\n\n cout<< “answer =” <<(x||!y&&z)<< endl;\n \n```\n\nがどのように出力されるかについての質問です。\n\n出力してみると、answer = 1となるのですが、なぜこのような結果となるかご教示いただけますと幸いです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T13:07:24.507",
"favorite_count": 0,
"id": "39827",
"last_activity_date": "2018-01-23T01:21:40.557",
"last_edit_date": "2018-01-23T01:21:40.557",
"last_editor_user_id": "19110",
"owner_user_id": "26303",
"post_type": "question",
"score": 1,
"tags": [
"c++"
],
"title": "C++で異なる論理演算子を同時に使ったときの挙動が理解できない",
"view_count": 857
} | [
{
"body": "演算子には下記サイトにあるような優先順位があります。 \nここを手がかりに、式`(x||!y&&z)`の`||`と`!`と`&&`が評価される順番を整理してみてはいかがでしょうか。\n\n<https://msdn.microsoft.com/ja-jp/library/126fe14k.aspx>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T13:41:52.690",
"id": "39829",
"last_activity_date": "2017-11-25T13:41:52.690",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26311",
"parent_id": "39827",
"post_type": "answer",
"score": 0
},
{
"body": "演算子の優先順位は\n\n`!` > `&&` > `||`\n\nです。なので\n\n> !y\n>\n\n>> false\n\n>\n> !y && z\n>\n\n>> false\n\n>\n> x || !y && z\n>\n\n>> true\n\nとなります。つまり\n\n> (x || ((!y) && z))\n\nですね。\n\nなお GCCで`-Wall -Wextra`をつけてコンパイルすると\n\n```\n\n prog.cc: In function 'int main()':\n prog.cc:10:31: warning: suggest parentheses around '&&' within '||' [-Wparentheses]\n cout<< \"answer =\" <<(x||!y&&z)<< endl;\n ~~^~~\n \n```\n\nのように怒られます。またClangで同様に`-Wall -Wextra`をつけてコンパイルすると\n\n```\n\n prog.cc:10:31: warning: '&&' within '||' [-Wlogical-op-parentheses]\n cout<< \"answer =\" <<(x||!y&&z)<< endl;\n ~~~~^~~\n prog.cc:10:31: note: place parentheses around the '&&' expression to silence this warning\n cout<< \"answer =\" <<(x||!y&&z)<< endl;\n ^\n ( )\n 1 warning generated.\n \n```\n\nのように怒られます。実に親切なエラーメッセージですね!",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T13:49:27.223",
"id": "39830",
"last_activity_date": "2017-11-25T13:49:27.223",
"last_edit_date": "2020-06-17T08:14:45.997",
"last_editor_user_id": "-1",
"owner_user_id": "23941",
"parent_id": "39827",
"post_type": "answer",
"score": 2
}
]
| 39827 | 39829 | 39830 |
{
"accepted_answer_id": "39832",
"answer_count": 1,
"body": "```\n\n 1.bash\n Last login: Sat Nov 25 22:23:12 on ttys001\n -bash: eval: line 43: syntax error: unexpected end of file\n \n```\n\niterm2を開いた時に上記のようにsyntax errorが表示されます。 \n対処方法を教えて下さい、よろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T13:37:52.743",
"favorite_count": 0,
"id": "39828",
"last_activity_date": "2017-11-25T14:58:18.647",
"last_edit_date": "2017-11-25T14:51:21.580",
"last_editor_user_id": "19110",
"owner_user_id": "25422",
"post_type": "question",
"score": 0,
"tags": [
"bash"
],
"title": "iterm2を開いた時に上記のようにsyntax errorが表示されます。",
"view_count": 612
} | [
{
"body": "`~/.bashrc` や `~/.profile` など、bash\nが立ち上がる際に読み込まれるファイルの中身をよく読んでください。エラーメッセージにあるように、43行目が怪しいです。`unexpected end of\nfile` とエラーが出ているので、閉じカッコが不足していたり、`if` に対応する `fi` が無かったりなどしていないか確認してください。\n\niTerm2 ということは macOS だと思いますが、その場合、見た目で良いように見えても、ダブルクォーテーションが `\"` ではなく `“` や `”`\nになっていることがあるので、その点にもお気をつけください。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T14:58:18.647",
"id": "39832",
"last_activity_date": "2017-11-25T14:58:18.647",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "39828",
"post_type": "answer",
"score": 2
}
]
| 39828 | 39832 | 39832 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "```\n\n for i in range(5)\n \n```\n\nで出力される\n\n```\n\n 0\n 1\n 2\n 3\n 4\n \n```\n\nという結果を以下のように1行の行列に変換したいです。\n\n```\n\n [0,1,2,3,4]\n \n```\n\n宜しくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T15:07:07.267",
"favorite_count": 0,
"id": "39834",
"last_activity_date": "2018-08-17T03:02:32.970",
"last_edit_date": "2017-11-25T21:46:56.063",
"last_editor_user_id": "19110",
"owner_user_id": "26328",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "rangeなどで作成した変数を行列に変換したい",
"view_count": 1015
} | [
{
"body": "rangeを使って連続した数値を持つリストを作成する、というご質問でしたら下記の方法が使えます。\n\n```\n\n list(range(5))\n \n```\n\n目的がリストではなくnumpyの行列でしたら、\n\n```\n\n import numpy\n numpy.array(range(5))\n \n```\n\nといった方法があります。\n\n* * *\n\n追記2017/11/26\n\n```\n\n A=[]\n idx=0\n while idx<4:\n A.append(idx+1)\n idx += 1\n print(A)\n \n```",
"comment_count": 9,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T15:26:26.143",
"id": "39835",
"last_activity_date": "2017-11-25T16:55:39.180",
"last_edit_date": "2017-11-25T16:55:39.180",
"last_editor_user_id": "26311",
"owner_user_id": "26311",
"parent_id": "39834",
"post_type": "answer",
"score": 2
}
]
| 39834 | null | 39835 |
{
"accepted_answer_id": "39838",
"answer_count": 2,
"body": "```\n\n int number = 6;\n number++;\n cout << number << endl;\n \n```\n\n上記コードは7と出力されます。\n\n一方、\n\n```\n\n int number = 6;\n int x = 0;\n x =number++;\n cout << x << endl;\n \n```\n\n上記コードは6と出力されます。\n\nどちらのコードも7と出力されると思っていただけに \nなぜこのような違いが生じるかご教示いただけますと幸いです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T15:43:34.080",
"favorite_count": 0,
"id": "39837",
"last_activity_date": "2018-01-23T01:25:14.523",
"last_edit_date": "2018-01-23T01:25:14.523",
"last_editor_user_id": "19110",
"owner_user_id": "26303",
"post_type": "question",
"score": 0,
"tags": [
"c++"
],
"title": "後置インクリメント演算子の使い方によって結果が変わるのは何故?",
"view_count": 401
} | [
{
"body": "それが前置演算子ではなく後置演算子だからです。\n\n[関数の創世から深淵まで駆け抜ける関数とはなんぞや講座 -\nQiita#演算子を関数のように解釈してみよう](https://qiita.com/yumetodo/items/cdfb41781d32d98be1b4#%E6%BC%94%E7%AE%97%E5%AD%90%E3%82%92%E9%96%A2%E6%95%B0%E3%81%AE%E3%82%88%E3%81%86%E3%81%AB%E8%A7%A3%E9%87%88%E3%81%97%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T15:45:11.897",
"id": "39838",
"last_activity_date": "2017-11-25T15:45:11.897",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "23941",
"parent_id": "39837",
"post_type": "answer",
"score": 2
},
{
"body": "C++ において、\n\n * 前置インクリメント `++number` は、`number` をインクリメントし、インクリメントされた値を返します。\n * 後置インクリメント `number++` は、`number` をインクリメントし、元の値のコピーを返します。\n\nしたがって、後者のプログラムの `x = number++;` という部分では、`number` の値である `6` が \n`x` に代入されると共に、副作用として `number` がインクリメントされます。したがって `x` には `6` が代入されているので、`cout\n<< x << endl;` では `6` が出力されます。\n\nこれに対して、もし `x = ++number;` と書いた場合、`x` には `7` が代入されることになります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T21:45:34.147",
"id": "39843",
"last_activity_date": "2017-11-25T21:45:34.147",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "39837",
"post_type": "answer",
"score": 4
}
]
| 39837 | 39838 | 39843 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "以下のプログラムで出力された結果を1行の行列として出力したいと考えています。 \n`niter`であれば、`[1,2,3,4,5,6,7....19,20]`のような行列で \n`rnorm`であれば、`[1.2340014751660304,0.9402715810329509...,1.0]`のような行列です。 \n宜しくお願い致します。\n\n```\n\n import math as ma\n \n d = 2500\n x = 2500 \n area = 100 \n e = 5e5 \n f = 0 \n resid = 0 \n nincr = 1 \n fincr = 1.5e7 \n cnorm = 1e-20 \n miter = 20 \n \n lzero = ma.sqrt(x**2 + d**2) \n vol = area*lzero \n stiff = (area/lzero)*e*(x/lzero)*(x/lzero) \n for incrm in range(1,nincr+1):\n f = f + fincr \n resid = resid - fincr \n \n rnorm = cnorm*2 \n niter = 0\n while ((rnorm > cnorm) and (niter < miter)):\n niter = niter+1\n u = resid/stiff\n x = x+u\n l = ma.sqrt(x*x + d*d)\n area = vol/l\n stress = e*ma.log(l/lzero)\n t = stress*area*x/l\n resid = t-f\n rnorm = abs(resid/f)\n stiff = (area/l)*(e-2*stress)*(x/l)*(x/l) + (stress*area/l)\n \n print(niter)\n print(rnorm)\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T17:23:31.740",
"favorite_count": 0,
"id": "39841",
"last_activity_date": "2017-11-25T17:59:54.707",
"last_edit_date": "2017-11-25T17:28:39.437",
"last_editor_user_id": "3060",
"owner_user_id": "26328",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "一つの変数に入った複数の値を、1行の行列としてまとめたい",
"view_count": 69
} | [
{
"body": "とりあえず動くコードだとこんな感じです。`rnorm[-1]`は`rnorm`の一番最後の要素を取り出します。変更した後半だけ書いておきます。\n\n```\n\n rnorm = [cnorm*2] \n niter = [0]\n while ((rnorm[-1] > cnorm) and (niter[-1] < miter)):\n niter.append(niter[-1]+1)\n u = resid/stiff\n x = x+u\n l = ma.sqrt(x*x + d*d)\n area = vol/l\n stress = e*ma.log(l/lzero)\n t = stress*area*x/l\n resid = t-f\n rnorm.append(abs(resid/f))\n stiff = (area/l)*(e-2*stress)*(x/l)*(x/l) + (stress*area/l)\n \n print(niter)\n print(rnorm)\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-25T17:59:54.707",
"id": "39842",
"last_activity_date": "2017-11-25T17:59:54.707",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26311",
"parent_id": "39841",
"post_type": "answer",
"score": 0
}
]
| 39841 | null | 39842 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Mac 10.12.6で treeコマンドを使用しています。 \nその際に-Cのオプションを使用して実行するとファイルの種類ごとに \n色分けをしてくれるのですが、この色を変更したい場合には \nLinuxでの設定は問題ないのですが、 \nmacの場合にはどのファイルを編集すればよいのでしょうか? \nmanで書かれている下記のディレクトリにはファイルがないようです。\n\n`/etc/DIR_COLORS System color database.`\n\nまた自分で設定しているLSCOLORSとは別の色でtreeコマンドは出力されています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T02:31:34.630",
"favorite_count": 0,
"id": "39845",
"last_activity_date": "2017-11-26T08:20:30.537",
"last_edit_date": "2017-11-26T05:22:21.067",
"last_editor_user_id": "76",
"owner_user_id": "26264",
"post_type": "question",
"score": 0,
"tags": [
"macos"
],
"title": "mac treeコマンド 色の変更の仕方",
"view_count": 324
} | [
{
"body": "macOS自体にtreeコマンドは付いてこないようなので、HomebrewやMacPortsでインストールしたものだと思いますが、 `LSCOLORS`\nではなく `LS_COLORS` (`_` がある)ではないでしょうか?\n\n↓MacPortsのtree(1)↓\n\n> Tree is a recursive directory listing program that produces a depth indented \n> listing of files, which is colorized ala dircolors if the LS_COLORS\n> environment \n> variable is set and output is to tty.\n\nここにも書かれていますが、端末に出力する場合はオプションなしで色付けされるようです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T08:20:30.537",
"id": "39852",
"last_activity_date": "2017-11-26T08:20:30.537",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "17037",
"parent_id": "39845",
"post_type": "answer",
"score": 2
}
]
| 39845 | null | 39852 |
{
"accepted_answer_id": "39854",
"answer_count": 4,
"body": "Qiita\nのページを見ていると、そのままコピーして手元の開発に使いたくなるようなコードを見かけたりなどします。OSS系のソースを書いていた場合には、そのコピーしたコードを組み込みながら、レポジトリを公開したくなります。\n\n# 質問\n\n * Qiita に投稿されている記事の中の、ソースコードを利用するにあたってのライセンス的な規定はどうなっていますか?\n * 特に、公開レポジトリに組み込むことはできますか?その場合の制約は何になりますか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T05:37:57.927",
"favorite_count": 0,
"id": "39847",
"last_activity_date": "2020-01-12T12:18:54.947",
"last_edit_date": "2017-11-26T12:54:41.363",
"last_editor_user_id": "754",
"owner_user_id": "754",
"post_type": "question",
"score": 9,
"tags": [
"ライセンス"
],
"title": "Qiita のページに載っているスクリプトのライセンスは?",
"view_count": 6443
} | [
{
"body": "Qiitaの規約については、Qiitaに確認するのが確実です、という点に留意の上で、 \n公開されている情報([Qiitaの利用規約ページ](https://qiita.com/terms))にそれらしい記載がありましたので、引用しておきます。\n\n> 第9条(ユーザーによる投稿内容の取扱い) \n> 2\\.\n> ユーザーは、当社に対し、投稿内容について、無償にて利用(複製、複写、改変、第三者への再許諾その他のあらゆる利用を含む。)する権利を許諾するものとします。本項に基づく、ユーザーの当社への利用許諾の範囲には、本サービスを通じて、当社が他のユーザーに対して投稿内容の利用を再許諾することも含むものとします。特に、ユーザーは本サイトに投稿したコード、スニペットなどプログラムに類するものは他のユーザーが商用私用問わず使用することを許諾し、他のユーザーはこれを使用できるものとします。これにより、ユーザーは、本サービス上で他のユーザーが投稿した投稿内容を、当社の定める方法で編集、改変、複製することができるようになります。\n\n投稿内容が著作権等に違反していないのが前提ですが、投稿内容は制限なく利用できる、と記載されていると思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T06:37:17.740",
"id": "39849",
"last_activity_date": "2017-11-26T07:13:26.460",
"last_edit_date": "2017-11-26T07:13:26.460",
"last_editor_user_id": "19110",
"owner_user_id": "20098",
"parent_id": "39847",
"post_type": "answer",
"score": 1
},
{
"body": "Qiitaの利用規約には不明確な点があるので、Qiitaに問いあわせる必要があります。少なくとも「制限無く利用できる」という解釈は誤りです。\n\n> 第9条(ユーザーによる投稿内容の取扱い) \n> 2\n> ユーザーは、当社に対し、投稿内容について、無償にて利用(複製、複写、改変、第三者への再許諾その他のあらゆる利用を含む。)する権利を許諾するものとします。本項に基づく、ユーザーの当社への利用許諾の範囲には、本サービスを通じて、当社が他のユーザーに対して投稿内容の利用を再許諾することも含むものとします。特に、ユーザーは本サイトに投稿したコード、スニペットなどプログラムに類するものは他のユーザーが商用私用問わず使用することを許諾し、他のユーザーはこれを使用できるものとします。これにより、ユーザーは、本サービス上で他のユーザーが投稿した投稿内容を、当社の定める方法で編集、改変、複製することができるようになります。\n\n最後の文がどこにかかっているのか、また「当社の定める方法」が何を指すのか不明です。\n\nコードに対する定めにもこの文がかかっていると解釈すると、商用私用問わず使用することが許諾されていることにはなりますが、使用の方法については「当社の定める方法」に制限されます。\n\n> 5\n> 第2項から前項までの規定にかかわらず、ユーザは以下のライセンスに準拠する投稿内容を本サービスに投稿することができます。その場合、投稿内容の権利については当該ライセンスの定めに従うものとし、ユーザは投稿内容が当該ライセンスに違反していないことについて当社に保証するものとします。 \n> (1)Creative Commons \n> (a)表示 \n> (b)表示 - 継承 \n> (2)GNU GPL \n> (3)BSDライセンス及び修正BSDライセンス \n> (4)前各号のライセンスに準ずるライセンスであって当社の認めるもの\n\n投稿内容にこれらのライセンスが指定されている場合それらのライセンスによる制限が発生します。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T09:03:09.230",
"id": "39854",
"last_activity_date": "2017-11-27T01:29:53.773",
"last_edit_date": "2017-11-27T01:29:53.773",
"last_editor_user_id": "5793",
"owner_user_id": "5793",
"parent_id": "39847",
"post_type": "answer",
"score": 11
},
{
"body": "すでに引用がある箇所を解釈すると\n\n投稿者Aの投稿した記事のうち\n\n 1. Qiitaで認められているライセンスの明示がある場合=>それに従う\n 2. 記事中に含まれる **ソースコードの類** =>`商用私用問わず使用することを許諾`\n 3. ソースコード類ではない記事部分(解説文章等)=>Qiitaの編集リクエスト機能のように編集、改変、複製できる\n\nとなります。\n\n@suzukis 氏は\n\n> 少なくとも「制限無く利用できる」という解釈は誤りです。\n\nと書かれていますが **特に投稿者がQiitaで認められているライセンスを明示していない場合制限なく利用できる**\n、と解するべきでしょう。ただ気になるのはCCで言うところのBYの部分ですね。SAとNCとNDは否定されていますが・・・。\n\n@user20098 氏は\n\n> 投稿内容が著作権等に違反していないのが前提ですが\n\nと書いていますがこれは語弊があり、正確には\n\n 1. 記事が二次利用の場合→許諾なしでの二次利用なら記事そのものがアウト、許諾ありなら上記解釈どおり\n 2. 記事が二次創作の場合→二次創作物としての記事は上記解釈に従うと **同時に** 一次創作物の許諾条件の制約を受ける\n\nが留意するべき点です。\n\n* * *\n\n> CC 系などが明記してあれば、著作者がライセンスを直指定しているので、多分普通に web サイトで CC\n> などで公開されているのと同じ扱いで良い気がしています。\n\n上述のとおり明示されたライセンスがQiita指定のものならばそれに従う\n\n> 何も指定がなかった場合は、ちょっと確認の必要がありそうだ、と思ってます。\n\n上述 `2.`, `3.`のとおり",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T15:23:52.807",
"id": "39865",
"last_activity_date": "2017-11-28T02:17:39.807",
"last_edit_date": "2017-11-28T02:17:39.807",
"last_editor_user_id": "23941",
"owner_user_id": "23941",
"parent_id": "39847",
"post_type": "answer",
"score": 4
},
{
"body": "解決ずみになっていますが、質問内容と回答が気になったので・・・\n\n> 公開レポジトリに組み込むことはできますか?その場合の制約は何になりますか?\n\n最近、英語圏のオープンソースプロジェクトでは ライセンスに気を付けて作業している事が多いようです。 \nLinux カーネルや git 等では コミットの下に\n\n```\n\n Signed-off-by: ユーザ名 <メールアドレス>\n \n```\n\nのような署名を付けて、開発者による コードのライセンスの正当性を確認したものだけを \n取り込むようにしています。\n\n[OSSコミュニティのリスク対策](http://ossforum.jp/node/803)\n\nにも書かれていますが、開発者によってライセンスの明示されていないソースは 利用しないことが \n安全だと思います。\n\n* * *\n\nQiita の利用規約では 投稿できるけど、投稿者に責任があると明記しています。 \n投稿者が ライセンスを明記していない投稿は 利用しない方が安全です。\n\n[利用規約 - Qiita](https://qiita.com/terms) より 投稿者の責任に関する部分を抜粋\n\n> 第7条(ユーザーの責任) \n>\n> 5.ユーザーが他人の名誉を毀損した場合、プライバシー権を侵害した場合、著作権法に違反する行為を行った場合、その他他人の権利を侵害した場合、当該ユーザーは自身の責任と費用において解決しなければならず、当社は一切の責任を負いません。 \n>\n> 6.ユーザーが、他者及びユーザー自身が本サービス上に投稿、コメントした情報やプログラムの使用によって不利益が生じた場合、当該ユーザー自身に責任があるものとし、当社は一切の責任を負いません。\n>\n> 第8条(禁止事項) \n> 4.ユーザーは、本サービスの「Qiita」を利用するに際し、以下のような行為を行ってはなりません。 \n> (1)他者の著作権や機密情報、その他の権利を侵害する情報を掲載する行為\n>\n> 第9条(ユーザーによる投稿内容の取扱い) \n>\n> 1.ユーザーは、本サービスを利用して本サイト上に投稿した投稿、コメント、公開プロフィールの自己紹介などのテキストデータ、および画像や動画・音声ファイルなどの投稿テキストに付随的に投稿されたデータ(以下「投稿内容」といいます。)について、自らが投稿又は送信することについての適法な権利を有していること、及び投稿内容が第三者の権利を侵害しないことについて、表明し、保証するものとします。\n\n* * *\n\nちなみに stackoverflow は投稿する内容は \n[CC-BY-SAクリエイティブコモンズライセンス条項](https://creativecommons.org/licenses/by-sa/4.0/) \nに違反しないことと、投稿者が著作者であるもの を制約としているように \n(Google 翻訳した日本語では)読み取れます。\n\n一部でも GPL のソースを コピー&ペーストして 回答してはいけません。\n\n[https://meta.stackoverflow.com/questions/287986/posting-gpl-code-in-an-\nanswer?noredirect=1&lq=1](https://meta.stackoverflow.com/questions/287986/posting-\ngpl-code-in-an-answer?noredirect=1&lq=1) \nを Google 翻訳した抜粋\n\n```\n\n 要するに:いいえ、ここにGPLコードを投稿することはできません。\n \n FSF は、CC-BY-SAがGPLと互換性がないと見なします\n (ページ上部のキーに示されているように、ページの左側にある黄色の破線はこれを示します)。\n これは、事実を立証する実際の裁判とは異なりますが、次善策です。\n \n Stack Exchangeの利用規約では、CC-BY-SAに基づくすべての貢献のライセンスを取得する必要があります。\n 選ぶことはできません(つまり、「このコードはGPLですが、私の答えの残りはCC-BY-SAです」)。\n \n 投稿の小さなサンプルコードの量は、4つの要因に応じて、公正使用の下で法的かもしれません。\n しかし、これは複雑な問題であり、プログラマーはしばしば間違いを犯します\n (特に、コメントを読まずにメタ投稿にリンクされているものを支持することによって)。\n \n フェアユースは常にケースバイケースで評価されます。\n つまり、あなたが明確にいることを絶対に確認する唯一の方法は、訴えられて勝つことです。\n おそらくそれはしたくないでしょう。\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2020-01-12T11:52:17.663",
"id": "62190",
"last_activity_date": "2020-01-12T12:18:54.947",
"last_edit_date": "2020-01-12T12:18:54.947",
"last_editor_user_id": "18851",
"owner_user_id": "18851",
"parent_id": "39847",
"post_type": "answer",
"score": 1
}
]
| 39847 | 39854 | 39854 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "[マルチポスト](https://teratail.com/questions/102083?modal=q-comp) \nUnityで解像度800×600のゲームを作っています。 \n現在フルスクリーンに対応するため色々やっているのですが,どうしても画像が横に伸びてしまいます。 \n解像度は保ったまま,余分な部分は黒帯を入れたいです。 \nどうすれば,比率を保ったままフルスクリーンで表示できるでしょうか?\n\n以下のURLを参考にしたのですが,やはり画像が伸びます。 \n<http://tsubakit1.hateblo.jp/entry/2014/12/24/233000> \nScreen.SetResolution(800, 600, true); \n[](https://i.stack.imgur.com/hu2af.png)\n\n以下はCanvasの設定です。 \n[](https://i.stack.imgur.com/cbHmn.png)\n\nテスト環境はこちらです。 \n<https://drive.google.com/open?id=11RwuILr_rV0VttWp1pwJzEneOK8Nk0bk>",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T06:02:23.677",
"favorite_count": 0,
"id": "39848",
"last_activity_date": "2017-11-29T05:51:57.890",
"last_edit_date": "2017-11-29T05:51:57.890",
"last_editor_user_id": "19110",
"owner_user_id": "8100",
"post_type": "question",
"score": 0,
"tags": [
"unity3d",
"unity2d"
],
"title": "解像度を保ったままフルスクリーンで表示する",
"view_count": 927
} | []
| 39848 | null | null |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Realm入門という本の「06_モデルオブジェクトの生成と初期化」の下記サンプルコードをダウンロードして使おうとXcode9.1で開いた所、エラーが出て前に進めません。解決方法を御教示頂けないでしょうか。\n\n### エラー内容\n\nModelCreationのViewController.swift/import RealmSwiftのところに\n\n```\n\n Module compiled with Swift 3.0.2 cannot be imported in Swift 3.2.2\n \n```\n\n### 試したこと\n\nネットで探して以下の4点を試しました。 \n①`carthage bootstrap --platform iOS --no-use-binaries` \n(結果→`-bash: carthage: command not found`) \n②`$ brew update`/`$ brew install carthage`をやった(結果→ `command not found`。) \n③`Carthage.pkg` をダウンロードしてインストール後に①(結果→ `command not found`。) \n④`build holder`のクリーン後に①(結果→ `command not found`。)\n\n環境 MacBookPro HighSierra10.13.1 Xcode9.1\n\n```\n\n import UIKit\n import RealmSwift\n \n class Person: Object {\n dynamic var name = \"\"\n dynamic var age = 0\n dynamic var dog: Dog? // Dogモデルと1対1の関連\n let cats = List<Cat>() // Catモデルと1対多の関連\n }\n \n class Animal: Object {\n dynamic var name = \"\"\n dynamic var age = 0\n }\n \n class Dog: Animal {\n }\n \n class Cat: Animal {\n }\n \n class ViewController: UIViewController {\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n // MARK: - 6.2 生成と初期化する方法\n print(\"6.2 生成と初期化する方法(p035)\")\n \n print(\"- ①生成後に各プロパティ値を設定する(p036)\")\n var dog = Dog()\n dog.name = \"Momo\"\n dog.age = 9\n \n print(\"- ②キー値コーディング(KVC)に準拠しているオブジェクトで初期化する(p036)\")\n dog = Dog(value: [\"name\": \"Momo\", \"age\": 9]) // Dictionaryで初期化\n \n print(\"- ③各プロパティの値の配列で初期化する(p036)\")\n dog = Dog(value: [\"Momo\", 9])\n \n // MARK: - 6.3 ネストしたモデルオブジェクトの生成と初期化\n print(\"6.3 ネストしたモデルオブジェクトの生成と初期化(p037)\")\n \n let cat1 = Cat(value: [\"Toto\", 1])\n let cat2 = Cat(value: [\"Rao\", 2])\n \n print(\"- ①生成後に各プロパティ値を設定する(p037)\")\n var person = Person()\n person.name = \"Yu\"\n person.age = 32\n person.dog = dog\n person.cats.append(objectsIn: [cat1, cat2])\n \n print(\"- ②キー値コーディング(KVC)に準拠しているオブジェクトで初期化する(p037)\")\n person = Person(value: [\"name\": \"Yu\",\n \"age\": 32,\n \"dog\": [\"name\": \"Momo\", \"age\": 9],\n \"cats\": [[\"name\": \"Toto\", \"age\": 1],\n [\"name\": \"Rao\", \"age\": 2]]])\n \n // Objectもキー値コーディングに準拠しているので初期化に使用できます。\n person = Person(value: [\"name\": \"Yu\",\n \"age\": 32,\n \"dog\": dog,\n \"cats\": [cat1, cat2]])\n \n print(\"- ③各プロパティの値の配列で初期化する(p038)\")\n person = Person(value: [\"Yu\",\n 32,\n dog,\n [cat1, cat2]])\n \n // オプショナル型やListクラス内の要素がない場合でも、配列内の値を省略することはできません。\n // 値がない場合はnilを指定する必要があります。\n person = Person(value: [\"Yu\",\n 32,\n nil,\n nil] as [Any?])\n \n // 例えば次のコードはオプショナル型とList型に対しての要素がないためクラッシュする。\n // person = Person(value: [\"Yu\", 32]) // ← 実行すると例外が発生しクラッシュ\n }\n \n // MARK: - Util\n \n @IBOutlet weak var textView: UITextView!\n \n func print(_ string: String) {\n Swift.print(string)\n if textView.text.characters.count > 0 {\n textView.text = textView.text.appending(\"\\n\")\n }\n textView.text = textView.text.appending(string)\n }\n \n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-11-26T06:38:50.670",
"favorite_count": 0,
"id": "39850",
"last_activity_date": "2019-12-19T17:50:43.910",
"last_edit_date": "2020-06-17T08:14:45.997",
"last_editor_user_id": "-1",
"owner_user_id": "13657",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"realm"
],
"title": "Module compiled with Swift 3.0.2 cannot be imported in Swift 3.2.2 の対策",
"view_count": 201
} | [
{
"body": "解決しました。 \nサンプルソースにある、このプロジェクトのディレクトリをダウンロードしたディレクトリとは異なる場所に移動してから、プロジェクトを開き、中のRealmと、RealmSwiftのframeworkを削除して、使用しているXcodeのバージョンに対応したRealmと、RealmSwiftのframeworkをインストールしたところ、simulatorで動きました。 \nインストールは、この本の「第3章Realmのインストール(DynamicFrameworkによるインストール)」に従いました。 \nコンパイルをする段階にバージョンの違いがあると思い込んでいましたが、frameworkそのものにXcodeのバージョンに対応しているものがあることを理解しました。carthageの問題ではありませんでした。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-01T07:36:11.573",
"id": "39965",
"last_activity_date": "2017-12-01T07:46:55.397",
"last_edit_date": "2017-12-01T07:46:55.397",
"last_editor_user_id": "13657",
"owner_user_id": "13657",
"parent_id": "39850",
"post_type": "answer",
"score": 1
}
]
| 39850 | null | 39965 |
{
"accepted_answer_id": "39859",
"answer_count": 1,
"body": "ローカルに立てた管理ページ(<http://localhost:3000>)からAPIサーバー(<https://api.myapp.com/admin/>*)へ通信し、コンテンツを編集する…という設計を考えています。\n\n通信する際にヘッダーへ管理者用パスワードを含めるのですが、この手法はセキュアなのでしょうか。\n\nちなみにAPIサーバーは管理者用エンドポイントの他に公開用エンドポイントも存在します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T11:33:19.810",
"favorite_count": 0,
"id": "39857",
"last_activity_date": "2017-11-26T12:32:02.847",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26332",
"post_type": "question",
"score": 1,
"tags": [
"security",
"https"
],
"title": "HTTPからHTTPSへの通信はセキュアですか?",
"view_count": 125
} | [
{
"body": "通信のエンドポイントがJavaScriptかローカルHTTPサーバーか読み取れなかったので両方について書きます。\n\nまずブラウザ上のJavaScriptからAPIサーバーと通信しているのであればページのオリジンに関わらずすべての通信がユーザーに筒抜けです。この場合は絶対に管理者パスワードなどを含めるべきではありません。\n\nまたローカルで動作するHTTPサーバーからAPIサーバーと通信する場合は一般のアプリケーションと同様に中間者攻撃の危険があります。またファイルシステムやメモリ上に平文でパスワードを保存した場合、比較的容易に抜き出すことができます。\n\n程度の差はあれどちらもそれほど安全ではありません。管理権限を持たないユーザーにも配布するのであれば、埋め込みキーではなくきちんとサーバー側でユーザー認証を行うべきです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T12:32:02.847",
"id": "39859",
"last_activity_date": "2017-11-26T12:32:02.847",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5750",
"parent_id": "39857",
"post_type": "answer",
"score": 3
}
]
| 39857 | 39859 | 39859 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "お忙しいところ大変申し訳無いのですが。 \n初めてご質問させていただきます。\n\nこの度、Djangoにてアプリを作成していたのですが、 \n一つのページを作る際に、MySQLにHTMLのタグごと保存し、 \nそれを、必要に応じて呼び出しを行おうとしたところ、HTMLタグが有効に表示されず、 \n全てが、文字列として出力されてしまいました。 \n(HTMLタグとして機能せず、タグも表示される)\n\n色々とgoogle先生に聞いてもこれといった答えが見出せず、悩み続けていました。\n\n解決方法をご教授頂けますと助かります。\n\n例) \nMySQLに保存(モデル `models.TextField()` )\n\n```\n\n <a href=\"http://hogehoge.com/\" target=\"_blank\">Hogehogeこっそり</a>\n \n```\n\n↓\n\nDjangoからHTMLページに呼び出し\n\n```\n\n <a href=\"http://hogehoge.com/\" target=\"_blank\">Hogehogeこっそり</a>\"\n \n```\n\n(タグが有効にならず、そのまま表示される)\n\nおそらく、タグを含めて文字列として扱っているのだろうと思うのですが、 \nHTMLタグを有効にすることができません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T11:38:26.613",
"favorite_count": 0,
"id": "39858",
"last_activity_date": "2019-02-08T08:02:20.460",
"last_edit_date": "2017-11-26T13:40:30.160",
"last_editor_user_id": "19110",
"owner_user_id": "26333",
"post_type": "question",
"score": 0,
"tags": [
"html",
"mysql",
"python3",
"django"
],
"title": "DjangoでMySQLにHTMLを入力(保存?)",
"view_count": 242
} | [
{
"body": "HTML(テンプレート)側で呼び出すときに {{ data }} ではなく {{ data|safe }}\nとすればエスケープされずに表示されると思いますが、いかがでしょうか?\n\n参考: [Django\nテンプレート言語](http://docs.djangoproject.jp/en/latest/topics/templates.html)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2018-01-31T04:25:48.450",
"id": "41341",
"last_activity_date": "2018-01-31T04:25:48.450",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "27214",
"parent_id": "39858",
"post_type": "answer",
"score": 1
}
]
| 39858 | null | 41341 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "[fullcalendar](https://fullcalendar.io/docs/)のイベントについて行き詰っており質問です。\n\n### 実現したいこと\n\n 1. 国民の休日をgoogleから取得\n 2. スタッフの毎週の出勤日をカレンダーに表示[](eventSourcesにdowで実装)←ここまでは実装できています。\n 3. **会社の公休日にスタッフの出勤日を表示しないようにしたい。(←ここで行き詰ってます。)**\n\n### fullcalendar 現状のコード\n\n```\n\n <script src='js/moment.min.js'></script>\n <script src='js/fullcalendar.js'></script>\n <script src='js/ja.js'></script>\n <script>\n $(function () {\n $('#calendar').fullCalendar({\n firstDay: 1,\n timeFormat: 'H:mm',\n axisFormat: 'H:mm',\n eventSources:[\n {\n url: 'data/json1.php',//ここでGoogleの休日を取得してます。\n dataType: 'json',\n },\n {\n url: 'data/json2.php',//※1\n dataType: 'json',\n async: false,\n type: 'POST',\n data: {\n id: \"1\",\n id2: \"100\",\n },\n },\n ]\n });\n });\n </script>\n \n```\n\n※1の部分\n\n```\n\n 一部省略(POSTでIDを参考に)\n $list = array();\n $i=0;\n foreach ($app->getValues()->staff_all as $staff) {\n $list[$i]['title']=\"出勤日\";\n $list[$i]['color']=\"blue\";\n $list[$i]['start']=$staff->in_time;//出勤時間\n $list[$i]['end']=$staff->out_time;//終わり時間\n $list[$i]['dow']=\"[\".$staff->in_yobi.\"]\";//毎週の曜日指定\n $i++;\n }\n header('Content-Type: application/json; charset=utf-8');\n echo json_encode($list);\n \n```\n\n上記のコードで毎週の予定は取れているのですが、 \nそれに合わせて、会社の公休日は表示されないようにしたいのですが、 \nどんなコードを追記すればよいのかわからず行き詰っております。 \n英語が得意ではなく、fullcalendar を眺めているのですが、解決方法が見つからず \nご教授頂ければ幸いです。\n\n環境 \nphp 5.6 \nmysql 5.6 \nfullcalendar-3.7.0",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-11-26T13:52:23.843",
"favorite_count": 0,
"id": "39862",
"last_activity_date": "2023-07-06T12:07:26.000",
"last_edit_date": "2023-05-30T03:51:29.060",
"last_editor_user_id": "3060",
"owner_user_id": "26336",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"php",
"jquery",
"mysql",
"fullcalendar"
],
"title": "fullcalendarの定期イベントdowの一部上書き(非表示)について。",
"view_count": 768
} | [
{
"body": "予定をDBから抽出する時に、公休日を除外するSQLにすればいいのではないでしょうか?? \nSQLは変更不可?\n\nあとは、 \nfullcalendarのイベント描画のタイミングでカレンダーに表示しないようにすることは可能だと思います。 \nJSONに公休日の情報も含めて判別できるようにする\n\n```\n\n eventRender: function (event, element) {\n if (event.公休日判別フラグ == true) {\n return false; // イベント描画を抜ける\n }\n },\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-22T00:52:48.580",
"id": "40469",
"last_activity_date": "2017-12-22T00:52:48.580",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26742",
"parent_id": "39862",
"post_type": "answer",
"score": 0
}
]
| 39862 | null | 40469 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "DBのデータを抽出できる検索ページを作りました。(index.php) \nただ、条件を指定してもその条件通りのレコードを上手くDBから引っ張って来れません、、、\n\n[実現したいこと] \n以下の検索フォーム(index.html)にて、検索した条件とマッチするにレコードをブラウザに表示させたいです。\n\n[うまくいっていること]\n\n```\n\n print $sql.\";<br>\".PHP_EOL;\n print_r($data);\n \n```\n\n上記の結果は以下の通りブラウザに表示されます。(都道府県->東京、分類->保育園で指定した場合)\n\n```\n\n SELECT * FROM zenkoku where 1AND prefecture = ? AND type = ? ;\n Array ( [0] => 東京都 [1] => 保育園 )\n \n```\n\n[うまくいかないこと] \n上記の[うまくいっていること]の場合でもそのほかの場合でも下記のようなエラーが出ます。\n\n```\n\n Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'prefecture = '東京都' AND type = '保育園'' at line 1\n \n```\n\n[教えて欲しいこと] \nエラーがなぜ出ているかと、その原因をご教示いただけますか?\n\n[環境] \nローカル開発環境、MacOSX,mysql\n\nindex.html\n\n```\n\n <!DOCTYPE html>\n <html lang=\"ja\">\n <head>\n <meta charset=\"UTF-8\">\n <tittle>入力フォーム</title>\n </head>\n <body>\n <form method=\"post\" action=\"SEARCH_Show.php\"><br>\n 名称<br>\n <input type=\"text\" name=\"name\" size=\"60\" maxlength=\"30\" value=\"\"><br>\n 電話番号<br>\n <input type=\"tel\" name=\"tel\" size=\"30\" maxlength=\"12\" value=\"\"><br>\n 担当者名<br>\n <input type=\"text\" name=\"person_name\" size=\"30\" maxlength=\"20\" \n value=\"\"><br>\n 都道府県<br>\n <select name=\"prefecture\"><br>\n <option value=\"全て\">全て</option>\n <option value=\"東京都\">東京都</option>\n <option value=\"神奈川県\">神奈川県</option>\n <option value=\"千葉県\">千葉県</option>\n <option value=\"埼玉県\">埼玉県</option>\n <option value=\"北海道\">北海道</option>\n <option value=\"宮城県\">宮城県</option>\n <option value=\"愛知県\">愛知県</option>\n <option value=\"大阪府\">大阪府</option>\n <option value=\"福岡県\">福岡県</option>\n </select><br>\n 市区町村<br>\n <input type=\"text\" name=\"city\" size=\"30\" maxlength=\"30\" value=\"\"><br>\n 分類<br>\n <select name=\"type\"><br>\n <option value=\"全て\">全て</option>\n <option value=\"保育園\">保育園</option>\n <option value=\"幼稚園\">幼稚園</option>\n <option value=\"サークル\">サークル</option>\n <option value=\"その他\">その他</option>\n </select><br>\n <button type=\"submit\" class=\"\">検索</button>\n </form>\n </body>\n </html>\n \n```\n\nindex.php\n\n```\n\n <?php\n require 'Manager.php';\n require 'Escape.php';\n ini_set('display_errors',1);\n ?>\n <!DOCTYPE html>\n <html lang = \"ja\">\n <head>\n <meta charset =\"UTF-8\">\n <tittle>登録ページ</tittle>\n </head>\n <body>\n <table border='1' class=\"TableStyle1\" width=\"1000\">\n <tr>\n <th>名称</th>\n <th>都道府県</th>\n <th>市区町村</th>\n <th>番地</th>\n <th>区分</th>\n <th>電話番号</th>\n <th>担当者名</th>\n <th>部数</th>\n <th>設置/配布</th>\n <th>消去</th>\n </tr>\n <?php\n try{\n $db = connect();\n $name=filter_input(INPUT_POST,'name');\n $tel=filter_input(INPUT_POST,'tel');\n $person_name=filter_input(INPUT_POST,'person_name');\n $prefecture=filter_input(INPUT_POST,'prefecture');\n $city=filter_input(INPUT_POST,'city');\n $type=filter_input(INPUT_POST,'type');\n \n \n if(!is_null($name)){\n $sql = \"SELECT * FROM zenkoku where 1\";\n $data=[];\n }\n if($name!==\"\"){\n $sql.=\"AND name = ?\" ;\n $data[]=$name; \n }\n if($tel!==\"\"){ \n $sql.= \"AND tel = ? \"; \n $data[]=$tel;\n }\n if($person_name!==\"\"){\n $sql.= \"AND person_name = ? \";\n $data[]=$person_name;\n }\n if($prefecture!==\"全て\"){\n $sql.= \"AND prefecture = ? \";\n $data[]=$prefecture;\n }\n if($city!==\"\"){\n $sql.= \"AND city = ? \";\n $data[]=$city;\n }\n if($type!==\"\"){\n $sql.= \"AND type = ? \";\n $data[]=$type;\n }\n print $sql.\";<br>\".PHP_EOL;\n print_r($data);\n $stmt = $db->prepare($sql);\n $stmt->execute($data);\n while($row = $stmt->fetch(PDO::FETCH_ASSOC)){\n ?>\n <tr>\n <td><?php es($row['name']);?></td>\n <td><?php es($row['prefecture']);?></td>\n <td><?php es($row['city']);?></td>\n <td><?php es($row['address']);?></td>\n <td><?php es($row['type']);?></td>\n <td><?php es($row['tel']);?></td>\n <td><?php es($row['person_name']);?></td>\n <td><?php es($row['copies']);?></td>\n <td><?php es($row['set_type']);?></td>\n </tr>\n <?php\n }\n }catch(PDOException $e){\n echo $e->getMessage();\n exit;\n }\n ?>\n </table>\n </body>\n </html>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T14:28:43.190",
"favorite_count": 0,
"id": "39863",
"last_activity_date": "2017-11-27T02:45:59.360",
"last_edit_date": "2017-11-26T20:26:17.183",
"last_editor_user_id": "3068",
"owner_user_id": "26337",
"post_type": "question",
"score": 0,
"tags": [
"php",
"mysql",
"sql"
],
"title": "phpで検索ページを作りDBから条件通りのレコードを抽出したい",
"view_count": 2199
} | [
{
"body": "吐き出されているSQLを確認すると `1AND`と 本来 `1 AND` とスペースで区切られる部分が区切られていないようです。\n\nPHPのSQLの成形部分で全てに前後に空白を加えると正しいSQLが発行できると思います。\n\n```\n\n $sql = \"SELECT * FROM zenkoku where 1 \";\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T02:45:59.360",
"id": "39873",
"last_activity_date": "2017-11-27T02:45:59.360",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "22665",
"parent_id": "39863",
"post_type": "answer",
"score": 1
}
]
| 39863 | null | 39873 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "下記のような座標を持つファイルをrubyで処理したいのですが、どのようにしたらいいか検討がつかず頓挫しています。アイデアを頂けますか。\n\n処理前\n\n```\n\n group start end id distance value1 value2\n A 5817 7756 id1 1939 0 3\n A 5817 7754 id2 1937 -2 1\n A 5817 7752 id3 1935 -4 1\n A 5817 7747 id4 1930 -9 1\n A 5817 10699 id5 1938 -50 1\n A 5819 7756 id6 1937 -2 1\n A 5819 7755 id7 1936 -3 1\n A 5828 7756 id8 1928 -11 1\n A 5983 8180 id9 2197 1 2\n A 5983 8175 id10 2192 -5 2\n A 5983 8174 id11 2191 -6 1\n A 5984 8175 id12 2191 -6 1\n \n```\n\n上記のような重なりを持つ座標に関して、例として\n\n```\n\n (id2;end – id1;end) – (id2;start – id1;start) = id2;value1\n (id3;end – id1;end) – (id3;start – id1;start) = id3;value1\n \n```\n\nというような条件を満たせば、id1とid2及びid3は同じグループに所属するとみなし、グループ内で一番大きいvalue1を持つid1のvalue2にそのカウントを足していきたいのです。\n\n処理後\n\n```\n\n group start end id length value1 value2\n A 5817 7756 id1 1939 0 9\n A 5817 10699 id5 1938 -50 1\n A 5983 8180 id9 2197 1 5\n \n```\n\n以上、ご教示の程、宜しくお願いいたします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T17:02:41.500",
"favorite_count": 0,
"id": "39867",
"last_activity_date": "2018-11-10T01:44:15.563",
"last_edit_date": "2017-11-26T20:24:21.460",
"last_editor_user_id": "3068",
"owner_user_id": "26338",
"post_type": "question",
"score": 0,
"tags": [
"ruby"
],
"title": "ファイル中の座標の処理",
"view_count": 91
} | [
{
"body": "```\n\n require 'pp'\n \n list = []\n open('/tmp/hoge.txt').read.split(\"\\n\").select.with_index{|a,i| i != 0}.map{|a| a.split(\" \")}.map do |a|\n list << {\n group: a[0],\n start: a[1].to_i,\n end: a[2].to_i,\n id: a[3],\n distance: a[4].to_i,\n value1: a[5].to_i,\n value2: a[6].to_i\n }\n end\n \n id_comb_list = list.map{|a| a[:id]}.combination(3).to_a\n id_comb_list.each do |ic|\n id1 = list.find{|a| a[:id] == ic[0]}\n id2 = list.find{|a| a[:id] == ic[1]}\n id3 = list.find{|a| a[:id] == ic[2]}\n if ( (id2[:end] - id1[:end]) - (id2[:start] - id1[:start]) == id2[:value1] ) &&\n ( (id3[:end] - id1[:end]) - (id3[:start] - id1[:start]) == id3[:value1] )\n target = [id1, id2, id3].sort_by{|c| c[:value1]}.last\n target[:value2] += target[:value1]\n end\n end\n \n pp list\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2018-11-10T01:44:15.563",
"id": "50149",
"last_activity_date": "2018-11-10T01:44:15.563",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "30913",
"parent_id": "39867",
"post_type": "answer",
"score": 0
}
]
| 39867 | null | 50149 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "設定した時間後にアラート画面を出すサンプルコードは見つかりましたが、音を鳴らすにはどのようにコードを書き換えれば良いですか?\n\nサンプルコードは以下のサイトのものを参考にしています。 \n<http://www.pori2.net/js/timer/6.html>\n\n### 追記 2017/12/21\n\nアドバイス有難う御座います下のように書き換えてみたのですが音がなりませんでした。 \nどこかおかしいですか?\n\n```\n\n <script>\n var timer1; //タイマーを格納する変数(タイマーID)の宣言\n \n //カウントダウン関数を1000ミリ秒毎に呼び出す関数\n function cntStart()\n {\n document.timer.elements[2].disabled=true;\n timer1=setInterval(\"countDown()\",1000);\n }\n \n //タイマー停止関数\n function cntStop()\n {\n document.timer.elements[2].disabled=false;\n clearInterval(timer1);\n }\n \n //カウントダウン関数\n function countDown()\n {\n var min=document.timer.elements[0].value;\n var sec=document.timer.elements[1].value;\n \n if( (min==\"\") && (sec==\"\") )\n {\n alert(\"時刻を設定してください!\");\n reSet();\n }\n else\n {\n if (min==\"\") min=0;\n min=parseInt(min);\n \n if (sec==\"\") sec=0;\n sec=parseInt(sec);\n \n tmWrite(min*60+sec-1);\n }\n }\n \n //残り時間を書き出す関数\n function tmWrite(int)\n {\n int=parseInt(int);\n \n if (int<=0)\n {\n reSet();\n new Audio(\"hoge.mp3\");\n play();\n }\n else\n {\n //残り分数はintを60で割って切り捨てる\n document.timer.elements[0].value=Math.floor(int/60);\n //残り秒数はintを60で割った余り\n document.timer.elements[1].value=int % 60;\n }\n }\n \n //フォームを初期状態に戻す(リセット)関数\n function reSet()\n {\n document.timer.elements[0].value=\"0\";\n document.timer.elements[1].value=\"0\";\n document.timer.elements[2].disabled=false;\n clearInterval(timer1);\n } \n </script>\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T18:22:54.580",
"favorite_count": 0,
"id": "39868",
"last_activity_date": "2018-04-21T06:58:44.080",
"last_edit_date": "2018-04-21T06:58:44.080",
"last_editor_user_id": "754",
"owner_user_id": "26339",
"post_type": "question",
"score": 1,
"tags": [
"javascript"
],
"title": "キッチンタイマーで音を鳴らす",
"view_count": 1213
} | [
{
"body": "コードは詳しく見ないと読めない方なのですが、ざっと見てtmWrite関数の中のif文にある`alert(\"時間です!\");`を音を鳴らすコードにしては? \n鳴らせる音ファイルの拡張子はmp3、wavです。 \n簡単にできる方法だと\n\n```\n\n new Audio(\"パス\");\n play();\n \n```\n\nになります。 \nplay()以外だと、stop()で止めたり、loop()でループさせたりできます。 \nloop関数の引数に数字を入れると指定回数だけループ。入れないとエンドレスループ。 \nplay()すると音/音楽が終わったら自動的に停止します。 \nあまり凝ったことはできません。 \n<http://webos-goodies.jp/archives/50855398.html>\n\nそして、私は使っていませんが少し凝ったことができる方法。 \nリンクだけ掲載しておきます。 \n<https://syncer.jp/html5-javascript-hello-button>\n\nmp3が再生できるブラウザは2010~2014年からのブラウザです。wavや他について知りたければ \n<https://caniuse.com/#> \nを参考に。他の機能なども調べられます。(私の記憶では)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T21:53:06.840",
"id": "39894",
"last_activity_date": "2017-11-27T23:03:08.037",
"last_edit_date": "2017-11-27T23:03:08.037",
"last_editor_user_id": "19110",
"owner_user_id": "26334",
"parent_id": "39868",
"post_type": "answer",
"score": 1
}
]
| 39868 | null | 39894 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "2次元配列liがあり\n\n```\n\n li =[[1,2],\n [2,3],\n [3,4],\n [4,5],\n [1,3],\n [1,4]]\n \n```\n\n1つ目の要素が1である箇所の2つ目の要素の合計を計算したいです. \n上のリストの場合,1つ目の要素が1である[1,2][1,3][1,4]の \n2つ目の要素の合計を算出(2+3+4=9)といった具合です.\n\nfilter,map,sum,lambdaをうまく使えば,できると思うのですが・・・\n\n分かりにくい文章で申し訳ありませんが,よろしくお願いいたします.",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-26T23:34:35.080",
"favorite_count": 0,
"id": "39869",
"last_activity_date": "2017-11-27T03:47:40.507",
"last_edit_date": "2017-11-27T02:18:20.783",
"last_editor_user_id": "19110",
"owner_user_id": "26341",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "pythonで2次元配列の1つ目の要素から,2つ目の合計を算出",
"view_count": 2259
} | [
{
"body": "numpy.whereを使ってみてはどうでしょう。\n\n```\n\n import numpy as np\n \n li =[[1,2],\n [2,3],\n [3,4],\n [4,5],\n [1,3],\n [1,4]]\n \n m = np.array(li)\n idx = np.where(m[:,0]==1)\n np.sum(m[idx, 1])\n \n```\n\n以下、追記。 \nお遊びレベルの修正ですが、pandasのDataFrameを使えば、次のようにまとめられます。\n\n```\n\n import pandas as pd\n df = pd.DataFrame(li)\n a = df.where(df[0]==1).sum()[1]\n \n```\n\nあと、ご質問のコメントの中にある回答ですが、\n\n```\n\n sum([e[1] for e in li if e[0] == 1])\n \n```\n\nは、内包表記の[]は省略できます。\n\n```\n\n sum(e[1] for e in li if e[0] == 1)\n \n```\n\nこちらは、中間のリストを作成しない分メモリ効率がよくなる場合があるようです(差が出るようなサイズで試したことがないので伝聞調です)。詳細な仕組みまでは説明しませんが、Pythonのジェネレータ式としてsumの中が機能しています。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T00:56:10.743",
"id": "39871",
"last_activity_date": "2017-11-27T03:47:40.507",
"last_edit_date": "2017-11-27T03:47:40.507",
"last_editor_user_id": "26311",
"owner_user_id": "26311",
"parent_id": "39869",
"post_type": "answer",
"score": 0
},
{
"body": "filter, mapを使っても可能ですが、あまりPythonicではありません。\n\n```\n\n filtered = filter(lambda e: e[0] == 1, li)\n mapped = map(lambda e: e[1], filtered)\n print(sum(mapped))\n \n```\n\nコメントで言われているように、(件数にもよりますが)内包表現を使ったほうが簡潔でオススメです。\n\n```\n\n print(sum(e[1] for e in li if e[0] == 1))\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T01:37:59.280",
"id": "39872",
"last_activity_date": "2017-11-27T01:37:59.280",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26172",
"parent_id": "39869",
"post_type": "answer",
"score": 2
}
]
| 39869 | null | 39872 |
{
"accepted_answer_id": "39877",
"answer_count": 1,
"body": "ruby の特定のメソッドが、期待する引数の個数を range で取得したいと考えました。\n\nどういうことかというと、 ruby にはデフォルト引数があるので、例えば以下のメソッドでは 0~2 個の引数を指定できます。\n\n```\n\n def hoge(a=1, b=2)\n p a; p b\n end\n \n```\n\nこの場合は、 `0..2` を取得したいです。\n\n本家で検索したところ、 `arity` メソッドがそれらしかったのですが、`arity`\nメソッドは、可変長パラメータを引数に取る場合には、「(-1)*(必須parameterの個数+1)」が帰ってくる様子です。実際上記`hoge`メソッドに対して実行すると、`-1`が返ってきます。\n\n参考: <https://stackoverflow.com/questions/17590080/is-there-a-way-to-know-how-\nmany-parameters-are-needed-for-a-method>\n\n### 質問\n\n * ruby で、対象のメソッドが、実際に何個の引数を取り得るかの range を取得したいです。これは、実現可能でしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T04:55:31.640",
"favorite_count": 0,
"id": "39876",
"last_activity_date": "2017-11-27T05:12:38.280",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 0,
"tags": [
"ruby"
],
"title": "ruby のメソッドに対して、期待引数個数の range を取得したい",
"view_count": 50
} | [
{
"body": "丁度、質問投稿を見直していると、 accepted answer の下の方に、`Method#parameters`\nメソッドについての説明がありました。これを実際に実行してみると、\n\n```\n\n method(:hoge).parameters\n # => [[:opt, :a], [:opt, :b]]\n \n```\n\nとなったので、これが欲しかったメソッドの様子です。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T05:12:38.280",
"id": "39877",
"last_activity_date": "2017-11-27T05:12:38.280",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"parent_id": "39876",
"post_type": "answer",
"score": 1
}
]
| 39876 | 39877 | 39877 |
{
"accepted_answer_id": "39883",
"answer_count": 1,
"body": "[c](/questions/tagged/c \"'c' のタグが付いた質問を表示\") および\n[c++](/questions/tagged/c%2b%2b \"'c++' のタグが付いた質問を表示\") のプリプロセッサ `#if`\nの条件式と、いわゆる「本文」中の条件式は同じ結果を得るものだと思っていましたが、違うことがあるようです。\n\n```\n\n #include <stdio.h>\n #define PHYSICAL_ROM_TOP (-262144) /* 0xFFFC0000 を符号付きで表記 */\n int main() {\n printf(\"%d\\n\", PHYSICAL_ROM_TOP==0xFFFC0000);\n #if PHYSICAL_ROM_TOP==0xFFFC0000\n printf(\"same\\n\");\n #else\n printf(\"different\\n\");\n #endif\n return 0;\n }\n \n```\n\nVisual C++ 2005 での結果 `cl -Ox -FAsc foo.c` で `1 different` \[email protected] での結果 `gcc -O foo.c` で `1 different` \n野良ビルドした gcc-7.1.0@i686-pc-cygwin (32bit) での結果 `1 different` \n某組み込み系ワンチップマイコン用のコンパイラの1 `1 different` \n某組み込み系ワンチップマイコン用のコンパイラの2 `1 same`\n\nちゃんとコンパイル時定数式として扱ってくれているかどうかの確認のためアセンブラも出力させてみました。最適化を有効にすると全てのコンパイラで `1`\nに対して即値を生成しているので、コンパイル時定数式と見てくれているのは間違いないです。\n\n言語規格書をチラ見した範囲ではこの違いについて納得できる説明を見つけることができませんでした\n([c++](/questions/tagged/c%2b%2b \"'c++' のタグが付いた質問を表示\") 規格書 JIS X 3014:2003 の\n16.1 や 5.19 や 18.2)\n\nこの `#if` が `#else` 側になる説明をしていただけると幸いです。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T06:30:41.410",
"favorite_count": 0,
"id": "39878",
"last_activity_date": "2017-11-29T10:05:40.160",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "8589",
"post_type": "question",
"score": 6,
"tags": [
"c++",
"c"
],
"title": "プリプロセッサの条件式と通常の条件式は結果が異なる?",
"view_count": 611
} | [
{
"body": "自己回答になっちゃいます。 JIS X 3014:2003 (C++03) でなくて JIS X 3010:2003 (C99) を見ればよかった。以下\nJIS X 3010:2003 [c99](/questions/tagged/c99 \"'c99' のタグが付いた質問を表示\")\nの要約というか、オイラの勝手な解釈というか。\n\n6.10.1 条件付き取込み \n(プリプロセス中は)すべての符号付き整数は `intmax_t` として、符号無し整数は `uintmax_t` として扱う。\n\n6.7.2 型指定子 \n`long long int` と `unsigned long long int` は型指定子である。 \n(要するに [c99](/questions/tagged/c99 \"'c99' のタグが付いた質問を表示\") を名乗るには `long long int`\nをサポートしなければならない)\n\n5.2.4.2.1 整数型の大きさ \n`long long int` と `unsigned long long int` は 64bit 以上の大きさでなければならない。\n\n7.18.1.5 最大幅整数型 \n`intmax_t` はすべての符号付き整数値を表現可能な型 \n`uintmax_t` はすべての符号無し整数値を表現可能な型 \n処理系はこれらを提供することが必須。\n\nすなわち `intmax_t` は 64bit 以上の整数型と読み解けます。\n\nということで **C99 以後では** `(-262144)` は [プリプロセッサが処理する際には] \n`0xFFFFFFFFFFFC0000` に等しく `0x00000000FFFC0000` とは等しくない、ということになります。 `same`\nとなったコンパイラは確かに [c99](/questions/tagged/c99 \"'c99' のタグが付いた質問を表示\") 非対応な古いものでした。\n\nJIS X3014 というか ISO/IEC 14882 の新しい版では 16.1\nに改正が入っているのでしょう(未確認)。この種の疑義を晴らすには新しい版を入手する必要がありそうです。\n\n追記: `JIS X 3010-1993` (C89) を確認してみました。 \n`JIS X 3010-1993` 6.8.1 条件付き取込み\n\n> `int` 及び `unsigned int` がそれぞれ `long` 及び `unsigned long` の表現をもつかのように動作する。\n\nC89 には 64bit 型をサポートしなければならない規定は無いはずなので、プリプロセッサ中の演算は(今回挙げた例では) 32bit で行われて結果は\n`same` になる、ということです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T10:37:08.830",
"id": "39883",
"last_activity_date": "2017-11-29T10:05:40.160",
"last_edit_date": "2017-11-29T10:05:40.160",
"last_editor_user_id": "8589",
"owner_user_id": "8589",
"parent_id": "39878",
"post_type": "answer",
"score": 7
}
]
| 39878 | 39883 | 39883 |
{
"accepted_answer_id": "39881",
"answer_count": 1,
"body": "現在、chart.jsを使ってプログラムの作成をしていますが、期待通りの挙動になりません。 \n動作としては、毎秒特定のcsvファイルを読み込んで数値をロードし、その数値をリアルタイムの棒グラフ上に出力するものを想定していますが、以下のコードを実行したところcellsに燗するundefinedエラーが出力されてしまい動きません。 \n上記のようなグラフを実装するにはどうすればいいでしょうか、よろしくお願いします。\n\n```\n\n function csv2Array() {\n var req = new XMLHttpRequest();\n var filePath = 'logs/logdata.csv';\n req.open('GET', filePath, true);\n req.send(null);\n req.onload = function () {\n var tmp = req.responseText.replace(/\\r?\\n/g, '');\n cells = tmp.split(',');\n } \n return cells;\n }\n \n function drawBarChart() {\n // 4)chart.jsで描画\n var ctx = document.getElementById('myChart').getContext('2d');\n var myChart = new Chart(ctx, {\n type: 'bar',\n data: {\n datasets: [\n {\n label: 'RX-OK',\n data: [\n ],\n backgroundColor: '#FFBBBB'\n },\n {\n label: 'TX-OK',\n data: [\n ],\n backgroundColor: '#BBBBFF'\n }\n ]\n },\n options: {\n scales: {\n xAxes: [\n {\n type: 'realtime'\n }\n ]\n },\n plugins: {\n streaming: {\n onRefresh: function (chart) {\n csv2Array();\n Array.prototype.push.apply(chart.data.datasets[0].data, cells[1]\n );\n Array.prototype.push.apply(chart.data.datasets[1].data, cells[2]\n );\n }\n \n \n }\n }\n }\n });\n }\n \n function main() {\n drawBarChart();\n }\n \n main();\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T08:39:14.163",
"favorite_count": 0,
"id": "39879",
"last_activity_date": "2018-04-13T04:04:38.327",
"last_edit_date": "2018-04-13T04:04:38.327",
"last_editor_user_id": "19110",
"owner_user_id": "26347",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"chart.js"
],
"title": "chart.jsを用いたリアルタイムでデータを表示するグラフの作成について",
"view_count": 2607
} | [
{
"body": "JavaScript における変数のスコープと初期化の方法に注意してください。変数 `cells`\nがどこで定義されていてどこで代入されているのかが不明瞭なコードになってしまっています。\n\n具体的には、表を更新する `onRefresh` の部分で CSV を読み込むために `csv2Array()`\nを呼び出していますが、この結果の戻り値はどこにも代入されていません。また、この関数のローカルスコープでは変数 `cells`\nが定義されていない場合があります。同様に、`csv2Array` 関数の中における変数 `cells` の扱いにも注意してみてください。\n\n更に、`XMLHttpRequest` を使う際には、`send` する前にイベントリスナを設定する必要があることにも注意してください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T08:59:06.107",
"id": "39881",
"last_activity_date": "2017-11-27T08:59:06.107",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "39879",
"post_type": "answer",
"score": 1
}
]
| 39879 | 39881 | 39881 |
{
"accepted_answer_id": "39888",
"answer_count": 1,
"body": "このコードはグーグル翻訳に英文を飛ばして、翻訳されたものを取得しようとしたプログラムです。PhantomJSを用いた類似プログラムではうまくspan要素を取得できたのですが、bs4を用いた、コードではこれがうまく取得できません。\n\nこの違いはなんなのか、誰か分かる方はいらっしゃいますでしょうか?\n\n```\n\n import pyperclip, requests, bs4, pprint\n \n res = requests.get('https://translate.google.co.jp/?hl=ja#en/ja/' + pyperclip.paste())\n res.raise_for_status() \n soup = bs4.BeautifulSoup(res.text)\n elems = soup.select('span')\n for i in range(len(elems)):\n print(elems[i].getText())\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T08:53:21.547",
"favorite_count": 0,
"id": "39880",
"last_activity_date": "2017-11-27T14:19:39.103",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26076",
"post_type": "question",
"score": 0,
"tags": [
"python"
],
"title": "なぜbs4で要素を取得することができないのでしょうか?",
"view_count": 208
} | [
{
"body": "* グーグル翻訳は **javascriptが動作する環境** でしか「 **翻訳できません** 」。 \n * Python の `requests` では **javascript動かして** ページを取得することはできません。\n * javascriptが必要になるページを **動的なページ** と呼び、HTML/CSSだけのようなページをを **静的なページ** と呼んだりします。\n * PhantomJS は **ヘッドレスブラウザ** と呼ばれるライブラリの一つで、ブラウザと同様に **javascript** を実行して **動的なページ** を取得できます。\n\nPython で **動的なページ** をスクレイピングしたい時も、結局\nPhantomJSなりを用意して、それをSeleniumなどのライブラリを通して使ったりします。\n\nPython, Selenium, WebDriver, PhantomJS あたりのキーワードでやり方はいっぱい出てくると思うのでググってみてください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T14:19:39.103",
"id": "39888",
"last_activity_date": "2017-11-27T14:19:39.103",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2168",
"parent_id": "39880",
"post_type": "answer",
"score": 3
}
]
| 39880 | 39888 | 39888 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "2次元リストがあり、1つ目の要素と2つ目の要素を条件に3つ目に入れる要素を決定したいです。\n\n```\n\n li=np.array([-1,-2]\n [ 1,-2]\n [-1, 2]\n [ 1, 2]\n )\n \n```\n\n具体的には \n(1つ目の要素 < 0) and (2つ目の要素 < 0) なら3つ目に1を \n(1つ目の要素 > 0) and (2つ目の要素 < 0) なら3つ目に2を \n(1つ目の要素 < 0) and (2つ目の要素 > 0) なら3つ目に3を \n(1つ目の要素 > 0) and (2つ目の要素 > 0) なら3つ目に4を \n追加し、\n\n```\n\n result=[[-1,-2, 1]\n [ 1,-2, 2]\n [-1, 2, 3]\n [ 1, 2, 4]]\n \n```\n\nとなるようなものです。\n\n内包表現やシーケンス操作(filterやmap、where)を用いる方法で行いたいです。\n\nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T10:26:40.370",
"favorite_count": 0,
"id": "39882",
"last_activity_date": "2017-11-28T06:12:16.143",
"last_edit_date": "2017-11-27T10:59:04.027",
"last_editor_user_id": "19110",
"owner_user_id": "26341",
"post_type": "question",
"score": 0,
"tags": [
"python",
"python3"
],
"title": "pythonで配列の1つ目と2つ目の要素を条件に3つ目の要素を決定する。",
"view_count": 525
} | [
{
"body": "一応かけましたが、もっと良い方法があるような気がします。 \nあと読みにくいので自分は素直に`for`で書かれたものの方が好きです。\n\n```\n\n li = [[-1,-2],\n [ 1,-2],\n [-1, 2],\n [ 1, 2]]\n \n [ i + [(1 if i[0]>0 else 0)+(2 if i[1]>0 else 0)+1] for i in li ]\n \n```\n\n出力\n\n```\n\n [[-1, -2, 1], [1, -2, 2], [-1, 2, 3], [1, 2, 4]]\n \n```\n\n* * *\n\n**追記** \n少し短くできたので追記。\n\n```\n\n [ i + [int(i[0]>0) + int(i[1]>0)*2 + 1] for i in li ]\n \n```\n\nあと`numpy`を使うと以下のようにもかけます。 \nもしかすると速いかもしれませんが、すごく読みにくいです。 \nもっと良い方法知っている方がいましたら、お願いします。\n\n```\n\n import numpy as np\n ni = np.array(li)\n \n np.hstack(( ni, np.sum((ni>0)*[1,2],1)[None].T+1 )) # 方法1\n np.vstack(( ni.T, np.sum((ni.T>0)*[[1],[2]],0)+1 )).T # 方法2\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T13:18:38.020",
"id": "39884",
"last_activity_date": "2017-11-28T02:29:34.160",
"last_edit_date": "2017-11-28T02:29:34.160",
"last_editor_user_id": "3974",
"owner_user_id": "3974",
"parent_id": "39882",
"post_type": "answer",
"score": 1
},
{
"body": "これでどうでしょう\n\n```\n\n >>> import numpy as np\n >>> li = np.array([[-1, -2],\n ... [ 1, -2],\n ... [-1, 2],\n ... [ 1, 2]])\n >>> n = li.shape[0]\n >>> li2 = np.hstack([li, np.zeros((n,1))])\n >>> li2\n array([[-1., -2., 0.],\n [ 1., -2., 0.],\n [-1., 2., 0.],\n [ 1., 2., 0.]])\n >>> li2[np.where((li2[:,0]<0) & (li2[:,1]<0)),2] = 1\n >>> li2[np.where((li2[:,0]>0) & (li2[:,1]<0)),2] = 2\n >>> li2[np.where((li2[:,0]<0) & (li2[:,1]>0)),2] = 3\n >>> li2[np.where((li2[:,0]>0) & (li2[:,1]>0)),2] = 4\n >>> li2\n array([[-1., -2., 1.],\n [ 1., -2., 2.],\n [-1., 2., 3.],\n [ 1., 2., 4.]])\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T06:12:16.143",
"id": "39899",
"last_activity_date": "2017-11-28T06:12:16.143",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "806",
"parent_id": "39882",
"post_type": "answer",
"score": 2
}
]
| 39882 | null | 39899 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "<https://employment.en-japan.com/engineerhub/entry/2017/01/31/110000>\n\nこちらのサイトを参考にGithubを設定していましたが \n私のプロキシ環境下ではGithubにアクセスできず,聞いたところによると \nsshではなくhttpsではアクセスできるそうです。\n\nやり方がわかりません \n教えていただけないでしょうか\n\n環境はWindows10です",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T13:46:06.400",
"favorite_count": 0,
"id": "39885",
"last_activity_date": "2017-11-27T14:47:45.800",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "24896",
"post_type": "question",
"score": 0,
"tags": [
"git",
"github"
],
"title": "GithubへのアクセスをSSHではなくHttpsでやりたい",
"view_count": 3846
} | [
{
"body": "Github の ヘルプに書いてあるのでこちらを試してみてください。\n\n<https://help.github.com/articles/which-remote-url-should-i-use/#cloning-with-\nhttps-urls-recommended>\n\n**追記** httpsで利用する際に参考URLのどこの内容が変わってくるか記載します。\n\n<https://employment.en-japan.com/engineerhub/entry/2017/01/31/110000>\n\n**GitHubへのSSH接続を確認する**\n\n * 接続できないとのことなので飛ばしていいです。\n\n**GitHubで作成したリポジトリ名をコピーする**\n\n * GitHubのサイトで、リポジトリのページの右側の「Clone or download」をクリックし、最初の「Clone with HTTP」の状態のまま。URLをコピーします。\n\n * 「<https://github.com/>【ユーザー名】//【リポジトリ名】.git」みたいなURLが取得できます\n\n * 下記のようにコマンドを実行してローカルにリポジトリをコピーしてください。\n\n * `git clone https://github.com/【ユーザー名】//【リポジトリ名】.git`\n\n**GitHubへプッシュする**\n\n * githubのヘルプによれば、pushを実行した時にでGithubのID/PASSが聞かれます。\n * 登録したID/PASSを入力して pushがうまくいくか確認してください。\n\n以上の部分が https で Githubリポジトリを操作した時に、参考URLの内容と変わってくると思います。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T13:59:19.320",
"id": "39886",
"last_activity_date": "2017-11-27T14:47:45.800",
"last_edit_date": "2017-11-27T14:47:45.800",
"last_editor_user_id": "2168",
"owner_user_id": "2168",
"parent_id": "39885",
"post_type": "answer",
"score": 1
}
]
| 39885 | null | 39886 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "multiprocessing.Processでtarget関数(引数`target`として渡す関数)のなかでSIGTERMをハンドルしたいのですがうまくいきません \nどうすればいいのでしょうか?\n\nGUIを使ったプログラムでStartボタンを押すと別プロセスで`test_main`関数が動きます \nStopボタンを押すとStartボタンを押したときに起動したプロセスにSIGTERMが送られます \nしかし、test_main内ではWebdriverが動いており、このWebdriverを片付けてから(driver.quit()してから)プロセスを終了させたいです。\n\nそこでtest_main内でsignal.signalを設定してSIGTERMを受け取ったらwebdriverを片付けた後でプロセスを終了させたいのですがStopボタンを押してSIGTERMを送ってもうまくいきません\n\n```\n\n \n import tkinter as tk\n from multiprocessing import Process\n from tkinter import messagebox\n import sys\n import signal\n import time\n import os\n from selenium.webdriver.support.wait import WebDriverWait\n from selenium import webdriver\n from selenium.webdriver.common.by import By\n from selenium.webdriver.chrome.options import Options\n from selenium.webdriver.support import expected_conditions as EC\n \n \n def create_driver():\n options = Options()\n if sys.platform == \"darwin\":\n options.binary_location = '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'\n #options.add_experimental_option(\"detach\", True)\n if sys.platform == \"win32\":\n options.binary_location = \"C:\\\\(user_home)\\\\AppData\\\\Local\\\\Google\\\\Chrome SxS\\\\Application\\\\chrome.exe\" #location of chrome canary for windows\n options.add_argument('--headless')\n #options.add_argument('--disable-gpu')\n options.add_argument('--reduce-security-for-testing')\n options.add_argument('--allow-insecure-localhost')\n if sys.platform == \"win32\":\n chromedriver_path = r\".\\chromedriver\"\n else:\n chromedriver_path = \"./chromedriver\"\n \n driver = webdriver.Chrome(chromedriver_path, chrome_options=options)\n return driver\n \n \n \n class GUI(tk.Frame):\n def __init__(self, master=None):\n super().__init__(master)\n self.cur_process = None\n self.pack()\n self.create_widget()\n \n def create_widget(self):\n self.start = tk.Button(self, width=5, padx=10, pady=3)\n self.start[\"text\"] = \"Start\"\n self.start[\"command\"] = self.start_event\n self.start.grid(row=2, column=2, columnspan=2, padx=4, pady=10)\n self.quit = tk.Button(self, width=5, padx=10, pady=3)\n self.quit[\"text\"] = \"Stop\"\n self.quit[\"command\"] = self.stop_event\n self.quit.grid(row=3, column=2, columnspan=2, padx=4, pady=10)\n \n def start_event(self):\n if self.cur_process is None:\n self.cur_process = Process(target=test_main) #target function\n self.cur_process.start()\n \n def stop_event(self):\n if self.cur_process != None:\n os.kill(self.cur_process.pid, signal.SIGTERM)\n # self.driver.quit()\n self.cur_process = None\n \n \n def test_main(): #target function\n # set signal handler to SIGTERM\n def k():\n print(\"set new signal handler\")\n try:\n driver.quit()\n # then terminate process\n except NameError:# driver is not defined\n pass # do nothing\n sys.exit() # terminate process\n signal.signal(signal.SIGTERM, k)\n # do something with driver\n driver = create_driver()\n def gui():\n root = tk.Tk()\n root.geometry(\"400x300\")\n g = GUI(master=root)\n g.mainloop()\n \n \n if __name__ == \"__main__\":\n gui()\n \n \n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T14:16:52.107",
"favorite_count": 0,
"id": "39887",
"last_activity_date": "2020-09-23T04:06:00.580",
"last_edit_date": "2017-11-27T15:19:40.460",
"last_editor_user_id": "5246",
"owner_user_id": "5246",
"post_type": "question",
"score": 0,
"tags": [
"windows",
"python3",
"selenium-webdriver"
],
"title": "multiprocessing.Processのtarget内でsignalをhandleできない",
"view_count": 313
} | [
{
"body": "もしかしたら見当違いの回答になってしまうかもしれませんが、自分でSIGTERMを捕まえてワーカープロセスの掃除をするよりは、ワーカープロセスを\ndaemonモードで動かしてしまうのはどうでしょうか。\n\n<http://ja.pymotw.com/2/multiprocessing/basics.html#id3>\n\ndaemonモードで動かすとそのワーカープロセスはメインのプログラムが終了するとその直前に、自動的に終了してくれるようです。\n\n追記: 質問文を良くみたら「ストップボタン=プログラム終了」ではないので、この回答は妥当ではないですね。すいません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T15:12:41.740",
"id": "39891",
"last_activity_date": "2017-11-27T15:12:41.740",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2168",
"parent_id": "39887",
"post_type": "answer",
"score": 0
},
{
"body": "Windows限定ですが、/fの強制終了と/tの子プロセス含むのオプションを付けて、taskkillコマンドを実行するのが良いかもしれません。 \n[release Selenium chromedriver.exe from\nmemory](https://stackoverflow.com/questions/21320837/release-selenium-\nchromedriver-exe-from-memory) \n[Is it possible to kill a process on Windows from within\nPython?](https://stackoverflow.com/questions/6278847/is-it-possible-to-kill-a-\nprocess-on-windows-from-within-python)\n\nあるいは、アプリで作った自分の子プロセスとseleniumで作ったWebDriverの子プロセスの両方を別々に終了させる必要があるのかもしれません。\n\nなお、必要ならばrunasで管理者権限にて実行することもできるはずです。 \n[Set administrator privileges to subprocess.check_call() in\nPython](https://stackoverflow.com/questions/20505893/set-administrator-\nprivileges-to-subprocess-check-call-in-python) \n[Request UAC elevation from within a Python\nscript?](https://stackoverflow.com/questions/130763/request-uac-elevation-\nfrom-within-a-python-script) \n[Run .exe file via Python as\nAdministrator](https://superuser.com/questions/615654/run-exe-file-via-python-\nas-administrator)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-15T00:57:38.563",
"id": "40289",
"last_activity_date": "2017-12-15T01:48:52.600",
"last_edit_date": "2017-12-15T01:48:52.600",
"last_editor_user_id": "26370",
"owner_user_id": "26370",
"parent_id": "39887",
"post_type": "answer",
"score": 0
}
]
| 39887 | null | 39891 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "AWSのcognitoにてidトークンによる認証をおこなっています。 \nその中でトークンの有効期限が切れた場合に、リフレッシュトークンを用いてidトークンの再発行を行い、httpリクエストを継続できるような実装を考えております。\n\n上記を実現しようとした際、idトークンの有効期限はクライアントのクッキー(メモリ)に保持しておき、有効期限が切れていたら、リフレッシュトークンを用いてidの再発行をサーバ(aws)にリクエストするのがベストプラクティスでしょうか。 \nしかし、それだと毎回httpリクエストの前にidトークンの有効期限をチェックしなければいけないのでその方法がいいか気になり質問させていただきました。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T14:25:19.423",
"favorite_count": 0,
"id": "39889",
"last_activity_date": "2023-07-27T02:01:10.123",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19977",
"post_type": "question",
"score": 0,
"tags": [
"aws",
"oauth",
"aws-lambda"
],
"title": "リフレッシュトークンによるidトークン再発行の実装方法",
"view_count": 1079
} | [
{
"body": "いま手元にコードがないので、うろ覚えですが、cognitoのgetSession(だったかな?)メソッドを呼べば必要に応じてRefreshもやってくれます。 \nまた、これもうろ覚えです、useCodeGrantFlowを呼ばないとRefreshはできないはずです。 \nこれらをキーワードにしてググってみてください。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2019-06-01T09:39:35.443",
"id": "55434",
"last_activity_date": "2019-06-01T09:39:35.443",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "34547",
"parent_id": "39889",
"post_type": "answer",
"score": 0
}
]
| 39889 | null | 55434 |
{
"accepted_answer_id": null,
"answer_count": 4,
"body": "Windowsの.batファイルを`プログラムから開く`にはどうすればいいのでしょうか? \n右クリックしても`プログラムから開く`メニューが見当たりません \nAtom Editorなどを使って開きたいです \nただし、拡張子の関連付けを変更したくはありません。(普通に開くとcmd.exeで実行されるようにはしておきたい) \nどうすればいいのでしょうか?\n\nOS: windows10 Home 1709",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T14:26:20.957",
"favorite_count": 0,
"id": "39890",
"last_activity_date": "2017-11-29T01:04:38.210",
"last_edit_date": "2017-11-28T13:02:52.093",
"last_editor_user_id": "5246",
"owner_user_id": "5246",
"post_type": "question",
"score": 2,
"tags": [
"windows-10",
"batch-file"
],
"title": "Windowsで.batファイルを右クリックしても\"プログラムから開く\"メニューがない",
"view_count": 12855
} | [
{
"body": "* 開きたいプログラムにD&Dする\n * 右クリックで編集を押す\n\nお好きな方を",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T02:34:31.780",
"id": "39896",
"last_activity_date": "2017-11-28T02:34:31.780",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "23941",
"parent_id": "39890",
"post_type": "answer",
"score": 0
},
{
"body": "「送る」を使う方法があります。\n\nエクスプローラーで `shell:sendto` を開いて、プログラムのショートカットを作成してください。.bat ファイル\nを右クリック→送る→作成したショートカット を選べばプログラムから開くことが出来ます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T05:16:17.657",
"id": "39898",
"last_activity_date": "2017-11-28T05:16:17.657",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5008",
"parent_id": "39890",
"post_type": "answer",
"score": 3
},
{
"body": ".batファイルには、コマンドプロンプトで実行されるプログラムを書きます。 \nなので、コマンドプロンプトで.batファイルを実行することが出来ます。\n\n具体的には、以下のような操作をします \n・コマンドプロンプトを起動して、コマンドプロンプトのウィンドウに.batファイルをドラッグ&ドロップする。 \n・コマンドプロンプトで、.batファイル名を入力してリターンキーを押す。(.batファイル名の前にフォルダ名を付ける必要がある事もある。どのフォルダーに居るのかに依存)\n\n[補足] \n.batファイルがメッセージを表示するものの場合、「送る」でショートカットを作って、それをクリックする方法は良くありません。というのは、ショートカットをクリックするとコマンドプロンプトが起動されて、.batファイルが実行され、実行が終わると同時にコマンドプロンプトが終了(画面から消える)するので、メッセージを読む余裕がないからです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T07:20:42.197",
"id": "39901",
"last_activity_date": "2017-11-28T07:20:42.197",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "217",
"parent_id": "39890",
"post_type": "answer",
"score": 0
},
{
"body": "送るなどに入れても実現できますが、`右クリック~送る~Atom`と選択するよりも、`右クリック~Atom`とできた方がワンクッション少なくて良いかな?と思うのでレジストリをいじる方法を提案します。\n\n* * *\n\n 1. レジストリを開く\n\n`Windows + r`を押して`regedit`を入力、レジストリエディタを起動します。 \n`\\HKEY_CURRENT_USER\\Software\\Classes\\*\\`に移動します。 \n`*`の並びにズラッと並んでるのは拡張子です。 \n今回は`.bat`だけを対象にしようとしたんですが、どうにもできなかったので`*`でやります。 \n`*`以下に設定すると全てのファイルが対象になるので、bat以外のファイルのメニューにも増えてしまいますが...\n\n 2. atom用のキーを作る\n\n`*`を右クリックして[新規]-[キー]を選択。新しいキーの名前を`shell`に変更。 \n更にその下に`atom`というキーを作る。この`atom`という名前自体は何でも良いです。\n\n 3. 右クリックメニューを作る\n\n先程作ったキー`atom`をクリックすると、右側に`(規定)`というのがあると思います。 \n(規定)をダブルクリックするとダイアログが開くので、『値のデータ』というところにメニュー名を入力してやります。 \n今回は`Open with Atom`にします。 \n※本来、任意のメニュー名が設定できるんですが、この設定をしてAtomを起動すると、Atom本来の設定と被ってしまって強制的にメニュー名が変えられてしまうようです。\n\n 4. 実行ファイルを指定する\n\n先程作ったキー`atom`の下に`command`というキーを作ってやります。 \nできた`command`をクリックすると、右側に`(規定)`というのがあります。 \n(規定)をダブルクリックするとダイアログが開くので、『値のデータ』というところに実行ファイルへのpathを入力してやります。 \natomの実行ファイルが`C:\\Users\\hoge\\AppData\\Local\\atom\\app-1.19.2\\atom.exe`にあるとしたら、 \n`\"C:\\Users\\hoge\\AppData\\Local\\atom\\app-1.19.2\\atom.exe\" \"%1\"` \nと指定してやります。 \nちなみに、ダブルクォーテーションで囲んでやらないと、半角スペースなどを含むpathで開けないことがあるので注意。\n\n 5. 試してみる\n\n適当なbatファイルを右クリックしてみてください。 \n`Atom Editor`というメニューが増えて、そのメニューを選択するとAtomが起動すると思います。 \n最初に言いましたが、全てのファイルでメニューが追加されてると思うので、txtやdocx、html、jsなどでも同様のメニューで開けることを確認してみてください。\n\n* * *\n\n参考までに、Atomだけで良いのなら、Atomの設定から簡単に右クリックメニューに『Open with Atom』というメニューを追加・削除できますよ。\n\n[File]-[Settings]でSettingsが開く。 \nSystemを選択で表示される \n`Show in file context menus`で、全ての種類のファイルの右クリックメニューに、 \n`Show in foler context menus`で、フォルダの右クリックメニューに、 \n`Open with Atom`というメニューが追加できます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T00:54:04.950",
"id": "39924",
"last_activity_date": "2017-11-29T01:04:38.210",
"last_edit_date": "2017-11-29T01:04:38.210",
"last_editor_user_id": "2383",
"owner_user_id": "2383",
"parent_id": "39890",
"post_type": "answer",
"score": 2
}
]
| 39890 | null | 39898 |
{
"accepted_answer_id": "39893",
"answer_count": 1,
"body": "```\n\n int w = 98;\n int x = 99;\n int y = 0;\n int z = 1;\n \n if(x >= 99)\n {\n if(x < 99)\n cout << y << endl;\n else\n cout << z << endl;\n }\n else\n {\n if(x == 99)\n cout << x << endl;\n else\n cout << w << endl;\n }\n \n```\n\n上記コードのアウトプットは99と表示されると考えておりましたが、実際には1と表示されます。 \n理由につき、ご教示いただけますと幸いです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T16:02:04.110",
"favorite_count": 0,
"id": "39892",
"last_activity_date": "2017-11-27T16:29:26.510",
"last_edit_date": "2017-11-27T16:29:26.510",
"last_editor_user_id": "3060",
"owner_user_id": "26303",
"post_type": "question",
"score": 0,
"tags": [
"c++"
],
"title": "c++のif else文について",
"view_count": 195
} | [
{
"body": "x = 99は99以上 かつ 99未満\"ではない\"ため \nz = 1が表示されています",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T16:16:02.723",
"id": "39893",
"last_activity_date": "2017-11-27T16:16:02.723",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26230",
"parent_id": "39892",
"post_type": "answer",
"score": 1
}
]
| 39892 | 39893 | 39893 |
{
"accepted_answer_id": "39905",
"answer_count": 1,
"body": "あるページ(親)から別ドメインのページ(子)をiframeにて表示しており \n親ページでのイベントで、文字の大きさ等を変更するjsを実行した場合に \niframe内のDOMにも反映したいのですが \nクロスドメイン制約の為、直接変更することができず困っております。\n\nCORSのレスポンスヘッダー(Access-Control-Allow-Origin)のように、 \nクロスドメインでのDOM操作を許可する設定方法、 \nまたは別のやり方で回避する方法がありましたら教えて頂きたいです。\n\n宜しくお願い致します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T07:13:41.167",
"favorite_count": 0,
"id": "39900",
"last_activity_date": "2017-11-28T09:46:14.173",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20906",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"cors"
],
"title": "クロスドメインでのiframe内DOM操作",
"view_count": 10537
} | [
{
"body": "`postMessage`を使うのはどうでしょう?\n<https://developer.mozilla.org/ja/docs/Web/API/Window/postMessage> \nこんなiframeのとき\n\n```\n\n <iframe id=\"iframeID\" src=\"url\"></iframe>\n \n```\n\niframeのwindowオブジェクトでiframeの中へメッセージを送り\n\n```\n\n var iframeOBJ = document.getElementById('iframeID').contentWindow;\n iframeOBJ.postMessage(\"メッセージを送る\", 'iframeで表示しているurl');\n \n```\n\niframe中では、イベント'message'で待ち、メッセージが来たら処理する。\n\n```\n\n window.addEventListener('message', function(event){\n //event.data を見て処理を分岐させる。\n if(\"メッセージを送る\" == event.data ) { /*何かの処理*/ }\n });\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T09:46:14.173",
"id": "39905",
"last_activity_date": "2017-11-28T09:46:14.173",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "22793",
"parent_id": "39900",
"post_type": "answer",
"score": 1
}
]
| 39900 | 39905 | 39905 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "SQLite3を使用し、以下のようなデータを想定しているのですが、「type_idが同一で、日付が連番となっているデータについて、(type_id、開始日、終了日)を抽出する」ことはできますでしょうか。\n\n◇data \n・id : Integer(primary key) \n・type_id : Integer \n・date : Date\n\n実際のデータは、 \n| id | type_id | date | \n| 1 | 1 | date(2017, 1, 1) | \n| 2 | 1 | date(2017, 1, 1) | \n| 3 | 1 | date(2017, 1, 2) | \n| 4 | 1 | date(2017, 1, 2) | \n| 5 | 1 | date(2017, 1, 3) | \n| 6 | 1 | date(2017, 1, 3) | \n| 7 | 1 | date(2017, 1,17) | \n| 8 | 1 | date(2017, 1,18) | \n| 9 | 1 | date(2017, 1,19) | \n| 10 | 1 | date(2017, 2, 1) | \n... \n| ? | 2 | date(2017, 1, 1) | \n... \nのようになっています。\n\n上の例で、期待するレスポンスは、\n\n(1, date(2017, 1, 1), date(2017, 1, 3)) \n(1, date(2017, 1,17), date(2017, 1,19)) \n...\n\nといった具合です。\n\nどうぞよろしくお願いいたします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T08:43:37.537",
"favorite_count": 0,
"id": "39904",
"last_activity_date": "2017-11-30T08:31:13.473",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26359",
"post_type": "question",
"score": 1,
"tags": [
"sql",
"sqlite"
],
"title": "SQLiteで日付が連続になっているデータをまとめたい",
"view_count": 385
} | [
{
"body": "* 1日後のエントリがないエントリを探す(*1)\n * (*1)のエントリそれぞれについて、過去、かつ最近のエントリを探し、その日数差を求める\n * (*1)と元のテーブルを結合し、過去、かつ上記日数差以内のエントリごとにまとめる\n\nとすれば求まりますが、多数回の自己結合操作をしなければならない高コストなクエリを発行する必要があります\n\n共通テーブル式の再帰を用いれば、より簡潔な記述ができると思います \n<https://sqlite.org/lang_with.html>\n\n```\n\n SELECT\n MIN(T2.id) AS id,\n MIN(T2.date) AS date_min,\n MAX(T2.date) AS date_max\n FROM (\n SELECT\n T1.id,\n T1.type_id,\n T1.date,\n COALESCE(T1.date - MAX(T2.date), 365) AS diff\n FROM (\n /* ---- 同じ ---- */\n SELECT\n MIN(T1.id) AS id,\n MIN(T1.type_id) AS type_id,\n MIN(T1.date) AS date\n FROM\n my_table T1\n LEFT JOIN\n my_table T2 ON (T1.type_id = T2.type_id AND T1.date + 1 = T2.date)\n GROUP BY\n T1.type_id, T1.date\n HAVING\n MIN(T2.date) IS NULL\n /* ---- 同じ ---- */\n ) T1\n LEFT JOIN (\n /* ---- 同じ ---- */\n SELECT\n MIN(T1.id) AS id,\n MIN(T1.type_id) AS type_id,\n MIN(T1.date) AS date\n FROM\n my_table T1\n LEFT JOIN\n my_table T2 ON (T1.type_id = T2.type_id AND T1.date + 1 = T2.date)\n GROUP BY\n T1.type_id, T1.date\n HAVING\n MIN(T2.date) IS NULL\n /* ---- 同じ ---- */\n ) T2 ON (T1.type_id = T2.type_id AND T1.date > T2.date)\n GROUP BY\n T1.id,\n T1.type_id,\n T1.date\n ) T1\n LEFT JOIN\n my_table T2 ON (T1.type_id = T2.type_id AND T1.date >= T2.date AND T1.date - diff < T2.date)\n GROUP BY\n T1.id\n ORDER BY\n T1.id\n ;\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T08:31:13.473",
"id": "39948",
"last_activity_date": "2017-11-30T08:31:13.473",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9796",
"parent_id": "39904",
"post_type": "answer",
"score": 2
}
]
| 39904 | null | 39948 |
{
"accepted_answer_id": "39919",
"answer_count": 2,
"body": "今、 ubuntu/xenial64 を指定して、 vagrant で、 virtualbox の仮想マシンを起動しました。 vagrant ssh\nを行うと、次のエラーメッセージが表示されます。\n\n```\n\n manpath: can't set the locale; make sure $LC_* and $LANG are correct\n \n```\n\n上記はワーニング的で、表示されたからといってシェルが起動しないわけでもなく、少し触ってみても、得に何か取り立てて問題がおこっている訳ではないのですが、ワーニングならば、わざわざ罠にはまる前に解消しておきたいと考えました。\n\n質問: 上記エラーメッセージを解消するには、何をやったらいいのでしょうか?",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T10:25:55.227",
"favorite_count": 0,
"id": "39907",
"last_activity_date": "2017-11-28T16:44:05.820",
"last_edit_date": "2017-11-28T16:44:05.820",
"last_editor_user_id": "754",
"owner_user_id": "754",
"post_type": "question",
"score": 0,
"tags": [
"ubuntu",
"locale",
"openssh"
],
"title": "ubuntu 16.04 で can't set locale を解消するには?",
"view_count": 1514
} | [
{
"body": "英語版SOにも同様のやり取りがありました。 \n[manpath: can't set the locale; make sure $LC_* and $LANG are correct - Stack\nOverflow](https://stackoverflow.com/questions/45995530/manpath-cant-set-the-\nlocale-make-sure-lc-and-lang-are-correct)\n\n日本語環境に置き換えると\n\n```\n\n sudo locale-gen \"ja_JP.UTF-8\"\n sudo dpkg-reconfigure locales\n \n```\n\nまた、`/etc/default/locale`をエディタで開いて`LC_ALL=\"ja_JP.UTF-8\"`を追記または編集後、念のためマシンにログインし直してみてください。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T11:52:30.943",
"id": "39910",
"last_activity_date": "2017-11-28T11:52:30.943",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3060",
"parent_id": "39907",
"post_type": "answer",
"score": 0
},
{
"body": "mac から vagrant ssh していたのですが、 mac の ssh が\n\n```\n\n SendEnv LANG LC_*\n \n```\n\nする設定になっていて、そのためにローカルの `LC_*` 系の環境変数が送られてしまい、 ubuntu \nのシステムに入っていないロケールの値が指定され、おかしくなっていました。\n\nmac の `/etc/ssh/ssh_config` にて、上記設定行をコメントアウトすることで、解決しました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T16:33:24.527",
"id": "39919",
"last_activity_date": "2017-11-28T16:33:24.527",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"parent_id": "39907",
"post_type": "answer",
"score": 1
}
]
| 39907 | 39919 | 39919 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "`INFO: Python2 version: 3.6.3↲`となってしまうのは何故でしょうか。 \nvirtualenvでpy2用のneovim2とpy3用のneovim3は作っています。\n\n```\n\n health#provider#check↲\n ========================================================================↲\n ## Clipboard (optional)↲\n - OK: Clipboard tool found: pbcopy↲\n ↲\n ## Python 2 provider (optional)↲\n - OK: pyenv found: \"/Users/okamura/dotfiles/.pyenv/libexec/pyenv\"↲\n - INFO: Using: g:python_host_prog = \"~/.pyenv/versions/neovim2/bin/python\"↲\n - INFO: Executable: /Users/okamura/.pyenv/versions/3.6.3/bin/python↲\n - WARNING: Unexpected Python version. This could lead to confusing error messages.↲\n - INFO: Python2 version: 3.6.3↲\n - INFO: python-neovim version: 0.2.0↲\n - OK: Latest python-neovim is installed: 0.2.0↲\n ↲\n ## Python 3 provider (optional)↲\n - OK: pyenv found: \"/Users/okamura/dotfiles/.pyenv/libexec/pyenv\"↲\n - INFO: Using: g:python3_host_prog = \"~/.pyenv/versions/neovim3/bin/python\"↲\n - INFO: Executable: /Users/okamura/.pyenv/versions/3.6.3/bin/python↲\n - INFO: Python3 version: 3.6.3↲\n - INFO: python-neovim version: 0.2.0↲\n - OK: Latest python-neovim is installed: 0.2.0↲\n \n```\n\n`.config/nvim/init.vim`には下記の2行を記載しています。\n\n```\n\n let g:python_host_prog = '~/.pyenv/versions/neovim2/bin/python'↲\n let g:python3_host_prog = '~/.pyenv/versions/neovim3/bin/python'\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-11-28T12:43:19.767",
"favorite_count": 0,
"id": "39911",
"last_activity_date": "2022-08-19T01:55:00.063",
"last_edit_date": "2022-08-19T01:55:00.063",
"last_editor_user_id": "3060",
"owner_user_id": "26365",
"post_type": "question",
"score": 1,
"tags": [
"python",
"vim",
"neovim"
],
"title": "neovimのCheckHealthでpython2がpython3を見に行ってしまう",
"view_count": 655
} | [
{
"body": "すいません自己解決しました。`python_host_prog`をフルパスにしたら治りました\n\n```\n\n health#provider#check↲\n ========================================================================↲\n ## Clipboard (optional)↲\n - OK: Clipboard tool found: pbcopy↲\n ↲\n ## Python 2 provider (optional)↲\n - OK: pyenv found: \"/Users/okamura/dotfiles/.pyenv/libexec/pyenv\"↲\n - INFO: Using: g:python_host_prog = \"/Users/okamura/dotfiles/.pyenv/versions/neovim2/bin/python\"↲\n - INFO: Executable: /Users/okamura/dotfiles/.pyenv/versions/neovim2/bin/python↲\n - INFO: Python2 version: 2.7.14↲\n - INFO: python-neovim version: 0.2.0↲\n - OK: Latest python-neovim is installed: 0.2.0↲\n ↲\n ## Python 3 provider (optional)↲\n - OK: pyenv found: \"/Users/okamura/dotfiles/.pyenv/libexec/pyenv\"↲\n - INFO: Using: g:python3_host_prog = \"/Users/okamura/dotfiles/.pyenv/versions/neovim3/bin/python\"↲\n - INFO: Executable: /Users/okamura/dotfiles/.pyenv/versions/neovim3/bin/python↲\n - INFO: Python3 version: 3.6.3↲\n - INFO: python-neovim version: 0.2.0↲\n - OK: Latest python-neovim is installed: 0.2.0↲\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T13:00:21.610",
"id": "39912",
"last_activity_date": "2017-11-28T13:00:21.610",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26365",
"parent_id": "39911",
"post_type": "answer",
"score": 1
}
]
| 39911 | null | 39912 |
{
"accepted_answer_id": "39918",
"answer_count": 1,
"body": "if(i = 0) でも 以下のJavaScriptコードが内容を実行するのはなぜですか? if( \"==\")でなければならないことを知っていますが。\n\"I'm\"と \"A\" \"A\" \"A\"...という出力を得ることができます。PythonやJavaで見たことがないと思います。\n\n```\n\n function titleCase(str) {\r\n var array = str.split(\" \");\r\n var str1 = \"\";\r\n var i = 0;\r\n while(i < array.length){\r\n str = array[i]\r\n if(i = 0){\r\n console.log(str.charAt(0).toUpperCase() + str.substring(1));\r\n }else{\r\n console.log(console.log(str.charAt(0).toUpperCase() + str.substring(1)));\r\n }\r\n i++;\r\n }\r\n console.log(str1)\r\n }\r\n \r\n titleCase(\"I'm a little tea pot\");\n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T15:10:02.797",
"favorite_count": 0,
"id": "39917",
"last_activity_date": "2017-11-28T15:58:54.683",
"last_edit_date": "2017-11-28T15:24:02.407",
"last_editor_user_id": "25766",
"owner_user_id": "25766",
"post_type": "question",
"score": 0,
"tags": [
"javascript"
],
"title": "java script if else statement if i \"=\" 0でも数回出力する。",
"view_count": 79
} | [
{
"body": "`if(i = 0)`で毎回iに0が代入されてるのに、whileを抜ける条件が『array.lengthより大きくなったら』だからです。 \niは1までしか増えないので永遠にloopを抜けれません。\n\n* * *\n\nstrを取得するタイミングではiは1なので、strにはaが入ってます。 \nif文でiは0になります。\n\nif文は、`i =\n0`の結果である0を評価します。0はfalseとして扱われるので、`console.log(console.log(str.charAt(0).toUpperCase()\n+ str.substring(1)));`しか実行されませんね。\n\nと、いうわけで2回目のloop以降は、永遠にAが出力され続けませんか?",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T15:52:24.683",
"id": "39918",
"last_activity_date": "2017-11-28T15:58:54.683",
"last_edit_date": "2017-11-28T15:58:54.683",
"last_editor_user_id": "2383",
"owner_user_id": "2383",
"parent_id": "39917",
"post_type": "answer",
"score": 2
}
]
| 39917 | 39918 | 39918 |
{
"accepted_answer_id": "39923",
"answer_count": 1,
"body": "C言語入門 (ASCII SOFTWARE SCIENCE Language)に\n\n>\n> 基本データ型の初期化については第3章で説明しました。配列も初期化できますが、記憶クラスが外部変数か静的変数の配列に限定されます。自動変数の配列は初期化できません。配列の初期化は、以下のように行います。\n```\n\n> static int room[6] = {3, 2, 0, 2, 1, 4};\n> \n```\n\nと書かれていました。\n\nこの、「自動変数の配列は初期化できません」が良く分かりません。\n\n最初は、「自動変数として配列を宣言した場合は初期化できない」という事なのかと思ったのですが、 \n以下のコードで考えてみると、それは違うようです。\n\n```\n\n #include <stdio.h>\n \n void tekitou(void);\n int main(void)\n {\n tekitou();\n tekitou();\n return 0;\n }\n \n void tekitou(void)\n {\n // auto int room[]={3,2,0,2,1,4};\n static int room[]={3,2,0,2,1,4};\n // int room[]={3,2,0,2,1,4};\n for (int i=0;i<sizeof(room)/sizeof(int);i++)\n {\n printf(\"%d \",room[i]);\n }\n room[0]=100;\n printf(\"\\n%d\\n\",room[0]);\n }\n \n```\n\n配列の宣言がstaticの場合は出力が\n\n```\n\n 3 2 0 2 1 4\n 100\n 100 2 0 2 1 4\n 100\n \n```\n\nとなり、autoか何も付けない場合は\n\n```\n\n 3 2 0 2 1 4\n 100\n 3 2 0 2 1 4\n 100\n \n```\n\nとなり、静的変数の場合とは挙動が異なり、 \nちゃんと自動変数として配列が初期化できているように思えます。\n\nこの「自動変数の配列は初期化できません」というのは、どういう意味なのでしょうか? \n(単純に本が古いから、現在は仕様が変わったという事かもしれません)",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T17:49:00.283",
"favorite_count": 0,
"id": "39922",
"last_activity_date": "2017-11-30T07:42:05.390",
"last_edit_date": "2017-11-29T05:03:18.087",
"last_editor_user_id": "19110",
"owner_user_id": "25791",
"post_type": "question",
"score": 5,
"tags": [
"c"
],
"title": "「自動変数の配列は初期化できません」の意味が分かりません",
"view_count": 1068
} | [
{
"body": "はい、その解説は古いもので、現在は仕様が変わっているだけです。\n\n以下は蛇足。プログラム言語 [c](/questions/tagged/c \"'c' のタグが付いた質問を表示\")\nの仕様は歴史的に4つにわけることができます。\n\n * 最初の C : Dennis Ritchie が作ったもの(オレオレプログラム言語の1つでしかなかった) \nK&R 本の古いものはこれを解説しています。\n\n * C89 : `ANSI X3.159-1989` 米国国家規格協会で定めた米国内規格 \n俗に ANSI-C と呼ばれているものはこれです。 K&R 本の新しいもの (ANSI 対応と書いてあるもの) はこれを解説しています。 \nC90 : C89 をほぼそのまま `ISO/IEC 9899:1990` として国際規格にしたもの \nC95 : `ISO/IEC 9899/Amd1:1995` 微小な改正 Amendment\nがあって追補の形で規格改正されています。多国語対応のための機能追加があったので日本人はもっと知っておくべきなんですけどね。多くのプログラマは C90\nと同じものとして扱っています。 \nこのような事情により ANSI-C/C89/C90/C95 は同じ規格と考えてよいです。\n\n * C99 : `ISO/IEC 9899:1999` として国際規格が改定されたもの \n市販されているコンパイラの多くはこれに各ベンダが独自の拡張を施したものです。\n\n * C11 : `ISO/IEC 9899:2011` として国際規格が改定されたもの \nこのコメント書いている時点では、パソコン向けコンパイラは対応が進んでいますがマイコン向けコンパイラは対応していないものがほとんどです。\n\n`ISO/IEC 9899` を日本語に翻訳したものが JIS 規格 `JIS X 3010`\nとして採用されています。オイラは今その「本」(紙ですね)を参照してこのコメントを書いています。\n\n最初の C では自動変数として定義された配列の初期化はできませんでした。お持ちのその本はおそらく K&R 本の古いやつで、「最初の C\n」の解説をしているのだと思われます。\n\nC89 では仕様が変更されており、配列の自動変数も初期化できることになっています。 `JIS X 3010-1993` の 6.5.7 初期化 の章の注釈\n(74)\nにて「参考文献1と異なり、自動記憶域期間をもつ任意のオブジェクトを初期化できる」となっています。今オイラが見ている紙の本では検索が効かないので参考文献1が何かを確認できませんが、おそらくあなたの持っている\nK&R 本を指しているはずです。\n\nC99/C11 でもその辺の事情は変わっていませんので「できる」ことになっています。",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-28T21:12:10.970",
"id": "39923",
"last_activity_date": "2017-11-30T07:42:05.390",
"last_edit_date": "2017-11-30T07:42:05.390",
"last_editor_user_id": "8589",
"owner_user_id": "8589",
"parent_id": "39922",
"post_type": "answer",
"score": 10
}
]
| 39922 | 39923 | 39923 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Unityを始めたばかりの初心者です。 \nUnityでゲームを作っているのですが、プレイヤーとエネミーが衝突した時の判定がうまくいかず悩んでいます。 \n具体的にはプレイヤーのコードを\n\n```\n\n void OnTriggerEnter2D(Collider2D col)\n { \n if (col.gameObject.CompareTag(\"地面\"))\n {\n Debug.Log(\"着地\");\n }\n if (col.gameObject.CompareTag(\"エネミー\"))\n {\n Debug.Log(\"衝突\");\n }\n }\n \n```\n\nとしているのですが、ログを見ると地面の着地はうまくいっているのですが、エネミーとの衝突が1回のみ衝突してるはずがログに2回「衝突」と表示されてしまいます。 \nどうすれば1回の衝突で1回の処理になるのでしょうか。 \nよろしくお願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T01:47:24.980",
"favorite_count": 0,
"id": "39925",
"last_activity_date": "2020-10-23T05:04:30.450",
"last_edit_date": "2017-11-29T02:29:53.647",
"last_editor_user_id": "19110",
"owner_user_id": "26371",
"post_type": "question",
"score": 1,
"tags": [
"unity2d"
],
"title": "Unityの衝突判定",
"view_count": 226
} | [
{
"body": "使用されているcollider の問題ではないでしょうか。 \nこちらを参考にしてみてください。\n\n<https://answers.unity.com/questions/1474400/ontriggerenter2d-gets-called-\ntwice-sometimes.html>",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2018-09-19T08:20:14.383",
"id": "48548",
"last_activity_date": "2018-09-19T08:20:14.383",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "30170",
"parent_id": "39925",
"post_type": "answer",
"score": 0
}
]
| 39925 | null | 48548 |
{
"accepted_answer_id": null,
"answer_count": 3,
"body": "毎度、右上をクリックしてユーザーを選ぶのが面倒に思えてきました。\n\nchrome でキーボードショートカットでユーザーを切り替えるにはどうすればよいのでしょうか?\n\nもしくはブラウザを使い分けるとか、他に実践している良い方法がありますか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T02:05:00.293",
"favorite_count": 0,
"id": "39926",
"last_activity_date": "2018-04-09T03:36:10.353",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12896",
"post_type": "question",
"score": 1,
"tags": [
"google-chrome"
],
"title": "chrome のユーザー切り替えのショートカット",
"view_count": 3148
} | [
{
"body": "Windows: `%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\User Data\\` \nMac: `/Users/(ログインID)/Library/Application Support/Google/Chrome`\n\n上記のディレクトリに `Profile 1` などの ユーザープロファイル ディレクトリがあります。 \nこれらを `--profile-directory` オプションで指定できます。\n\n`> chrome.exe --profile-directory=\"Default\"` \n`> chrome.exe --profile-directory=\"Profile 1\"`\n\nあとは、何かしらのアプリケーションランチャーを導入して、起動すれば良いと思います。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T06:31:10.640",
"id": "39929",
"last_activity_date": "2017-11-29T06:31:10.640",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5008",
"parent_id": "39926",
"post_type": "answer",
"score": 0
},
{
"body": "利用しているのが Windows であれば、Chrome\nで複数ユーザーを切り替えて利用するという点で言うと、一旦ユーザーを切り替えた後、当該ユーザーのウィンドウで設定を開くと \"ユーザー名 ‣\"\nと表示されないでしょうか。 \nこの部分をクリックするとユーザー名やアイコンの編集以外に \"デスクトップショートカットを表示\" の on/off 項目がありますので、これを on\nにするとデスクトップにショートカットが表示されます。(\"ユーザー名\" - Chrome)\n\nこれはデスクトップに新しいリンクとして作成されますが、そのままスタートにピン留めすると「デスクトップにあるショートカットをピン留めした」扱いとなるため、%APPDATA%\\Microsoft\\Windows\\Start\nMenu\\Programs 以下にコピーした上で……というのが、タスクバー上に常駐させたいといった場合には良いかもしれません。 \nデスクトップにアイコンを置いておくだけでいいなら、単に「デスクトップショートカットを表示」だけで良いでしょう。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2018-04-08T21:47:14.450",
"id": "43070",
"last_activity_date": "2018-04-08T21:47:14.450",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13613",
"parent_id": "39926",
"post_type": "answer",
"score": 0
},
{
"body": "Windowsであれば「Ctrl + Shift + M」でユーザー切り替えができるようです。\n\n[Chrome のキーボード ショートカット - Google Chrome\nヘルプ](https://support.google.com/chrome/answer/157179?hl=ja)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2018-04-08T22:07:46.527",
"id": "43071",
"last_activity_date": "2018-04-09T03:36:10.353",
"last_edit_date": "2018-04-09T03:36:10.353",
"last_editor_user_id": "3060",
"owner_user_id": "3060",
"parent_id": "39926",
"post_type": "answer",
"score": 1
}
]
| 39926 | null | 43071 |
{
"accepted_answer_id": "39932",
"answer_count": 2,
"body": "javascriptを使用しcanvasでペイントツールを作成しています。\n\nこのとき stroke()関数を使って太い線を引いた時に、縁が実際に指定したRGBとは違う値が出てきてしまいます。 \nアンチエイリアス処理が働いている様ですが、これをやらない方法はあるのでしょうか? \nコンテキストのアンチエイリアス処理はOFFにしてありますがそれでもなってしまいます。\n\n```\n\n ctx.beginPath();\n ctx.lineWidth = 10;\n ctx.moveTo(startX, startY);\n ctx.lineTo(endX, endY);\n ctx.stroke();\n \n```\n\nこの様な処理で線を書いています。 \nstartとendはマウスイベントで取得しています。\n\nこの時こうなってしまいます。 \n[](https://i.stack.imgur.com/682ap.png)\n\nこうなってほしいです。(ペイントで少し修正しました。) \n[](https://i.stack.imgur.com/CMyle.png)\n\nどなたか分かる方ご教授お願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T02:32:28.500",
"favorite_count": 0,
"id": "39927",
"last_activity_date": "2017-11-29T10:24:10.357",
"last_edit_date": "2017-11-29T04:56:47.797",
"last_editor_user_id": "26372",
"owner_user_id": "26372",
"post_type": "question",
"score": 4,
"tags": [
"javascript"
],
"title": "canvas stroke()をした時の線の縁をぼやけさせない様にする方法について",
"view_count": 1510
} | [
{
"body": "根本的な解決はしていませんが、求めていた結果は取得できたので解決とします。\n\n解決方法としては、 \n今回はある一定の色を数十色しか使用しない為、線を描くと同時に書いた範囲にgetImageDataを行いRGBを確認して、背景でもなく使用している数十色に当てはまらない場合は今回書いたRGBに無理してからputImageDataを行うというフィルタをかけました。 \nこれで何とか理想の結果になりました。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T07:32:38.213",
"id": "39930",
"last_activity_date": "2017-11-29T07:32:38.213",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26372",
"parent_id": "39927",
"post_type": "answer",
"score": 1
},
{
"body": "以前本家のstackoverflowにて全く同じ質問がありました.\n\nOvercoming antialiasing on canvas lines for mouse event \n<https://stackoverflow.com/questions/46839876/overcoming-antialiasing-on-\ncanvas-lines-for-mouse-event/46840699#46840699>\n\nFireFoxであればアルファ値を除去するSVGフィルタをfilterプロパティに設定するだけ済みます.\n\n```\n\n const ctx = canvas.getContext(\"2d\");\r\n \r\n //normal line(antialiased)\r\n ctx.moveTo(20,20); ctx.lineTo(180,20);\r\n ctx.stroke();\r\n \r\n //set \"crisp edge\" filter\r\n ctx.filter = \"url(#crisp)\";\r\n //crisp line\r\n ctx.beginPath();ctx.moveTo(20,40); ctx.lineTo(180,40);\r\n ctx.moveTo(20, 50); ctx.lineTo(180, 70);\r\n //crisp circle\r\n ctx.moveTo(150, 130); ctx.arc(100, 130, 50, 0, Math.PI*2);\r\n ctx.stroke();\n```\n\n```\n\n <canvas id=\"canvas\" width=\"200\" height=\"200\"></canvas>\r\n <svg style=\"visibility:hidden;width:0;height:0;\">\r\n <defs>\r\n <!--SVG filter to remove alpha-->\r\n <filter id=\"crisp\">\r\n <feComponentTransfer>\r\n <feFuncA type=\"discrete\" tableValues=\"0,1\"></feFuncA>\r\n </feComponentTransfer>\r\n </filter>\r\n </defs>\r\n </svg>\n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T10:24:10.357",
"id": "39932",
"last_activity_date": "2017-11-29T10:24:10.357",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5667",
"parent_id": "39927",
"post_type": "answer",
"score": 2
}
]
| 39927 | 39932 | 39932 |
{
"accepted_answer_id": "39934",
"answer_count": 1,
"body": "以下の構造になってるテーブル郡があり、全てのテーブルにデータが幾つか入っているとします。\n\n```\n\n CREATE TABLE A (\n id BIGINT(20) NOT NULL AUTO_INCREMENT,\n PRIMARY KEY(id)\n );\n CREATE TABLE B (\n id BIGINT(20) NOT NULL AUTO_INCREMENT,\n a_id BIGINT(20) NOT NULL,\n PRIMARY KEY(id),\n FOREIGN KEY(a_id) REFERENCES A(id)\n );\n CREATE TABLE C (\n id BIGINT(20) NOT NULL AUTO_INCREMENT,\n a_id BIGINT(20) NOT NULL,\n PRIMARY KEY(id),\n FOREIGN KEY(a_id) REFERENCES A(id)\n );\n \n```\n\nその後、テーブルCに対して\n\n 1. a_idを削除したい(DROP FOREIGN KEY, DROP COLUMN)\n 2. b_idという外部キーを追加したい。\n\nという要件があり、以下のようなSQLを書きました。\n\n```\n\n INSERT INTO A VALUES();\n SELECT @A_ID:=last_insert_id();\n \n INSERT INTO B (b_id) VALUES(@A_ID);\n SELECT @B_ID:=last_insert_id();\n \n ALTER TABLE C ADD COLUMN b_id BIGINT(20) NOT NULL DEFAULT @B_ID,\n ADD CONSTRAINT FOREIGN KEY (b_id) REFERENCES B(id);\n \n ALTER TABLE C DROP FOREIGN KEY `c_ibfk_1`;\n ALTER TABLE C DROP COLUMN a_id;\n \n```\n\nですが、`ADD COLUMN`の`DEFAULT @B_ID`がシンタックスエラーになります。\n\nこのように`ALTER TABLE`で外部キーを追加しつつ、`NOT NULL`にしたいようなケースでは \nどのようなSQLを書くべきでしょうか。\n\nご教示いただければ幸いでございます。 \nどうぞよろしくお願い致します。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T08:48:29.307",
"favorite_count": 0,
"id": "39931",
"last_activity_date": "2017-11-29T11:34:58.653",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5836",
"post_type": "question",
"score": 0,
"tags": [
"mysql",
"sql"
],
"title": "MySQLにおいてDEFAULT値にユーザ定義変数を指定することは可能でしょうか?",
"view_count": 455
} | [
{
"body": "1ステートメントで実現するのは難しいのではないでしょうか\n\n * ADD COLUMN\n * UPDATE\n * ADD CONSTRAINT\n\nの3つのステートメントに分割するのが無難だと思います\n\nただ、mysqlはDDLにtransactionがかからないので、オンラインで作業を実施するときは問題になるかもしれません",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T11:34:58.653",
"id": "39934",
"last_activity_date": "2017-11-29T11:34:58.653",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9796",
"parent_id": "39931",
"post_type": "answer",
"score": 0
}
]
| 39931 | 39934 | 39934 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "gccにおける-staticオプションのような手法で,nvcc(cuda)で静的リンクをつけてコンパイルすることは可能でしょうか? \nシミュレータ上でcuda-stream\nbenchmarkを走らせたいのですが,シミュレータが動的リンクに対応していないため,nvccで静的リンクできる手法を必要としています. \nコンパイルに使用するCUDA等のバージョンは問いません. \nよろしくお願い致します.",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T10:52:34.493",
"favorite_count": 0,
"id": "39933",
"last_activity_date": "2017-12-01T15:09:02.073",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26314",
"post_type": "question",
"score": 0,
"tags": [
"cuda",
"compiler"
],
"title": "nvcc(cuda)での静的リンクをつけてのコンパイル",
"view_count": 754
} | [
{
"body": "質問するときは最低限のマナーとして、環境(OS、ハードウェア、……)に関する情報を詳しく書いてください。\n\n[技術系メーリングリストで質問するときのパターン・ランゲージ](http://www.hyuki.com/writing/techask.html#env)\n\n具体的にCUDAの何を静的リンクしたいのかが明記されていませんが、CUDA 5.5以降でRuntime APIライブラリの静的リンクに対応しています。\n\n[NVCC :: CUDA Toolkit Documentation](http://docs.nvidia.com/cuda/cuda-\ncompiler-driver-nvcc/index.html)\n\n> `--cudart {none|shared|static}`\n\n質問する前に公式マニュアルくらいは目を通してください。\n\nなお、Driver APIやcuBLAS、cuFFTなどは静的リンクに対応していないらしいです。\n\n[CUDA 5.5の新機能(2): CUDA Runtimeの静的リンク -\nトータル・ディスクロージャ・サイト(事実をありのままに)](http://topsecret.hpc.co.jp/wiki/index.php/CUDA_5.5%E3%81%AE%E6%96%B0%E6%A9%9F%E8%83%BD\\(2\\):_CUDA_Runtime%E3%81%AE%E9%9D%99%E7%9A%84%E3%83%AA%E3%83%B3%E3%82%AF)",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-01T15:09:02.073",
"id": "39969",
"last_activity_date": "2017-12-01T15:09:02.073",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "15413",
"parent_id": "39933",
"post_type": "answer",
"score": -1
}
]
| 39933 | null | 39969 |
{
"accepted_answer_id": "39941",
"answer_count": 1,
"body": "vagrant 上の ubuntu16.04 (box 名称 ubuntu/xenial64) に、 mysql\nをインストールしようとしています。このサーバーは、ひとまず host <-> guest のネットワークのみから、アクセスできるようにしています。 (IP\n指定で private_network を指定している。)\n\nこの上にインストールした mysql に対して、ホストからアクセスしたいです。現状だと、以下のエラーが発生します。\n\n```\n\n $ mysql -h 192.168.33.20 -uroot\n ERROR 1130 (HY000): Host '192.168.33.1' is not allowed to connect to this MySQL server\n \n```\n\n少しネットで検索した結果、 `grant all` をやればよい、と書いあるのが多いので、ゲスト(ubuntu) の中で、それを実行してみた結果が次です。\n\n```\n\n mysql> grant all privileges on *.* to 'root'@'%';\n ERROR 1133 (42000): Can't find any matching row in the user table\n \n```\n\n### 質問\n\n * どうやったら、任意のホストからの root アクセスを、このサーバーに対して許可することができますか? \n * 開発用で、プライベートネットワークに閉じた範囲でしかアクセスできない用途で使うので、セキュリティはなくてもいいです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T14:30:26.247",
"favorite_count": 0,
"id": "39937",
"last_activity_date": "2017-11-30T02:34:16.350",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"post_type": "question",
"score": 0,
"tags": [
"mysql",
"ubuntu"
],
"title": "ubuntu 16.04 でインストールした mysql-5.7 に対して、 root のすべてのアクセスを grant したい",
"view_count": 231
} | [
{
"body": "GRANT の前にユーザーを作る必要があります。\n\n```\n\n mysql> CREATE USER 'root'@'%';\n \n```\n\n以前は GRANT が CREATE USER も兼ねてたのですが、今は別になったようです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T02:34:16.350",
"id": "39941",
"last_activity_date": "2017-11-30T02:34:16.350",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3249",
"parent_id": "39937",
"post_type": "answer",
"score": 3
}
]
| 39937 | 39941 | 39941 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "pythonについての質問です。urllib.request.urlopen().read()でページのソースを取得しようとしたのですが、思い通りに取得できません。詳細は以下です。以下のプログラムにより、指定したurlのソースを取得し、\"1.txt\"に出力しました。\n\n```\n\n import urllib.request\n \n url = \"http://www.data.jma.go.jp/obd/stats/etrn/view/10min_a1.php?\n prec_no=91&block_no=47945&year=2016&month=8&day=22&view=\"\n html_nodecoded = urllib.request.urlopen(url).read()\n html_decoded = html_nodecoded.decode('utf-8')\n \n filename = \"1.txt\"\n fa = open(filename,\"w\",encoding=\"utf-8\")\n fa.write(html_decoded)\n fa.close()\n \n```\n\nしかしながら問題ここで問題が起こりました。 \n正確にhtmlを取得できているか確認するためにページのソースと\"1.txt\"を比べたところ、一部が食い違っており、正確に取得できていないことがわかりました。 \n以下は、\"1.txt\"のうち正確に取得できていなかった部分の近辺を抜き出したものです。\n\n「\"1.txt\"(説明に必要な部分)」\n\n```\n\n ..........\n ..(省略)..\n ..........\n <li>10分ごとの値</li>\n </ul></div>\n <!-- //pankuzu menu -->\n \n <div id=\"main\">\n <!-- contents -->\n <h1 class=\"print\">10分ごとの値</h1>\n \n <br />ページを表示することが出来ませんでした。<br />ブラウザの「戻る」ボタンをクリ\n ックしてください。</div></div></div><div id=\"footer_area\"><div id=\"nfooter\">\n <p>気象庁:〒100-8122東京都千代田区大手町1-3-4 代表電話:03-3212-8341</p><ul>\n <li><a href=\"http://www.jma.go.jp/jma/kishou/info/coment.html\">気象庁ホームペ\n ージについて</a></li></ul></div></div></body></html>\n \n```\n\n取得先のページのソースを確認したところ、ソースコードの一部分が \n`<br />ページを表示することが出来ませんでした。<br />ブラウザの「戻る」ボタンをクリックしてください。</div>` \nと置き換わってしまっていることがわかりました。\n\n取得先のページのURLは以下です。 \n[http://www.data.jma.go.jp/obd/stats/etrn/view/10min_a1.php?prec_no=91&block_no=47945&year=2016&month=8&day=22&view=](http://www.data.jma.go.jp/obd/stats/etrn/view/10min_a1.php?prec_no=91&block_no=47945&year=2016&month=8&day=22&view=)\n\nどうすれば正確に取得できるかわからず途方に暮れています。。\n\n実行環境はpython3.7、windows10のコマンドプロンプトです。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-29T16:32:50.867",
"favorite_count": 0,
"id": "39938",
"last_activity_date": "2017-12-04T07:01:58.843",
"last_edit_date": "2017-12-04T07:01:58.843",
"last_editor_user_id": "19110",
"owner_user_id": "26384",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"python",
"html",
"python3"
],
"title": "URLからHTMLを取得すると「ページを表示することができませんでした」と返ってくる",
"view_count": 337
} | [
{
"body": "取得しているURLを再度確認してください。 \n見てみましたがHTTPのリクエストが存在しないだけですよ。 \n例えば以下なら正しく取得できました。\n\n```\n\n \"http://www.data.jma.go.jp/obd/stats/etrn/view/10min_a1.php?prec_no=44&block_no=1133&year=2016&month=8&day=22&view=\"\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T06:37:25.853",
"id": "39976",
"last_activity_date": "2017-12-02T06:37:25.853",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26446",
"parent_id": "39938",
"post_type": "answer",
"score": 2
}
]
| 39938 | null | 39976 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "以下のコードが何をしてるのか分かりましたら具体的に教えて下さい。\n\n`std::sheard_ptr<std::vector<std::sheard_ptr<RxInfos>>> rxinfo;`",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-27T09:31:50.373",
"favorite_count": 0,
"id": "39940",
"last_activity_date": "2017-11-30T02:59:25.307",
"last_edit_date": "2017-11-30T02:58:18.713",
"last_editor_user_id": "19110",
"owner_user_id": "26348",
"post_type": "question",
"score": 0,
"tags": [
"c++"
],
"title": "標準ライブラリが入り混じったコードの意味が知りたい",
"view_count": 248
} | [
{
"body": "[cpprefjp](https://cpprefjp.github.io/reference/memory/shared_ptr.html) から\n`std::shared_ptr` の解説を引用します。\n\n> `shared_ptr` は、指定されたリソースへの所有権(ownership)を共有(share)するスマートポインタである。\n\nこのもとで、ご提示のソースは「`RxInfo` への `shared_ptr` のベクターへの `shared_ptr`」を宣言しています\n(`RxInfos` が具体的に何なのかは知りませんが……)。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T02:56:57.443",
"id": "39943",
"last_activity_date": "2017-11-30T02:56:57.443",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "39940",
"post_type": "answer",
"score": 0
},
{
"body": "「何をしているか」については「変数」を用意しているだけですが、 \nこういった、込み入った型は、typedefかusingを使って \n分解してみるとわかりやすいかもしれません。自分はたいていそうしてます。\n\n```\n\n //std::shared_ptr<std::vector<std::shared_ptr<RxInfos>>> rxinfo; を分解すると・・\n using RxInfos_Ptr = std::shared_ptr<RxInfos>;\n using RxInfos_Ptr_Vct = std::vector<RxInfos_Ptr>;\n using RxInfos_Ptr_Vct_Ptr = std::shared_ptr< RxInfos_Ptr_Vct>;\n RxInfos_Ptr_Vct_Ptr rxinfo;//最終的にはこれ\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T02:59:25.307",
"id": "39944",
"last_activity_date": "2017-11-30T02:59:25.307",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "3793",
"parent_id": "39940",
"post_type": "answer",
"score": 1
}
]
| 39940 | null | 39944 |
{
"accepted_answer_id": "39947",
"answer_count": 1,
"body": "```\n\n command_not_found_handle () {\n if [[ \"$1\" =~ [[:digit:]][d+-] ]]; then\n dice \"$1\"\n return $?\n elif [ -x /usr/lib/command-not-found ]; then\n /usr/lib/command-not-found -- \"$1\";\n return $?;\n else\n if [ -x /usr/share/command-not-found/command-not-found ]; then\n /usr/share/command-not-found/command-not-found -- \"$1\";\n return $?;\n else\n printf \"%s: command not found\\n\" \"$1\" 1>&2;\n return 127;\n fi;\n fi\n }\n \n```\n\n上記のように.bashrcで`command_not_found_handle()`を再定義して、特徴的な引数なら該当するプログラムに渡すようにしました。 \nオリジナルの関数をそのままコピーしてきて冒頭に処理を挟み込んだのですが、予めオリジナルの関数を`command_not_found_handle_orig()`みたいにリネームしておいて最後に呼び出せばよりスマートだと思いました。\n\n```\n\n command_not_found_handle () {\n if [[ \"$1\" =~ [[:digit:]][d+-] ]]; then\n dice \"$1\"\n return $?\n else\n command_not_found_handle_orig \"$1\"\n fi\n }\n \n```\n\n自前で再定義せずに関数の名前だけ変える方法か`type command_not_found_handle | tail\n--lines=+3`の出力を利用して関数を再定義する方法はありますでしょうか?",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T04:59:11.027",
"favorite_count": 0,
"id": "39945",
"last_activity_date": "2017-11-30T09:51:49.020",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "25936",
"post_type": "question",
"score": 2,
"tags": [
"bash"
],
"title": "定義済みの関数をリネームする方法はありますか?",
"view_count": 352
} | [
{
"body": "bash でよいなら、`declare -f` を使ったハックが出来ます。\n\n```\n\n #!/bin/bash\n \n foo () {\n echo foo\n }\n \n eval \"orig_$(declare -f foo)\"\n \n foo () {\n orig_foo \"$@\";\n echo bar\n }\n \n # ここで foo を呼び出すと foo bar が出力されます。\n foo\n \n```\n\nただしシェルスクリプトは[動的スコープ](https://ja.wikipedia.org/wiki/%E5%8B%95%E7%9A%84%E3%82%B9%E3%82%B3%E3%83%BC%E3%83%97)を採用しているので、上の方法は一般的な状況においては使えないことに注意してください。気になる場合、単に元の定義を新しい定義に手でコピペする方が良いです。\n\nまず、`.bashrc` のようにトップレベルで評価される場合、他の箇所で `orig_foo` が定義されていないことを確認してください。既存の\n`orig_foo` を上書きしてしまったり、他の `orig_foo` で上書きされてしまうかもしれません。\n\nまた、関数が再帰呼び出しを含む場合、 **上のコードだと上手くいきません。**\nこれをするためには関数定義のどの部分が関数呼び出しになっているのか分析できないといけないように思います。また、シェルスクリプトにおいては文字列操作の結果関数呼び出しが生まれる可能性があるので、そこまで対応しようと思うと更に困難になりそうです。\n\n参考: [How do I rename a bash\nfunction?](https://stackoverflow.com/q/1203583/5989200) \\-- 本家 Stack Overflow",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T07:27:30.690",
"id": "39947",
"last_activity_date": "2017-11-30T09:51:49.020",
"last_edit_date": "2017-11-30T09:51:49.020",
"last_editor_user_id": "19110",
"owner_user_id": "19110",
"parent_id": "39945",
"post_type": "answer",
"score": 2
}
]
| 39945 | 39947 | 39947 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "以下のようなコードで、いろんなコントローラ共通のviewをパーシャルとして切り出し、個別の部分をindexに書く、ということをしたいです。 \nこの個別の部分は実際にはコードが長くなるので、変数で渡すことは考えておりません。 \n以下のようにすると、aaaaaaは表示されますが、yieldが動かず、bbbbbが表示されません。 \nどうすれば良いでしょうか。\n\n```\n\n <!-- /shared/_index.html.erb -->\n <div class=\"contents\">\n aaaaaa\n <% yield %>\n </div>\n \n <!-- index.html.erb -->\n <%= render :layout => \"shared/index\" do%>\n bbbbb\n <% end %>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T07:22:54.233",
"favorite_count": 0,
"id": "39946",
"last_activity_date": "2017-12-01T02:37:35.703",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "25545",
"post_type": "question",
"score": 0,
"tags": [
"ruby-on-rails"
],
"title": "Railsで、パーシャルの中に個別のviewの内容を表示したい",
"view_count": 131
} | [
{
"body": "```\n\n <% yield %>\n \n```\n\nじゃなくて\n\n```\n\n <%= yield %>\n \n```\n\nじゃないでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-01T02:37:35.703",
"id": "39961",
"last_activity_date": "2017-12-01T02:37:35.703",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "9608",
"parent_id": "39946",
"post_type": "answer",
"score": 2
}
]
| 39946 | null | 39961 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "現在単視点RGB画像から手の姿勢推定を行いたくて、機械学習でやろうと思っています。 \n関節の位置をラベルとしてつけるイメージです。 \nこのラベルなのですが、配列は学習データとして取り入れられるのでしょうか? \n出力は推定される関節の位置で、これを手モデルに合成できればいいかなと思います。\n\n機械学習の経験が浅く、どう学習データを作るのかがわかりません。ご教授頂けると幸いです。\n\n* * *\n\n追記 (具体的な方法):\nボールを握っているような状況の手を、その中心(この場合は透明なボールの中心)から写します。モーションキャプチャーで撮影したものを用いるので、関節や手の甲の3次元位置はわかっています。これを学習データのラベルとして、CNNなどの既存のネットワークにかけられれば良いかなと思っています。入力は画像のみ、出力は推定される関節や手の甲の3次元位置をまとめた配列で出す、のが具体的な手法のイメージです。クラスに分類、というのは調べると見かけますが、回帰的なものの参考資料はなかなかないですね..。",
"comment_count": 16,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T08:49:29.263",
"favorite_count": 0,
"id": "39949",
"last_activity_date": "2020-09-05T09:00:55.087",
"last_edit_date": "2017-11-30T12:52:18.267",
"last_editor_user_id": "19110",
"owner_user_id": "26406",
"post_type": "question",
"score": 1,
"tags": [
"機械学習"
],
"title": "手の姿勢推定における学習データのラベル付け",
"view_count": 602
} | [
{
"body": "「ラベル」という言葉の使い方が妙な気もしますが、結論から言うと可能です。\n\n具体的な手法は、たとえば ICCV 2017 に出された Christian Zimmermann & Thomas Brox. [\"Learning to\nEstimate 3D Hand Pose from Single RGB Images\"](https://lmb.informatik.uni-\nfreiburg.de/projects/hand3d/) が参考になると思います。\n\n手の姿勢推定という研究は色々と行われているので、他の研究をまとめたサイトも存在しています。 \n<https://github.com/xinghaochen/awesome-hand-pose-estimation>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-07T09:17:52.423",
"id": "40112",
"last_activity_date": "2017-12-07T09:17:52.423",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "19110",
"parent_id": "39949",
"post_type": "answer",
"score": 1
}
]
| 39949 | null | 40112 |
{
"accepted_answer_id": "39953",
"answer_count": 1,
"body": "次のコードにおいて型検査時に、`go = readArray array` で、その次の行のコメントのようなエラーが出ました。 \nエラーの原因としては、2つの `ST` の(片方は `STArray` ですが)内部状態の `s` と `s1`\nが別物だと認識されていることと考えています。 \nこの `s` と `s1` が同じであると明記することはできますか? \nまたは、この形式だと根本的に `s` と `s1` は別物になるべきでしょうか?\n\nちなみに `go` のシグネチャを変更したコメントアウトした版にすると `s` が同じことが明記できるので型検査が通ります。\n\n```\n\n #!/usr/bin/env stack\n -- stack --resolver lts-9.14 --install-ghc runghc --package array\n \n import Control.Monad.ST\n import Data.Array.ST\n \n main = print $ runST $ do\n array <- newArray (0, 1 :: Int) (0 :: Int) :: ST s (STArray s Int Int)\n let\n go :: Int -> ST s Int\n go = readArray array\n -- starray.hs:11:14: error:\n -- • No instance for (MArray (STArray s) Int (ST s1))\n -- arising from a use of ‘readArray\n -- go :: STArray s Int Int -> Int -> ST s Int\n -- go = readArray\n writeArray array 1 1\n go 1\n -- go array 1\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T09:44:09.037",
"favorite_count": 0,
"id": "39952",
"last_activity_date": "2017-11-30T10:17:25.697",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "153",
"post_type": "question",
"score": 3,
"tags": [
"haskell"
],
"title": "2つの ST s の s が同じであることを明示する方法はありますか?",
"view_count": 120
} | [
{
"body": "(詳しい人曰く) `ScopedTypeVariables` 言語拡張を使うと良いそうです。 \n以下のコードで `stack runghc` したら `1` と返ってきましたよ。\n\n```\n\n {-# LANGUAGE ScopedTypeVariables #-}\n \n module Main where\n \n import Control.Monad.ST\n import Data.Array.ST\n \n main :: IO ()\n main = print $ runST st\n \n st :: forall s . ST s Int\n st = do\n array <- newArray (0, 1) 0 :: ST s (STArray s Int Int)\n let\n go :: Int -> ST s Int\n go = readArray array\n writeArray array 1 1\n go 1\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T10:17:25.697",
"id": "39953",
"last_activity_date": "2017-11-30T10:17:25.697",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "24425",
"parent_id": "39952",
"post_type": "answer",
"score": 1
}
]
| 39952 | 39953 | 39953 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "はじめまして。\n\n現在iOSのアプリを作成しているのですが、通知周りで躓いています。\n\nやりたいことは下記のような感じです。\n\n・ViewControllerのUISwitchの値が変更されたら通知許可を書き換える \nex: 許可がtrueならUISwitchをfalseにしたら許可もfalseになる\n\n現在通知の状態を取得することはできるのですが上書きすることはできないのか悩んでいます。\n\niOS11からアプリの通知設定画面にもURLスキーマで飛ばせなくなったみたいなので困っています。\n\nどうか教えてください。もうstackoverflowです。。。\n\n他にいいやりかたがあればご教示いただければ幸いです。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T13:32:26.350",
"favorite_count": 0,
"id": "39955",
"last_activity_date": "2017-12-01T00:07:44.597",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26416",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"ios"
],
"title": "iOSでpush通知の許可を書き換える方法",
"view_count": 633
} | [
{
"body": "できません。プッシュ通知を受けるかどうかはユーザーがコントロールするものなのでユーザーが拒否しているものをアプリ側で勝手に変えることはできません。それができたら許可の仕組みが意味をなさなくなってしまいます。",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-01T00:07:44.597",
"id": "39960",
"last_activity_date": "2017-12-01T00:07:44.597",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5519",
"parent_id": "39955",
"post_type": "answer",
"score": 2
}
]
| 39955 | null | 39960 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "現在、読み込んだ一つの動画から複数のサムネイルを取得し横に並べるiOSアプリを作成しています。動画からサムネイルを取得し横に並べることはできたのですが,そこから1つのサムネイルをタップした時に別のUIImageViewにそのサムネイルを表示したいのですがうまくできません。\n\n現状の手法として、UIImageViewを継承したクラスを作成し、その値をタップイベントの方に送っているのですが、値が0,1,2など数字ではなく15桁などのランダムな数字が出てしまいます。\n\nなぜそのような値が返ってくるのかわからないので教えていただけると助かります。また別な方法で構いません。\n\n以下、ソースコード、実行結果と参考にしたサイトになります。\n\nソースコード\n\n```\n\n import UIKit\n import AVFoundation\n import AssetsLibrary\n \n class ViewController: UIViewController, UIGestureRecognizerDelegate {\n \n @IBOutlet weak var topimage: UIImageView!\n @IBOutlet weak var scroll: UIScrollView!\n \n let time = 20\n \n class MyUIImageView: UIImageView{\n let x:Int\n let y:Int\n init(x:Int,y:Int,frame:CGRect){\n self.x = x\n self.y = y\n super.init(frame:frame)\n }\n required init(coder aDecoder: NSCoder) {\n fatalError(\"*** init(coder:) has not been implemented\")\n }\n }\n \n override func viewDidLoad() {\n super.viewDidLoad()\n \n let filePath: URL = URL(fileURLWithPath: \"動画のパス\")\n let asset = AVURLAsset(url: filePath, options: nil)\n let imgGenerator = AVAssetImageGenerator(asset: asset)\n imgGenerator.appliesPreferredTrackTransform = true\n \n scroll.contentSize = CGSize(width: time * 100, height: 200)\n scroll.bounces = false\n self.scroll.isScrollEnabled = true\n self.scroll.showsHorizontalScrollIndicator = false\n \n do{\n for x in 0...time - 1{\n //位置を変えながらviewを作る\n let iv : UIImageView = MyUIImageView(\n x:x,\n y:1,\n frame:CGRect(x:CGFloat(x)*100, y:100, width:100, height:150))\n \n //サムネイルの作成\n let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(Int64(seconds / (time - x)), 3), actualTime: nil)\n let thumbnail = UIImage(cgImage: cgImage)\n \n //画像をviewに追加\n iv.image = thumbnail\n //タップジェスチャ\n iv.isUserInteractionEnabled = true\n iv.addGestureRecognizer(UITapGestureRecognizer(\n target: self,\n action: #selector(imageViewTapped)))\n \n //画面に追加\n scroll.addSubview(iv)\n }\n }catch let error {\n print(\"*** Error generating thumbnail:\\(error.localizedDescription)\")\n }\n }\n \n @objc func imageViewTapped(views:MyUIImageView, gestureRecognizer: UITapGestureRecognizer) {\n //ここでxを取得できれば同じ上記と同じプログラムを書けば表示できると考えています。\n print(views.x)\n }\n \n override func didReceiveMemoryWarning() {\n super.didReceiveMemoryWarning()\n \n }\n }\n \n```\n\n実行結果\n\n```\n\n view at (140434724710272) is tapped //一つ目のサムネイル\n view at (0) is tapped //二つ目のサムネイル\n view at (140434743678464) is tapped //三つ目のサムネイル\n view at (140434724710848) is tapped //四つ目のサムネイル\n \n```\n\n参考サイト \n<https://qiita.com/fetaro/items/199e36d71ee9c0015488>",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T18:20:41.263",
"favorite_count": 0,
"id": "39958",
"last_activity_date": "2017-11-30T23:56:33.877",
"last_edit_date": "2017-11-30T23:56:33.877",
"last_editor_user_id": "16882",
"owner_user_id": "16882",
"post_type": "question",
"score": 0,
"tags": [
"swift",
"ios"
],
"title": "Swiftにて画像をタップした時の動作について",
"view_count": 533
} | [
{
"body": "iOS側からセレクタで指定されたメソッドを呼び出す場合、どのようなパラメーターを渡すかはiOSのどの機能を使うかで決まっています。\n\n[`UIGestureRecognizer`の場合](https://developer.apple.com/documentation/uikit/uigesturerecognizer)、以下のシグニチャーのいずれかでないといけません。\n\n>\n```\n\n> @IBAction func myActionMethod()\n> @IBAction func myActionMethod(_ sender: UIGestureRecognizer)\n> \n```\n\n`@IBAction`なんてのは単にドキュメントの記述上の話なのでサクッと無視してもらって、肝心なのは引数として受け取れるのは最大で1個、その1個は`UIGestureRecognizer`を表していると言うことです。\n\nメソッド宣言で引数を追加したとしても、iOS側はそんなことは一切無視して1個目の引数として`UIGestureRecognizer`のインスタンス(あなたの場合`UITapGestureRecognizer`)を渡します。あなたのメソッドはそれを無理やり`MyUIImageView`と解釈して`MyUIImageView`用のプロパティゲッターを呼んでいるのですから、まともな値が返らないどころか、即座にクラッシュしていてもおかしくないところです。\n\nセレクタで呼び出されるメソッドには、ちゃんとお約束通りの引数を宣言して下さい。\n\n```\n\n @objc func imageViewTapped(_ gestureRecognizer: UITapGestureRecognizer) {\n //UIGestureRecognizerのセット先のビューを取り出したい場合は、`view`プロパティを使う\n //UITapGestureRecognizerの設定を間違えていた場合にはクラッシュで知らせるため、意図的に`!`や`as!`を使っている\n let myImageView = gestureRecognizer.view! as! MyUIImageView\n print(myImageView.x)\n }\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-11-30T21:14:15.690",
"id": "39959",
"last_activity_date": "2017-11-30T21:14:15.690",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "13972",
"parent_id": "39958",
"post_type": "answer",
"score": 1
}
]
| 39958 | null | 39959 |
{
"accepted_answer_id": "39964",
"answer_count": 1,
"body": "Minitest実行のために下記のように`sample_test.rb`ファイルを作成しました。\n\n```\n\n require 'minitest/autorun'\n \n class SampleTest < Minitest::Test\n def test_sample\n assert_equal 'RUBY', 'ruby'.upcase\n end\n end\n \n```\n\nここで`sample_test.rb`を実行すると\n\n```\n\n /Users/xxxxx/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/specification.rb:2291:in `raise_if_conflicts': Unable to activate railties-5.1.3, because activesupport-5.1.2 conflicts with activesupport (= 5.1.3) (Gem::ConflictError)\n from /Users/xxxxx/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/specification.rb:1411:in `activate' \n 以下略\n \n```\n\nというエラーが確認され、Testに進めません。\n\n`gem cleanup`と`gem uninstall activesupport -v\n\"5.1.3\"`を試してファイル実行しましたが結果変わらず手詰まりになっています。\n\nちなみにrubyのversionは`ruby 2.4.1p111 (2017-03-22 revision 58053)\n[x86_64-darwin16]`です。\n\nご意見頂きたくよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-01T05:27:51.503",
"favorite_count": 0,
"id": "39962",
"last_activity_date": "2018-10-22T22:21:33.953",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"post_type": "question",
"score": 2,
"tags": [
"ruby",
"rubygems",
"bundler"
],
"title": "Ruby test raise_if_conflictsのエラーについて",
"view_count": 425
} | [
{
"body": "あまり根本的な解決策ではないですが、bundler経由で実行すれば依存関係の問題は解消するかもしれません。\n\n```\n\n gem install bundler\n bundle init\n \n```\n\n```\n\n # Edit Gemfile\n gem 'minitest'\n \n```\n\n```\n\n bundle install\n bundle exec ruby sample_test.rb\n \n```\n\n「プロを目指す人のためのRuby入門」をお持ちなら、第12章のBundlerの説明も参照してください。\n\n**2018.10.23追記**\n\nこの問題は新しいバージョンのRailsをインストールすることで解決するかもしれません。 \n詳しくは以下の記事をご覧ください。\n\n[「プロを目指す人のためのRuby入門」でテスト失敗時に実行結果が正常に表示されない場合 -\nQiita](https://qiita.com/jnchito/items/1e928f8088b2cc6bd3fa)",
"comment_count": 2,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-12-01T07:10:18.093",
"id": "39964",
"last_activity_date": "2018-10-22T22:21:33.953",
"last_edit_date": "2018-10-22T22:21:33.953",
"last_editor_user_id": "85",
"owner_user_id": "85",
"parent_id": "39962",
"post_type": "answer",
"score": 2
}
]
| 39962 | 39964 | 39964 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Adobe Acrobat Readerの画面にはなるのですが、指定したPDFが表示されません。どうしたらいいでしょうか?\n\n```\n\n -(void)hoge:(UIButton*)button{\n NSString *path = [[NSBundle mainBundle]pathForResource:@\"title1\"fType:@\"pdf\"];\n NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@\"com.adobe.Adobe-Reader://%@\", path]];\n \n UIApplication *application = [UIApplication sharedApplication];\n \n [application openURL:url options:@{} completionHandler:^(BOOL success) {\n if (success) {\n NSLog(@\"Opened url\");\n }\n }];\n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-01T10:06:20.620",
"favorite_count": 0,
"id": "39966",
"last_activity_date": "2017-12-01T13:52:49.237",
"last_edit_date": "2017-12-01T13:52:49.237",
"last_editor_user_id": "5519",
"owner_user_id": "26431",
"post_type": "question",
"score": 0,
"tags": [
"ios",
"objective-c",
"pdf"
],
"title": "iOSでPDFファイルをAdobe Acrobat Readerに渡す方法",
"view_count": 392
} | []
| 39966 | null | null |
{
"accepted_answer_id": "40037",
"answer_count": 2,
"body": "====質問=== \ntable内の行に配置されたボタン要素押下で、当該tableの一番下の行=tr要素を取得したいのですが自分の未熟さから捉えられない状態です。下の図の緑枠のtr要素を変数$rowに格納したいのですが、どういった関数記述で達成できるのでしょうか? \nちなみに、console.logに$(this).nextAll(\"table\").eq(0).prop(\"tagName\")を表してみたのですがundefinedになってしまいます。 \nいつもながら初歩的な質問で申し訳ありませんがご支援をよろしくお願い致します。 \n[](https://i.stack.imgur.com/3XGF7.png)\n\n```\n\n <div class=\"appLines\">\n <table>\n <tr class=\"appLineDummy\">\n <td></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td></td>\n <td></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd\"></td>\n <td><button class=\"rowins\" type=\"button\">+</button></td>\n <td><button class=\"rowdel\" type=\"button\">-</button></td>\n </tr>\n <tr > //動的生成\n <td></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td></td>\n <td></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd\"></td>\n <td><button class=\"rowins\" type=\"button\">+</button></td>\n <td><button class=\"rowdel\" type=\"button\">-</button></td>\n </tr>\n <tr > //動的生成\n <td></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td></td>\n <td></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd\"></td>\n <td><button class=\"rowins\" type=\"button\">+</button></td>\n <td><button class=\"rowdel\" type=\"button\">-</button></td>\n </tr>\n <tr > //動的生成\n <td></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td></td>\n <td></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd\"></td>\n <td><button class=\"rowins\" type=\"button\">+</button></td>\n <td><button class=\"rowdel\" type=\"button\">-</button></td>\n </tr>\n <tr > //動的生成\n <td></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td></td>\n <td></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd\"></td>\n <td><button class=\"rowins\" type=\"button\">+</button></td>\n <td><button class=\"rowdel\" type=\"button\">-</button></td>\n </tr>\n <tr > //動的生成\n <td></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td class=\"extd\"></td>\n <td></td>\n <td></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd_kin\"></td>\n <td class=\"extd\"></td>\n <td><button class=\"rowins\" type=\"button\">+</button></td>\n <td><button class=\"rowdel\" type=\"button\">-</button></td>\n </tr>\n </table>\n </div>\n <div class=\"appFooter\">\n <table>\n <tr>\n <td colspan=\"6\"></td>\n <td colspan=\"2\"></td>\n </tr>\n </table>\n </div>\n \n```\n\n====補足==== \n皆様、いつもご支援をありがとうございます。 \n既存の関数 addRowBelow は行追加のために機能しており、こちらへ引数で行要素を指定すると \nその下に行が追加される想定でいます。(今話題にしてるボタンも、こちらから動的に生成されたtr要素上のボタン) \n問い合わせは、目的としている行要素を見つけるための手立てでしたが、 \nこちらの関数に引数で渡すための問い合わせでした。\n\n...でも相変わらずうまくいかない状況で、ちょっと困っています。(前方がpgrhoさん参考、後方がyyzさんを参考)引き続き\nご見解を頂けますと幸いでございます、よろしくお願い致します。\n\n```\n\n var $dummyRow = $(\"tr.appLineDummy\"); //漏れてました...\n \n function addRowBelow($ele) {\n var $newRow = $dummyRow.clone(true);\n $newRow.removeClass(\"appLineDummy\");\n $newRow.insertAfter($ele);\n }\n \n```\n\n【無反応になってしまいます】\n\n```\n\n // 行削除 & 行の補い(常に5行表示を保つ意味))\n $(document).on(\"click\", \".rowdel\", function(e) {\n var row = $(this).closest(\"tr\").remove();\n $(row).remove();\n \n \n $row = $(this).closest('table').find('tr:last');\n addRowBelow($row);\n });\n \n```\n\n【当該Webページ一番下に行追加されてしまう(ボタンが配置されたtrを含むテーブルの一番下が希望)】\n\n```\n\n // 行削除 & 行の補い(常に5行表示を保つ意味))\n $(document).on(\"click\", \".rowdel\", function(e) {\n var row = $(this).closest(\"tr\").remove();\n $(row).remove();\n \n var table_no = $('table').index($(this));\n addRowBelow($('table:eq('+table_no+') tr:last'));\n \n });\n \n```",
"comment_count": 11,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-01T13:30:34.263",
"favorite_count": 0,
"id": "39968",
"last_activity_date": "2017-12-05T01:34:40.493",
"last_edit_date": "2017-12-04T23:21:33.997",
"last_editor_user_id": "25696",
"owner_user_id": "25696",
"post_type": "question",
"score": 1,
"tags": [
"jquery",
"html5"
],
"title": "JQuery 要素を思うように捉えられない",
"view_count": 411
} | [
{
"body": "質問の記述では`this`が何かはっきりしませんが、クリックされた`<button>`要素だとすると\n\n```\n\n $(this).closest('table')\n \n```\n\nで`<button>`の上位にある`<table>`を得ることができます。この要素に対して`tr:last`を探せばよいので結局\n\n```\n\n $(this).closest('table').find('tr:last')\n \n```\n\nで最下行を取得することができます。\n\nしかし`<tbody>`の末尾に`<tr>`を追加するだけであれば`tr:last`にアクセスする必要は特にないように思われます。\n\n```\n\n $(this).closest('tbody').append(/* 追加するtr */);\n \n```\n\nなお`this`が他のオブジェクトであっても引数から`event.currentTarget`とイベントの発生した要素にアクセスすることもできます。\n\n## 追記\n\n一応下記のソースで問題なく動くことを確認しました。質問文では明示されていない箇所で例外が発生しているのでは。ブラウザのコンソールを確認してみてください。\n\n```\n\n <!DOCTYPE html>\n <html>\n <body>\n <table>\n <tr class=\"appLineDummy\">\n <td><button class=\"rowins\">+</button></td>\n </tr>\n </table>\n <table>\n <tr>\n <td><button class=\"rowins\">+</button></td>\n </tr>\n </table>\n <script src=\"https://code.jquery.com/jquery-3.2.1.slim.min.js\"></script>\n <script>\n var i = 0;\n var $dummyRow = $('.appLineDummy'); // なかったので追加\n function addRowBelow($ele) {\n var $newRow = $dummyRow.clone(true);\n $newRow.removeClass(\"appLineDummy\");\n $newRow.append($('<td>').text(i++)); // 結果確認用\n $newRow.insertAfter($ele);\n }\n \n // 行を動的に追加しているのでライブイベントを使用する\n $(document.body).on(\"click\", \".rowins\", null, function () {\n $row = $(this).closest('table').find('tr:last');\n addRowBelow($row);\n });\n </script>\n </body>\n </html>\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T04:00:10.070",
"id": "39972",
"last_activity_date": "2017-12-04T13:39:29.650",
"last_edit_date": "2017-12-04T13:39:29.650",
"last_editor_user_id": "5750",
"owner_user_id": "5750",
"parent_id": "39968",
"post_type": "answer",
"score": 4
},
{
"body": "以下のように、追加してから削除してみましょう。\n\n```\n\n // 行を動的に追加しているのでライブイベントを使用する\n $(document.body).on(\"click\", \".rowins\", null, function () \n {\n //追加\n var row2 = $(this).closest('table').find('tr:last');\n addRowBelow(row2);\n \n //削除\n var row = $(this).closest(\"tr\").remove();\n $(row).remove();\n });\n \n```\n\nsaya24さんがされている以下の文だと、先に削除されているせいで、thisの指すボタンがテーブルから外れ、closestで失敗しているのかもしれません。\n\n```\n\n // 行削除 & 行の補い(常に5行表示を保つ意味))\n $(document).on(\"click\", \".rowdel\", function(e) {\n var row = $(this).closest(\"tr\").remove();\n $(row).remove();\n \n $row = $(this).closest('table').find('tr:last');\n addRowBelow($row);\n });\n \n```\n\nお試しください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-05T01:34:40.493",
"id": "40037",
"last_activity_date": "2017-12-05T01:34:40.493",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "17014",
"parent_id": "39968",
"post_type": "answer",
"score": 1
}
]
| 39968 | 40037 | 39972 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "このようなスクリプトを書きました。 \n自分のメールアドレスとパスワードを入力しているのにログインできません。 \nエラー内容は次の通りです。\n\n> SMTPAuthenticationError: (535, b'5.7.0 (#AUTH012) Incorrect username \n> or password.')\n\nエラーをどう解決すればよいか見当もつきません、何か調べたほうが良い事などありますでしょうか?\n\n```\n\n import smtplib\n from email.mime.text import MIMEText\n from email.header import Header\n \n charset = 'iso-2022-jp'\n \n msg=MIMEText('###', 'plain', charset)\n msg['Subject'] = Header('###'.encode(charset), charset)\n \n smtp_obj = smtplib.SMTP('smtp.mail.yahoo.com', 587)#接続\n smtp_obj.ehlo()#問い合わせ\n smtp_obj.starttls()#TLSモードに\n my =\n p =\n y =\n smtp_obj.login(my, p)#メルアドとpass\n smtp_obj.sendmail(my, y, msg.as_string())\n \n```",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-01T17:14:48.970",
"favorite_count": 0,
"id": "39970",
"last_activity_date": "2021-09-09T01:41:35.580",
"last_edit_date": "2021-09-09T01:41:35.580",
"last_editor_user_id": "3060",
"owner_user_id": "26076",
"post_type": "question",
"score": 1,
"tags": [
"python",
"smtplib"
],
"title": "import smtplibで書籍通りにプログラムを書いて実行したが、passかusernameが間違っているといわれる。",
"view_count": 170
} | []
| 39970 | null | null |
{
"accepted_answer_id": "40021",
"answer_count": 1,
"body": "レコメンドシステムの協調フィルタリングでアイテムベースとユーザーベースの違いがわからないので質問します。\n\nぐぐってみると、あるページではアイテムベースと紹介されてるような内容が、他のページではユーザーベースだったり、その逆だったりがあります。\n\nこの2つを区別する要素を教えていただきたいのと、できれば下記の例で説明していただきたいです。 \n下記の例でアイテムベースが、この認識であってるかどうかもちょっと自信がないです。\n\n実際のサービスで使うのとかけ離れた少ないデータでの例になってるのはご了承ください。\n\n## (例)アマゾンでの本のレコメンド\n\n## 1.アイテムベース\n\n### インプット\n\nAさんはジャンプ、マガジン、コロコロを買っている \nBさんはジャンプ、マガジンを買っている\n\n### アウトプット\n\nAさんとBさんは、買う雑誌の傾向が似ている \nだから、Bさんにコロコロをレコメンドしよう\n\n## 2.ユーザーベース\n\n### インプット\n\nどういうインプットかわからない\n\n### アウトプット\n\nBさんにXXをレコメンドしよう",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T00:46:51.150",
"favorite_count": 0,
"id": "39971",
"last_activity_date": "2017-12-18T02:26:43.197",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "25065",
"post_type": "question",
"score": 3,
"tags": [
"python",
"ruby",
"機械学習",
"自然言語処理"
],
"title": "協調フィルタリングにおける、アイテムベースとユーザーベースの区別方法",
"view_count": 3652
} | [
{
"body": "Asuka さんが質問文で例に挙げている「アイテムベース」の例は、むしろユーザーベースの例だと思います。\n\n### ユーザーベース vs アイテムベース\n\nユーザーベース協調フィルタリングでは、どのユーザーがどのアイテムを買ったかを元に、ユーザー×アイテムの表をデータベースとして持っています。そして新しいユーザー\nA が商品を買ったとき、どのアイテムを推薦するべきかを A さんと似た購入履歴を持つ **ユーザー**\nを探すことで決めます。ユーザー間の関係性をもとに推薦アイテムを決めているので、ユーザーベースです。\n\n対してアイテムベース協調フィルタリングでは、どのユーザーがどのアイテムを買ったかを元に、アイテム間の類似性を示すアイテム×アイテムの表をデータベースとして持っています。そして新しいユーザーが商品\nX を買ったとき、どのアイテムを推薦するべきかを X と関連の高い **アイテム**\nを探すことで決めます。アイテム間の関係性をもとに推薦アイテムを決めているので、アイテムベースです。\n\n### 参考\n\n英語でよければ、くだけた説明としては Wikipedia:en の [\"Collaborative filtering -\nMethodology\"](https://en.wikipedia.org/wiki/Collaborative_filtering#Methodology)\nが分かりやすいと思います。また、アイテムベース協調フィルタリングを提案した最初の論文であると言われている Sarwar らの [\"Item-based\ncollaborative filtering recommendation\nalgorithms\"](https://dl.acm.org/citation.cfm?id=372071)\n中に書かれた説明も分かりやすかったです。また、2017年春に公開された IEEE Internet Computing の [\"Two Decades of\nRecommender Systems at\nAmazon.com\"](https://www.computer.org/csdl/mags/ic/2017/03/mic2017030012.html)\nもよくまとまっていると思います。これを日本語で要約したブログ記事として[「Amazonの推薦システムの20年」](https://takuti.me/note/two-\ndecades-of-amazon-recommender/)があります。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T07:32:06.730",
"id": "40021",
"last_activity_date": "2017-12-18T02:26:43.197",
"last_edit_date": "2017-12-18T02:26:43.197",
"last_editor_user_id": "19110",
"owner_user_id": "19110",
"parent_id": "39971",
"post_type": "answer",
"score": 2
}
]
| 39971 | 40021 | 40021 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "マクロ初心者です。 \n現在マクロの勉強をしてるのですが、以下のコードを実行しようとしたときに \n「BASIC ランタイムエラー Sub または Function プロシージャーの未定義」 \nとエラーが出てきて処理ができません。 \n何が問題なのでしょうか?\n\n**■環境** \nOpenOffice\n\n**■実行したマクロ**\n\n```\n\n Sub Module1 ()\n \n Dim a As String\n a = Cells(3, 2).Value\n MsgBox (a)\n \n End Sub\n \n```\n\n**■エラー文** \nBASIC ランタイムエラー \nSub または Function プロシージャーの未定義\n\n**■確認した事項** \n・[ツール]>[オプション]>[読み込みと保存]>[VBA属性]>[実行可能コード]にチェック \n・[ツール]>[オプション]>[Java]>[Javaランタイム環境を使用]にチェック \n・マクロの配置を「マイマクロ」下から「{ファイル名}」下に変更 \n・ファイルをxlsmファイルとして保存してから実行する \n \n**■補足** \n「a = \"Hello World\"」のようにaを定義すると正常に実行され、 \nメッセージボックスが表示されました。 \n「Range」「Cells」のようなシートに働きかける関数を使用した途端に \nうまく動かなくなったので、何かしら環境上の問題ではないかと考えています。\n\n以上が現在発生している問題です。 \n以前に同様の問題を経験したことのある方、解決方法のわかる方、 \nいらっしゃいましたらお答えいただきたいです。\n\nよろしくお願いします。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T04:38:04.203",
"favorite_count": 0,
"id": "39974",
"last_activity_date": "2018-02-27T05:41:31.003",
"last_edit_date": "2017-12-02T06:19:30.223",
"last_editor_user_id": "3060",
"owner_user_id": "26443",
"post_type": "question",
"score": 0,
"tags": [
"vba"
],
"title": "マクロVBAで「BASIC ランタイムエラー」が出てきます。何が問題でしょうか?",
"view_count": 5629
} | [
{
"body": "VBAについては詳しく知らないのですが、OpenOfficeを使っているということで、その観点から見ると\n\nあなたが開発している言語はOpenOfficeのVBAと似た別のものらしいです。\n\n「OpenOffice Basic」というものらしい。\n\nもしかしたら、その環境では実行できないのかもしれません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T00:02:35.467",
"id": "39990",
"last_activity_date": "2017-12-03T00:02:35.467",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26334",
"parent_id": "39974",
"post_type": "answer",
"score": 1
}
]
| 39974 | null | 39990 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "現在DCGANをkerasで実装しようとしているのですが、generatorの最初ところ(1024,4,4)を(1,1)の大きさのカーネルをストライド5で(512,8,8)へ逆畳み込みしていますよね? \nkerasのConv2DTransposeを使おうと思っているのですが、その際、paddingはsameかvalidどのようにしたらいいですか?また(4,4)のサイズにカーネルのストライド5は大丈夫なのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T05:07:32.990",
"favorite_count": 0,
"id": "39975",
"last_activity_date": "2020-08-03T06:00:55.233",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26444",
"post_type": "question",
"score": 0,
"tags": [
"python",
"tensorflow",
"機械学習",
"keras"
],
"title": "DCGANの実装のpaddingに関して",
"view_count": 190
} | [
{
"body": "padding = \"same\"を指定すると出力の大きさが変わらないようになるので、padding = \"valid\"で良いと思います。 \n実験してないのでなんとも言えませんが(4,4)にstrides = 5は無理があると思います。モデルの性能的にも、です。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2018-08-27T02:27:01.040",
"id": "47835",
"last_activity_date": "2018-08-27T02:27:01.040",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "29873",
"parent_id": "39975",
"post_type": "answer",
"score": 0
}
]
| 39975 | null | 47835 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "Javaで、Mavenプロジェクトに入っていないような単品のプログラムに対して、 \n外部のライブラリをいい感じに追加する方法ってありますか?\n\n例えば、以下のように外部ライブラリを使うプログラムで、\n\n```\n\n import java.io.*;\n import org.apache.commons.csv.*;\n \n public class Main{\n public static void main(String[] args){\n try{\n Reader fr = new FileReader(\"ppap.csv\");\n Iterable<CSVRecord> records = CSVFormat.RFC4180.withHeader().parse(fr);\n \n for(CSVRecord rec: records){\n System.out.println(rec.get(\"a\"));\n }\n }catch(IOException e){}\n }\n }\n \n```\n\n今はコンパイルを通すため、.jarファイルを手動でダウンロードしています。 \nコンパイル時・起動時も手動で -classpath を指定しています。\n\nこれが面倒なのですが、みなさんはどんな方法を使っていますか? \nよろしくお願いいたします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T07:56:18.050",
"favorite_count": 0,
"id": "39978",
"last_activity_date": "2017-12-02T08:24:48.720",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26110",
"post_type": "question",
"score": 1,
"tags": [
"java",
"maven"
],
"title": "Javaで単品のプログラムの依存性をpipみたいに管理したい",
"view_count": 97
} | [
{
"body": "Javaのプロジェクトなら[Maven](http://maven.apache.org)や[Gradle](http://gradle.org)でプロジェクトの依存管理が出来ます。このシステムを利用すると、フォルダー構成が固定になりますので自由度が少しなくなりますが、簡単に依存を追加したり、更新したり出来ますので便利です。\n\nMavenをインストールしましたら、コマンドから`mvn\narchetype:generate`を実行し、パッケージ名とJarファイル名を入力すればMavenの設定ファイル(pom.xml)とフォルダー構成が作成されます。(Windowsだとエンターキーをもう一度押す必要ある場合があります。)\n\n```\n\n Choose org.apache.maven.archetypes:maven-archetype-quickstart version:\n 1: 1.0-alpha-1\n 2: 1.0-alpha-2\n 3: 1.0-alpha-3\n 4: 1.0-alpha-4\n 5: 1.0\n 6: 1.1\n Choose a number: 6: Define value for property 'groupId': com.example\n Define value for property 'artifactId': hogehoge-app\n Define value for property 'version' 1.0-SNAPSHOT: :\n Define value for property 'package' com.example: :\n Confirm properties configuration:\n groupId: com.example\n artifactId: hogehoge-app\n version: 1.0-SNAPSHOT\n package: com.example\n Y: : y\n \n```\n\nその後は`mvn test`で単体テストの実行や`mvn package`でJarファイルを作成する事が出来ます。`package`したら`mvn\nexec:java\n-Dexec.mainClass=com.example.App`を実行すればすべての依存がクラスパスに追加してメインクラスを実行されます。\n\n依存を追加するのに[search.maven.org](http://search.maven.org)から検索し、詳細画面に出る`<dependency>`のXMLをpom.xmlファイルの`<dependencies>`の中に追加するだけです。",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T08:24:48.720",
"id": "39979",
"last_activity_date": "2017-12-02T08:24:48.720",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26450",
"parent_id": "39978",
"post_type": "answer",
"score": 1
}
]
| 39978 | null | 39979 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "python初心者のものです。 \n2011枚の画像データを格納しているcsvを読み込み、PCAをかけて結果を前半1000と後半1011に分けてグラフに出力するコードを実行すると\n\n> IndexError: index 2 is out of bounds for axis 1 with size 2\n\nと怒られてしまいました。エラーの対処方法をご存じの方はご教授お願い致します。\n\n```\n\n import numpy as np\n from sklearn.cluster import KMeans\n from sklearn.decomposition import PCA\n import matplotlib.pyplot as plt\n import pandas as pd\n \n users = np.loadtxt('/home/srl/mimamori1/b1/bb1.csv', delimiter=\",\")\n model = KMeans(n_clusters=2).fit(users) \n \n \n pca = PCA(n_components=2)\n users_r = pca.fit_transform(users)\n plt.figure()\n ccode=[1]*1000+[2]*1011\n \n plt.scatter(users_r[:,1],users_r[:,2],c=ccode)\n plt.xlabel('pc1')\n plt.ylabel('pc2')\n \n \n print('各次元の寄与率: {0}'.format(pca.explained_variance_ratio_))\n print('累積寄与率: {0}'.format(sum(pca.explained_variance_ratio_)))\n plt.show()\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T09:49:23.010",
"favorite_count": 0,
"id": "39980",
"last_activity_date": "2018-02-10T17:36:16.173",
"last_edit_date": "2017-12-02T09:55:31.053",
"last_editor_user_id": "26452",
"owner_user_id": "26452",
"post_type": "question",
"score": 0,
"tags": [
"python",
"matplotlib",
"pca"
],
"title": "index 2 is out of bounds for axis 1 with size 2の対処方法",
"view_count": 34758
} | [
{
"body": "Pythonのインデックスは(matlabと違って)0始まりなので、\n\n```\n\n users_r[:,1],users_r[:,2]\n \n```\n\nを\n\n```\n\n users_r[:,0],users_r[:,1]\n \n```\n\nに直して見てください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T19:41:30.017",
"id": "39987",
"last_activity_date": "2017-12-02T19:41:30.017",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26311",
"parent_id": "39980",
"post_type": "answer",
"score": 1
}
]
| 39980 | null | 39987 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "現在『ゲームを作りながら楽しく学べるpythonプログラミング』で勉強中の初心者です。\n\n本書で、`image.load(\"\")`ができなくて困っております。 \n以下のコードを入力して(`pythonlogo.jpg`)を表示したいのですが、なぜかpygame\nwindowという真っ黒のインターフェース画面が表示されるだけで画像が全く表示がされません。\n\n実行ファイルと画像の置き位置がおかしいのかと思い、実行ファイルと画像(`pythonlogo.jpg`)を同じ階層に置いて試しましたが駄目でした。\nやりかたはコマンドプロンプトから「idle」で3.6.3 Shell を起動し、File(実行.py)を開いて`Run module\nf5`で試していますが何も表示されません。\n\nこのやり方が間違っているのかファイルのパスがおかしいのでしょうか。\n\n```\n\n import sys\n import pygame\n from pygame.locals import QUIT\n pygame.init()\n SURFACE=pygame.display.set_mode((400,300))\n FPSCLOCK=pygame.time.Clock() \n def main():\n logo=pygame.image.load(\"pythonlogo.jpg\")\n while True:\n for event in pygame.event.get():\n if event.type==QUIT:\n pygame.quit()\n sys.exit()\n SURFACE.fill((255,255,255))\n SURFACE.blit(logo,(20,50))\n pygame.display.update()\n FPSCLOCK.tick(30) \n if __name__=='__main__':\n main() \n \n```\n\n※Windows環境です。\n\nどうかご教授よろしくお願いします。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T11:14:28.880",
"favorite_count": 0,
"id": "39981",
"last_activity_date": "2018-05-08T07:31:29.433",
"last_edit_date": "2017-12-08T07:57:48.703",
"last_editor_user_id": "24284",
"owner_user_id": "26453",
"post_type": "question",
"score": 1,
"tags": [
"python",
"画像",
"pygame"
],
"title": "pythonのpygameでimage.load(\"\")で画像表示ができなくてすごく困っております。",
"view_count": 2542
} | [
{
"body": "(改行がおかしい等、記述ミスかも知れませんが) \n`logo`を表示するのはイベントループに入る前の必要があると思います。\n\n具体的には\n\n```\n\n logo=pygame.image.load(\"pythonlogo.jpg\")\n while True:\n for event in pygame.event.get():\n if event.type==QUIT:\n pygame.quit()\n sys.exit()\n SURFACE.fill((255,255,255))\n SURFACE.blit(logo,(20,50))\n pygame.display.update()\n \n```\n\nの順ではなく、\n\n```\n\n logo=pygame.image.load(\"pythonlogo.jpg\")\n while True:\n SURFACE.fill((255,255,255))\n SURFACE.blit(logo,(20,50))\n pygame.display.update()\n for event in pygame.event.get():\n if event.type==QUIT:\n pygame.quit()\n sys.exit()\n \n```\n\nの順かと思います。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T07:59:18.180",
"id": "39999",
"last_activity_date": "2017-12-03T07:59:18.180",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "20098",
"parent_id": "39981",
"post_type": "answer",
"score": 3
},
{
"body": "```\n\n pygame.display.update()\n FPSCLOCK.tick(30)\n \n```\n\nの二つの行が\n\nwhile True:\n\nにかかっていないと、 \n初期表示時点ではブラックスクリーンです。 \nただ、一度最小化してみるとちゃんと表示されるはずです。",
"comment_count": 0,
"content_license": "CC BY-SA 4.0",
"creation_date": "2018-05-08T07:31:29.433",
"id": "43863",
"last_activity_date": "2018-05-08T07:31:29.433",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "28454",
"parent_id": "39981",
"post_type": "answer",
"score": 0
}
]
| 39981 | null | 39999 |
{
"accepted_answer_id": "39998",
"answer_count": 1,
"body": "brew cask で Emacs.app をインストールしました。バージョンは 25.3 です。\n\n以下の設定のみを記述した状態で emacs を初期化すると、`list-packages` の際に、 gpg のエラーが発生している様子で、 gnu の\npackage を取得できません。\n\n### init.el\n\n```\n\n (require 'package)\n (setq package-check-signature t)\n (package-initialize)\n \n```\n\n### emacs が `list-packages` 時に `*Messages*` で伝えるエラー内容\n\n```\n\n Cannot import default keyring: (\"no usable configuration\" OpenPGP)\n Package refresh done\n error in process filter: epg-context--make: GPG error: \"no usable configuration\", OpenPGP\n error in process filter: GPG error: \"no usable configuration\", OpenPGP\n \n```\n\n`package-check-signature` を nil に設定すれば、通るのかもしれませんが、確か、 emacs の packages\nのダウンロードはあまりセキュアでなかったと記憶していて、なので signature のチェックは強制したいと考えています。\n\n## 質問\n\n * package-check-signature を t にした状態で、 gnu のパッケージを取得できるようになりたいです。どうやったらこれを実現できますでしょうか。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T15:15:24.760",
"favorite_count": 0,
"id": "39983",
"last_activity_date": "2017-12-03T06:44:51.843",
"last_edit_date": "2017-12-02T15:50:22.627",
"last_editor_user_id": "754",
"owner_user_id": "754",
"post_type": "question",
"score": 0,
"tags": [
"macos",
"emacs"
],
"title": "mac os x の emacs で、 GPG error: \"no usable configuration\"",
"view_count": 444
} | [
{
"body": "パッケージを検証するためのプログラム (`gpg`) がインストールされているか確認してください。\n\nもしなければ、<https://gnupg.org/download/> からダウンロードするか `brew install gnupg`\nでインストールしてください。\n\n蛇足ですが、変数`package-check-signature`を`t` (すべて検証する)\nに設定すると、[MELPA](https://melpa.org/)などのパッケージに署名のないサイトではエラーが発生します。`gpg`プログラムが入っていれば`'allow-\nunsigned` (未署名を許容する) がデフォルト設定になっているはずです。こちらを選択したほうが無難かもしれません。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T06:44:51.843",
"id": "39998",
"last_activity_date": "2017-12-03T06:44:51.843",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2391",
"parent_id": "39983",
"post_type": "answer",
"score": 1
}
]
| 39983 | 39998 | 39998 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "### 前提・実現したいこと\n\n我ながらお恥ずかしい話ですが、APIから取得するデータでツリー表示をさせ、画面上にデータとして残すようなページをサンプルで作っています。 \nどうか皆様のアドバイス(ソースコード)などのお力添えをお願いいたします。 \n環境等は最下部に記載しています。 \n以下が実現したいことです。\n\nJsonデータ ⇒ 取得してツリー表示(初期表示) ⇒ ツリー内のボタン(プラスボタンなど) ⇒対象のJsonデータを再度取得 ⇒\n取得したデータを画面上の任意の箇所に表示ボタンが押された場合にのみ表示\n\n### イメージ\n\n```\n\n -書店\n - BOOK\n ワンピース☑️\n +ホテル\n +電気\n +八百屋\n \n \n 表示ボタン\n \n \n 表示場所[ワンピース]\n \n```\n\nチェック箇所の情報をHTML(thymeleaf)内の任意の場所に表示する。 \n表示内容はイメージのとこにあるワンピースという名称でページ数などは裏で結びついて持っていきたい。\n\n### 発生している問題・エラーメッセージ\n\nAjaxとJavaでの連携でJsonを取得して、ツリー表示できない。 \n実現できるなら、AjaxでもJavaでもどちらでもいいのですが、Jsonをツリー表示するのがわからなく、プラスボタンで再度Jsonデータを呼びに行く方法がわからないという現状です。\n\n### 該当のソースコード\n\n**Java**\n\n```\n\n @Service\n public class ZipCodeService {\n \n @Autowired\n @Qualifier(\"zipCodeSearchRestTemplate\")\n RestTemplate restTemplate;\n \n /** サンプル検索API リクエストURL */\n private static final String URL = \"http://zipcloud.ibsnet.co.jp/api/search?zipcode={zipcode}\";\n \n public ZipCodeDto service(String zipcode) {\n return restTemplate.getForObject(URL, ZipCodeDto.class, zipcode);\n }\n \n }\n \n```\n\n**java**\n\n```\n\n @Controller\n public class ZipCodeController {\n \n @Autowired\n ZipCodeService zpcService;\n \n /**\n * サンプル入力フォーム\n * @return \"zipcode\"\n */\n @RequestMapping(\"/zipcode\")\n public String zipcodeForm(HttpSession session, Model model) {\n return \"zipcode\";\n }\n \n /**\n * サンプル情報表示 \n * @return \"zipcode-confirm\"\n */\n @RequestMapping(value=\"/zipcode/confirm\", method=RequestMethod.POST)\n public String zipcodeConfirm(HttpSession session, Model model, \n @RequestParam(\"zipcode\") String zipcode){\n \n // 一応必須チェックのみ 数字・桁数チェックは省略\n // nullまたは空文字の場合、入力フォームにエラーメッセージを表示\n if (zipcode == null || zipcode.equals(\"\")) {\n model.addAttribute(\"errorMessage\", \"郵便番号を入力してください。\");\n return zipcodeForm(session, model);\n }\n \n // サンプル検索APIサービス呼び出し\n ZipCodeDto zipCodeDto = zpcService.service(zipcode);\n // thymeleafでリストを展開して表示する\n model.addAttribute(\"zipcodeList\", zipCodeDto.getResults());\n return \"zipcode-confirm\"; \n }\n }\n \n```\n\n**HTML**\n\n```\n\n <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"ja\">\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <meta http-equiv=\"imagetoolbar\" content=\"no\" />\n <title>設置サンプル</title>\n <link rel=\"stylesheet\" type=\"text/css\" href=\"/content/lib/yui/build/treeview/treeview.css?_yuiversion=2.4.1\" />\n <link rel=\"stylesheet\" type=\"text/css\" href=\"/content/lib/yui/build/treeview/tree.css?_yuiversion=2.4.1\" />\n <script type=\"text/javascript\" src=\"/content/lib/yui/build/yahoo/yahoo.js?_yuiversion=2.4.1\"></script>\n <script type=\"text/javascript\" src=\"/content/lib/yui/build/event/event.js?_yuiversion=2.4.1\"></script>\n <script type=\"text/javascript\" src=\"/content/lib/yui/build/treeview/treeview.js?_yuiversion=2.4.1\"></script>\n <style type=\"text/css\">\n * {\n margin:0; padding:0;\n }\n body{\n margin:0 auto; padding:0;\n background-color:#666;\n color:#666;\n font:81%/1.5 verdana,sans-serif;\n text-align:center;\n }\n #wrap {\n width:500px;\n margin:0 auto; padding:0;\n background-color:#fff;\n text-align:center;\n }\n #content {\n margin:0 20px; padding:0;\n text-align:left;\n }\n #footer {\n margin:1em 0 0 0; padding:.2em .5em;\n background-color:#999;\n color:#fff;\n font-size:78%;\n text-align:right;\n }\n #footer * {\n font-style:normal;\n font-size:100%;\n color:#fff;\n }\n h1 {\n margin:0 0 1em 0; padding:.5em 1em;\n background-color:#999;\n color:#fff;\n font-size:100%;\n text-align:left;\n }\n h1 a {\n color:#fff;\n }\n p {\n margin:1em 0; padding:0;\n }\n img {\n border:0;\n }\n </style>\n </head>\n <body>\n <div id=\"wrap\">\n <h1>設置サンプル</h1>\n <p>参照:<a href=\"http://developer.yahoo.com/yui/examples/treeview/folder_style.html\">YUI Library » Tree View Control » Folder-Style TreeView Design</a></p>\n <div id=\"content\">\n <p>\n <a id=\"expand\" href=\"#\">Expand all</a> | \n <a id=\"collapse\" href=\"#\">Collapse all</a>\n </p>\n <div id=\"treeDiv1\"></div>\n <script type=\"text/javascript\">\n //an anonymous function wraps our code to keep our variables\n //in function scope rather than in the global namespace:\n (function() {\n var tree; //will hold our TreeView instance\n function treeInit() {\n YAHOO.log(\"Example's treeInit function firing.\", \"info\", \"example\");\n //Hand off ot a method that randomly generates tree nodes:\n buildRandomTextNodeTree();\n //handler for expanding all nodes\n YAHOO.util.Event.on(\"expand\", \"click\", function(e) {\n YAHOO.log(\"Expanding all TreeView nodes.\", \"info\", \"example\");\n tree.expandAll();\n YAHOO.util.Event.preventDefault(e);\n });\n //handler for collapsing all nodes\n YAHOO.util.Event.on(\"collapse\", \"click\", function(e) {\n YAHOO.log(\"Collapsing all TreeView nodes.\", \"info\", \"example\");\n tree.collapseAll();\n YAHOO.util.Event.preventDefault(e);\n });\n }\n //This method will build a TreeView instance and populate it with\n //between 3 and 7 top-level nodes\n function buildRandomTextNodeTree() {\n //instantiate the tree:\n tree = new YAHOO.widget.TreeView(\"treeDiv1\");\n \n //create top-level nodes\n for (var i = 0; i < Math.floor((Math.random()*4) + 3); i++) {\n var tmpNode = new YAHOO.widget.TextNode(\"label-\" + i, tree.getRoot(), false);\n \n //we'll delegate to another function to build child nodes:\n buildRandomTextBranch(tmpNode);\n }\n //once it's all built out, we need to render\n //our TreeView instance:\n tree.draw();\n }\n //This function adds a random number <4 of child nodes to a given\n //node, stopping at a specific node depth:\n function buildRandomTextBranch(node) {\n if (node.depth < 6) {\n YAHOO.log(\"buildRandomTextBranch: \" + node.index);\n for ( var i = 0; i < Math.floor(Math.random() * 4) ; i++ ) {\n var tmpNode = new YAHOO.widget.TextNode(node.label + \"-\" + i, node, false);\n buildRandomTextBranch(tmpNode);\n }\n }\n }\n //When the DOM is done loading, we can initialize our TreeView\n //instance:\n YAHOO.util.Event.onDOMReady(treeInit);\n })();//anonymous function wrapper closed; () notation executes function\n </script>\n </div><!-- div#wrap/div#content -->\n </div><!-- div#wrap -->\n </body>\n </html>\n \n```\n\n**js**\n\n```\n\n jQuery( function() {\n jQuery( '#jquery-sample-button' ) . toggle(\n function() {\n jQuery . ajax( {\n url: 'jquery-sample-ajax-json.php',\n dataType: 'json',\n data: {\n year: '2011',\n month: '11',\n day: '25'\n },\n success: function( data ) {\n jQuery . each( data, function( key, value ) {\n jQuery( '#jquery-sample-ajax' ) . append( '<p>' + key + ': ' + value + '</p>' );\n } );\n jQuery( '#jquery-sample-textStatus' ) . text( '読み込み成功' );\n },\n error: function( data ) {\n jQuery( '#jquery-sample-textStatus' ) . text( '読み込み失敗' );\n }\n } );\n },\n function() {\n jQuery( '#jquery-sample-ajax' ) . html( '' );\n jQuery( '#jquery-sample-textStatus' ) . text( '' );\n }\n );\n } );\n \n```\n\n### 対象のJSONデータ\n\n**Json**\n\n```\n\n {\n \"book1\":{\n \"title\": \"Book\",\n \"year\": 2005 ,\n \"page\": 399\n },\n \"book2\":{\n \"title\": \"ワンピース\",\n \"year\": 2006 ,\n \"page\": 650\n }\n }\n \n```\n\n### 補足情報(言語/FW/ツール等のバージョンなど)\n\nSTS、SpringBoot、Java8,Javascript、HTML、Timeleaf",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-02T15:28:43.017",
"favorite_count": 0,
"id": "39984",
"last_activity_date": "2017-12-02T15:52:45.247",
"last_edit_date": "2017-12-02T15:52:45.247",
"last_editor_user_id": "26459",
"owner_user_id": "26459",
"post_type": "question",
"score": 1,
"tags": [
"javascript",
"java",
"json",
"ajax",
"thymeleaf"
],
"title": "Jsonデータの持ち回りと値の受け渡しについて",
"view_count": 1316
} | []
| 39984 | null | null |
{
"accepted_answer_id": "40721",
"answer_count": 3,
"body": "**Pythonの基本的なデータ型を確認したいのですが、**\n\n* * *\n\n**Q1.どうやって確認するのでしょうか?** \n・type()? \n・pprint()? \n・両者の違いは?\n\n* * *\n\n**Q2.下記コードで結果に何も表示されないのは何故ですか?** \n・type()はオブジェクト型のみが対象?\n\n```\n\n from fractions import Fraction\n f = Fraction(5, 7)\n type(f)\n \n```\n\n* * *\n\n**Q3.Pythonでプリミティブデータ型という言い方をしますか?**\n\n* * *\n\n**Q4.分数について** \n・「Fraction」で一つのデータ型ですか? \n・意味合いで言えば、「int」や「float」と同等ですか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T02:53:23.677",
"favorite_count": 0,
"id": "39993",
"last_activity_date": "2018-01-05T02:57:06.747",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7886",
"post_type": "question",
"score": 1,
"tags": [
"python",
"python3"
],
"title": "Pythonでデータ型を確認したい。 typeとpprintの違いは?",
"view_count": 1656
} | [
{
"body": "> Q2.下記コードで結果に何も表示されないのは何故ですか? \n> ・type()はオブジェクト型のみが対象?\n\nprintしないと表示されません。\n\n```\n\n from fractions import Fraction\n f = Fraction(5, 7)\n print(type(f))\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T05:40:33.420",
"id": "39996",
"last_activity_date": "2017-12-03T05:40:33.420",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26311",
"parent_id": "39993",
"post_type": "answer",
"score": 1
},
{
"body": "Q1.どうやって確認するのでしょうか? \n・type()? \n・pprint()? \n・両者の違いは? \ntype()を使います。 \npprint()は、複雑なデータを整えて表示する機能を持ちます。\n\n```\n\n import pprint\n \n print([[i for i in range(10)]]*2)\n pprint.pprint([[i for i in range(11)]]*3)\n #print\n [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]\n #pprint\n [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]\n \n```\n\nQ2.下記コードで結果に何も表示されないのは何故ですか? \n・type()はオブジェクト型のみが対象?\n\n```\n\n from fractions import Fraction\n f = Fraction(5, 7)\n type(f)\n \n```\n\n別の回答者様が書かれていますが、\n\n```\n\n print(type(f))\n \n```\n\nとして初めて表示されます。 \n`type()`だけだと、`f`の型を取得はできても、出力表示するという \n命令までは持っていないからです。 \n`type()`は、オブジェクト型のみが対象です。 \nオブジェクト型というのは、名前を付けることのできるものです。\n\n```\n\n b = \"オブジェクト\"\n print(type(b))\n <class 'str'>\n def sai():\n return 1\n \n print(type(sai()))\n <class 'int'>\n print(type(sai))\n <class 'function'>\n import re\n print(type(re))\n <class 'module'>\n #cという名前のついたreモジュール\n c = re \n print(type(c))\n <class 'module'>\n \n```\n\nPythonでは、変数名をつけられるものはすべてオブジェクトと \n言っていいと思います。\n\nQ3.Pythonでプリミティブデータ型という言い方をしますか?\n\n「Pythonの基本的なデータ型を確認したいのですが」 \nという質問なので、Pythonの基本的なデータ型を、 \nプリミティブデータ型という言い方をしますか?という \n質問だと判断します。 \nPythonの基本的なデータ型は、ビルトインタイプ、 \nビルトイン型、組み込み型と呼ばれ、そのようには \n呼ばれないです。\n\nQ4.分数について \n・「Fraction」で一つのデータ型ですか? \nそうです。 \n・意味合いで言えば、「int」や「float」と同等ですか? \nそうです。 \nただ、`int`は、 **組み込み型** なので、`import`しなくても、 \n即座に使えます。 \n`Fraction`は、 \n\n```\n\n from fractions import Fraction\n \n```\n\nとあるように、フラクションモジュールの中にある \n`Fraction`型です。モジュールの中に入っているか \nどうかの違いだけです。こういう、`Python`に最初から \nあるという点では **組み込み型** だけど、インポートが \n別に必要な場合を、 **標準ライブラリ** と言います。 \nこれに、`pygame`や、`PyQt5`など、外部から別に持ってきた \nモジュールで、インストール後にインポートできるような \nものを、 **サードパーティーモジュール** と言います。 \nゆえに、 **組み込み型** は、「特別な宣言や命令なしに \n利用できる型」と言えます。 \n導入にちょっと段階がいるだけで、データ型であることは \n変わりません。",
"comment_count": 7,
"content_license": "CC BY-SA 3.0",
"creation_date": "2018-01-04T12:04:11.693",
"id": "40721",
"last_activity_date": "2018-01-05T02:57:06.747",
"last_edit_date": "2018-01-05T02:57:06.747",
"last_editor_user_id": "24284",
"owner_user_id": "24284",
"parent_id": "39993",
"post_type": "answer",
"score": 3
},
{
"body": "Q3への回答について補足します。\n\n### Q3.Pythonでプリミティブデータ型という言い方をしますか?\n\nしないです。[公式ドキュメント](https://docs.python.org/3/index.html) で「primitive data\ntype」を検索してみてください。\n\nただし、非公式な個人ドキュメント([Learn Python\nVisually](http://pythonvisually.com/ebook/primitive-data-types.html),\n[ZetCodeのPython\nTutorial](http://zetcode.com/lang/python/datatypes/))ではそのような表現もみられました。\n\nプリミティブデータ型については、オブジェクトと非オブジェクトで区別する人もいれば、複合型でなければプリミティブと捉える人もいます。Pythonにプリミティブデータ型はあるか?\nと質問したら不毛な論争になるかもしません。定義が共有されてない場合があるので、どういう意味で聞いているかによります。\n\nただ、[他の方の回答](https://ja.stackoverflow.com/a/40721/26045) でプリミティブデータ型について、\n\n> ビルトインタイプ、ビルトイン型とか、組み込み型と言われます。\n\nと書かれているのは、指しているものが全く違うので適切ではないと思います(ので、補足として回答させてもらいました)。組み込み型はプリミティブデータ型の言い換えではありません。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2018-01-04T20:44:59.420",
"id": "40728",
"last_activity_date": "2018-01-04T20:44:59.420",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": null,
"parent_id": "39993",
"post_type": "answer",
"score": 2
}
]
| 39993 | 40721 | 40721 |
{
"accepted_answer_id": null,
"answer_count": 3,
"body": "初歩的な質問です.下記のようなコードがあったとします.\n\n```\n\n for(int i=0; i<100; ++i)\n {\n int a = i;\n std::cout << a << std::endl;\n }\n \n```\n\nここで,aはforの中でしか使用しません.しかし,スコープをできるだけ小さくしたほうがいいからといってforの中に入れて何回も宣言させるのは効率が悪い気がします.つまり,\n\n```\n\n int a;\n for(int i=0; i<100; ++i)\n {\n a = i;\n std::cout << a << std::endl;\n }\n \n```\n\nこのようなプログラムとではスコープが大きくなる以外で何か不都合が起きたりするのでしょうか.",
"comment_count": 4,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T04:53:18.197",
"favorite_count": 0,
"id": "39994",
"last_activity_date": "2017-12-18T03:20:06.477",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "23768",
"post_type": "question",
"score": 1,
"tags": [
"java",
"c++",
"c"
],
"title": "変数のスコープはfor内に入れてでもできるだけ狭くしたほうがいいか?",
"view_count": 4061
} | [
{
"body": "C++言語にはコンストラクタ・デストラクタが存在します。\n\n>\n```\n\n> int a = i;\n> \n```\n\nは`i`で初期化されますが\n\n>\n```\n\n> int a;\n> a = i;\n> \n```\n\nは空で初期化した上で、後から`i`をコピー・代入を行っています。また、デストラクターが実行されるタイミングも後者は`for`ループ終了直後ですが、前者はスコープを抜けるまでそのまま生き続けます。 \n単純な整数であれば違いはありませんが、汎用性を考慮すれば常に適切な変数スコープを意識すべきです。\n\nこれに関連して、C++言語では`for`だけでなく`if`や`switch`でも効率的な変数宣言できるように拡張されています。[if文とswitch文の条件式と初期化を分離](https://cpprefjp.github.io/lang/cpp17/selection_statements_with_initializer.html)",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T05:06:51.200",
"id": "39995",
"last_activity_date": "2017-12-03T22:55:19.990",
"last_edit_date": "2017-12-03T22:55:19.990",
"last_editor_user_id": "4236",
"owner_user_id": "4236",
"parent_id": "39994",
"post_type": "answer",
"score": 8
},
{
"body": "> しかし,スコープをできるだけ小さくしたほうがいいからといってforの中に入れて何回も宣言させるのは効率が悪い気がします\n\nメモリー効率的には変わらず実行速度的にも変わらず、可読性が向上するので積極的にスコープは小さくしましょう。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T15:19:02.213",
"id": "40004",
"last_activity_date": "2017-12-03T15:19:02.213",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "23941",
"parent_id": "39994",
"post_type": "answer",
"score": 3
},
{
"body": "質問文を読み、変数宣言にかかるコストに対して懸念が有る、というふうに理解しました。 \n私も以前同様の疑問を抱き、Java(Java5)とC(GCC 4.4.3)調べてみたことがあります。\n\n * [ループ内で変数を宣言しない方が良いのか: 発火後忘失](http://feather.cocolog-nifty.com/weblog/2010/05/post-a00a.html) \n(※7年以上前の話なので、疑問の発端となったページは消えてしまっていますが…)\n\n結論としては、ループ外で宣言しようが中で宣言しようが **効率は完全に同一である** 、というものでした。 \nコンパイル後のバイトコード/アセンブリからは変数宣言した、という情報は無くなっていました。つまりローカル変数宣言にかかるコストはゼロです。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-18T03:20:06.477",
"id": "40350",
"last_activity_date": "2017-12-18T03:20:06.477",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2808",
"parent_id": "39994",
"post_type": "answer",
"score": 1
}
]
| 39994 | null | 39995 |
{
"accepted_answer_id": "40005",
"answer_count": 1,
"body": "正規表現のビギナーです。分かっていると思えるのは、\\bが最初と最後のスペースだけマッチ。/gがグローバルで、一つだけではなく全てマッチする。\\wがA-Z,a-z,0-9,_をマッチ。\n\n理解が少し進んだのか、今のところアポストロフィをマッチングするための表現が合っていれば[\\']?を入れる場所です。\n\nしかしとすると、var arr = str.match(/\\b(\\w+|\\')\\b/g);\n\n[ 'Hell', '\\'', 'o', 'World' ]と出力します。\n\n結果として出したいのは['Hell'o', 'World']です。\n\n```\n\n function countWords(str) {\r\n var count = 0;\r\n var arr = str.match(/\\b(\\w+)[^']\\b/g);\r\n for(var i = 0; i < arr.length; i++){\r\n if(arr[i] != \"\"){\r\n count++;\r\n }\r\n }\r\n return count;\r\n }\r\n countWords(\"Hell'o World \")\n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T11:57:01.970",
"favorite_count": 0,
"id": "40000",
"last_activity_date": "2017-12-03T15:48:08.677",
"last_edit_date": "2017-12-03T15:44:28.640",
"last_editor_user_id": "2383",
"owner_user_id": "25766",
"post_type": "question",
"score": 2,
"tags": [
"javascript",
"正規表現"
],
"title": "正規表現 アポストロフィも文字列の一部としてマッチしたい。",
"view_count": 1261
} | [
{
"body": "```\n\n str.match(/[\\w']+/g);\n \n```\n\nこれで良いような気がします。\n\n半角スペースをデリミタとしてmatchしたいのであれば\n\n```\n\n str.match(/\\S+/g);\n \n```\n\nでも良い気がします。",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T15:41:12.767",
"id": "40005",
"last_activity_date": "2017-12-03T15:48:08.677",
"last_edit_date": "2017-12-03T15:48:08.677",
"last_editor_user_id": "2383",
"owner_user_id": "2383",
"parent_id": "40000",
"post_type": "answer",
"score": 2
}
]
| 40000 | 40005 | 40005 |
{
"accepted_answer_id": null,
"answer_count": 2,
"body": "スレッドはthreadingでメソッドを複数生成して、ほぼ並列処理みたいな感じというのはなんとなくわかったのですが、メソッドの戻り値がほしいときは、どのようにしてとったらよいのでしょうか?理想は全ての戻り値を足すことができればと思っているのですが・・・\n\nまず考え方が間違っているのでしょうか?\n\n```\n\n def pulus(x, y):\n sums = x + y\n return sums\n \n pulus_threads = []\n for i in range(1, 3):\n pulus_thread = threading.Thread(target=pulus, args=(i, i))\n pulus_threads.append(pulus_thread)\n pulus_thread.start()\n for pulus_thread in pulus_threads:\n pulus_thread.join()\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T17:57:02.320",
"favorite_count": 0,
"id": "40007",
"last_activity_date": "2018-03-30T06:40:49.157",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26076",
"post_type": "question",
"score": 3,
"tags": [
"python"
],
"title": "pythonのマルチスレッドのメソッドから戻り値を得るにはどうしたらよいですか?",
"view_count": 13793
} | [
{
"body": "\"python multithread return value\"で検索すると、色々と出てきます。 \n英語版のStackOverflowにいくつか良さそうなのがありました。\n\n1.multiprocessingモジュールのThreadpoolを使う方法 \nベストアンサーではapply_asyncでスレッドプールを作成し、getで結果を取得しています。 \nただし、ベストアンサーについても、色々と議論の余地があるようです。 \nhow to get the return value from a thread in python? \n<https://stackoverflow.com/questions/6893968/how-to-get-the-return-value-from-\na-thread-in-python> \n関連 \nHow to obtain the results from a pool of threads in python? \n<https://stackoverflow.com/questions/26104512/how-to-obtain-the-results-from-\na-pool-of-threads-in-python/26104609#26104609>\n\n2.QueueモジュールのQueueを使う方法 \nベストアンサーでは先にQueueを作成し、各スレッドのパラメータにそのQueueを指定し、スレッドは結果をQueueに詰める。 \n呼び出し元はすべてのスレッドが終了してからQueueの結果が無くなるまで合計なり平均なりのやりたい処理を行う。 \nこちらも議論の余地があるようです。 \nReturn value from thread \n<https://stackoverflow.com/questions/1886090/return-value-from-thread>\n\n3.参考 \npythonのモジュールに関する解説サイトから \nthreading – Manage concurrent threads \n<https://pymotw.com/2/threading/> \nmultiprocessing — Manage Processes Like Threads \n<https://pymotw.com/3/multiprocessing/index.html>",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-03T23:45:31.400",
"id": "40010",
"last_activity_date": "2017-12-03T23:45:31.400",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26370",
"parent_id": "40007",
"post_type": "answer",
"score": 0
},
{
"body": "用途によりけりなのですが、今回の場合は`concurrent.futures`の[`ThreadPoolExecutor`](https://docs.python.org/3/library/concurrent.futures.html#executor-\nobjects)を使うと楽に実装できます。\n\n```\n\n from concurrent.futures import ThreadPoolExecutor\n \n def pulus(x, y):\n sums = x + y\n return sums\n \n with ThreadPoolExecutor(max_workers=10) as executor:\n x = range(5)\n y = range(5, 10)\n res = executor.map(pulus, x, y)\n \n \n print(list(x))\n print(list(y))\n print(list(res))\n \n```\n\n`ThreadPoolExecutor`はI/Oがボトルネックのときによく使われます。重い処理を複数のCPUに分散させることが目的でしたら、`ProcessPoolExecutor`のほうがいいかもしれません。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T04:32:00.700",
"id": "40016",
"last_activity_date": "2017-12-04T04:32:00.700",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26311",
"parent_id": "40007",
"post_type": "answer",
"score": 2
}
]
| 40007 | null | 40016 |
{
"accepted_answer_id": "40017",
"answer_count": 3,
"body": "横に長いUITableViewを考えています。\n\n 1. Cellは無限に増える可能性がある\n 2. UITableView(UIScrollView)のオリジナルの挙動(慣性スクロールや、バウンス)はそのまま残したい\n 3. 縦横スクロールは1タップで同時に行いたい\n 4. できるだけカスタムクラスは作りたくない\n\nという要件があります。\n\n * オリジナルのViewを作ってそれをScrollViewに貼り付けるという方法では、1. の要件を満たすのが複雑になります。\n * ScrollViewの上にTableViewを貼り付けて、縦ScrollはTableViewに、横ScrollはScrollViewにそれぞれ担当させると、一度に一方向へしかScrollが効かず、3. が満たされません。\n * TableViewCellの中にScrollViewまたはCollectionViewを乗せても、3. が満たされませんでした。\n * ScrollView上にTableViewを乗せそれぞれのUser Interaction EnableをNOにし、さらにその上にPanGestureを設定したUIViewを乗せて、UIViewで感知した縦横のPanGestureをScrollView、TableViewそれぞれに伝達しContentOffsetを操作しましたが、2. が満たされませんでした。\n\nUITableViewの横スクロール問題はよく話題になるかとは思いますが、最善の(最も簡単で、オリジナルUIを継承しつつ、デバイス不可も少ない)方法はどのようなものなのでしょうか。 \nもし成功されている方がいらっしゃいましたら、アドバイスをお願いいたします。\n\n* * *\n\n回答してくださった皆さんのおかげで解決することができました。 \n結論としては、UICollectionViewを使用し、UICollectionViewLayoutを自作することですべての要件を満たすことができました。 \n以下、UICollectionViewLayoutのobjcのコードを転載しておきます。\n\n```\n\n #import \"BidirectionalCollectionLayout.h\" // UICollectionViewLayoutを継承\n \n @implementation BidirectionalCollectionLayout {\n NSInteger cellCount;\n CGSize cellSize;\n }\n \n - (void)prepareLayout\n {\n [super prepareLayout];\n cellCount = [self.collectionView numberOfItemsInSection:0];\n cellSize = CGSizeMake(2000.0f, 66.0f);\n }\n \n - (CGSize)collectionViewContentSize {\n return CGSizeMake(cellSize.width, cellCount * cellSize.height);\n }\n \n - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect\n {\n NSArray *indexPathsArray = [self indexPathsForItemsInRect:rect];\n NSMutableArray *array = [NSMutableArray array];\n for (NSIndexPath *indexPath in indexPathsArray) {\n [array addObject:[self layoutAttributesForItemAtIndexPath:indexPath]];\n }\n return array;\n }\n \n - (NSArray *)indexPathsForItemsInRect:(CGRect)rect\n {\n NSMutableArray *array = [NSMutableArray array];\n \n NSInteger minRow = MAX(0, (NSInteger)floor(rect.origin.y / cellSize.height));\n NSInteger maxRow = MIN(cellCount, (NSInteger)ceil((rect.origin.y + rect.size.height) / cellSize.height));\n for (NSInteger i = minRow; i < maxRow; i++) {\n [array addObject:[NSIndexPath indexPathForItem:i inSection:0]];\n }\n return array;\n }\n \n - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath\n {\n UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];\n CGFloat offsetY = indexPath.item * cellSize.height;\n CGRect frame = CGRectMake(0, offsetY, cellSize.width, cellSize.height);\n attributes.frame = frame;\n return attributes;\n }\n \n @end\n \n```",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T02:12:00.730",
"favorite_count": 0,
"id": "40012",
"last_activity_date": "2017-12-05T14:04:15.393",
"last_edit_date": "2017-12-05T14:04:15.393",
"last_editor_user_id": "8501",
"owner_user_id": "8501",
"post_type": "question",
"score": 1,
"tags": [
"ios",
"objective-c",
"uitableview",
"uicollectionview"
],
"title": "UITableViewに横スクロールを実装する最良の方法",
"view_count": 2809
} | [
{
"body": "※コメントで指摘いただきましたが、下記方法では上下方向のスクロールができません。お目汚し失礼しました。\n\nCGAffineTransformを利用するとViewを回転して表示することができます。 \nUITableViewを90度回転させて表示すれば目的の通りになると思います\n\n```\n\n - (void)viewDidLoad\n {\n [super viewDidLoad];\n // Do any additional setup after loading the view, typically from a nib.\n \n CGRect bounds = [[UIScreen mainScreen] bounds];\n \n UITableView *tblView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];\n \n CGAffineTransform rotate90 = CGAffineTransformMakeRotation(-M_PI / 2.0);\n [tblView setTransform:rotate90];\n tblView.frame = bounds;\n [self.view addSubview:tblView];\n \n }\n \n```\n\nただし、UITableViewCellの中身も回転してしまうので、逆回転したビューをCellの上に配置してあげる必要があります。\n\n\\---追記--- \n以下URLのようにUICollectionViewを使う方法もあるようです。 \n<https://qiita.com/koyopro/items/b4363cfd7f0838f88103>\n\n\\---追記--- \n参照先がSwiftだったのでCocoaでのサンプルコードも載せておきます。\n\n```\n\n - (void)viewDidLoad\n {\n [super viewDidLoad];\n // Do any additional setup after loading the view, typically from a nib.\n \n CGRect bounds = [[UIScreen mainScreen] bounds];\n \n UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];\n \n layout.itemSize = CGSizeMake(50, 100);\n layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);\n layout.minimumLineSpacing = 0.0;\n layout.minimumInteritemSpacing = 0.0;\n layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;\n \n UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:bounds collectionViewLayout:layout];\n \n [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class])];\n \n collectionView.frame = CGRectMake(0, 0, bounds.size.width, 100);\n [self.view addSubview:collectionView];\n //クラスに<UICollectionViewDataSource>を設定しておいてください\n collectionView.dataSource = self;\n }\n \n \n - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section\n {\n return 20;\n }\n \n - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath\n {\n NSInteger row = indexPath.row;\n \n UICollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath];\n \n if(cell == nil)\n {\n }\n cell.backgroundColor = [UIColor colorWithRed:row * 20 / 255.0 green:1.0 blue:0.0 alpha:1.0];\n \n return cell;\n }\n \n```",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T02:51:23.123",
"id": "40013",
"last_activity_date": "2017-12-04T06:36:02.237",
"last_edit_date": "2017-12-04T06:36:02.237",
"last_editor_user_id": "17014",
"owner_user_id": "17014",
"parent_id": "40012",
"post_type": "answer",
"score": 1
},
{
"body": "上記コメントで書きましたが、UITableViewを使って実現するのはなかなか難しいのではないかと思います。\n\n「ScrollView上にTableViewを乗せ〜」で、かつそのViewへのタッチイベントを全て補足してそれぞれのビューをスクロールさせる方法なども一応考えられますが、UITableViewやUIScrollViewと同じ手触りのスクロールを実現するには相応の苦労が伴うと思います。\n\n他の方法として、近い機能を提供するOSSライブラリを利用することが考えられます。\n\n例えば、以下のライブラリはiOS上にMSエクセルの様なスプレッドシートを表示することができます。\n\n**kishikawakatsumi/SpreadsheetView** \n<https://github.com/kishikawakatsumi/SpreadsheetView>\n\nUITableViewとは勝手が違う部分もあるでしょうが、縦横へのスクロールは可能になると思います。\n\n* * *\n\n**追記**\n\nコメントで指摘されたとおり、UICollectionViewで実現可能でした。 \n以下、縦横へスクロールするUICollectionViewLayoutの簡易実装例です。 \nセルサイズ固定で、単一セクションのみ対応など必要最低限以下の実装ですので、 \nあくまで参考程度にお願いします。 \nより実用的なLayoutの実装には[UICollectionViewLayout](https://developer.apple.com/documentation/uikit/uicollectionviewlayout)のドキュメント等を参考にしてください。 \n(Swiftで失礼。適宜Objective-Cへ読み替えてください)\n\n```\n\n import UIKit\n \n // 縦横スクロールレイアウトの超簡易実装\n // セルサイズ固定、単一Sectionのみ対応、ヘッダー・フッター非対応、セルの追加削除への考慮なし\n class SampleLayout: UICollectionViewLayout {\n \n let cellSize = CGSize(width:1000, height: 60);\n \n private var _contentSize = CGSize.zero\n \n override var collectionViewContentSize: CGSize {\n return _contentSize\n }\n \n override func prepare() {\n super.prepare()\n let num = self.collectionView!.numberOfItems(inSection: 0)\n self._contentSize = CGSize(width: cellSize.width, height: cellSize.height * CGFloat(num))\n }\n \n override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {\n let attr = UICollectionViewLayoutAttributes.init(forCellWith: indexPath)\n attr.frame = CGRect(origin: CGPoint(x:0, y: CGFloat(indexPath.item) * cellSize.height), size: cellSize)\n return attr\n }\n \n override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {\n var attrs:[UICollectionViewLayoutAttributes] = []\n \n let begin = max(0, Int(floor(rect.minY / cellSize.height)))\n let end = min(collectionView!.numberOfItems(inSection: 0), Int(ceil(rect.maxY / cellSize.height)))\n \n for item in (begin..<end) {\n attrs.append(layoutAttributesForItem(at: IndexPath(item: item, section: 0))!)\n }\n \n return attrs\n }\n }\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T06:54:01.457",
"id": "40017",
"last_activity_date": "2017-12-04T08:05:26.727",
"last_edit_date": "2017-12-04T08:05:26.727",
"last_editor_user_id": "23829",
"owner_user_id": "23829",
"parent_id": "40012",
"post_type": "answer",
"score": 1
},
{
"body": "次のような感じでいかがでしょうか? \n最初からテーブルで表示される要素のサイズがわかっている必要があります。 \nスクロールビュー上にテーブルビューを置くのは一緒ですが、 \nスクロール量をUIViewのPanイベントでとるのではなく、スクロールビューとテーブルビューのスクロール量を一致させるのがコツです。 \nセルが横方向にも並ぶのであれば、もう少し改造する必要があります。\n\n```\n\n #import \"ViewController.h\"\n \n @interface ViewController ()<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>\n {\n UIScrollView *scrView;\n UITableView *tblView;\n \n int rowNum;\n CGSize rowSize;\n }\n \n @end\n \n @implementation ViewController\n \n - (void)viewDidLoad\n {\n [super viewDidLoad];\n // Do any additional setup after loading the view, typically from a nib.\n \n rowNum = 100;\n rowSize = CGSizeMake(1000, 70);\n \n CGRect bounds = [[UIScreen mainScreen] bounds];\n \n scrView = [[UIScrollView alloc] initWithFrame:bounds];\n \n float contentViewHeight = rowSize.height * rowNum;\n \n //行数が少ない時は縦Bounceのために、スクロールビューを1px大きくする\n if(contentViewHeight <= bounds.size.height)\n {\n contentViewHeight = bounds.size.height+ 1;\n }\n \n \n tblView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, rowSize.width, bounds.size.height)];\n \n tblView.userInteractionEnabled = NO;\n tblView.delegate = self;\n tblView.dataSource= self;\n tblView.rowHeight = rowSize.height;\n [self.view addSubview:tblView];\n \n scrView.delegate = self;\n [scrView setContentSize:CGSizeMake(rowSize.width, contentViewHeight)];\n scrView.backgroundColor = [UIColor clearColor];\n [self.view addSubview:scrView];\n }\n \n \n - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section\n {\n return rowNum;\n }\n \n - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath\n {\n UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@\"cell\"];\n if(cell == nil)\n {\n cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@\"cell\"];\n UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 1000, 44)];\n \n lbl.tag = 1;\n \n [cell.contentView addSubview:lbl];\n }\n \n UILabel *label = [cell viewWithTag:1];\n \n label.text = [NSString stringWithFormat:@\"%dABCDEFGHIJKLMUOPQRSTUVWXYZABCDEFGHIJKLMUOPQRSTUVWXYZABCDEFGHIJKLMUOPQRSTUVWXYZABCDEFGHIJKLMUOPQRSTUVWXYZABCDEFGHIJKLMUOPQRSTUVWXYZABCDEFGHIJKLMUOPQRSTUVWXYZABCDEFGHIJKLMUOPQRSTUVWXYZ\", (int)indexPath.row];\n \n NSLog(@\"%d\", (int)indexPath.row);\n \n return cell;\n }\n \n -(void)scrollViewDidScroll:(UIScrollView *)scrollView\n {\n //下地のスクロールビューと上に乗っているテーブルビューのクスロール量を合わせる\n tblView.contentOffset = CGPointMake(scrView.contentOffset.x, scrView.contentOffset.y);\n }\n \n - (void)didReceiveMemoryWarning\n {\n [super didReceiveMemoryWarning];\n // Dispose of any resources that can be recreated.\n \n \n }\n \n \n @end\n \n```\n\n**編集1** \n対処療法的ですが、行数が少なくても縦Bouncesが効くようにしました。 \n小手先感が否めないので、CollectionViewで対応できるならそちらで対応する方が自然だと思います。 \n**編集2** \nスクロールバーが出てなかったので、出るように調整してみました。",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T07:19:56.490",
"id": "40019",
"last_activity_date": "2017-12-05T02:04:14.260",
"last_edit_date": "2017-12-05T02:04:14.260",
"last_editor_user_id": "17014",
"owner_user_id": "17014",
"parent_id": "40012",
"post_type": "answer",
"score": 0
}
]
| 40012 | 40017 | 40013 |
{
"accepted_answer_id": null,
"answer_count": 0,
"body": "Python MySQL csv \nについての質問です。 \n現在センサの勉強を行っており、サーバにセンサデータを送って処理をするということをやって勉強しています。 \nプログラムを書いたのですが、エラー出てわからないので質問させていただきました。\n\nプログラムの内容としてcsvファイルに書き込まれているデータの一番最初の列がIDでそのIDを取り出して、 \nその取り出したIDからデータベースにあるメールアドレスを特定してbに代入、printで表示するものです。 \nおそらくエラーを読む限り、変数の型がちがうのではないかと思っているのですが、プログラムの書き方がわかりません。\n\n教えていただけると助かります。\n\n```\n\n import csv\n import MySQLdb\n \n MySQL接続\n cur = cnt.cursor()\n \n f=open('data2.csv','r')\n for line in f:\n a=line.split(',')[0]\n cur.execute('SELECT ADDRESS FROM user WHERE ID=%d',int(a))\n b=cur.fetchone()\n print (b)\n \n cur.close\n cnt.close\n f.close()\n \n```\n\ndata2.csv (一番最初の列がID)\n\n```\n\n 1111,4686\n 2222,4846\n \n```\n\nデータベース\n\n```\n\n ID MAIL\n 1111 [email protected]\n 2222 [email protected]\n \n```\n\n実行結果エラー\n\n```\n\n Traceback (most recent call last):\n File \".py\", line 11, in <module>\n cur.execute('SELECT ADDRESS FROM user WHERE ID=%d',int(a))\n File \"/root/.pyev/versions/anaconda3.1/lib/python3.6/site-pakages/MySQLdb/cursors.py\", line 234, in execute\n args = tuple(map(db.literal, args))\n TypeError: 'int' object is not iterable\n \n```",
"comment_count": 3,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T07:35:58.410",
"favorite_count": 0,
"id": "40022",
"last_activity_date": "2017-12-04T12:57:49.403",
"last_edit_date": "2017-12-04T09:49:04.363",
"last_editor_user_id": "2238",
"owner_user_id": "26490",
"post_type": "question",
"score": 0,
"tags": [
"python",
"mysql",
"csv"
],
"title": "Python MySQL csvについての質問です。",
"view_count": 325
} | []
| 40022 | null | null |
{
"accepted_answer_id": "40028",
"answer_count": 1,
"body": "C#(Visual studio2015)でComboBoxの値に応じてレイアウトを変更したいです。\n\nxamlファイル\n\n```\n\n <ComboBox Grid.Row=\"1\" Grid.Column=\"1\" \n ItemsSource=\"{Binding TypeCollection}\"\n DisplayMemberPath=\"Text\"\n Width=\"140\" HorizontalAlignment=\"Left\" />\n <TextBlock Grid.Row=\"2\" Text=\"test A!\" HorizontalAlignment=\"Right\" VerticalAlignment=\"Center\"/>★1\n <TextBlock Grid.Row=\"3\" Text=\"test B!\" HorizontalAlignment=\"Right\" VerticalAlignment=\"Center\"/>★2\n \n```\n\nTypeCollectionにはAとBが選択できるようになっているのですが、 \nAを選んだ時に★1、Bを選んだ時に★2のテキストを表示させたいです。\n\nxamlでそのような条件わけができるのでしょうか? \nそれともCSファイル側で行うべきなのでしょうか?",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T09:46:03.903",
"favorite_count": 0,
"id": "40026",
"last_activity_date": "2017-12-04T12:25:35.700",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12842",
"post_type": "question",
"score": 0,
"tags": [
"c#",
"visual-studio"
],
"title": "C#でComboBoxの値に応じてレイアウトを変更したい",
"view_count": 1933
} | [
{
"body": "`ComboBox`には選択値に応じて変化するプロパティがいくつかありますので、そのいずれかに対する`{Binding}`を作成すれば`DataTrigger`に使用することができます。手順としては\n\n 1. `<ComboBox>`に`Name`を指定する\n 2. `<TextBlock>`に`<Style>`を追加する\n 3. `<Style.Triggers>`に`<DataTrigger>`を追加し、`Binding`に`ElementName`として`1.`を、`Path`に`Selected****`を指定する。\n 4. `<DataTrigger>`に`Visibility`を変更する`<Setter>`を追加する。\n\nとなり、例えば`SelectedIndex`が分かっている場合は\n\n```\n\n <ComboBox\n x:Name=\"comboBox\" />\n <TextBlock>\n <TextBlock.Style>\n <Style\n TargetType=\"TextBlock\">\n <Style.Triggers>\n <DataTrigger\n Binding=\"{Binding ElementName=comboBox, Path=SelectedIndex}\"\n Value=\"1\">\n <Setter\n Property=\"Visibility\"\n Value=\"Collapsed\" />\n </DataTrigger>\n </Style.Triggers>\n </Style>\n </TextBlock.Style>\n test A!\n </TextBlock>\n \n```\n\nのようになります。\n\nただ`ComboBox.ItemsSource`をバインドしているのに特定のインデックスや値を要素を想定したトリガーをビュー側に記述するのは行儀が良いとはいいがたいです。コーディング量も`DataContext`内で適切に実装した方が少なくなりますので、参考程度に考えてください。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T12:25:35.700",
"id": "40028",
"last_activity_date": "2017-12-04T12:25:35.700",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5750",
"parent_id": "40026",
"post_type": "answer",
"score": 0
}
]
| 40026 | 40028 | 40028 |
{
"accepted_answer_id": "40039",
"answer_count": 1,
"body": "<https://qiita.com/tsunet111/items/0ba0e8fc61882c3905c0> \nこちらの記事が比較的シンプルだった為、紹介されているqdmail.phpとqdsmtp.phpというライブラリを利用したいのですが、ページが表示されない状況で、困っています。 \nPHPのログをみると、やはり\n\n```\n\n PHP Parse error: syntax error, unexpected 'new' (T_NEW) in C:\\xampp\\htdocs\\ATOZ\\qdmail.php on line 661\n \n```\n\nと表示されていました。当方PHP Version 7.0.4です。\n\n====質問==== \n現在起きている状況は、自分のPHPのVerに対応していないライブラリを選定している、ということでしょうか?それとも読み込みに失敗しているだけなのでしょうか?",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T11:33:34.073",
"favorite_count": 0,
"id": "40027",
"last_activity_date": "2017-12-13T02:39:38.397",
"last_edit_date": "2017-12-05T04:25:58.613",
"last_editor_user_id": "25696",
"owner_user_id": "25696",
"post_type": "question",
"score": 0,
"tags": [
"php",
"mail"
],
"title": "SMTP経由のメール送信を達成する為、ネットで紹介されたライブラリを使用したいが利用できない",
"view_count": 2260
} | [
{
"body": ">\n> ①現在起きている状況は、自分のPHPのVerに対応していないライブラリを選定している、ということでしょうか?それとも読み込みに失敗しているだけなのでしょうか?\n\nはい、PHP7に対応していないと思われます。(php5系統なら動くのでは)\n\n> ②SMTPサーバを経由したメールを利用する上では、ライブラリを使うのが一般的のようですが、\n\n無難なPHPのメーラーライブラリならPHPMailerですが、<https://github.com/PHPMailer/PHPMailer>\n色々ありますので,自身で試して使い易い長くメンテナンスされているライブラリを選定してください。 \n*すでに作り始めているようなので、`mb_send_mail`等で処理を完成させてからどのライブラリを使用するか検討することをお薦めします。\n\n追記、PHPMailerの送信サンプル(PHPMailer 6.0.2. php7.1.6で送信確認しています。) \n'Exception.php'、'PHPMailer.php'、'SMTP.php'のパスは実行環境に合わせて変更してください。 \nsmtpサーバなどの設定もテスト環境に合わせて変更してください。 \n最後に、メールの誤送信に注意してください。\n\n```\n\n use PHPMailer\\PHPMailer\\PHPMailer;\n use PHPMailer\\PHPMailer\\Exception;\n \n require 'Exception.php';\n require 'PHPMailer.php';\n require 'SMTP.php';\n \n $mail = new PHPMailer(true); // Passing `true` enables exceptions\n try {\n $mail->IsSMTP();\n $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only\n $mail->SMTPAuth = true;\n //$mail->CharSet = 'utf-8';\n //$mail->SMTPSecure = 'tls';\n $mail->Host = \"smtp.hoge.jp\";\n $mail->Port = 587;\n $mail->IsHTML(false);\n $mail->Username = '[email protected]';\n $mail->Password = 'hogehoge';\n $mail->SetFrom('[email protected]');\n $mail->From = '[email protected]';\n $mail->Subject = 'test send';\n $mail->Body = 'test send';\n $mail->AddAddress('[email protected]');\n $mail->send();\n \n } catch (Exception $e) {\n echo $mail->ErrorInfo;\n }\n \n```\n\n追記、php `use` 名前空間について簡単な説明 \nphpは名前空間が指定されない限り、関数名が重複できません(`Fatal\nerror`になります)、関数名が重複しないように名前空間を付けます(名前空間を定義するには、`namespace` を使います。) \n`use` はどこの名前空間なのかを指定しています、指定する名前空間はソースを見るか、ドキュメント通りそのまま指定します。(名前空間名\\関数名;\nここに指定例あり- <https://github.com/PHPMailer/PHPMailer#installation--loading>)\n\n読み込むライブラリは、置いたパスを指定してください。以下(この送信サンプル)は、phpファイルと同じフォルダーに置いた例です。\n\n```\n\n //指定された名前空間の設定\n use PHPMailer\\PHPMailer\\PHPMailer;\n use PHPMailer\\PHPMailer\\Exception;\n \n //ライブラリの指定は include include_once require require_once 何でも良いです\n require 'Exception.php';\n require 'PHPMailer.php';\n require 'SMTP.php';\n \n```",
"comment_count": 5,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-05T02:14:12.690",
"id": "40039",
"last_activity_date": "2017-12-13T02:39:38.397",
"last_edit_date": "2017-12-13T02:39:38.397",
"last_editor_user_id": "22793",
"owner_user_id": "22793",
"parent_id": "40027",
"post_type": "answer",
"score": 1
}
]
| 40027 | 40039 | 40039 |
{
"accepted_answer_id": "40135",
"answer_count": 1,
"body": "# 発生してる問題\n\nGAE初心者です。GAE/Goでデプロイができません。 \nビルドは完了するのですが、serviceのアップデートに時間がかかりすぎてtimeoutになってしまいます。 \nimportするpackageをhttprouterのみにすると成功するので、外部packageの問題だと認識しています。 \nGAEは`syscall` や `unsafe`パッケージのインポートが許されていないことは調べて分かりました。 \n`golang.org/x/sys/unix`をインポートしているので、これが原因なのでしょうか?? \n以下にて現状をお伝えするので、GAE/Goのよくある問題等、ヒントになる情報が欲しいです。 \nもし少しでも気になったことがあったらコメントして頂けますでしょうか?? \nよろしくお願い致します。\n\n## ディレクトリ構成\n\napp.yamlはルート配下のappディレクトリに置いてあります。\n\n[](https://i.stack.imgur.com/bmyLr.png)\n\n## app.yaml\n\n```\n\n runtime: go\n env: flex\n api_version: go1.8\n manual_scaling:\n instances: 1\n resources:\n cpu: 2\n memory_gb: 2.3\n disk_size_gb: 20\n readiness_check:\n app_start_timeout_sec: 3600\n beta_settings:\n cloud_sql_instances: \"インスタンス接続名\"\n \n```\n\n## エラーメッセージ\n\n```\n\n ERROR: (gcloud.app.deploy) Operation \n [apps/profect_id/operations/24c2d890-3bb4-4c72-b037-e7cb57f85b7f] timed \n out. This operation may still be underway.\n \n```\n\n## インポートしているpackage\n\n * github.com/jinzhu/inflection\n * github.com/jinzhu/gorm\n * github.com/go-sql-driver/mysql\n * github.com/jinzhu/gorm/dialects/mysql\n * github.com/julienschmidt/httprouter\n\n## デプロイツール\n\ngcloud app deploy",
"comment_count": 6,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T12:54:39.927",
"favorite_count": 0,
"id": "40029",
"last_activity_date": "2017-12-08T08:05:27.350",
"last_edit_date": "2017-12-06T23:47:30.630",
"last_editor_user_id": "26499",
"owner_user_id": "26499",
"post_type": "question",
"score": 0,
"tags": [
"go",
"google-app-engine",
"google-cloud",
"デプロイ"
],
"title": "GAE/Goでデプロイ出来ない",
"view_count": 681
} | [
{
"body": "# 原因\n\n`Updated health\nchecks`を有効にしているのにも関わらず、`readiness_check`のエンドポイントを設定していないのが原因でした。\n\n# GAEのヘルスチェック\n\nGAEには`Legacy health checks`と`Updated health checks`があり、今回`Updated health\nchecks`を有効にしていました。\n\n# Updated health checks\n\nUpdated health checksは以下の2つを確認します。\n\n## Liveness checks\n\nVMとDockerコンテナが実行中であることを確認する\n\n## Readiness checks\n\nインスタンスがリクエストを受け入れられる状態かどうかをチェックします\n\n今回は、上記のReadiness checksのエンドポイントをアプリケーションで設定していなかったため、サービスをアップデートする事ができませんでした。\n\n*間違いがあったらご指摘お願いします。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-08T08:05:27.350",
"id": "40135",
"last_activity_date": "2017-12-08T08:05:27.350",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "26499",
"parent_id": "40029",
"post_type": "answer",
"score": 0
}
]
| 40029 | 40135 | 40135 |
{
"accepted_answer_id": "40094",
"answer_count": 1,
"body": "volumeについて、`docker-compose.yml` には、`/var/lib/postgresql` 設定してあり、`Dockerfile`\nには `/var/lib/postgresql/data` が設定されています。 \nこのとき、`Dockerfile`のvolume設定を`docker-compose.yml`から解除することは可能でしょうか。\n\n## 解消したい問題の経緯\n\nvolume-driverにはconvoyを使用しているため、`lost+found` が存在すると、`initdb`\nにて次のようなエラーが出てしまう。これを回避しつつ、volume-driverにconvoyを使用したい。\n\n> initdb: directory \"/var/lib/postgresql/data\" exists but is not empty\n\n上記問題を回避するためにとった対策と現実: \n親ディレクトリである `/var/lib/postgresql` をvolumeとすれば解決できると考えた。 \n実際、 `/var/lib/postgresql` と `/var/lib/postgresql/data` にvolumeが使用された。 \n結果、`/var/lib/postgresql` にはデータが入らず、 `/var/lib/postgresql/data` のみにデータが記録された。 \n`/var/lib/postgresql/data`\nがvolumeとして設定されることを防げれば、`/var/lib/postgresql`にデータが入ると考えた。\n\n\\---追記(2017/12/05 02:06) ここから--- \n上記解決したい問題については、[解決策](https://github.com/docker-library/postgres/issues/263\n\"Using volumes for persistent data:'initdb: directory /var/lib/postgresql/data\nexists but is not empty'\") がありました。 \n環境変数 `PGDATA` に `/var/lib/postgresql/data1` 等、異なるパスを記述することで解決できるようです。 \n解決の糸口は見つけましたが、表題の方法があるかどうかについて、気になるので、質問は削除せず、継続させていただきます。 \n\\---追記(2017/12/05 02:06) ここまで---\n\n備考: \n[lost+foundを消すことも検討した](https://ja.stackoverflow.com/questions/28465/lostfound-%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%81%AF%E5%89%8A%E9%99%A4%E3%81%97%E3%81%A6%E5%95%8F%E9%A1%8C%E3%81%AA%E3%81%84\n\"lost+found ディレクトリは削除して問題ない?\")\nが、必要となることもあるため、削除という手段は使用していない。かつ、再度lost+foundが作成されたとき、DB一覧にlost+foundが表示されてしまう(8.x系の記憶なので、最新でどうであるかは未検証)。 \n[convoy側でlost+foundを抑止する可能性](https://github.com/rancher/convoy/issues/104\n\"rancher/convoy - New volumes contain lost+found -\n#104\")も考慮したが、issueの状態が更新されていないことから対応される見込みは薄いと判断した。\n\n### 各種ファイルおよびコマンド実行結果\n\nDockerfile\n\n<https://github.com/docker-\nlibrary/postgres/blob/d1725ffa8ba29ed7649bd453065eb392f63a3113/9.6/alpine/Dockerfile>\n\ndocker-compose.yml\n\n```\n\n version: '3.1'\n services:\n db:\n image: postgres:9.6-alpine\n environment:\n POSTGRES_USER: work\n POSTGRES_PASSWORD: password1\n container_name: test_sv\n volumes:\n - data-db:/var/lib/postgresql\n volumes:\n data-db:\n # 事前にvolumeを作成している場合は以下のコメントを外す\n # external:\n # name: convoy_data-db\n \n```\n\nsudo docker inspect test_sv\n\n```\n\n [\n {\n \"Id\": \"15aa91af404f082ecbaa6b397096f5f47b20640c62dcc9c635457bd2055a7975\",\n \"Created\": \"2017-12-04T14:28:11.596184856Z\",\n \"Path\": \"docker-entrypoint.sh\",\n \"Args\": [\n \"postgres\"\n ],\n ...\n \"Name\": \"/test_sv\",\n \"RestartCount\": 0,\n \"Driver\": \"overlay\",\n \"Platform\": \"linux\",\n \"MountLabel\": \"\",\n \"ProcessLabel\": \"\",\n \"AppArmorProfile\": \"\",\n \"ExecIDs\": null,\n \"HostConfig\": {\n \"Binds\": [\n \"work_data-db:/var/lib/postgresql:rw\"\n ],\n \"ContainerIDFile\": \"\",\n \"LogConfig\": {\n \"Type\": \"json-file\",\n \"Config\": {}\n },\n \"NetworkMode\": \"work_default\",\n \"PortBindings\": {},\n \"RestartPolicy\": {\n \"Name\": \"\",\n \"MaximumRetryCount\": 0\n },\n \"AutoRemove\": false,\n \"VolumeDriver\": \"\",\n \"VolumesFrom\": [],\n ...\n },\n \"GraphDriver\": {\n ...\n },\n \"Mounts\": [\n {\n \"Type\": \"volume\",\n \"Name\": \"9e44772442f9a93457a01172a17816801601b43ffeaea009a1548d55d8efebde\",\n \"Source\": \"/var/lib/docker/volumes/9e44772442f9a93457a01172a17816801601b43ffeaea009a1548d55d8efebde/_data\",\n \"Destination\": \"/var/lib/postgresql/data\",\n \"Driver\": \"local\",\n \"Mode\": \"\",\n \"RW\": true,\n \"Propagation\": \"\"\n },\n {\n \"Type\": \"volume\",\n \"Name\": \"work_data-db\",\n \"Source\": \"/var/lib/docker/volumes/work_data-db/_data\",\n \"Destination\": \"/var/lib/postgresql\",\n \"Driver\": \"local\",\n \"Mode\": \"rw\",\n \"RW\": true,\n \"Propagation\": \"\"\n }\n ],\n \"Config\": {\n \"Hostname\": \"15aa91af404f\",\n \"Domainname\": \"\",\n \"User\": \"\",\n \"AttachStdin\": false,\n \"AttachStdout\": false,\n \"AttachStderr\": false,\n \"ExposedPorts\": {\n \"5432/tcp\": {}\n },\n \"Tty\": false,\n \"OpenStdin\": false,\n \"StdinOnce\": false,\n \"Env\": [\n \"POSTGRES_PASSWORD=password1\",\n \"POSTGRES_USER=work\",\n \"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\",\n \"LANG=en_US.utf8\",\n \"PG_MAJOR=9.6\",\n \"PG_VERSION=9.6.5\",\n \"PG_SHA256=06da12a7e3dddeb803962af8309fa06da9d6989f49e22865335f0a14bad0aaaa\",\n \"PGDATA=/var/lib/postgresql/data\"\n ],\n \"Cmd\": [\n \"postgres\"\n ],\n \"ArgsEscaped\": true,\n \"Image\": \"postgres:9.6-alpine\",\n \"Volumes\": {\n \"/var/lib/postgresql\": {},\n \"/var/lib/postgresql/data\": {}\n },\n \"WorkingDir\": \"\",\n \"Entrypoint\": [\n \"docker-entrypoint.sh\"\n ],\n \"OnBuild\": null,\n \"Labels\": {\n \"com.docker.compose.config-hash\": \"9313f5bb20018503d6e305687c67a382e204b9e0911a3fdd66c54507ee9293ce\",\n \"com.docker.compose.container-number\": \"1\",\n \"com.docker.compose.oneoff\": \"False\",\n \"com.docker.compose.project\": \"work\",\n \"com.docker.compose.service\": \"db\",\n \"com.docker.compose.version\": \"1.16.1\"\n }\n },\n \"NetworkSettings\": {\n ...\n }\n }\n ]\n \n```\n\n### 関連文章\n\n[Compose ファイル・リファレンス - volumes,\nvolume_driver](http://docs.docker.jp/compose/compose-file.html#volumes-volume-\ndriver \"Compose ファイル・リファレンス - volumes, volume_driver\")",
"comment_count": 2,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T16:44:12.163",
"favorite_count": 0,
"id": "40033",
"last_activity_date": "2017-12-06T14:16:03.603",
"last_edit_date": "2017-12-04T17:06:39.610",
"last_editor_user_id": "882",
"owner_user_id": "882",
"post_type": "question",
"score": 0,
"tags": [
"docker",
"docker-compose"
],
"title": "docker-composeでDockerfileのvolume設定を解除することは可能でしょうか",
"view_count": 1433
} | [
{
"body": "コメントよりは、回答の方が良いので、投稿します。\n\nソースはちょっと思い出せないのですが、 docker の image で volume が一度定義されていたとすると、少なくとも layer\nを重ねる方式では、 volume 指定をなかったことにすることはできなかったと記憶しています。\n\nですので、 volume のパスが気にくわない、やり直したいと思った場合には、 オリジナルの Dockerfile を取得し、 Volume\n指定を外した上でイメージをビルドし直す、などが必要になると思っています。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-06T14:16:03.603",
"id": "40094",
"last_activity_date": "2017-12-06T14:16:03.603",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "754",
"parent_id": "40033",
"post_type": "answer",
"score": 0
}
]
| 40033 | 40094 | 40094 |
{
"accepted_answer_id": null,
"answer_count": 1,
"body": "[正規表現\nアポストロフィも文字列の一部としてマッチしたい。](https://ja.stackoverflow.com/questions/40000/%E6%AD%A3%E8%A6%8F%E8%A1%A8%E7%8F%BE-%E3%82%A2%E3%83%9D%E3%82%B9%E3%83%88%E3%83%AD%E3%83%95%E3%82%A3%E3%82%82%E6%96%87%E5%AD%97%E5%88%97%E3%81%AE%E4%B8%80%E9%83%A8%E3%81%A8%E3%81%97%E3%81%A6%E3%83%9E%E3%83%83%E3%83%81%E3%81%97%E3%81%9F%E3%81%84/40005?noredirect=1#comment40562_40005)\nに少し関連して、以下のコードでsingle quoteをエスケープできるようになりました。しかし、僕が使っているrepl.itでは、\n\n/[w']+/g \n[ 'Hell\\'o', 'World' ] \n/[^s]+/g \n[ 'Hell\\'o', 'World' ]\n\nと出力されるようです。オンラインエディタによってはエスケープしているように解釈しなきゃいけないようです。(rendering\nartifactと呼ばれている)質問はオンラインエディタで、正規表現初心者でこのようにエスケープなどで誤解しやすい様になっているものはありますか?\n\n```\n\n function printWords(str) {\r\n var count = 0;\r\n var arr = str.match(/[\\w']+/g);\r\n console.log(\"/[\\w']+/g\\n\", arr);\r\n }\r\n printWords(\"Hell'o World \");\r\n \r\n function printWordss(str) {\r\n var count = 0;\r\n var arr = str.match(/[^\\s]+/g);\r\n console.log(\"/[^\\s]+/g\\n\", arr);\r\n }\r\n printWordss(\"Hell'o World \")\n```\n\nedit1:\n\nコメントの依頼からrendering\nartifactの用語について、<https://stackoverflow.com/questions/40006095/escaping-regex-\nsingle-quote-creates-extra-backslashes-on-repl-it> の回答者のコメントより。",
"comment_count": 9,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-04T23:23:09.347",
"favorite_count": 0,
"id": "40035",
"last_activity_date": "2017-12-06T00:33:46.353",
"last_edit_date": "2017-12-05T09:46:50.373",
"last_editor_user_id": "25766",
"owner_user_id": "25766",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"正規表現"
],
"title": "正規表現の表示に関するオンラインエディタの特徴について",
"view_count": 162
} | [
{
"body": "nekketsuuuさんのコメントからするとsingle quoteのような文字リテラルをartifact扱いとし、正規表現でマッチングした後、single\nquoteをrendering\nartifactとして文字列として扱っているよう表現するようにrepl.itで採用されているようです。質問としては、正規表現で出力結果としてrendering\nartifactで表現するのはオンラインエディタでは良くあるものなのかと言うことでした。\n\n以下抜粋 上記リンクより\n\n> _semantics of artifact in software engineering_\n>\n> In graphics programming, its often used to reference part of an image \n> that did not render correctly. For example, if a small piece of a \n> previous frame or view is still left on screen after drawing is done, \n> that'd be referred to as an artifact.\n>\n> _rendering artifact in repl.it_\n>\n> That's a rendering artifact of how the REPL you are using represents a \n> string when it displays a string as the result of evaluating your \n> code.",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-06T00:16:26.230",
"id": "40067",
"last_activity_date": "2017-12-06T00:33:46.353",
"last_edit_date": "2017-12-06T00:33:46.353",
"last_editor_user_id": "3060",
"owner_user_id": "25766",
"parent_id": "40035",
"post_type": "answer",
"score": 0
}
]
| 40035 | null | 40067 |
{
"accepted_answer_id": "40042",
"answer_count": 2,
"body": "RailsでWebサービスを作りました。 \n2日前にベーシック認証を外したのですが、Googleやヤフーでサービス名を検索したところ、まだサイトが表示されません。 \n以下のサイトでも調べましたが表示されませんでした。 \n<http://checker.search-rank-check.com/#result>\n\nGoogleやヤフーに登録(検索されるようにする)にはどうすれば良いでしょうか? \nご教示の程、宜しくお願い申し上げます。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-05T01:43:35.220",
"favorite_count": 0,
"id": "40038",
"last_activity_date": "2017-12-05T02:44:29.107",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "12323",
"post_type": "question",
"score": 2,
"tags": [
"ruby-on-rails"
],
"title": "Webサービスを作った後、Googleやヤフーに登録(検索されるようにする)にはどうすれば良いでしょうか?",
"view_count": 735
} | [
{
"body": "これはSEOというやつですね。 \nあまりやるとランクを下げられるところもありますが、基本的にはリンクされていないとクローラーが拾えないので、多くのサイトにリンクされるようにすることでしょうか。",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-05T02:15:41.443",
"id": "40040",
"last_activity_date": "2017-12-05T02:15:41.443",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "925",
"parent_id": "40038",
"post_type": "answer",
"score": 0
},
{
"body": "**Google へのサイトの登録** \n[https://support.google.com/webmasters/answer/34397?hl=ja&ref_topic=3309469](https://support.google.com/webmasters/answer/34397?hl=ja&ref_topic=3309469)\n\n> Google の検索結果に、ご自身のサイトを無料で簡単に表示させることができます。Google にサイトを送信する必要すらありません。Google\n> は完全に自動化された検索エンジンです。「ウェブクローラ」というソフトウェアを使用して定期的にウェブを探索し、見つかったサイトを Google\n> のインデックスに登録しています。Google\n> 検索結果に表示されるサイトのほとんどは、手動で登録されたものではなく、ロボットがウェブをクロールして見つかったサイトが自動的に追加されたものです。\n\n特に作業は必要ありませんが、見つけてもらうのを待てない場合は下記の手順を実施してください。\n\n**Webマスターチェックリスト** (PDF) \n<https://storage.googleapis.com/support-kms-\nprod/DED5FEC4F7C3118641D255CD0843F9ECC50F>\n\n> 「site:」の後に自分のドメインを指定して検索し、ページがインデックスに登録されているか確認しましょう(例:site:example.com)。\n> 自分のサイトが表示されない場合は、Google Search\n> Console(g.co/searchconsole)でウェブサイトの所有権を確認して、サイトが インデックスに登録されるよう\n> google.com/webmasters/tools/submit-url でサイトの情報を送信しましょう。\n\nなお、 **Yahoo! JAPANの検索はGoogleの検索エンジンを使っている**\nので、検索結果のカスタマイズはあるものの基本的に同じものです。サイトを見つけてもらうために、Yahoo! JAPAN向けの作業をする必要はありません。",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-05T02:44:29.107",
"id": "40042",
"last_activity_date": "2017-12-05T02:44:29.107",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "2238",
"parent_id": "40038",
"post_type": "answer",
"score": 5
}
]
| 40038 | 40042 | 40042 |
{
"accepted_answer_id": "40049",
"answer_count": 1,
"body": "グローバル変数宣言と同時に代入するとエラー表示されないのですが\n\n```\n\n a=1;\n \n```\n\nグローバル変数宣言だけだとエラーになるのはなぜですか?\n\n```\n\n a;\n \n```\n\n> Uncaught ReferenceError: a is not defined\n\n* * *\n\n「var a;」はOKで「a;」がNGな理由は、仕様だから??",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-05T02:29:55.577",
"favorite_count": 0,
"id": "40041",
"last_activity_date": "2017-12-05T06:34:53.793",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "7886",
"post_type": "question",
"score": 1,
"tags": [
"javascript"
],
"title": "グローバル変数宣言時に、代入しないとエラーになる理由",
"view_count": 214
} | [
{
"body": "`a;`は、変数を宣言しているのではなく参照しているからです。(既にある変数として値を読み出す。(そしてその値は捨てる))",
"comment_count": 1,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-05T06:34:53.793",
"id": "40049",
"last_activity_date": "2017-12-05T06:34:53.793",
"last_edit_date": null,
"last_editor_user_id": null,
"owner_user_id": "5044",
"parent_id": "40041",
"post_type": "answer",
"score": 1
}
]
| 40041 | 40049 | 40049 |
{
"accepted_answer_id": "40044",
"answer_count": 1,
"body": "初歩的な質問で申し訳ないのですが、以下のような場合に`div#b`が`div#a`の中に入ってしまいます。 \nそれを解除して順番通りに表示するにはどうすればいいのか原因と対策を教えてください。 \nscriptがまとめて処理されるので順番通りに表示されないのでしょうか?\n\n```\n\n <div id=\"kihon14\">\n <p>kihon14</p>\n <script>\n for (var i=1 ; i<=10 ; i++){\n document.write(\"繰り返し文ですYO!\" + i + \"<br>\");\n }\n </script>\n </div>\n \n <div id=\"a\">\n <p>配列との組み合わせ</p>\n <script>\n var rank = 1;\n var mnt = new Array(\n \"富士山\",\n \"白根山\",\n \"奥穂高岳\",\n \"間ノ岳\",\n \"槍ヶ岳\"\n );\n document.write('<table border=\"5\">');\n for(var h = 0; h<=4; h++){\n document.write('<tr>');\n document.write('<td>'+rank+'位</td>');\n document.write('<td>'+mnt[h]+'</td>');\n document.write('</td>');\n rank++;\n }\n </script>\n </div>\n \n <div id=\"b\">\n <p>continue + break</p>\n <script>\n for(var s=0; s<=10; s++){\n if(s == 3) continue;\n if(s == 7) break;\n document.write(s + \"回目の繰り返しです。<br>\");\n }\n </script>\n </div>\n \n```",
"comment_count": 0,
"content_license": "CC BY-SA 3.0",
"creation_date": "2017-12-05T03:03:20.500",
"favorite_count": 0,
"id": "40043",
"last_activity_date": "2019-12-13T18:16:55.363",
"last_edit_date": "2017-12-05T03:52:06.873",
"last_editor_user_id": "3060",
"owner_user_id": "26506",
"post_type": "question",
"score": 0,
"tags": [
"javascript",
"html"
],
"title": "配列の要素を順番通りに表示させたい",
"view_count": 222
} | [
{
"body": "tableタグを閉じていないのでは? \n付け足した所動作してるようです\n\n```\n\n <div id=\"kihon14\">\r\n <p>kihon14</p>\r\n <script>\r\n for (var i = 1; i <= 10; i++) {\r\n document.write(\"繰り返し文ですYO!\" + i + \"<br>\");\r\n }\r\n </script>\r\n </div>\r\n \r\n <div id=\"a\">\r\n <p>配列との組み合わせ</p>\r\n <script>\r\n var rank = 1;\r\n var mnt = new Array(\r\n \"富士山\",\r\n \"白根山\",\r\n \"奥穂高岳\",\r\n \"間ノ岳\",\r\n \"槍ヶ岳\"\r\n );\r\n document.write('<table border=\"5\">');\r\n for (var h = 0; h <= 4; h++) {\r\n document.write('<tr>');\r\n document.write('<td>' + rank + '位</td>');\r\n document.write('<td>' + mnt[h] + '</td>');\r\n document.write('</td>');\r\n rank++;\r\n }\r\n document.write('</table>');\r\n </script>\r\n </div>\r\n \r\n <div id=\"b\">\r\n <p>continue + break</p>\r\n <script>\r\n for (var s = 0; s <= 10; s++) {\r\n if (s == 3) continue;\r\n if (s == 7) break;\r\n document.write(s + \"回目の繰り返しです。<br>\");\r\n }\r\n </script>\r\n </div>\n```",
"comment_count": 1,
"content_license": "CC BY-SA 4.0",
"creation_date": "2017-12-05T03:16:15.460",
"id": "40044",
"last_activity_date": "2019-12-13T18:16:55.363",
"last_edit_date": "2019-12-13T18:16:55.363",
"last_editor_user_id": "32986",
"owner_user_id": "26230",
"parent_id": "40043",
"post_type": "answer",
"score": 2
}
]
| 40043 | 40044 | 40044 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.